From 6933d16125995c6d1cd3280f986ff93d26d646f4 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Fri, 2 Jun 2017 14:40:39 -0700 Subject: [PATCH] Inline decorators with no arguments (#1910) Fixes #1898 --- src/printer.js | 9 +++++---- .../__snapshots__/jsfmt.spec.js.snap | 17 +++++++++++++++-- tests/typescript_decorators/decorators.js | 7 +++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/printer.js b/src/printer.js index d28ab891b..b8270ccd6 100644 --- a/src/printer.js +++ b/src/printer.js @@ -100,10 +100,11 @@ function genericPrint(path, options, printPath, args) { (decorator.type === "Identifier" || decorator.type === "MemberExpression" || (decorator.type === "CallExpression" && - decorator.arguments.length === 1 && - (isStringLiteral(decorator.arguments[0]) || - decorator.arguments[0].type === "Identifier" || - decorator.arguments[0].type === "MemberExpression"))) + (decorator.arguments.length === 0 || + (decorator.arguments.length === 1 && + (isStringLiteral(decorator.arguments[0]) || + decorator.arguments[0].type === "Identifier" || + decorator.arguments[0].type === "MemberExpression"))))) ) { separator = " "; } diff --git a/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap index 3d7fd3ef3..1b1aee030 100644 --- a/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,13 @@ export class TestTextFileService { @commonEditorContribution export class TabCompletionController { } + +@Component({ + selector: 'angular-component', +}) +class AngularComponent { + @Input() myInput: string; +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ export class TestTextFileService { constructor(@ILifecycleService lifecycleService) {} @@ -19,6 +26,13 @@ export class TestTextFileService { @commonEditorContribution export class TabCompletionController {} +@Component({ + selector: "angular-component" +}) +class AngularComponent { + @Input() myInput: string; +} + `; exports[`inline-decorators.ts 1`] = ` @@ -95,8 +109,7 @@ class Class3 { @d1 fieldA; @d2(foo) fieldB; @d3.bar fieldC; - @d4.baz() - fieldD; + @d4.baz() fieldD; constructor( @d1 private x: number, diff --git a/tests/typescript_decorators/decorators.js b/tests/typescript_decorators/decorators.js index f8210c53e..3224863b2 100644 --- a/tests/typescript_decorators/decorators.js +++ b/tests/typescript_decorators/decorators.js @@ -8,3 +8,10 @@ export class TestTextFileService { @commonEditorContribution export class TabCompletionController { } + +@Component({ + selector: 'angular-component', +}) +class AngularComponent { + @Input() myInput: string; +}