Skip to content

Commit

Permalink
🤖 Pick PR #54450 (Resolve tslib re-exports before che...) into releas…
Browse files Browse the repository at this point in the history
…e-5.1 (#54457)

Co-authored-by: Andrew Branch <andrew@wheream.io>
  • Loading branch information
TypeScript Bot and andrewbranch authored May 30, 2023
1 parent a360d9f commit b7d523e
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
56 changes: 56 additions & 0 deletions tests/baselines/reference/tslibReExportHelpers2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//// [tests/cases/compiler/tslibReExportHelpers2.ts] ////

//// [index.d.ts]
export declare function __classPrivateFieldGet<T extends object, V>(
receiver: T,
state: { has(o: T): boolean, get(o: T): V | undefined },
kind?: "f"
): V;
export declare function __classPrivateFieldGet<T extends new (...args: any[]) => 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';
};
75 changes: 75 additions & 0 deletions tests/baselines/reference/tslibReExportHelpers2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
=== /node_modules/tslib/index.d.ts ===
export declare function __classPrivateFieldGet<T extends object, V>(
>__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<T extends new (...args: any[]) => 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';
}
}

64 changes: 64 additions & 0 deletions tests/baselines/reference/tslibReExportHelpers2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
=== /node_modules/tslib/index.d.ts ===
export declare function __classPrivateFieldGet<T extends object, V>(
>__classPrivateFieldGet : { <T extends object, V>(receiver: T, state: { has(o: T): boolean; get(o: T): V | undefined; }, kind?: "f"): V; <T extends new (...args: any[]) => 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<T extends new (...args: any[]) => unknown, V>(
>__classPrivateFieldGet : { <T extends object, V>(receiver: T, state: { has(o: T): boolean; get(o: T): V; }, kind?: "f"): V; <T extends new (...args: any[]) => 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 : { <T extends object, V>(receiver: T, state: { has(o: T): boolean; get(o: T): V; }, kind?: "f"): V; <T extends new (...args: any[]) => 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"
}
}

45 changes: 45 additions & 0 deletions tests/cases/compiler/tslibReExportHelpers2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @module: nodenext
// @importHelpers: true
// @target: es2021

// @Filename: /node_modules/tslib/index.d.ts
export declare function __classPrivateFieldGet<T extends object, V>(
receiver: T,
state: { has(o: T): boolean, get(o: T): V | undefined },
kind?: "f"
): V;
export declare function __classPrivateFieldGet<T extends new (...args: any[]) => 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';
}
}

0 comments on commit b7d523e

Please sign in to comment.