Skip to content

Commit 4d07d5f

Browse files
committed
Update baselines
1 parent df44987 commit 4d07d5f

8 files changed

+48
-31
lines changed

src/compiler/checker.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27052705
return symbol;
27062706
}
27072707
if (symbol.flags & SymbolFlags.Alias) {
2708-
const targetFlags = getAllSymbolFlags(symbol);
2708+
const targetFlags = getSymbolFlags(symbol);
27092709
// `targetFlags` will be `SymbolFlags.All` if an error occurred in alias resolution; this avoids cascading errors
27102710
if (targetFlags & meaning) {
27112711
return symbol;
@@ -3724,7 +3724,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37243724
return true;
37253725
}
37263726
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
3727-
const allFlags = symbol && getAllSymbolFlags(symbol);
3727+
const allFlags = symbol && getSymbolFlags(symbol);
37283728
if (symbol && allFlags !== undefined && !(allFlags & SymbolFlags.Value)) {
37293729
const rawName = unescapeLeadingUnderscores(name);
37303730
if (isES2015OrLaterConstructorName(name)) {
@@ -4457,14 +4457,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
44574457
* @returns SymbolFlags.All if `symbol` is an alias that ultimately resolves to `unknown`;
44584458
* combined flags of all alias targets otherwise.
44594459
*/
4460-
function getAllSymbolFlags(symbol: Symbol, excludeTypeOnlyMeanings?: boolean): SymbolFlags {
4460+
function getSymbolFlags(symbol: Symbol, excludeTypeOnlyMeanings?: boolean, excludeLocalMeanings?: boolean): SymbolFlags {
44614461
const typeOnlyDeclaration = excludeTypeOnlyMeanings && getTypeOnlyAliasDeclaration(symbol);
4462-
const typeOnlyResolution = typeOnlyDeclaration && resolveAlias(typeOnlyDeclaration.symbol);
4463-
let flags = symbol.flags;
4462+
const typeOnlyDeclarationIsExportStar = typeOnlyDeclaration && isExportDeclaration(typeOnlyDeclaration);
4463+
const typeOnlyResolution = typeOnlyDeclaration && (
4464+
typeOnlyDeclarationIsExportStar
4465+
? resolveExternalModuleName(typeOnlyDeclaration.moduleSpecifier, typeOnlyDeclaration.moduleSpecifier, /*ignoreErrors*/ true)
4466+
: resolveAlias(typeOnlyDeclaration.symbol));
4467+
const typeOnlyExportStarTargets = typeOnlyDeclarationIsExportStar && typeOnlyResolution ? getExportsOfModule(typeOnlyResolution) : undefined;
4468+
let flags = excludeLocalMeanings ? SymbolFlags.None : symbol.flags;
44644469
let seenSymbols;
44654470
while (symbol.flags & SymbolFlags.Alias) {
4466-
const target = resolveAlias(symbol);
4467-
if (target === typeOnlyResolution) {
4471+
const target = getExportSymbolOfValueSymbolIfExported(resolveAlias(symbol));
4472+
if (!typeOnlyDeclarationIsExportStar && target === typeOnlyResolution ||
4473+
typeOnlyExportStarTargets?.get(target.escapedName) === target
4474+
) {
44684475
break;
44694476
}
44704477
if (target === unknownSymbol) {
@@ -4515,7 +4522,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45154522
immediateTarget: Symbol | undefined,
45164523
finalTarget: Symbol | undefined,
45174524
overwriteEmpty: boolean,
4518-
exportStarDeclaration?: ExportDeclaration & { readonly isTypeOnly: true },
4525+
exportStarDeclaration?: ExportDeclaration & { readonly isTypeOnly: true, readonly moduleSpecifier: Expression },
45194526
exportStarName?: __String,
45204527
): boolean {
45214528
if (!aliasDeclaration || isPropertyAccessExpression(aliasDeclaration)) return false;
@@ -4564,7 +4571,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45644571
const resolved = links.typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration
45654572
? resolveSymbol(getExportsOfModule(links.typeOnlyDeclaration.symbol.parent!).get(links.typeOnlyExportStarName || symbol.escapedName))!
45664573
: resolveAlias(links.typeOnlyDeclaration.symbol);
4567-
return getAllSymbolFlags(resolved) & include ? links.typeOnlyDeclaration : undefined;
4574+
return getSymbolFlags(resolved) & include ? links.typeOnlyDeclaration : undefined;
45684575
}
45694576
return undefined;
45704577
}
@@ -4577,7 +4584,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45774584
const target = resolveAlias(symbol);
45784585
if (target) {
45794586
const markAlias = target === unknownSymbol ||
4580-
((getAllSymbolFlags(target, /*excludeTypeOnlyMeanings*/ true) & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
4587+
((getSymbolFlags(symbol, /*excludeTypeOnlyMeanings*/ true) & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
45814588

45824589
if (markAlias) {
45834590
markAliasSymbolAsReferenced(symbol);
@@ -4599,7 +4606,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
45994606
// This way a chain of imports can be elided if ultimately the final input is only used in a type
46004607
// position.
46014608
if (isInternalModuleImportEqualsDeclaration(node)) {
4602-
if (getAllSymbolFlags(resolveSymbol(symbol)) & SymbolFlags.Value) {
4609+
if (getSymbolFlags(resolveSymbol(symbol)) & SymbolFlags.Value) {
46034610
// import foo = <symbol>
46044611
checkExpressionCached(node.moduleReference as Expression);
46054612
}
@@ -5314,7 +5321,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
53145321

53155322
function getExportsOfModuleWorker(moduleSymbol: Symbol) {
53165323
const visitedSymbols: Symbol[] = [];
5317-
let typeOnlyExportStarMap: Map<__String, ExportDeclaration & { readonly isTypeOnly: true }> | undefined;
5324+
let typeOnlyExportStarMap: Map<__String, ExportDeclaration & { readonly isTypeOnly: true, readonly moduleSpecifier: Expression }> | undefined;
53185325
const nonTypeOnlyNames = new Set<__String>();
53195326

53205327
// A module defined by an 'export=' consists of one export that needs to be resolved
@@ -5381,7 +5388,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
53815388
typeOnlyExportStarMap ??= new Map();
53825389
symbols.forEach((_, escapedName) => typeOnlyExportStarMap!.set(
53835390
escapedName,
5384-
exportStar as ExportDeclaration & { readonly isTypeOnly: true }));
5391+
exportStar as ExportDeclaration & { readonly isTypeOnly: true, readonly moduleSpecifier: Expression }));
53855392
}
53865393
return symbols;
53875394
}
@@ -5572,7 +5579,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
55725579
function symbolIsValue(symbol: Symbol, includeTypeOnlyMembers?: boolean): boolean {
55735580
return !!(
55745581
symbol.flags & SymbolFlags.Value ||
5575-
symbol.flags & SymbolFlags.Alias && getAllSymbolFlags(symbol, !includeTypeOnlyMembers) & SymbolFlags.Value);
5582+
symbol.flags & SymbolFlags.Alias && getSymbolFlags(symbol, !includeTypeOnlyMembers) & SymbolFlags.Value);
55765583
}
55775584

55785585
function findConstructorDeclaration(node: ClassLikeDeclaration): ConstructorDeclaration | undefined {
@@ -5871,7 +5878,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
58715878
// Qualify if the symbol from symbol table has same meaning as expected
58725879
const shouldResolveAlias = (symbolFromSymbolTable.flags & SymbolFlags.Alias && !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier));
58735880
symbolFromSymbolTable = shouldResolveAlias ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
5874-
const flags = shouldResolveAlias ? getAllSymbolFlags(symbolFromSymbolTable) : symbolFromSymbolTable.flags;
5881+
const flags = shouldResolveAlias ? getSymbolFlags(symbolFromSymbolTable) : symbolFromSymbolTable.flags;
58755882
if (flags & meaning) {
58765883
qualify = true;
58775884
return true;
@@ -8910,7 +8917,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
89108917
}
89118918

89128919
function isTypeOnlyNamespace(symbol: Symbol) {
8913-
return every(getNamespaceMembersForSerialization(symbol), m => !(getAllSymbolFlags(resolveSymbol(m)) & SymbolFlags.Value));
8920+
return every(getNamespaceMembersForSerialization(symbol), m => !(getSymbolFlags(resolveSymbol(m)) & SymbolFlags.Value));
89148921
}
89158922

89168923
function serializeModule(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) {
@@ -11421,7 +11428,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1142111428
links.type = exportSymbol?.declarations && isDuplicatedCommonJSExport(exportSymbol.declarations) && symbol.declarations!.length ? getFlowTypeFromCommonJSExport(exportSymbol)
1142211429
: isDuplicatedCommonJSExport(symbol.declarations) ? autoType
1142311430
: declaredType ? declaredType
11424-
: getAllSymbolFlags(targetSymbol) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
11431+
: getSymbolFlags(targetSymbol) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
1142511432
: errorType;
1142611433
}
1142711434
return links.type;
@@ -27815,7 +27822,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2781527822
}
2781627823
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location)) {
2781727824
const target = resolveAlias(symbol);
27818-
if (getAllSymbolFlags(target, /*excludeTypeOnlyMeanings*/ true) & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
27825+
if (getSymbolFlags(symbol, /*excludeTypeOnlyMeanings*/ true) & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
2781927826
// An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
2782027827
// (because the const enum value will not be inlined), or if (2) the alias is an export
2782127828
// of a const enum declaration that will be preserved.
@@ -44240,7 +44247,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4424044247
return;
4424144248
}
4424244249

44243-
const targetFlags = getAllSymbolFlags(target);
44250+
const targetFlags = getSymbolFlags(target);
4424444251
const excludedMeanings =
4424544252
(symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) |
4424644253
(symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) |
@@ -44442,7 +44449,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4444244449
if (node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) {
4444344450
const target = resolveAlias(getSymbolOfDeclaration(node));
4444444451
if (target !== unknownSymbol) {
44445-
const targetFlags = getAllSymbolFlags(target);
44452+
const targetFlags = getSymbolFlags(target);
4444644453
if (targetFlags & SymbolFlags.Value) {
4444744454
// Target is a value symbol, check that it is not hidden by a local declaration with the same name
4444844455
const moduleName = getFirstIdentifier(node.moduleReference);
@@ -44599,7 +44606,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4459944606
markExportAsReferenced(node);
4460044607
}
4460144608
const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
44602-
if (!target || getAllSymbolFlags(target) & SymbolFlags.Value) {
44609+
if (!target || getSymbolFlags(target) & SymbolFlags.Value) {
4460344610
checkExpressionCached(node.propertyName || node.name);
4460444611
}
4460544612
}
@@ -44655,7 +44662,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4465544662
if (sym) {
4465644663
markAliasReferenced(sym, id);
4465744664
// If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
44658-
if (getAllSymbolFlags(sym) & SymbolFlags.Value) {
44665+
if (getSymbolFlags(sym) & SymbolFlags.Value) {
4465944666
// However if it is a value, we need to check it's being used correctly
4466044667
checkExpressionCached(id);
4466144668
if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) {
@@ -46162,7 +46169,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4616246169

4616346170
function isValue(s: Symbol): boolean {
4616446171
s = resolveSymbol(s);
46165-
return s && !!(getAllSymbolFlags(s) & SymbolFlags.Value);
46172+
return s && !!(getSymbolFlags(s) & SymbolFlags.Value);
4616646173
}
4616746174
}
4616846175

@@ -46353,7 +46360,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4635346360
}
4635446361
// const enums and modules that contain only const enums are not considered values from the emit perspective
4635546362
// unless 'preserveConstEnums' option is set to true
46356-
return !!((getAllSymbolFlags(target, excludeTypeOnlyValues) ?? -1) & SymbolFlags.Value) &&
46363+
return !!(getSymbolFlags(symbol, excludeTypeOnlyValues, /*excludeLocalMeanings*/ true) & SymbolFlags.Value) &&
4635746364
(shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target));
4635846365
}
4635946366

@@ -46371,7 +46378,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4637146378
}
4637246379
const target = getSymbolLinks(symbol).aliasTarget;
4637346380
if (target && getEffectiveModifierFlags(node) & ModifierFlags.Export &&
46374-
getAllSymbolFlags(target) & SymbolFlags.Value &&
46381+
getSymbolFlags(target) & SymbolFlags.Value &&
4637546382
(shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target))) {
4637646383
// An `export import ... =` of a value symbol is always considered referenced
4637746384
return true;

src/compiler/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,8 +3814,8 @@ export type TypeOnlyImportDeclaration =
38143814

38153815
export type TypeOnlyExportDeclaration =
38163816
| ExportSpecifier & ({ readonly isTypeOnly: true } | { readonly parent: NamedExports & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true } } })
3817-
| ExportDeclaration & { readonly isTypeOnly: true } // export * from "mod"
3818-
| NamespaceExport & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true } } // export * as ns from "mod"
3817+
| ExportDeclaration & { readonly isTypeOnly: true, readonly moduleSpecifier: Expression } // export * from "mod"
3818+
| NamespaceExport & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true, readonly moduleSpecifier: Expression } } // export * as ns from "mod"
38193819
;
38203820

38213821
export type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration;
@@ -5878,7 +5878,7 @@ export interface SymbolLinks {
58785878
deferralParent?: Type; // Source union/intersection of a deferred type
58795879
cjsExportMerged?: Symbol; // Version of the symbol with all non export= exports merged with the export= target
58805880
typeOnlyDeclaration?: TypeOnlyAliasDeclaration | false; // First resolved alias declaration that makes the symbol only usable in type constructs
5881-
typeOnlyExportStarMap?: Map<__String, ExportDeclaration & { readonly isTypeOnly: true }>; // Set on a module symbol when some of its exports were resolved through a 'export type * from "mod"' declaration
5881+
typeOnlyExportStarMap?: Map<__String, ExportDeclaration & { readonly isTypeOnly: true, readonly moduleSpecifier: Expression }>; // Set on a module symbol when some of its exports were resolved through a 'export type * from "mod"' declaration
58825882
typeOnlyExportStarName?: __String; // Set to the name of the symbol re-exported by an 'export type *' declaration, when different from the symbol name
58835883
isConstructorDeclaredProperty?: boolean; // Property declared through 'this.x = ...' assignment in constructor
58845884
tupleLabelDeclaration?: NamedTupleMember | ParameterDeclaration; // Declaration associated with the tuple's label

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5827,9 +5827,11 @@ declare namespace ts {
58275827
};
58285828
}) | ExportDeclaration & {
58295829
readonly isTypeOnly: true;
5830+
readonly moduleSpecifier: Expression;
58305831
} | NamespaceExport & {
58315832
readonly parent: ExportDeclaration & {
58325833
readonly isTypeOnly: true;
5834+
readonly moduleSpecifier: Expression;
58335835
};
58345836
};
58355837
type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,9 +1774,11 @@ declare namespace ts {
17741774
};
17751775
}) | ExportDeclaration & {
17761776
readonly isTypeOnly: true;
1777+
readonly moduleSpecifier: Expression;
17771778
} | NamespaceExport & {
17781779
readonly parent: ExportDeclaration & {
17791780
readonly isTypeOnly: true;
1781+
readonly moduleSpecifier: Expression;
17801782
};
17811783
};
17821784
type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration;

