From 747d80e2fd5db4f86d1b80adccdcb7dc42cc2adf Mon Sep 17 00:00:00 2001 From: Bo Lingen Date: Fri, 14 Jul 2017 20:45:37 +0000 Subject: [PATCH 1/3] remove get & set arrows --- src/plugins/lightscript.js | 11 ----------- src/tokenizer/index.js | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 521183172f..91b46c7ea6 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -253,8 +253,6 @@ pp.parseArrowType = function (node) { const isPlainFatArrow = val === "=>" && !node.id && !node.key; if (node.async && !isPlainFatArrow) this.unexpected(node.start, "Can't use async with lightscript arrows."); if (node.generator) this.unexpected(node.start, "Can't declare generators with arrows; try -*> instead."); - if (node.kind === "get") this.unexpected(node.start, "Can't use arrow method with get; try -get> instead."); - if (node.kind === "set") this.unexpected(node.start, "Can't use arrow method with set; try -set> instead."); if (node.kind === "constructor" && val !== "->") this.unexpected(null, "Can only use -> with constructor."); switch (val) { @@ -268,15 +266,6 @@ pp.parseArrowType = function (node) { 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."); - node.kind = "get"; - break; - case "-set>": - if (!node.kind) this.unexpected(null, "Only methods can be setters."); - node.kind = "set"; - break; case "=>": case "->": break; default: diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 6c5d4765ec..deb763a025 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -408,17 +408,6 @@ export default class Tokenizer { return this.finishToken(tt.arrow, "-*/>"); } } - - let getOrSet; - if (next === 103) getOrSet = "get"; - if (next === 115) getOrSet = "set"; - if (getOrSet && next2 === 101 && - this.input.charCodeAt(this.state.pos + 3) === 116 && - this.input.charCodeAt(this.state.pos + 4) === 62 - ) { - this.state.pos += 5; - return this.finishToken(tt.arrow, `-${getOrSet}>`); - } } if (next === 61) { From 7042ece3ce0edc6dd040afb21eceb34b24e821fa Mon Sep 17 00:00:00 2001 From: Bo Lingen Date: Fri, 14 Jul 2017 20:46:10 +0000 Subject: [PATCH 2/3] update tests for getters & setters --- .../class-get-malformed-one-param/actual.js | 2 +- .../class-get-malformed-two-params/actual.js | 2 +- .../arrow-methods/class-get/actual.js | 2 +- .../arrow-methods/class-get/expected.json | 40 ++++++------ .../class-malformed-async-get/actual.js | 3 - .../actual.js | 3 + .../options.json | 0 .../class-malformed-get-arrow/actual.js | 3 - .../class-malformed-get-arrow/options.json | 3 - .../class-malformed-get-fat/actual.js | 3 - .../class-malformed-get-fat/options.json | 3 - .../class-set-malformed-no-params/actual.js | 2 +- .../class-set-malformed-two-params/actual.js | 2 +- .../arrow-methods/class-set/actual.js | 2 +- .../arrow-methods/class-set/expected.json | 59 ++++++++--------- .../arrow-methods/obj-get/actual.js | 2 +- .../arrow-methods/obj-get/expected.json | 49 +++++++------- .../arrow-methods/obj-set/actual.js | 2 +- .../arrow-methods/obj-set/expected.json | 65 ++++++++++--------- .../malformed-get/actual.js | 1 - .../malformed-get/options.json | 3 - .../malformed-set/actual.js | 1 - .../malformed-set/options.json | 3 - 23 files changed, 123 insertions(+), 132 deletions(-) delete mode 100644 test/fixtures/lightscript/arrow-methods/class-malformed-async-get/actual.js create mode 100644 test/fixtures/lightscript/arrow-methods/class-malformed-async-skinny-arrow/actual.js rename test/fixtures/lightscript/arrow-methods/{class-malformed-async-get => class-malformed-async-skinny-arrow}/options.json (100%) delete mode 100644 test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/actual.js delete mode 100644 test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/options.json delete mode 100644 test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/actual.js delete mode 100644 test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/options.json delete mode 100644 test/fixtures/lightscript/named-arrow-functions/malformed-get/actual.js delete mode 100644 test/fixtures/lightscript/named-arrow-functions/malformed-get/options.json delete mode 100644 test/fixtures/lightscript/named-arrow-functions/malformed-set/actual.js delete mode 100644 test/fixtures/lightscript/named-arrow-functions/malformed-set/options.json diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-one-param/actual.js b/test/fixtures/lightscript/arrow-methods/class-get-malformed-one-param/actual.js index 7cbd4b77bd..be64acf3c3 100644 --- a/test/fixtures/lightscript/arrow-methods/class-get-malformed-one-param/actual.js +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-one-param/actual.js @@ -1,4 +1,4 @@ class X { - method(x) -get> + get method(x) -> x } diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-two-params/actual.js b/test/fixtures/lightscript/arrow-methods/class-get-malformed-two-params/actual.js index 00aa0d4e98..a4dbb67332 100644 --- a/test/fixtures/lightscript/arrow-methods/class-get-malformed-two-params/actual.js +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-two-params/actual.js @@ -1,4 +1,4 @@ class X { - method(x, y) -get> + get method(x, y) -> x + y } diff --git a/test/fixtures/lightscript/arrow-methods/class-get/actual.js b/test/fixtures/lightscript/arrow-methods/class-get/actual.js index 894a14cf08..ca7e1acd66 100644 --- a/test/fixtures/lightscript/arrow-methods/class-get/actual.js +++ b/test/fixtures/lightscript/arrow-methods/class-get/actual.js @@ -1,5 +1,5 @@ class X { - method() -get> + get method() -> a b } diff --git a/test/fixtures/lightscript/arrow-methods/class-get/expected.json b/test/fixtures/lightscript/arrow-methods/class-get/expected.json index 61122147c9..1e822c8d52 100644 --- a/test/fixtures/lightscript/arrow-methods/class-get/expected.json +++ b/test/fixtures/lightscript/arrow-methods/class-get/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "ClassDeclaration", "start": 0, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ "body": { "type": "ClassBody", "start": 8, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -78,7 +78,7 @@ { "type": "ClassMethod", "start": 12, - "end": 38, + "end": 39, "loc": { "start": { "line": 2, @@ -92,16 +92,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 12, - "end": 18, + "start": 16, + "end": 22, "loc": { "start": { "line": 2, - "column": 2 + "column": 6 }, "end": { "line": 2, - "column": 8 + "column": 12 }, "identifierName": "method" }, @@ -117,12 +117,12 @@ "skinny": true, "body": { "type": "BlockStatement", - "start": 21, - "end": 38, + "start": 25, + "end": 39, "loc": { "start": { "line": 2, - "column": 11 + "column": 15 }, "end": { "line": 4, @@ -132,8 +132,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 31, - "end": 32, + "start": 32, + "end": 33, "loc": { "start": { "line": 3, @@ -146,8 +146,8 @@ }, "expression": { "type": "Identifier", - "start": 31, - "end": 32, + "start": 32, + "end": 33, "loc": { "start": { "line": 3, @@ -164,8 +164,8 @@ }, { "type": "ExpressionStatement", - "start": 37, - "end": 38, + "start": 38, + "end": 39, "loc": { "start": { "line": 4, @@ -178,8 +178,8 @@ }, "expression": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 38, + "end": 39, "loc": { "start": { "line": 4, diff --git a/test/fixtures/lightscript/arrow-methods/class-malformed-async-get/actual.js b/test/fixtures/lightscript/arrow-methods/class-malformed-async-get/actual.js deleted file mode 100644 index a944c709d8..0000000000 --- a/test/fixtures/lightscript/arrow-methods/class-malformed-async-get/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class X { - async method() -get> await a -} diff --git a/test/fixtures/lightscript/arrow-methods/class-malformed-async-skinny-arrow/actual.js b/test/fixtures/lightscript/arrow-methods/class-malformed-async-skinny-arrow/actual.js new file mode 100644 index 0000000000..9b51886768 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-malformed-async-skinny-arrow/actual.js @@ -0,0 +1,3 @@ +class X { + async method() -> await a +} diff --git a/test/fixtures/lightscript/arrow-methods/class-malformed-async-get/options.json b/test/fixtures/lightscript/arrow-methods/class-malformed-async-skinny-arrow/options.json similarity index 100% rename from test/fixtures/lightscript/arrow-methods/class-malformed-async-get/options.json rename to test/fixtures/lightscript/arrow-methods/class-malformed-async-skinny-arrow/options.json diff --git a/test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/actual.js b/test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/actual.js deleted file mode 100644 index 4ded5708da..0000000000 --- a/test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class X { - get method() -> 1 -} diff --git a/test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/options.json b/test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/options.json deleted file mode 100644 index c2d9a02e57..0000000000 --- a/test/fixtures/lightscript/arrow-methods/class-malformed-get-arrow/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Can't use arrow method with get; try -get> instead. (2:2)" -} diff --git a/test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/actual.js b/test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/actual.js deleted file mode 100644 index e2a71b8fc8..0000000000 --- a/test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class X { - method() =get> 1 -} diff --git a/test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/options.json b/test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/options.json deleted file mode 100644 index 87331c2450..0000000000 --- a/test/fixtures/lightscript/arrow-methods/class-malformed-get-fat/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token, expected { (2:11)" -} diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-no-params/actual.js b/test/fixtures/lightscript/arrow-methods/class-set-malformed-no-params/actual.js index f73ac4cc82..2694b2260d 100644 --- a/test/fixtures/lightscript/arrow-methods/class-set-malformed-no-params/actual.js +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-no-params/actual.js @@ -1,4 +1,4 @@ class X { - method() -set> + set method() -> this.x = x } diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-two-params/actual.js b/test/fixtures/lightscript/arrow-methods/class-set-malformed-two-params/actual.js index 4cb3f528ff..f146df8af7 100644 --- a/test/fixtures/lightscript/arrow-methods/class-set-malformed-two-params/actual.js +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-two-params/actual.js @@ -1,4 +1,4 @@ class X { - method(x, y) -set> + set method(x, y) -> this.x = x } diff --git a/test/fixtures/lightscript/arrow-methods/class-set/actual.js b/test/fixtures/lightscript/arrow-methods/class-set/actual.js index 65ad59da21..af633e1bc0 100644 --- a/test/fixtures/lightscript/arrow-methods/class-set/actual.js +++ b/test/fixtures/lightscript/arrow-methods/class-set/actual.js @@ -1,4 +1,4 @@ class X { - method(x) -set> + set method(x) -> this.x = x } diff --git a/test/fixtures/lightscript/arrow-methods/class-set/expected.json b/test/fixtures/lightscript/arrow-methods/class-set/expected.json index 5624a70e6d..37ee7c2a63 100644 --- a/test/fixtures/lightscript/arrow-methods/class-set/expected.json +++ b/test/fixtures/lightscript/arrow-methods/class-set/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 44, + "end": 45, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 44, + "end": 45, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "ClassDeclaration", "start": 0, - "end": 44, + "end": 45, "loc": { "start": { "line": 1, @@ -63,7 +63,7 @@ "body": { "type": "ClassBody", "start": 8, - "end": 44, + "end": 45, "loc": { "start": { "line": 1, @@ -78,7 +78,7 @@ { "type": "ClassMethod", "start": 12, - "end": 42, + "end": 43, "loc": { "start": { "line": 2, @@ -92,16 +92,16 @@ "computed": false, "key": { "type": "Identifier", - "start": 12, - "end": 18, + "start": 16, + "end": 22, "loc": { "start": { "line": 2, - "column": 2 + "column": 6 }, "end": { "line": 2, - "column": 8 + "column": 12 }, "identifierName": "method" }, @@ -116,16 +116,16 @@ "params": [ { "type": "Identifier", - "start": 19, - "end": 20, + "start": 23, + "end": 24, "loc": { "start": { "line": 2, - "column": 9 + "column": 13 }, "end": { "line": 2, - "column": 10 + "column": 14 }, "identifierName": "x" }, @@ -135,12 +135,12 @@ "skinny": true, "body": { "type": "BlockStatement", - "start": 22, - "end": 42, + "start": 26, + "end": 43, "loc": { "start": { "line": 2, - "column": 12 + "column": 16 }, "end": { "line": 3, @@ -150,8 +150,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 32, - "end": 42, + "start": 33, + "end": 43, "loc": { "start": { "line": 3, @@ -164,8 +164,8 @@ }, "expression": { "type": "AssignmentExpression", - "start": 32, - "end": 42, + "start": 33, + "end": 43, "loc": { "start": { "line": 3, @@ -179,8 +179,8 @@ "operator": "=", "left": { "type": "MemberExpression", - "start": 32, - "end": 38, + "start": 33, + "end": 39, "loc": { "start": { "line": 3, @@ -193,8 +193,8 @@ }, "object": { "type": "ThisExpression", - "start": 32, - "end": 36, + "start": 33, + "end": 37, "loc": { "start": { "line": 3, @@ -208,8 +208,8 @@ }, "property": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 38, + "end": 39, "loc": { "start": { "line": 3, @@ -227,8 +227,8 @@ }, "right": { "type": "Identifier", - "start": 41, - "end": 42, + "start": 42, + "end": 43, "loc": { "start": { "line": 3, @@ -241,7 +241,8 @@ "identifierName": "x" }, "name": "x" - } + }, + "isNowAssign": false } } ], diff --git a/test/fixtures/lightscript/arrow-methods/obj-get/actual.js b/test/fixtures/lightscript/arrow-methods/obj-get/actual.js index eb052f0431..cd083e1b5e 100644 --- a/test/fixtures/lightscript/arrow-methods/obj-get/actual.js +++ b/test/fixtures/lightscript/arrow-methods/obj-get/actual.js @@ -1,5 +1,5 @@ x = { - method() -get> + get method() -> a b } diff --git a/test/fixtures/lightscript/arrow-methods/obj-get/expected.json b/test/fixtures/lightscript/arrow-methods/obj-get/expected.json index db8ba986db..63862cf2fc 100644 --- a/test/fixtures/lightscript/arrow-methods/obj-get/expected.json +++ b/test/fixtures/lightscript/arrow-methods/obj-get/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 36, + "end": 37, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 36, + "end": 37, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 36, + "end": 37, "loc": { "start": { "line": 1, @@ -43,11 +43,14 @@ } }, "kind": "const", + "extra": { + "implicit": true + }, "declarations": [ { "type": "VariableDeclarator", "start": 0, - "end": 36, + "end": 37, "loc": { "start": { "line": 1, @@ -78,7 +81,7 @@ "init": { "type": "ObjectExpression", "start": 4, - "end": 36, + "end": 37, "loc": { "start": { "line": 1, @@ -93,7 +96,7 @@ { "type": "ObjectMethod", "start": 8, - "end": 34, + "end": 35, "loc": { "start": { "line": 2, @@ -104,27 +107,29 @@ "column": 5 } }, - "method": true, + "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 8, - "end": 14, + "start": 12, + "end": 18, "loc": { "start": { "line": 2, - "column": 2 + "column": 6 }, "end": { "line": 2, - "column": 8 + "column": 12 }, "identifierName": "method" }, "name": "method" }, "kind": "get", + "variance": null, + "variancePos": 12, "id": null, "generator": false, "expression": false, @@ -133,12 +138,12 @@ "skinny": true, "body": { "type": "BlockStatement", - "start": 17, - "end": 34, + "start": 21, + "end": 35, "loc": { "start": { "line": 2, - "column": 11 + "column": 15 }, "end": { "line": 4, @@ -148,8 +153,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 27, - "end": 28, + "start": 28, + "end": 29, "loc": { "start": { "line": 3, @@ -162,8 +167,8 @@ }, "expression": { "type": "Identifier", - "start": 27, - "end": 28, + "start": 28, + "end": 29, "loc": { "start": { "line": 3, @@ -180,8 +185,8 @@ }, { "type": "ExpressionStatement", - "start": 33, - "end": 34, + "start": 34, + "end": 35, "loc": { "start": { "line": 4, @@ -194,8 +199,8 @@ }, "expression": { "type": "Identifier", - "start": 33, - "end": 34, + "start": 34, + "end": 35, "loc": { "start": { "line": 4, diff --git a/test/fixtures/lightscript/arrow-methods/obj-set/actual.js b/test/fixtures/lightscript/arrow-methods/obj-set/actual.js index 83963a0df9..76806af83a 100644 --- a/test/fixtures/lightscript/arrow-methods/obj-set/actual.js +++ b/test/fixtures/lightscript/arrow-methods/obj-set/actual.js @@ -1,4 +1,4 @@ x = { - method(y) -set> + set method(y) -> this.y = y } diff --git a/test/fixtures/lightscript/arrow-methods/obj-set/expected.json b/test/fixtures/lightscript/arrow-methods/obj-set/expected.json index 55c568996d..3e70ac7227 100644 --- a/test/fixtures/lightscript/arrow-methods/obj-set/expected.json +++ b/test/fixtures/lightscript/arrow-methods/obj-set/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "VariableDeclaration", "start": 0, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -43,11 +43,14 @@ } }, "kind": "const", + "extra": { + "implicit": true + }, "declarations": [ { "type": "VariableDeclarator", "start": 0, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -78,7 +81,7 @@ "init": { "type": "ObjectExpression", "start": 4, - "end": 40, + "end": 41, "loc": { "start": { "line": 1, @@ -93,7 +96,7 @@ { "type": "ObjectMethod", "start": 8, - "end": 38, + "end": 39, "loc": { "start": { "line": 2, @@ -104,27 +107,29 @@ "column": 14 } }, - "method": true, + "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 8, - "end": 14, + "start": 12, + "end": 18, "loc": { "start": { "line": 2, - "column": 2 + "column": 6 }, "end": { "line": 2, - "column": 8 + "column": 12 }, "identifierName": "method" }, "name": "method" }, "kind": "set", + "variance": null, + "variancePos": 12, "id": null, "generator": false, "expression": false, @@ -132,16 +137,16 @@ "params": [ { "type": "Identifier", - "start": 15, - "end": 16, + "start": 19, + "end": 20, "loc": { "start": { "line": 2, - "column": 9 + "column": 13 }, "end": { "line": 2, - "column": 10 + "column": 14 }, "identifierName": "y" }, @@ -151,12 +156,12 @@ "skinny": true, "body": { "type": "BlockStatement", - "start": 18, - "end": 38, + "start": 22, + "end": 39, "loc": { "start": { "line": 2, - "column": 12 + "column": 16 }, "end": { "line": 3, @@ -166,8 +171,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 28, - "end": 38, + "start": 29, + "end": 39, "loc": { "start": { "line": 3, @@ -180,8 +185,8 @@ }, "expression": { "type": "AssignmentExpression", - "start": 28, - "end": 38, + "start": 29, + "end": 39, "loc": { "start": { "line": 3, @@ -195,8 +200,8 @@ "operator": "=", "left": { "type": "MemberExpression", - "start": 28, - "end": 34, + "start": 29, + "end": 35, "loc": { "start": { "line": 3, @@ -209,8 +214,8 @@ }, "object": { "type": "ThisExpression", - "start": 28, - "end": 32, + "start": 29, + "end": 33, "loc": { "start": { "line": 3, @@ -224,8 +229,8 @@ }, "property": { "type": "Identifier", - "start": 33, - "end": 34, + "start": 34, + "end": 35, "loc": { "start": { "line": 3, @@ -243,8 +248,8 @@ }, "right": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 38, + "end": 39, "loc": { "start": { "line": 3, diff --git a/test/fixtures/lightscript/named-arrow-functions/malformed-get/actual.js b/test/fixtures/lightscript/named-arrow-functions/malformed-get/actual.js deleted file mode 100644 index f508adafec..0000000000 --- a/test/fixtures/lightscript/named-arrow-functions/malformed-get/actual.js +++ /dev/null @@ -1 +0,0 @@ -fn() -get> 1 diff --git a/test/fixtures/lightscript/named-arrow-functions/malformed-get/options.json b/test/fixtures/lightscript/named-arrow-functions/malformed-get/options.json deleted file mode 100644 index 91e36be88d..0000000000 --- a/test/fixtures/lightscript/named-arrow-functions/malformed-get/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only methods can be getters. (1:5)" -} diff --git a/test/fixtures/lightscript/named-arrow-functions/malformed-set/actual.js b/test/fixtures/lightscript/named-arrow-functions/malformed-set/actual.js deleted file mode 100644 index 7d87b8822c..0000000000 --- a/test/fixtures/lightscript/named-arrow-functions/malformed-set/actual.js +++ /dev/null @@ -1 +0,0 @@ -fn(x) -set> 1 diff --git a/test/fixtures/lightscript/named-arrow-functions/malformed-set/options.json b/test/fixtures/lightscript/named-arrow-functions/malformed-set/options.json deleted file mode 100644 index b049180dc5..0000000000 --- a/test/fixtures/lightscript/named-arrow-functions/malformed-set/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only methods can be setters. (1:6)" -} From c4cc1d0a3f66519742bbc88bc3d78906ba0f508e Mon Sep 17 00:00:00 2001 From: Bo Lingen Date: Sat, 15 Jul 2017 06:36:29 +0000 Subject: [PATCH 3/3] add error for non-skinny arrow getter / setter --- src/plugins/lightscript.js | 4 ++++ .../arrow-methods/class-get-malformed-async/actual.js | 3 +++ .../arrow-methods/class-get-malformed-async/options.json | 3 +++ .../arrow-methods/class-get-malformed-fat-arrow/actual.js | 3 +++ .../arrow-methods/class-get-malformed-fat-arrow/options.json | 3 +++ .../arrow-methods/class-get-malformed-generator/actual.js | 3 +++ .../arrow-methods/class-get-malformed-generator/options.json | 3 +++ .../arrow-methods/class-set-malformed-async/actual.js | 3 +++ .../arrow-methods/class-set-malformed-async/options.json | 3 +++ .../arrow-methods/class-set-malformed-fat-arrow/actual.js | 3 +++ .../arrow-methods/class-set-malformed-fat-arrow/options.json | 3 +++ .../arrow-methods/class-set-malformed-generator/actual.js | 3 +++ .../arrow-methods/class-set-malformed-generator/options.json | 3 +++ 13 files changed, 40 insertions(+) create mode 100644 test/fixtures/lightscript/arrow-methods/class-get-malformed-async/actual.js create mode 100644 test/fixtures/lightscript/arrow-methods/class-get-malformed-async/options.json create mode 100644 test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/actual.js create mode 100644 test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/options.json create mode 100644 test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/actual.js create mode 100644 test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/options.json create mode 100644 test/fixtures/lightscript/arrow-methods/class-set-malformed-async/actual.js create mode 100644 test/fixtures/lightscript/arrow-methods/class-set-malformed-async/options.json create mode 100644 test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/actual.js create mode 100644 test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/options.json create mode 100644 test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/actual.js create mode 100644 test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/options.json diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index 91b46c7ea6..fd992ae6ca 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -255,6 +255,10 @@ pp.parseArrowType = function (node) { if (node.generator) this.unexpected(node.start, "Can't declare generators with arrows; try -*> instead."); if (node.kind === "constructor" && val !== "->") this.unexpected(null, "Can only use -> with constructor."); + if ((node.kind === "get" || node.kind === "set") && val !== "->") { + this.unexpected(node.start, "Can only use -> with getters & setters."); + } + switch (val) { case "=/>": case "-/>": node.async = true; diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-async/actual.js b/test/fixtures/lightscript/arrow-methods/class-get-malformed-async/actual.js new file mode 100644 index 0000000000..508e94649b --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-async/actual.js @@ -0,0 +1,3 @@ +class X { + get method() -/> await a +} diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-async/options.json b/test/fixtures/lightscript/arrow-methods/class-get-malformed-async/options.json new file mode 100644 index 0000000000..42a9334774 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-async/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can only use -> with getters & setters. (2:2)" +} diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/actual.js b/test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/actual.js new file mode 100644 index 0000000000..18edff3f53 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/actual.js @@ -0,0 +1,3 @@ +class X { + get method() => 1 +} diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/options.json b/test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/options.json new file mode 100644 index 0000000000..42a9334774 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-fat-arrow/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can only use -> with getters & setters. (2:2)" +} diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/actual.js b/test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/actual.js new file mode 100644 index 0000000000..a035c9f207 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/actual.js @@ -0,0 +1,3 @@ +class X { + get method() -*> await a +} diff --git a/test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/options.json b/test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/options.json new file mode 100644 index 0000000000..42a9334774 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-get-malformed-generator/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can only use -> with getters & setters. (2:2)" +} diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-async/actual.js b/test/fixtures/lightscript/arrow-methods/class-set-malformed-async/actual.js new file mode 100644 index 0000000000..ba0e38d10f --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-async/actual.js @@ -0,0 +1,3 @@ +class X { + set method() -/> await a +} diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-async/options.json b/test/fixtures/lightscript/arrow-methods/class-set-malformed-async/options.json new file mode 100644 index 0000000000..42a9334774 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-async/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can only use -> with getters & setters. (2:2)" +} diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/actual.js b/test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/actual.js new file mode 100644 index 0000000000..a08008e31d --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/actual.js @@ -0,0 +1,3 @@ +class X { + set method() => 1 +} diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/options.json b/test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/options.json new file mode 100644 index 0000000000..42a9334774 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-fat-arrow/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can only use -> with getters & setters. (2:2)" +} diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/actual.js b/test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/actual.js new file mode 100644 index 0000000000..a19ccee9fc --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/actual.js @@ -0,0 +1,3 @@ +class X { + set method() -*> await a +} diff --git a/test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/options.json b/test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/options.json new file mode 100644 index 0000000000..42a9334774 --- /dev/null +++ b/test/fixtures/lightscript/arrow-methods/class-set-malformed-generator/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can only use -> with getters & setters. (2:2)" +}