From 3474056b36f8c2e8a8418f16731257b37d8f8081 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sat, 24 Jun 2017 00:53:42 +1000 Subject: [PATCH] fix(typescript): handle ObjectPattern instead of ObjectExpression inside BinaryExpression, fixes #2237 (#2238) --- src/util.js | 3 +++ tests/arrows/__snapshots__/jsfmt.spec.js.snap | 10 ++++------ tests/arrows/arrow_function_expression.js | 5 ++--- tests/arrows/jsfmt.spec.js | 2 +- tests/arrows_bind/__snapshots__/jsfmt.spec.js.snap | 12 ++++++++++++ tests/arrows_bind/arrows-bind.js | 3 +++ tests/arrows_bind/jsfmt.spec.js | 1 + 7 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 tests/arrows_bind/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/arrows_bind/arrows-bind.js create mode 100644 tests/arrows_bind/jsfmt.spec.js diff --git a/src/util.js b/src/util.js index e8c9e6de5..fba714742 100644 --- a/src/util.js +++ b/src/util.js @@ -315,6 +315,9 @@ function getPrecedence(op) { function startsWithNoLookaheadToken(node, forbidFunctionAndClass) { node = getLeftMost(node); switch (node.type) { + // Hack. Remove after https://github.com/eslint/typescript-eslint-parser/issues/331 + case "ObjectPattern": + return !forbidFunctionAndClass; case "FunctionExpression": case "ClassExpression": return forbidFunctionAndClass; diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index ed1f5c8c0..9ec2a8852 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -22,17 +22,16 @@ a = () => ({} = 0); a = () => ({}, a); a => a instanceof {}; a => ({}().b && 0) -a => ({}::b()\`\`[''].c++ && 0 ? 0 : 0) a => ({}().c = 0) x => ({}()()) x => ({}()\`\`) x => ({}().b); -(a => b)::c; -a::(b => c); a = b => c; a = (b?) => c; x => (y = z); x => (y += z); +f(a => ({})) + 1; +(a => ({})) || 0; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (a => {}).length; typeof (() => {}); @@ -56,17 +55,16 @@ a = () => ({} = 0); a = () => ({}, a); a => a instanceof {}; a => ({}().b && 0); -a => ({}::b()\`\`[""].c++ && 0 ? 0 : 0); a => ({}().c = 0); x => ({}()()); x => ({}()\`\`); x => ({}().b); -(a => b)::c; -a::(b => c); a = b => c; a = (b?) => c; x => (y = z); x => (y += z); +f(a => ({})) + 1; +(a => ({})) || 0; `; diff --git a/tests/arrows/arrow_function_expression.js b/tests/arrows/arrow_function_expression.js index 64e2b6760..4e0071e03 100644 --- a/tests/arrows/arrow_function_expression.js +++ b/tests/arrows/arrow_function_expression.js @@ -19,14 +19,13 @@ a = () => ({} = 0); a = () => ({}, a); a => a instanceof {}; a => ({}().b && 0) -a => ({}::b()``[''].c++ && 0 ? 0 : 0) a => ({}().c = 0) x => ({}()()) x => ({}()``) x => ({}().b); -(a => b)::c; -a::(b => c); a = b => c; a = (b?) => c; x => (y = z); x => (y += z); +f(a => ({})) + 1; +(a => ({})) || 0; diff --git a/tests/arrows/jsfmt.spec.js b/tests/arrows/jsfmt.spec.js index f974ed6c7..6a6711aef 100644 --- a/tests/arrows/jsfmt.spec.js +++ b/tests/arrows/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, { parser: "babylon" }); +run_spec(__dirname, { parser: "babylon" }, ["typescript"]); diff --git a/tests/arrows_bind/__snapshots__/jsfmt.spec.js.snap b/tests/arrows_bind/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..c306aa57d --- /dev/null +++ b/tests/arrows_bind/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`arrows-bind.js 1`] = ` +a => ({}::b()\`\`[''].c++ && 0 ? 0 : 0); +(a => b)::c; +a::(b => c); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +a => ({}::b()\`\`[""].c++ && 0 ? 0 : 0); +(a => b)::c; +a::(b => c); + +`; diff --git a/tests/arrows_bind/arrows-bind.js b/tests/arrows_bind/arrows-bind.js new file mode 100644 index 000000000..6446f69e8 --- /dev/null +++ b/tests/arrows_bind/arrows-bind.js @@ -0,0 +1,3 @@ +a => ({}::b()``[''].c++ && 0 ? 0 : 0); +(a => b)::c; +a::(b => c); diff --git a/tests/arrows_bind/jsfmt.spec.js b/tests/arrows_bind/jsfmt.spec.js new file mode 100644 index 000000000..f974ed6c7 --- /dev/null +++ b/tests/arrows_bind/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "babylon" });