Skip to content

Commit

Permalink
Merge pull request #13295 from rwjblue/prevent-render-block
Browse files Browse the repository at this point in the history
Disable `render` helper in block form.
  • Loading branch information
rwjblue committed Apr 11, 2016
2 parents f1983cc + 82970e1 commit 6b78bcb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 46 deletions.
4 changes: 2 additions & 2 deletions packages/ember-template-compiler/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TransformAngleBracketComponents from 'ember-template-compiler/plugins/tra
import TransformInputOnToOnEvent from 'ember-template-compiler/plugins/transform-input-on-to-onEvent';
import TransformTopLevelComponents from 'ember-template-compiler/plugins/transform-top-level-components';
import DeprecateRenderModel from 'ember-template-compiler/plugins/deprecate-render-model';
import DeprecateRenderBlock from 'ember-template-compiler/plugins/deprecate-render-block';
import PreventRenderBlock from 'ember-template-compiler/plugins/prevent-render-block';
import TransformInlineLinkTo from 'ember-template-compiler/plugins/transform-inline-link-to';
import AssertNoViewAndControllerPaths from 'ember-template-compiler/plugins/assert-no-view-and-controller-paths';
import AssertNoViewHelper from 'ember-template-compiler/plugins/assert-no-view-helper';
Expand All @@ -33,7 +33,7 @@ registerPlugin('ast', TransformAngleBracketComponents);
registerPlugin('ast', TransformInputOnToOnEvent);
registerPlugin('ast', TransformTopLevelComponents);
registerPlugin('ast', DeprecateRenderModel);
registerPlugin('ast', DeprecateRenderBlock);
registerPlugin('ast', PreventRenderBlock);
registerPlugin('ast', AssertNoEachIn);
registerPlugin('ast', TransformInlineLinkTo);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Error from 'ember-metal/error';
import calculateLocationDisplay from
'ember-template-compiler/system/calculate-location-display';

export default function PreventRenderBlock(options) {
this.syntax = null;
this.options = options;
}

PreventRenderBlock.prototype.transform =
function PreventRenderBlock_transform(ast) {
let moduleName = this.options.moduleName;
let walker = new this.syntax.Walker();

walker.visit(ast, function(node) {
if (!validate(node)) { return; }

throw new Error(assertionMessage(moduleName, node));
});

return ast;
};

function validate(node) {
return (node.type === 'BlockStatement') &&
(node.path.original === 'render');
}

function assertionMessage(moduleName, node) {
let sourceInformation = calculateLocationDisplay(moduleName, node.loc);

return `Usage of \`render\` in block form is unsupported ${sourceInformation}.`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ if (!isEnabled('ember-glimmer')) {

QUnit.module('ember-template-compiler: deprecate-render-block');

QUnit.test('Using `render` with a block issues a deprecation', function() {
QUnit.test('Using `render` with a block throws an error', function() {
expect(1);

let expectedMessage = `Usage of \`render\` in block form is deprecated ('baz/foo-bar' @ L1:C0) .`;
let expectedMessage = `Usage of \`render\` in block form is unsupported ('baz/foo-bar' @ L1:C0) .`;

expectDeprecation(function() {
throws(function() {
compile('{{#render "foo-bar"}}{{/render}}', {
moduleName: 'baz/foo-bar'
});
Expand Down

0 comments on commit 6b78bcb

Please sign in to comment.