contextual async/await keywords - closes 6to5/6to5#157

This commit is contained in:
Sebastian McKenzie
2014-12-13 00:37:40 +11:00
parent 6623756312
commit 71bb9d6123
3 changed files with 601 additions and 111 deletions

View File

@@ -115,7 +115,6 @@ test("class Foo { memo bar() {} }", {
defaults: [],
rest: null,
generator: false,
async: false,
body: {
type: "BlockStatement",
start: 23,
@@ -178,7 +177,6 @@ test("var foo = { memo bar() {} };",
defaults: [],
rest: null,
generator: false,
async: false,
body: {
type: "BlockStatement",
start: 23,
@@ -199,6 +197,54 @@ test("var foo = { memo bar() {} };",
// Memoization assignment operator
testFail("obj ?= 2;", "You can only use member expressions in memoization assignment (1:0)");
test("obj.x ?= 2;", {
type: "Program",
start: 0,
end: 11,
body: [{
type: "ExpressionStatement",
start: 0,
end: 11,
expression: {
type: "AssignmentExpression",
start: 0,
end: 10,
left: {
type: "MemberExpression",
start: 0,
end: 5,
object: {
type: "Identifier",
start: 0,
end: 3,
name: "obj"
},
property: {
type: "Identifier",
start: 4,
end: 5,
name: "x"
},
computed: false
},
right: {
type: "Literal",
start: 9,
end: 10,
value: 2,
raw: "2"
},
operator: "?="
}
}]
}, {
playground: true
});
// Method binding
//- Make sure conditionals still work
test("y ? 1 : 2", {
@@ -287,54 +333,6 @@ test("y ? 1 : 2", {
playground: true
});
testFail("obj ?= 2;", "You can only use member expressions in memoization assignment (1:0)");
test("obj.x ?= 2;", {
type: "Program",
start: 0,
end: 11,
body: [{
type: "ExpressionStatement",
start: 0,
end: 11,
expression: {
type: "AssignmentExpression",
start: 0,
end: 10,
left: {
type: "MemberExpression",
start: 0,
end: 5,
object: {
type: "Identifier",
start: 0,
end: 3,
name: "obj"
},
property: {
type: "Identifier",
start: 4,
end: 5,
name: "x"
},
computed: false
},
right: {
type: "Literal",
start: 9,
end: 10,
value: 2,
raw: "2"
},
operator: "?="
}
}]
}, {
playground: true
});
// Method binding
test("var fn = obj:method", {
type: "Program",
start: 0,

View File

@@ -1247,6 +1247,492 @@ test('f(async function(promise) { await promise })', {
locations: true
});
test('f(a, async(1, 2), b)', {
type: "Program",
body: [{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "f",
"range": [
0,
1
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
}
},
"arguments": [
{
"type": "Identifier",
"name": "a",
"range": [
2,
3
],
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
}
}
},
{
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "async",
"range": [
5,
10
],
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 10
}
}
},
"arguments": [
{
"type": "Literal",
"value": 1,
"raw": "1",
"range": [
11,
12
],
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
}
},
{
"type": "Literal",
"value": 2,
"raw": "2",
"range": [
14,
15
],
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
}
}
}
],
"range": [
5,
16
],
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 16
}
}
},
{
"type": "Identifier",
"name": "b",
"range": [
18,
19
],
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 19
}
}
}
],
"range": [
0,
20
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
}
},
"range": [
0,
20
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
}
}]
}, {
ecmaVersion: 7,
locations: true,
ranges: true
});
test('var ok = async(x)', {
type: "Program",
body: [{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "ok",
"range": [
4,
6
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 6
}
}
},
"init": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "async",
"range": [
9,
14
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 14
}
}
},
"arguments": [
{
"type": "Identifier",
"name": "x",
"range": [
15,
16
],
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
}
}
}
],
"range": [
9,
17
],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 17
}
}
},
"range": [
4,
17
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 17
}
}
}
],
"kind": "var",
"range": [
0,
17
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
}
}]
}, {
ecmaVersion: 7,
locations: true,
ranges: true
});
test('(function() { var async; async = 10 })', {
type: "Program",
body: [{
"type": "ExpressionStatement",
"expression": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "async",
"range": [
18,
23
],
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 23
}
}
},
"init": null,
"range": [
18,
23
],
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 23
}
}
}
],
"kind": "var",
"range": [
14,
24
],
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 24
}
}
},
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"operator": "=",
"left": {
"type": "Identifier",
"name": "async",
"range": [
25,
30
],
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 30
}
}
},
"right": {
"type": "Literal",
"value": 10,
"raw": "10",
"range": [
33,
35
],
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 35
}
}
},
"range": [
25,
35
],
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 35
}
}
},
"range": [
25,
35
],
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 35
}
}
}
],
"range": [
12,
37
],
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 37
}
}
},
"rest": null,
"generator": false,
"expression": false,
"range": [
1,
37
],
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 37
}
}
},
"range": [
0,
38
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 38
}
}
}]
}, {
ecmaVersion: 7,
locations: true,
ranges: true
});
// ES7: Abstract references
test('foo::bar;', {