Skip to content

Commit

Permalink
fix(emit): surface diagnostic for invalid left hand side assignment (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Aug 22, 2024
1 parent 9632305 commit 61cc2f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/transpiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ fn is_fatal_syntax_error(error_kind: &SyntaxError) -> bool {
SyntaxError::LegacyDecimal |
// expected expression
SyntaxError::TS1109 |
// invalid left hand side of assignment
SyntaxError::TS2406 |
// unterminated string literal
SyntaxError::UnterminatedStrLit |
// nullish coalescing with logical op
Expand Down Expand Up @@ -1442,6 +1444,20 @@ for (let i = 0; i < testVariable >> 1; i++) callCount++;
));
}

#[test]
fn diagnostic_invalid_left_hand_side_of_assignment() {
assert_eq!(get_diagnostic("(true ? a : b) = 1;"), concat!(
"The left-hand side of an assignment expression must be a variable or a property access. at https://deno.land/x/mod.ts:1:1\n\n",
" (true ? a : b) = 1;\n",
" ~~~~~~~~~~~~~~\n",
"\n",
// for some reason, swc does the same diagnostic twice
"The left-hand side of an assignment expression must be a variable or a property access. at https://deno.land/x/mod.ts:1:1\n\n",
" (true ? a : b) = 1;\n",
" ~~~~~~~~~~~~~~",
));
}

fn get_diagnostic(source: &str) -> String {
let specifier =
ModuleSpecifier::parse("https://deno.land/x/mod.ts").unwrap();
Expand Down

0 comments on commit 61cc2f4

Please sign in to comment.