Skip to content

Commit

Permalink
Recognize export * as default as a syntactic default export for syn…
Browse files Browse the repository at this point in the history
…thetic default detection (microsoft#55985)
  • Loading branch information
andrewbranch authored Oct 5, 2023
1 parent e9f68cb commit 21109b7
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4022,7 +4022,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function isSyntacticDefault(node: Node) {
return ((isExportAssignment(node) && !node.isExportEquals) || hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node));
return ((isExportAssignment(node) && !node.isExportEquals)
|| hasSyntacticModifier(node, ModifierFlags.Default)
|| isExportSpecifier(node)
|| isNamespaceExport(node));
}

function getUsageModeForExpression(usage: Expression) {
Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/exportAsNamespace5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/conformance/es2020/modules/exportAsNamespace5.ts] ////

//// [three.d.ts]
export type Named = 0;
declare const Named: 0;

//// [two.d.ts]
export * as default from "./three";

//// [one.ts]
import ns from "./two";
type Alias = ns.Named;
ns.Named;


//// [one.js]
import ns from "./two";
ns.Named;
27 changes: 27 additions & 0 deletions tests/baselines/reference/exportAsNamespace5.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [tests/cases/conformance/es2020/modules/exportAsNamespace5.ts] ////

=== three.d.ts ===
export type Named = 0;
>Named : Symbol(Named, Decl(three.d.ts, 0, 0), Decl(three.d.ts, 1, 13))

declare const Named: 0;
>Named : Symbol(Named, Decl(three.d.ts, 0, 0), Decl(three.d.ts, 1, 13))

=== two.d.ts ===
export * as default from "./three";
>default : Symbol(default, Decl(two.d.ts, 0, 6))

=== one.ts ===
import ns from "./two";
>ns : Symbol(ns, Decl(one.ts, 0, 6))

type Alias = ns.Named;
>Alias : Symbol(Alias, Decl(one.ts, 0, 23))
>ns : Symbol(ns, Decl(one.ts, 0, 6))
>Named : Symbol(ns.Named, Decl(three.d.ts, 0, 0), Decl(three.d.ts, 1, 13))

ns.Named;
>ns.Named : Symbol(ns.Named, Decl(three.d.ts, 0, 0), Decl(three.d.ts, 1, 13))
>ns : Symbol(ns, Decl(one.ts, 0, 6))
>Named : Symbol(ns.Named, Decl(three.d.ts, 0, 0), Decl(three.d.ts, 1, 13))

26 changes: 26 additions & 0 deletions tests/baselines/reference/exportAsNamespace5.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [tests/cases/conformance/es2020/modules/exportAsNamespace5.ts] ////

=== three.d.ts ===
export type Named = 0;
>Named : 0

declare const Named: 0;
>Named : 0

=== two.d.ts ===
export * as default from "./three";
>default : typeof import("three")

=== one.ts ===
import ns from "./two";
>ns : typeof ns

type Alias = ns.Named;
>Alias : 0
>ns : any

ns.Named;
>ns.Named : 0
>ns : typeof ns
>Named : 0

14 changes: 14 additions & 0 deletions tests/cases/conformance/es2020/modules/exportAsNamespace5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @module: esnext
// @moduleResolution: bundler

// @filename: three.d.ts
export type Named = 0;
declare const Named: 0;

// @filename: two.d.ts
export * as default from "./three";

// @filename: one.ts
import ns from "./two";
type Alias = ns.Named;
ns.Named;

0 comments on commit 21109b7

Please sign in to comment.