-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13295 from rwjblue/prevent-render-block
Disable `render` helper in block form.
- Loading branch information
Showing
4 changed files
with
38 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
packages/ember-template-compiler/lib/plugins/deprecate-render-block.js
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
packages/ember-template-compiler/lib/plugins/prevent-render-block.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters