Skip to content

Commit

Permalink
Merge pull request #906 from bmish/super-class-non-identifier
Browse files Browse the repository at this point in the history
Avoid crash from classes extending a non-identifier superclass during Ember core module check
  • Loading branch information
bmish authored Aug 7, 2020
2 parents f4b4060 + 09b821e commit b673ed6
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 b673ed6

Please sign in to comment.