diff --git a/src/fast-path.js b/src/fast-path.js index 9ec8f0606..2ce4c9cce 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -329,6 +329,9 @@ FPp.needsParens = function(assumeExpressionContext) { && name === "object" && parent.object === node; + case "NumericLiteral": + return parent.type === "MemberExpression"; + case "AssignmentExpression": case "ConditionalExpression": switch (parent.type) { diff --git a/tests/literal/__snapshots__/jsfmt.spec.js.snap b/tests/literal/__snapshots__/jsfmt.spec.js.snap index 54fe861d5..655ae21ee 100644 --- a/tests/literal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/literal/__snapshots__/jsfmt.spec.js.snap @@ -84,6 +84,11 @@ function test4(flip_times: number): number { } return x; } + +// parentheses around numeric literal should be preserved +function test5(): string { + return (100).toString(); +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function test1(x: number): number { return -x; @@ -108,5 +113,10 @@ function test4(flip_times: number): number { } return x; } + +// parentheses around numeric literal should be preserved +function test5(): string { + return (100).toString(); +} " `; diff --git a/tests/literal/number.js b/tests/literal/number.js index 1ec529919..9765a13eb 100644 --- a/tests/literal/number.js +++ b/tests/literal/number.js @@ -21,3 +21,8 @@ function test4(flip_times: number): number { } return x; } + +// parentheses around numeric literal should be preserved +function test5(): string { + return (100).toString(); +}