Skip to content

Commit 6c517ef

Browse files
authored
Dont let an import that doesnt need helpers override one that does (#22966)
1 parent 5c49133 commit 6c517ef

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

src/compiler/transformers/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ts {
6060
// import * as x from "mod"
6161
// import { x, y } from "mod"
6262
externalImports.push(<ImportDeclaration>node);
63-
hasImportStarOrImportDefault = getImportNeedsImportStarHelper(<ImportDeclaration>node) || getImportNeedsImportDefaultHelper(<ImportDeclaration>node);
63+
hasImportStarOrImportDefault = hasImportStarOrImportDefault || getImportNeedsImportStarHelper(<ImportDeclaration>node) || getImportNeedsImportDefaultHelper(<ImportDeclaration>node);
6464
break;
6565

6666
case SyntaxKind.ImportEqualsDeclaration:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [tests/cases/compiler/esModuleInteropImportTSLibHasImport.ts] ////
2+
3+
//// [types.d.ts]
4+
declare module "tslib" { export const __exportStar: any; export const __importDefault: any; export const __importStar: any; }
5+
//// [username.ts]
6+
export const username = () => 'username';
7+
//// [index.ts]
8+
export * from './username';
9+
//// [hello.ts]
10+
const sayHello = (name?: string) => void (`Hello, ${name}!`);
11+
12+
export default sayHello;
13+
//// [index.ts]
14+
import sayHello from "./hello";
15+
import { username } from './utils';
16+
17+
sayHello(username());
18+
19+
//// [username.js]
20+
"use strict";
21+
Object.defineProperty(exports, "__esModule", { value: true });
22+
exports.username = () => 'username';
23+
//// [index.js]
24+
"use strict";
25+
Object.defineProperty(exports, "__esModule", { value: true });
26+
const tslib_1 = require("tslib");
27+
tslib_1.__exportStar(require("./username"), exports);
28+
//// [hello.js]
29+
"use strict";
30+
Object.defineProperty(exports, "__esModule", { value: true });
31+
const sayHello = (name) => void (`Hello, ${name}!`);
32+
exports.default = sayHello;
33+
//// [index.js]
34+
"use strict";
35+
Object.defineProperty(exports, "__esModule", { value: true });
36+
const tslib_1 = require("tslib");
37+
const hello_1 = tslib_1.__importDefault(require("./hello"));
38+
const utils_1 = require("./utils");
39+
hello_1.default(utils_1.username());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/types.d.ts ===
2+
declare module "tslib" { export const __exportStar: any; export const __importDefault: any; export const __importStar: any; }
3+
>"tslib" : Symbol("tslib", Decl(types.d.ts, 0, 0))
4+
>__exportStar : Symbol(__exportStar, Decl(types.d.ts, 0, 37))
5+
>__importDefault : Symbol(__importDefault, Decl(types.d.ts, 0, 69))
6+
>__importStar : Symbol(__importStar, Decl(types.d.ts, 0, 104))
7+
8+
=== tests/cases/compiler/utils/username.ts ===
9+
export const username = () => 'username';
10+
>username : Symbol(username, Decl(username.ts, 0, 12))
11+
12+
=== tests/cases/compiler/utils/index.ts ===
13+
export * from './username';
14+
No type information for this code.=== tests/cases/compiler/hello.ts ===
15+
const sayHello = (name?: string) => void (`Hello, ${name}!`);
16+
>sayHello : Symbol(sayHello, Decl(hello.ts, 0, 5))
17+
>name : Symbol(name, Decl(hello.ts, 0, 18))
18+
>name : Symbol(name, Decl(hello.ts, 0, 18))
19+
20+
export default sayHello;
21+
>sayHello : Symbol(sayHello, Decl(hello.ts, 0, 5))
22+
23+
=== tests/cases/compiler/index.ts ===
24+
import sayHello from "./hello";
25+
>sayHello : Symbol(sayHello, Decl(index.ts, 0, 6))
26+
27+
import { username } from './utils';
28+
>username : Symbol(username, Decl(index.ts, 1, 8))
29+
30+
sayHello(username());
31+
>sayHello : Symbol(sayHello, Decl(index.ts, 0, 6))
32+
>username : Symbol(username, Decl(index.ts, 1, 8))
33+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=== tests/cases/compiler/types.d.ts ===
2+
declare module "tslib" { export const __exportStar: any; export const __importDefault: any; export const __importStar: any; }
3+
>"tslib" : typeof "tslib"
4+
>__exportStar : any
5+
>__importDefault : any
6+
>__importStar : any
7+
8+
=== tests/cases/compiler/utils/username.ts ===
9+
export const username = () => 'username';
10+
>username : () => string
11+
>() => 'username' : () => string
12+
>'username' : "username"
13+
14+
=== tests/cases/compiler/utils/index.ts ===
15+
export * from './username';
16+
No type information for this code.=== tests/cases/compiler/hello.ts ===
17+
const sayHello = (name?: string) => void (`Hello, ${name}!`);
18+
>sayHello : (name?: string) => any
19+
>(name?: string) => void (`Hello, ${name}!`) : (name?: string) => any
20+
>name : string
21+
>void (`Hello, ${name}!`) : undefined
22+
>(`Hello, ${name}!`) : string
23+
>`Hello, ${name}!` : string
24+
>name : string
25+
26+
export default sayHello;
27+
>sayHello : (name?: string) => any
28+
29+
=== tests/cases/compiler/index.ts ===
30+
import sayHello from "./hello";
31+
>sayHello : (name?: string) => any
32+
33+
import { username } from './utils';
34+
>username : () => string
35+
36+
sayHello(username());
37+
>sayHello(username()) : any
38+
>sayHello : (name?: string) => any
39+
>username() : string
40+
>username : () => string
41+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @esModuleInterop: true
2+
// @importHelpers: true
3+
// @noEmitHelpers: true
4+
// @target: es2017
5+
// @module: commonjs
6+
// @filename: types.d.ts
7+
declare module "tslib" { export const __exportStar: any; export const __importDefault: any; export const __importStar: any; }
8+
// @filename: utils/username.ts
9+
export const username = () => 'username';
10+
// @filename: utils/index.ts
11+
export * from './username';
12+
// @filename: hello.ts
13+
const sayHello = (name?: string) => void (`Hello, ${name}!`);
14+
15+
export default sayHello;
16+
// @filename: index.ts
17+
import sayHello from "./hello";
18+
import { username } from './utils';
19+
20+
sayHello(username());

0 commit comments

Comments
 (0)