fix(codegen): escape sources for empty import specifiers (#25586)

## Summary
- Route empty named-import sources through the shared string-literal printer.
- Cover quote and newline escaping, including minified quote selection.

Given:
```ts
import {} from 'h"i'
```

Before it would be printed as:
```ts
import {} from "h"i" // missing escape of `"` or should be using `'` quotes
```

After:
```ts
import {} from 'h"i'
```
This commit is contained in:
camc314 committed 2026-08-13 11:26:56 +00:00
1 parent 0c68b7ff8b
commit c002f29226
3 files changed
+5 -4

No files matched your search

+1 -3
View File
@@ -923,9 +923,7 @@ impl Gen for ImportDeclaration<'_> {
p.print_soft_space();
p.print_str("from");
p.print_soft_space();
p.print_ascii_byte(b'"');
p.print_str(self.source.value.as_str());
p.print_ascii_byte(b'"');
p.print_string_literal(&self.source, false);
if let Some(with_clause) = &self.with_clause {
p.print_hard_space();
with_clause.print(p, ctx);
@@ -29,6 +29,8 @@ fn module_decl() {
test("export * as foo from 'foo'", "export * as foo from \"foo\";\n");
test("import x from './foo.js' with {}", "import x from \"./foo.js\" with {};\n");
test("import {} from './foo.js' with {}", "import {} from \"./foo.js\" with {};\n");
test("import {} from './a\"b.mjs';", "import {} from \"./a\\\"b.mjs\";\n");
test("import {} from './a\\nb.mjs';", "import {} from \"./a\\nb.mjs\";\n");
test("export * from './foo.js' with {}", "export * from \"./foo.js\" with {};\n");
test(
"export { default } from './foo.js' with { type: 'json' }",
@@ -41,6 +43,7 @@ fn module_decl() {
"import x from './foo.custom' with { 'type': 'json' }",
"import x from\"./foo.custom\"with{\"type\":\"json\"};",
);
test_minify("import {} from './a\"b.mjs';", "import{}from'./a\"b.mjs';");
test_minify(
"export { default } from './foo.js' with { type: 'json' }",
"export{default}from\"./foo.js\"with{type:\"json\"};",
@@ -309,7 +309,7 @@ import { 'string name' as alias } from 'module-name';
import defaultExport, { export1 } from 'module-name';
import defaultExport, * as name from 'module-name';
import 'module-name';
import {} from "mod";
import {} from 'mod';
export let name1, name2;
export const name3 = 1, name4 = 2;
export function functionName() {/* … */}