add lineBreak test to tt.name.updateContext - fixes #2591

This commit is contained in:
Sebastian McKenzie 2015-11-03 11:46:01 +00:00
parent d8b17a9eaa
commit b486dfb675
5 changed files with 389 additions and 0 deletions

View File

@ -5,6 +5,7 @@
// See https://github.com/mozilla/sweet.js/wiki/design
import { types as tt } from "./types";
import { lineBreak } from "../util/whitespace";
export class TokContext {
constructor(
@ -54,6 +55,14 @@ tt.parenR.updateContext = tt.braceR.updateContext = function () {
}
};
tt.name.updateContext = function (prevType) {
if (prevType === tt._let || prevType === tt._const || prevType === tt._var) {
if (lineBreak.test(this.input.slice(this.state.end))) {
this.state.exprAllowed = true;
}
}
};
tt.braceL.updateContext = function (prevType) {
this.state.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
this.state.exprAllowed = true;

View File

@ -0,0 +1,4 @@
function x() {
let x
/wow/;
}

View File

@ -0,0 +1,171 @@
{
"type": "File",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"name": "x"
},
"generator": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 13,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "VariableDeclaration",
"start": 17,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 7
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
}
},
"id": {
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
}
},
"name": "x"
},
"init": null
}
],
"kind": "let"
},
{
"type": "ExpressionStatement",
"start": 25,
"end": 31,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 8
}
},
"expression": {
"type": "RegExpLiteral",
"start": 25,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 7
}
},
"extra": {
"raw": "/wow/"
},
"pattern": "wow",
"flags": ""
}
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,4 @@
function x() {
let x
<div />
}

View File

@ -0,0 +1,201 @@
{
"type": "File",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"name": "x"
},
"generator": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 13,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "VariableDeclaration",
"start": 17,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 7
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
}
},
"id": {
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
}
},
"name": "x"
},
"init": null
}
],
"kind": "let"
},
{
"type": "ExpressionStatement",
"start": 25,
"end": 32,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 9
}
},
"expression": {
"type": "JSXElement",
"start": 25,
"end": 32,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 9
}
},
"openingElement": {
"type": "JSXOpeningElement",
"start": 25,
"end": 32,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 9
}
},
"attributes": [],
"name": {
"type": "JSXIdentifier",
"start": 26,
"end": 29,
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 6
}
},
"name": "div"
},
"selfClosing": true
},
"closingElement": null,
"children": []
}
}
],
"directives": []
}
}
],
"directives": []
}
}