Skip to content

Commit 70a1a64

Browse files
authored
Merge pull request #18452 from asgerf/js/import-spec-strings
JS: Fix crash in case of string literal in export specifier
2 parents 14cfac5 + a7fbfb2 commit 70a1a64

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

javascript/extractor/src/com/semmle/ts/extractor/TypeScriptASTConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,8 @@ private Node convertExportDeclaration(JsonObject node, SourceLocation loc) throw
12171217
}
12181218

12191219
private Node convertExportSpecifier(JsonObject node, SourceLocation loc) throws ParseError {
1220-
Identifier local = convertChild(node, hasChild(node, "propertyName") ? "propertyName" : "name");
1220+
JsonObject localToken = node.get(hasChild(node, "propertyName") ? "propertyName" : "name").getAsJsonObject();
1221+
Identifier local = convertNodeAsIdentifier(localToken);
12211222
JsonObject exportedToken = node.get("name").getAsJsonObject();
12221223
Identifier exported = convertNodeAsIdentifier(exportedToken);
12231224

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed a TypeScript extractor crash that would occur when encountering an export specifier
5+
whose local specifier was a string literal.

javascript/ql/test/library-tests/Modules/arbitrarySpecifier.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ import { "Foo::new" as Foo_new } from "./foo.wasm"
33
const foo = Foo_new()
44

55
export { Foo_new as "Foo::new" }
6-
export type * as "Foo_types" from './mod'
6+
export type * as "Foo_types" from './mod'
7+
8+
export { "<X>" as "<Y>" } from "somewhere";
9+
export { "<X>" } from "somewhere";

javascript/ql/test/library-tests/Modules/tests.expected

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ test_ExportDeclarations
55
| a.js:5:1:5:32 | export ... } = o; |
66
| arbitrarySpecifier.ts:5:1:5:32 | export ... :new" } |
77
| arbitrarySpecifier.ts:6:1:6:41 | export ... './mod' |
8+
| arbitrarySpecifier.ts:8:1:8:43 | export ... where"; |
9+
| arbitrarySpecifier.ts:9:1:9:34 | export ... where"; |
810
| b.js:5:1:5:18 | export { f as g }; |
911
| b.js:7:1:7:21 | export ... './a'; |
1012
| d.js:4:1:4:20 | export * from 'm/c'; |
@@ -22,6 +24,8 @@ test_ExportDefaultDeclarations
2224
| es2015_require.js:3:1:3:25 | export ... ss C {} |
2325
test_ExportSpecifiers
2426
| arbitrarySpecifier.ts:5:10:5:30 | Foo_new ... o::new" | arbitrarySpecifier.ts:5:10:5:16 | Foo_new | arbitrarySpecifier.ts:5:21:5:30 | "Foo::new" |
27+
| arbitrarySpecifier.ts:8:10:8:23 | "<X>" as "<Y>" | arbitrarySpecifier.ts:8:10:8:14 | "<X>" | arbitrarySpecifier.ts:8:19:8:23 | "<Y>" |
28+
| arbitrarySpecifier.ts:9:10:9:14 | "<X>" | arbitrarySpecifier.ts:9:10:9:14 | "<X>" | arbitrarySpecifier.ts:9:10:9:14 | "<X>" |
2529
| b.js:5:10:5:15 | f as g | b.js:5:10:5:10 | f | b.js:5:15:5:15 | g |
2630
| e.js:2:10:2:10 | x | e.js:2:10:2:10 | x | e.js:2:10:2:10 | x |
2731
| e.js:2:13:2:13 | y | e.js:2:13:2:13 | y | e.js:2:13:2:13 | y |
@@ -81,8 +85,8 @@ test_Module_exports
8185
| a.js:1:1:5:32 | <toplevel> | default | a.js:1:16:3:1 | functio ... n 23;\\n} |
8286
| a.js:1:1:5:32 | <toplevel> | x | a.js:5:18:5:20 | f() |
8387
| a.js:1:1:5:32 | <toplevel> | y | a.js:5:25:5:25 | y |
84-
| arbitrarySpecifier.ts:1:1:6:41 | <toplevel> | Foo::new | arbitrarySpecifier.ts:5:10:5:16 | Foo_new |
85-
| arbitrarySpecifier.ts:1:1:6:41 | <toplevel> | Foo_types | arbitrarySpecifier.ts:6:13:6:28 | * as "Foo_types" |
88+
| arbitrarySpecifier.ts:1:1:10:0 | <toplevel> | Foo::new | arbitrarySpecifier.ts:5:10:5:16 | Foo_new |
89+
| arbitrarySpecifier.ts:1:1:10:0 | <toplevel> | Foo_types | arbitrarySpecifier.ts:6:13:6:28 | * as "Foo_types" |
8690
| b.js:1:1:8:0 | <toplevel> | f2 | a.js:1:16:3:1 | functio ... n 23;\\n} |
8791
| b.js:1:1:8:0 | <toplevel> | g | b.js:5:10:5:10 | f |
8892
| e.js:1:1:4:0 | <toplevel> | g | a.js:1:16:3:1 | functio ... n 23;\\n} |
@@ -109,6 +113,8 @@ test_OtherImports
109113
| import-indirect-path.js:5:1:5:14 | require(x + y) | a.js:1:1:5:32 | <toplevel> |
110114
test_ReExportDeclarations
111115
| arbitrarySpecifier.ts:6:1:6:41 | export ... './mod' | arbitrarySpecifier.ts:6:35:6:41 | './mod' |
116+
| arbitrarySpecifier.ts:8:1:8:43 | export ... where"; | arbitrarySpecifier.ts:8:32:8:42 | "somewhere" |
117+
| arbitrarySpecifier.ts:9:1:9:34 | export ... where"; | arbitrarySpecifier.ts:9:23:9:33 | "somewhere" |
112118
| b.js:7:1:7:21 | export ... './a'; | b.js:7:16:7:20 | './a' |
113119
| d.js:4:1:4:20 | export * from 'm/c'; | d.js:4:15:4:19 | 'm/c' |
114120
| e.js:3:1:3:35 | export ... './a'; | e.js:3:30:3:34 | './a' |
@@ -128,6 +134,8 @@ test_getAnImportedModule
128134
test_getExportedName
129135
| arbitrarySpecifier.ts:5:10:5:30 | Foo_new ... o::new" | Foo::new |
130136
| arbitrarySpecifier.ts:6:13:6:28 | * as "Foo_types" | Foo_types |
137+
| arbitrarySpecifier.ts:8:10:8:23 | "<X>" as "<Y>" | <Y> |
138+
| arbitrarySpecifier.ts:9:10:9:14 | "<X>" | <X> |
131139
| b.js:5:10:5:15 | f as g | g |
132140
| b.js:7:8:7:9 | f2 | f2 |
133141
| e.js:2:10:2:10 | x | x |
@@ -152,6 +160,8 @@ test_getImportedName
152160
| unresolved.js:1:8:1:8 | f | default |
153161
test_getLocalName
154162
| arbitrarySpecifier.ts:5:10:5:30 | Foo_new ... o::new" | Foo_new |
163+
| arbitrarySpecifier.ts:8:10:8:23 | "<X>" as "<Y>" | <X> |
164+
| arbitrarySpecifier.ts:9:10:9:14 | "<X>" | <X> |
155165
| b.js:5:10:5:15 | f as g | f |
156166
| b.js:7:8:7:9 | f2 | default |
157167
| e.js:2:10:2:10 | x | x |

0 commit comments

Comments
 (0)