mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 05:17:43 -05:00
Change es2015 transform to retain comments on for of loop bodies (#22396)
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user