Closure-compiler: Object literal getters/setters

Created on 20 Mar 2016  路  3Comments  路  Source: google/closure-compiler

This code

function Test() {}

Test.prototype = {
  get test() {

  },

  set test(val) {

  }
};

Produces this errors on https://closure-compiler.appspot.com/

Number of errors: 2

JSC_CANNOT_CONVERT: This code cannot be converted from ES6. ES5 getters/setters (consider using --language_out=ES5) at line 4 character 6
  get test() {
      ^
JSC_CANNOT_CONVERT: This code cannot be converted from ES6. ES5 getters/setters (consider using --language_out=ES5) at line 8 character 6
  set test(val) {
      ^

This is part of ES5 and following specs (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) and is implemented by engines for a while.

So why it produces errors?

Most helpful comment

It is ->
// @language ECMASCRIPT5

All 3 comments

Like the compiler itself, the web service defaults language_out to ES3, try adding:

// @language_out ecmascript5

To the beginning of the file.

I think it's

// @language_out ES5

It is ->
// @language ECMASCRIPT5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChadKillingsworth picture ChadKillingsworth  路  7Comments

cramforce picture cramforce  路  5Comments

jart picture jart  路  7Comments

ChadKillingsworth picture ChadKillingsworth  路  5Comments

zzo picture zzo  路  6Comments