Skip to content

Commit

Permalink
🦄 refactor: Add type info for regex
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 24, 2024
1 parent 88dd04c commit d782ee8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ public static Swc4jAstTokenTextValue<Double> createNumber(
* @return the ast token regex
* @since 0.2.0
*/
public static Swc4jAstTokenTextValueFlags createRegex(
public static Swc4jAstTokenTextValueFlags<String> createRegex(
String text, String value, String flags, int startPosition, int endPosition, boolean lineBreakAhead) {
return new Swc4jAstTokenTextValueFlags(
return new Swc4jAstTokenTextValueFlags<>(
Swc4jAstTokenType.Regex, text, value, flags, startPosition, endPosition, lineBreakAhead);
}

Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/caoccao/javet/swc4j/TestSwc4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void testParseJsxWithDefaultOptions() throws Swc4jCoreException {
assertNull(output.getTokens());
}

@SuppressWarnings("unchecked")
@Test
public void testParseTypeScriptWithCaptureTokens() throws Swc4jCoreException {
Swc4jParseOptions options = new Swc4jParseOptions()
Expand Down Expand Up @@ -240,16 +241,16 @@ public void testParseTypeScriptWithCaptureTokens() throws Swc4jCoreException {
parseAndAssert("1 &&= 2", options, Swc4jAstTokenType.AndAssign, "&&=", 2, 5, 1, 3);
parseAndAssert("1 ||= 2", options, Swc4jAstTokenType.OrAssign, "||=", 2, 5, 1, 3);
parseAndAssert("1 ??= 2", options, Swc4jAstTokenType.NullishAssign, "??=", 2, 5, 1, 3);
// TextAndValue
// TextValue
assertTokenValue("/usr/bin/env -S -i node", parseAndAssert("#!/usr/bin/env -S -i node", options, Swc4jAstTokenType.Shebang, "#!/usr/bin/env -S -i node", 0, 25, 0, 1));
assertTokenValue("x", parseAndAssert("a = 'x';", options, Swc4jAstTokenType.Str, "'x'", 4, 7, 2, 4));
assertTokenValue(1D, parseAndAssert("a = 1;", options, Swc4jAstTokenType.Num, "1", 4, 5, 2, 4));
assertTokenValue(1.23D, parseAndAssert("a = -1.23;", options, Swc4jAstTokenType.Num, "1.23", 5, 9, 3, 5));
assertTokenValue(BigInteger.valueOf(1), parseAndAssert("a = 1n;", options, Swc4jAstTokenType.BigInt, "1n", 4, 6, 2, 4));
assertTokenValue(BigInteger.valueOf(1), parseAndAssert("a = -1n;", options, Swc4jAstTokenType.BigInt, "1n", 5, 7, 3, 5));
assertTokenValue(new BigInteger("1234567890123456789012345678901234567890"), parseAndAssert("a = 1234567890123456789012345678901234567890n;", options, Swc4jAstTokenType.BigInt, "1234567890123456789012345678901234567890n", 4, 45, 2, 4));
// Atom - Tri
Swc4jAstTokenTextValueFlags astTokenRegex = (Swc4jAstTokenTextValueFlags) parseAndAssert("a = /x/ig;", options, Swc4jAstTokenType.Regex, "x/ig", 5, 9, 3, 5);
// TextValueFlags
Swc4jAstTokenTextValueFlags<String> astTokenRegex = (Swc4jAstTokenTextValueFlags<String>) parseAndAssert("a = /x/ig;", options, Swc4jAstTokenType.Regex, "x/ig", 5, 9, 3, 5);
assertEquals("x", astTokenRegex.getValue());
assertEquals("ig", astTokenRegex.getFlags());
assertTokenValue("a ", parseAndAssert("`a ${b} c`", options, Swc4jAstTokenType.Template, "a ", 1, 3, 1, 7));
Expand Down

0 comments on commit d782ee8

Please sign in to comment.