Skip to content

Commit 18ac349

Browse files
authored
Merge pull request #69 from jrjohnson/static-classnamebinding
Handle static class name bindings
2 parents c895810 + f1e907d commit 18ac349

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/__tests__/__snapshots__/transform.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ exports[`classic components handles \`classNameBindings\` correctly 1`] = `
9797
"==========
9898
9999
export default Component.extend({
100-
classNameBindings: ['a:b', 'x:y:z', 'foo::bar'],
100+
classNameBindings: ['a:b', 'x:y:z', 'foo::bar', ':static'],
101101
});
102102
103103
~~~~~~~~~~
@@ -111,7 +111,7 @@ foo
111111
});
112112
113113
~~~~~~~~~~
114-
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}}\\" ...attributes>
114+
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}} static\\" ...attributes>
115115
foo
116116
</div>
117117
=========="
@@ -447,7 +447,7 @@ exports[`native components handles \`@classNameBindings\` correctly 1`] = `
447447
import Component from '@ember/component';
448448
import { classNameBindings } from '@ember-decorators/component';
449449
450-
@classNameBindings('a:b', 'x:y:z', 'foo::bar')
450+
@classNameBindings('a:b', 'x:y:z', 'foo::bar', ':static')
451451
export default class FooComponent extends Component {
452452
}
453453
@@ -465,7 +465,7 @@ foo
465465
}
466466
467467
~~~~~~~~~~
468-
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}}\\" ...attributes>
468+
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}} static\\" ...attributes>
469469
foo
470470
</div>
471471
=========="

lib/__tests__/transform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('classic components', function() {
101101
test('handles `classNameBindings` correctly', () => {
102102
let source = `
103103
export default Component.extend({
104-
classNameBindings: ['a:b', 'x:y:z', 'foo::bar'],
104+
classNameBindings: ['a:b', 'x:y:z', 'foo::bar', ':static'],
105105
});
106106
`;
107107

@@ -447,7 +447,7 @@ describe('native components', function() {
447447
import Component from '@ember/component';
448448
import { classNameBindings } from '@ember-decorators/component';
449449
450-
@classNameBindings('a:b', 'x:y:z', 'foo::bar')
450+
@classNameBindings('a:b', 'x:y:z', 'foo::bar', ':static')
451451
export default class FooComponent extends Component {
452452
}
453453
`;

lib/transform/template.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module.exports = function transformTemplate(
2222
classNameBindings.forEach(([truthy, falsy], property) => {
2323
if (!truthy) {
2424
classNodes.push(b.mustache(`unless this.${property} "${falsy}"`));
25+
} else if (!property) {
26+
classNodes.push(b.text(truthy));
2527
} else {
2628
classNodes.push(b.mustache(`if this.${property} "${truthy}"${falsy ? ` "${falsy}"` : ''}`));
2729
}

0 commit comments

Comments
 (0)