Fix broken export comment (#899)

* Add new helper function to convert comments as blocks in ExportNamedDeclaration.

* Add new test.

* Switch to a leading position.

* Update test accordingly.
master
Davy Duperron 2017-03-06 06:49:07 +01:00 committed by Christopher Chedeau
parent f6bbc2ed2e
commit 3f6259554e
3 changed files with 30 additions and 1 deletions

View File

@ -186,7 +186,8 @@ function attach(comments, ast, text, options) {
handleTemplateLiteralComments(enclosingNode, comment) ||
handleCallExpressionComments(precedingNode, enclosingNode, comment) ||
handleClassComments(enclosingNode, comment) ||
handlePropertyComments(enclosingNode, comment)
handlePropertyComments(enclosingNode, comment) ||
handleExportNamedDeclarationComments(enclosingNode, comment)
) {
// We're good
} else if (precedingNode) {
@ -575,6 +576,14 @@ function handlePropertyComments(enclosingNode, comment) {
return false;
}
function handleExportNamedDeclarationComments(enclosingNode, comment) {
if (enclosingNode && enclosingNode.type === "ExportNamedDeclaration") {
addLeadingComment(enclosingNode, comment);
return true;
}
return false;
}
function printComment(commentPath) {
const comment = commentPath.getValue();
comment.printed = true;

View File

@ -242,6 +242,24 @@ for (;;);
"
`;
exports[`export.js 1`] = `
"export //comment
{}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//comment
export {};
"
`;
exports[`export.js 2`] = `
"export //comment
{}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//comment
export {};
"
`;
exports[`first-line.js 1`] = `
"a // comment
b

2
tests/comments/export.js Normal file
View File

@ -0,0 +1,2 @@
export //comment
{}