From bc0719a1455d351f25aa66a1fdbebccfa992d038 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Fri, 21 Apr 2017 09:25:34 -0500 Subject: [PATCH] Ensure non pattern shorthand props are checked for reserved words (#479) --- src/parser/expression.js | 3 ++- test/fixtures/es2015/shorthand/1/actual.js | 1 + test/fixtures/es2015/shorthand/1/options.json | 3 +++ test/fixtures/es2015/shorthand/2/actual.js | 1 + test/fixtures/es2015/shorthand/2/options.json | 3 +++ 5 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/es2015/shorthand/1/actual.js create mode 100644 test/fixtures/es2015/shorthand/1/options.json create mode 100644 test/fixtures/es2015/shorthand/2/actual.js create mode 100644 test/fixtures/es2015/shorthand/2/options.json diff --git a/src/parser/expression.js b/src/parser/expression.js index aeb6464f8d..e813460314 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -878,8 +878,9 @@ pp.parseObjectProperty = function (prop, startPos, startLoc, isPattern, refShort } if (!prop.computed && prop.key.type === "Identifier") { + this.checkReservedWord(prop.key.name, prop.key.start, true, true); + if (isPattern) { - this.checkReservedWord(prop.key.name, prop.key.start, true, true); prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone()); } else if (this.match(tt.eq) && refShorthandDefaultPos) { if (!refShorthandDefaultPos.start) { diff --git a/test/fixtures/es2015/shorthand/1/actual.js b/test/fixtures/es2015/shorthand/1/actual.js new file mode 100644 index 0000000000..5ce7c9deac --- /dev/null +++ b/test/fixtures/es2015/shorthand/1/actual.js @@ -0,0 +1 @@ +var x = ({ const }); diff --git a/test/fixtures/es2015/shorthand/1/options.json b/test/fixtures/es2015/shorthand/1/options.json new file mode 100644 index 0000000000..a618f5e2ef --- /dev/null +++ b/test/fixtures/es2015/shorthand/1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "const is a reserved word (1:11)" +} diff --git a/test/fixtures/es2015/shorthand/2/actual.js b/test/fixtures/es2015/shorthand/2/actual.js new file mode 100644 index 0000000000..fabf36837d --- /dev/null +++ b/test/fixtures/es2015/shorthand/2/actual.js @@ -0,0 +1 @@ +({ get, this, if }); diff --git a/test/fixtures/es2015/shorthand/2/options.json b/test/fixtures/es2015/shorthand/2/options.json new file mode 100644 index 0000000000..7691eb820f --- /dev/null +++ b/test/fixtures/es2015/shorthand/2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "this is a reserved word (1:8)" +}