diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index d574d79edb..fd8d18656c 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -265,6 +265,10 @@ pp.parseArrowType = function (node) { case "=*>": case "-*>": node.generator = true; break; + case "=*/>": case "-*/>": + node.async = true; + node.generator = true; + break; case "-get>": // TODO: validate that it's in a method not a function if (!node.kind) this.unexpected(null, "Only methods can be getters."); diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index c0927925f5..adcb63e204 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -401,6 +401,14 @@ export default class Tokenizer { return this.finishToken(tt.arrow, "-*>"); } + if (this.hasPlugin("asyncGenerators")) { + const next3 = this.input.charCodeAt(this.state.pos + 3); + if (next === 42 && next2 === 47 && next3 === 62) { + this.state.pos += 4; + return this.finishToken(tt.arrow, "-*/>"); + } + } + let getOrSet; if (next === 103) getOrSet = "get"; if (next === 115) getOrSet = "set"; @@ -478,6 +486,14 @@ export default class Tokenizer { this.state.pos += 3; return this.finishToken(tt.arrow, "=*>"); } + + if (this.hasPlugin("asyncGenerators")) { + const next3 = this.input.charCodeAt(this.state.pos + 3); + if (next === 42 && next2 === 47 && next3 === 62) { + this.state.pos += 4; + return this.finishToken(tt.arrow, "=*/>"); + } + } } if (code === 61 && next === 62) { // '=>' diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/actual.js b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/actual.js new file mode 100644 index 0000000000..354ed0a5dc --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/actual.js @@ -0,0 +1,2 @@ +fn() =*/> + yield await x diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/expected.json b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/expected.json new file mode 100644 index 0000000000..9dd98eb150 --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/expected.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": true, + "expression": false, + "async": true, + "params": [], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 5, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 12, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "expression": { + "type": "YieldExpression", + "start": 12, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "argument": { + "type": "AwaitExpression", + "start": 18, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "argument": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/options.json b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/options.json new file mode 100644 index 0000000000..a2159d522d --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["lightscript", "jsx", "flow", "asyncGenerators"] +} diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/actual.js b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/actual.js new file mode 100644 index 0000000000..b5fdc7d568 --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/actual.js @@ -0,0 +1,2 @@ +fn() -*/> + yield await x diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/expected.json b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/expected.json new file mode 100644 index 0000000000..9460cc5f4c --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/expected.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": true, + "expression": false, + "async": true, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 5, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 12, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "expression": { + "type": "YieldExpression", + "start": 12, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "argument": { + "type": "AwaitExpression", + "start": 18, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "argument": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + } + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ], + "directives": [] + } +} diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/options.json b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/options.json new file mode 100644 index 0000000000..a2159d522d --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["lightscript", "jsx", "flow", "asyncGenerators"] +}