-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: goldstein: add ability to parse no async code with await
- Loading branch information
1 parent
db11881
commit 98f3048
Showing
9 changed files
with
89 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
function hello() => {} | ||
function world() {} | ||
function hello() { | ||
await world(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
function hello() {} | ||
|
||
function world() {} | ||
async function hello() { | ||
await world(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import {tokTypes as tt} from 'acorn'; | ||
const {defineProperty} = Object; | ||
|
||
export default function fn(Parser) { | ||
return class extends Parser { | ||
parseBlock(createNewLexicalScope, node, exitStrict) { | ||
if (createNewLexicalScope === void 0) | ||
createNewLexicalScope = true; | ||
|
||
if (node === void 0) | ||
node = this.startNode(); | ||
parseFunction(node, statement, allowExpressionBody, isAsync, forInit) { | ||
return super.parseFunction(node, statement, allowExpressionBody, true, forInit); | ||
} | ||
|
||
checkUnreserved({start, end, name}) { | ||
if (this.inGenerator && name === 'yield') | ||
this.raiseRecoverable(start, `Cannot use 'yield' as identifier inside a generator`); | ||
|
||
node.body = []; | ||
// optionally parse arrow | ||
this.eat(tt.arrow); | ||
this.expect(tt.braceL); | ||
if (this.inAsync && name === 'await') | ||
this.raiseRecoverable(start, `Cannot use 'await' as identifier inside an async function`); | ||
|
||
if (createNewLexicalScope) | ||
this.enterScope(0); | ||
if (this.currentThisScope().inClassFieldInit && name === 'arguments') | ||
this.raiseRecoverable(start, `Cannot use 'arguments' in class field initializer`); | ||
|
||
while (this.type !== tt.braceR) { | ||
const stmt = this.parseStatement(null); | ||
node.body.push(stmt); | ||
} | ||
if (this.inClassStaticBlock && (name === 'arguments' || name === 'await')) | ||
this.raise(start, `Cannot use ${name} in class static initialization block`); | ||
|
||
if (exitStrict) | ||
this.strict = false; | ||
if (this.keywords.test(name)) | ||
this.raise(start, `Unexpected keyword '` + name + `'`); | ||
|
||
this.next(); | ||
if (this.options.ecmaVersion < 6 && this.input.slice(start, end).includes('\\')) | ||
return; | ||
|
||
if (createNewLexicalScope) | ||
this.exitScope(); | ||
const re = this.strict ? this.reservedWordsStrict : this.reservedWords; | ||
|
||
return this.finishNode(node, 'BlockStatement'); | ||
if (re.test(name) && !this.inAsync && name === 'await') | ||
defineProperty(this, 'inAsync', { | ||
value: true, | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters