Skip to content

Commit df342b7

Browse files
authored
Fixed rewriteRelativeImportExtensions for import() within call expressions (#61154)
1 parent 775412a commit df342b7

File tree

6 files changed

+36
-3
lines changed

6 files changed

+36
-3
lines changed

src/compiler/transformers/module/esnextAnd2015.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S
158158
if (node === importsAndRequiresToRewriteOrShim?.[0]) {
159159
return visitImportOrRequireCall(importsAndRequiresToRewriteOrShim.shift()!);
160160
}
161-
break;
161+
// fallthrough
162162
default:
163163
if (importsAndRequiresToRewriteOrShim?.length && rangeContainsRange(node, importsAndRequiresToRewriteOrShim[0])) {
164164
return visitEachChild(node, visitor, context);

tests/baselines/reference/emit(jsx=preserve).errors.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding
66
main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
77
main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
88
main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
9+
main.ts(13,18): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
10+
main.ts(14,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
911
no.ts(1,16): error TS2307: Cannot find module './foo.ts/foo.js' or its corresponding type declarations.
1012
no.ts(2,16): error TS2307: Cannot find module 'foo.ts' or its corresponding type declarations.
1113
no.ts(3,16): error TS2307: Cannot find module 'pkg/foo.ts' or its corresponding type declarations.
@@ -21,7 +23,7 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
2123
==== globals.d.ts (0 errors) ====
2224
declare function require(module: string): any;
2325

24-
==== main.ts (8 errors) ====
26+
==== main.ts (10 errors) ====
2527
// Rewrite
2628
import {} from "./foo.ts";
2729
~~~~~~~~~~
@@ -45,6 +47,13 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
4547
//Shim
4648
import("./foo.ts");
4749
~~~~~~~~~~
50+
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
51+
import("./foo.ts").then(() => {});
52+
~~~~~~~~~~
53+
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
54+
function acceptAny(arg: any) {}
55+
acceptAny(import("./foo.ts"));
56+
~~~~~~~~~~
4857
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
4958
import("./foo.ts", { with: { attr: "value" } });
5059
~~~~~~~~~~

tests/baselines/reference/emit(jsx=preserve).js

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import "./foo.ts";
1414
export * from "./foo.ts";
1515
//Shim
1616
import("./foo.ts");
17+
import("./foo.ts").then(() => {});
18+
function acceptAny(arg: any) {}
19+
acceptAny(import("./foo.ts"));
1720
import("./foo.ts", { with: { attr: "value" } });
1821
import("" + "./foo.ts");
1922
//// [js.js]
@@ -71,6 +74,9 @@ import "./foo.js";
7174
export * from "./foo.js";
7275
//Shim
7376
import("./foo.js");
77+
import("./foo.js").then(() => { });
78+
function acceptAny(arg) { }
79+
acceptAny(import("./foo.js"));
7480
import("./foo.js", { with: { attr: "value" } });
7581
import(__rewriteRelativeImportExtension("" + "./foo.ts", true));
7682
//// [js.js]

tests/baselines/reference/emit(jsx=react).errors.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding
66
main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
77
main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
88
main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
9+
main.ts(13,18): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
10+
main.ts(14,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
911
no.ts(1,16): error TS2307: Cannot find module './foo.ts/foo.js' or its corresponding type declarations.
1012
no.ts(2,16): error TS2307: Cannot find module 'foo.ts' or its corresponding type declarations.
1113
no.ts(3,16): error TS2307: Cannot find module 'pkg/foo.ts' or its corresponding type declarations.
@@ -21,7 +23,7 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
2123
==== globals.d.ts (0 errors) ====
2224
declare function require(module: string): any;
2325

24-
==== main.ts (8 errors) ====
26+
==== main.ts (10 errors) ====
2527
// Rewrite
2628
import {} from "./foo.ts";
2729
~~~~~~~~~~
@@ -45,6 +47,13 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
4547
//Shim
4648
import("./foo.ts");
4749
~~~~~~~~~~
50+
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
51+
import("./foo.ts").then(() => {});
52+
~~~~~~~~~~
53+
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
54+
function acceptAny(arg: any) {}
55+
acceptAny(import("./foo.ts"));
56+
~~~~~~~~~~
4857
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
4958
import("./foo.ts", { with: { attr: "value" } });
5059
~~~~~~~~~~

tests/baselines/reference/emit(jsx=react).js

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import "./foo.ts";
1414
export * from "./foo.ts";
1515
//Shim
1616
import("./foo.ts");
17+
import("./foo.ts").then(() => {});
18+
function acceptAny(arg: any) {}
19+
acceptAny(import("./foo.ts"));
1720
import("./foo.ts", { with: { attr: "value" } });
1821
import("" + "./foo.ts");
1922
//// [js.js]
@@ -71,6 +74,9 @@ import "./foo.js";
7174
export * from "./foo.js";
7275
//Shim
7376
import("./foo.js");
77+
import("./foo.js").then(() => { });
78+
function acceptAny(arg) { }
79+
acceptAny(import("./foo.js"));
7480
import("./foo.js", { with: { attr: "value" } });
7581
import(__rewriteRelativeImportExtension("" + "./foo.ts"));
7682
//// [js.js]

tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/emit.ts

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import "./foo.ts";
2121
export * from "./foo.ts";
2222
//Shim
2323
import("./foo.ts");
24+
import("./foo.ts").then(() => {});
25+
function acceptAny(arg: any) {}
26+
acceptAny(import("./foo.ts"));
2427
import("./foo.ts", { with: { attr: "value" } });
2528
import("" + "./foo.ts");
2629
// @Filename: js.js

0 commit comments

Comments
 (0)