Skip to content

Commit f6df59f

Browse files
papandreoumichaelficarra
authored andcommitted
Change the precedence of await so it's the same as other unary expressions
Fixes estools#384 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
1 parent 52df4da commit f6df59f

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

escodegen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
Precedence = {
8383
Sequence: 0,
8484
Yield: 1,
85-
Await: 1,
8685
Assignment: 1,
8786
Conditional: 2,
8887
ArrowFunction: 2,
@@ -96,6 +95,7 @@
9695
BitwiseSHIFT: 10,
9796
Additive: 11,
9897
Multiplicative: 12,
98+
Await: 13,
9999
Unary: 13,
100100
Postfix: 14,
101101
Call: 15,

test/harmony.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5927,6 +5927,46 @@ data = {
59275927
}
59285928
},
59295929

5930+
'async function test() {\n await (foo ? bar : quux);\n}': {
5931+
generateFrom: {
5932+
"type": "FunctionDeclaration",
5933+
"id": {
5934+
"type": "Identifier",
5935+
"name": "test"
5936+
},
5937+
"params": [],
5938+
"body": {
5939+
"type": "BlockStatement",
5940+
"body": [
5941+
{
5942+
"type": "ExpressionStatement",
5943+
"expression": {
5944+
"type": "AwaitExpression",
5945+
"argument": {
5946+
"type": "ConditionalExpression",
5947+
"test": {
5948+
"type": "Identifier",
5949+
"name": "foo"
5950+
},
5951+
"consequent": {
5952+
"type": "Identifier",
5953+
"name": "bar"
5954+
},
5955+
"alternate": {
5956+
"type": "Identifier",
5957+
"name": "quux"
5958+
}
5959+
}
5960+
}
5961+
}
5962+
]
5963+
},
5964+
"generator": false,
5965+
"expression": false,
5966+
"async": true
5967+
}
5968+
},
5969+
59305970
'f(async function (promise) {\n await promise;\n});': {
59315971
generateFrom: {
59325972
"type": "ExpressionStatement",

0 commit comments

Comments
 (0)