简体   繁体   中英

Sencha Cmd, C2001 closure compiler error: extending native class: Array

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 () { }

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);

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" } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM