-
-
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 #14441 from josemarluedke/deprecate-render
Deprecate {{render helper
- Loading branch information
Showing
6 changed files
with
161 additions
and
23 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
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
51 changes: 51 additions & 0 deletions
51
packages/ember-template-compiler/lib/plugins/deprecate-render.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,51 @@ | ||
import { deprecate } from 'ember-metal'; | ||
import calculateLocationDisplay from '../system/calculate-location-display'; | ||
|
||
export default function DeprecateRender(options) { | ||
this.syntax = null; | ||
this.options = options; | ||
} | ||
|
||
DeprecateRender.prototype.transform = | ||
function DeprecateRender_transform(ast) { | ||
let moduleName = this.options.meta.moduleName; | ||
let walker = new this.syntax.Walker(); | ||
|
||
walker.visit(ast, function(node) { | ||
if (!validate(node)) { return; } | ||
|
||
each(node.params, (param) => { | ||
if (param.type !== 'StringLiteral') { return; } | ||
|
||
deprecate(deprecationMessage(moduleName, node), false, { | ||
id: 'ember-template-compiler.deprecate-render', | ||
until: '3.0.0', | ||
url: 'http://emberjs.com/deprecations/v2.x#toc_code-render-code-helper' | ||
}); | ||
}); | ||
}); | ||
|
||
return ast; | ||
}; | ||
|
||
function validate(node) { | ||
return (node.type === 'MustacheStatement') && | ||
(node.path.original === 'render') && | ||
(node.params.length === 1); | ||
} | ||
|
||
function each(list, callback) { | ||
for (let i = 0, l = list.length; i < l; i++) { | ||
callback(list[i]); | ||
} | ||
} | ||
|
||
function deprecationMessage(moduleName, node) { | ||
let sourceInformation = calculateLocationDisplay(moduleName, node.loc); | ||
let componentName = node.params[0].original; | ||
let original = `{{render "${componentName}"}}`; | ||
let preferred = `{{${componentName}}}`; | ||
|
||
return `Please refactor \`${original}\` to a component and invoke via` + | ||
` \`${preferred}\`. ${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
17 changes: 17 additions & 0 deletions
17
packages/ember-template-compiler/tests/plugins/deprecate-render-test.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,17 @@ | ||
import { compile } from '../../index'; | ||
|
||
QUnit.module('ember-template-compiler: deprecate-render'); | ||
|
||
QUnit.test('Using `{{render` without a model provides a deprecation', function() { | ||
expect(1); | ||
|
||
let expectedMessage = | ||
`Please refactor \`{{render "foo-bar"}}\` to a component and` + | ||
` invoke via \`{{foo-bar}}\`. ('baz/foo-bar' @ L1:C0) `; | ||
|
||
expectDeprecation(() => { | ||
compile('{{render "foo-bar"}}', { | ||
moduleName: 'baz/foo-bar' | ||
}); | ||
}, expectedMessage); | ||
}); |
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