Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate usage of {{render helper with a model param #13268

Merged
merged 1 commit into from
Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 49 additions & 35 deletions packages/ember-routing-htmlbars/tests/helpers/render_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ QUnit.test('{{render}} helper should render given template with a supplied model
[OWNER]: appInstance
});

view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
expectDeprecation(() => {
view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
}, /Please refactor [\w\{\}"` ]+ to a component/);

var postController;
var PostController = EmberController.extend({
Expand Down Expand Up @@ -181,11 +183,13 @@ QUnit.test('{{render}} helper with a supplied model should not fire observers on
post: post
});

view = EmberView.create({
[OWNER]: appInstance,
controller,
template: compile(template)
});
expectDeprecation(() => {
view = EmberView.create({
[OWNER]: appInstance,
controller,
template: compile(template)
});
}, /Please refactor [\w\{\}"` ]+ to a component/);

var PostController = EmberController.extend({
modelDidChange: observer('model', function() {
Expand Down Expand Up @@ -336,11 +340,13 @@ QUnit.test('{{render}} helper should render templates with models multiple times
[OWNER]: appInstance
});

view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
expectDeprecation(() => {
view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
}, /Please refactor [\w\{\}"` ]+ to a component/);

var postController1, postController2;
var PostController = EmberController.extend({
Expand Down Expand Up @@ -383,11 +389,13 @@ QUnit.test('{{render}} helper should not leak controllers', function() {
[OWNER]: appInstance
});

view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
expectDeprecation(() => {
view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
}, /Please refactor [\w\{\}"` ]+ to a component/);

var postController;
var PostController = EmberController.extend({
Expand Down Expand Up @@ -415,11 +423,13 @@ QUnit.test('{{render}} helper should not treat invocations with falsy contexts a
zero: false
});

view = EmberView.create({
[OWNER]: appInstance,
controller,
template: compile(template)
});
expectDeprecation(() => {
view = EmberView.create({
[OWNER]: appInstance,
controller,
template: compile(template)
});
}, /Please refactor [\w\{\}"` ]+ to a component/);

var postController1, postController2;
var PostController = EmberController.extend({
Expand Down Expand Up @@ -457,11 +467,13 @@ QUnit.test('{{render}} helper should render templates both with and without mode
[OWNER]: appInstance
});

view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
expectDeprecation(() => {
view = EmberView.create({
[OWNER]: appInstance,
controller: controller,
template: compile(template)
});
}, /Please refactor [\w\{\}"` ]+ to a component/);

var postController1, postController2;
var PostController = EmberController.extend({
Expand Down Expand Up @@ -695,16 +707,18 @@ QUnit.test('{{render}} helper should not require view to provide its own templat
});

QUnit.test('{{render}} helper should set router as target when parentController is not found', function() {
expect(2);
expect(3);

Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT = false;

let template = `{{render 'post' post1}}`;

view = EmberView.create({
[OWNER]: appInstance,
template: compile(template)
});
expectDeprecation(() => {
view = EmberView.create({
[OWNER]: appInstance,
template: compile(template)
});
}, /Please refactor [\w\{\}"` ]+ to a component/);

let postController;
let PostController = EmberController.extend({
Expand Down
2 changes: 2 additions & 0 deletions packages/ember-template-compiler/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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 TransformUnescapedInlineLinkTo from 'ember-template-compiler/plugins/transform-unescaped-inline-link-to';
import DeprecateRenderModel from 'ember-template-compiler/plugins/deprecate-render-model';
import AssertNoViewAndControllerPaths from 'ember-template-compiler/plugins/assert-no-view-and-controller-paths';
import AssertNoViewHelper from 'ember-template-compiler/plugins/assert-no-view-helper';
import AssertNoEachIn from 'ember-template-compiler/plugins/assert-no-each-in';
Expand All @@ -31,6 +32,7 @@ registerPlugin('ast', TransformAngleBracketComponents);
registerPlugin('ast', TransformInputOnToOnEvent);
registerPlugin('ast', TransformTopLevelComponents);
registerPlugin('ast', TransformUnescapedInlineLinkTo);
registerPlugin('ast', DeprecateRenderModel);
registerPlugin('ast', AssertNoEachIn);

if (!_Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT) {
Expand Down
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! I just realized that this doesn't include the URL from the website PR. Can you submit a follow up to add that in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

});
});
});

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}`;
}
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);
});
}