Skip to content

Commit 7f8af46

Browse files
12wrigjacopybara-github
authored andcommitted
Avoid emitting @closureUnaware JSDoc annotations when generating typed interface summary files, as typed summary files are effectively closure-aware generated code.
PiperOrigin-RevId: 715439401
1 parent 0b44714 commit 7f8af46

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/com/google/javascript/jscomp/ijs/ConvertToTypedInterface.java

+11
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ private void processFile(Node scriptNode) {
133133
scriptNode.detach();
134134
return;
135135
}
136+
137+
JSDocInfo scriptJsDoc = scriptNode.getJSDocInfo();
138+
if (scriptJsDoc != null && scriptJsDoc.isClosureUnawareCode()) {
139+
// If we are generating type summary files, then those files won't contain the method content
140+
// from within the closure-unaware section, and the entire file effectively becomes
141+
// closure-aware again (as it is generated code that describes a module shape).
142+
JSDocInfo.Builder scriptJsDocBuilder = scriptJsDoc.toBuilder();
143+
var unused = scriptJsDocBuilder.removeClosureUnawareCode();
144+
scriptNode.setJSDocInfo(scriptJsDocBuilder.build());
145+
}
146+
136147
FileInfo currentFile = new FileInfo();
137148
NodeTraversal.traverse(compiler, scriptNode, new RemoveNonDeclarations());
138149
NodeTraversal.traverse(compiler, scriptNode, new PropagateConstJsdoc(currentFile));

src/com/google/javascript/rhino/JSDocInfo.java

+9
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,15 @@ public boolean recordClosureUnawareCode() {
27182718
return populateBit(Bit.CLOSURE_UNAWARE_CODE, true);
27192719
}
27202720

2721+
/**
2722+
* Removes the {@code @closureUnaware} annotation from this JSDoc, returning true the annotation
2723+
* was present before removal.
2724+
*/
2725+
@CanIgnoreReturnValue
2726+
public boolean removeClosureUnawareCode() {
2727+
return populateBit(Bit.CLOSURE_UNAWARE_CODE, false);
2728+
}
2729+
27212730
/** Records that this JSDoc was annotated with the {@code @usedViaDotConstructor} annotation. */
27222731
public boolean recordUsedViaDotConstructor() {
27232732
return populateBit(Bit.USED_VIA_DOT_CONSTRUCTOR, true);

test/com/google/javascript/jscomp/ijs/ConvertToTypedInterfaceTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -2433,4 +2433,15 @@ public void testGoogModuleGet() {
24332433
"a.b.c.d = goog.module.get('x.y.z').d;",
24342434
""));
24352435
}
2436+
2437+
@Test
2438+
public void testRemovesClosureUnawareCodeAnnotationIfPresent() {
2439+
test(
2440+
lines("/** @fileoverview @closureUnaware */", "goog.module('a.b.c');", "exports.foo = 10;"),
2441+
lines(
2442+
"/**@fileoverview */",
2443+
"goog.module('a.b.c');",
2444+
"/** @const @type {number} */",
2445+
"exports.foo;"));
2446+
}
24362447
}

0 commit comments

Comments
 (0)