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(emit): surface diagnostic for invalid left hand side assignment #271

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
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