mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 12:15:34 -06:00
Added change to omit comments for variable statements when appropriate.
This commit is contained in:
parent
e3812ff8f2
commit
bd2139694a
@ -2229,9 +2229,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
emitEmbeddedStatement(node.statement);
|
||||
}
|
||||
|
||||
/* Returns true if start of variable declaration list was emitted.
|
||||
* Return false if nothing was written - this can happen for source file level variable declarations
|
||||
* in system modules - such variable declarations are hoisted.
|
||||
/**
|
||||
* Returns true if start of variable declaration list was emitted.
|
||||
* Returns false if nothing was written - this can happen for source file level variable declarations
|
||||
* in system modules where such variable declarations are hoisted.
|
||||
*/
|
||||
function tryEmitStartOfVariableDeclarationList(decl: VariableDeclarationList, startPos?: number): boolean {
|
||||
if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) {
|
||||
@ -3060,6 +3061,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
|
||||
function emitVariableStatement(node: VariableStatement) {
|
||||
let startIsEmitted = false;
|
||||
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
if (isES6ExportedDeclaration(node)) {
|
||||
// Exported ES6 module member
|
||||
@ -3070,6 +3072,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
else {
|
||||
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
|
||||
}
|
||||
|
||||
if (startIsEmitted) {
|
||||
emitCommaList(node.declarationList.declarations);
|
||||
write(";");
|
||||
@ -3085,6 +3088,28 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node: VariableStatement) {
|
||||
// If we're not exporting the variables, there's nothing special here.
|
||||
// Always emit comments for these nodes.
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we are exporting, but it's a top-level ES6 module exports,
|
||||
// we'll emit the declaration list verbatim, so emit comments too.
|
||||
if (isES6ExportedDeclaration(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, only emit if we have at least one initializer present.
|
||||
for (let declaration of node.declarationList.declarations) {
|
||||
if (declaration.initializer) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function emitParameter(node: ParameterDeclaration) {
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
if (isBindingPattern(node.name)) {
|
||||
@ -5747,6 +5772,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return false;
|
||||
|
||||
case SyntaxKind.VariableStatement:
|
||||
return shouldEmitLeadingAndTrailingCommentsForVariableStatement(<VariableStatement>node);
|
||||
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
// Only emit the leading/trailing comments for a module if we're actually
|
||||
// emitting the module as well.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user