using is not a keyword

This commit is contained in:
erik-krogh
2023-08-30 08:44:59 +02:00
parent 5e11fe74f7
commit 2643ab3dbf
5 changed files with 60 additions and 6 deletions

View File

@@ -51,9 +51,6 @@ import java.util.Set;
public class ESNextParser extends JSXParser {
public ESNextParser(Options options, String input, int startPos) {
super(options.allowImportExportEverywhere(true), input, startPos);
// recognise `using` as a keyword. See https://github.com/tc39/proposal-explicit-resource-management
this.keywords.add("using");
}
/*

View File

@@ -2699,6 +2699,19 @@ public class Parser {
|| !Identifiers.isIdentifierChar(this.input.codePointAt(next + len), false));
}
// matches "using [identifier]"
boolean isUsingDecl() {
if (this.type != TokenType.name
|| this.options.ecmaVersion() < 8
|| !this.value.equals("using")) return false;
Matcher m = Whitespace.skipWhiteSpace.matcher(this.input);
m.find(this.pos);
int next = m.end();
return !Whitespace.lineBreakG.matcher(inputSubstring(this.pos, next)).matches()
&& Identifiers.isIdentifierChar(this.input.codePointAt(next + 1), false);
}
/**
* Parse a single statement.
*
@@ -2749,7 +2762,7 @@ public class Parser {
return this.parseThrowStatement(startLoc);
} else if (starttype == TokenType._try) {
return this.parseTryStatement(startLoc);
} else if (starttype == TokenType._const || starttype == TokenType._var || starttype == TokenType._using) {
} else if (starttype == TokenType._const || starttype == TokenType._var || this.isUsingDecl()) {
if (kind == null) kind = String.valueOf(this.value);
if (!declaration && !kind.equals("var")) this.unexpected();
return this.parseVarStatement(startLoc, kind);
@@ -2859,7 +2872,7 @@ public class Parser {
if (this.isAwaitUsing() && this.inAsync) {
this.next(); // just skip the await and treat it as a `using` statement
}
if (this.type == TokenType._var || this.type == TokenType._const || isLet || this.type == TokenType._using) {
if (this.type == TokenType._var || this.type == TokenType._const || isLet || (this.type == TokenType.name && this.value.equals("using"))) {
Position initStartLoc = this.startLoc;
String kind = isLet ? "let" : String.valueOf(this.value);
this.next();

View File

@@ -180,7 +180,6 @@ public class TokenType {
_try = new TokenType(kw("try")),
_var = new TokenType(kw("var")),
_const = new TokenType(kw("const")),
_using = new TokenType(kw("using")),
_while = new TokenType(kw("while").isLoop()),
_with = new TokenType(kw("with")),
_new = new TokenType(kw("new").beforeExpr().startsExpr()),

View File

@@ -1,6 +1,8 @@
nodes
| file://:0:0:0:0 | (Arguments) | semmle.label | (Arguments) |
| file://:0:0:0:0 | (Arguments) | semmle.label | (Arguments) |
| file://:0:0:0:0 | (Arguments) | semmle.label | (Arguments) |
| file://:0:0:0:0 | (Parameters) | semmle.label | (Parameters) |
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | semmle.label | [FunctionDeclStmt] functio ... } } |
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | semmle.order | 1 |
| tst.js:1:10:1:10 | [VarDecl] g | semmle.label | [VarDecl] g |
@@ -47,11 +49,27 @@ nodes
| tst.js:20:5:20:23 | [ExprStmt] console.log("end"); | semmle.label | [ExprStmt] console.log("end"); |
| tst.js:20:13:20:15 | [Label] log | semmle.label | [Label] log |
| tst.js:20:17:20:21 | [Literal] "end" | semmle.label | [Literal] "end" |
| tst.js:23:1:28:1 | [FunctionDeclStmt] functio ... } } | semmle.label | [FunctionDeclStmt] functio ... } } |
| tst.js:23:1:28:1 | [FunctionDeclStmt] functio ... } } | semmle.order | 3 |
| tst.js:23:10:23:18 | [VarDecl] usesUsing | semmle.label | [VarDecl] usesUsing |
| tst.js:23:22:28:1 | [BlockStmt] { u ... } } | semmle.label | [BlockStmt] { u ... } } |
| tst.js:24:5:24:9 | [VarRef] using | semmle.label | [VarRef] using |
| tst.js:24:5:24:16 | [CallExpr] using("foo") | semmle.label | [CallExpr] using("foo") |
| tst.js:24:5:24:17 | [ExprStmt] using("foo"); | semmle.label | [ExprStmt] using("foo"); |
| tst.js:24:11:24:15 | [Literal] "foo" | semmle.label | [Literal] "foo" |
| tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | semmle.label | [FunctionDeclStmt] functio ... . } |
| tst.js:25:14:25:18 | [VarDecl] using | semmle.label | [VarDecl] using |
| tst.js:25:20:25:22 | [SimpleParameter] foo | semmle.label | [SimpleParameter] foo |
| tst.js:25:25:27:5 | [BlockStmt] { ... . } | semmle.label | [BlockStmt] { ... . } |
edges
| file://:0:0:0:0 | (Arguments) | tst.js:4:10:4:18 | [AssignExpr] test = 20 | semmle.label | 0 |
| file://:0:0:0:0 | (Arguments) | tst.js:4:10:4:18 | [AssignExpr] test = 20 | semmle.order | 0 |
| file://:0:0:0:0 | (Arguments) | tst.js:20:17:20:21 | [Literal] "end" | semmle.label | 0 |
| file://:0:0:0:0 | (Arguments) | tst.js:20:17:20:21 | [Literal] "end" | semmle.order | 0 |
| file://:0:0:0:0 | (Arguments) | tst.js:24:11:24:15 | [Literal] "foo" | semmle.label | 0 |
| file://:0:0:0:0 | (Arguments) | tst.js:24:11:24:15 | [Literal] "foo" | semmle.order | 0 |
| file://:0:0:0:0 | (Parameters) | tst.js:25:20:25:22 | [SimpleParameter] foo | semmle.label | 0 |
| file://:0:0:0:0 | (Parameters) | tst.js:25:20:25:22 | [SimpleParameter] foo | semmle.order | 0 |
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | tst.js:1:10:1:10 | [VarDecl] g | semmle.label | 0 |
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | tst.js:1:10:1:10 | [VarDecl] g | semmle.order | 0 |
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | tst.js:1:14:10:1 | [BlockStmt] { u ... } } | semmle.label | 5 |
@@ -136,5 +154,25 @@ edges
| tst.js:20:5:20:22 | [MethodCallExpr] console.log("end") | tst.js:20:5:20:15 | [DotExpr] console.log | semmle.order | 0 |
| tst.js:20:5:20:23 | [ExprStmt] console.log("end"); | tst.js:20:5:20:22 | [MethodCallExpr] console.log("end") | semmle.label | 1 |
| tst.js:20:5:20:23 | [ExprStmt] console.log("end"); | tst.js:20:5:20:22 | [MethodCallExpr] console.log("end") | semmle.order | 1 |
| tst.js:23:1:28:1 | [FunctionDeclStmt] functio ... } } | tst.js:23:10:23:18 | [VarDecl] usesUsing | semmle.label | 0 |
| tst.js:23:1:28:1 | [FunctionDeclStmt] functio ... } } | tst.js:23:10:23:18 | [VarDecl] usesUsing | semmle.order | 0 |
| tst.js:23:1:28:1 | [FunctionDeclStmt] functio ... } } | tst.js:23:22:28:1 | [BlockStmt] { u ... } } | semmle.label | 5 |
| tst.js:23:1:28:1 | [FunctionDeclStmt] functio ... } } | tst.js:23:22:28:1 | [BlockStmt] { u ... } } | semmle.order | 5 |
| tst.js:23:22:28:1 | [BlockStmt] { u ... } } | tst.js:24:5:24:17 | [ExprStmt] using("foo"); | semmle.label | 1 |
| tst.js:23:22:28:1 | [BlockStmt] { u ... } } | tst.js:24:5:24:17 | [ExprStmt] using("foo"); | semmle.order | 1 |
| tst.js:23:22:28:1 | [BlockStmt] { u ... } } | tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | semmle.label | 2 |
| tst.js:23:22:28:1 | [BlockStmt] { u ... } } | tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | semmle.order | 2 |
| tst.js:24:5:24:16 | [CallExpr] using("foo") | file://:0:0:0:0 | (Arguments) | semmle.label | 1 |
| tst.js:24:5:24:16 | [CallExpr] using("foo") | file://:0:0:0:0 | (Arguments) | semmle.order | 1 |
| tst.js:24:5:24:16 | [CallExpr] using("foo") | tst.js:24:5:24:9 | [VarRef] using | semmle.label | 0 |
| tst.js:24:5:24:16 | [CallExpr] using("foo") | tst.js:24:5:24:9 | [VarRef] using | semmle.order | 0 |
| tst.js:24:5:24:17 | [ExprStmt] using("foo"); | tst.js:24:5:24:16 | [CallExpr] using("foo") | semmle.label | 1 |
| tst.js:24:5:24:17 | [ExprStmt] using("foo"); | tst.js:24:5:24:16 | [CallExpr] using("foo") | semmle.order | 1 |
| tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | file://:0:0:0:0 | (Parameters) | semmle.label | 1 |
| tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | file://:0:0:0:0 | (Parameters) | semmle.order | 1 |
| tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | tst.js:25:14:25:18 | [VarDecl] using | semmle.label | 0 |
| tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | tst.js:25:14:25:18 | [VarDecl] using | semmle.order | 0 |
| tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | tst.js:25:25:27:5 | [BlockStmt] { ... . } | semmle.label | 5 |
| tst.js:25:5:27:5 | [FunctionDeclStmt] functio ... . } | tst.js:25:25:27:5 | [BlockStmt] { ... . } | semmle.order | 5 |
graphProperties
| semmle.graphKind | tree |

View File

@@ -18,4 +18,11 @@ async function h() {
}
console.log("end");
}
function usesUsing() {
using("foo");
function using(foo) {
// ...
}
}