Skip to content

Commit

Permalink
✨ feat: Add semi, comma to tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 22, 2024
1 parent 82f13cb commit 80d601e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rust/src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ pub fn token_and_spans_to_java_list<'local>(
Token::RBrace => {
java_ast_token_factory.create_generic_operator(env, AstTokenType::RBrace, index_range, line_break_ahead)
}
Token::Semi => {
java_ast_token_factory.create_generic_operator(env, AstTokenType::Semi, index_range, line_break_ahead)
}
Token::Comma => {
java_ast_token_factory.create_generic_operator(env, AstTokenType::Comma, index_range, line_break_ahead)
}
_ => java_ast_token_factory.create_unknown(env, &text, index_range, line_break_ahead),
};
java_array_list.add(env, &list, &ast_token);
Expand Down
6 changes: 6 additions & 0 deletions rust/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub enum AstTokenType {
RBracket, // 50
LBrace, // 51
RBrace, // 52
Semi, // 53
Comma, // 54
}

impl IdentifiableEnum<AstTokenType> for AstTokenType {
Expand Down Expand Up @@ -142,6 +144,8 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
AstTokenType::RBracket => 50,
AstTokenType::LBrace => 51,
AstTokenType::RBrace => 52,
AstTokenType::Semi => 53,
AstTokenType::Comma => 54,
_ => 0,
}
}
Expand Down Expand Up @@ -199,6 +203,8 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
50 => AstTokenType::RBracket,
51 => AstTokenType::LBrace,
52 => AstTokenType::RBrace,
53 => AstTokenType::Semi,
54 => AstTokenType::Comma,
_ => AstTokenType::Unknown,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public enum Swc4jAstTokenType {
RBracket(50, "]", false, true),
LBrace(51, "{", false, true),
RBrace(52, "}", false, true),
Semi(53, ";", false, true),
Comma(54, ",", false, true),
;

private static final int LENGTH = values().length;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/caoccao/javet/swc4j/TestSwc4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public void testParseTypeScriptWithCaptureTokens() throws Swc4jCoreException {
parseAndAssert("a[0]", options, Swc4jAstTokenType.RBracket, "]", 3, 4, 3, 4);
parseAndAssert("a={}", options, Swc4jAstTokenType.LBrace, "{", 2, 3, 2, 4);
parseAndAssert("a={}", options, Swc4jAstTokenType.RBrace, "}", 3, 4, 3, 4);
parseAndAssert(";", options, Swc4jAstTokenType.Semi, ";", 0, 1);
parseAndAssert("let a, b;", options, Swc4jAstTokenType.Comma, ",", 5, 6, 2, 5);
}

@Test
Expand Down

0 comments on commit 80d601e

Please sign in to comment.