Skip to content

Commit d34529b

Browse files
Closure Teamcopybara-github
authored andcommitted
Implemented detached check to i.js for public fields.
There are test cases where we do not want to call `simplify()` for public fields given that they are detached. When we are in `processDeclaration()`, we will now check if the declaration is detached and break out of the method so we do not call `simplify`. Unit tests have been added to show public field support. PiperOrigin-RevId: 551272612
1 parent 833f465 commit d34529b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ private static String rootName(String qualifiedName) {
534534
}
535535

536536
private boolean shouldRemove(String name, PotentialDeclaration decl) {
537+
if (decl.isDetached()) {
538+
return true;
539+
}
537540
if (rootName(name).startsWith("$jscomp")) {
538-
if (decl.isDetached()) {
539-
return true;
540-
}
541541
// These are created by goog.scope processing, but clash with each other
542542
// and should not be depended on.
543543
if ((decl.getRhs() != null && decl.getRhs().isClass())

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ public void testComputedFieldNoRHS() {
8787
"}"));
8888
}
8989

90+
@Test
91+
public void testDoubleAssignmentField() {
92+
test(
93+
lines(
94+
"let Snackbar = Snackbar1 = class Snackbar {", //
95+
" x = 5",
96+
"}"),
97+
"/** @const @type {UnusableType} */ var Snackbar;");
98+
}
99+
100+
@Test
101+
public void testDoubleAssignmentStaticField() {
102+
test(
103+
lines(
104+
"let A = B = class C {", //
105+
" static y = true",
106+
"}"),
107+
"/** @const @type {UnusableType} */ var A;");
108+
}
109+
90110
@Test
91111
public void testSuperClassFields() {
92112
test(

0 commit comments

Comments
 (0)