Skip to content

Commit 61cc2f4

Browse files
authored
fix(emit): surface diagnostic for invalid left hand side assignment (#271)
1 parent 9632305 commit 61cc2f4

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

Cargo.lock

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/transpiling/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ fn is_fatal_syntax_error(error_kind: &SyntaxError) -> bool {
594594
SyntaxError::LegacyDecimal |
595595
// expected expression
596596
SyntaxError::TS1109 |
597+
// invalid left hand side of assignment
598+
SyntaxError::TS2406 |
597599
// unterminated string literal
598600
SyntaxError::UnterminatedStrLit |
599601
// nullish coalescing with logical op
@@ -1442,6 +1444,20 @@ for (let i = 0; i < testVariable >> 1; i++) callCount++;
14421444
));
14431445
}
14441446

1447+
#[test]
1448+
fn diagnostic_invalid_left_hand_side_of_assignment() {
1449+
assert_eq!(get_diagnostic("(true ? a : b) = 1;"), concat!(
1450+
"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",
1451+
" (true ? a : b) = 1;\n",
1452+
" ~~~~~~~~~~~~~~\n",
1453+
"\n",
1454+
// for some reason, swc does the same diagnostic twice
1455+
"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",
1456+
" (true ? a : b) = 1;\n",
1457+
" ~~~~~~~~~~~~~~",
1458+
));
1459+
}
1460+
14451461
fn get_diagnostic(source: &str) -> String {
14461462
let specifier =
14471463
ModuleSpecifier::parse("https://deno.land/x/mod.ts").unwrap();

0 commit comments

Comments
 (0)