Skip to content

Commit 1fd0406

Browse files
committed
Fix removing unrelated decorators from class
1 parent 11ce8b5 commit 1fd0406

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

lib/__tests__/__snapshots__/transform.js.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,38 @@ foo
547547
=========="
548548
`;
549549
550+
exports[`native components keeps unrelated decorators in place 1`] = `
551+
"==========
552+
553+
import Component from '@ember/component';
554+
import { classNames, layout } from '@ember-decorators/component';
555+
556+
@layout(template)
557+
@classNames('foo')
558+
export default class FooComponent extends Component {
559+
}
560+
561+
~~~~~~~~~~
562+
foo
563+
~~~~~~~~~~
564+
=> tagName: div
565+
~~~~~~~~~~
566+
567+
import Component from '@ember/component';
568+
import { layout, tagName } from '@ember-decorators/component';
569+
570+
@tagName(\\"\\")
571+
@layout(template)
572+
export default class FooComponent extends Component {
573+
}
574+
575+
~~~~~~~~~~
576+
<div class=\\"foo\\" ...attributes>
577+
foo
578+
</div>
579+
=========="
580+
`;
581+
550582
exports[`native components multi-line template 1`] = `
551583
"==========
552584

lib/__tests__/transform.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,22 @@ describe('native components', function() {
452452
);
453453
});
454454

455+
test('keeps unrelated decorators in place', () => {
456+
let source = `
457+
import Component from '@ember/component';
458+
import { classNames, layout } from '@ember-decorators/component';
459+
460+
@layout(template)
461+
@classNames('foo')
462+
export default class FooComponent extends Component {
463+
}
464+
`;
465+
466+
let template = `foo`;
467+
468+
expect(generateSnapshot(source, template)).toMatchSnapshot();
469+
});
470+
455471
test('skips tagless components', () => {
456472
let source = `
457473
import Component from '@ember/component';

lib/transform/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ module.exports = function transformNativeComponent(root, options) {
120120
debug('classNameBindings: %o', classNameBindings);
121121

122122
// set `@tagName('')`
123-
addClassDecorator(exportDefaultDeclaration, 'tagName', [j.stringLiteral('')]);
123+
addClassDecorator(classDeclaration, 'tagName', [j.stringLiteral('')]);
124124
ensureImport(root, 'tagName', '@ember-decorators/component');
125125

126126
// remove `elementId`, `attributeBindings`, `classNames` and `classNameBindings`

0 commit comments

Comments
 (0)