Skip to content

Commit 6b14789

Browse files
committed
JS: Fix bad join in export logic
1 parent 5fbf877 commit 6b14789

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

javascript/ql/lib/semmle/javascript/ES2015Modules.qll

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ES2015Module extends Module {
2929
override string getName() { result = this.getFile().getStem() }
3030

3131
/** Gets an export declaration in this module. */
32+
pragma[nomagic]
3233
ExportDeclaration getAnExport() { result.getTopLevel() = this }
3334

3435
overlay[global]
@@ -38,6 +39,7 @@ class ES2015Module extends Module {
3839

3940
/** Holds if this module exports variable `v` under the name `name`. */
4041
overlay[global]
42+
pragma[nomagic]
4143
predicate exportsAs(LexicalName v, string name) { this.getAnExport().exportsAs(v, name) }
4244

4345
override predicate isStrict() {
@@ -345,6 +347,7 @@ abstract class ExportDeclaration extends Stmt, @export_declaration {
345347

346348
/** Holds if this export declaration exports variable `v` under the name `name`. */
347349
overlay[global]
350+
pragma[nomagic]
348351
final predicate exportsAs(LexicalName v, string name) {
349352
this.exportsDirectlyAs(v, name)
350353
or
@@ -821,18 +824,31 @@ class SelectiveReExportDeclaration extends ReExportDeclaration, ExportNamedDecla
821824
result = ExportNamedDeclaration.super.getImportedPath()
822825
}
823826

827+
overlay[global]
828+
pragma[nomagic]
829+
private predicate reExportsFrom(ES2015Module mod, string originalName, string reExportedName) {
830+
exists(ExportSpecifier spec |
831+
spec = this.getASpecifier() and
832+
reExportedName = spec.getExportedName() and
833+
originalName = spec.getLocalName() and
834+
mod = this.getReExportedES2015Module()
835+
)
836+
}
837+
824838
overlay[global]
825839
override predicate reExportsAs(LexicalName v, string name) {
826-
exists(ExportSpecifier spec | spec = this.getASpecifier() and name = spec.getExportedName() |
827-
this.getReExportedES2015Module().exportsAs(v, spec.getLocalName())
840+
exists(ES2015Module mod, string originalName |
841+
this.reExportsFrom(mod, originalName, name) and
842+
mod.exportsAs(v, originalName)
828843
) and
829844
not (this.isTypeOnly() and v instanceof Variable)
830845
}
831846

832847
overlay[global]
833848
override DataFlow::Node getReExportedSourceNode(string name) {
834-
exists(ExportSpecifier spec | spec = this.getASpecifier() and name = spec.getExportedName() |
835-
result = this.getReExportedES2015Module().getAnExport().getSourceNode(spec.getLocalName())
849+
exists(ES2015Module mod, string originalName |
850+
this.reExportsFrom(mod, originalName, name) and
851+
result = mod.getAnExport().getSourceNode(originalName)
836852
)
837853
}
838854
}

0 commit comments

Comments
 (0)