I have an error with transplied class:
Uncaught TypeError: Failed to construct 'FormData': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
at Form.ExtendableBuiltin (http://local.yandex.ru:30002/bundle.js:79395:14)
at new Form (http://local.yandex.ru:30002/bundle.js:79422:103)
My .babelrc:
{
"presets": ["react", "latest"],
"plugins": [
"babel-plugin-syntax-decorators",
"babel-plugin-transform-decorators-legacy",
["babel-plugin-transform-builtin-extend", { // Class Extending Natives
globals: ["FormData"],
approximate: true
}],
"transform-es2015-arrow-functions",
// "syntax-async-functions",
// "transform-async-to-generator",
// "transform-regenerator",
"transform-object-rest-spread",
"transform-rebem-jsx",
"transform-es2015-typeof-symbol"
],
}
My class:
import map from 'lodash/map'
export default class Form extends FormData {
constructor (data) {
super()
map(data, (val, key) => this.append(key, val))
}
}
A piece of transpiled code:
function _extendableBuiltin(cls) {
function ExtendableBuiltin() {
cls.apply(this, arguments);
}
Where cls
is FormData
.
Expected something like this:
function _extendableBuiltin(cls) {
return function ExtendableBuiltin() {
return new cls(arguments);
}
babel --version 6.14.0 (babel-core 6.14.0)
webpack --version Version: webpack 1.13.2
What am I doing wrong?