mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
Merge pull request #8064 from Microsoft/trailingModuleComments
[Transforms] Fixes trailing comments emit for modules and enum declaration
This commit is contained in:
commit
02c8315aed
@ -2223,24 +2223,6 @@ namespace ts {
|
||||
|| (isES6ExportedDeclaration(node) && isFirstDeclarationOfKind(node, node.kind));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a leading VariableStatement for an enum or module declaration.
|
||||
*/
|
||||
function addVarForEnumDeclaration(statements: Statement[], node: EnumDeclaration) {
|
||||
// Emit a variable statement for the enum.
|
||||
statements.push(
|
||||
createVariableStatement(
|
||||
isES6ExportedDeclaration(node)
|
||||
? visitNodes(node.modifiers, visitor, isModifier)
|
||||
: undefined,
|
||||
[createVariableDeclaration(
|
||||
getDeclarationName(node)
|
||||
)],
|
||||
/*location*/ node
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a trailing VariableStatement for an enum or module declaration.
|
||||
*/
|
||||
@ -2271,7 +2253,7 @@ namespace ts {
|
||||
|
||||
const statements: Statement[] = [];
|
||||
if (shouldEmitVarForEnumDeclaration(node)) {
|
||||
addVarForEnumDeclaration(statements, node);
|
||||
addVarForEnumOrModuleDeclaration(statements, node);
|
||||
}
|
||||
|
||||
const localName = getGeneratedNameForNode(node);
|
||||
@ -2408,9 +2390,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a leading VariableStatement for a module declaration.
|
||||
* Adds a leading VariableStatement for a enum or module declaration.
|
||||
*/
|
||||
function addVarForModuleDeclaration(statements: Statement[], node: ModuleDeclaration) {
|
||||
function addVarForEnumOrModuleDeclaration(statements: Statement[], node: ModuleDeclaration | EnumDeclaration) {
|
||||
// Emit a variable statement for the module.
|
||||
statements.push(
|
||||
setOriginalNode(
|
||||
@ -2421,7 +2403,21 @@ namespace ts {
|
||||
[createVariableDeclaration(
|
||||
getDeclarationName(node)
|
||||
)],
|
||||
/*location*/ node
|
||||
// Trailing comments for module declaration should be emitted with function closure instead of variable statement
|
||||
// So do not set the end position for the variable statement node
|
||||
// /** Module comment*/
|
||||
// module m1 {
|
||||
// function foo4Export() {
|
||||
// }
|
||||
// } // trailing comment module
|
||||
// Should emit
|
||||
// /** Module comment*/
|
||||
// var m1;
|
||||
// (function (m1) {
|
||||
// function foo4Export() {
|
||||
// }
|
||||
// })(m1 || (m1 = {})); // trailing comment module
|
||||
/*location*/ { pos: node.pos, end: -1 }
|
||||
),
|
||||
node
|
||||
)
|
||||
@ -2446,7 +2442,7 @@ namespace ts {
|
||||
const statements: Statement[] = [];
|
||||
|
||||
if (shouldEmitVarForModuleDeclaration(node)) {
|
||||
addVarForModuleDeclaration(statements, node);
|
||||
addVarForEnumOrModuleDeclaration(statements, node);
|
||||
}
|
||||
|
||||
const localName = getGeneratedNameForNode(node);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user