feature(rome_js_parser): JSX support in .js files
Enable JSX by default for all javascript files (not typescript)
MODIFY
crates/rome_analyze/tests/specs/flipBinExp.js
crates/rome_analyze/tests/specs/flipBinExp.js
@@ -24,7 +24,7 @@ const a = b ** c;
const a = b << c;
const a = b >> c;
-const a = b <<< c;
+const a = b >>> c;
const a = b & c;
const a = b | c;
const a = b ^ c;

MODIFY
crates/rome_analyze/tests/specs/flipBinExp.js.snap
crates/rome_analyze/tests/specs/flipBinExp.js.snap
---
source: crates/rome_analyze/tests/spec_tests.rs
-assertion_line: 92
expression: flipBinExp.js
-
---
# Input
```js
@@ -32,7 +30,7 @@ const a = b ** c;
const a = b << c;
const a = b >> c;
-const a = b <<< c;
+const a = b >>> c;
const a = b & c;
const a = b | c;
const a = b ^ c;
@@ -170,7 +168,7 @@ const a = b ^ c;
| @@ -25,6 +25,6 @@
24 24 | const a = b << c;
25 25 | const a = b >> c;
-26 26 | const a = b <<< c;
+26 26 | const a = b >>> c;
27 | - const a = b & c;
27 | + const a = c & b;
28 28 | const a = b | c;
@@ -181,7 +179,7 @@ const a = b ^ c;
```
| @@ -26,5 +26,5 @@
25 25 | const a = b >> c;
-26 26 | const a = b <<< c;
+26 26 | const a = b >>> c;
27 27 | const a = b & c;
28 | - const a = b | c;
28 | + const a = c | b;
@@ -191,7 +189,7 @@ const a = b ^ c;
```
| @@ -27,4 +27,4 @@
-26 26 | const a = b <<< c;
+26 26 | const a = b >>> c;
27 27 | const a = b & c;
28 28 | const a = b | c;
29 | - const a = b ^ c;

MODIFY
crates/rome_js_parser/src/lexer/mod.rs
crates/rome_js_parser/src/lexer/mod.rs
@@ -312,7 +312,7 @@ impl<'src> Lexer<'src> {
ReLexContext::BinaryOperator => self.re_lex_binary_operator(),
ReLexContext::TypeArgumentLessThan => self.re_lex_type_argument_less_than(),
ReLexContext::JsxIdentifier => self.re_lex_jsx_identifier(old_position),
- ReLexContext::JsxChild => self.lex_jsx_child_token(),
+ ReLexContext::JsxChild if !self.is_eof() => self.lex_jsx_child_token(),
_ => self.current(),
};

MODIFY
crates/rome_js_parser/src/syntax/jsx/mod.rs
crates/rome_js_parser/src/syntax/jsx/mod.rs
@@ -35,11 +35,12 @@ use super::typescript::parse_ts_type_arguments;
// <div />
// test_err jsx_or_type_assertion
+// // SCRIPT
// function f() {
// let a = <div>a</div>; // JSX
// let b = <string>b; // type assertion
// let c = <string>b<a>d; // type assertion
-// let d = <div>a</div>/; // ambigous: JSX or "type assertion a less than regex /div>/". Probably JSX.
+// let d = <div>a</div>/; // ambiguous: JSX or "type assertion a less than regex /div>/". Probably JSX.
// let d = <string>a</string>/;
// }

MODIFY
crates/rome_js_parser/test_data/inline/err/jsx_or_type_assertion.js
crates/rome_js_parser/test_data/inline/err/jsx_or_type_assertion.js
+// SCRIPT
function f() {
let a = <div>a</div>; // JSX
let b = <string>b; // type assertion
let c = <string>b<a>d; // type assertion
- let d = <div>a</div>/; // ambigous: JSX or "type assertion a less than regex /div>/". Probably JSX.
+ let d = <div>a</div>/; // ambiguous: JSX or "type assertion a less than regex /div>/". Probably JSX.
let d = <string>a</string>/;
}

MODIFY
crates/rome_js_syntax/src/source_type.rs
crates/rome_js_syntax/src/source_type.rs
@@ -238,9 +238,8 @@ fn compute_source_type_from_path_or_extension(
SourceType::d_ts().with_module_kind(ModuleKind::Script)
} else {
match extension {
- "js" | "mjs" => SourceType::js_module(),
"cjs" => SourceType::js_module().with_module_kind(ModuleKind::Script),
- "jsx" => SourceType::jsx(),
+ "js" | "mjs" | "jsx" => SourceType::jsx(),
"ts" | "mts" => SourceType::ts(),
"cts" => SourceType::ts().with_module_kind(ModuleKind::Script),
"tsx" => SourceType::tsx(),

feature(rome_js_parser): JSX support in .js files (#2674)

Enable JSX by default for all javascript files (not typescript)