JS: add initial support for import.meta expressions in TypeScript#2169
JS: add initial support for import.meta expressions in TypeScript#2169asger-semmle merged 3 commits intogithub:masterfrom
Conversation
| } | ||
|
|
||
| function handleParseCommand(command: ParseCommand) { | ||
| function handleParseCommand(command: ParseCommand, checkPending = true) { |
There was a problem hiding this comment.
This change is not needed to support import.meta.
But it was required for me to run the "standalone" commands, so I kept the change.
|
It might need a db upgrade script. I forgot about that. |
xiemaisi
left a comment
There was a problem hiding this comment.
Looks plausible, though I can't comment on the TypeScript extractor change. I'd also suggest making import.meta expressions source nodes by adding astNode instanceof ImportMetaExpr to the characteristic predicate of SourceNode::DefaultRange in Sources.qll.
As you say, this will need a dbscheme upgrade script.
| /** | ||
| * An `import.meta` expression. | ||
| */ | ||
| class ImportMeta extends @importmetaexpr, Expr { |
There was a problem hiding this comment.
I think this class would feel more at home in Expr.qll, and should probably be called ImportMetaExpr by analogy with other similar classes. Also, it looks like import.meta expressions are pure, so it may be worth adding an override of isImpure().
asger-semmle
left a comment
There was a problem hiding this comment.
We'll also need to open an internal PR to bump the dbscheme hash.
| new Position(metaStart.getLine(), metaStart.getColumn() + 3, metaStart.getOffset() + 3); | ||
| SourceLocation metaLoc = new SourceLocation("new", metaStart, metaEnd); | ||
| Identifier meta = new Identifier(metaLoc, "new"); | ||
| String keyWordKind = syntaxKinds.get(node.getAsJsonPrimitive("keywordToken").getAsInt() + "").toString(); |
There was a problem hiding this comment.
Use getAsString instead of toString.
Also keyWordKind -> keywordKind
| SourceLocation metaLoc = new SourceLocation("new", metaStart, metaEnd); | ||
| Identifier meta = new Identifier(metaLoc, "new"); | ||
| String keyWordKind = syntaxKinds.get(node.getAsJsonPrimitive("keywordToken").getAsInt() + "").toString(); | ||
| String identifier = keyWordKind.equals("\"ImportKeyword\"") ? "import" : "new"; |
There was a problem hiding this comment.
The quotes \" are unnecessary with getAsString
| @@ -1582,8 +1582,10 @@ private Node convertMetaProperty(JsonObject node, SourceLocation loc) throws Par | |||
| Position metaStart = loc.getStart(); | |||
| Position metaEnd = | |||
| new Position(metaStart.getLine(), metaStart.getColumn() + 3, metaStart.getOffset() + 3); | |||
There was a problem hiding this comment.
The magic constant 3 here seems to have been outdated, as it should presumably be 4 for import.meta.
| } | ||
|
|
||
| /** | ||
| * An `import.meta` expression. |
There was a problem hiding this comment.
Our AST classes have concrete syntax examples:
| * An `import.meta` expression. | |
| * An `import.meta` expression. | |
| * | |
| * Example: | |
| * ```js | |
| * let url = import.meta.url; | |
| * ``` |
| - [rate-limiter-flexible](https://www.npmjs.com/package/rate-limiter-flexible) | ||
|
|
||
| * The call graph has been improved to resolve method calls in more cases. This may produce more security alerts. | ||
| * import.meta is now supported in TypeScript. |
There was a problem hiding this comment.
With this change I believe we have complete support for 3.6 so I'd rather just mention that we support TypeScript 3.6 now.
Bonus nitpick: add linebreak before the bullet point
javascript/upgrades/ab0dab3b55b386f366e9904e10139edebca0495c/upgrade.properties
Outdated
Show resolved
Hide resolved
|
Some tests are failing (in the internal PR) due to |
Co-Authored-By: Max Schaefer <54907921+max-schaefer@users.noreply.github.com>
9387c11 to
ab42b5d
Compare
|
Internal PR just turned green. |
Adding initial support for
import.metain TypeScript.This is only for TypeScript, and the recently reported FP is therefore not fixed.
Adding support for
import.metain JavaScript should just be a case of emitting anew MetaProperty(..)instead ofunexpected token.