Использование Вавилона, чтобы Прозрачно завершить часть обещаний - PullRequest
3 голосов
/ 17 мая 2019

Я пытался выучить Бабель и читать документы (но я должен сказать, что это очень запутанно - большой барьер для входа).Во всяком случае, я хотел задать вопрос о том, что я ожидал работать, но не сделал.

Это преобразование предложения finally в promises, которое состояния этой страницы могут быть переданы.(Хотя я не думаю, что оператор require был бы полезен в браузере).

Я просто переношу браузер (не Node), используя Babel CLI.

My package.json (соответствующие биты):

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

Конфигурация Babel:

const presets = [
  [
    '@babel/preset-env',
    {
      useBuiltIns: 'entry',
      debug: true,
      corejs: { version: '3.1' }
    }
  ]
];

module.exports = { presets };

Я использую Bootstrap 4 .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

Сценарий, с которого я начинаю как источник:

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.

Вывод идентичен, но для"use strict"; добавлено вверху.

Пожалуйста, дайте мне знать, если я не использую его должным образом.
Приветствия

...