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

Add a better deprecation for {{bind-attr}}. #11138

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 @@ -24,9 +24,10 @@ import { dasherize } from "ember-template-compiler/system/string";
@class TransformBindAttrToAttributes
@private
*/
function TransformBindAttrToAttributes() {
function TransformBindAttrToAttributes(options) {
// set later within HTMLBars to the syntax package
this.syntax = null;
this.options = options || {};
}

/**
Expand All @@ -36,14 +37,15 @@ function TransformBindAttrToAttributes() {
*/
TransformBindAttrToAttributes.prototype.transform = function TransformBindAttrToAttributes_transform(ast) {
var plugin = this;
var moduleName = this.options.moduleName;
var walker = new this.syntax.Walker();

walker.visit(ast, function(node) {
if (node.type === 'ElementNode') {
for (var i = 0; i < node.modifiers.length; i++) {
var modifier = node.modifiers[i];

if (isBindAttrModifier(modifier)) {
if (isBindAttrModifier(modifier, moduleName)) {
node.modifiers.splice(i--, 1);
plugin.assignAttrs(node, modifier.hash);
}
Expand Down Expand Up @@ -156,13 +158,28 @@ TransformBindAttrToAttributes.prototype.parseClass = function parseClass(value)
}
};

function isBindAttrModifier(modifier) {
function isBindAttrModifier(modifier, moduleName) {
var name = modifier.path.original;

let { column, line } = modifier.path.loc.start || {};
let moduleInfo = '';

if (moduleName) {
moduleInfo += `'${moduleName}' @ `;
}

if (line && column) {
moduleInfo += `L${line}:C${column}`;
}

if (moduleInfo) {
moduleInfo = `(${moduleInfo}) `;
}

if (name === 'bind-attr' || name === 'bindAttr') {
Ember.deprecate(
'The `' + name + '` helper is deprecated in favor of ' +
'HTMLBars-style bound attributes'
'The `' + name + '` helper ' + moduleInfo + 'is deprecated in favor of ' +
'HTMLBars-style bound attributes.'
);
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ QUnit.test("Using the `bind-attr` helper throws a deprecation", function() {
expect(1);

expectDeprecation(function() {
compile('<div {{bind-attr class=view.foo}}></div>');
}, /The `bind-attr` helper is deprecated in favor of HTMLBars-style bound attributes/);
compile('<div {{bind-attr class=view.foo}}></div>', {
moduleName: 'foo/bar/baz'
});
}, "The `bind-attr` helper ('foo/bar/baz' @ L1:C7) is deprecated in favor of HTMLBars-style bound attributes.");
});

QUnit.test("Using the `bindAttr` helper throws a deprecation", function() {
expect(1);

expectDeprecation(function() {
compile('<div {{bindAttr class=view.foo}}></div>');
}, /The `bindAttr` helper is deprecated in favor of HTMLBars-style bound attributes/);
}, "The `bindAttr` helper (L1:C7) is deprecated in favor of HTMLBars-style bound attributes.");
});

QUnit.test("asserts for <div class='foo' {{bind-attr class='bar'}}></div>", function() {
Expand Down