tests/baselines/reference/importElisionExportNonExportAndDefault.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import MyFunction from "./MyComponent";
55
>MyFunction : Symbol(MyFunction, Decl(main.ts, 0, 6))
66

77
MyFunction({msg: "Hello World"});
8+
>MyFunction : Symbol(MyFunction, Decl(main.ts, 0, 6))
89
>msg : Symbol(msg, Decl(main.ts, 2, 12))
910

1011

tests/baselines/reference/importEquals3.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ exports.A = A;
3333
//// [b.js]
3434
"use strict";
3535
Object.defineProperty(exports, "__esModule", { value: true });
36-
exports.x = void 0;
36+
exports.x = exports.A = void 0;
37+
var A = a.A; // Error
38+
exports.A = A;
3739
var x = 0;
3840
exports.x = x;
3941
//// [c.js]

tests/baselines/reference/namespaceImportTypeQuery3.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ let t: typeof types = {
1717
//// [a.js]
1818
"use strict";
1919
Object.defineProperty(exports, "__esModule", { value: true });
20-
exports.B = void 0;
20+
exports.B = exports.A = void 0;
2121
var A = 0;
22+
exports.A = A;
2223
var B = /** @class */ (function () {
2324
function B() {
2425
}

tests/baselines/reference/typeOnlyMerge3.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ function A() { }
2525
//// [b.js]
2626
"use strict";
2727
Object.defineProperty(exports, "__esModule", { value: true });
28+
exports.A = void 0;
2829
var A;
2930
(function (A) {
3031
A.displayName = "A";
31-
})(A || (A = {}));
32+
})(A || (exports.A = A = {}));
3233
//// [c.js]
3334
"use strict";
3435
Object.defineProperty(exports, "__esModule", { value: true });
36+
var b_1 = require("./b");
3537
A;
3638
A.displayName;
3739
A();

0 commit comments

Comments
 (0)