Skip to content

Commit 5180277

Browse files
authored
Merge pull request #16 from Turbo87/element-id
Skip components that use `this.elementId`
2 parents 489a561 + ab88deb commit 5180277

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/__tests__/transform.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ test('throws if component is using `this.element`', () => {
149149
);
150150
});
151151

152+
test('throws if component is using `this.elementId`', () => {
153+
let source = `
154+
export default Component.extend({
155+
didInsertElement() {
156+
console.log(this.elementId);
157+
},
158+
});
159+
`;
160+
161+
expect(() => transform(source, '')).toThrowErrorMatchingInlineSnapshot(
162+
`"Using \`this.elementId\` is not supported in tagless components"`
163+
);
164+
});
165+
152166
test('throws if component is using `keyDown()`', () => {
153167
let source = `
154168
export default Component.extend({

lib/transform.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ function transform(source, template, options = {}) {
126126
throw new SilentError(`Using \`this.element\` is not supported in tagless components`);
127127
}
128128

129+
// skip components that use `this.elementId`
130+
let thisElementIdPaths = j(objectArg).find(j.MemberExpression, {
131+
object: { type: 'ThisExpression' },
132+
property: { name: 'elementId' },
133+
});
134+
if (thisElementIdPaths.length !== 0) {
135+
throw new SilentError(`Using \`this.elementId\` is not supported in tagless components`);
136+
}
137+
129138
// skip components that use `click()` etc.
130139
for (let methodName of EVENT_HANDLER_METHODS) {
131140
let handlerMethod = properties.filter(path => isMethod(path, methodName))[0];

0 commit comments

Comments
 (0)