Improve code quality and write tests

This commit is contained in:
Shivam Mathur
2019-09-20 08:11:20 +05:30
parent db44db4b97
commit 43178a7254
3597 changed files with 255478 additions and 785554 deletions

View File

@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _utils = require("../../utils");
function isRegeneratorSource(source) {
return source === "regenerator-runtime/runtime";
}
function _default() {
const visitor = {
ImportDeclaration(path) {
if (isRegeneratorSource((0, _utils.getImportSource)(path))) {
this.regeneratorImportExcluded = true;
path.remove();
}
},
Program(path) {
path.get("body").forEach(bodyPath => {
if (isRegeneratorSource((0, _utils.getRequireSource)(bodyPath))) {
this.regeneratorImportExcluded = true;
bodyPath.remove();
}
});
}
};
return {
name: "regenerator-entry",
visitor,
pre() {
this.regeneratorImportExcluded = false;
},
post() {
if (this.opts.debug && this.regeneratorImportExcluded) {
console.log(`\n[${this.file.opts.filename}] Based on your targets, regenerator-runtime import excluded.`);
}
}
};
}

View File

@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _utils = require("../../utils");
function _default() {
return {
name: "regenerator-usage",
pre() {
this.usesRegenerator = false;
},
visitor: {
Function(path) {
const {
node
} = path;
if (!this.usesRegenerator && (node.generator || node.async)) {
this.usesRegenerator = true;
(0, _utils.createImport)(path, "regenerator-runtime");
}
}
},
post() {
if (this.opts.debug && this.usesRegenerator) {
console.log(`\n[${this.file.opts.filename}] Based on your code and targets, added regenerator-runtime.`);
}
}
};
}