Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/plugins/lightscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ 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.");

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;
Expand All @@ -268,15 +270,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:
Expand Down
11 changes: 0 additions & 11 deletions src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class X {
get method() -/> await a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Can only use -> with getters & setters. (2:2)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class X {
get method() => 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Can only use -> with getters & setters. (2:2)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class X {
get method() -*> await a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Can only use -> with getters & setters. (2:2)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class X {
method(x) -get>
get method(x) ->
x
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class X {
method(x, y) -get>
get method(x, y) ->
x + y
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class X {
method() -get>
get method() ->
a
b
}
40 changes: 20 additions & 20 deletions test/fixtures/lightscript/arrow-methods/class-get/expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "File",
"start": 0,
"end": 40,
"end": 41,
"loc": {
"start": {
"line": 1,
Expand All @@ -15,7 +15,7 @@
"program": {
"type": "Program",
"start": 0,
"end": 40,
"end": 41,
"loc": {
"start": {
"line": 1,
Expand All @@ -31,7 +31,7 @@
{
"type": "ClassDeclaration",
"start": 0,
"end": 40,
"end": 41,
"loc": {
"start": {
"line": 1,
Expand Down Expand Up @@ -63,7 +63,7 @@
"body": {
"type": "ClassBody",
"start": 8,
"end": 40,
"end": 41,
"loc": {
"start": {
"line": 1,
Expand All @@ -78,7 +78,7 @@
{
"type": "ClassMethod",
"start": 12,
"end": 38,
"end": 39,
"loc": {
"start": {
"line": 2,
Expand All @@ -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"
},
Expand All @@ -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,
Expand All @@ -132,8 +132,8 @@
"body": [
{
"type": "ExpressionStatement",
"start": 31,
"end": 32,
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 3,
Expand All @@ -146,8 +146,8 @@
},
"expression": {
"type": "Identifier",
"start": 31,
"end": 32,
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 3,
Expand All @@ -164,8 +164,8 @@
},
{
"type": "ExpressionStatement",
"start": 37,
"end": 38,
"start": 38,
"end": 39,
"loc": {
"start": {
"line": 4,
Expand All @@ -178,8 +178,8 @@
},
"expression": {
"type": "Identifier",
"start": 37,
"end": 38,
"start": 38,
"end": 39,
"loc": {
"start": {
"line": 4,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class X {
async method() -> await a

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably now be:

  get method() -/> await a

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

....which of course should not throw Can't use async with lightscript arrows. (2:2) anymore, but should throw something. Chrome doesn't parse async get foo() {} or get async foo() {}.

Maybe Getters cannot be async ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be doable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the reason I made this a non-getter test is, like the fat arrow getter comment, you also can't do it in JS and so it seemed obvious. And there's a class-malformed-async-fat-arrow but no skinny until now

Copy link

@rattrayalex rattrayalex Jul 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we still need to test that it throws though (this is checking correct behavior of the parser, not documenting the language)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'm adding a new, separate test for that so we'll keep this one. Also to specify - a getter can return a Promise, it just can't be an actual async function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Womp, sorry, should have seen this before – we should remove (or at least rename) this test since it no longer tests what it says it does

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class X {
set method() -/> await a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Can only use -> with getters & setters. (2:2)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class X {
set method() => 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Can only use -> with getters & setters. (2:2)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class X {
set method() -*> await a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Can only use -> with getters & setters. (2:2)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class X {
method() -set>
set method() ->
this.x = x
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class X {
method(x, y) -set>
set method(x, y) ->
this.x = x
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class X {
method(x) -set>
set method(x) ->
this.x = x
}
Loading