Skip to content

Commit ef5d729

Browse files
lauraharkercopybara-github
authored andcommitted
Add test case showing JSCompiler transpilation of class inheritance within a local scope
We could optionally simplify the output by detecting that C's constructor does not return a value, and producing: let D = function() { C.apply(this, arguments); } Today this detection only works on globals/module exports, not function local classes. This probably doesn't matter for normal code, but @closureUnaware code is always wrapped in a function. PiperOrigin-RevId: 846298004
1 parent aae006c commit ef5d729

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/com/google/javascript/jscomp/Es6RewriteClassTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,30 @@ class C extends D { constructor(word) { super(word); } }
693693
""");
694694
}
695695

696+
@Test
697+
public void testExtends_nonGlobalClass() {
698+
test(
699+
srcs(
700+
"""
701+
function f() {
702+
class C {}
703+
class D extends C {}
704+
}
705+
"""),
706+
expected(
707+
"""
708+
function f() {
709+
/** @constructor */
710+
let C = function() {};
711+
/** @constructor */
712+
let D = function() {
713+
return C.apply(this, arguments) || this;
714+
};
715+
$jscomp.inherits(D, C);
716+
}
717+
"""));
718+
}
719+
696720
@Test
697721
public void testExtendsExternsClass() {
698722
test(

0 commit comments

Comments
 (0)