Skip to content

Commit

Permalink
fix: lex ident with emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed May 6, 2024
1 parent 795e1fe commit 9328c99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 67 deletions.
51 changes: 24 additions & 27 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,33 +154,30 @@ impl<'s> Lexer<'s> {
self.consume()?;
while self.cur().is_some() {
self.consume_comments()?;
let c = self.cur()?;
if c < '\u{80}' {
// https://drafts.csswg.org/css-syntax/#consume-token
match c {
c if is_white_space(c) => self.consume_space()?,
C_QUOTATION_MARK => self.consume_string(visitor, C_QUOTATION_MARK)?,
C_NUMBER_SIGN => self.consume_number_sign(visitor)?,
C_APOSTROPHE => self.consume_string(visitor, C_APOSTROPHE)?,
C_LEFT_PARENTHESIS => self.consume_left_parenthesis(visitor)?,
C_RIGHT_PARENTHESIS => self.consume_right_parenthesis(visitor)?,
C_PLUS_SIGN => self.consume_plus_sign()?,
C_COMMA => self.consume_comma(visitor)?,
C_HYPHEN_MINUS => self.consume_minus(visitor)?,
C_FULL_STOP => self.consume_full_stop(visitor)?,
C_COLON => self.consume_potential_pseudo(visitor)?,
C_SEMICOLON => self.consume_semicolon(visitor)?,
C_LESS_THAN_SIGN => self.consume_less_than_sign()?,
C_AT_SIGN => self.consume_at_sign(visitor)?,
C_LEFT_SQUARE => self.consume_delim()?,
C_REVERSE_SOLIDUS => self.consume_reverse_solidus(visitor)?,
C_RIGHT_SQUARE => self.consume_delim()?,
C_LEFT_CURLY => self.consume_left_curly(visitor)?,
C_RIGHT_CURLY => self.consume_right_curly(visitor)?,
c if is_digit(c) => self.consume_numeric_token()?,
c if is_ident_start(c) => self.consume_ident_like(visitor)?,
_ => self.consume_delim()?,
}
// https://drafts.csswg.org/css-syntax/#consume-token
match self.cur()? {
c if is_white_space(c) => self.consume_space()?,
C_QUOTATION_MARK => self.consume_string(visitor, C_QUOTATION_MARK)?,
C_NUMBER_SIGN => self.consume_number_sign(visitor)?,
C_APOSTROPHE => self.consume_string(visitor, C_APOSTROPHE)?,
C_LEFT_PARENTHESIS => self.consume_left_parenthesis(visitor)?,
C_RIGHT_PARENTHESIS => self.consume_right_parenthesis(visitor)?,
C_PLUS_SIGN => self.consume_plus_sign()?,
C_COMMA => self.consume_comma(visitor)?,
C_HYPHEN_MINUS => self.consume_minus(visitor)?,
C_FULL_STOP => self.consume_full_stop(visitor)?,
C_COLON => self.consume_potential_pseudo(visitor)?,
C_SEMICOLON => self.consume_semicolon(visitor)?,
C_LESS_THAN_SIGN => self.consume_less_than_sign()?,
C_AT_SIGN => self.consume_at_sign(visitor)?,
C_LEFT_SQUARE => self.consume_delim()?,
C_REVERSE_SOLIDUS => self.consume_reverse_solidus(visitor)?,
C_RIGHT_SQUARE => self.consume_delim()?,
C_LEFT_CURLY => self.consume_left_curly(visitor)?,
C_RIGHT_CURLY => self.consume_right_curly(visitor)?,
c if is_digit(c) => self.consume_numeric_token()?,
c if is_ident_start(c) => self.consume_ident_like(visitor)?,
_ => self.consume_delim()?,
}
}
Some(())
Expand Down
44 changes: 4 additions & 40 deletions tests/postcss_plugins/modules_local_by_default_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ fn not_localize_animation_name_in_a_var_function() {
".foo { animation-name: var(--bar); }",
":local(.foo) { animation-name: var(--bar); }",
);
}

#[test]
fn not_localize_animation_name_in_a_var_function_2() {
test(
".foo { animation-name: vAr(--bar); }",
":local(.foo) { animation-name: vAr(--bar); }",
Expand All @@ -250,10 +246,6 @@ fn not_localize_animation_name_in_an_env_function() {
".foo { animation-name: env(bar); }",
":local(.foo) { animation-name: env(bar); }",
);
}

#[test]
fn not_localize_animation_name_in_an_env_function_2() {
test(
".foo { animation-name: eNv(bar); }",
":local(.foo) { animation-name: eNv(bar); }",
Expand Down Expand Up @@ -322,68 +314,40 @@ fn localize_animation_using_special_characters() {
".foo { animation: \\@bounce; }",
":local(.foo) { animation: :local(\\@bounce); }",
);
}

#[test]
fn localize_animation_using_special_characters_2() {
test(
".foo { animation: bou\\@nce; }",
":local(.foo) { animation: :local(bou\\@nce); }",
);
}

#[test]
fn localize_animation_using_special_characters_3() {
test(
".foo { animation: \\ as; }",
":local(.foo) { animation: :local(\\ as); }",
);
}

#[test]
fn localize_animation_using_special_characters_4() {
test(
".foo { animation: t\\ t; }",
":local(.foo) { animation: :local(t\\ t); }",
);
}

#[test]
fn localize_animation_using_special_characters_5() {
test(
".foo { animation: -\\a; }",
":local(.foo) { animation: :local(-\\a); }",
);
}

#[test]
fn localize_animation_using_special_characters_6() {
test(
".foo { animation: --\\a; }",
":local(.foo) { animation: :local(--\\a); }",
);
}

#[test]
fn localize_animation_using_special_characters_7() {
test(
".foo { animation: \\a; }",
":local(.foo) { animation: :local(\\a); }",
);
}

#[test]
fn localize_animation_using_special_characters_8() {
test(
".foo { animation: -\\a; }",
":local(.foo) { animation: :local(-\\a); }",
);
}

#[test]
fn localize_animation_using_special_characters_9() {
test(
".foo { animation: --; }",
":local(.foo) { animation: :local(--); }",
);
test(
".foo { animation: 😃bounce😃; }",
":local(.foo) { animation: :local(😃bounce😃); }",
);
}

0 comments on commit 9328c99

Please sign in to comment.