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

Handle static class name bindings #69

Merged
merged 1 commit into from
Mar 12, 2020
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
8 changes: 4 additions & 4 deletions lib/__tests__/__snapshots__/transform.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ exports[`classic components handles \`classNameBindings\` correctly 1`] = `
"==========

export default Component.extend({
classNameBindings: ['a:b', 'x:y:z', 'foo::bar'],
classNameBindings: ['a:b', 'x:y:z', 'foo::bar', ':static'],
});

~~~~~~~~~~
Expand All @@ -111,7 +111,7 @@ foo
});

~~~~~~~~~~
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}}\\" ...attributes>
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}} static\\" ...attributes>
foo
</div>
=========="
Expand Down Expand Up @@ -447,7 +447,7 @@ exports[`native components handles \`@classNameBindings\` correctly 1`] = `
import Component from '@ember/component';
import { classNameBindings } from '@ember-decorators/component';

@classNameBindings('a:b', 'x:y:z', 'foo::bar')
@classNameBindings('a:b', 'x:y:z', 'foo::bar', ':static')
export default class FooComponent extends Component {
}

Expand All @@ -465,7 +465,7 @@ foo
}

~~~~~~~~~~
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}}\\" ...attributes>
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}} static\\" ...attributes>
foo
</div>
=========="
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('classic components', function() {
test('handles `classNameBindings` correctly', () => {
let source = `
export default Component.extend({
classNameBindings: ['a:b', 'x:y:z', 'foo::bar'],
classNameBindings: ['a:b', 'x:y:z', 'foo::bar', ':static'],
});
`;

Expand Down Expand Up @@ -447,7 +447,7 @@ describe('native components', function() {
import Component from '@ember/component';
import { classNameBindings } from '@ember-decorators/component';

@classNameBindings('a:b', 'x:y:z', 'foo::bar')
@classNameBindings('a:b', 'x:y:z', 'foo::bar', ':static')
export default class FooComponent extends Component {
}
`;
Expand Down
2 changes: 2 additions & 0 deletions lib/transform/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = function transformTemplate(
classNameBindings.forEach(([truthy, falsy], property) => {
if (!truthy) {
classNodes.push(b.mustache(`unless this.${property} "${falsy}"`));
} else if (!property) {
classNodes.push(b.text(truthy));
} else {
classNodes.push(b.mustache(`if this.${property} "${truthy}"${falsy ? ` "${falsy}"` : ''}`));
}
Expand Down