Skip to content

Commit

Permalink
✨ feat: Add at, dot to tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 22, 2024
1 parent c70c9ca commit 667d187
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rust/src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ pub fn token_and_spans_to_java_list<'local>(
},
Token::Arrow => java_ast_token_factory.create_generic_operator(env, AstTokenType::Arrow, index_range),
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),
_ => java_ast_token_factory.create_unknown(env, &text, index_range),
};
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 @@ -75,6 +75,8 @@ pub enum AstTokenType {
IdentOther, // 40
Arrow, // 41
Hash, // 42
At, // 43
Dot, // 44
}

impl IdentifiableEnum<AstTokenType> for AstTokenType {
Expand Down Expand Up @@ -122,6 +124,8 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
AstTokenType::IdentOther => 40,
AstTokenType::Arrow => 41,
AstTokenType::Hash => 42,
AstTokenType::At => 43,
AstTokenType::Dot => 44,
_ => 0,
}
}
Expand Down Expand Up @@ -169,6 +173,8 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
40 => AstTokenType::IdentOther,
41 => AstTokenType::Arrow,
42 => AstTokenType::Hash,
43 => AstTokenType::At,
44 => AstTokenType::Dot,
_ => AstTokenType::Unknown,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public enum Swc4jAstTokenType {
// Operator
Arrow(41, "=>", false, true),
Hash(42, "#", false, true),
At(43, "@", false, true),
Dot(44, ".", false, true),
;

private static final int LENGTH = values().length;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/caoccao/javet/swc4j/TestSwc4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void testParseTypeScriptWithCaptureTokens() throws Swc4jCoreException {
parseAndAssert("測試", options, Swc4jAstTokenType.IdentOther, "測試", 0, 2);
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);
}

@Test
Expand Down

0 comments on commit 667d187

Please sign in to comment.