From a9f6ea6f2ded2fa69aabf573bbd9770c25d2dc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 13 Oct 2023 20:25:23 +0200 Subject: [PATCH 1/3] Emit declarations using alias chains --- src/compiler/checker.ts | 52 +++++-- .../declarationEmitUsingAliasSymbolChain1.js | 102 +++++++++++++ ...larationEmitUsingAliasSymbolChain1.symbols | 137 ++++++++++++++++++ ...eclarationEmitUsingAliasSymbolChain1.types | 103 +++++++++++++ .../declarationEmitUsingAliasSymbolChain1.ts | 65 +++++++++ 5 files changed, 443 insertions(+), 16 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js create mode 100644 tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols create mode 100644 tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.types create mode 100644 tests/cases/compiler/declarationEmitUsingAliasSymbolChain1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6098245cb6c67..a9bc3b54e12db 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5538,7 +5538,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (nodeIsSynthesized(importRef)) continue; // Synthetic names can't be resolved by `resolveExternalModuleName` - they'll cause a debug assert if they error const resolvedModule = resolveExternalModuleName(enclosingDeclaration, importRef, /*ignoreErrors*/ true); if (!resolvedModule) continue; - const ref = getAliasForSymbolInContainer(resolvedModule, symbol); + const ref = getAliasChainForSymbolInContainer(resolvedModule, symbol); if (!ref) continue; results = append(results, resolvedModule); } @@ -5555,7 +5555,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { for (const file of otherFiles) { if (!isExternalModule(file)) continue; const sym = getSymbolOfDeclaration(file); - const ref = getAliasForSymbolInContainer(sym, symbol); + const ref = getAliasChainForSymbolInContainer(sym, symbol); if (!ref) continue; results = append(results, sym); } @@ -5620,7 +5620,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!length(candidates)) { return undefined; } - return mapDefined(candidates, candidate => getAliasForSymbolInContainer(candidate, symbol) ? candidate : undefined); + return mapDefined(candidates, candidate => getAliasChainForSymbolInContainer(candidate, symbol) ? candidate : undefined); function fileSymbolIfFileSymbolExportEqualsContainer(d: Declaration) { return container && getFileSymbolIfFileSymbolExportEqualsContainer(d, container); @@ -5645,27 +5645,38 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return exported && getSymbolIfSameReference(exported, container) ? fileSymbol : undefined; } - function getAliasForSymbolInContainer(container: Symbol, symbol: Symbol) { + function getAliasChainForSymbolInContainer(container: Symbol, symbol: Symbol) { if (container === getParentOfSymbol(symbol)) { // fast path, `symbol` is either already the alias or isn't aliased - return symbol; + return [symbol]; } // Check if container is a thing with an `export=` which points directly at `symbol`, and if so, return // the container itself as the alias for the symbol const exportEquals = container.exports && container.exports.get(InternalSymbolName.ExportEquals); if (exportEquals && getSymbolIfSameReference(exportEquals, symbol)) { - return container; - } - const exports = getExportsOfSymbol(container); - const quick = exports.get(symbol.escapedName); - if (quick && getSymbolIfSameReference(quick, symbol)) { - return quick; + return [container]; } - return forEachEntry(exports, exported => { - if (getSymbolIfSameReference(exported, symbol)) { - return exported; + return getAliasChainRecursively(container); + + function getAliasChainRecursively(container: Symbol): Symbol[] | undefined { + const exports = getExportsOfSymbol(container); + const quick = exports.get(symbol.escapedName); + if (quick && getSymbolIfSameReference(quick, symbol)) { + return [quick]; } - }); + return forEachEntry(exports, exported => { + if (getSymbolIfSameReference(exported, symbol)) { + return [exported]; + } + if (exported.flags & SymbolFlags.Alias) { + const aliasChain = getAliasChainRecursively(resolveAlias(exported)); + if (aliasChain) { + aliasChain.unshift(exported); + return aliasChain; + } + } + }); + } } /** @@ -7792,7 +7803,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { accessibleSymbolChain = parentChain; break; } - accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); + if (accessibleSymbolChain) { + accessibleSymbolChain = parentChain.concat(accessibleSymbolChain); + break; + } + const aliasChain = getAliasChainForSymbolInContainer(parent, symbol); + if (aliasChain) { + accessibleSymbolChain = parentChain.concat(aliasChain); + break; + } + accessibleSymbolChain = parentChain.concat(symbol); break; } } diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js new file mode 100644 index 0000000000000..cf5783a7d6c12 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js @@ -0,0 +1,102 @@ +//// [tests/cases/compiler/declarationEmitUsingAliasSymbolChain1.ts] //// + +//// [Data.d.ts] +import type * as Types from "./Types.js"; +import type * as Equal from "./Equal.js"; + +export type Data> | ReadonlyArray> = + Readonly & Equal.Equal; + +export declare const TaggedClass: ( + tag: Key, +) => new >( + args: Types.Equals, {}> extends true + ? void + : Omit, +) => Data< + A & { + _tag: Key; + } +>; + +//// [Equal.d.ts] +import * as Hash from "./Hash.js"; + +export declare const symbol: unique symbol; + +export interface Equal extends Hash.Hash { + [symbol](that: Equal): boolean; +} + +//// [Hash.d.ts] +export declare const symbol: unique symbol; + +export interface Hash { + [symbol](): number; +} + +//// [Types.d.ts] +export type Equals = (() => T extends X ? 1 : 2) extends < + T, +>() => T extends Y ? 1 : 2 + ? true + : false; + +//// [index.d.ts] +export * as Data from "./Data.js"; +export * as Equal from "./Equal.js"; +export * as Types from "./Types.js"; + +//// [effect.cjs.d.ts] +export * from "./declarations/src/index"; + +//// [package.json] +{ + "name": "effect", + "exports": { + ".": "./dist/effect.cjs.js" + } +} + +//// [index.ts] +import { Data } from "effect"; +export class Foo extends Data.TaggedClass("Foo")<{}> {} + +//// [index.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Foo = void 0; +var effect_1 = require("effect"); +var Foo = /** @class */ (function (_super) { + __extends(Foo, _super); + function Foo() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Foo; +}(effect_1.Data.TaggedClass("Foo"))); +exports.Foo = Foo; + + +//// [index.d.ts] +import { Data } from "effect"; +declare const Foo_base: new >(args: import("effect").Types.Equals, {}> extends true ? void : Omit) => Data.Data; +export declare class Foo extends Foo_base<{}> { +} +export {}; diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols new file mode 100644 index 0000000000000..9dc541b9b13a7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols @@ -0,0 +1,137 @@ +//// [tests/cases/compiler/declarationEmitUsingAliasSymbolChain1.ts] //// + +=== node_modules/effect/dist/declarations/src/Data.d.ts === +import type * as Types from "./Types.js"; +>Types : Symbol(Types, Decl(Data.d.ts, 0, 11)) + +import type * as Equal from "./Equal.js"; +>Equal : Symbol(Equal, Decl(Data.d.ts, 1, 11)) + +export type Data> | ReadonlyArray> = +>Data : Symbol(Data, Decl(Data.d.ts, 1, 41)) +>A : Symbol(A, Decl(Data.d.ts, 3, 17)) +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --)) + + Readonly & Equal.Equal; +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>A : Symbol(A, Decl(Data.d.ts, 3, 17)) +>Equal : Symbol(Equal, Decl(Data.d.ts, 1, 11)) +>Equal : Symbol(Equal.Equal, Decl(Equal.d.ts, 2, 43)) + +export declare const TaggedClass: ( +>TaggedClass : Symbol(TaggedClass, Decl(Data.d.ts, 6, 20)) +>Key : Symbol(Key, Decl(Data.d.ts, 6, 35)) + + tag: Key, +>tag : Symbol(tag, Decl(Data.d.ts, 6, 55)) +>Key : Symbol(Key, Decl(Data.d.ts, 6, 35)) + +) => new >( +>A : Symbol(A, Decl(Data.d.ts, 8, 10)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + args: Types.Equals, {}> extends true +>args : Symbol(args, Decl(Data.d.ts, 8, 41)) +>Types : Symbol(Types, Decl(Data.d.ts, 0, 11)) +>Equals : Symbol(Types.Equals, Decl(Types.d.ts, 0, 0)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>A : Symbol(A, Decl(Data.d.ts, 8, 10)) +>Equal : Symbol(Equal, Decl(Data.d.ts, 1, 11)) +>Equal : Symbol(Equal.Equal, Decl(Equal.d.ts, 2, 43)) + + ? void + : Omit, +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>A : Symbol(A, Decl(Data.d.ts, 8, 10)) +>Equal : Symbol(Equal, Decl(Data.d.ts, 1, 11)) +>Equal : Symbol(Equal.Equal, Decl(Equal.d.ts, 2, 43)) + +) => Data< +>Data : Symbol(Data, Decl(Data.d.ts, 1, 41)) + + A & { +>A : Symbol(A, Decl(Data.d.ts, 8, 10)) + + _tag: Key; +>_tag : Symbol(_tag, Decl(Data.d.ts, 13, 7)) +>Key : Symbol(Key, Decl(Data.d.ts, 6, 35)) + } +>; + +=== node_modules/effect/dist/declarations/src/Equal.d.ts === +import * as Hash from "./Hash.js"; +>Hash : Symbol(Hash, Decl(Equal.d.ts, 0, 6)) + +export declare const symbol: unique symbol; +>symbol : Symbol(symbol, Decl(Equal.d.ts, 2, 20)) + +export interface Equal extends Hash.Hash { +>Equal : Symbol(Equal, Decl(Equal.d.ts, 2, 43)) +>Hash.Hash : Symbol(Hash.Hash, Decl(Hash.d.ts, 0, 43)) +>Hash : Symbol(Hash, Decl(Equal.d.ts, 0, 6)) +>Hash : Symbol(Hash.Hash, Decl(Hash.d.ts, 0, 43)) + + [symbol](that: Equal): boolean; +>[symbol] : Symbol(Equal[symbol], Decl(Equal.d.ts, 4, 42)) +>symbol : Symbol(symbol, Decl(Equal.d.ts, 2, 20)) +>that : Symbol(that, Decl(Equal.d.ts, 5, 11)) +>Equal : Symbol(Equal, Decl(Equal.d.ts, 2, 43)) +} + +=== node_modules/effect/dist/declarations/src/Hash.d.ts === +export declare const symbol: unique symbol; +>symbol : Symbol(symbol, Decl(Hash.d.ts, 0, 20)) + +export interface Hash { +>Hash : Symbol(Hash, Decl(Hash.d.ts, 0, 43)) + + [symbol](): number; +>[symbol] : Symbol(Hash[symbol], Decl(Hash.d.ts, 2, 23)) +>symbol : Symbol(symbol, Decl(Hash.d.ts, 0, 20)) +} + +=== node_modules/effect/dist/declarations/src/Types.d.ts === +export type Equals = (() => T extends X ? 1 : 2) extends < +>Equals : Symbol(Equals, Decl(Types.d.ts, 0, 0)) +>X : Symbol(X, Decl(Types.d.ts, 0, 19)) +>Y : Symbol(Y, Decl(Types.d.ts, 0, 21)) +>T : Symbol(T, Decl(Types.d.ts, 0, 29)) +>T : Symbol(T, Decl(Types.d.ts, 0, 29)) +>X : Symbol(X, Decl(Types.d.ts, 0, 19)) + + T, +>T : Symbol(T, Decl(Types.d.ts, 0, 67)) + +>() => T extends Y ? 1 : 2 +>T : Symbol(T, Decl(Types.d.ts, 0, 67)) +>Y : Symbol(Y, Decl(Types.d.ts, 0, 21)) + + ? true + : false; + +=== node_modules/effect/dist/declarations/src/index.d.ts === +export * as Data from "./Data.js"; +>Data : Symbol(Data, Decl(index.d.ts, 0, 6)) + +export * as Equal from "./Equal.js"; +>Equal : Symbol(Equal, Decl(index.d.ts, 1, 6)) + +export * as Types from "./Types.js"; +>Types : Symbol(Types, Decl(index.d.ts, 2, 6)) + +=== node_modules/effect/dist/effect.cjs.d.ts === + +export * from "./declarations/src/index"; + +=== src/index.ts === +import { Data } from "effect"; +>Data : Symbol(Data, Decl(index.ts, 0, 8)) + +export class Foo extends Data.TaggedClass("Foo")<{}> {} +>Foo : Symbol(Foo, Decl(index.ts, 0, 30)) +>Data.TaggedClass : Symbol(Data.TaggedClass, Decl(Data.d.ts, 6, 20)) +>Data : Symbol(Data, Decl(index.ts, 0, 8)) +>TaggedClass : Symbol(Data.TaggedClass, Decl(Data.d.ts, 6, 20)) + diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.types b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.types new file mode 100644 index 0000000000000..5901d3ee80585 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.types @@ -0,0 +1,103 @@ +//// [tests/cases/compiler/declarationEmitUsingAliasSymbolChain1.ts] //// + +=== node_modules/effect/dist/declarations/src/Data.d.ts === +import type * as Types from "./Types.js"; +>Types : typeof Types + +import type * as Equal from "./Equal.js"; +>Equal : typeof Equal + +export type Data> | ReadonlyArray> = +>Data : Data + + Readonly & Equal.Equal; +>Equal : any + +export declare const TaggedClass: ( +>TaggedClass : (tag: Key) => new >(args: Types.Equals, {}> extends true ? void : Omit) => Data + + tag: Key, +>tag : Key + +) => new >( + args: Types.Equals, {}> extends true +>args : Types.Equals, {}> extends true ? void : Omit +>Types : any +>Equal : any +>true : true + + ? void + : Omit, +>Equal : any + +) => Data< + A & { + _tag: Key; +>_tag : Key + } +>; + +=== node_modules/effect/dist/declarations/src/Equal.d.ts === +import * as Hash from "./Hash.js"; +>Hash : typeof Hash + +export declare const symbol: unique symbol; +>symbol : unique symbol + +export interface Equal extends Hash.Hash { +>Hash : typeof Hash + + [symbol](that: Equal): boolean; +>[symbol] : (that: Equal) => boolean +>symbol : unique symbol +>that : Equal +} + +=== node_modules/effect/dist/declarations/src/Hash.d.ts === +export declare const symbol: unique symbol; +>symbol : unique symbol + +export interface Hash { + [symbol](): number; +>[symbol] : () => number +>symbol : unique symbol +} + +=== node_modules/effect/dist/declarations/src/Types.d.ts === +export type Equals = (() => T extends X ? 1 : 2) extends < +>Equals : Equals + + T, +>() => T extends Y ? 1 : 2 + ? true +>true : true + + : false; +>false : false + +=== node_modules/effect/dist/declarations/src/index.d.ts === +export * as Data from "./Data.js"; +>Data : typeof import("node_modules/effect/dist/declarations/src/Data") + +export * as Equal from "./Equal.js"; +>Equal : typeof import("node_modules/effect/dist/declarations/src/Equal") + +export * as Types from "./Types.js"; +>Types : typeof import("node_modules/effect/dist/declarations/src/Types") + +=== node_modules/effect/dist/effect.cjs.d.ts === + +export * from "./declarations/src/index"; + +=== src/index.ts === +import { Data } from "effect"; +>Data : typeof Data + +export class Foo extends Data.TaggedClass("Foo")<{}> {} +>Foo : Foo +>Data.TaggedClass("Foo") : Data.Data<{ _tag: "Foo"; }> +>Data.TaggedClass : (tag: Key) => new >(args: import("node_modules/effect/dist/effect.cjs").Types.Equals, {}> extends true ? void : Omit) => Data.Data +>Data : typeof Data +>TaggedClass : (tag: Key) => new >(args: import("node_modules/effect/dist/effect.cjs").Types.Equals, {}> extends true ? void : Omit) => Data.Data +>"Foo" : "Foo" + diff --git a/tests/cases/compiler/declarationEmitUsingAliasSymbolChain1.ts b/tests/cases/compiler/declarationEmitUsingAliasSymbolChain1.ts new file mode 100644 index 0000000000000..0021df970f97f --- /dev/null +++ b/tests/cases/compiler/declarationEmitUsingAliasSymbolChain1.ts @@ -0,0 +1,65 @@ +// @strict: true +// @declaration: true +// @module: nodenext + +// @filename: node_modules/effect/dist/declarations/src/Data.d.ts +import type * as Types from "./Types.js"; +import type * as Equal from "./Equal.js"; + +export type Data> | ReadonlyArray> = + Readonly & Equal.Equal; + +export declare const TaggedClass: ( + tag: Key, +) => new >( + args: Types.Equals, {}> extends true + ? void + : Omit, +) => Data< + A & { + _tag: Key; + } +>; + +// @filename: node_modules/effect/dist/declarations/src/Equal.d.ts +import * as Hash from "./Hash.js"; + +export declare const symbol: unique symbol; + +export interface Equal extends Hash.Hash { + [symbol](that: Equal): boolean; +} + +// @filename: node_modules/effect/dist/declarations/src/Hash.d.ts +export declare const symbol: unique symbol; + +export interface Hash { + [symbol](): number; +} + +// @filename: node_modules/effect/dist/declarations/src/Types.d.ts +export type Equals = (() => T extends X ? 1 : 2) extends < + T, +>() => T extends Y ? 1 : 2 + ? true + : false; + +// @filename: node_modules/effect/dist/declarations/src/index.d.ts +export * as Data from "./Data.js"; +export * as Equal from "./Equal.js"; +export * as Types from "./Types.js"; + +// @filename: node_modules/effect/dist/effect.cjs.d.ts +export * from "./declarations/src/index"; + +// @filename: node_modules/effect/package.json +{ + "name": "effect", + "exports": { + ".": "./dist/effect.cjs.js" + } +} + +// @filename: src/index.ts +import { Data } from "effect"; +export class Foo extends Data.TaggedClass("Foo")<{}> {} \ No newline at end of file From 9aa27219095143d1110adf72b5d5d50768b93073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 17 Feb 2024 11:01:30 +0100 Subject: [PATCH 2/3] Add an extra test case --- .../declarationEmitUsingAliasSymbolChain2.js | 49 +++++++++++++ ...larationEmitUsingAliasSymbolChain2.symbols | 68 +++++++++++++++++++ ...eclarationEmitUsingAliasSymbolChain2.types | 61 +++++++++++++++++ .../declarationEmitUsingAliasSymbolChain2.ts | 34 ++++++++++ 4 files changed, 212 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.js create mode 100644 tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.symbols create mode 100644 tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.types create mode 100644 tests/cases/compiler/declarationEmitUsingAliasSymbolChain2.ts diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.js b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.js new file mode 100644 index 0000000000000..d9efd0a14e2f6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.js @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/declarationEmitUsingAliasSymbolChain2.ts] //// + +//// [index.d.ts] +import * as DefaultExport from "./internal/default_exports"; +export { DefaultExport as default }; +export * as BaseWindow from "./internal/windows/basewindow"; + +//// [default_exports.d.ts] +export { default as BaseWindow } from "./windows/basewindow"; + +//// [basewindow.d.ts] +interface BaseWindow {} +export interface BaseWindowConstructor {} +declare const BaseWindow: BaseWindowConstructor; +export default BaseWindow; + + +//// [widget-config.d.ts] +import type UI from "../../lib/index"; +export interface WidgetFactory { + instantiator(parentWindow: UI.BaseWindow): void; +} + +//// [widget-factory.ts] +import {WidgetFactory} from "../../lib-utils/shared-types/widget-config"; + +declare const instantiator: WidgetFactory['instantiator']; + +export default Object.freeze({ + instantiator +}); + +import type * as __synthetic_export_lib_1 from "../../lib/index"; + + +//// [widget-factory.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Object.freeze({ + instantiator: instantiator +}); + + +//// [widget-factory.d.ts] +declare const _default: Readonly<{ + instantiator: (parentWindow: __synthetic_export_lib_1.default.BaseWindow) => void; +}>; +export default _default; +import type * as __synthetic_export_lib_1 from "../../lib/index"; diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.symbols b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.symbols new file mode 100644 index 0000000000000..05f9494ba10d7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.symbols @@ -0,0 +1,68 @@ +//// [tests/cases/compiler/declarationEmitUsingAliasSymbolChain2.ts] //// + +=== lib/index.d.ts === +import * as DefaultExport from "./internal/default_exports"; +>DefaultExport : Symbol(DefaultExport, Decl(index.d.ts, 0, 6)) + +export { DefaultExport as default }; +>DefaultExport : Symbol(DefaultExport, Decl(index.d.ts, 0, 6)) +>default : Symbol(default, Decl(index.d.ts, 1, 8)) + +export * as BaseWindow from "./internal/windows/basewindow"; +>BaseWindow : Symbol(BaseWindow, Decl(index.d.ts, 2, 6)) + +=== lib/internal/default_exports.d.ts === +export { default as BaseWindow } from "./windows/basewindow"; +>default : Symbol(default, Decl(basewindow.d.ts, 2, 48)) +>BaseWindow : Symbol(BaseWindow, Decl(default_exports.d.ts, 0, 8)) + +=== lib/internal/windows/basewindow.d.ts === +interface BaseWindow {} +>BaseWindow : Symbol(BaseWindow, Decl(basewindow.d.ts, 0, 0), Decl(basewindow.d.ts, 2, 13)) + +export interface BaseWindowConstructor {} +>BaseWindowConstructor : Symbol(BaseWindowConstructor, Decl(basewindow.d.ts, 0, 23)) + +declare const BaseWindow: BaseWindowConstructor; +>BaseWindow : Symbol(BaseWindow, Decl(basewindow.d.ts, 0, 0), Decl(basewindow.d.ts, 2, 13)) +>BaseWindowConstructor : Symbol(BaseWindowConstructor, Decl(basewindow.d.ts, 0, 23)) + +export default BaseWindow; +>BaseWindow : Symbol(BaseWindow, Decl(basewindow.d.ts, 0, 0), Decl(basewindow.d.ts, 2, 13)) + + +=== lib-utils/shared-types/widget-config.d.ts === +import type UI from "../../lib/index"; +>UI : Symbol(UI, Decl(widget-config.d.ts, 0, 6)) + +export interface WidgetFactory { +>WidgetFactory : Symbol(WidgetFactory, Decl(widget-config.d.ts, 0, 38)) + + instantiator(parentWindow: UI.BaseWindow): void; +>instantiator : Symbol(WidgetFactory.instantiator, Decl(widget-config.d.ts, 1, 32)) +>parentWindow : Symbol(parentWindow, Decl(widget-config.d.ts, 2, 17)) +>UI : Symbol(UI, Decl(widget-config.d.ts, 0, 6)) +>BaseWindow : Symbol(UI.BaseWindow, Decl(default_exports.d.ts, 0, 8)) +} + +=== app/navigator/widget-factory.ts === +import {WidgetFactory} from "../../lib-utils/shared-types/widget-config"; +>WidgetFactory : Symbol(WidgetFactory, Decl(widget-factory.ts, 0, 8)) + +declare const instantiator: WidgetFactory['instantiator']; +>instantiator : Symbol(instantiator, Decl(widget-factory.ts, 2, 13)) +>WidgetFactory : Symbol(WidgetFactory, Decl(widget-factory.ts, 0, 8)) + +export default Object.freeze({ +>Object.freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>freeze : Symbol(ObjectConstructor.freeze, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + instantiator +>instantiator : Symbol(instantiator, Decl(widget-factory.ts, 4, 30)) + +}); + +import type * as __synthetic_export_lib_1 from "../../lib/index"; +>__synthetic_export_lib_1 : Symbol(__synthetic_export_lib_1, Decl(widget-factory.ts, 8, 11)) + diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.types b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.types new file mode 100644 index 0000000000000..3f041758bea61 --- /dev/null +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain2.types @@ -0,0 +1,61 @@ +//// [tests/cases/compiler/declarationEmitUsingAliasSymbolChain2.ts] //// + +=== lib/index.d.ts === +import * as DefaultExport from "./internal/default_exports"; +>DefaultExport : typeof DefaultExport + +export { DefaultExport as default }; +>DefaultExport : typeof DefaultExport +>default : typeof DefaultExport + +export * as BaseWindow from "./internal/windows/basewindow"; +>BaseWindow : typeof import("lib/internal/windows/basewindow") + +=== lib/internal/default_exports.d.ts === +export { default as BaseWindow } from "./windows/basewindow"; +>default : import("lib/internal/windows/basewindow").BaseWindowConstructor +>BaseWindow : import("lib/internal/windows/basewindow").BaseWindowConstructor + +=== lib/internal/windows/basewindow.d.ts === +interface BaseWindow {} +export interface BaseWindowConstructor {} +declare const BaseWindow: BaseWindowConstructor; +>BaseWindow : BaseWindowConstructor + +export default BaseWindow; +>BaseWindow : BaseWindow + + +=== lib-utils/shared-types/widget-config.d.ts === +import type UI from "../../lib/index"; +>UI : any + +export interface WidgetFactory { + instantiator(parentWindow: UI.BaseWindow): void; +>instantiator : (parentWindow: UI.BaseWindow) => void +>parentWindow : UI.BaseWindow +>UI : any +} + +=== app/navigator/widget-factory.ts === +import {WidgetFactory} from "../../lib-utils/shared-types/widget-config"; +>WidgetFactory : any + +declare const instantiator: WidgetFactory['instantiator']; +>instantiator : (parentWindow: __synthetic_export_lib_1.default.BaseWindow) => void + +export default Object.freeze({ +>Object.freeze({ instantiator}) : Readonly<{ instantiator: (parentWindow: __synthetic_export_lib_1.default.BaseWindow) => void; }> +>Object.freeze : { (f: T): T; (o: T_1): Readonly; (o: T_2): Readonly; } +>Object : ObjectConstructor +>freeze : { (f: T): T; (o: T_1): Readonly; (o: T_2): Readonly; } +>{ instantiator} : { instantiator: (parentWindow: __synthetic_export_lib_1.default.BaseWindow) => void; } + + instantiator +>instantiator : (parentWindow: __synthetic_export_lib_1.default.BaseWindow) => void + +}); + +import type * as __synthetic_export_lib_1 from "../../lib/index"; +>__synthetic_export_lib_1 : typeof __synthetic_export_lib_1 + diff --git a/tests/cases/compiler/declarationEmitUsingAliasSymbolChain2.ts b/tests/cases/compiler/declarationEmitUsingAliasSymbolChain2.ts new file mode 100644 index 0000000000000..6ffcd5c1906d9 --- /dev/null +++ b/tests/cases/compiler/declarationEmitUsingAliasSymbolChain2.ts @@ -0,0 +1,34 @@ +// @strict: true +// @declaration: true + +// @filename: lib/index.d.ts +import * as DefaultExport from "./internal/default_exports"; +export { DefaultExport as default }; +export * as BaseWindow from "./internal/windows/basewindow"; + +// @filename: lib/internal/default_exports.d.ts +export { default as BaseWindow } from "./windows/basewindow"; + +// @filename: lib/internal/windows/basewindow.d.ts +interface BaseWindow {} +export interface BaseWindowConstructor {} +declare const BaseWindow: BaseWindowConstructor; +export default BaseWindow; + + +// @filename: lib-utils/shared-types/widget-config.d.ts +import type UI from "../../lib/index"; +export interface WidgetFactory { + instantiator(parentWindow: UI.BaseWindow): void; +} + +// @filename: app/navigator/widget-factory.ts +import {WidgetFactory} from "../../lib-utils/shared-types/widget-config"; + +declare const instantiator: WidgetFactory['instantiator']; + +export default Object.freeze({ + instantiator +}); + +import type * as __synthetic_export_lib_1 from "../../lib/index"; From a9f1dff53ff64d805fc02f603706c5c5e1a769fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 20 Mar 2024 10:18:23 +0100 Subject: [PATCH 3/3] update baselines --- .../declarationEmitUsingAliasSymbolChain1.js | 26 +++---------------- ...larationEmitUsingAliasSymbolChain1.symbols | 2 +- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js index cf5783a7d6c12..a7b831e6a58a9 100644 --- a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.js @@ -64,31 +64,11 @@ export class Foo extends Data.TaggedClass("Foo")<{}> {} //// [index.js] "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Foo = void 0; -var effect_1 = require("effect"); -var Foo = /** @class */ (function (_super) { - __extends(Foo, _super); - function Foo() { - return _super !== null && _super.apply(this, arguments) || this; - } - return Foo; -}(effect_1.Data.TaggedClass("Foo"))); +const effect_1 = require("effect"); +class Foo extends effect_1.Data.TaggedClass("Foo") { +} exports.Foo = Foo; diff --git a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols index 9dc541b9b13a7..8e30c5a30d55d 100644 --- a/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols +++ b/tests/baselines/reference/declarationEmitUsingAliasSymbolChain1.symbols @@ -12,7 +12,7 @@ export type Data> | ReadonlyArray> = >A : Symbol(A, Decl(Data.d.ts, 3, 17)) >Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --)) +>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --) ... and 3 more) Readonly & Equal.Equal; >Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --))