Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement experimentalTopLevelAwait option (#2235)
- Loading branch information
1 parent
cd437b7
commit cf96883
Showing
15 changed files
with
85 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
import MagicString from 'magic-string'; | ||
import { RenderOptions } from '../../utils/renderHelpers'; | ||
import { ExecutionPathOptions } from '../ExecutionPathOptions'; | ||
import ArrowFunctionExpression from './ArrowFunctionExpression'; | ||
import * as NodeType from './NodeType'; | ||
import FunctionNode from './shared/FunctionNode'; | ||
import { Node } from './shared/Node'; | ||
import { ExpressionNode, NodeBase } from './shared/Node'; | ||
|
||
export default class AwaitExpression extends NodeBase { | ||
type: NodeType.tAwaitExpression; | ||
argument: ExpressionNode; | ||
|
||
include() { | ||
super.include(); | ||
if (!this.context.usesTopLevelAwait) { | ||
let parent = this.parent; | ||
do { | ||
if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression) return; | ||
} while ((parent = <Node>(<Node>parent).parent)); | ||
this.context.usesTopLevelAwait = true; | ||
} | ||
} | ||
|
||
hasEffects(options: ExecutionPathOptions) { | ||
return super.hasEffects(options) || !options.ignoreReturnAwaitYield(); | ||
} | ||
|
||
render(code: MagicString, options: RenderOptions) { | ||
super.render(code, options); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
description: 'top-level await support', | ||
formats: ['system', 'es'], | ||
options: { | ||
experimentalTopLevelAwait: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await operation(); |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: async function () { | ||
|
||
await operation(); | ||
|
||
} | ||
}; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
await operation(); | ||
|
||
if (false) | ||
await treeshakenOperation(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.