From 37ad6a4aed56e9430c0e661b3e874810412119dd Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Mon, 24 Apr 2017 19:49:56 -0400 Subject: [PATCH 1/8] Add parsing test for =/*> --- .../fat-async-gen/actual.js | 2 + .../fat-async-gen/expected.json | 154 ++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 test/fixtures/lightscript/named-arrow-functions/fat-async-gen/actual.js create mode 100644 test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/actual.js b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/actual.js new file mode 100644 index 0000000000..2a28ce423b --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/actual.js @@ -0,0 +1,2 @@ +fn() =/*> + yield await x diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json new file mode 100644 index 0000000000..8d5f929f8a --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/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": 11, + "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": 17, + "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": [] + } +} From 28b1f100de9cfbf5f602865cb2ed326b8f99f004 Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Mon, 24 Apr 2017 19:51:21 -0400 Subject: [PATCH 2/8] Add parsing test for -/*> (skinny version) --- .../skinny-async-gen/actual.js | 2 + .../skinny-async-gen/expected.json | 154 ++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/actual.js create mode 100644 test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/actual.js b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/actual.js new file mode 100644 index 0000000000..1001478f62 --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/actual.js @@ -0,0 +1,2 @@ +fn() -/*> + yield await x diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json new file mode 100644 index 0000000000..05b1f38541 --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/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": 11, + "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": 17, + "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": [] + } +} From efa75145c02c6ca56c07f27622e263e5a98b2500 Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Mon, 24 Apr 2017 21:05:53 -0400 Subject: [PATCH 3/8] tokenize -/*> and =/*> --- src/tokenizer/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index ac3ea1b19b..99d672b5f7 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -413,6 +413,12 @@ export default class Tokenizer extends LocationParser { return this.finishToken(tt.arrow, "-*>"); } + const next3 = this.input.charCodeAt(this.state.pos + 3); + if (next === 47 && next2 === 42 && next3 === 62) { + this.state.pos += 4; + return this.finishToken(tt.arrow, "-/*>"); + } + let getOrSet; if (next === 103) getOrSet = "get"; if (next === 115) getOrSet = "set"; @@ -490,6 +496,12 @@ export default class Tokenizer extends LocationParser { this.state.pos += 3; return this.finishToken(tt.arrow, "=*>"); } + + const next3 = this.input.charCodeAt(this.state.pos + 3); + if (next === 47 && next2 === 42 && next3 === 62) { + this.state.pos += 4; + return this.finishToken(tt.arrow, "=/*>"); + } } if (code === 61 && next === 62) { // '=>' From b1415bd46f0af13ced2ae6975c83601492c6c7cf Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Mon, 24 Apr 2017 21:15:47 -0400 Subject: [PATCH 4/8] handle =/*> and -/*> in parsArrowType --- src/plugins/lightscript.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 40d008b81e..fbef39f5d7 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -260,6 +260,10 @@ export default (superClass: Class): Class => class extends super 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."); From 6dd4a0894e0487048c51389ed81ee78b06e95672 Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Mon, 24 Apr 2017 21:16:00 -0400 Subject: [PATCH 5/8] Fix the tests so they pass --- .../named-arrow-functions/fat-async-gen/expected.json | 4 ++-- .../named-arrow-functions/skinny-async-gen/expected.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json index 8d5f929f8a..9dd98eb150 100644 --- a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json @@ -81,7 +81,7 @@ "body": [ { "type": "ExpressionStatement", - "start": 11, + "start": 12, "end": 25, "loc": { "start": { @@ -109,7 +109,7 @@ }, "argument": { "type": "AwaitExpression", - "start": 17, + "start": 18, "end": 25, "loc": { "start": { diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json index 05b1f38541..9460cc5f4c 100644 --- a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json @@ -81,7 +81,7 @@ "body": [ { "type": "ExpressionStatement", - "start": 11, + "start": 12, "end": 25, "loc": { "start": { @@ -109,7 +109,7 @@ }, "argument": { "type": "AwaitExpression", - "start": 17, + "start": 18, "end": 25, "loc": { "start": { From 8bdb77152d200764e9f2fb2a2f12cb5583c0d7cb Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Mon, 24 Apr 2017 22:06:52 -0400 Subject: [PATCH 6/8] Wrap stuff inside `if hasPlugin('asyncGenerators')` --- src/tokenizer/index.js | 20 +++++++++++-------- .../fat-async-gen/options.json | 3 +++ .../skinny-async-gen/options.json | 3 +++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/lightscript/named-arrow-functions/fat-async-gen/options.json create mode 100644 test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/options.json diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 99d672b5f7..b793bf1fb7 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -413,10 +413,12 @@ export default class Tokenizer extends LocationParser { return this.finishToken(tt.arrow, "-*>"); } - const next3 = this.input.charCodeAt(this.state.pos + 3); - if (next === 47 && next2 === 42 && next3 === 62) { - this.state.pos += 4; - return this.finishToken(tt.arrow, "-/*>"); + if (this.hasPlugin("asyncGenerators")) { + const next3 = this.input.charCodeAt(this.state.pos + 3); + if (next === 47 && next2 === 42 && next3 === 62) { + this.state.pos += 4; + return this.finishToken(tt.arrow, "-/*>"); + } } let getOrSet; @@ -497,10 +499,12 @@ export default class Tokenizer extends LocationParser { return this.finishToken(tt.arrow, "=*>"); } - const next3 = this.input.charCodeAt(this.state.pos + 3); - if (next === 47 && next2 === 42 && next3 === 62) { - this.state.pos += 4; - return this.finishToken(tt.arrow, "=/*>"); + if (this.hasPlugin("asyncGenerators")) { + const next3 = this.input.charCodeAt(this.state.pos + 3); + if (next === 47 && next2 === 42 && next3 === 62) { + this.state.pos += 4; + return this.finishToken(tt.arrow, "=/*>"); + } } } diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/options.json b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/options.json new file mode 100644 index 0000000000..a2159d522d --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["lightscript", "jsx", "flow", "asyncGenerators"] +} diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/options.json b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/options.json new file mode 100644 index 0000000000..a2159d522d --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["lightscript", "jsx", "flow", "asyncGenerators"] +} From 05e34afee8b941595fa543caa87133af7f418e6b Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Mon, 24 Apr 2017 22:13:19 -0400 Subject: [PATCH 7/8] Rename tests to use `generators` instead of `gen` --- .../{fat-async-gen => fat-async-generators}/actual.js | 0 .../{fat-async-gen => fat-async-generators}/expected.json | 0 .../{fat-async-gen => fat-async-generators}/options.json | 0 .../{skinny-async-gen => skinny-async-generators}/actual.js | 0 .../{skinny-async-gen => skinny-async-generators}/expected.json | 0 .../{skinny-async-gen => skinny-async-generators}/options.json | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename test/fixtures/lightscript/named-arrow-functions/{fat-async-gen => fat-async-generators}/actual.js (100%) rename test/fixtures/lightscript/named-arrow-functions/{fat-async-gen => fat-async-generators}/expected.json (100%) rename test/fixtures/lightscript/named-arrow-functions/{fat-async-gen => fat-async-generators}/options.json (100%) rename test/fixtures/lightscript/named-arrow-functions/{skinny-async-gen => skinny-async-generators}/actual.js (100%) rename test/fixtures/lightscript/named-arrow-functions/{skinny-async-gen => skinny-async-generators}/expected.json (100%) rename test/fixtures/lightscript/named-arrow-functions/{skinny-async-gen => skinny-async-generators}/options.json (100%) diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/actual.js b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/actual.js similarity index 100% rename from test/fixtures/lightscript/named-arrow-functions/fat-async-gen/actual.js rename to test/fixtures/lightscript/named-arrow-functions/fat-async-generators/actual.js diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/expected.json similarity index 100% rename from test/fixtures/lightscript/named-arrow-functions/fat-async-gen/expected.json rename to test/fixtures/lightscript/named-arrow-functions/fat-async-generators/expected.json diff --git a/test/fixtures/lightscript/named-arrow-functions/fat-async-gen/options.json b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/options.json similarity index 100% rename from test/fixtures/lightscript/named-arrow-functions/fat-async-gen/options.json rename to test/fixtures/lightscript/named-arrow-functions/fat-async-generators/options.json diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/actual.js b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/actual.js similarity index 100% rename from test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/actual.js rename to test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/actual.js diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/expected.json similarity index 100% rename from test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/expected.json rename to test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/expected.json diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/options.json b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/options.json similarity index 100% rename from test/fixtures/lightscript/named-arrow-functions/skinny-async-gen/options.json rename to test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/options.json From 9dce21adf944dc41c626667d7db9f4cd3f9763bf Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Wed, 3 May 2017 23:47:40 -0400 Subject: [PATCH 8/8] switch -/*> with -*/> --- src/plugins/lightscript.js | 2 +- src/tokenizer/index.js | 8 ++++---- .../named-arrow-functions/fat-async-generators/actual.js | 2 +- .../skinny-async-generators/actual.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index fbef39f5d7..8b8bfe266c 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -260,7 +260,7 @@ export default (superClass: Class): Class => class extends super case "=*>": case "-*>": node.generator = true; break; - case "=/*>": case "-/*>": + case "=*/>": case "-*/>": node.async = true; node.generator = true; break; diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index b793bf1fb7..b2ec537672 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -415,9 +415,9 @@ export default class Tokenizer extends LocationParser { if (this.hasPlugin("asyncGenerators")) { const next3 = this.input.charCodeAt(this.state.pos + 3); - if (next === 47 && next2 === 42 && next3 === 62) { + if (next === 42 && next2 === 47 && next3 === 62) { this.state.pos += 4; - return this.finishToken(tt.arrow, "-/*>"); + return this.finishToken(tt.arrow, "-*/>"); } } @@ -501,9 +501,9 @@ export default class Tokenizer extends LocationParser { if (this.hasPlugin("asyncGenerators")) { const next3 = this.input.charCodeAt(this.state.pos + 3); - if (next === 47 && next2 === 42 && next3 === 62) { + if (next === 42 && next2 === 47 && next3 === 62) { this.state.pos += 4; - return this.finishToken(tt.arrow, "=/*>"); + return this.finishToken(tt.arrow, "=*/>"); } } } 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 index 2a28ce423b..354ed0a5dc 100644 --- a/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/actual.js +++ b/test/fixtures/lightscript/named-arrow-functions/fat-async-generators/actual.js @@ -1,2 +1,2 @@ -fn() =/*> +fn() =*/> yield await x 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 index 1001478f62..b5fdc7d568 100644 --- a/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/actual.js +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-async-generators/actual.js @@ -1,2 +1,2 @@ -fn() -/*> +fn() -*/> yield await x