From 09b821eccb06753691bf866f80fc5458f0f6f6dc Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Thu, 6 Aug 2020 14:44:47 -0400 Subject: [PATCH] fix: ignore classes extending a non-identifier super class in Ember core module check --- lib/utils/ember.js | 2 +- tests/lib/utils/ember-test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/utils/ember.js b/lib/utils/ember.js index c30d42023b..70a6554c41 100644 --- a/lib/utils/ember.js +++ b/lib/utils/ember.js @@ -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( diff --git a/tests/lib/utils/ember-test.js b/tests/lib/utils/ember-test.js index 1550073cfc..9f7123d91b 100644 --- a/tests/lib/utils/ember-test.js +++ b/tests/lib/utils/ember-test.js @@ -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];