File tree Expand file tree Collapse file tree
ql/test/library-tests/Modules Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -240,6 +240,9 @@ protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
240240 if (this .type == TokenType ._import ) {
241241 Position startLoc = this .startLoc ;
242242 this .next ();
243+ if (this .type == TokenType .dot ) {
244+ return parseImportMeta (startLoc );
245+ }
243246 this .expect (TokenType .parenL );
244247 return parseDynamicImport (startLoc );
245248 }
@@ -413,6 +416,20 @@ protected Statement parseImport(Position startLoc) {
413416 }
414417 }
415418
419+ /**
420+ * Parses an import.meta expression, assuming that the initial "import" has been consumed.
421+ */
422+ private MetaProperty parseImportMeta (Position loc ) {
423+ Identifier meta = new Identifier (new SourceLocation (loc ), "import" );
424+ this .next ();
425+ Position propertyLoc = this .startLoc ;
426+ Identifier property = this .parseIdent (true );
427+ if (!property .getName ().equals ("meta" )) {
428+ this .unexpected (propertyLoc );
429+ }
430+ return this .finishNode (new MetaProperty (new SourceLocation (loc ), meta , property ));
431+ }
432+
416433 /**
417434 * Parses a dynamic import, assuming that the keyword `import` and the opening parenthesis have
418435 * already been consumed.
Original file line number Diff line number Diff line change 33/**
44 * A meta property access (cf. ECMAScript 2015 Language Specification, Chapter 12.3.8).
55 *
6- * <p>Currently the only recognised meta properties are <code>new.target</code> and <code>
7- * function.sent</code>.
6+ * <p>Currently the only recognised meta properties are <code>new.target</code>,
7+ * <code>import.meta</code> and <code> function.sent</code>.
88 */
99public class MetaProperty extends Expression {
1010 private final Identifier meta , property ;
Original file line number Diff line number Diff line change 1+ import semmle.javascript.ES2015Modules
2+
3+ query predicate test_ImportMetaExpr ( ImportMetaExpr meta ) {
4+ any ( )
5+ }
Original file line number Diff line number Diff line change 1+ var foo = new URL ( '../cli.svg' , import . meta. url ) . pathname ;
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ test_getExportedName
2626| m/c.js:5:10:5:15 | g as h | g |
2727test_OtherImports
2828| es2015_require.js:1:11:1:24 | require('./d') | d.js:1:1:5:0 | <toplevel> |
29+ test_ImportMetaExpr
30+ | importmeta.js:1:33:1:43 | import.meta |
2931test_ReExportDeclarations
3032| b.js:7:1:7:21 | export ... './a'; | b.js:7:16:7:20 | './a' |
3133| d.js:4:1:4:20 | export * from 'm/c'; | d.js:4:15:4:19 | 'm/c' |
@@ -102,6 +104,7 @@ test_NamedImportSpecifier
102104test_GlobalVariableRef
103105| a.js:5:31:5:31 | o |
104106| exports.js:3:9:3:15 | exports |
107+ | importmeta.js:1:15:1:17 | URL |
105108| tst.html:6:3:6:7 | alert |
106109test_BulkReExportDeclarations
107110| d.js:4:1:4:20 | export * from 'm/c'; |
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import ImportSpecifiers
22import getLocalName
33import getExportedName
44import OtherImports
5+ import ImportMeta
56import ReExportDeclarations
67import ImportDefaultSpecifiers
78import getImportedName
You can’t perform that action at this time.
0 commit comments