Skip to content

Commit

Permalink
fix(parser): add missing ChainExpression in optional `TSInstantiati…
Browse files Browse the repository at this point in the history
…onExpression` (#7371)
  • Loading branch information
Boshen committed Nov 20, 2024
1 parent 7bf970a commit 666b6c1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/oxc/no_optional_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn test() {
("var x = a/*?.*/?.b", None),
("var x = '?.'?.['?.']", None),
("var x = '?.'?.['?.']", None),
("a?.c?.b<c>", None),
(
"var x = a?.b",
Some(serde_json::json!([{
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_linter/src/snapshots/no_optional_chaining.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ snapshot_kind: text
· ────────────
╰────

oxc(no-optional-chaining): Optional chaining is not allowed.
╭─[no_optional_chaining.tsx:1:1]
1a?.c?.b<c>
· ───────
╰────

⚠ oxc(no-optional-chaining): Optional chaining is not allowed.
╭─[no_optional_chaining.tsx:1:9]
1 │ var x = a?.b
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/examples/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use pico_args::Arguments;
fn main() -> Result<(), String> {
let mut args = Arguments::from_env();

let name = args.subcommand().ok().flatten().unwrap_or_else(|| String::from("test.js"));
let show_ast = args.contains("--ast");
let show_comments = args.contains("--comments");
let name = args.free_from_str().unwrap_or_else(|_| "test.js".to_string());

let path = Path::new(&name);
let source_text = fs::read_to_string(path).map_err(|_| format!("Missing '{name}'"))?;
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,15 @@ impl<'a> ParserImpl<'a> {
self.parse_tagged_template(lhs_span, expr, *in_optional_chain, type_parameters)?
}
Kind::LAngle | Kind::ShiftLeft => {
let optional_chain_span = (*in_optional_chain).then(|| self.end_span(lhs_span));
if let Some(Some(arguments)) =
self.try_parse(Self::parse_type_arguments_in_expression)
{
// `a?.c?.b<c>`
if let Some(optional_chain_span) = optional_chain_span {
*in_optional_chain = false;
lhs = self.map_to_chain_expression(optional_chain_span, lhs);
}
lhs = self.ast.expression_ts_instantiation(
self.end_span(lhs_span),
lhs,
Expand Down
4 changes: 1 addition & 3 deletions tasks/transform_conformance/snapshots/babel.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -1987,9 +1987,7 @@ after transform: ["C", "T"]
rebuilt : ["C"]

* type-arguments/optional-call/input.ts
Unresolved references mismatch:
after transform: ["Q", "T", "f", "x"]
rebuilt : ["f", "x"]
x Output mismatch

* type-arguments/tagged-template/input.ts
Unresolved references mismatch:
Expand Down

0 comments on commit 666b6c1

Please sign in to comment.