Skip to content

Commit 13ef69a

Browse files
committed
support arbitary export specifiers
1 parent d5387c4 commit 13ef69a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

javascript/extractor/src/com/semmle/jcorn/Parser.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3547,7 +3547,19 @@ protected List<ExportSpecifier> parseExportSpecifiers(Set<String> exports) {
35473547

35483548
SourceLocation loc = new SourceLocation(this.startLoc);
35493549
Identifier local = this.parseIdent(this.type == TokenType._default);
3550-
Identifier exported = this.eatContextual("as") ? this.parseIdent(true) : local;
3550+
Identifier exported;
3551+
if (!this.eatContextual("as")) {
3552+
exported = local;
3553+
} else {
3554+
if (this.type == TokenType.string) {
3555+
// e.g. `export { Foo_new as "Foo::new" }`
3556+
Expression string = this.parseExprAtom(null);
3557+
String str = ((Literal)string).getStringValue();
3558+
exported = new Identifier(loc, str);
3559+
} else {
3560+
exported = this.parseIdent(true);
3561+
}
3562+
}
35513563
checkExport(exports, exported.getName(), exported.getLoc().getStart());
35523564
nodes.add(this.finishNode(new ExportSpecifier(loc, local, exported)));
35533565
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
import { "Foo::new" as Foo_new } from "./foo.wasm"
2+
3+
const foo = Foo_new()
4+
5+
export { Foo_new as "Foo::new" }

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ test_BulkReExportDeclarations
33
test_ExportDeclarations
44
| a.js:1:1:3:1 | export ... n 23;\\n} |
55
| a.js:5:1:5:32 | export ... } = o; |
6+
| arbitarySpecifier.js:5:1:5:32 | export ... :new" } |
67
| b.js:5:1:5:18 | export { f as g }; |
78
| b.js:7:1:7:21 | export ... './a'; |
89
| d.js:4:1:4:20 | export * from 'm/c'; |
@@ -18,6 +19,7 @@ test_ExportDefaultDeclarations
1819
| a.js:1:1:3:1 | export ... n 23;\\n} |
1920
| es2015_require.js:3:1:3:25 | export ... ss C {} |
2021
test_ExportSpecifiers
22+
| arbitarySpecifier.js:5:10:5:30 | Foo_new ... o::new" | arbitarySpecifier.js:5:10:5:16 | Foo_new | arbitarySpecifier.js:5:10:5:30 | Foo_new ... o::new" |
2123
| b.js:5:10:5:15 | f as g | b.js:5:10:5:10 | f | b.js:5:15:5:15 | g |
2224
| e.js:2:10:2:10 | x | e.js:2:10:2:10 | x | e.js:2:10:2:10 | x |
2325
| e.js:2:13:2:13 | y | e.js:2:13:2:13 | y | e.js:2:13:2:13 | y |
@@ -74,6 +76,7 @@ test_Module_exports
7476
| a.js:1:1:5:32 | <toplevel> | default | a.js:1:16:3:1 | functio ... n 23;\\n} |
7577
| a.js:1:1:5:32 | <toplevel> | x | a.js:5:18:5:20 | f() |
7678
| a.js:1:1:5:32 | <toplevel> | y | a.js:5:25:5:25 | y |
79+
| arbitarySpecifier.js:1:1:5:32 | <toplevel> | Foo::new | arbitarySpecifier.js:5:10:5:16 | Foo_new |
7780
| b.js:1:1:8:0 | <toplevel> | f2 | a.js:1:16:3:1 | functio ... n 23;\\n} |
7881
| b.js:1:1:8:0 | <toplevel> | g | b.js:5:10:5:10 | f |
7982
| e.js:1:1:4:0 | <toplevel> | g | a.js:1:16:3:1 | functio ... n 23;\\n} |
@@ -114,6 +117,7 @@ test_getAnImportedModule
114117
| library-tests/Modules/m/c.js | library-tests/Modules/b.js |
115118
| library-tests/Modules/reExportNamespaceClient.js | library-tests/Modules/reExportNamespace.js |
116119
test_getExportedName
120+
| arbitarySpecifier.js:5:10:5:30 | Foo_new ... o::new" | Foo::new |
117121
| b.js:5:10:5:15 | f as g | g |
118122
| b.js:7:8:7:9 | f2 | f2 |
119123
| e.js:2:10:2:10 | x | x |
@@ -135,6 +139,7 @@ test_getImportedName
135139
| tst.html:5:10:5:10 | f | default |
136140
| unresolved.js:1:8:1:8 | f | default |
137141
test_getLocalName
142+
| arbitarySpecifier.js:5:10:5:30 | Foo_new ... o::new" | Foo_new |
138143
| b.js:5:10:5:15 | f as g | f |
139144
| b.js:7:8:7:9 | f2 | default |
140145
| e.js:2:10:2:10 | x | x |
@@ -145,6 +150,7 @@ test_getSourceNode
145150
| a.js:1:1:3:1 | export ... n 23;\\n} | default | a.js:1:16:3:1 | functio ... n 23;\\n} |
146151
| a.js:5:1:5:32 | export ... } = o; | x | a.js:5:18:5:20 | f() |
147152
| a.js:5:1:5:32 | export ... } = o; | y | a.js:5:25:5:25 | y |
153+
| arbitarySpecifier.js:5:1:5:32 | export ... :new" } | Foo::new | arbitarySpecifier.js:5:10:5:16 | Foo_new |
148154
| b.js:5:1:5:18 | export { f as g }; | g | b.js:5:10:5:10 | f |
149155
| b.js:7:1:7:21 | export ... './a'; | f2 | a.js:1:16:3:1 | functio ... n 23;\\n} |
150156
| e.js:2:1:2:16 | export { x, y }; | x | e.js:2:10:2:10 | x |

0 commit comments

Comments
 (0)