mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Ensure moduleType is structured during cloneTypeAsModuleType (#51136)
This commit is contained in:
parent
074bf34633
commit
dfa30bbe2a
@ -5156,7 +5156,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
getPropertyOfType(type, InternalSymbolName.Default, /*skipObjectFunctionPropertyAugment*/ true) ||
|
||||
isEsmCjsRef
|
||||
) {
|
||||
const moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol!, reference);
|
||||
const moduleType = type.flags & TypeFlags.StructuredType
|
||||
? getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol!, reference)
|
||||
: createDefaultPropertyWrapperForModule(symbol, symbol.parent);
|
||||
return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
|
||||
}
|
||||
}
|
||||
@ -34177,7 +34179,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return createPromiseReturnType(node, anyType);
|
||||
}
|
||||
|
||||
function createDefaultPropertyWrapperForModule(symbol: Symbol, originalSymbol: Symbol, anonymousSymbol?: Symbol | undefined) {
|
||||
function createDefaultPropertyWrapperForModule(symbol: Symbol, originalSymbol: Symbol | undefined, anonymousSymbol?: Symbol | undefined) {
|
||||
const memberTable = createSymbolTable();
|
||||
const newSymbol = createSymbol(SymbolFlags.Alias, InternalSymbolName.Default);
|
||||
newSymbol.parent = originalSymbol;
|
||||
|
||||
37
tests/baselines/reference/moduleExportNonStructured.js
Normal file
37
tests/baselines/reference/moduleExportNonStructured.js
Normal file
@ -0,0 +1,37 @@
|
||||
//// [tests/cases/compiler/moduleExportNonStructured.ts] ////
|
||||
|
||||
//// [package.json]
|
||||
{
|
||||
"name": "test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"module": "index.mjs"
|
||||
}
|
||||
|
||||
//// [index.mts]
|
||||
import * as exportAny from "./exportAny.cjs";
|
||||
import * as exportUnknown from "./exportUnknown.cjs";
|
||||
import * as exportSymbol from "./exportSymbol.cjs";
|
||||
|
||||
import type * as exportAnyType from "./exportAny.cjs";
|
||||
import type * as exportUnknownType from "./exportUnknown.cjs";
|
||||
import type * as exportSymbolType from "./exportSymbol.cjs";
|
||||
|
||||
//// [exportAny.d.cts]
|
||||
declare const __: any;
|
||||
export = __;
|
||||
|
||||
|
||||
//// [exportUnknown.d.cts]
|
||||
declare const __: unknown;
|
||||
export = __;
|
||||
|
||||
|
||||
//// [exportSymbol.d.cts]
|
||||
declare const __: symbol;
|
||||
export = __;
|
||||
|
||||
|
||||
//// [index.mjs]
|
||||
export {};
|
||||
42
tests/baselines/reference/moduleExportNonStructured.symbols
Normal file
42
tests/baselines/reference/moduleExportNonStructured.symbols
Normal file
@ -0,0 +1,42 @@
|
||||
=== tests/cases/compiler/index.mts ===
|
||||
import * as exportAny from "./exportAny.cjs";
|
||||
>exportAny : Symbol(exportAny, Decl(index.mts, 0, 6))
|
||||
|
||||
import * as exportUnknown from "./exportUnknown.cjs";
|
||||
>exportUnknown : Symbol(exportUnknown, Decl(index.mts, 1, 6))
|
||||
|
||||
import * as exportSymbol from "./exportSymbol.cjs";
|
||||
>exportSymbol : Symbol(exportSymbol, Decl(index.mts, 2, 6))
|
||||
|
||||
import type * as exportAnyType from "./exportAny.cjs";
|
||||
>exportAnyType : Symbol(exportAnyType, Decl(index.mts, 4, 11))
|
||||
|
||||
import type * as exportUnknownType from "./exportUnknown.cjs";
|
||||
>exportUnknownType : Symbol(exportUnknownType, Decl(index.mts, 5, 11))
|
||||
|
||||
import type * as exportSymbolType from "./exportSymbol.cjs";
|
||||
>exportSymbolType : Symbol(exportSymbolType, Decl(index.mts, 6, 11))
|
||||
|
||||
=== tests/cases/compiler/exportAny.d.cts ===
|
||||
declare const __: any;
|
||||
>__ : Symbol(__, Decl(exportAny.d.cts, 0, 13))
|
||||
|
||||
export = __;
|
||||
>__ : Symbol(__, Decl(exportAny.d.cts, 0, 13))
|
||||
|
||||
|
||||
=== tests/cases/compiler/exportUnknown.d.cts ===
|
||||
declare const __: unknown;
|
||||
>__ : Symbol(__, Decl(exportUnknown.d.cts, 0, 13))
|
||||
|
||||
export = __;
|
||||
>__ : Symbol(__, Decl(exportUnknown.d.cts, 0, 13))
|
||||
|
||||
|
||||
=== tests/cases/compiler/exportSymbol.d.cts ===
|
||||
declare const __: symbol;
|
||||
>__ : Symbol(__, Decl(exportSymbol.d.cts, 0, 13))
|
||||
|
||||
export = __;
|
||||
>__ : Symbol(__, Decl(exportSymbol.d.cts, 0, 13))
|
||||
|
||||
42
tests/baselines/reference/moduleExportNonStructured.types
Normal file
42
tests/baselines/reference/moduleExportNonStructured.types
Normal file
@ -0,0 +1,42 @@
|
||||
=== tests/cases/compiler/index.mts ===
|
||||
import * as exportAny from "./exportAny.cjs";
|
||||
>exportAny : { default: any; }
|
||||
|
||||
import * as exportUnknown from "./exportUnknown.cjs";
|
||||
>exportUnknown : { default: unknown; }
|
||||
|
||||
import * as exportSymbol from "./exportSymbol.cjs";
|
||||
>exportSymbol : { default: symbol; }
|
||||
|
||||
import type * as exportAnyType from "./exportAny.cjs";
|
||||
>exportAnyType : { default: any; }
|
||||
|
||||
import type * as exportUnknownType from "./exportUnknown.cjs";
|
||||
>exportUnknownType : { default: unknown; }
|
||||
|
||||
import type * as exportSymbolType from "./exportSymbol.cjs";
|
||||
>exportSymbolType : { default: symbol; }
|
||||
|
||||
=== tests/cases/compiler/exportAny.d.cts ===
|
||||
declare const __: any;
|
||||
>__ : any
|
||||
|
||||
export = __;
|
||||
>__ : any
|
||||
|
||||
|
||||
=== tests/cases/compiler/exportUnknown.d.cts ===
|
||||
declare const __: unknown;
|
||||
>__ : unknown
|
||||
|
||||
export = __;
|
||||
>__ : unknown
|
||||
|
||||
|
||||
=== tests/cases/compiler/exportSymbol.d.cts ===
|
||||
declare const __: symbol;
|
||||
>__ : symbol
|
||||
|
||||
export = __;
|
||||
>__ : symbol
|
||||
|
||||
36
tests/cases/compiler/moduleExportNonStructured.ts
Normal file
36
tests/cases/compiler/moduleExportNonStructured.ts
Normal file
@ -0,0 +1,36 @@
|
||||
// @target: ESNext
|
||||
// @module: ESNext
|
||||
// @moduleResolution: NodeNext
|
||||
// @strict: true
|
||||
|
||||
// @filename: package.json
|
||||
{
|
||||
"name": "test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"module": "index.mjs"
|
||||
}
|
||||
|
||||
// @filename: index.mts
|
||||
import * as exportAny from "./exportAny.cjs";
|
||||
import * as exportUnknown from "./exportUnknown.cjs";
|
||||
import * as exportSymbol from "./exportSymbol.cjs";
|
||||
|
||||
import type * as exportAnyType from "./exportAny.cjs";
|
||||
import type * as exportUnknownType from "./exportUnknown.cjs";
|
||||
import type * as exportSymbolType from "./exportSymbol.cjs";
|
||||
|
||||
// @filename: exportAny.d.cts
|
||||
declare const __: any;
|
||||
export = __;
|
||||
|
||||
|
||||
// @filename: exportUnknown.d.cts
|
||||
declare const __: unknown;
|
||||
export = __;
|
||||
|
||||
|
||||
// @filename: exportSymbol.d.cts
|
||||
declare const __: symbol;
|
||||
export = __;
|
||||
Loading…
x
Reference in New Issue
Block a user