Print parens around type assertions for decorators (#3329)

master
Lucas Azzola 2017-11-27 23:10:33 +11:00 committed by GitHub
parent 9b4ecec183
commit 2dd76c6a95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -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": {

View File

@ -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(

View File

@ -0,0 +1,9 @@
@(bind as ClassDecorator)
class Decorated {
}
@(<ClassDecorator>bind)
class Decorated {
}