Skip to content

Commit a113f7e

Browse files
committedMar 17, 2025·
fix(parser): error when } and > appear in JSXText (#9777)
closes #9770
1 parent ea7e3f0 commit a113f7e

13 files changed

+228
-235
lines changed
 

‎crates/oxc_codegen/src/gen.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2578,8 +2578,9 @@ impl Gen for JSXText<'_> {
25782578

25792579
impl Gen for JSXSpreadChild<'_> {
25802580
fn r#gen(&self, p: &mut Codegen, _ctx: Context) {
2581-
p.print_str("...");
2581+
p.print_str("{...");
25822582
p.print_expression(&self.expression);
2583+
p.print_ascii_byte(b'}');
25832584
}
25842585
}
25852586

@@ -2588,7 +2589,7 @@ impl Gen for JSXChild<'_> {
25882589
match self {
25892590
Self::Fragment(fragment) => fragment.print(p, ctx),
25902591
Self::Element(el) => el.print(p, ctx),
2591-
Self::Spread(spread) => p.print_expression(&spread.expression),
2592+
Self::Spread(spread) => spread.print(p, ctx),
25922593
Self::ExpressionContainer(expr_container) => expr_container.print(p, ctx),
25932594
Self::Text(text) => text.print(p, ctx),
25942595
}

