JS: Fix location of assert clause

This commit is contained in:
Asger F
2023-03-03 11:59:51 +01:00
parent 38194c6ae7
commit 7a55b003d2
3 changed files with 34 additions and 28 deletions

View File

@@ -177,6 +177,7 @@ public class TypeScriptASTConverter {
private static final Pattern EXPORT_DECL_START =
Pattern.compile("^export" + "(" + WHITESPACE_CHAR + "+default)?" + WHITESPACE_CHAR + "+");
private static final Pattern TYPEOF_START = Pattern.compile("^typeof" + WHITESPACE_CHAR + "+");
private static final Pattern ASSERT_START = Pattern.compile("^assert" + WHITESPACE_CHAR + "+");
private static final Pattern WHITESPACE_END_PAREN =
Pattern.compile("^" + WHITESPACE_CHAR + "*\\)");
@@ -2287,6 +2288,11 @@ public class TypeScriptASTConverter {
for (INode child : convertChildren(node, "elements")) {
properties.add((Property)child);
}
// Adjust location to skip over the `assert` keyword.
Matcher m = ASSERT_START.matcher(loc.getSource());
if (m.find()) {
advance(loc, m.group(0));
}
return new ObjectExpression(loc, properties);
}

View File

@@ -726,9 +726,9 @@ locations_default(#20275,#10000,1,9,1,14)
hasLocation(#20274,#20275)
regexp_const_value(#20274,"module")
#20276=*
exprs(#20276,8,#20272,-10,"assert ... json"" }")
#20277=@"loc,{#10000},1,17,1,39"
locations_default(#20277,#10000,1,17,1,39)
exprs(#20276,8,#20272,-10,"{ type: ""json"" }")
#20277=@"loc,{#10000},1,24,1,39"
locations_default(#20277,#10000,1,24,1,39)
hasLocation(#20276,#20277)
enclosing_stmt(#20276,#20272)
expr_containers(#20276,#20001)
@@ -754,9 +754,9 @@ locations_default(#20283,#10000,2,22,2,27)
hasLocation(#20282,#20283)
regexp_const_value(#20282,"module")
#20284=*
exprs(#20284,8,#20280,-10,"assert ... json"" }")
#20285=@"loc,{#10000},2,30,2,52"
locations_default(#20285,#10000,2,30,2,52)
exprs(#20284,8,#20280,-10,"{ type: ""json"" }")
#20285=@"loc,{#10000},2,37,2,52"
locations_default(#20285,#10000,2,37,2,52)
hasLocation(#20284,#20285)
enclosing_stmt(#20284,#20280)
expr_containers(#20284,#20001)
@@ -798,9 +798,9 @@ locations_default(#20294,#10000,3,21,3,26)
hasLocation(#20293,#20294)
regexp_const_value(#20293,"module")
#20295=*
exprs(#20295,8,#20291,-10,"assert ... json"" }")
#20296=@"loc,{#10000},3,29,3,51"
locations_default(#20296,#10000,3,29,3,51)
exprs(#20295,8,#20291,-10,"{ type: ""json"" }")
#20296=@"loc,{#10000},3,36,3,51"
locations_default(#20296,#10000,3,36,3,51)
hasLocation(#20295,#20296)
enclosing_stmt(#20295,#20291)
expr_containers(#20295,#20001)
@@ -846,9 +846,9 @@ locations_default(#20305,#10000,4,17,4,22)
hasLocation(#20304,#20305)
regexp_const_value(#20304,"module")
#20306=*
exprs(#20306,8,#20302,-10,"assert ... json"" }")
#20307=@"loc,{#10000},4,25,4,47"
locations_default(#20307,#10000,4,25,4,47)
exprs(#20306,8,#20302,-10,"{ type: ""json"" }")
#20307=@"loc,{#10000},4,32,4,47"
locations_default(#20307,#10000,4,32,4,47)
hasLocation(#20306,#20307)
enclosing_stmt(#20306,#20302)
expr_containers(#20306,#20001)
@@ -888,9 +888,9 @@ locations_default(#20315,#10000,6,21,6,26)
hasLocation(#20314,#20315)
regexp_const_value(#20314,"module")
#20316=*
exprs(#20316,8,#20312,-10,"assert ... json"" }")
#20317=@"loc,{#10000},6,29,6,51"
locations_default(#20317,#10000,6,29,6,51)
exprs(#20316,8,#20312,-10,"{ type: ""json"" }")
#20317=@"loc,{#10000},6,36,6,51"
locations_default(#20317,#10000,6,36,6,51)
hasLocation(#20316,#20317)
enclosing_stmt(#20316,#20312)
expr_containers(#20316,#20001)
@@ -933,9 +933,9 @@ locations_default(#20326,#10000,7,16,7,21)
hasLocation(#20325,#20326)
regexp_const_value(#20325,"module")
#20327=*
exprs(#20327,8,#20323,-10,"assert ... json"" }")
#20328=@"loc,{#10000},7,24,7,46"
locations_default(#20328,#10000,7,24,7,46)
exprs(#20327,8,#20323,-10,"{ type: ""json"" }")
#20328=@"loc,{#10000},7,31,7,46"
locations_default(#20328,#10000,7,31,7,46)
hasLocation(#20327,#20328)
enclosing_stmt(#20327,#20323)
expr_containers(#20327,#20001)
@@ -961,9 +961,9 @@ locations_default(#20334,#10000,8,22,8,27)
hasLocation(#20333,#20334)
regexp_const_value(#20333,"module")
#20335=*
exprs(#20335,8,#20331,-10,"assert ... json"" }")
#20336=@"loc,{#10000},8,30,8,52"
locations_default(#20336,#10000,8,30,8,52)
exprs(#20335,8,#20331,-10,"{ type: ""json"" }")
#20336=@"loc,{#10000},8,37,8,52"
locations_default(#20336,#10000,8,37,8,52)
hasLocation(#20335,#20336)
enclosing_stmt(#20335,#20331)
expr_containers(#20335,#20001)

View File

@@ -3,17 +3,17 @@ getImportAssertionFromImport
| js-import-assertions.js:2:1:2:53 | import ... son" }; | js-import-assertions.js:2:37:2:52 | { type: "json" } |
| js-import-assertions.js:3:1:3:52 | import ... son" }; | js-import-assertions.js:3:36:3:51 | { type: "json" } |
| js-import-assertions.js:4:1:4:48 | import ... son" }; | js-import-assertions.js:4:32:4:47 | { type: "json" } |
| ts-import-assertions.ts:3:1:3:40 | import ... son" }; | ts-import-assertions.ts:3:17:3:39 | assert ... json" } |
| ts-import-assertions.ts:4:1:4:53 | import ... son" }; | ts-import-assertions.ts:4:30:4:52 | assert ... json" } |
| ts-import-assertions.ts:5:1:5:52 | import ... son" }; | ts-import-assertions.ts:5:29:5:51 | assert ... json" } |
| ts-import-assertions.ts:6:1:6:48 | import ... son" }; | ts-import-assertions.ts:6:25:6:47 | assert ... json" } |
| ts-import-assertions.ts:3:1:3:40 | import ... son" }; | ts-import-assertions.ts:3:24:3:39 | { type: "json" } |
| ts-import-assertions.ts:4:1:4:53 | import ... son" }; | ts-import-assertions.ts:4:37:4:52 | { type: "json" } |
| ts-import-assertions.ts:5:1:5:52 | import ... son" }; | ts-import-assertions.ts:5:36:5:51 | { type: "json" } |
| ts-import-assertions.ts:6:1:6:48 | import ... son" }; | ts-import-assertions.ts:6:32:6:47 | { type: "json" } |
getImportAssertionFromExport
| js-import-assertions.js:6:1:6:52 | export ... son" }; | js-import-assertions.js:6:36:6:51 | { type: "json" } |
| js-import-assertions.js:7:1:7:47 | export ... son" }; | js-import-assertions.js:7:31:7:46 | { type: "json" } |
| js-import-assertions.js:8:1:8:53 | export ... son" }; | js-import-assertions.js:8:37:8:52 | { type: "json" } |
| ts-import-assertions.ts:8:1:8:52 | export ... son" }; | ts-import-assertions.ts:8:29:8:51 | assert ... json" } |
| ts-import-assertions.ts:9:1:9:47 | export ... son" }; | ts-import-assertions.ts:9:24:9:46 | assert ... json" } |
| ts-import-assertions.ts:10:1:10:53 | export ... son" }; | ts-import-assertions.ts:10:30:10:52 | assert ... json" } |
| ts-import-assertions.ts:8:1:8:52 | export ... son" }; | ts-import-assertions.ts:8:36:8:51 | { type: "json" } |
| ts-import-assertions.ts:9:1:9:47 | export ... son" }; | ts-import-assertions.ts:9:31:9:46 | { type: "json" } |
| ts-import-assertions.ts:10:1:10:53 | export ... son" }; | ts-import-assertions.ts:10:37:10:52 | { type: "json" } |
getImportAttributes
| js-import-assertions.js:10:12:10:57 | import( ... n" } }) | js-import-assertions.js:10:29:10:56 | { asser ... on" } } |
| ts-import-assertions.ts:12:12:12:57 | import( ... n" } }) | ts-import-assertions.ts:12:29:12:56 | { asser ... on" } } |