From b7d523ecbbd583d37766b7946860bc5ce4835c5f Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Tue, 30 May 2023 13:46:43 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#54450=20(Resolve=20?= =?UTF-8?q?tslib=20re-exports=20before=20che...)=20into=20release-5.1=20(#?= =?UTF-8?q?54457)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrew Branch --- src/compiler/checker.ts | 2 +- .../reference/tslibReExportHelpers2.js | 56 ++++++++++++++ .../reference/tslibReExportHelpers2.symbols | 75 +++++++++++++++++++ .../reference/tslibReExportHelpers2.types | 64 ++++++++++++++++ tests/cases/compiler/tslibReExportHelpers2.ts | 45 +++++++++++ 5 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/tslibReExportHelpers2.js create mode 100644 tests/baselines/reference/tslibReExportHelpers2.symbols create mode 100644 tests/baselines/reference/tslibReExportHelpers2.types create mode 100644 tests/cases/compiler/tslibReExportHelpers2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 161a78ff86610..0715f58e71429 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -46984,7 +46984,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (requestedExternalEmitHelperNames.has(name)) continue; requestedExternalEmitHelperNames.add(name); - const symbol = getSymbol(getExportsOfModule(helpersModule), escapeLeadingUnderscores(name), SymbolFlags.Value); + const symbol = resolveSymbol(getSymbol(getExportsOfModule(helpersModule), escapeLeadingUnderscores(name), SymbolFlags.Value)); if (!symbol) { error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_which_does_not_exist_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name); } diff --git a/tests/baselines/reference/tslibReExportHelpers2.js b/tests/baselines/reference/tslibReExportHelpers2.js new file mode 100644 index 0000000000000..367cb6a0bb70f --- /dev/null +++ b/tests/baselines/reference/tslibReExportHelpers2.js @@ -0,0 +1,56 @@ +//// [tests/cases/compiler/tslibReExportHelpers2.ts] //// + +//// [index.d.ts] +export declare function __classPrivateFieldGet( + receiver: T, + state: { has(o: T): boolean, get(o: T): V | undefined }, + kind?: "f" +): V; +export declare function __classPrivateFieldGet unknown, V>( + receiver: T, + state: T, + kind: "f", + f: { value: V } +): V; + +//// [index.d.mts] +export { __classPrivateFieldGet } from "./index.js"; + +//// [package.json] +{ + "name": "tslib", + "version": "1.0.0", + "types": "index.d.ts", + "exports": { + ".": { + "types": { + "import": "./index.d.mts", + "default": "./index.d.ts" + } + } + } +} + +//// [index.mts] +export class Foo { + constructor() { + console.log(Foo.#test()); + } + + static #test() { + return 'success'; + } +} + + +//// [index.mjs] +var _a, _Foo_test; +import { __classPrivateFieldGet } from "tslib"; +export class Foo { + constructor() { + console.log(__classPrivateFieldGet(Foo, _a, "m", _Foo_test).call(Foo)); + } +} +_a = Foo, _Foo_test = function _Foo_test() { + return 'success'; +}; diff --git a/tests/baselines/reference/tslibReExportHelpers2.symbols b/tests/baselines/reference/tslibReExportHelpers2.symbols new file mode 100644 index 0000000000000..1dd7c12a705e1 --- /dev/null +++ b/tests/baselines/reference/tslibReExportHelpers2.symbols @@ -0,0 +1,75 @@ +=== /node_modules/tslib/index.d.ts === +export declare function __classPrivateFieldGet( +>__classPrivateFieldGet : Symbol(__classPrivateFieldGet, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 4, 5)) +>T : Symbol(T, Decl(index.d.ts, 0, 47)) +>V : Symbol(V, Decl(index.d.ts, 0, 64)) + + receiver: T, +>receiver : Symbol(receiver, Decl(index.d.ts, 0, 68)) +>T : Symbol(T, Decl(index.d.ts, 0, 47)) + + state: { has(o: T): boolean, get(o: T): V | undefined }, +>state : Symbol(state, Decl(index.d.ts, 1, 14)) +>has : Symbol(has, Decl(index.d.ts, 2, 10)) +>o : Symbol(o, Decl(index.d.ts, 2, 15)) +>T : Symbol(T, Decl(index.d.ts, 0, 47)) +>get : Symbol(get, Decl(index.d.ts, 2, 30)) +>o : Symbol(o, Decl(index.d.ts, 2, 35)) +>T : Symbol(T, Decl(index.d.ts, 0, 47)) +>V : Symbol(V, Decl(index.d.ts, 0, 64)) + + kind?: "f" +>kind : Symbol(kind, Decl(index.d.ts, 2, 58)) + +): V; +>V : Symbol(V, Decl(index.d.ts, 0, 64)) + +export declare function __classPrivateFieldGet unknown, V>( +>__classPrivateFieldGet : Symbol(__classPrivateFieldGet, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 4, 5)) +>T : Symbol(T, Decl(index.d.ts, 5, 47)) +>args : Symbol(args, Decl(index.d.ts, 5, 62)) +>V : Symbol(V, Decl(index.d.ts, 5, 89)) + + receiver: T, +>receiver : Symbol(receiver, Decl(index.d.ts, 5, 93)) +>T : Symbol(T, Decl(index.d.ts, 5, 47)) + + state: T, +>state : Symbol(state, Decl(index.d.ts, 6, 14)) +>T : Symbol(T, Decl(index.d.ts, 5, 47)) + + kind: "f", +>kind : Symbol(kind, Decl(index.d.ts, 7, 11)) + + f: { value: V } +>f : Symbol(f, Decl(index.d.ts, 8, 12)) +>value : Symbol(value, Decl(index.d.ts, 9, 6)) +>V : Symbol(V, Decl(index.d.ts, 5, 89)) + +): V; +>V : Symbol(V, Decl(index.d.ts, 5, 89)) + +=== /node_modules/tslib/index.d.mts === +export { __classPrivateFieldGet } from "./index.js"; +>__classPrivateFieldGet : Symbol(__classPrivateFieldGet, Decl(index.d.mts, 0, 8)) + +=== /index.mts === +export class Foo { +>Foo : Symbol(Foo, Decl(index.mts, 0, 0)) + + constructor() { + console.log(Foo.#test()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Foo.#test : Symbol(Foo.#test, Decl(index.mts, 3, 3)) +>Foo : Symbol(Foo, Decl(index.mts, 0, 0)) + } + + static #test() { +>#test : Symbol(Foo.#test, Decl(index.mts, 3, 3)) + + return 'success'; + } +} + diff --git a/tests/baselines/reference/tslibReExportHelpers2.types b/tests/baselines/reference/tslibReExportHelpers2.types new file mode 100644 index 0000000000000..d21cc81281997 --- /dev/null +++ b/tests/baselines/reference/tslibReExportHelpers2.types @@ -0,0 +1,64 @@ +=== /node_modules/tslib/index.d.ts === +export declare function __classPrivateFieldGet( +>__classPrivateFieldGet : { (receiver: T, state: { has(o: T): boolean; get(o: T): V | undefined; }, kind?: "f"): V; unknown, V>(receiver: T, state: T, kind: "f", f: { value: V; }): V; } + + receiver: T, +>receiver : T + + state: { has(o: T): boolean, get(o: T): V | undefined }, +>state : { has(o: T): boolean; get(o: T): V | undefined; } +>has : (o: T) => boolean +>o : T +>get : (o: T) => V | undefined +>o : T + + kind?: "f" +>kind : "f" + +): V; +export declare function __classPrivateFieldGet unknown, V>( +>__classPrivateFieldGet : { (receiver: T, state: { has(o: T): boolean; get(o: T): V; }, kind?: "f"): V; unknown, V>(receiver: T, state: T, kind: "f", f: { value: V;}): V; } +>args : any[] + + receiver: T, +>receiver : T + + state: T, +>state : T + + kind: "f", +>kind : "f" + + f: { value: V } +>f : { value: V; } +>value : V + +): V; + +=== /node_modules/tslib/index.d.mts === +export { __classPrivateFieldGet } from "./index.js"; +>__classPrivateFieldGet : { (receiver: T, state: { has(o: T): boolean; get(o: T): V; }, kind?: "f"): V; unknown, V>(receiver: T, state: T, kind: "f", f: { value: V; }): V; } + +=== /index.mts === +export class Foo { +>Foo : Foo + + constructor() { + console.log(Foo.#test()); +>console.log(Foo.#test()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Foo.#test() : string +>Foo.#test : () => string +>Foo : typeof Foo + } + + static #test() { +>#test : () => string + + return 'success'; +>'success' : "success" + } +} + diff --git a/tests/cases/compiler/tslibReExportHelpers2.ts b/tests/cases/compiler/tslibReExportHelpers2.ts new file mode 100644 index 0000000000000..c08fdcff65161 --- /dev/null +++ b/tests/cases/compiler/tslibReExportHelpers2.ts @@ -0,0 +1,45 @@ +// @module: nodenext +// @importHelpers: true +// @target: es2021 + +// @Filename: /node_modules/tslib/index.d.ts +export declare function __classPrivateFieldGet( + receiver: T, + state: { has(o: T): boolean, get(o: T): V | undefined }, + kind?: "f" +): V; +export declare function __classPrivateFieldGet unknown, V>( + receiver: T, + state: T, + kind: "f", + f: { value: V } +): V; + +// @Filename: /node_modules/tslib/index.d.mts +export { __classPrivateFieldGet } from "./index.js"; + +// @Filename: /node_modules/tslib/package.json +{ + "name": "tslib", + "version": "1.0.0", + "types": "index.d.ts", + "exports": { + ".": { + "types": { + "import": "./index.d.mts", + "default": "./index.d.ts" + } + } + } +} + +// @Filename: /index.mts +export class Foo { + constructor() { + console.log(Foo.#test()); + } + + static #test() { + return 'success'; + } +}