Skip to content

Commit

Permalink
🧪 test: Add testTranspileTypeScriptWithCaptureTokens()
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 22, 2024
1 parent 0911656 commit 0bf80ef
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/java/com/caoccao/javet/swc4j/TestSwc4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,29 @@ public void testTranspileJsxWithDefaultOptions() throws Swc4jCoreException {
assertNull(output.getSourceMap());
}

@Test
public void testTranspileTypeScriptWithCaptureTokens() throws Swc4jCoreException {
Swc4jTranspileOptions options = new Swc4jTranspileOptions()
.setMediaType(Swc4jMediaType.TypeScript)
.setCaptureTokens(true);
String code = "function add加法(a變量:number, b變量:number) { return a變量+b變量; }";
Swc4jTranspileOutput output = swc4j.transpile(code, options);
assertNotNull(output);
assertTrue(output.isModule());
assertFalse(output.isScript());
List<BaseSwc4jAstToken> tokens = output.getTokens();
assertNotNull(tokens);
assertEquals(18, tokens.size());
assertEquals(Swc4jAstTokenType.Function, tokens.get(0).getType());
assertTrue(tokens.get(0).isLineBreakAhead());
assertEquals(Swc4jAstTokenType.Return, tokens.get(12).getType());
assertFalse(tokens.get(12).isLineBreakAhead());
tokens.forEach(token ->
assertEquals(
code.substring(token.getStartPosition(), token.getEndPosition()),
token.getText()));
}

@Test
public void testTranspileTypeScriptWithInlineSourceMap() throws Swc4jCoreException {
String code = "function add(a:number, b:number) { return a+b; }";
Expand Down

0 comments on commit 0bf80ef

Please sign in to comment.