-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Simplify mergeEmitNode #59613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify mergeEmitNode #59613
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { | ||
__String, | ||
AccessorDeclaration, | ||
addRange, | ||
append, | ||
appendIfUnique, | ||
ArrayBindingElement, | ||
ArrayBindingPattern, | ||
ArrayLiteralExpression, | ||
|
@@ -422,7 +420,6 @@ import { | |
TemplateMiddle, | ||
TemplateSpan, | ||
TemplateTail, | ||
TextRange, | ||
ThisExpression, | ||
ThisTypeNode, | ||
ThrowStatement, | ||
|
@@ -7449,13 +7446,13 @@ function mergeEmitNode(sourceEmitNode: EmitNode, destEmitNode: EmitNode | undefi | |
// `leadingComments` are concatenated with any existing leading comments on the destination | ||
if (leadingComments) { | ||
// We use `.slice()` in case `destEmitNode.leadingComments` is pushed to later | ||
destEmitNode.leadingComments = addRange(leadingComments.slice(), destEmitNode.leadingComments); | ||
destEmitNode.leadingComments = leadingComments.slice(); | ||
} | ||
|
||
// `trailingComments` are concatenated with any existing trailing comments on the destination | ||
if (trailingComments) { | ||
// We use `.slice()` in case `destEmitNode.trailingComments` is pushed to later | ||
destEmitNode.trailingComments = addRange(trailingComments.slice(), destEmitNode.trailingComments); | ||
destEmitNode.trailingComments = trailingComments.slice(); | ||
} | ||
|
||
// `commentRange` overwrites the destination | ||
|
@@ -7470,7 +7467,7 @@ function mergeEmitNode(sourceEmitNode: EmitNode, destEmitNode: EmitNode | undefi | |
|
||
// `tokenSourceMapRanges` are merged with the destination | ||
if (tokenSourceMapRanges) { | ||
destEmitNode.tokenSourceMapRanges = mergeTokenSourceMapRanges(tokenSourceMapRanges, destEmitNode.tokenSourceMapRanges!); | ||
destEmitNode.tokenSourceMapRanges = tokenSourceMapRanges.slice(); | ||
} | ||
|
||
// `constantValue` overwrites the destination | ||
|
@@ -7483,9 +7480,7 @@ function mergeEmitNode(sourceEmitNode: EmitNode, destEmitNode: EmitNode | undefi | |
|
||
// `helpers` are merged into the destination | ||
if (helpers) { | ||
for (const helper of helpers) { | ||
destEmitNode.helpers = appendIfUnique(destEmitNode.helpers, helper); | ||
} | ||
destEmitNode.helpers = helpers.slice(); | ||
} | ||
|
||
// `startsOnNewLine` overwrites the destination | ||
|
@@ -7517,11 +7512,3 @@ function mergeEmitNode(sourceEmitNode: EmitNode, destEmitNode: EmitNode | undefi | |
|
||
return destEmitNode; | ||
} | ||
|
||
function mergeTokenSourceMapRanges(sourceRanges: (TextRange | undefined)[], destRanges: (TextRange | undefined)[]) { | ||
if (!destRanges) destRanges = []; | ||
for (const key in sourceRanges) { | ||
destRanges[key] = sourceRanges[key]; | ||
} | ||
return destRanges; | ||
} | ||
Comment on lines
-7521
to
-7527
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I read this function and it sort of scared me; what if the test has more elements than the source? Then I replaced it and nothing changed, so I kept going... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry this results in a different inconsistency now. Before, we would attempt to merge the emit information for the old node into anything set on the new node prior to calling
setOriginalNode
. Now we will conditionally overwrite some properties but not others.After this change we end up with
oldNode
's leading comments butnewNodes
trailing comments, which seems more confusing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I certainly am not confident in this PR, but we do need something for #59332.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally considered using
appendIfUnique
to avoid duplicating but also to concatenate. Would you think that's a good fix?