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 beta] Remove deprecation for classBinding and classNameBindings. #11271

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
56 changes: 22 additions & 34 deletions packages/ember-htmlbars/tests/helpers/view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,10 @@ QUnit.test("allows you to pass attributes that will be assigned to the class ins
});

QUnit.test("Should apply class without condition always", function() {
expectDeprecation(function() {
view = EmberView.create({
controller: Ember.Object.create(),
template: compile('{{#view id="foo" classBinding=":foo"}} Foo{{/view}}')
});
}, /legacy class binding syntax/);
view = EmberView.create({
controller: Ember.Object.create(),
template: compile('{{#view id="foo" classBinding=":foo"}} Foo{{/view}}')
});

runAppend(view);

Expand Down Expand Up @@ -855,12 +853,10 @@ QUnit.test('{{view}} should evaluate class bindings set to global paths DEPRECAT
});
});

expectDeprecation(function() {
view = EmberView.create({
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled:enabled:disabled"}}')
});
}, /legacy class binding/);
view = EmberView.create({
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled:enabled:disabled"}}')
});

expectDeprecation(function() {
runAppend(view);
Expand All @@ -886,16 +882,14 @@ QUnit.test('{{view}} should evaluate class bindings set to global paths DEPRECAT
});

QUnit.test('{{view}} should evaluate class bindings set in the current context', function() {
expectDeprecation(function() {
view = EmberView.create({
isView: true,
isEditable: true,
directClass: 'view-direct',
isEnabled: true,
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="view.isEditable:editable view.directClass view.isView view.isEnabled:enabled:disabled"}}')
});
}, /legacy class binding syntax/);
view = EmberView.create({
isView: true,
isEditable: true,
directClass: 'view-direct',
isEnabled: true,
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="view.isEditable:editable view.directClass view.isView view.isEnabled:enabled:disabled"}}')
});

runAppend(view);

Expand Down Expand Up @@ -926,12 +920,10 @@ QUnit.test('{{view}} should evaluate class bindings set with either classBinding
});
});

expectDeprecation(function() {
view = EmberView.create({
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="App.isGreat:great App.isEnabled:enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled:really-enabled:really-disabled"}}')
});
}, /legacy class binding/);
view = EmberView.create({
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="App.isGreat:great App.isEnabled:enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled:really-enabled:really-disabled"}}')
});

expectDeprecation(function() {
runAppend(view);
Expand Down Expand Up @@ -996,9 +988,7 @@ QUnit.test('{{view}} should evaluate other attributes bindings set in the curren
});

QUnit.test('{{view}} should be able to bind class names to truthy properties', function() {
expectDeprecation(function() {
registry.register('template:template', compile('{{#view view.classBindingView classBinding="view.number:is-truthy"}}foo{{/view}}'));
}, /legacy class binding syntax/);
registry.register('template:template', compile('{{#view view.classBindingView classBinding="view.number:is-truthy"}}foo{{/view}}'));

var ClassBindingView = EmberView.extend();

Expand All @@ -1021,9 +1011,7 @@ QUnit.test('{{view}} should be able to bind class names to truthy properties', f
});

QUnit.test('{{view}} should be able to bind class names to truthy or falsy properties', function() {
expectDeprecation(function() {
registry.register('template:template', compile('{{#view view.classBindingView classBinding="view.number:is-truthy:is-falsy"}}foo{{/view}}'));
}, /legacy class binding syntax/);
registry.register('template:template', compile('{{#view view.classBindingView classBinding="view.number:is-truthy:is-falsy"}}foo{{/view}}'));

var ClassBindingView = EmberView.extend();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import Ember from 'ember-metal/core';
import calculateLocationDisplay from "ember-template-compiler/system/calculate-location-display";

export default function TransformOldClassBindingSyntax(options) {
this.syntax = null;
this.options = options;
Expand All @@ -9,7 +6,6 @@ export default function TransformOldClassBindingSyntax(options) {
TransformOldClassBindingSyntax.prototype.transform = function TransformOldClassBindingSyntax_transform(ast) {
var b = this.syntax.builders;
var walker = new this.syntax.Walker();
var moduleName = this.options.moduleName;

walker.visit(ast, function(node) {
if (!validate(node)) { return; }
Expand Down Expand Up @@ -46,10 +42,8 @@ TransformOldClassBindingSyntax.prototype.transform = function TransformOldClassB

each(allOfTheMicrosyntaxes, ({ value, loc }) => {
let sexprs = [];
let sourceInformation = calculateLocationDisplay(moduleName, loc);

// TODO: Parse the microsyntax and offer the correct information
Ember.deprecate(`You're using legacy class binding syntax: classBinding=${exprToString(value)} ${sourceInformation}. Please replace with class=""`);
// TODO: add helpful deprecation when both `classNames` and `classNameBindings` can
// be removed.

if (value.type === 'StringLiteral') {
let microsyntax = parseMicrosyntax(value.original);
Expand Down Expand Up @@ -125,10 +119,3 @@ function parseMicrosyntax(string) {

return segments;
}

function exprToString(expr) {
switch (expr.type) {
case 'StringLiteral': return `"${expr.original}"`;
case 'PathExpression': return expr.original;
}
}