acorn-loose
Advanced tools
+6
-0
@@ -0,1 +1,7 @@ | ||
| ## 8.1.0 (2021-04-24) | ||
| ### New features | ||
| Add support for ES2022 class fields and private methods. | ||
| ## 8.0.2 (2021-01-25) | ||
@@ -2,0 +8,0 @@ |
+137
-47
@@ -32,2 +32,3 @@ (function (global, factory) { | ||
| this.inAsync = false; | ||
| this.inGenerator = false; | ||
| this.inFunction = false; | ||
@@ -572,44 +573,4 @@ }; | ||
| while (!this.closes(acorn.tokTypes.braceR, indent, line)) { | ||
| if (this.semicolon()) { continue } | ||
| var method = this.startNode(), isGenerator = (void 0), isAsync = (void 0); | ||
| if (this.options.ecmaVersion >= 6) { | ||
| method.static = false; | ||
| isGenerator = this.eat(acorn.tokTypes.star); | ||
| } | ||
| this.parsePropertyName(method); | ||
| if (isDummy(method.key)) { if (isDummy(this.parseMaybeAssign())) { this.next(); } this.eat(acorn.tokTypes.comma); continue } | ||
| if (method.key.type === "Identifier" && !method.computed && method.key.name === "static" && | ||
| (this.tok.type !== acorn.tokTypes.parenL && this.tok.type !== acorn.tokTypes.braceL)) { | ||
| method.static = true; | ||
| isGenerator = this.eat(acorn.tokTypes.star); | ||
| this.parsePropertyName(method); | ||
| } else { | ||
| method.static = false; | ||
| } | ||
| if (!method.computed && | ||
| method.key.type === "Identifier" && method.key.name === "async" && this.tok.type !== acorn.tokTypes.parenL && | ||
| !this.canInsertSemicolon()) { | ||
| isAsync = true; | ||
| isGenerator = this.options.ecmaVersion >= 9 && this.eat(acorn.tokTypes.star); | ||
| this.parsePropertyName(method); | ||
| } else { | ||
| isAsync = false; | ||
| } | ||
| if (this.options.ecmaVersion >= 5 && method.key.type === "Identifier" && | ||
| !method.computed && (method.key.name === "get" || method.key.name === "set") && | ||
| this.tok.type !== acorn.tokTypes.parenL && this.tok.type !== acorn.tokTypes.braceL) { | ||
| method.kind = method.key.name; | ||
| this.parsePropertyName(method); | ||
| method.value = this.parseMethod(false); | ||
| } else { | ||
| if (!method.computed && !method.static && !isGenerator && !isAsync && ( | ||
| method.key.type === "Identifier" && method.key.name === "constructor" || | ||
| method.key.type === "Literal" && method.key.value === "constructor")) { | ||
| method.kind = "constructor"; | ||
| } else { | ||
| method.kind = "method"; | ||
| } | ||
| method.value = this.parseMethod(isGenerator, isAsync); | ||
| } | ||
| node.body.body.push(this.finishNode(method, "MethodDefinition")); | ||
| var element = this.parseClassElement(); | ||
| if (element) { node.body.body.push(element); } | ||
| } | ||
@@ -628,4 +589,119 @@ this.popCx(); | ||
| lp$1.parseClassElement = function() { | ||
| if (this.eat(acorn.tokTypes.semi)) { return null } | ||
| var ref = this.options; | ||
| var ecmaVersion = ref.ecmaVersion; | ||
| var locations = ref.locations; | ||
| var indent = this.curIndent; | ||
| var line = this.curLineStart; | ||
| var node = this.startNode(); | ||
| var keyName = ""; | ||
| var isGenerator = false; | ||
| var isAsync = false; | ||
| var kind = "method"; | ||
| // Parse modifiers | ||
| node.static = false; | ||
| if (this.eatContextual("static")) { | ||
| if (this.isClassElementNameStart() || this.toks.type === acorn.tokTypes.star) { | ||
| node.static = true; | ||
| } else { | ||
| keyName = "static"; | ||
| } | ||
| } | ||
| if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) { | ||
| if ((this.isClassElementNameStart() || this.toks.type === acorn.tokTypes.star) && !this.canInsertSemicolon()) { | ||
| isAsync = true; | ||
| } else { | ||
| keyName = "async"; | ||
| } | ||
| } | ||
| if (!keyName) { | ||
| isGenerator = this.eat(acorn.tokTypes.star); | ||
| var lastValue = this.toks.value; | ||
| if (this.eatContextual("get") || this.eatContextual("set")) { | ||
| if (this.isClassElementNameStart()) { | ||
| kind = lastValue; | ||
| } else { | ||
| keyName = lastValue; | ||
| } | ||
| } | ||
| } | ||
| // Parse element name | ||
| if (keyName) { | ||
| // 'async', 'get', 'set', or 'static' were not a keyword contextually. | ||
| // The last token is any of those. Make it the element name. | ||
| node.computed = false; | ||
| node.key = this.startNodeAt(locations ? [this.toks.lastTokStart, this.toks.lastTokStartLoc] : this.toks.lastTokStart); | ||
| node.key.name = keyName; | ||
| this.finishNode(node.key, "Identifier"); | ||
| } else { | ||
| this.parseClassElementName(node); | ||
| // From https://github.com/acornjs/acorn/blob/7deba41118d6384a2c498c61176b3cf434f69590/acorn-loose/src/statement.js#L291 | ||
| // Skip broken stuff. | ||
| if (isDummy(node.key)) { | ||
| if (isDummy(this.parseMaybeAssign())) { this.next(); } | ||
| this.eat(acorn.tokTypes.comma); | ||
| return null | ||
| } | ||
| } | ||
| // Parse element value | ||
| if (ecmaVersion < 13 || this.toks.type === acorn.tokTypes.parenL || kind !== "method" || isGenerator || isAsync) { | ||
| // Method | ||
| var isConstructor = | ||
| !node.computed && | ||
| !node.static && | ||
| !isGenerator && | ||
| !isAsync && | ||
| kind === "method" && ( | ||
| node.key.type === "Identifier" && node.key.name === "constructor" || | ||
| node.key.type === "Literal" && node.key.value === "constructor" | ||
| ); | ||
| node.kind = isConstructor ? "constructor" : kind; | ||
| node.value = this.parseMethod(isGenerator, isAsync); | ||
| this.finishNode(node, "MethodDefinition"); | ||
| } else { | ||
| // Field | ||
| if (this.eat(acorn.tokTypes.eq)) { | ||
| if (this.curLineStart !== line && this.curIndent <= indent && this.tokenStartsLine()) { | ||
| // Estimated the next line is the next class element by indentations. | ||
| node.value = null; | ||
| } else { | ||
| var oldInAsync = this.inAsync; | ||
| var oldInGenerator = this.inGenerator; | ||
| this.inAsync = false; | ||
| this.inGenerator = false; | ||
| node.value = this.parseMaybeAssign(); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| } | ||
| } else { | ||
| node.value = null; | ||
| } | ||
| this.semicolon(); | ||
| this.finishNode(node, "PropertyDefinition"); | ||
| } | ||
| return node | ||
| }; | ||
| lp$1.isClassElementNameStart = function() { | ||
| return this.toks.isClassElementNameStart() | ||
| }; | ||
| lp$1.parseClassElementName = function(element) { | ||
| if (this.toks.type === acorn.tokTypes.privateId) { | ||
| element.computed = false; | ||
| element.key = this.parsePrivateIdent(); | ||
| } else { | ||
| this.parsePropertyName(element); | ||
| } | ||
| }; | ||
| lp$1.parseFunction = function(node, isStatement, isAsync) { | ||
| var oldInAsync = this.inAsync, oldInFunction = this.inFunction; | ||
| var oldInAsync = this.inAsync, oldInGenerator = this.inGenerator, oldInFunction = this.inFunction; | ||
| this.initFunction(node); | ||
@@ -641,2 +717,3 @@ if (this.options.ecmaVersion >= 6) { | ||
| this.inAsync = node.async; | ||
| this.inGenerator = node.generator; | ||
| this.inFunction = true; | ||
@@ -647,2 +724,3 @@ node.params = this.parseFunctionParams(); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| this.inFunction = oldInFunction; | ||
@@ -811,3 +889,4 @@ return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
| lp$2.parseMaybeAssign = function(noIn) { | ||
| if (this.toks.isContextual("yield")) { | ||
| // `yield` should be an identifier reference if it's not in generator functions. | ||
| if (this.inGenerator && this.toks.isContextual("yield")) { | ||
| var node = this.startNode(); | ||
@@ -1277,2 +1356,3 @@ this.next(); | ||
| if (this.tok.type === acorn.tokTypes.name || this.tok.type.keyword) { return this.parseIdent() } | ||
| if (this.tok.type === acorn.tokTypes.privateId) { return this.parsePrivateIdent() } | ||
| }; | ||
@@ -1289,2 +1369,9 @@ | ||
| lp$2.parsePrivateIdent = function() { | ||
| var node = this.startNode(); | ||
| node.name = this.tok.value; | ||
| this.next(); | ||
| return this.finishNode(node, "PrivateIdentifier") | ||
| }; | ||
| lp$2.initFunction = function(node) { | ||
@@ -1350,3 +1437,3 @@ node.id = null; | ||
| lp$2.parseMethod = function(isGenerator, isAsync) { | ||
| var node = this.startNode(), oldInAsync = this.inAsync, oldInFunction = this.inFunction; | ||
| var node = this.startNode(), oldInAsync = this.inAsync, oldInGenerator = this.inGenerator, oldInFunction = this.inFunction; | ||
| this.initFunction(node); | ||
@@ -1358,2 +1445,3 @@ if (this.options.ecmaVersion >= 6) | ||
| this.inAsync = node.async; | ||
| this.inGenerator = node.generator; | ||
| this.inFunction = true; | ||
@@ -1364,2 +1452,3 @@ node.params = this.parseFunctionParams(); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| this.inFunction = oldInFunction; | ||
@@ -1370,3 +1459,3 @@ return this.finishNode(node, "FunctionExpression") | ||
| lp$2.parseArrowExpression = function(node, params, isAsync) { | ||
| var oldInAsync = this.inAsync, oldInFunction = this.inFunction; | ||
| var oldInAsync = this.inAsync, oldInGenerator = this.inGenerator, oldInFunction = this.inFunction; | ||
| this.initFunction(node); | ||
@@ -1376,2 +1465,3 @@ if (this.options.ecmaVersion >= 8) | ||
| this.inAsync = node.async; | ||
| this.inGenerator = false; | ||
| this.inFunction = true; | ||
@@ -1387,2 +1477,3 @@ node.params = this.toAssignableList(params, true); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| this.inFunction = oldInFunction; | ||
@@ -1442,2 +1533,1 @@ return this.finishNode(node, "ArrowFunctionExpression") | ||
| }))); | ||
| //# sourceMappingURL=acorn-loose.js.map |
+137
-47
@@ -28,2 +28,3 @@ import { tokTypes, SourceLocation, Node, lineBreak, isNewLine, Parser, Token, getLineInfo, lineBreakG, defaultOptions } from 'acorn'; | ||
| this.inAsync = false; | ||
| this.inGenerator = false; | ||
| this.inFunction = false; | ||
@@ -568,44 +569,4 @@ }; | ||
| while (!this.closes(tokTypes.braceR, indent, line)) { | ||
| if (this.semicolon()) { continue } | ||
| var method = this.startNode(), isGenerator = (void 0), isAsync = (void 0); | ||
| if (this.options.ecmaVersion >= 6) { | ||
| method.static = false; | ||
| isGenerator = this.eat(tokTypes.star); | ||
| } | ||
| this.parsePropertyName(method); | ||
| if (isDummy(method.key)) { if (isDummy(this.parseMaybeAssign())) { this.next(); } this.eat(tokTypes.comma); continue } | ||
| if (method.key.type === "Identifier" && !method.computed && method.key.name === "static" && | ||
| (this.tok.type !== tokTypes.parenL && this.tok.type !== tokTypes.braceL)) { | ||
| method.static = true; | ||
| isGenerator = this.eat(tokTypes.star); | ||
| this.parsePropertyName(method); | ||
| } else { | ||
| method.static = false; | ||
| } | ||
| if (!method.computed && | ||
| method.key.type === "Identifier" && method.key.name === "async" && this.tok.type !== tokTypes.parenL && | ||
| !this.canInsertSemicolon()) { | ||
| isAsync = true; | ||
| isGenerator = this.options.ecmaVersion >= 9 && this.eat(tokTypes.star); | ||
| this.parsePropertyName(method); | ||
| } else { | ||
| isAsync = false; | ||
| } | ||
| if (this.options.ecmaVersion >= 5 && method.key.type === "Identifier" && | ||
| !method.computed && (method.key.name === "get" || method.key.name === "set") && | ||
| this.tok.type !== tokTypes.parenL && this.tok.type !== tokTypes.braceL) { | ||
| method.kind = method.key.name; | ||
| this.parsePropertyName(method); | ||
| method.value = this.parseMethod(false); | ||
| } else { | ||
| if (!method.computed && !method.static && !isGenerator && !isAsync && ( | ||
| method.key.type === "Identifier" && method.key.name === "constructor" || | ||
| method.key.type === "Literal" && method.key.value === "constructor")) { | ||
| method.kind = "constructor"; | ||
| } else { | ||
| method.kind = "method"; | ||
| } | ||
| method.value = this.parseMethod(isGenerator, isAsync); | ||
| } | ||
| node.body.body.push(this.finishNode(method, "MethodDefinition")); | ||
| var element = this.parseClassElement(); | ||
| if (element) { node.body.body.push(element); } | ||
| } | ||
@@ -624,4 +585,119 @@ this.popCx(); | ||
| lp$1.parseClassElement = function() { | ||
| if (this.eat(tokTypes.semi)) { return null } | ||
| var ref = this.options; | ||
| var ecmaVersion = ref.ecmaVersion; | ||
| var locations = ref.locations; | ||
| var indent = this.curIndent; | ||
| var line = this.curLineStart; | ||
| var node = this.startNode(); | ||
| var keyName = ""; | ||
| var isGenerator = false; | ||
| var isAsync = false; | ||
| var kind = "method"; | ||
| // Parse modifiers | ||
| node.static = false; | ||
| if (this.eatContextual("static")) { | ||
| if (this.isClassElementNameStart() || this.toks.type === tokTypes.star) { | ||
| node.static = true; | ||
| } else { | ||
| keyName = "static"; | ||
| } | ||
| } | ||
| if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) { | ||
| if ((this.isClassElementNameStart() || this.toks.type === tokTypes.star) && !this.canInsertSemicolon()) { | ||
| isAsync = true; | ||
| } else { | ||
| keyName = "async"; | ||
| } | ||
| } | ||
| if (!keyName) { | ||
| isGenerator = this.eat(tokTypes.star); | ||
| var lastValue = this.toks.value; | ||
| if (this.eatContextual("get") || this.eatContextual("set")) { | ||
| if (this.isClassElementNameStart()) { | ||
| kind = lastValue; | ||
| } else { | ||
| keyName = lastValue; | ||
| } | ||
| } | ||
| } | ||
| // Parse element name | ||
| if (keyName) { | ||
| // 'async', 'get', 'set', or 'static' were not a keyword contextually. | ||
| // The last token is any of those. Make it the element name. | ||
| node.computed = false; | ||
| node.key = this.startNodeAt(locations ? [this.toks.lastTokStart, this.toks.lastTokStartLoc] : this.toks.lastTokStart); | ||
| node.key.name = keyName; | ||
| this.finishNode(node.key, "Identifier"); | ||
| } else { | ||
| this.parseClassElementName(node); | ||
| // From https://github.com/acornjs/acorn/blob/7deba41118d6384a2c498c61176b3cf434f69590/acorn-loose/src/statement.js#L291 | ||
| // Skip broken stuff. | ||
| if (isDummy(node.key)) { | ||
| if (isDummy(this.parseMaybeAssign())) { this.next(); } | ||
| this.eat(tokTypes.comma); | ||
| return null | ||
| } | ||
| } | ||
| // Parse element value | ||
| if (ecmaVersion < 13 || this.toks.type === tokTypes.parenL || kind !== "method" || isGenerator || isAsync) { | ||
| // Method | ||
| var isConstructor = | ||
| !node.computed && | ||
| !node.static && | ||
| !isGenerator && | ||
| !isAsync && | ||
| kind === "method" && ( | ||
| node.key.type === "Identifier" && node.key.name === "constructor" || | ||
| node.key.type === "Literal" && node.key.value === "constructor" | ||
| ); | ||
| node.kind = isConstructor ? "constructor" : kind; | ||
| node.value = this.parseMethod(isGenerator, isAsync); | ||
| this.finishNode(node, "MethodDefinition"); | ||
| } else { | ||
| // Field | ||
| if (this.eat(tokTypes.eq)) { | ||
| if (this.curLineStart !== line && this.curIndent <= indent && this.tokenStartsLine()) { | ||
| // Estimated the next line is the next class element by indentations. | ||
| node.value = null; | ||
| } else { | ||
| var oldInAsync = this.inAsync; | ||
| var oldInGenerator = this.inGenerator; | ||
| this.inAsync = false; | ||
| this.inGenerator = false; | ||
| node.value = this.parseMaybeAssign(); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| } | ||
| } else { | ||
| node.value = null; | ||
| } | ||
| this.semicolon(); | ||
| this.finishNode(node, "PropertyDefinition"); | ||
| } | ||
| return node | ||
| }; | ||
| lp$1.isClassElementNameStart = function() { | ||
| return this.toks.isClassElementNameStart() | ||
| }; | ||
| lp$1.parseClassElementName = function(element) { | ||
| if (this.toks.type === tokTypes.privateId) { | ||
| element.computed = false; | ||
| element.key = this.parsePrivateIdent(); | ||
| } else { | ||
| this.parsePropertyName(element); | ||
| } | ||
| }; | ||
| lp$1.parseFunction = function(node, isStatement, isAsync) { | ||
| var oldInAsync = this.inAsync, oldInFunction = this.inFunction; | ||
| var oldInAsync = this.inAsync, oldInGenerator = this.inGenerator, oldInFunction = this.inFunction; | ||
| this.initFunction(node); | ||
@@ -637,2 +713,3 @@ if (this.options.ecmaVersion >= 6) { | ||
| this.inAsync = node.async; | ||
| this.inGenerator = node.generator; | ||
| this.inFunction = true; | ||
@@ -643,2 +720,3 @@ node.params = this.parseFunctionParams(); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| this.inFunction = oldInFunction; | ||
@@ -807,3 +885,4 @@ return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
| lp$2.parseMaybeAssign = function(noIn) { | ||
| if (this.toks.isContextual("yield")) { | ||
| // `yield` should be an identifier reference if it's not in generator functions. | ||
| if (this.inGenerator && this.toks.isContextual("yield")) { | ||
| var node = this.startNode(); | ||
@@ -1273,2 +1352,3 @@ this.next(); | ||
| if (this.tok.type === tokTypes.name || this.tok.type.keyword) { return this.parseIdent() } | ||
| if (this.tok.type === tokTypes.privateId) { return this.parsePrivateIdent() } | ||
| }; | ||
@@ -1285,2 +1365,9 @@ | ||
| lp$2.parsePrivateIdent = function() { | ||
| var node = this.startNode(); | ||
| node.name = this.tok.value; | ||
| this.next(); | ||
| return this.finishNode(node, "PrivateIdentifier") | ||
| }; | ||
| lp$2.initFunction = function(node) { | ||
@@ -1346,3 +1433,3 @@ node.id = null; | ||
| lp$2.parseMethod = function(isGenerator, isAsync) { | ||
| var node = this.startNode(), oldInAsync = this.inAsync, oldInFunction = this.inFunction; | ||
| var node = this.startNode(), oldInAsync = this.inAsync, oldInGenerator = this.inGenerator, oldInFunction = this.inFunction; | ||
| this.initFunction(node); | ||
@@ -1354,2 +1441,3 @@ if (this.options.ecmaVersion >= 6) | ||
| this.inAsync = node.async; | ||
| this.inGenerator = node.generator; | ||
| this.inFunction = true; | ||
@@ -1360,2 +1448,3 @@ node.params = this.parseFunctionParams(); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| this.inFunction = oldInFunction; | ||
@@ -1366,3 +1455,3 @@ return this.finishNode(node, "FunctionExpression") | ||
| lp$2.parseArrowExpression = function(node, params, isAsync) { | ||
| var oldInAsync = this.inAsync, oldInFunction = this.inFunction; | ||
| var oldInAsync = this.inAsync, oldInGenerator = this.inGenerator, oldInFunction = this.inFunction; | ||
| this.initFunction(node); | ||
@@ -1372,2 +1461,3 @@ if (this.options.ecmaVersion >= 8) | ||
| this.inAsync = node.async; | ||
| this.inGenerator = false; | ||
| this.inFunction = true; | ||
@@ -1383,2 +1473,3 @@ node.params = this.toAssignableList(params, true); | ||
| this.inAsync = oldInAsync; | ||
| this.inGenerator = oldInGenerator; | ||
| this.inFunction = oldInFunction; | ||
@@ -1432,2 +1523,1 @@ return this.finishNode(node, "ArrowFunctionExpression") | ||
| export { LooseParser, isDummy, parse }; | ||
| //# sourceMappingURL=acorn-loose.mjs.map |
+2
-2
@@ -18,6 +18,6 @@ { | ||
| }, | ||
| "version": "8.0.2", | ||
| "version": "8.1.0", | ||
| "engines": {"node": ">=0.4.0"}, | ||
| "dependencies": { | ||
| "acorn": "^8.0.0" | ||
| "acorn": "^8.2.0" | ||
| }, | ||
@@ -24,0 +24,0 @@ "maintainers": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
2736
6.21%111315
-65.88%6
-25%3
Infinity%Updated