Skip to content

Commit

Permalink
Set exprAllowed to false for star token
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Apr 21, 2020
1 parent d18d465 commit 3a761e6
Show file tree
Hide file tree
Showing 15 changed files with 465 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/babel-parser/src/tokenizer/context.js
Expand Up @@ -133,3 +133,7 @@ tt.backQuote.updateContext = function() {
}
this.state.exprAllowed = false;
};

tt.star.updateContext = function() {
this.state.exprAllowed = false;
};
@@ -0,0 +1 @@
a * /b/
@@ -0,0 +1,36 @@
{
"type": "File",
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
"program": {
"type": "Program",
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
"expression": {
"type": "BinaryExpression",
"start":0,"end":7,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":7}},
"left": {
"type": "Identifier",
"start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"a"},
"name": "a"
},
"operator": "*",
"right": {
"type": "RegExpLiteral",
"start":4,"end":7,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":7}},
"extra": {
"raw": "/b/"
},
"pattern": "b",
"flags": ""
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
function* x() { yield* /z/ }
@@ -0,0 +1,50 @@
{
"type": "File",
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"program": {
"type": "Program",
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"id": {
"type": "Identifier",
"start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"x"},
"name": "x"
},
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":14,"end":28,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":28}},
"body": [
{
"type": "ExpressionStatement",
"start":16,"end":26,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":26}},
"expression": {
"type": "YieldExpression",
"start":16,"end":26,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":26}},
"delegate": true,
"argument": {
"type": "RegExpLiteral",
"start":23,"end":26,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":26}},
"extra": {
"raw": "/z/"
},
"pattern": "z",
"flags": ""
}
}
}
],
"directives": []
}
}
],
"directives": []
}
}
@@ -0,0 +1,3 @@
const fn = function* <,>(input: T): Generator<number> {
yield 2;
}
@@ -0,0 +1,5 @@
{
"sourceType": "module",
"plugins": ["jsx", "flow"],
"throws": "Unexpected token (1:22)"
}
@@ -0,0 +1,3 @@
const fn = function* <T>(input: T): Generator<number> {
yield 2;
}
@@ -0,0 +1,118 @@
{
"type": "File",
"start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"program": {
"type": "Program",
"start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"declarations": [
{
"type": "VariableDeclarator",
"start":6,"end":68,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":1}},
"id": {
"type": "Identifier",
"start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8},"identifierName":"fn"},
"name": "fn"
},
"init": {
"type": "FunctionExpression",
"start":11,"end":68,"loc":{"start":{"line":1,"column":11},"end":{"line":3,"column":1}},
"id": null,
"generator": true,
"async": false,
"typeParameters": {
"type": "TypeParameterDeclaration",
"start":21,"end":24,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":24}},
"params": [
{
"type": "TypeParameter",
"start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}},
"name": "T",
"variance": null
}
]
},
"params": [
{
"type": "Identifier",
"start":25,"end":33,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":33},"identifierName":"input"},
"name": "input",
"typeAnnotation": {
"type": "TypeAnnotation",
"start":30,"end":33,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":33}},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33}},
"typeParameters": null,
"id": {
"type": "Identifier",
"start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33},"identifierName":"T"},
"name": "T"
}
}
}
}
],
"predicate": null,
"returnType": {
"type": "TypeAnnotation",
"start":34,"end":53,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":53}},
"typeAnnotation": {
"type": "GenericTypeAnnotation",
"start":36,"end":53,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":53}},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start":45,"end":53,"loc":{"start":{"line":1,"column":45},"end":{"line":1,"column":53}},
"params": [
{
"type": "NumberTypeAnnotation",
"start":46,"end":52,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":52}}
}
]
},
"id": {
"type": "Identifier",
"start":36,"end":45,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":45},"identifierName":"Generator"},
"name": "Generator"
}
}
},
"body": {
"type": "BlockStatement",
"start":54,"end":68,"loc":{"start":{"line":1,"column":54},"end":{"line":3,"column":1}},
"body": [
{
"type": "ExpressionStatement",
"start":58,"end":66,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10}},
"expression": {
"type": "YieldExpression",
"start":58,"end":65,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":9}},
"delegate": false,
"argument": {
"type": "NumericLiteral",
"start":64,"end":65,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9}},
"extra": {
"rawValue": 2,
"raw": "2"
},
"value": 2
}
}
}
],
"directives": []
}
}
}
],
"kind": "const"
}
],
"directives": []
}
}
@@ -0,0 +1,3 @@
const fn = function* <T>(input: T): Generator<number> {
yield 2;
}
@@ -0,0 +1,115 @@
{
"type": "File",
"start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"program": {
"type": "Program",
"start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":68,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"declarations": [
{
"type": "VariableDeclarator",
"start":6,"end":68,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":1}},
"id": {
"type": "Identifier",
"start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8},"identifierName":"fn"},
"name": "fn"
},
"init": {
"type": "FunctionExpression",
"start":11,"end":68,"loc":{"start":{"line":1,"column":11},"end":{"line":3,"column":1}},
"id": null,
"generator": true,
"async": false,
"typeParameters": {
"type": "TSTypeParameterDeclaration",
"start":21,"end":24,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":24}},
"params": [
{
"type": "TSTypeParameter",
"start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}},
"name": "T"
}
]
},
"params": [
{
"type": "Identifier",
"start":25,"end":33,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":33},"identifierName":"input"},
"name": "input",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start":30,"end":33,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":33}},
"typeAnnotation": {
"type": "TSTypeReference",
"start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33}},
"typeName": {
"type": "Identifier",
"start":32,"end":33,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":33},"identifierName":"T"},
"name": "T"
}
}
}
}
],
"returnType": {
"type": "TSTypeAnnotation",
"start":34,"end":53,"loc":{"start":{"line":1,"column":34},"end":{"line":1,"column":53}},
"typeAnnotation": {
"type": "TSTypeReference",
"start":36,"end":53,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":53}},
"typeName": {
"type": "Identifier",
"start":36,"end":45,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":45},"identifierName":"Generator"},
"name": "Generator"
},
"typeParameters": {
"type": "TSTypeParameterInstantiation",
"start":45,"end":53,"loc":{"start":{"line":1,"column":45},"end":{"line":1,"column":53}},
"params": [
{
"type": "TSNumberKeyword",
"start":46,"end":52,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":52}}
}
]
}
}
},
"body": {
"type": "BlockStatement",
"start":54,"end":68,"loc":{"start":{"line":1,"column":54},"end":{"line":3,"column":1}},
"body": [
{
"type": "ExpressionStatement",
"start":58,"end":66,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10}},
"expression": {
"type": "YieldExpression",
"start":58,"end":65,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":9}},
"delegate": false,
"argument": {
"type": "NumericLiteral",
"start":64,"end":65,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9}},
"extra": {
"rawValue": 2,
"raw": "2"
},
"value": 2
}
}
}
],
"directives": []
}
}
}
],
"kind": "const"
}
],
"directives": []
}
}
@@ -0,0 +1,3 @@
const fn = function* <,>(input: T): Generator<number> {
yield 2;
}
@@ -0,0 +1,5 @@
{
"plugins": ["jsx", "typescript"],
"sourceType": "module",
"throws": "Unexpected token (1:22)"
}
@@ -0,0 +1,3 @@
const fn = function* <T>(input: T): Generator<number> {
yield 2;
}

0 comments on commit 3a761e6

Please sign in to comment.