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
parent
f6bbc2ed2e
commit
3f6259554e
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
export //comment
|
||||
{}
|
Loading…
Reference in New Issue