Change es2015 transform to retain comments on for of loop bodies (#22396)

This commit is contained in:
Wesley Wigham
2018-03-16 12:57:38 -07:00
committed by GitHub
parent 9774cd5eb5
commit 2d01d76ee5
39 changed files with 777 additions and 154 deletions

View File

@@ -2348,32 +2348,26 @@ namespace ts {
}
}
let bodyLocation: TextRange;
let statementsLocation: TextRange;
if (convertedLoopBodyStatements) {
addRange(statements, convertedLoopBodyStatements);
return createSyntheticBlockForConvertedStatements(addRange(statements, convertedLoopBodyStatements));
}
else {
const statement = visitNode(node.statement, visitor, isStatement, liftToBlock);
if (isBlock(statement)) {
addRange(statements, statement.statements);
bodyLocation = statement;
statementsLocation = statement.statements;
return updateBlock(statement, setTextRange(createNodeArray(concatenate(statements, statement.statements)), statement.statements));
}
else {
statements.push(statement);
return createSyntheticBlockForConvertedStatements(statements);
}
}
}
// The old emitter does not emit source maps for the block.
// We add the location to preserve comments.
function createSyntheticBlockForConvertedStatements(statements: Statement[]) {
return setEmitFlags(
setTextRange(
createBlock(
setTextRange(createNodeArray(statements), statementsLocation),
/*multiLine*/ true
),
bodyLocation,
createBlock(
createNodeArray(statements),
/*multiLine*/ true
),
EmitFlags.NoSourceMap | EmitFlags.NoTokenSourceMaps
);