‎crates/oxc_linter/src/rules/eslint/no_unused_expressions.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ fn test() {
292292
"
293293
namespace Foo {
294294
'use strict';
295-
295+
296296
export class Foo {}
297297
export class Bar {}
298298
}
@@ -303,7 +303,7 @@ fn test() {
303303
"
304304
function foo() {
305305
'use strict';
306-
306+
307307
return null;
308308
}
309309
",
@@ -383,7 +383,7 @@ fn test() {
383383
("<></>", Some(serde_json::json!([{ "enforceForJSX": true }]))), // { "parserOptions": { "ecmaFeatures": { "jsx": true } } },
384384
("class C { static { 'use strict'; } }", None), // { "ecmaVersion": 2022 },
385385
(
386-
"class C { static {
386+
"class C { static {
387387
'foo'
388388
'bar'
389389
} }",
@@ -479,7 +479,7 @@ fn test() {
479479
namespace Foo {
480480
export class Foo {}
481481
export class Bar {}
482-
482+
483483
'use strict';
484484
}
485485
",
@@ -489,7 +489,7 @@ fn test() {
489489
"
490490
function foo() {
491491
const foo = true;
492-
492+
493493
'use strict';
494494
}
495495
",
@@ -519,13 +519,13 @@ fn test() {
519519
",
520520
None,
521521
),
522-
(
523-
"
524-
declare const foo: number | undefined;
525-
<any>foo;
526-
",
527-
None,
528-
),
522+
// (
523+
// "
524+
// declare const foo: number | undefined;
525+
// <any>foo;
526+
// ",
527+
// None,
528+
// ),
529529
(
530530
"
531531
declare const foo: number | undefined;

‎crates/oxc_linter/src/rules/react/no_unescaped_entities.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,11 @@ impl Rule for NoUnescapedEntities {
7676
}
7777

7878
// NOTE: If we add substantially more characters, we should consider using a hash set instead.
79-
pub const CHARS: [char; 4] = ['>', '"', '\'', '}'];
79+
pub const CHARS: [char; 2] = ['"', '\''];
8080

8181
pub const DEFAULTS: Map<char, &'static [&'static str]> = phf_map! {
82-
'>' => &["&gt;"],
8382
'"' => &["&quot;", "&ldquo;", "&#34;", "&rdquo;"],
8483
'\'' => &["&apos;", "&lsquo;", "&#39;", "&rsquo;"],
85-
'}' => &["&#125;"],
8684
};
8785

8886
#[test]

‎crates/oxc_linter/src/rules/typescript/array_type.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,10 @@ fn test() {
10111011
"let x: Array<undefined> = [undefined] as undefined[];",
10121012
Some(serde_json::json!([{"default":"array-simple"}])),
10131013
),
1014-
(
1015-
"let y: string[] = <Array<string>>['2'];",
1016-
Some(serde_json::json!([{"default":"array-simple"}])),
1017-
),
1014+
// (
1015+
// "let y: string[] = <Array<string>>['2'];",
1016+
// Some(serde_json::json!([{"default":"array-simple"}])),
1017+
// ),
10181018
("let z: Array = [3, '4'];", Some(serde_json::json!([{"default":"array-simple"}]))),
10191019
(
10201020
"let ya = [[1, '2']] as [number, string][];",
@@ -1062,7 +1062,7 @@ fn test() {
10621062
"let x: Array<undefined> = [undefined] as undefined[];",
10631063
Some(serde_json::json!([{"default":"array"}])),
10641064
),
1065-
("let y: string[] = <Array<string>>['2'];", Some(serde_json::json!([{"default":"array"}]))),
1065+
// ("let y: string[] = <Array<string>>['2'];", Some(serde_json::json!([{"default":"array"}]))),
10661066
("let z: Array = [3, '4'];", Some(serde_json::json!([{"default":"array"}]))),
10671067
("type Arr<T> = Array<T>;", Some(serde_json::json!([{"default":"array"}]))),
10681068
// ("
@@ -1706,5 +1706,8 @@ fn test() {
17061706
),
17071707
];
17081708

1709-
Tester::new(ArrayType::NAME, ArrayType::PLUGIN, pass, fail).expect_fix(fix).test_and_snapshot();
1709+
Tester::new(ArrayType::NAME, ArrayType::PLUGIN, pass, fail)
1710+
.change_rule_path_extension("ts")
1711+
.expect_fix(fix)
1712+
.test_and_snapshot();
17101713
}

‎crates/oxc_linter/src/snapshots/eslint_no_unused_expressions.snap

+3-9
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ source: crates/oxc_linter/src/tester.rs
241241

242242
eslint(no-unused-expressions): Disallow unused expressions
243243
╭─[no_unused_expressions.tsx:2:4]
244-
1class C { static {
244+
1class C { static {
245245
2 │ 'foo'
246246
· ─────
247247
3 │ 'bar'
@@ -378,7 +378,7 @@ source: crates/oxc_linter/src/tester.rs
378378

379379
eslint(no-unused-expressions): Disallow unused expressions
380380
╭─[no_unused_expressions.tsx:6:6]
381-
5
381+
5
382382
6'use strict';
383383
· ─────────────
384384
7 │ }
@@ -387,7 +387,7 @@ source: crates/oxc_linter/src/tester.rs
387387

388388
eslint(no-unused-expressions): Disallow unused expressions
389389
╭─[no_unused_expressions.tsx:5:6]
390-
4
390+
4
391391
5'use strict';
392392
· ─────────────
393393
6 │ }
@@ -442,12 +442,6 @@ source: crates/oxc_linter/src/tester.rs
442442
╰────
443443
help: Consider removing this expression
444444

445-
× Expected `<` but found `EOF`
446-
╭─[no_unused_expressions.tsx:4:10]
447-
3 │ <any>foo;
448-
4 │
449-
╰────
450-
451445
⚠ eslint(no-unused-expressions): Disallow unused expressions
452446
╭─[no_unused_expressions.tsx:3:4]
453447
2 │ declare const foo: number | undefined;

‎crates/oxc_linter/src/snapshots/react_no_unescaped_entities.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
source: crates/oxc_linter/src/tester.rs
33
---
4-
eslint-plugin-react(no-unescaped-entities): `>` can be escaped with &gt;
4+
× Unexpected token. Did you mean `{'>'}` or `&gt;`?
55
╭─[no_unescaped_entities.tsx:3:24]
66
2render: function() {
77
3return <>> babel-eslint</>;
8-
·
8+
·
99
4 │ }
1010
╰────
1111

12-
eslint-plugin-react(no-unescaped-entities): `>` can be escaped with &gt;
12+
× Unexpected token. Did you mean `{'>'}` or `&gt;`?
1313
╭─[no_unescaped_entities.tsx:5:47]
1414
4so is second
1515
5and here are some bad entities: ></>
16-
·
16+
·
1717
6 │ }
1818
╰────
1919

@@ -25,11 +25,11 @@ source: crates/oxc_linter/src/tester.rs
2525
5 │ }
2626
╰────
2727

28-
eslint-plugin-react(no-unescaped-entities): `}` can be escaped with &#125;
28+
× Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
2929
╭─[no_unescaped_entities.tsx:4:60]
3030
3render: function() {
3131
4return <>{"Unbalanced braces - babel-eslint"}}</>;
32-
·
32+
·
3333
5 │ }
3434
╰────
3535

0 commit comments

Comments
 (0)
Please sign in to comment.