Skip to content

Commit

Permalink
Fix errors, run UPDATE=1 cargo test from tools/generate-code
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Nov 12, 2024
1 parent b8c3eb6 commit d6ae7f6
Show file tree
Hide file tree
Showing 7 changed files with 2,736 additions and 1,536 deletions.
4 changes: 3 additions & 1 deletion crates/swc_css_visit/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84590,7 +84590,9 @@ impl<V: ?Sized + Fold> FoldWith<V> for Token {
let raw = { <swc_atoms::Atom as FoldWith<V>>::fold_with(raw, visitor) };
Token::BadUrl { raw }
}
Token::Delim { value } => Token::Delim { value },
Token::Delim { value } => {
Token::Delim { value }
}
Token::Number {
value,
raw,
Expand Down
3 changes: 1 addition & 2 deletions crates/swc_ecma_ast/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::{
TsTypeParamInstantiation,
},
BigInt, ComputedPropName, ContentTagContent, ContentTagEnd, ContentTagStart, EmptyStmt, Id,
Ident, Number,
BigInt, ComputedPropName, EmptyStmt, Id, Ident, IdentName, Number,
Ident, IdentName, Number,
};

#[ast_node]
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_ast/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ impl Expr {
Expr::JSXEmpty(e) => e.span = span,
Expr::JSXElement(e) => e.span = span,
Expr::JSXFragment(e) => e.span = span,
Expr::ContentTagExpression(e) => e.span = span,
Expr::PrivateName(e) => e.span = span,
Expr::OptChain(e) => e.span = span,
Expr::Lit(e) => e.set_span(span),
Expand Down
153 changes: 9 additions & 144 deletions crates/swc_ecma_parser/src/lexer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ impl Lexer<'_> {
}

fn next_token(&mut self, start: &mut BytePos) -> Result<Option<Token>, Error> {
if self.state.content_tag_template == ContentTagState::Reading {
return Ok(Some(self.read_content_tag_template()?));
}

if self.state.content_tag_template == ContentTagState::Ending {
return Ok(Some(self.end_content_tag_template()?));
}

if let Some(start) = self.state.next_regexp {
return Ok(Some(self.read_regexp(start)?));
}
Expand Down Expand Up @@ -361,149 +369,6 @@ impl Iterator for Lexer<'_> {
fn next(&mut self) -> Option<Self::Item> {
let mut start = self.cur_pos();

let res = (|| -> Result<Option<_>, _> {
if self.state.content_tag_template == ContentTagState::Reading {
return Ok(Some(self.read_content_tag_template()?));
}

if self.state.content_tag_template == ContentTagState::Ending {
return Ok(Some(self.end_content_tag_template()?));
}

if let Some(start) = self.state.next_regexp {
return Ok(Some(self.read_regexp(start)?));
}

if self.state.is_first {
if let Some(shebang) = self.read_shebang()? {
return Ok(Some(Token::Shebang(shebang)));
}
}

self.state.had_line_break = self.state.is_first;
self.state.is_first = false;

// skip spaces before getting next character, if we are allowed to.
if self.state.can_skip_space() {
self.skip_space::<true>()?;
start = self.input.cur_pos();
};

match self.input.cur() {
Some(..) => {}
// End of input.
None => {
if let Some(comments) = self.comments.as_mut() {
let comments_buffer = self.comments_buffer.as_mut().unwrap();
let last = self.state.prev_hi;

// move the pending to the leading or trailing
for c in comments_buffer.take_pending_leading() {
// if the file had no tokens and no shebang, then treat any
// comments in the leading comments buffer as leading.
// Otherwise treat them as trailing.
if last == self.start_pos {
comments_buffer.push(BufferedComment {
kind: BufferedCommentKind::Leading,
pos: last,
comment: c,
});
} else {
comments_buffer.push(BufferedComment {
kind: BufferedCommentKind::Trailing,
pos: last,
comment: c,
});
}
}

// now fill the user's passed in comments
for comment in comments_buffer.take_comments() {
match comment.kind {
BufferedCommentKind::Leading => {
comments.add_leading(comment.pos, comment.comment);
}
BufferedCommentKind::Trailing => {
comments.add_trailing(comment.pos, comment.comment);
}
}
}
}

return Ok(None);
}
};

// println!(
// "\tContext: ({:?}) {:?}",
// self.input.cur().unwrap(),
// self.state.context.0
// );

self.state.start = start;

if self.syntax.jsx() && !self.ctx.in_property_name && !self.ctx.in_type {
//jsx
if self.state.context.current() == Some(TokenContext::JSXExpr) {
return self.read_jsx_token();
}

let c = self.cur();
if let Some(c) = c {
if self.state.context.current() == Some(TokenContext::JSXOpeningTag)
|| self.state.context.current() == Some(TokenContext::JSXClosingTag)
{
if c.is_ident_start() {
return self.read_jsx_word().map(Some);
}

if c == '>' {
unsafe {
// Safety: cur() is Some('>')
self.input.bump();
}
return Ok(Some(Token::JSXTagEnd));
}

if (c == '\'' || c == '"')
&& self.state.context.current() == Some(TokenContext::JSXOpeningTag)
{
return self.read_jsx_str(c).map(Some);
}
}

if c == '<' && self.state.is_expr_allowed && self.input.peek() != Some('!') {
let had_line_break_before_last = self.had_line_break_before_last();
let cur_pos = self.input.cur_pos();

unsafe {
// Safety: cur() is Some('<')
self.input.bump();
}

if had_line_break_before_last && self.is_str("<<<<<< ") {
let span = Span::new(cur_pos, cur_pos + BytePos(7), Default::default());

self.emit_error_span(span, SyntaxError::TS1185);
self.skip_line_comment(6);
self.skip_space::<true>()?;
return self.read_token();
}

return Ok(Some(Token::JSXTagStart));
}
}
}

if let Some(TokenContext::Tpl {
start: start_pos_of_tpl,
}) = self.state.context.current()
{
return self.read_tmpl_token(start_pos_of_tpl).map(Some);
}

self.read_token()
})();
let res = self.next_token(&mut start);

let token = match res.map_err(Token::Error).map_err(Some) {
Expand Down Expand Up @@ -556,8 +421,8 @@ impl State {
tpl_start: BytePos::DUMMY,
context,
syntax,
content_tag_template: ContentTagState::None,
token_type: None,
content_tag_template: ContentTagState::None,
}
}
}
Expand Down
Loading

0 comments on commit d6ae7f6

Please sign in to comment.