Skip to content

Commit c9a5c6d

Browse files
Copilotsapphi-red
andcommitted
Merge main branch and resolve conflicts
Merged latest main branch into the PR. Resolved conflicts by keeping both the new escaping tests and our import.meta tests. All 23 inject_global_variables tests pass. Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent f550e2e commit c9a5c6d

File tree

4 files changed

+109
-38
lines changed

4 files changed

+109
-38
lines changed

apps/oxlint/src/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ mod test {
13251325
}
13261326

13271327
#[test]
1328-
#[cfg(not(target_endian = "big"))]
1328+
#[cfg(all(not(target_os = "windows"), not(target_endian = "big")))]
13291329
fn test_tsgolint_config_error() {
13301330
let args = &["--type-aware"];
13311331
Tester::new().with_cwd("fixtures/tsgolint_config_error".into()).test_and_snapshot(args);

crates/oxc_transformer_plugins/tests/integrations/inject_global_variables.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,67 @@ fn is_reference() {
364364
);
365365
}
366366

367+
#[test]
368+
fn escape_source_with_double_quote() {
369+
// Test case from issue: source string containing a double quote should be escaped
370+
let config =
371+
InjectGlobalVariablesConfig::new(vec![InjectImport::default_specifier("foo\"", "a")]);
372+
test(
373+
"console.log(a)",
374+
r#"
375+
import a from "foo\"";
376+
console.log(a)
377+
"#,
378+
config,
379+
);
380+
}
381+
382+
#[test]
383+
fn escape_source_with_single_quote() {
384+
// Source string containing a single quote should be escaped when using single quotes
385+
let config =
386+
InjectGlobalVariablesConfig::new(vec![InjectImport::default_specifier("foo'", "a")]);
387+
// Note: The test helper uses single_quote: true in codegen options
388+
test(
389+
"console.log(a)",
390+
r"
391+
import a from 'foo\'';
392+
console.log(a)
393+
",
394+
config,
395+
);
396+
}
397+
398+
#[test]
399+
fn escape_source_with_backslash() {
400+
// Source string containing a backslash should be escaped
401+
let config =
402+
InjectGlobalVariablesConfig::new(vec![InjectImport::default_specifier("foo\\bar", "a")]);
403+
test(
404+
"console.log(a)",
405+
r"
406+
import a from 'foo\\bar';
407+
console.log(a)
408+
",
409+
config,
410+
);
411+
}
412+
413+
#[test]
414+
fn escape_source_with_newline() {
415+
// Source string containing a newline should be escaped
416+
let config =
417+
InjectGlobalVariablesConfig::new(vec![InjectImport::default_specifier("foo\nbar", "a")]);
418+
test(
419+
"console.log(a)",
420+
r"
421+
import a from 'foo\nbar';
422+
console.log(a)
423+
",
424+
config,
425+
);
426+
}
427+
367428
#[test]
368429
fn import_meta() {
369430
// handles import.meta

napi/transform/test/transform.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,16 @@ describe('inject plugin', () => {
312312
});
313313
expect(ret.code).toEqual('import $inject_Object_assign from "foo";\nlet _ = $inject_Object_assign;\n');
314314
});
315+
316+
it('escapes quotes in source module name', () => {
317+
const code = 'console.log(a)';
318+
const ret = transform('test.tsx', code, {
319+
inject: {
320+
a: 'foo"',
321+
},
322+
});
323+
expect(ret.code).toEqual('import a from "foo\\"";\nconsole.log(a);\n');
324+
});
315325
});
316326

317327
describe('legacy decorator', () => {

pnpm-lock.yaml

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)