-
-
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.
Deprecate '{{render' helper with model param
- Loading branch information
Robbie Pitts
committed
Apr 6, 2016
1 parent
02047a0
commit 39c71b4
Showing
4 changed files
with
125 additions
and
35 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
52 changes: 52 additions & 0 deletions
52
packages/ember-template-compiler/lib/plugins/deprecate-render-model.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,52 @@ | ||
import { deprecate } from 'ember-metal/debug'; | ||
import calculateLocationDisplay from | ||
'ember-template-compiler/system/calculate-location-display'; | ||
|
||
export default function DeprecateRenderModel(options) { | ||
this.syntax = null; | ||
this.options = options; | ||
} | ||
|
||
DeprecateRenderModel.prototype.transform = | ||
function DeprecateRenderModel_transform(ast) { | ||
let moduleName = this.options.moduleName; | ||
let walker = new this.syntax.Walker(); | ||
|
||
walker.visit(ast, function(node) { | ||
if (!validate(node)) { return; } | ||
|
||
each(node.params, (param) => { | ||
if (param.type !== 'PathExpression') { return; } | ||
|
||
deprecate(deprecationMessage(moduleName, node, param), false, { | ||
id: 'ember-template-compiler.deprecate-render-model', | ||
until: '3.0.0' | ||
}); | ||
}); | ||
}); | ||
|
||
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, param) { | ||
let sourceInformation = calculateLocationDisplay(moduleName, node.loc); | ||
let componentName = node.params[0].original; | ||
let modelName = param.original; | ||
let original = `{{render "${componentName}" ${modelName}}}`; | ||
let preferred = `{{${componentName} model=${modelName}}}`; | ||
|
||
return `Please refactor \`${original}\` to a component and invoke via` + | ||
` \`${preferred}\`. ${sourceInformation}`; | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/ember-template-compiler/tests/plugins/deprecate-render-model-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,22 @@ | ||
import { compile } from 'ember-template-compiler'; | ||
import isEnabled from 'ember-metal/features'; | ||
|
||
if (!isEnabled('ember-glimmer')) { | ||
// jscs:disable | ||
|
||
QUnit.module('ember-template-compiler: deprecate-model-render'); | ||
|
||
QUnit.test('Using `{{render` with model provides a deprecation', function() { | ||
expect(1); | ||
|
||
let expectedMessage = | ||
`Please refactor \`{{render "foo-bar" coolModel}}\` to a component and` + | ||
` invoke via \`{{foo-bar model=coolModel}}\`. ('baz/foo-bar' @ L1:C0) `; | ||
|
||
expectDeprecation(function() { | ||
compile('{{render "foo-bar" coolModel}}', { | ||
moduleName: 'baz/foo-bar' | ||
}); | ||
}, expectedMessage); | ||
}); | ||
} |