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(ecma/parser): parse JSX with ASI #6577

Merged
merged 4 commits into from Dec 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/swc_ecma_parser/src/lexer/state.rs
Expand Up @@ -25,6 +25,8 @@ pub(super) struct State {
pub next_regexp: Option<BytePos>,
/// if line break exists between previous token and new token?
pub had_line_break: bool,
/// if line break exists before last?
pub had_line_break_before_last: bool,
/// TODO: Remove this field.
is_first: bool,
pub start: BytePos,
Expand Down Expand Up @@ -352,8 +354,10 @@ impl<'a, I: Input> Iterator for Lexer<'a, I> {
});
}
}

self.state.update(start, token);
self.state.prev_hi = self.last_pos();
self.state.had_line_break_before_last = self.had_line_break_before_last();
}

token.map(|token| {
Expand All @@ -376,6 +380,7 @@ impl State {
next_regexp: None,
is_first: true,
had_line_break: false,
had_line_break_before_last: false,
prev_hi: start_pos,
context,
token_type: None,
Expand Down Expand Up @@ -438,6 +443,7 @@ impl State {
start,
next,
self.had_line_break,
self.had_line_break_before_last,
self.is_expr_allowed,
);
}
Expand All @@ -451,6 +457,7 @@ impl State {
start: BytePos,
next: &Token,
had_line_break: bool,
had_line_break_before_last: bool,
is_expr_allowed: bool,
) -> bool {
let is_next_keyword = matches!(*next, Word(Word::Keyword(..)));
Expand Down Expand Up @@ -544,7 +551,7 @@ impl State {
TokenType::Keyword(Let)
| TokenType::Keyword(Const)
| TokenType::Keyword(Var)
if had_line_break =>
if had_line_break_before_last =>
{
true
}
Expand Down
32 changes: 32 additions & 0 deletions crates/swc_ecma_parser/tests/jsx/basic/issue-6522/input.js
@@ -0,0 +1,32 @@
let x
<Comp></Comp>

let x

<Comp></Comp>

let x;
<Comp></Comp>

var x
<Comp></Comp>

var x;
<Comp></Comp>

function x() {
let x
<div />
}

{ foo: 'test' }
<Comp></Comp>

function test1() {}
<Comp></Comp>

class Foo {}
<>
<Comp></Comp>
<Comp></Comp>
</>