Skip to content

Commit

Permalink
Merge pull request #11138 from rwjblue/make-bind-attr-deprecation-mor…
Browse files Browse the repository at this point in the history
…e-debuggable

Add a better deprecation for `{{bind-attr}}`.
  • Loading branch information
rwjblue committed May 14, 2015
2 parents 0fe3ae5 + 196b290 commit f2540bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
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

0 comments on commit f2540bf

Please sign in to comment.