Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): add missing ChainExpression in optional TSInstantiationExpression #7371

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
1 │ a?.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
Loading