Skip to content

Commit

Permalink
Print the shadow node content instead of the shadow node host.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 698213559
  • Loading branch information
12wrigja authored and copybara-github committed Nov 20, 2024
1 parent e507d71 commit 93f8c26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/com/google/javascript/jscomp/CodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ protected void add(Node node, Context context, boolean printComments) {
if (!cc.continueProcessing()) {
return;
}
// If this node is actually a shadow host node, then print the shadow content instead.
Node shadow = node.getClosureUnawareShadow();
if (shadow != null) {
add(shadow.getFirstFirstChild().getFirstChild(), context, printComments);
return;
}
if (printComments) {
printLeadingCommentsInOrder(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ public void process(Node externs, Node root) {
Node expectedShadowContent =
this.parseExpectedJs(lines("(function() {", " window['foo'] = 5;", "})"));
assertNode(shadowedContent).isEqualIncludingJsDocTo(expectedShadowContent);

assertThat(result.compiler.toSource(result.sourceRoot))
.isEqualTo("(function(){window[\"foo\"]=5})()");
}

@Test
Expand Down

0 comments on commit 93f8c26

Please sign in to comment.