mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Change es2015 transform to retain comments on for of loop bodies (#22396)
This commit is contained in:
1 parent
9774cd5eb5
commit
2d01d76ee5
39 files changed
+777
-154
No files matched your search
@@ -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