From 8f3615bf7b4fdc587ed48f01001abbfadc6b5a3f Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Mon, 10 Aug 2015 19:03:13 -0400 Subject: [PATCH 1/3] fix unexpected token issue for regex after block case - Ex: `if (1) {} /foo/` Fixes babel/babel-eslint#161 Ref marijnh/acorn#289 --- src/tokenizer/index.js | 2 +- .../categorized/regex-after-block/actual.js | 4 + .../regex-after-block/expected.json | 120 ++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/core/categorized/regex-after-block/actual.js create mode 100644 test/fixtures/core/categorized/regex-after-block/expected.json diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 8b40220364..7bff031091 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -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; } diff --git a/test/fixtures/core/categorized/regex-after-block/actual.js b/test/fixtures/core/categorized/regex-after-block/actual.js new file mode 100644 index 0000000000..eaf38a64b8 --- /dev/null +++ b/test/fixtures/core/categorized/regex-after-block/actual.js @@ -0,0 +1,4 @@ +if (true) { +} + +/foo/ \ No newline at end of file diff --git a/test/fixtures/core/categorized/regex-after-block/expected.json b/test/fixtures/core/categorized/regex-after-block/expected.json new file mode 100644 index 0000000000..baf001440d --- /dev/null +++ b/test/fixtures/core/categorized/regex-after-block/expected.json @@ -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": "" + } + } + } + ] + } +} \ No newline at end of file From babf64473bb5208b72c3d5c0d53191646d262c58 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Mon, 10 Aug 2015 19:31:26 -0400 Subject: [PATCH 2/3] fix broken test from regex-after-block --- test/fixtures/core/categorized/regex-after-block/expected.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/fixtures/core/categorized/regex-after-block/expected.json b/test/fixtures/core/categorized/regex-after-block/expected.json index baf001440d..9865ab3100 100644 --- a/test/fixtures/core/categorized/regex-after-block/expected.json +++ b/test/fixtures/core/categorized/regex-after-block/expected.json @@ -106,8 +106,6 @@ "column": 5 } }, - "value": {}, - "rawValue": {}, "raw": "/foo/", "regex": { "pattern": "foo", From 87c604b64e0465c438330a50ccf7cc6b0017f334 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 11 Aug 2015 01:00:54 +0100 Subject: [PATCH 3/3] v5.8.22 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c61717350e..0da5690336 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babylon", - "version": "5.8.21", + "version": "5.8.22", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/",