@@ -20,13 +20,11 @@ import { catalogWireAdapters } from './wire';
2020
2121import { removeDecoratorImport } from './remove-decorator-import' ;
2222import { generateError } from './errors' ;
23- import type { NodePath } from 'estree-toolkit' ;
2423import type { ComponentTransformOptions } from '../shared' ;
2524import type {
2625 Identifier as EsIdentifier ,
2726 Program as EsProgram ,
2827 Decorator as EsDecorator ,
29- ClassDeclaration as EsClassDeclaration ,
3028} from 'estree' ;
3129import type { Visitors , ComponentMetaState } from './types' ;
3230import type { CompilationMode } from '@lwc/shared' ;
@@ -74,7 +72,15 @@ const visitors: Visitors = {
7472 } ,
7573 ClassDeclaration ( path , state ) {
7674 const { node } = path ;
77- if ( 123 ) {
75+ if (
76+ node ?. superClass &&
77+ // export default class extends LightningElement {}
78+ ( is . exportDefaultDeclaration ( path . parentPath ) ||
79+ // class Cmp extends LightningElement {}; export default Cmp
80+ path . scope
81+ ?. getBinding ( node . id . name )
82+ ?. references . some ( ( ref ) => is . exportDefaultDeclaration ( ref . parent ) ) )
83+ ) {
7884 // If it's a default-exported class with a superclass, then it's an LWC component!
7985 state . isLWC = true ;
8086 if ( node . id ) {
@@ -212,43 +218,6 @@ const visitors: Visitors = {
212218 } ,
213219} ;
214220
215- /**
216- * Determines whether a class declaration is an LWC component. Returns true if the class has a
217- * superclass and is a default export.
218- */
219- function isLwcComponent ( path : NodePath < EsClassDeclaration > ) {
220- const { node } = path ;
221- if ( ! node ?. superClass ) {
222- // class Cmp {}
223- return false ;
224- }
225- if ( is . exportDefaultDeclaration ( path . parentPath ) ) {
226- // export default class Cmp extends LightningElement {} => true
227- return true ;
228- }
229- const binding = path . scope ?. getBinding ( node . id . name ) ;
230- if ( ! binding ) {
231- // Never exported
232- return false ;
233- }
234- return binding . references . some ( ( ref ) => {
235- const { parent } = ref ;
236- if ( is . exportDefaultDeclaration ( parent ) ) {
237- // class Cmp extends LightningElement {}; export default Cmp
238- return true ;
239- }
240- if ( is . exportSpecifier ( parent ) ) {
241- // class Cmp extends LightningElement {}; export { Cmp as default }
242- // class Cmp extends LightningElement {}; export { Cmp as 'default' }
243- const exported = is . identifier ( parent . exported )
244- ? parent . exported . name
245- : parent . exported . value ;
246- return exported === 'default' ;
247- }
248- return false ;
249- } ) ;
250- }
251-
252221function validateUniqueDecorator ( decorators : EsDecorator [ ] ) {
253222 if ( decorators . length < 2 ) {
254223 return ;
0 commit comments