Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn test() {
"a! != b;",
"a! !== b;",
];

let fail = vec![
"a! == b;",
"a! === b;",
Expand All @@ -163,8 +164,8 @@ fn test() {
"(a==b)! ==c;",
"a! = b;",
"(obj = new new OuterObj().InnerObj).Name! = c;",
"(a=b)! =c;",
];

// let fix = vec![
// // source, expected, rule_config?
// // ("f = 1 + d! == 2", "f = (1 + d!) == 2", None), TODO: Add suggest or the weird ;() fix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,3 @@ source: crates/oxc_linter/src/tester.rs
· ─────────────────────────────────────────────
╰────
help: Remove the "!", or wrap the left-hand side in parentheses.

⚠ typescript-eslint(no-confusing-non-null-assertion): Confusing combinations of non-null assertion and assignment like "a! = b", which looks very similar to not equal "a != b".
╭─[no_confusing_non_null_assertion.tsx:1:1]
1 │ (a=b)! =c;
· ─────────
╰────
help: Remove the "!", or wrap the left-hand side in parentheses.
42 changes: 36 additions & 6 deletions crates/oxc_parser/src/js/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,44 @@ impl<'a> CoverGrammar<'a, Expression<'a>> for SimpleAssignmentTarget<'a> {
expr => SimpleAssignmentTarget::cover(expr, p),
}
}
Expression::TSAsExpression(expr) => SimpleAssignmentTarget::TSAsExpression(expr),
Expression::TSAsExpression(expr) => match expr.expression.get_inner_expression() {
Expression::Identifier(_)
| Expression::StaticMemberExpression(_)
| Expression::ComputedMemberExpression(_)
| Expression::PrivateFieldExpression(_) => {
SimpleAssignmentTarget::TSAsExpression(expr)
}
_ => p.fatal_error(diagnostics::invalid_assignment(expr.span())),
},
Expression::TSSatisfiesExpression(expr) => {
SimpleAssignmentTarget::TSSatisfiesExpression(expr)
}
Expression::TSNonNullExpression(expr) => {
SimpleAssignmentTarget::TSNonNullExpression(expr)
match expr.expression.get_inner_expression() {
Expression::Identifier(_)
| Expression::StaticMemberExpression(_)
| Expression::ComputedMemberExpression(_)
| Expression::PrivateFieldExpression(_) => {
SimpleAssignmentTarget::TSSatisfiesExpression(expr)
}
_ => p.fatal_error(diagnostics::invalid_assignment(expr.span())),
}
}
Expression::TSTypeAssertion(expr) => SimpleAssignmentTarget::TSTypeAssertion(expr),
Expression::TSNonNullExpression(expr) => match expr.expression.get_inner_expression() {
Expression::Identifier(_)
| Expression::StaticMemberExpression(_)
| Expression::ComputedMemberExpression(_)
| Expression::PrivateFieldExpression(_) => {
SimpleAssignmentTarget::TSNonNullExpression(expr)
}
_ => p.fatal_error(diagnostics::invalid_assignment(expr.span())),
},
Expression::TSTypeAssertion(expr) => match expr.expression.get_inner_expression() {
Expression::Identifier(_)
| Expression::StaticMemberExpression(_)
| Expression::ComputedMemberExpression(_)
| Expression::PrivateFieldExpression(_) => {
SimpleAssignmentTarget::TSTypeAssertion(expr)
}
_ => p.fatal_error(diagnostics::invalid_assignment(expr.span())),
},
Expression::TSInstantiationExpression(expr) => {
p.fatal_error(diagnostics::invalid_lhs_assignment(expr.span()))
}
Expand Down
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-12612-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(foo() as bar) = 123;
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-12612-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(<any>foo()) = 123;
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-12612-3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(foo() satisfies any) = 123;
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-12612-4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(foo() as number as any) = 123;
25 changes: 25 additions & 0 deletions tasks/coverage/misc/pass/oxc-12612.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Type assertions with valid assignment targets should parse successfully
// https://github.com/oxc-project/oxc/issues/12612

