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

[BUGFIX LTS] Prevent transformation of block params called attrs #19472

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,27 @@ export default function transformAttrsIntoArgs(env: EmberASTPluginEnvironment):

let stack: string[][] = [[]];

function updateBlockParamsStack(blockParams: string[]) {
let parent = stack[stack.length - 1];
stack.push(parent.concat(blockParams));
}

return {
name: 'transform-attrs-into-args',

visitor: {
Program: {
enter(node: AST.Program) {
let parent = stack[stack.length - 1];
stack.push(parent.concat(node.blockParams));
updateBlockParamsStack(node.blockParams);
},
exit() {
stack.pop();
},
},

ElementNode: {
enter(node: AST.ElementNode) {
updateBlockParamsStack(node.blockParams);
},
exit() {
stack.pop();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import TransformTestCase from '../utils/transform-test-case';
import { moduleFor, RenderingTestCase } from 'internal-test-helpers';

moduleFor(
'ember-template-compiler: transforming attrs into @args',
class extends TransformTestCase {
['@test it transforms attrs into @args']() {
expectDeprecation(() => {
this.assertTransformed(`{{attrs.foo}}`, `{{@foo}}`);
}, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./);

expectDeprecation(() => {
this.assertTransformed(`{{attrs.foo.bar}}`, `{{@foo.bar}}`);
}, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo.bar}} should be updated to {{@foo.bar}}./);

expectDeprecation(() => {
this.assertTransformed(`{{if attrs.foo "foo"}}`, `{{if @foo "foo"}}`);
}, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./);

expectDeprecation(() => {
this.assertTransformed(`{{#if attrs.foo}}{{/if}}`, `{{#if @foo}}{{/if}}`);
}, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./);

expectDeprecation(() => {
this.assertTransformed(`{{deeply (nested attrs.foo.bar)}}`, `{{deeply (nested @foo.bar)}}`);
}, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo.bar}} should be updated to {{@foo.bar}}./);

expectDeprecation(() => {
this.assertTransformed(`{{this.attrs.foo}}`, `{{@foo}}`);
}, /Using {{attrs}} to reference named arguments has been deprecated. {{attrs.foo}} should be updated to {{@foo}}./);
}
}
);

moduleFor(
'ember-template-compiler: not transforming block params named "attrs" into @args',
class extends RenderingTestCase {
["@test it doesn't transform block params"]() {
this.registerComponent('foo', {
template: '{{#let "foo" as |attrs|}}{{attrs}}{{/let}}',
});
this.render('<Foo />');
this.assertComponentElement(this.firstChild, { content: 'foo' });
}

["@test it doesn't transform component block params"]() {
this.registerComponent('foo', {
template: '{{yield "foo"}}',
});
this.render('<Foo as |attrs|>{{attrs}}</Foo>');
this.assertComponentElement(this.firstChild, { content: 'foo' });
}

["@test it doesn't transform block params with nested keys"]() {
this.registerComponent('foo', {
template: '{{yield (hash bar="baz")}}',
});
this.render('<Foo as |attrs|>{{attrs.bar}}</Foo>');
this.assertComponentElement(this.firstChild, { content: 'baz' });
}
}
);