Skip to content

Commit 2f16c3c

Browse files
authored
Fix canHaveSyntheticDefault (#2101)
1 parent c9d2894 commit 2f16c3c

File tree

32 files changed

+41
-258
lines changed

32 files changed

+41
-258
lines changed

internal/ast/ast.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10757,7 +10757,9 @@ type SourceFile struct {
1075710757
NodeCount int
1075810758
TextCount int
1075910759
CommonJSModuleIndicator *Node
10760-
ExternalModuleIndicator *Node
10760+
// If this is the SourceFile itself, then this module was "forced"
10761+
// to be an external module (previously "true").
10762+
ExternalModuleIndicator *Node
1076110763

1076210764
// Fields set by binder
1076310765

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14440,7 +14440,7 @@ func (c *Checker) canHaveSyntheticDefault(file *ast.Node, moduleSymbol *ast.Symb
1444014440
}
1444114441

1444214442
// 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
14443-
return !ast.IsExternalModule(file.AsSourceFile()) && c.resolveExportByName(moduleSymbol, "__esModule", nil /*sourceNode*/, dontResolveAlias) == nil
14443+
return (file.AsSourceFile().ExternalModuleIndicator == nil || file.AsSourceFile().ExternalModuleIndicator == file) && c.resolveExportByName(moduleSymbol, "__esModule", nil /*sourceNode*/, dontResolveAlias) == nil
1444414444
}
1444514445

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

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node16).errors.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node16).errors.txt.diff

Lines changed: 0 additions & 14 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node16).symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ import foo from "./foo.cjs"
1111
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
1212

1313
foo.foo;
14+
>foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
1415
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
16+
>foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
1517

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node16).symbols.diff

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,4 @@
88
+>exports : Symbol("foo", Decl(foo.cjs, 0, 0))
99
>foo : Symbol(foo, Decl(foo.cjs, 0, 0))
1010

11-
=== bar.ts ===
12-
@@= skipped -8, +8 lines =@@
13-
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
14-
15-
foo.foo;
16-
->foo.foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
17-
>foo : Symbol(foo, Decl(bar.ts, 0, 6))
18-
->foo : Symbol(foo.foo, Decl(foo.cjs, 0, 0))
11+
=== bar.ts ===

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node16).types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ exports.foo = "foo"
1010

1111
=== bar.ts ===
1212
import foo from "./foo.cjs"
13-
>foo : any
13+
>foo : typeof foo
1414

1515
foo.foo;
16-
>foo.foo : any
17-
>foo : any
18-
>foo : any
16+
>foo.foo : "foo"
17+
>foo : typeof foo
18+
>foo : "foo"
1919

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node16).types.diff

Lines changed: 0 additions & 16 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node18).errors.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsCjsFromJs(module=node18).errors.txt.diff

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)