@@ -683,7 +683,9 @@ func (b *Binder) bind(node *ast.Node) bool {
683683 case ast .KindInterfaceDeclaration :
684684 b .bindBlockScopedDeclaration (node , ast .SymbolFlagsInterface , ast .SymbolFlagsInterfaceExcludes )
685685 case ast .KindCallExpression :
686- b .bindCallExpression (node )
686+ if ast .IsInJSFile (node ) {
687+ b .bindCallExpression (node )
688+ }
687689 case ast .KindTypeAliasDeclaration , ast .KindJSTypeAliasDeclaration :
688690 b .bindBlockScopedDeclaration (node , ast .SymbolFlagsTypeAlias , ast .SymbolFlagsTypeAliasExcludes )
689691 case ast .KindEnumDeclaration :
@@ -910,16 +912,24 @@ func (b *Binder) bindFunctionExpression(node *ast.Node) {
910912}
911913
912914func (b * Binder ) bindCallExpression (node * ast.Node ) {
913- // !!! for ModuleDetectionKind.Force, external module indicator is forced to `true` in Strada for source files, in which case
914- // we should set the commonjs module indicator but not call b.bindSourceFileAsExternalModule
915- // !!! && file.externalModuleIndicator !== true (used for ModuleDetectionKind.Force)
916- if ast .IsInJSFile (node ) &&
917- b .file .ExternalModuleIndicator == nil &&
918- b .file .CommonJSModuleIndicator == nil &&
919- ast .IsRequireCall (node , false /*requireStringLiteralLikeArgument*/ ) {
915+ // We're only inspecting call expressions to detect CommonJS modules, so we can skip
916+ // this check if we've already seen the module indicator
917+ if b .file .CommonJSModuleIndicator == nil && ast .IsRequireCall (node , false /*requireStringLiteralLikeArgument*/ ) {
918+ b .setCommonJSModuleIndicator (node )
919+ }
920+ }
921+
922+ func (b * Binder ) setCommonJSModuleIndicator (node * ast.Node ) bool {
923+ if b .file .ExternalModuleIndicator != nil && b .file .ExternalModuleIndicator != b .file .AsNode () {
924+ return false
925+ }
926+ if b .file .CommonJSModuleIndicator == nil {
920927 b .file .CommonJSModuleIndicator = node
921- b .bindSourceFileAsExternalModule ()
928+ if b .file .ExternalModuleIndicator == nil {
929+ b .bindSourceFileAsExternalModule ()
930+ }
922931 }
932+ return true
923933}
924934
925935func (b * Binder ) bindClassLikeDeclaration (node * ast.Node ) {
0 commit comments