1
0
mirror of https://github.com/actions/labeler synced 2026-05-11 23:51:14 +02:00
This commit is contained in:
David Kale
2020-09-08 13:25:36 -04:00
parent e4246d2b5b
commit 91fcbb0108
4227 changed files with 416837 additions and 457884 deletions

View File

@@ -9,29 +9,15 @@ exports.getDependencies = getDependencies;
exports.ensure = ensure;
exports.default = exports.list = void 0;
function _traverse() {
const data = _interopRequireDefault(require("@babel/traverse"));
var _traverse = _interopRequireDefault(require("@babel/traverse"));
_traverse = function () {
return data;
};
return data;
}
function t() {
const data = _interopRequireWildcard(require("@babel/types"));
t = function () {
return data;
};
return data;
}
var t = _interopRequireWildcard(require("@babel/types"));
var _helpers = _interopRequireDefault(require("./helpers"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -46,6 +32,8 @@ function makePath(path) {
return parts.reverse().join(".");
}
let fileClass = undefined;
function getHelperMetadata(file) {
const globals = new Set();
const localBindingNames = new Set();
@@ -55,7 +43,7 @@ function getHelperMetadata(file) {
const exportBindingAssignments = [];
const importPaths = [];
const importBindingsReferences = [];
(0, _traverse().default)(file, {
const dependencyVisitor = {
ImportDeclaration(child) {
const name = child.node.source.value;
@@ -99,8 +87,8 @@ function getHelperMetadata(file) {
child.skip();
}
});
(0, _traverse().default)(file, {
};
const referenceVisitor = {
Program(path) {
const bindings = path.scope.getAllBindings();
Object.keys(bindings).forEach(name => {
@@ -131,12 +119,14 @@ function getHelperMetadata(file) {
const binding = child.scope.getBinding(exportName);
if (binding && binding.scope.path.isProgram()) {
if (binding == null ? void 0 : binding.scope.path.isProgram()) {
exportBindingAssignments.push(makePath(child));
}
}
});
};
(0, _traverse.default)(file.ast, dependencyVisitor, file.scope);
(0, _traverse.default)(file.ast, referenceVisitor, file.scope);
if (!exportPath) throw new Error("Helpers must default-export something.");
exportBindingAssignments.reverse();
return {
@@ -184,7 +174,7 @@ function permuteHelperAST(file, metadata, id, localBindings, getDependency) {
toRename[exportName] = id.name;
}
(0, _traverse().default)(file, {
const visitor = {
Program(path) {
const exp = path.get(exportPath);
const imps = importPaths.map(p => path.get(p));
@@ -195,18 +185,18 @@ function permuteHelperAST(file, metadata, id, localBindings, getDependency) {
if (decl.isFunctionDeclaration()) {
exp.replaceWith(decl);
} else {
exp.replaceWith(t().variableDeclaration("var", [t().variableDeclarator(id, decl.node)]));
exp.replaceWith(t.variableDeclaration("var", [t.variableDeclarator(id, decl.node)]));
}
} else if (id.type === "MemberExpression") {
if (decl.isFunctionDeclaration()) {
exportBindingAssignments.forEach(assignPath => {
const assign = path.get(assignPath);
assign.replaceWith(t().assignmentExpression("=", id, assign.node));
assign.replaceWith(t.assignmentExpression("=", id, assign.node));
});
exp.replaceWith(decl);
path.pushContainer("body", t().expressionStatement(t().assignmentExpression("=", id, t().identifier(exportName))));
path.pushContainer("body", t.expressionStatement(t.assignmentExpression("=", id, t.identifier(exportName))));
} else {
exp.replaceWith(t().expressionStatement(t().assignmentExpression("=", id, decl.node)));
exp.replaceWith(t.expressionStatement(t.assignmentExpression("=", id, decl.node)));
}
} else {
throw new Error("Unexpected helper format.");
@@ -219,14 +209,15 @@ function permuteHelperAST(file, metadata, id, localBindings, getDependency) {
for (const path of imps) path.remove();
for (const path of impsBindingRefs) {
const node = t().cloneNode(dependenciesRefs[path.node.name]);
const node = t.cloneNode(dependenciesRefs[path.node.name]);
path.replaceWith(node);
}
path.stop();
}
});
};
(0, _traverse.default)(file.ast, visitor, file.scope);
}
const helperData = Object.create(null);
@@ -243,7 +234,17 @@ function loadHelper(name) {
}
const fn = () => {
return t().file(helper.ast());
const file = {
ast: t.file(helper.ast())
};
if (fileClass) {
return new fileClass({
filename: `babel-helper://${name}`
}, file);
}
return file;
};
const metadata = getHelperMetadata(fn());
@@ -252,7 +253,7 @@ function loadHelper(name) {
const file = fn();
permuteHelperAST(file, metadata, id, localBindings, getDependency);
return {
nodes: file.program.body,
nodes: file.ast.program.body,
globals: metadata.globals
};
},
@@ -280,7 +281,11 @@ function getDependencies(name) {
return Array.from(loadHelper(name).dependencies.values());
}
function ensure(name) {
function ensure(name, newFileClass) {
if (!fileClass) {
fileClass = newFileClass;
}
loadHelper(name);
}