Skip to content

Commit

Permalink
Revert change dropping await on return
Browse files Browse the repository at this point in the history
Reverses lightscript#23

`return await x` is semantically different from `return x`. The user should be in control of when he wants which semantics, rather than `await` implicitly being dropped.
  • Loading branch information
wcjohnson committed Oct 25, 2017
1 parent e577175 commit 2187800
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/helpers/functions.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export addImplicitReturns(functionPath) ->
throw path.buildCodeFrameError("Ambiguous implicit `return` of multiple variables. " +
"Add an explicit `return` statement on the next line.")

if expr~isa("AwaitExpression"):
t.returnStatement(expr.argument)~atNode(expr)
else:
t.returnStatement(expr)~atNode(expr)
t.returnStatement(expr)~atNode(expr)

transformTails(
functionPath.get("body")
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/arrow-function-expressions/async/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(async function () {
await 1;
return 2;
return await 2;
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async () => {
await 1;
return 2;
return await 2;
};
2 changes: 1 addition & 1 deletion test/fixtures/arrow-methods-class/fat-async/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class A {
}

async f() {
return this;
return await this;
}
}
2 changes: 1 addition & 1 deletion test/fixtures/arrow-methods-obj/fat-async/expected.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const o = {
async f() {
return this;
return await this;
} };
o.f = o.f.bind(o);
2 changes: 1 addition & 1 deletion test/fixtures/arrow-methods-obj/skinny-async/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const o = {
async f(x) {
return x;
return await x;
} };
2 changes: 1 addition & 1 deletion test/fixtures/await-arrow/await-array/expected.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
async function fn() {
const x = await Promise.all([p1, p2]);
const y = await Promise.all([p1, p2]);
return Promise.all((() => {
return await Promise.all((() => {
const _arr = [];for (const p of ps) _arr.push(p);return _arr;
})());
}
2 changes: 1 addition & 1 deletion test/fixtures/await-arrow/safe-statement/expected.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
async function fn() {
return (async () => {
return await (async () => {
try {
return await fetch();
} catch (_err) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/await-arrow/statement/expected.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
async function fn() {
return fetch();
return await fetch();
}
2 changes: 1 addition & 1 deletion test/fixtures/named-arrow-functions/async/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async function fn() {
await 1;
return 2;
return await 2;
}
2 changes: 1 addition & 1 deletion test/fixtures/named-arrow-functions/fat-async/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fn = async () => {
await 1;
return 2;
return await 2;
};

0 comments on commit 2187800

Please sign in to comment.