diff --git a/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java b/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java index 8207338caf1..31c53d9e3a3 100644 --- a/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java +++ b/test/com/google/javascript/jscomp/ConcretizeStaticInheritanceForInliningTest.java @@ -625,4 +625,37 @@ public void testAddSingletonGetter() { "$jscomp.inherits(Subclass, Example);", "goog.addSingletonGetter(Subclass);")); } + + @Test + public void testNonQnameConstructor_doesntPolluteListOfAssignments() { + // Reproduce a pretty bad bug caused by accidentally reading/writing 'null' keys from a map. + test( + lines( + "const ns = {};", + "/** @constructor */", + "ns['NOT_A_NAME'] = function() {};", + "ns['NOT_A_NAME'].staticMethod = function() { alert(1); }", + "", + "/** @constructor */", + "const Example = function() {}", + "", + "/** @constructor @extends {Example} */", + "function Subclass() {}", + "$jscomp.inherits(Subclass, Example);"), + lines( + "const ns = {};", + "/** @constructor */", + "ns['NOT_A_NAME'] = function() {};", + "ns['NOT_A_NAME'].staticMethod = function() { alert(1); }", + "", + "/** @constructor */", + "const Example = function() {}", + "", + "/** @constructor @extends {Example} */", + "function Subclass() {}", + "$jscomp.inherits(Subclass, Example);", + // TODO(b/293320792) - stop producing this assignment, there's no + // actual Example.staticMethod. + "Subclass.staticMethod = Example.staticMethod;")); + } }