Skip to content

Commit

Permalink
✨ feat: Add dotdotdot, bang, lparen, rparen to tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 22, 2024
1 parent 667d187 commit 1e85efb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rust/src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ pub fn token_and_spans_to_java_list<'local>(
Token::Hash => java_ast_token_factory.create_generic_operator(env, AstTokenType::Hash, index_range),
Token::At => java_ast_token_factory.create_generic_operator(env, AstTokenType::At, index_range),
Token::Dot => java_ast_token_factory.create_generic_operator(env, AstTokenType::Dot, index_range),
Token::DotDotDot => java_ast_token_factory.create_generic_operator(env, AstTokenType::DotDotDot, index_range),
Token::Bang => java_ast_token_factory.create_generic_operator(env, AstTokenType::Bang, index_range),
Token::LParen => java_ast_token_factory.create_generic_operator(env, AstTokenType::LParen, index_range),
Token::RParen => java_ast_token_factory.create_generic_operator(env, AstTokenType::RParen, index_range),
_ => java_ast_token_factory.create_unknown(env, &text, index_range),
};
java_array_list.add(env, &list, &ast_token);
Expand Down
12 changes: 12 additions & 0 deletions rust/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ pub enum AstTokenType {
Hash, // 42
At, // 43
Dot, // 44
DotDotDot, // 45
Bang, // 46
LParen, // 47
RParen, // 48
}

impl IdentifiableEnum<AstTokenType> for AstTokenType {
Expand Down Expand Up @@ -126,6 +130,10 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
AstTokenType::Hash => 42,
AstTokenType::At => 43,
AstTokenType::Dot => 44,
AstTokenType::DotDotDot => 45,
AstTokenType::Bang => 46,
AstTokenType::LParen => 47,
AstTokenType::RParen => 48,
_ => 0,
}
}
Expand Down Expand Up @@ -175,6 +183,10 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
42 => AstTokenType::Hash,
43 => AstTokenType::At,
44 => AstTokenType::Dot,
45 => AstTokenType::DotDotDot,
46 => AstTokenType::Bang,
47 => AstTokenType::LParen,
48 => AstTokenType::RParen,
_ => AstTokenType::Unknown,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public enum Swc4jAstTokenType {
Hash(42, "#", false, true),
At(43, "@", false, true),
Dot(44, ".", false, true),
DotDotDot(45, "...", false, true),
Bang(46, "!", false, true),
LParen(47, "(", false, true),
RParen(48, ")", false, true),
;

private static final int LENGTH = values().length;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/caoccao/javet/swc4j/TestSwc4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public void testParseTypeScriptWithCaptureTokens() throws Swc4jCoreException {
parseAndAssert("() => {}", options, Swc4jAstTokenType.Arrow, "=>", 3, 5, 2, 5);
parseAndAssert("class A { #abc; }", options, Swc4jAstTokenType.Hash, "#", 10, 11, 3, 7);
parseAndAssert("a.b", options, Swc4jAstTokenType.Dot, ".", 1, 2, 1, 3);
parseAndAssert("[...a]", options, Swc4jAstTokenType.DotDotDot, "...", 1, 4, 1, 4);
parseAndAssert("!true", options, Swc4jAstTokenType.Bang, "!", 0, 1, 0, 2);
parseAndAssert("a()", options, Swc4jAstTokenType.LParen, "(", 1, 2, 1, 3);
parseAndAssert("a()", options, Swc4jAstTokenType.RParen, ")", 2, 3, 2, 3);
}

@Test
Expand Down

0 comments on commit 1e85efb

Please sign in to comment.