Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix printing of comments around decorators and class properties #3382

Merged
merged 1 commit into from
Dec 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ function handleMethodNameComments(text, enclosingNode, precedingNode, comment) {
enclosingNode &&
precedingNode.type === "Decorator" &&
(enclosingNode.type === "ClassMethod" ||
enclosingNode.type === "ClassProperty" ||
enclosingNode.type === "TSAbstractClassProperty" ||
enclosingNode.type === "TSAbstractMethodDefinition" ||
enclosingNode.type === "MethodDefinition")
) {
addTrailingComment(precedingNode, comment);
Expand Down
16 changes: 16 additions & 0 deletions tests/decorator_comments/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`comments.js 1`] = `
class Something {
@Annotateme()
// comment
static property: Array<string>;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Something {
@Annotateme()
// comment
static property: Array<string>;
}

`;
5 changes: 5 additions & 0 deletions tests/decorator_comments/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Something {
@Annotateme()
// comment
static property: Array<string>;
}
1 change: 1 addition & 0 deletions tests/decorator_comments/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, ["babylon", "typescript"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget to include flow? 😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow doesn't support decorators

35 changes: 35 additions & 0 deletions tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ class Foo4 {
async *method() {}
}

class Something {
@foo()
// comment
readonly property: Array<string>
}

class Something {
@foo()
// comment
abstract property: Array<string>
}

class Something {
@foo()
// comment
abstract method(): Array<string>
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Foo1 {
@foo
Expand All @@ -105,6 +122,24 @@ class Foo4 {
async *method() {}
}

class Something {
@foo()
// comment
readonly property: Array<string>;
}

class Something {
@foo()
// comment
abstract property: Array<string>;
}

class Something {
@foo()
// comment
abstract method(): Array<string>;
}

`;

exports[`inline-decorators.ts 1`] = `
Expand Down
17 changes: 17 additions & 0 deletions tests/typescript_decorators/decorators-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@ class Foo4 {
async *method() {}
}

class Something {
@foo()
// comment
readonly property: Array<string>
}

class Something {
@foo()
// comment
abstract property: Array<string>
}

class Something {
@foo()
// comment
abstract method(): Array<string>
}