diff --git a/javascript/ql/test/ApiGraphs/classes/classes.js b/javascript/ql/test/ApiGraphs/classes/classes.js index f4eb7023262d..29e7d223247b 100644 --- a/javascript/ql/test/ApiGraphs/classes/classes.js +++ b/javascript/ql/test/ApiGraphs/classes/classes.js @@ -25,3 +25,24 @@ MyOtherStream.prototype.instanceProp = 1; /* def=moduleImport("classes").getMemb MyOtherStream.classProp = 1; /* def=moduleImport("classes").getMember("exports").getMember("MyOtherStream").getMember("classProp") */ module.exports.MyOtherStream = MyOtherStream; + + +// function-style class without .prototype reference +function MyThirdStream() { /* use=moduleImport("classes").getMember("exports").getMember("MyThirdStream").getInstance() */ +} +let instance = new MyThirdStream(); /* use=moduleImport("classes").getMember("exports").getMember("MyThirdStream").getInstance() */ + +module.exports.MyThirdStream = MyThirdStream; + + +// function-style class without .prototype reference (through global variable) +(function(f) { + foo.bar = function() { /* use=moduleImport("classes").getMember("exports").getMember("bar").getInstance() */ + } +})(foo = foo || {}); + +(function(f) { + let x = new f.bar(); /* use=moduleImport("classes").getMember("exports").getMember("bar").getInstance() */ +})(foo = foo || {}); + +module.exports.bar = foo.bar; diff --git a/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected b/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected index e69de29bb2d1..8b137891791f 100644 --- a/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected +++ b/javascript/ql/test/library-tests/TypeTracking/TypeTracking.expected @@ -0,0 +1 @@ + diff --git a/javascript/ql/test/library-tests/TypeTracking/implicit-receiver.js b/javascript/ql/test/library-tests/TypeTracking/implicit-receiver.js new file mode 100644 index 000000000000..447a3eb0e057 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeTracking/implicit-receiver.js @@ -0,0 +1,27 @@ +import 'dummy'; + +let trackedProp = "implicit-receiver-prop"; // name: implicit-receiver-prop + +function factory() { + let obj = unknown(); // name: implicit-receiver-obj + obj.foo = function() { + track(this); // track: implicit-receiver-obj + track(this.x); // track: implicit-receiver-obj track: implicit-receiver-prop + } + return obj; +} +let obj = factory(); +obj.x = trackedProp; + + +function factory2() { + let obj2 = { // name: implicit-receiver-obj2 + foo: function() { + track(this); // track: implicit-receiver-obj2 + track(this.x); // track: implicit-receiver-obj2 track: implicit-receiver-prop + } + } + return obj2; +} +let obj2 = factory2() +obj2.x = trackedProp;