Skip to content

Commit

Permalink
add super getter / setter unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
brad4d committed Jun 8, 2017
1 parent bfb9f14 commit c7c09dd
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/com/google/javascript/jscomp/Es6ToEs3ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,62 @@ public void testSuperGet() {
"};"));
}

public void testSuperAccessToGettersAndSetters() {
// Getters cannot be transpiled to ES3
setLanguageOut(LanguageMode.ECMASCRIPT5);
test(
LINE_JOINER.join(
"class Base {",
" get g() { return 'base'; }",
" set g(v) { alert('base.prototype.g = ' + v); }",
"}",
"class Sub extends Base {",
" get g() { return super.g + '-sub'; }",
" set g(v) { super.g = v + '-sub'; }",
"}"),
LINE_JOINER.join(
"/** @constructor @struct */",
"var Base = function() {};",
"/** @type {?} */",
"Base.prototype.g;",
"$jscomp.global.Object.defineProperties(",
" Base.prototype,",
" {",
" g:{",
" configurable:true,",
" enumerable:true,",
" /** @this {Base} */",
" get:function(){return\"base\"},",
" /** @this {Base} */",
" set:function(v){alert(\"base.prototype.g = \" + v);}",
" }",
" });",
"/**",
" * @constructor @struct",
" * @extends {Base}",
" * @param {...?} var_args",
" */",
"var Sub = function(var_args) {",
" Base.apply(this, arguments);",
"};",
"/** @type {?} */",
"Sub.prototype.g;",
"$jscomp.inherits(Sub, Base);",
"$jscomp.global.Object.defineProperties(",
" Sub.prototype,",
" {",
" g:{",
" configurable:true,",
" enumerable:true,",
" /** @this {Sub} */",
" get:function(){return Base.prototype.g + \"-sub\";},",
" /** @this {Sub} */",
" set:function(v){Base.prototype.g = v + \"-sub\";}",
" }",
" });",
""));
}

public void testSuperNew() {
testError("class D {} class C extends D { f() {var s = new super;} }", INVALID_SUPER_CALL);
testError(
Expand Down

0 comments on commit c7c09dd

Please sign in to comment.