Skip to content

Commit

Permalink
fix: ignore classes extending a non-identifier super class in Ember c…
Browse files Browse the repository at this point in the history
…ore module check
  • Loading branch information
bmish committed Aug 6, 2020
1 parent f4b4060 commit 09b821e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/ember.js
Expand Up @@ -207,7 +207,7 @@ function isEmberCoreModule(context, node, moduleName) {
return isClassicEmberCoreModule(node, moduleName, context.getFilename());
} else if (types.isClassDeclaration(node)) {
// native classes
if (!node.superClass) {
if (!node.superClass || !types.isIdentifier(node.superClass)) {
return false;
}
const superClassImportPath = importUtils.getSourceModuleNameForIdentifier(
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/utils/ember-test.js
Expand Up @@ -204,6 +204,24 @@ describe('isEmberCoreModule', () => {
expect(emberUtils.isEmberCoreModule(context, node, 'Route')).toBeTruthy();
});

it('should check if current file is a route with native class', () => {
const context = new FauxContext(
"import Route from '@ember/routing/route'; class MyRoute extends Route {}",
'example-app/some-twisted-path/some-route.js'
);
const node = context.ast.body[1];
expect(emberUtils.isEmberCoreModule(context, node, 'Route')).toBeTruthy();
});

it('ignores a native class with a non-identifier super class', () => {
const context = new FauxContext(
'class MyRoute extends this.ContainerObject {}',
'example-app/some-twisted-path/some-route.js'
);
const node = context.ast.body[0];
expect(emberUtils.isEmberCoreModule(context, node, 'Route')).toBeFalsy();
});

it('throws when called on wrong type of node', () => {
const context = new FauxContext('const x = 123;');
const node = context.ast.body[0];
Expand Down

0 comments on commit 09b821e

Please sign in to comment.