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
4 changes: 4 additions & 0 deletions src/plugins/lightscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
16 changes: 16 additions & 0 deletions src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@ export default class Tokenizer {
return this.finishToken(tt.arrow, "-*>");
}

if (this.hasPlugin("asyncGenerators")) {

Choose a reason for hiding this comment

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

nice, this looks good!

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";
Expand Down Expand Up @@ -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) { // '=>'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn() =*/>
yield await x
Original file line number Diff line number Diff line change
@@ -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": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["lightscript", "jsx", "flow", "asyncGenerators"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn() -*/>
yield await x
Original file line number Diff line number Diff line change
@@ -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": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["lightscript", "jsx", "flow", "asyncGenerators"]
}