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

Fix parsing of awaited tagged template expressions #376

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ func (p *parser) parsePrefix(level ast.L, errors *deferredErrors, flags exprFlag
if p.fnOptsParse.arrowArgErrors != nil {
p.fnOptsParse.arrowArgErrors.invalidExprAwait = nameRange
}
return ast.Expr{Loc: loc, Data: &ast.EAwait{Value: p.parseExpr(ast.LPrefix)}}
return ast.Expr{Loc: loc, Data: &ast.EAwait{Value: p.parseExpr(ast.LLowest)}}
}
}

Expand Down
9 changes: 9 additions & 0 deletions internal/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,15 @@ func TestAsync(t *testing.T) {
expectParseError(t, "async (...x,) => {}", "<stdin>: error: Unexpected \",\" after rest pattern\n")
expectParseError(t, "async => await 0", "<stdin>: error: Expected \";\" but found \"0\"\n")

expectPrinted(t, "async () => { await foo`bar` }", "async () => {\n await foo`bar`;\n};\n")
expectPrinted(t, "async () => { await foo`bar${baz}` }", "async () => {\n await foo`bar${baz}`;\n};\n")
expectPrinted(t, "async () => { (await foo)`bar` }", "async () => {\n (await foo)`bar`;\n};\n")
expectPrinted(t, "async () => { (await foo)`bar${baz}` }", "async () => {\n (await foo)`bar${baz}`;\n};\n")
expectPrinted(t, "async () => { await a, b }", "async () => {\n await a, b;\n};\n")
expectPrinted(t, "async () => { (await a), b }", "async () => {\n await a, b;\n};\n")
expectPrinted(t, "async () => { await foo.bar }", "async () => {\n await foo.bar;\n};\n")
expectPrinted(t, "async () => { (await foo).bar }", "async () => {\n (await foo).bar;\n};\n")

expectPrinted(t, "(async x => y), z", "async (x) => y, z;\n")
expectPrinted(t, "(async x => y, z)", "async (x) => y, z;\n")
expectPrinted(t, "(async x => (y, z))", "async (x) => (y, z);\n")
Expand Down
2 changes: 1 addition & 1 deletion internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,7 @@ func (p *printer) printExpr(expr ast.Expr, level ast.L, flags int) {
p.printSpaceBeforeIdentifier()
p.print("await")
p.printSpace()
p.printExpr(e.Value, ast.LPrefix, 0)
p.printExpr(e.Value, ast.LLowest, 0)

if wrap {
p.print(")")
Expand Down