Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash from classes extending a non-identifier superclass during Ember core module check #906

Merged
merged 1 commit into from Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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