From 6202c8890178aba8185ad3110dea6f1972743393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 31 May 2018 08:32:40 +0800 Subject: [PATCH] fix: parenthesize superClass on non-idetifier case (#158) --- packages/istanbul-lib-instrument/src/visitor.js | 12 ++++++------ packages/istanbul-lib-instrument/test/varia.test.js | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/istanbul-lib-instrument/src/visitor.js b/packages/istanbul-lib-instrument/src/visitor.js index 7057aedc..2a1b6b6b 100644 --- a/packages/istanbul-lib-instrument/src/visitor.js +++ b/packages/istanbul-lib-instrument/src/visitor.js @@ -339,16 +339,16 @@ function blockProp(prop) { }; } -function makeParenthesizedExpression(path) { - var T = this.types; - if (path.node) { - path.replaceWith(T.parenthesizedExpression(path.node)); - } +function makeParenthesizedExpressionForNonIdentifier(path) { + var T = this.types; + if (path.node && !path.isIdentifier()) { + path.replaceWith(T.parenthesizedExpression(path.node)); + } } function parenthesizedExpressionProp(prop) { return function (path) { - makeParenthesizedExpression.call(this, path.get(prop)); + makeParenthesizedExpressionForNonIdentifier.call(this, path.get(prop)); }; } diff --git a/packages/istanbul-lib-instrument/test/varia.test.js b/packages/istanbul-lib-instrument/test/varia.test.js index 45045bf9..c19adc76 100644 --- a/packages/istanbul-lib-instrument/test/varia.test.js +++ b/packages/istanbul-lib-instrument/test/varia.test.js @@ -142,4 +142,12 @@ describe('varia', function () { code = v.getGeneratedCode(); assert.ok(code.match(/cov_(.+);export class App extends/)); }); + + it('does not add extra parenthesis when superclass is an identifier', function () { + var v = verifier.create('class App extends Component {};', { generateOnly: true }), + code; + assert.ok(!v.err); + code = v.getGeneratedCode(); + assert.ok(code.match(/cov_(.+);class App extends Component/)); + }); });