Commit 5233d73
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- crates/oxc_codegen/tests/integration
- snapshots
3 files changed
+41
-0
lines changedLines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
136 | 141 | | |
137 | 142 | | |
138 | 143 | | |
| |||
0 commit comments