Parser refactoring (#11871)

* refactor: parseMaybeUnary => parseUnary

* refactor: extract shouldExitDescending method

* refactor: add parseUpdate

* refactor: avoid comparing with hardcoded token value

* refactor: add ParseNewOrNewTarget

* refactor: add parseCoverCallAndAsyncArrowHead

* add parseBind

* refactor: polish parseTaggedTemplateExpression interface

* refactor: add parseMember method

* refactor: add parseSuper method

* refactor: add parseAsyncArrowUnaryFunction method

* fix: disallow line break before async binding arrow

* refactor: simplify tt.name logic

* refactor: add parseDo method

* refactor: misc

* refactor: rename parseObjectMember by parsePropertyDefinition

* refactor: unify set/get/async keyword parsing in ObjectMethod

* refactor: misc

* refactor: add parseArrayLike method

* refactor: move fsharp epilogure and prologue inside parseObjectLike

* fixup

* refactor: rename parseFunctionExpression to parseFunctionOrFunctionSent

* refactor: remove redundant logic

* refactor: rename parseClassPropertyName by parseClassElementName

* refactor: avoid unecessary lookahead when parsing tt._export

* fix: export-default-from should support escaped async as export binding

* address review comments

* parseUnary -> parseMaybeUnary
This commit is contained in:
Huáng Jùnliàng
2020-07-31 20:36:04 -04:00
committed by GitHub
parent ad60153a98
commit a4ebe29b3f
29 changed files with 620 additions and 430 deletions

View File

@@ -1,3 +1,3 @@
{
"throws": "Unexpected token, expected \"{\" (1:7)"
}
}

View File

@@ -0,0 +1,2 @@
async x
=> x

View File

@@ -0,0 +1,39 @@
{
"type": "File",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
"errors": [
"SyntaxError: No line break is allowed before '=>' (2:2)"
],
"program": {
"type": "Program",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
"expression": {
"type": "ArrowFunctionExpression",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
"id": null,
"generator": false,
"async": true,
"params": [
{
"type": "Identifier",
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"x"},
"name": "x"
}
],
"body": {
"type": "Identifier",
"start":11,"end":12,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"x"},
"name": "x"
}
}
}
],
"directives": []
}
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["exportDefaultFrom"],
"sourceType": "module"
}

View File

@@ -1,4 +0,0 @@
{
"sourceType": "module",
"plugins": ["exportDefaultFrom"]
}

View File

@@ -1,4 +0,0 @@
{
"sourceType": "module",
"plugins": ["exportDefaultFrom"]
}

View File

@@ -0,0 +1 @@
export asyn\u{63} from "async";

View File

@@ -0,0 +1,37 @@
{
"type": "File",
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},
"program": {
"type": "Program",
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}},
"specifiers": [
{
"type": "ExportDefaultSpecifier",
"start":7,"end":17,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":17}},
"exported": {
"type": "Identifier",
"start":7,"end":17,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":17},"identifierName":"async"},
"name": "async"
}
}
],
"source": {
"type": "StringLiteral",
"start":23,"end":30,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":30}},
"extra": {
"rawValue": "async",
"raw": "\"async\""
},
"value": "async"
}
}
],
"directives": []
}
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["exportDefaultFrom"],
"sourceType": "module"
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["exportDefaultFrom"],
"sourceType": "module"
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["exportDefaultFrom"],
"sourceType": "module"
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["exportDefaultFrom"],
"sourceType": "module"
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["exportDefaultFrom"],
"sourceType": "module"
}

View File

@@ -34,7 +34,6 @@
},
"computed": false,
"kind": "set",
"variance": null,
"id": null,
"generator": false,
"async": false,

View File

@@ -34,7 +34,6 @@
},
"computed": false,
"kind": "set",
"variance": null,
"id": null,
"generator": false,
"async": false,

View File

@@ -34,7 +34,6 @@
},
"computed": false,
"kind": "get",
"variance": null,
"id": null,
"generator": false,
"async": false,