Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -10757,7 +10757,9 @@ type SourceFile struct {
NodeCount int
TextCount int
CommonJSModuleIndicator *Node
ExternalModuleIndicator *Node
// If this is the SourceFile itself, then this module was "forced"
// to be an external module (previously "true").
ExternalModuleIndicator *Node

// Fields set by binder

Expand Down
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14440,7 +14440,7 @@ func (c *Checker) canHaveSyntheticDefault(file *ast.Node, moduleSymbol *ast.Symb
}

// JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker
return !ast.IsExternalModule(file.AsSourceFile()) && c.resolveExportByName(moduleSymbol, "__esModule", nil /*sourceNode*/, dontResolveAlias) == nil
return (file.AsSourceFile().ExternalModuleIndicator == nil || file.AsSourceFile().ExternalModuleIndicator == file) && c.resolveExportByName(moduleSymbol, "__esModule", nil /*sourceNode*/, dontResolveAlias) == nil
}

func (c *Checker) getEmitSyntaxForModuleSpecifierExpression(usage *ast.Node) core.ResolutionMode {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ import foo from "./foo.cjs"
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
>foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
>foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,4 @@
+>exports : Symbol("foo", Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(foo.cjs, 0, 0))

=== bar.ts ===
@@= skipped -8, +8 lines =@@
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
->foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
->foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
=== bar.ts ===
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ exports.foo = "foo"

=== bar.ts ===
import foo from "./foo.cjs"
>foo : any
>foo : typeof foo

foo.foo;
>foo.foo : any
>foo : any
>foo : any
>foo.foo : "foo"
>foo : typeof foo
>foo : "foo"

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ import foo from "./foo.cjs"
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
>foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
>foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,4 @@
+>exports : Symbol("foo", Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(foo.cjs, 0, 0))

=== bar.ts ===
@@= skipped -8, +8 lines =@@
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
->foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
->foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
=== bar.ts ===
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ exports.foo = "foo"

=== bar.ts ===
import foo from "./foo.cjs"
>foo : any
>foo : typeof foo

foo.foo;
>foo.foo : any
>foo : any
>foo : any
>foo.foo : "foo"
>foo : typeof foo
>foo : "foo"

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ import foo from "./foo.cjs"
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
>foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
>foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,4 @@
+>exports : Symbol("foo", Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(foo.cjs, 0, 0))

=== bar.ts ===
@@= skipped -8, +8 lines =@@
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
->foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
->foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
=== bar.ts ===
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ exports.foo = "foo"

=== bar.ts ===
import foo from "./foo.cjs"
>foo : any
>foo : typeof foo

foo.foo;
>foo.foo : any
>foo : any
>foo : any
>foo.foo : "foo"
>foo : typeof foo
>foo : "foo"

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ import foo from "./foo.cjs"
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
>foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
>foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,4 @@
+>exports : Symbol("foo", Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(foo.cjs, 0, 0))

=== bar.ts ===
@@= skipped -8, +8 lines =@@
>foo : Symbol(foo, Decl(bar.ts, 0, 6))

foo.foo;
->foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
->foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
=== bar.ts ===
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ exports.foo = "foo"

=== bar.ts ===
import foo from "./foo.cjs"
>foo : any
>foo : typeof foo

foo.foo;
>foo.foo : any
>foo : any
>foo : any
>foo.foo : "foo"
>foo : typeof foo
>foo : "foo"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/5.cjs(1,8): error TS1192: Module '"/2"' has no default export.
/5.cjs(2,8): error TS1192: Module '"/3"' has no default export.


Expand All @@ -15,10 +14,8 @@
==== /4.cjs (0 errors) ====
;

==== /5.cjs (2 errors) ====
==== /5.cjs (1 errors) ====
import two from "./2.cjs"; // ok
~~~
!!! error TS1192: Module '"/2"' has no default export.
import three from "./3.cjs"; // error
~~~~~
!!! error TS1192: Module '"/3"' has no default export.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
+++ new.nodeModulesCJSEmit1(module=node18).errors.txt
@@= skipped -0, +0 lines =@@
-/3.cjs(2,1): error TS2304: Cannot find name 'exports'.
+/5.cjs(1,8): error TS1192: Module '"/2"' has no default export.
/5.cjs(2,8): error TS1192: Module '"/3"' has no default export.


@@= skipped -7, +7 lines =@@
@@= skipped -7, +6 lines =@@
==== /2.cjs (0 errors) ====
exports.foo = 0;

Expand All @@ -18,13 +17,4 @@
-!!! error TS2304: Cannot find name 'exports'.

==== /4.cjs (0 errors) ====
;

-==== /5.cjs (1 errors) ====
+==== /5.cjs (2 errors) ====
import two from "./2.cjs"; // ok
+ ~~~
+!!! error TS1192: Module '"/2"' has no default export.
import three from "./3.cjs"; // error
~~~~~
!!! error TS1192: Module '"/3"' has no default export.
;
Loading