Skip to content

Commit

Permalink
fix: error for more unterminated nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Apr 18, 2024
1 parent afe9c68 commit 61108ec
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/swc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn ensure_no_specific_syntax_errors(parsed_source: &ParsedSource) -> Result<
.diagnostics()
.iter()
.filter(|e| {
eprintln!("ERROR: {:?}", e.kind);
matches!(
e.kind,
// unexpected eof
Expand All @@ -124,6 +125,12 @@ pub fn ensure_no_specific_syntax_errors(parsed_source: &ParsedSource) -> Result<
SyntaxError::ExpectedDigit { .. } |
SyntaxError::ExpectedSemiForExprStmt { .. } |
SyntaxError::ExpectedUnicodeEscape |
// various unterminated
SyntaxError::UnterminatedStrLit |
SyntaxError::UnterminatedBlockComment |
SyntaxError::UnterminatedJSXContents |
SyntaxError::UnterminatedRegExp |
SyntaxError::UnterminatedTpl |
// unexpected token
SyntaxError::Unexpected { .. } |
// Merge conflict marker
Expand Down Expand Up @@ -293,6 +300,19 @@ mod tests {
);
}

#[test]
fn it_should_error_for_exected_string_literal() {
run_non_fatal_diagnostic_test(
"./test.ts",
"var foo = 'test",
concat!(
"Unterminated string constant at file:///test.ts:1:11\n\n",
" var foo = 'test\n",
" ~~~~~"
),
);
}

#[test]
fn it_should_error_for_merge_conflict_marker() {
run_non_fatal_diagnostic_test(
Expand Down

0 comments on commit 61108ec

Please sign in to comment.