test/com/google/javascript/jscomp/Es6TranspilationIntegrationTest.java
/**
   * Getters and setters are supported, both in object literals and in classes, but only if the
   * output language is ES5.
   */
Getters and setters are supported, both in object literals and in classes, but only if the
output language is ES5.
Getters and setters are supported both in object literals and in classes but only if the output language is ES5 .
@Test
  public void testEs5GettersAndSettersClasses() {
    setLanguageOut(LanguageMode.ECMASCRIPT5);
    test(
        "class C { get value() { return 0; } }",
        lines(
            "/** @constructor @struct */",
            "var C = function() {};",
            "/** @type {?} */",
            "C.prototype.value;",
            "$jscomp.global.Object.defineProperties(C.prototype, {",
            "  value: {",
            "    configurable: true,",
            "    enumerable: true,",
            "    /** @this {C} */",
            "    get: function() {",
            "      return 0;",
            "    }",
            "  }",
            "});"));
    test(
        "class C { set value(val) { this.internalVal = val; } }",
        lines(
            "/** @constructor @struct */",
            "var C = function() {};",
            "/** @type {?} */",
            "C.prototype.value;",
            "$jscomp.global.Object.defineProperties(C.prototype, {",
            "  value: {",
            "    configurable: true,",
            "    enumerable: true,",
            "    /** @this {C} */",
            "    set: function(val) {",
            "      this.internalVal = val;",
            "    }",
            "  }",
            "});"));
    test(
        lines(
            "class C {",
            "  set value(val) {",
            "    this.internalVal = val;",
            "  }",
            "  get value() {",
            "    return this.internalVal;",
            "  }",
            "}"),
        lines(
            "/** @constructor @struct */",
            "var C = function() {};",
            "/** @type {?} */",
            "C.prototype.value;",
            "$jscomp.global.Object.defineProperties(C.prototype, {",
            "  value: {",
            "    configurable: true,",
            "    enumerable: true,",
            "    /** @this {C} */",
            "    set: function(val) {",
            "      this.internalVal = val;",
            "    },",
            "    /** @this {C} */",
            "    get: function() {",
            "      return this.internalVal;",
            "    }",
            "  }",
            "});"));
    test(
        lines(
            "class C {",
            "  get alwaysTwo() {",
            "    return 2;",
            "  }",
            "",
            "  get alwaysThree() {",
            "    return 3;",
            "  }",
            "}"),
        lines(
            "/** @constructor @struct */",
            "var C = function() {};",
            "/** @type {?} */",
            "C.prototype.alwaysTwo;",
            "/** @type {?} */",
            "C.prototype.alwaysThree;",
            "$jscomp.global.Object.defineProperties(C.prototype, {",
            "  alwaysTwo: {",
            "    configurable: true,",
            "    enumerable: true,",
            "    /** @this {C} */",
            "    get: function() {",
            "      return 2;",
            "    }",
            "  },",
            "  alwaysThree: {",
            "    configurable: true,",
            "    enumerable: true,",
            "    /** @this {C} */",
            "    get: function() {",
            "      return 3;",
            "    }",
            "  },",
            "});"));
  }
@ Test public void testEs5GettersAndSettersClasses ( ) { setLanguageOut ( LanguageMode . ECMASCRIPT5 ) ; test ( "class C { get value() { return 0; } }" , lines ( "/** @constructor @struct */" , "var C = function() {};" , "/** @type {?} */" , "C.prototype.value;" , "$jscomp.global.Object.defineProperties(C.prototype, {" , "  value: {" , "    configurable: true," , "    enumerable: true," , "    /** @this {C} */" , "    get: function() {" , "      return 0;" , "    }" , "  }" , "});" ) ) ; test ( "class C { set value(val) { this.internalVal = val; } }" , lines ( "/** @constructor @struct */" , "var C = function() {};" , "/** @type {?} */" , "C.prototype.value;" , "$jscomp.global.Object.defineProperties(C.prototype, {" , "  value: {" , "    configurable: true," , "    enumerable: true," , "    /** @this {C} */" , "    set: function(val) {" , "      this.internalVal = val;" , "    }" , "  }" , "});" ) ) ; test ( lines ( "class C {" , "  set value(val) {" , "    this.internalVal = val;" , "  }" , "  get value() {" , "    return this.internalVal;" , "  }" , "}" ) , lines ( "/** @constructor @struct */" , "var C = function() {};" , "/** @type {?} */" , "C.prototype.value;" , "$jscomp.global.Object.defineProperties(C.prototype, {" , "  value: {" , "    configurable: true," , "    enumerable: true," , "    /** @this {C} */" , "    set: function(val) {" , "      this.internalVal = val;" , "    }," , "    /** @this {C} */" , "    get: function() {" , "      return this.internalVal;" , "    }" , "  }" , "});" ) ) ; test ( lines ( "class C {" , "  get alwaysTwo() {" , "    return 2;" , "  }" , "" , "  get alwaysThree() {" , "    return 3;" , "  }" , "}" ) , lines ( "/** @constructor @struct */" , "var C = function() {};" , "/** @type {?} */" , "C.prototype.alwaysTwo;" , "/** @type {?} */" , "C.prototype.alwaysThree;" , "$jscomp.global.Object.defineProperties(C.prototype, {" , "  alwaysTwo: {" , "    configurable: true," , "    enumerable: true," , "    /** @this {C} */" , "    get: function() {" , "      return 2;" , "    }" , "  }," , "  alwaysThree: {" , "    configurable: true," , "    enumerable: true," , "    /** @this {C} */" , "    get: function() {" , "      return 3;" , "    }" , "  }," , "});" ) ) ; }
Getters and setters are supported, both in object literals and in classes, but only if the
 output language is ES5.
Getters and setters are supported both in object literals and in classes but only if the output language is ES5 .