Skip to content

Commit 8819513

Browse files
committed
JS: Merge VueInstance and ExtendedInstance into one case
1 parent ecda798 commit 8819513

File tree

1 file changed

+30
-33
lines changed
  • javascript/ql/lib/semmle/javascript/frameworks

1 file changed

+30
-33
lines changed

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

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ module Vue {
5858
}
5959

6060
private newtype TComponent =
61-
MkVueInstance(API::NewNode def) { def = vueLibrary().getAnInstantiation() } or
62-
MkExtendedVue(VueExtendCall extend) or
63-
MkExtendedInstance(VueExtendCall extend, API::NewNode sub) {
64-
sub = extend.getReturn().getAnInstantiation()
61+
MkComponentInstantiation(API::NewNode sub) {
62+
sub = component().getAnInstantiation()
6563
} or
64+
MkExtendedVue(VueExtendCall extend) or
6665
MkComponentRegistration(API::CallNode def) { def = vueLibrary().getMember("component").getACall() } or
6766
MkSingleFileComponent(VueFile file)
6867

@@ -389,12 +388,12 @@ module Vue {
389388
}
390389

391390
/**
392-
* A Vue component from `new Vue({...})`.
391+
* A Vue component created implicitly at an invocation of form `new Vue({...})` or `new CustomComponent({...})`.
393392
*/
394-
class VueInstance extends Component, MkVueInstance {
393+
private class ComponentInstantiation extends Component, MkComponentInstantiation {
395394
API::NewNode def;
396395

397-
VueInstance() { this = MkVueInstance(def) }
396+
ComponentInstantiation() { this = MkComponentInstantiation(def) }
398397

399398
override string toString() { result = def.toString() }
400399

@@ -411,6 +410,24 @@ module Vue {
411410
override DataFlow::Node getOwnOptionsObject() { result = def.getArgument(0) }
412411

413412
override Template::Element getTemplateElement() { none() }
413+
414+
override Component getABaseComponent() {
415+
result = Component.super.getABaseComponent()
416+
or
417+
result.getComponentRef().getAnInstantiation() = def
418+
}
419+
}
420+
421+
/**
422+
* DEPRECATED. Use `Vue::Component` instead.
423+
*
424+
* A Vue component from `new Vue({...})`.
425+
*/
426+
deprecated class VueInstance extends Component {
427+
VueInstance() {
428+
// restrict charpred to match original behavior
429+
this = MkComponentInstantiation(vueLibrary().getAnInstantiation())
430+
}
414431
}
415432

416433
/**
@@ -445,34 +462,14 @@ module Vue {
445462
}
446463

447464
/**
465+
* DEPRECATED. Use `Vue::Component` instead.
466+
*
448467
* An instance of an extended Vue, for example `instance` of `var Ext = Vue.extend({...}); var instance = new Ext({...})`.
449468
*/
450-
class ExtendedInstance extends Component, MkExtendedInstance {
451-
VueExtendCall extend;
452-
API::NewNode sub;
453-
454-
ExtendedInstance() { this = MkExtendedInstance(extend, sub) }
455-
456-
override string toString() { result = sub.toString() }
457-
458-
override predicate hasLocationInfo(
459-
string filepath, int startline, int startcolumn, int endline, int endcolumn
460-
) {
461-
sub.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
462-
}
463-
464-
override API::Node getComponentRef() { result = sub.getReturn() }
465-
466-
override API::Node getOwnOptions() { result = sub.getParameter(0) }
467-
468-
override DataFlow::Node getOwnOptionsObject() { result = sub.getArgument(0) }
469-
470-
override Template::Element getTemplateElement() { none() }
471-
472-
override Component getABaseComponent() {
473-
result = Component.super.getABaseComponent()
474-
or
475-
result.getComponentRef().getAnInstantiation() = sub
469+
deprecated class ExtendedInstance extends Component {
470+
ExtendedInstance() {
471+
// restrict charpred to match original behavior
472+
this = MkComponentInstantiation(vueLibrary().getMember("extend").getReturn().getAnInstantiation())
476473
}
477474
}
478475

0 commit comments

Comments
 (0)