From bd728e8d3d491eaf91c9a997b9dcb5437c26cbd0 Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Tue, 26 Sep 2017 08:10:04 +0100 Subject: [PATCH] Fix incorrect parsing of `%*`. --- src/tokenize.js | 2 +- test/tests-es7.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tokenize.js b/src/tokenize.js index 4f98e3407..f2611b012 100644 --- a/src/tokenize.js +++ b/src/tokenize.js @@ -221,7 +221,7 @@ pp.readToken_mult_modulo_exp = function(code) { // '%*' let tokentype = code === 42 ? tt.star : tt.modulo // exponentiation operator ** and **= - if (this.options.ecmaVersion >= 7 && next === 42) { + if (this.options.ecmaVersion >= 7 && code == 42 && next === 42) { ++size tokentype = tt.starstar next = this.input.charCodeAt(this.pos + 2) diff --git a/test/tests-es7.js b/test/tests-es7.js index 32c2efb90..4130cb22d 100644 --- a/test/tests-es7.js +++ b/test/tests-es7.js @@ -342,6 +342,10 @@ test("a-- ** 2", { "sourceType": "script" }, {ecmaVersion: 7}) +testFail("x %* y", "Unexpected token (1:3)", { ecmaVersion: 7 }); + +testFail("x %*= y", "Unexpected token (1:3)", { ecmaVersion: 7 }); + testFail("function foo(a=2) { 'use strict'; }", "Illegal 'use strict' directive in function with non-simple parameter list (1:0)", { ecmaVersion: 7 }) testFail("(a=2) => { 'use strict'; }", "Illegal 'use strict' directive in function with non-simple parameter list (1:0)", { ecmaVersion: 7 }) testFail("function foo({a}) { 'use strict'; }", "Illegal 'use strict' directive in function with non-simple parameter list (1:0)", { ecmaVersion: 7 })