Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues with multiple await return. #90

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/NUglify.Tests/JavaScript/ES2017.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ public void AsyncArrowFunction()
{
TestHelper.Instance.RunTest();
}

[Test]
public void MultipleAwaitExpression()
{
TestHelper.Instance.RunTest();
}
}
}
6 changes: 6 additions & 0 deletions src/NUglify.Tests/NUglify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@
<Content Include="TestData\JS\Expected\ES2017\AsyncFunctionExpressions.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\ES2017\MultipleAwaitExpression.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Expected\ES2017\TrailingComma.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -3014,6 +3017,9 @@
<Content Include="TestData\JS\Input\ES2017\AsyncArrowFunction.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Input\ES2017\MultipleAwaitExpression.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\JS\Input\ES2017\AsyncClassFunction.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
async function getNumberAfterTimeout(value) {
return new Promise((resolve) => {
window.setTimeout(() => resolve(value), 2000);
});
}

async function sum(x) {
var a = getNumberAfterTimeout(20);
var b = getNumberAfterTimeout(30);
return x + await a + await b;
}

(async () => { return x + await a(t) + await b; })()

// keep grouping
(async () => { return x + (await a(t) + await b); })()
29 changes: 10 additions & 19 deletions src/NUglify/JavaScript/JSParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4344,30 +4344,21 @@ private AstNode ParseAwaitExpression()
{
ParsedVersion = ScriptVersion.EcmaScript6;

// save the context of the yield operator, then skip past it
// save the context of the await operator, then skip past it
var context = m_currentToken.Clone();
var operatorContext = context.Clone();
GetNextToken();

// must be followed by an expression
var expression = ParseExpression(true);
if (expression == null)
{
// we only call this method if we KNOW we are ES6, so if there is no expression,
// then throw an error.
ReportError(JSError.ExpressionExpected);
}
else
{
context.UpdateWith(expression.Context);
}
bool bAssign;
AstNode expression = ParseUnaryExpression(out bAssign, false);
expression = new UnaryExpression(expression.Context.CombineWith(operatorContext))
{
OperatorContext = operatorContext,
OperatorToken = JSToken.Await,
Operand = expression
};

return new UnaryExpression(context)
{
OperatorContext = operatorContext,
OperatorToken = JSToken.Await,
Operand = expression
};
return expression;
}

private FunctionObject ParseArrowFunction(AstNode parameters)
Expand Down