同一段“导入模块”的代码,截然不同的处理
Bug重现代码:
void function () {
isSupportedRange('http://static.com/1GB.bin').then(bool => {
// ...
});
}();
import * as http from 'http';
import * as https from 'https';
import { URL } from 'url';
function isSupportedRange(url: URL | string): Promise<boolean> {
// use imported module: http, https, and URL
}
Wepback:
/* harmony import */ var http__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
/* harmony import */ var http__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(http__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var https__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
/* harmony import */ var https__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(https__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
/* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(url__WEBPACK_IMPORTED_MODULE_2__);
void function () {
isSupportedRange('http://baidu.com').then(function (bool) {
// ...
});
}();
// Removed
function isSupportedRange(url) {
// No problem!
}
tsc:
"use strict";
exports.__esModule = true;
void function () {
isSupportedRange('http://baidu.com').then(function (bool) {
// ...
});
}();
var http = require("http");
var https = require("https");
var url_1 = require("url");
function isSupportedRange(url) {
// Oops! http, https, and URL is undefined!
}