mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
Merge pull request #2552 from erik-krogh/ImportMeta
Approved by max-schaefer
This commit is contained in:
@@ -240,6 +240,9 @@ public class ESNextParser extends JSXParser {
|
||||
if (this.type == TokenType._import) {
|
||||
Position startLoc = this.startLoc;
|
||||
this.next();
|
||||
if (this.eat(TokenType.dot)) {
|
||||
return parseImportMeta(startLoc);
|
||||
}
|
||||
this.expect(TokenType.parenL);
|
||||
return parseDynamicImport(startLoc);
|
||||
}
|
||||
@@ -413,6 +416,19 @@ public class ESNextParser extends JSXParser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an import.meta expression, assuming that the initial "import" and "." has been consumed.
|
||||
*/
|
||||
private MetaProperty parseImportMeta(Position loc) {
|
||||
Position propertyLoc = this.startLoc;
|
||||
Identifier property = this.parseIdent(true);
|
||||
if (!property.getName().equals("meta")) {
|
||||
this.unexpected(propertyLoc);
|
||||
}
|
||||
return this.finishNode(
|
||||
new MetaProperty(new SourceLocation(loc), new Identifier(new SourceLocation(loc), "import"), property));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a dynamic import, assuming that the keyword `import` and the opening parenthesis have
|
||||
* already been consumed.
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.semmle.js.ast;
|
||||
/**
|
||||
* A meta property access (cf. ECMAScript 2015 Language Specification, Chapter 12.3.8).
|
||||
*
|
||||
* <p>Currently the only recognised meta properties are <code>new.target</code> and <code>
|
||||
* function.sent</code>.
|
||||
* <p>Currently the only recognised meta properties are <code>new.target</code>,
|
||||
* <code>import.meta</code> and <code> function.sent</code>.
|
||||
*/
|
||||
public class MetaProperty extends Expression {
|
||||
private final Identifier meta, property;
|
||||
|
||||
5
javascript/ql/test/library-tests/Modules/ImportMeta.qll
Normal file
5
javascript/ql/test/library-tests/Modules/ImportMeta.qll
Normal file
@@ -0,0 +1,5 @@
|
||||
import semmle.javascript.ES2015Modules
|
||||
|
||||
query predicate test_ImportMetaExpr(ImportMetaExpr meta) {
|
||||
any()
|
||||
}
|
||||
1
javascript/ql/test/library-tests/Modules/importmeta.js
Normal file
1
javascript/ql/test/library-tests/Modules/importmeta.js
Normal file
@@ -0,0 +1 @@
|
||||
var foo = new URL('../cli.svg', import.meta.url).pathname;
|
||||
@@ -26,6 +26,8 @@ test_getExportedName
|
||||
| m/c.js:5:10:5:15 | g as h | g |
|
||||
test_OtherImports
|
||||
| es2015_require.js:1:11:1:24 | require('./d') | d.js:1:1:5:0 | <toplevel> |
|
||||
test_ImportMetaExpr
|
||||
| importmeta.js:1:33:1:43 | import.meta |
|
||||
test_ReExportDeclarations
|
||||
| b.js:7:1:7:21 | export ... './a'; | b.js:7:16:7:20 | './a' |
|
||||
| d.js:4:1:4:20 | export * from 'm/c'; | d.js:4:15:4:19 | 'm/c' |
|
||||
@@ -102,6 +104,7 @@ test_NamedImportSpecifier
|
||||
test_GlobalVariableRef
|
||||
| a.js:5:31:5:31 | o |
|
||||
| exports.js:3:9:3:15 | exports |
|
||||
| importmeta.js:1:15:1:17 | URL |
|
||||
| tst.html:6:3:6:7 | alert |
|
||||
test_BulkReExportDeclarations
|
||||
| d.js:4:1:4:20 | export * from 'm/c'; |
|
||||
|
||||
@@ -2,6 +2,7 @@ import ImportSpecifiers
|
||||
import getLocalName
|
||||
import getExportedName
|
||||
import OtherImports
|
||||
import ImportMeta
|
||||
import ReExportDeclarations
|
||||
import ImportDefaultSpecifiers
|
||||
import getImportedName
|
||||
|
||||
Reference in New Issue
Block a user