利用Babel传递承诺的最后一部分

时间:2019-05-16 22:29:00

标签: javascript babel es6-modules

我一直在尝试学习Babel并阅读文档(但我不得不说这非常混乱-进入的巨大障碍)。无论如何,我想问一个问题,我希望它可以工作,但没有。

这是finally的{​​{1}}子句的转换,可以转换this page状态。 (尽管我认为promises语句在浏览器中不会有帮助。)

我只是使用Babel CLI为浏览器(而不是Node)进行编译。

我的require是(相关位):

package.json

Babel配置为:

"devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.4",
    "@babel/preset-env": "^7.4.4"
},
    "dependencies": {
    "core-js": "^3.0.1"
}

我正在使用Bootstrap 4 const presets = [ [ '@babel/preset-env', { useBuiltIns: 'entry', debug: true, corejs: { version: '3.1' } } ] ]; module.exports = { presets };

.browserslistrc

我作为源代码开始的脚本是:

>= 1%
last 1 major version
not dead
Chrome >= 45
Firefox >= 38
Edge >= 12
Explorer >= 10
iOS >= 9
Safari >= 9
Android >= 4.4
Opera >= 30

这是Debug输出:

var promise1 = new Promise(function(resolve, reject) {
  setTimeout(function() {
    resolve('foo');
  }, 300);
});

promise1
  .then(function(value) {
    console.log(value);
    // expected output: "foo"
  })
  .finally(function() {
    console.log('done');
  });

输出是相同的,但是在顶部添加了dave@NOSTROMO MINGW64 /e/Code/Babel $ npm run build > Babel@1.0.0 build E:\Code\Babel > babel src -d lib @babel/preset-env: `DEBUG` option Using targets: { "android": "4.4", "chrome": "45", "edge": "12", "firefox": "38", "ie": "10", "ios": "9", "opera": "30", "safari": "9", "samsung": "8.2" } Using modules transform: auto Using plugins: transform-template-literals { "android":"4.4", "edge":"12", "ie":"10", "ios":"9", "safari":"9" } transform-literals { "android":"4.4", "firefox":"38", "ie":"10", "opera":"30" } transform-function-name { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-arrow-functions { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-block-scoped-functions { "android":"4.4", "firefox":"38", "ie":"10", "ios":"9", "safari":"9" } transform-classes { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-object-super { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-shorthand-properties { "android":"4.4", "ie":"10" } transform-duplicate-keys { "android":"4.4", "ie":"10" } transform-computed-properties { "android":"4.4", "ie":"10", "opera":"30" } transform-for-of { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-sticky-regex { "android":"4.4", "chrome":"45", "edge":"12", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-dotall-regex { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-unicode-regex { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-spread { "android":"4.4", "chrome":"45", "edge":"12", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-parameters { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-destructuring { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-block-scoping { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-typeof-symbol { "android":"4.4", "ie":"10" } transform-new-target { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-regenerator { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-exponentiation-operator { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } transform-async-to-generator { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } proposal-async-generator-functions { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } proposal-object-rest-spread { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9" } proposal-unicode-property-regex { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9", "samsung":"8.2" } proposal-json-strings { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9", "samsung":"8.2" } proposal-optional-catch-binding { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9", "samsung":"8.2" } transform-named-capturing-groups-regex { "android":"4.4", "chrome":"45", "edge":"12", "firefox":"38", "ie":"10", "ios":"9", "opera":"30", "safari":"9", "samsung":"8.2" } Using polyfills with `entry` option: [E:\Code\Babel\src\app.js] Import of core-js was not found. Successfully compiled 1 file with Babel.

如果使用不当,请通知我。
干杯

0 个答案:

没有答案