Merge pull request #8064 from Microsoft/trailingModuleComments

[Transforms] Fixes trailing comments emit for modules and enum declaration
This commit is contained in:
Sheetal Nandi 2016-04-13 15:47:17 -07:00
commit 02c8315aed

View File

@ -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);