let a = 1;
let obj = { foo: 1 };

// Simple type assertions with identifiers
(a as any) = 42;
(<any>a) = 42;
(a satisfies number) = 42;

// Type assertions with member expressions
(obj.foo as any) = 42;
(<any>obj.foo) = 42;
(obj.foo satisfies number) = 42;

// Nested type assertions should work when the inner expression is assignable
(a as number as any) = 42;
(a satisfies number as any) = 42;
(<any>(a as number)) = 42;
(<number>(<any>a)) = 42;

// Mixed type assertions
(a! as any) = 42;
((a as any)!) = 42;
4 changes: 2 additions & 2 deletions tasks/coverage/snapshots/codegen_misc.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
codegen_misc Summary:
AST Parsed : 44/44 (100.00%)
Positive Passed: 44/44 (100.00%)
AST Parsed : 45/45 (100.00%)
Positive Passed: 45/45 (100.00%)
11 changes: 5 additions & 6 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11788,12 +11788,11 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
2 │ [...[] as T] = b;
╰────

× Invalid rest operator's argument.
╭─[babel/packages/babel-parser/test/fixtures/typescript/cast/destructuring-assignent-rest-invalid/input.ts:4:9]
3 │
4 │ 0, { ...({} as T)} = b;
· ─────────
5 │ [...([] as T)] = b;
× Cannot assign to this expression
╭─[babel/packages/babel-parser/test/fixtures/typescript/cast/destructuring-assignent-rest-invalid/input.ts:1:9]
1 │ 0, { ...{} as T} = b;
· ───────
2 │ [...[] as T] = b;
╰────

× Expected `=>` but found `;`
Expand Down
30 changes: 27 additions & 3 deletions tasks/coverage/snapshots/parser_misc.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parser_misc Summary:
AST Parsed : 44/44 (100.00%)
Positive Passed: 44/44 (100.00%)
Negative Passed: 48/48 (100.00%)
AST Parsed : 45/45 (100.00%)
Positive Passed: 45/45 (100.00%)
Negative Passed: 52/52 (100.00%)

× Cannot assign to 'arguments' in strict mode
╭─[misc/fail/arguments-eval.ts:1:10]
Expand Down Expand Up @@ -188,6 +188,30 @@ Negative Passed: 48/48 (100.00%)
· ──────────
╰────

× Cannot assign to this expression
╭─[misc/fail/oxc-12612-1.ts:1:2]
1 │ (foo() as bar) = 123;
· ────────────
╰────

× Cannot assign to this expression
╭─[misc/fail/oxc-12612-2.ts:1:2]
1 │ (<any>foo()) = 123;
· ──────────
╰────

× Cannot assign to this expression
╭─[misc/fail/oxc-12612-3.ts:1:2]
1 │ (foo() satisfies any) = 123;
· ───────────────────
╰────

× Cannot assign to this expression
╭─[misc/fail/oxc-12612-4.ts:1:2]
1 │ (foo() as number as any) = 123;
· ──────────────────────
╰────

× Unexpected token
╭─[misc/fail/oxc-169.js:2:1]
1 │ 1<(V=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V=uIV=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V<II>
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/snapshots/semantic_misc.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
semantic_misc Summary:
AST Parsed : 44/44 (100.00%)
Positive Passed: 28/44 (63.64%)
AST Parsed : 45/45 (100.00%)
Positive Passed: 29/45 (64.44%)
semantic Error: tasks/coverage/misc/pass/oxc-11593.ts
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1)]
Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/snapshots/transformer_misc.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
transformer_misc Summary:
AST Parsed : 44/44 (100.00%)
Positive Passed: 44/44 (100.00%)
AST Parsed : 45/45 (100.00%)
Positive Passed: 45/45 (100.00%)
Loading