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

Disallow paths beginning with @ in templates #13913

Merged
merged 1 commit into from
Jul 27, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { assert } from 'ember-metal/debug';
import calculateLocationDisplay from 'ember-template-compiler/system/calculate-location-display';

export default function AssertReservedNamedArguments(options) {
this.syntax = null;
this.options = options;
}

AssertReservedNamedArguments.prototype.transform = function AssertReservedNamedArguments_transform(ast) {
let moduleName = this.options.moduleName;

this.syntax.traverse(ast, {
PathExpression: function(node) {
if (node.original[0] === '@') {
assert(assertMessage(moduleName, node));
}
}
});

return ast;
};

function assertMessage(moduleName, node) {
let path = node.original;
let source = calculateLocationDisplay(moduleName, node.loc);

return `'${path}' is not a valid path. ${source}`;
}
8 changes: 5 additions & 3 deletions packages/ember-template-compiler/lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import TransformItemClass from 'ember-template-compiler/plugins/transform-item-c
import TransformAngleBracketComponents from 'ember-template-compiler/plugins/transform-angle-bracket-components';
import TransformInputOnToOnEvent from 'ember-template-compiler/plugins/transform-input-on-to-onEvent';
import TransformTopLevelComponents from 'ember-template-compiler/plugins/transform-top-level-components';
import DeprecateRenderModel from 'ember-template-compiler/plugins/deprecate-render-model';
import TransformInlineLinkTo from 'ember-template-compiler/plugins/transform-inline-link-to';
import TransformOldClassBindingSyntax from 'ember-template-compiler/plugins/transform-old-class-binding-syntax';
import DeprecateRenderModel from 'ember-template-compiler/plugins/deprecate-render-model';
import AssertReservedNamedArguments from 'ember-template-compiler/plugins/assert-reserved-named-arguments';

export default Object.freeze([
TransformOldBindingSyntax,
TransformItemClass,
TransformAngleBracketComponents,
TransformInputOnToOnEvent,
TransformTopLevelComponents,
DeprecateRenderModel,
TransformInlineLinkTo,
TransformOldClassBindingSyntax
TransformOldClassBindingSyntax,
DeprecateRenderModel,
AssertReservedNamedArguments
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { compile } from '../utils/helpers';

QUnit.module('ember-template-compiler: assert-reserved-named-arguments');

QUnit.test('Paths beginning with @ are not valid', function() {
expect(3);

expectAssertion(() => {
compile('{{@foo}}', {
moduleName: 'baz/foo-bar'
});
}, `'@foo' is not a valid path. ('baz/foo-bar' @ L1:C2) `);

expectAssertion(() => {
compile('{{#if @foo}}Yup{{/if}}', {
moduleName: 'baz/foo-bar'
});
}, `'@foo' is not a valid path. ('baz/foo-bar' @ L1:C6) `);

expectAssertion(() => {
compile('{{input type=(if @foo "bar" "baz")}}', {
moduleName: 'baz/foo-bar'
});
}, `'@foo' is not a valid path. ('baz/foo-bar' @ L1:C17) `);
Copy link
Member

Choose a reason for hiding this comment

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

@courajs can you add another test for <foo-bar @foo="bar" />?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can open another PR tmw. Any others I should include?

Copy link
Member

Choose a reason for hiding this comment

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

Those are the main ones I can think of, thanks!

});