Skip to content

Commit b9d1b55

Browse files
committed
JS: Add API-node version of getOwnOptions
1 parent 63b7c6a commit b9d1b55

File tree

1 file changed

+24
-3
lines changed
  • javascript/ql/lib/semmle/javascript/frameworks

1 file changed

+24
-3
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ module Vue {
139139
endcolumn = 0
140140
}
141141

142+
/**
143+
* Gets an API node referring to the options passed to the Vue object,
144+
* such as the object literal `{...}` in `new Vue{{...})` or the default export of a single-file component.
145+
*/
146+
API::Node getOwnOptions() { none() } // overridden in subclass
147+
142148
/**
143149
* Gets the options passed to the Vue object, such as the object literal `{...}` in `new Vue{{...})`
144150
* or the default export of a single-file component.
@@ -356,7 +362,7 @@ module Vue {
356362
* A Vue component from `new Vue({...})`.
357363
*/
358364
class VueInstance extends Component, MkVueInstance {
359-
DataFlow::NewNode def;
365+
API::NewNode def;
360366

361367
VueInstance() { this = MkVueInstance(def) }
362368

@@ -368,6 +374,8 @@ module Vue {
368374
def.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
369375
}
370376

377+
override API::Node getOwnOptions() { result = def.getParameter(0) }
378+
371379
override DataFlow::Node getOwnOptionsObject() { result = def.getArgument(0) }
372380

373381
override Template::Element getTemplateElement() { none() }
@@ -389,6 +397,8 @@ module Vue {
389397
extend.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
390398
}
391399

400+
override API::Node getOwnOptions() { result = extend.getParameter(0) }
401+
392402
override DataFlow::Node getOwnOptionsObject() { result = extend.getArgument(0) }
393403

394404
override Template::Element getTemplateElement() { none() }
@@ -399,7 +409,7 @@ module Vue {
399409
*/
400410
class ExtendedInstance extends Component, MkExtendedInstance {
401411
VueExtend extend;
402-
DataFlow::NewNode sub;
412+
API::NewNode sub;
403413

404414
ExtendedInstance() { this = MkExtendedInstance(extend, sub) }
405415

@@ -411,6 +421,8 @@ module Vue {
411421
sub.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
412422
}
413423

424+
override API::Node getOwnOptions() { result = sub.getParameter(0) }
425+
414426
override DataFlow::Node getOwnOptionsObject() { result = sub.getArgument(0) }
415427

416428
override DataFlow::Node getOption(string name) {
@@ -426,7 +438,7 @@ module Vue {
426438
* A Vue component from `Vue.component("my-component", { ... })`.
427439
*/
428440
class ComponentRegistration extends Component, MkComponentRegistration {
429-
DataFlow::CallNode def;
441+
API::CallNode def;
430442

431443
ComponentRegistration() { this = MkComponentRegistration(def) }
432444

@@ -438,6 +450,8 @@ module Vue {
438450
def.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
439451
}
440452

453+
override API::Node getOwnOptions() { result = def.getParameter(1) }
454+
441455
override DataFlow::Node getOwnOptionsObject() { result = def.getArgument(1) }
442456

443457
override Template::Element getTemplateElement() { none() }
@@ -476,6 +490,13 @@ module Vue {
476490
)
477491
}
478492

493+
override API::Node getOwnOptions() {
494+
exists(ExportDefaultDeclaration decl |
495+
decl.getTopLevel() = getModule() and
496+
result.getARhs() = DataFlow::valueNode(decl.getOperand())
497+
)
498+
}
499+
479500
override DataFlow::Node getOwnOptionsObject() {
480501
exists(ExportDefaultDeclaration decl |
481502
decl.getTopLevel() = getModule() and

0 commit comments

Comments
 (0)