1

When running Sencha Cmd v6.5.3.6, i get the following error message:

[ERR] C2001: Closure Compiler Error (This code cannot be converted from ES6. extending native class: Array) -- compression-input:111263

The error is caused by this code:

class Chains extends Array {
}

The error still occurs with methods inside class declaration.

Is there a way to make this code compiled by Sencha Cmd ?

UPDATED : To solve the problem, I change the code to:

function Chains() { };
Chains.prototype = new Array;
Chains.prototype.anyMethod = function () { }

Guillaume
  • 162
  • 3
  • 11

2 Answers2

1

I don't think ExtJS supports that syntax as of now. For the time being, you might have to go with their syntax:

Ext.define('Chains', {
    extend: 'Array'
});

Then in your code you can call it like this:

var chns = Ext.create('Chains');
chns.push('a');
console.log(chns);
Martin
  • 475
  • 4
  • 14
  • It compile now without error, but the Chains is no more an array. It is no more possible to call the "push" method on a Chains object, which is the behavior I need. – Guillaume May 25 '18 at 14:46
  • My bad, I was using "extends" instead of "extend". It works fine now. Thank you. – Guillaume May 26 '18 at 06:20
  • Sencha cmd display now this error message :"[ERR] Failed to resolve dependency Array for file Link.Chains [ERR] Unknown definition for dependency : Array" – Guillaume May 26 '18 at 16:10
  • So i'm going to use an array extension, involving prototype, and with a new class name, as described here : https://stackoverflow.com/questions/11337849/ways-to-extend-array-object-in-javascript But not the solution involving ES6 language version, no: class a extends b { } – Guillaume May 26 '18 at 16:20
1

You are using a feature of ES6 that cannot be transpiled into pre-ES6 code.

Sencha Cmd by default transpiles your code into pre-ES6 code because IE11 support has not yet been dropped.

You can disable code transpilation starting with Sencha Cmd 6.5.0 as described in the official docs:

There are cases where you won't need all that transpiling. Maybe you’re targeting Electron or you only support modern browsers that have all these features. You can disable the transpiler and still use the Sencha Cmd code compressor against your native ES6 code. Just a tweak to the app.json file and say goodbye to the transpiler and its polyfills:

"output": {
    "js": {
        "version": "ES6"
    }
}
Alexander
  • 19,906
  • 19
  • 75
  • 162