Skip to content

Commit 5233d73

Browse files
test(codegen): Add regression tests for TSImportType string literal output (#16120)
PR #16114 fixed TSImportType codegen to prevent backticks in minified output (which produces invalid TypeScript). This adds regression tests to ensure the fix persists. ## Changes - Added 4 test cases covering TSImportType variants: - Basic import types with single/double quotes - Import types with qualifiers (`.SomeType`) - Import types with type arguments (`<string>`) - Tests verify both normal and minified output via snapshots ## Example Input: ```typescript type T = typeof import('react'); ``` Minified output (now tested): ```typescript type T=typeof import("react"); // ✓ double quotes, not backticks ``` The minify snapshot ensures backticks are never used, preventing invalid TS like `import(\`react\`)`. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Codegen: Do not use backticks when printing argument of `TSImportType`</issue_title> > <issue_description>Input: > > ```ts > type T = typeof import('react'); > ``` > > Codegen output (with `minify: true`): > > ```ts > type T=typeof import(`react`); > ``` > > [Playground](https://playground.oxc.rs/#eNptU01rGzEQ/StGl7TgQhooBJceSlJDIW3SJjSXXma1s44SrUYdzcY2xv+9o/VKTiCn1b7RfLw3TztjzcLINuLsbvZllg/UzVwfieXdCSNYOXn/+W8wc0NmsTM8hPzxLohZdOATzk1H3IMIckWEIaQMV8Ql8iDYXqL1wCCOQqrB9YMTTBEsmoXwoEgPYeX1b7pgqY+M6ZiRLMV6OW37hnz5s91qurafmwic8lw7gxvBkLRtppuUDnhP698oA4frQZJrcTkEmwcrlXJL5Ge8AdbUgo55f86/B2GnBW0NJNSpxdlvzMQTqiNkqcYR9PxCqZ0ZEt5Bc+Qk0Ny7Vh7M4mxuMLTX3ZULStL4TseN2k2m+PmpdnNZoV8DyVGmx7S5fQP+l/9umKL2MpA+BMQWW62pa3I63uqC+h5yzHtFlYerZJXLuvDX+Bq2WbuGwT6h3OrKNL1cLij0eJh86k/NI1q5Z4hao4iaG42zfhUVshl0QuRXabiJyK7HIOCv9QhCfEPJHVaUFTIqabXaQVQBXqFa02A6O/34SbuozJfYaeEl8YWHlJYOfVu39rKLmpPGNsdo76SiP1CgBVGlptW+beqdScooqkGQA6gvixkttbjC8f2EbIRq2cfUkj7DSfIQSMZaBfG4KnfHKuUtZEeVh6LMKV7hM9aiT4jxp66iGGxMVdOSX6qBc8YzckOpCJ75hLyoHKqnvcLtKF+G62mf8Sxz4bT/D3SBh38=) > > This is invalid TypeScript. TS appears to require the argument to be a string literal, and nothing else - template literal is not allowable here. > > [TS Playground](https://www.typescriptlang.org/play/?#code/C4TwDgpgBAglC8VSQPYDMoEsC2YUCdgAKAA3wgEMBjYEgSgG4AoIA) > > Related to #16074.</issue_description> > > <agent_instructions>The issue itself is solved. Add a test for it.</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > <comment_new><author>@overlookmotel</author><body> > We might want to do #16111 first. That'll make this fix easier to implement.</body></comment_new> > <comment_new><author>@overlookmotel</author><body> > #16114 should have fixed this. We just need to add a test to make sure.</body></comment_new> > <comment_new><author>@camc314</author><body> > There are tests for this, they regressed after just the AST change. I fixed them back up in 16114 to avoid the regression</body></comment_new> > </comments> > </details> - Fixes #16078 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/oxc-project/oxc/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: overlookmotel <[email protected]>
1 parent d2b7dcb commit 5233d73

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

crates/oxc_codegen/tests/integration/snapshots/minify.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,19 @@ class C {
232232
}
233233
----------
234234
class C{static static;static bar(){}}
235+
########## 43
236+
type T = typeof import('react');
237+
----------
238+
type T=typeof import("react");
239+
########## 44
240+
type U = typeof import("vue");
241+
----------
242+
type U=typeof import("vue");
243+
########## 45
244+
type V = typeof import('some-module').SomeType;
245+
----------
246+
type V=typeof import("some-module").SomeType;
247+
########## 46
248+
type W = typeof import('pkg').default<string>;
249+
----------
250+
type W=typeof import("pkg").default<string>;

crates/oxc_codegen/tests/integration/snapshots/ts.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,23 @@ class C {
349349
static static;
350350
static bar() {}
351351
}
352+
353+
########## 43
354+
type T = typeof import('react');
355+
----------
356+
type T = typeof import('react');
357+
358+
########## 44
359+
type U = typeof import("vue");
360+
----------
361+
type U = typeof import('vue');
362+
363+
########## 45
364+
type V = typeof import('some-module').SomeType;
365+
----------
366+
type V = typeof import('some-module').SomeType;
367+
368+
########## 46
369+
type W = typeof import('pkg').default<string>;
370+
----------
371+
type W = typeof import('pkg').default<string>;

crates/oxc_codegen/tests/integration/ts.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ export import b = require("b");
133133
static
134134
bar() {}
135135
}",
136+
// TSImportType - ensure backticks are not used in minify mode
137+
"type T = typeof import('react');",
138+
"type U = typeof import(\"vue\");",
139+
"type V = typeof import('some-module').SomeType;",
140+
"type W = typeof import('pkg').default<string>;",
136141
];
137142

138143
snapshot("ts", &cases);

0 commit comments

Comments
 (0)