Skip to content

Commit

Permalink
fix: parenthesize superClass on non-idetifier case (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored and bcoe committed May 31, 2018
1 parent ce23e91 commit 6202c88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/istanbul-lib-instrument/src/visitor.js
Expand Up @@ -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));
};
}

Expand Down
8 changes: 8 additions & 0 deletions packages/istanbul-lib-instrument/test/varia.test.js
Expand Up @@ -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/));
});
});

0 comments on commit 6202c88

Please sign in to comment.