-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
157 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Node from '../Node.js'; | ||
|
||
const noop = () => {}; | ||
|
||
export default class AwaitExpression extends Node { | ||
static removeAsync(code, transforms, async, start, callback = noop) { | ||
if (transforms.asyncAwait && async) { | ||
code.remove(start, start + 6); | ||
callback(); | ||
} | ||
} | ||
|
||
transpile (code, transforms) { | ||
AwaitExpression.removeAsync(code, transforms, true, this.start, () => { | ||
code.insertLeft(this.argument.start, 'return '); | ||
}); | ||
|
||
super.transpile(code, transforms); | ||
} | ||
} |
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,25 @@ | ||
module.exports = [ | ||
{ | ||
description: 'transpiles await arrow function call', | ||
input: `async () => await a()`, | ||
output: `!function() { return Promise.resolve().then(function() { return a() }); }` | ||
}, | ||
|
||
{ | ||
description: 'transpiles await function call', | ||
input: `async function f() { await a(); }`, | ||
output: `function f() { return Promise.resolve().then(function() { return a(); }).then(function() {}) }` | ||
}, | ||
|
||
{ | ||
description: 'transpiles await function call with return statement', | ||
input: `async function f() { return await a(); }`, | ||
output: `function f() { return Promise.resolve().then(function() { return a(); }) }` | ||
}, | ||
|
||
{ | ||
description: 'transpiles await function call with more than one line of code', | ||
input: `async function f() { await a(); thing(); await a2(); stuff(); await a3(); await a4(); }`, | ||
output: `function f() { return Promise.resolve().then(function() { return a(); }) .then(function() { thing(); }) .then(function() { return a2(); }) .then(function() { stuff(); }) .then(function() { return a3(); }) .then(function() { return a4(); }).then(function() {}) }` | ||
} | ||
]; |