JS: Extract predicates for ES2015/closure modules

This commit is contained in:
Asger F
2019-01-30 12:24:35 +00:00
parent 51fe31d049
commit 8f3b0f584a
5 changed files with 15 additions and 2 deletions

View File

@@ -562,6 +562,9 @@ public class ASTExtractor {
scopeManager.enterScope(3, moduleScopeKey, toplevelLabel);
if (sourceType == SourceType.CLOSURE_MODULE) {
scopeManager.addVariables("exports");
trapwriter.addTuple("isClosureModule", toplevelLabel);
} else {
trapwriter.addTuple("isES2015Module", toplevelLabel);
}
trapwriter.addTuple("isModule", toplevelLabel);
}

View File

@@ -7,8 +7,7 @@ import javascript
*/
class ES2015Module extends Module {
ES2015Module() {
isModule(this) and
not isNodejs(this)
isES2015Module(this)
}
override ModuleScope getScope() { result.getScopeElement() = this }

View File

@@ -128,6 +128,8 @@ case @toplevel.kind of
isModule (int tl: @toplevel ref);
isNodejs (int tl: @toplevel ref);
isES2015Module (int tl: @toplevel ref);
isClosureModule (int tl: @toplevel ref);
// statements
#keyset[parent, idx]

View File

@@ -0,0 +1,4 @@
| tests/es6Module.js:0:0:0:0 | tests/es6Module.js |
| tests/es6ModuleDefault.js:0:0:0:0 | tests/es6ModuleDefault.js |
| tests/importFromEs6.js:0:0:0:0 | tests/importFromEs6.js |
| tests/requireFromEs6.js:0:0:0:0 | tests/requireFromEs6.js |

View File

@@ -0,0 +1,5 @@
import javascript
from TopLevel tl
where tl.isStrict()
select tl.getFile()