Я пытаюсь выяснить, почему я получаю сообщение об ошибке в моем коде в старых браузерах:
var the_dates = new Array();
Array.prototype.map.call(instance.days.children, i => {
the_dates.push(makeDateInFormatUK(i.dateObj));
});
Я получаю:
Uncaught SyntaxError: Неожиданный токен=>
Я использую Babel для дополнительной обработки кода для не-ES6 совместимых устройств, но по какой-то причине он не выполняет свою магию:
https://babeljs.io/docs/en/babel-plugin-transform-es2015-arrow-functions
Мой .babelrc
выглядит так:
{
"plugins": [
[
"transform-es2015-template-literals", {
"loose": true,
"retainLines": true
},
"transform-es2015-arrow-functions"
]
]
}
Я запускаю с:
babel /home/chambres/web/x.org/public_html/2018/js/lib/resa-booking.js > /home/chambres/web/x.org/public_html/2018/js/lib-non-es6/resa-booking.js
Нет ошибок,но когда я смотрю на выведенный файл, я все равно получаю:
var the_dates = new Array();
Array.prototype.map.call(instance.days.children, i => {
the_dates.push(makeDateInFormatUK(i.dateObj));
});
ОБНОВЛЕНИЕ: В качестве теста я создал файл test.js , с:
var a = () => {};
var bla = 1213;
var test = `foo bar ${bla}`;
Мой файл .bablerc имеет:
{
"plugins": ["@babel/plugin-transform-arrow-functions"]
}
Запустив его, я получаю:
babel /home/chambres/web/x.org/public_html/2018/js/lib/test.js
var a = () => {};
var bla = 1213;
var test = "foo bar " + bla;
Это почти как если бы он просто игнорировал .bablrc файл.Если я запускаю его со следующим:
babel --plugins @babel/plugin-transform-arrow-functions /home/chambres/web/x.org/public_html/2018/js/lib/test.js
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at /usr/local/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:178:20
at Array.map (native)
at Function.normalisePlugins (/usr/local/lib/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
Что я делаю не так?