Skip to content

Commit f450476

Browse files
committed
JS: Improve handling of default exports in Vue
1 parent cd6a60d commit f450476

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

javascript/ql/lib/semmle/javascript/Modules.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ abstract class Module extends TopLevel {
111111
cached
112112
abstract DataFlow::Node getAnExportedValue(string name);
113113

114+
/**
115+
* Gets a value that is exported as the whole exports object of this module.
116+
*/
117+
cached
118+
DataFlow::Node getABulkExportedNode() { none() } // overridden in subclasses
119+
120+
/**
121+
* Gets the ES2015 `default` export from this module, or for other types of modules,
122+
* gets a bulk exported node.
123+
*
124+
* This can be used to determine which value a default-import will likely refer to,
125+
* as the interaction between different module types is not standardized.
126+
*/
127+
DataFlow::Node getDefaultOrBulkExport() {
128+
result = [getAnExportedValue("default"), getABulkExportedNode()]
129+
}
130+
114131
/**
115132
* Gets the root folder relative to which the given import path (which must
116133
* appear in this module) is resolved.

javascript/ql/lib/semmle/javascript/NodeJS.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class NodeModule extends Module {
9999
)
100100
}
101101

102+
override DataFlow::Node getABulkExportedNode() {
103+
exists(DataFlow::PropWrite write |
104+
write.getBase().asExpr() = getModuleVariable().getAnAccess() and
105+
result = write.getRhs()
106+
)
107+
}
108+
102109
/** Gets a symbol that the module object inherits from its prototypes. */
103110
private string getAnImplicitlyExportedSymbol() {
104111
exists(ExternalConstructor ec | ec = getPrototypeOfExportedExpr() |

javascript/ql/lib/semmle/javascript/frameworks/Vue.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Vue {
2121
override DataFlow::SourceNode getAUse() { none() }
2222

2323
override DataFlow::Node getARhs() {
24-
result = any(SingleFileComponent c).getModule().getAnExportedValue("default")
24+
result = any(SingleFileComponent c).getModule().getDefaultOrBulkExport()
2525
}
2626
}
2727

@@ -550,10 +550,8 @@ module Vue {
550550
}
551551

552552
override API::Node getOwnOptions() {
553-
exists(ExportDefaultDeclaration decl |
554-
decl.getTopLevel() = getModule() and
555-
result.getARhs() = DataFlow::valueNode(decl.getOperand())
556-
)
553+
// Use the entry point generated by `VueExportEntryPoint`
554+
result.getARhs() = getModule().getDefaultOrBulkExport()
557555
}
558556

559557
override DataFlow::Node getOwnOptionsObject() {

0 commit comments

Comments
 (0)