Skip to content

Commit f7785d6

Browse files
authored
Merge pull request #65 from simonihmig/skip-tagless
Skip tagName='' tagless components
2 parents c72a84a + 47d1cc6 commit f7785d6

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/__tests__/transform.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ describe('native components', function() {
488488
expect(generateSnapshot(source, template)).toMatchSnapshot();
489489
});
490490

491-
test('skips tagless components', () => {
491+
test("skips @tagName('') components", () => {
492492
let source = `
493493
import Component from '@ember/component';
494494
import { tagName } from '@ember-decorators/component';
@@ -506,6 +506,23 @@ describe('native components', function() {
506506
expect(result.template).toEqual(template);
507507
});
508508

509+
test("skips tagName='' components", () => {
510+
let source = `
511+
import Component from '@ember/component';
512+
513+
export default class FooComponent extends Component {
514+
tagName = '';
515+
}
516+
`;
517+
518+
let template = 'foo';
519+
520+
let result = transform(source, template);
521+
expect(result.tagName).toEqual(undefined);
522+
expect(result.source).toEqual(source);
523+
expect(result.template).toEqual(template);
524+
});
525+
509526
test('throws if component is using `this.element`', () => {
510527
let source = `
511528
import Component from '@ember/component';

lib/utils/native.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ function findStringDecorator(path, name) {
7777
return decorator.value.expression.arguments[0].value;
7878
}
7979

80-
function findTagName(path) {
81-
let value = findStringDecorator(path, 'tagName');
82-
return value !== undefined ? value : 'div';
80+
function findTagName(classDeclaration) {
81+
let value = findStringDecorator(classDeclaration, 'tagName');
82+
if (value === undefined) {
83+
value = findStringProperty(classDeclaration.get('body', 'body'), 'tagName');
84+
}
85+
return value !== undefined && value !== null ? value : 'div';
8386
}
8487

8588
function findElementId(path) {

0 commit comments

Comments
 (0)