fix unexpected token issue for regex after block case
- Ex: `if (1) {} /foo/`
Fixes babel/babel-eslint#161
Ref marijnh/acorn#289
This commit is contained in:
parent
50add6753f
commit
04aedf37b4
@ -786,7 +786,7 @@ export default class Tokenizer {
|
||||
return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start));
|
||||
}
|
||||
|
||||
if (prevType === tt._else || prevType === tt.semi || prevType === tt.eof) {
|
||||
if (prevType === tt._else || prevType === tt.semi || prevType === tt.eof || prevType === tt.parenR) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
4
packages/babylon/test/fixtures/core/categorized/regex-after-block/actual.js
vendored
Normal file
4
packages/babylon/test/fixtures/core/categorized/regex-after-block/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
if (true) {
|
||||
}
|
||||
|
||||
/foo/
|
||||
120
packages/babylon/test/fixtures/core/categorized/regex-after-block/expected.json
vendored
Normal file
120
packages/babylon/test/fixtures/core/categorized/regex-after-block/expected.json
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"body": [
|
||||
{
|
||||
"type": "IfStatement",
|
||||
"start": 0,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"type": "Literal",
|
||||
"start": 4,
|
||||
"end": 8,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"value": true,
|
||||
"rawValue": true,
|
||||
"raw": "true"
|
||||
},
|
||||
"consequent": {
|
||||
"type": "BlockStatement",
|
||||
"start": 10,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
},
|
||||
"alternate": null
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 15,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "Literal",
|
||||
"start": 15,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"value": {},
|
||||
"rawValue": {},
|
||||
"raw": "/foo/",
|
||||
"regex": {
|
||||
"pattern": "foo",
|
||||
"flags": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user