Skip to content

Commit

Permalink
Print parens around type assertions for decorators (#3329)
Browse files Browse the repository at this point in the history
  • Loading branch information
azz committed Nov 27, 2017
1 parent 9b4ecec commit 2dd76c6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/fast-path.js
Expand Up @@ -322,6 +322,12 @@ FastPath.prototype.needsParens = function(options) {
(node.type === "TSTypeAssertionExpression" ||
node.type === "TSAsExpression")
);
case "Decorator":
return (
parent.expression === node &&
(node.type === "TSTypeAssertionExpression" ||
node.type === "TSAsExpression")
);

case "BinaryExpression":
case "LogicalExpression": {
Expand Down
19 changes: 19 additions & 0 deletions tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap
@@ -1,5 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`decorator-type-assertion.ts 1`] = `
@(bind as ClassDecorator)
class Decorated {
}
@(<ClassDecorator>bind)
class Decorated {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@(bind as ClassDecorator)
class Decorated {}
@(<ClassDecorator>bind)
class Decorated {}
`;
exports[`decorators.js 1`] = `
export class TestTextFileService {
constructor(
Expand Down
9 changes: 9 additions & 0 deletions tests/typescript_decorators/decorator-type-assertion.ts
@@ -0,0 +1,9 @@
@(bind as ClassDecorator)
class Decorated {

}

@(<ClassDecorator>bind)
class Decorated {

}

0 comments on commit 2dd76c6

Please sign in to comment.