1
0
mirror of https://github.com/actions/labeler synced 2026-05-10 19:01:02 +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

@@ -10,41 +10,19 @@ exports._replaceWith = _replaceWith;
exports.replaceExpressionWithStatements = replaceExpressionWithStatements;
exports.replaceInline = replaceInline;
function _codeFrame() {
const data = require("@babel/code-frame");
_codeFrame = function () {
return data;
};
return data;
}
var _codeFrame = require("@babel/code-frame");
var _index = _interopRequireDefault(require("../index"));
var _index2 = _interopRequireDefault(require("./index"));
function _parser() {
const data = require("@babel/parser");
var _parser = require("@babel/parser");
_parser = function () {
return data;
};
var t = _interopRequireWildcard(require("@babel/types"));
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function t() {
const data = _interopRequireWildcard(require("@babel/types"));
t = function () {
return data;
};
return data;
}
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 _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 }; }
@@ -67,7 +45,7 @@ const hoistVariablesVisitor = {
for (const declar of path.node.declarations) {
if (declar.init) {
exprs.push(t().expressionStatement(t().assignmentExpression("=", declar.id, declar.init)));
exprs.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init)));
}
}
@@ -79,8 +57,8 @@ const hoistVariablesVisitor = {
function replaceWithMultiple(nodes) {
this.resync();
nodes = this._verifyNodeList(nodes);
t().inheritLeadingComments(nodes[0], this.node);
t().inheritTrailingComments(nodes[nodes.length - 1], this.node);
t.inheritLeadingComments(nodes[0], this.node);
t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
this.node = this.container[this.key] = null;
const paths = this.insertAfter(nodes);
@@ -98,12 +76,12 @@ function replaceWithSourceString(replacement) {
try {
replacement = `(${replacement})`;
replacement = (0, _parser().parse)(replacement);
replacement = (0, _parser.parse)(replacement);
} catch (err) {
const loc = err.loc;
if (loc) {
err.message += " - make sure this is an expression.\n" + (0, _codeFrame().codeFrameColumns)(replacement, {
err.message += " - make sure this is an expression.\n" + (0, _codeFrame.codeFrameColumns)(replacement, {
start: {
line: loc.line,
column: loc.column + 1
@@ -141,7 +119,7 @@ function replaceWith(replacement) {
return [this];
}
if (this.isProgram() && !t().isProgram(replacement)) {
if (this.isProgram() && !t.isProgram(replacement)) {
throw new Error("You can only replace a Program root node with another Program node");
}
@@ -155,14 +133,14 @@ function replaceWith(replacement) {
let nodePath = "";
if (this.isNodeType("Statement") && t().isExpression(replacement)) {
if (this.isNodeType("Statement") && t.isExpression(replacement)) {
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
replacement = t().expressionStatement(replacement);
replacement = t.expressionStatement(replacement);
nodePath = "expression";
}
}
if (this.isNodeType("Expression") && t().isStatement(replacement)) {
if (this.isNodeType("Expression") && t.isStatement(replacement)) {
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
return this.replaceExpressionWithStatements([replacement]);
}
@@ -171,8 +149,8 @@ function replaceWith(replacement) {
const oldNode = this.node;
if (oldNode) {
t().inheritsComments(replacement, oldNode);
t().removeComments(oldNode);
t.inheritsComments(replacement, oldNode);
t.removeComments(oldNode);
}
this._replaceWith(replacement);
@@ -189,27 +167,27 @@ function _replaceWith(node) {
}
if (this.inList) {
t().validate(this.parent, this.key, [node]);
t.validate(this.parent, this.key, [node]);
} else {
t().validate(this.parent, this.key, node);
t.validate(this.parent, this.key, node);
}
this.debug(`Replace with ${node && node.type}`);
this.debug(`Replace with ${node == null ? void 0 : node.type}`);
this.node = this.container[this.key] = node;
}
function replaceExpressionWithStatements(nodes) {
this.resync();
const toSequenceExpression = t().toSequenceExpression(nodes, this.scope);
const toSequenceExpression = t.toSequenceExpression(nodes, this.scope);
if (toSequenceExpression) {
return this.replaceWith(toSequenceExpression)[0].get("expressions");
}
const functionParent = this.getFunctionParent();
const isParentAsync = functionParent && functionParent.is("async");
const container = t().arrowFunctionExpression([], t().blockStatement(nodes));
this.replaceWith(t().callExpression(container, []));
const isParentAsync = functionParent == null ? void 0 : functionParent.is("async");
const container = t.arrowFunctionExpression([], t.blockStatement(nodes));
this.replaceWith(t.callExpression(container, []));
this.traverse(hoistVariablesVisitor);
const completionRecords = this.get("callee").getCompletionRecords();
@@ -223,24 +201,24 @@ function replaceExpressionWithStatements(nodes) {
if (!uid) {
const callee = this.get("callee");
uid = callee.scope.generateDeclaredUidIdentifier("ret");
callee.get("body").pushContainer("body", t().returnStatement(t().cloneNode(uid)));
callee.get("body").pushContainer("body", t.returnStatement(t.cloneNode(uid)));
loop.setData("expressionReplacementReturnUid", uid);
} else {
uid = t().identifier(uid.name);
uid = t.identifier(uid.name);
}
path.get("expression").replaceWith(t().assignmentExpression("=", t().cloneNode(uid), path.node.expression));
path.get("expression").replaceWith(t.assignmentExpression("=", t.cloneNode(uid), path.node.expression));
} else {
path.replaceWith(t().returnStatement(path.node.expression));
path.replaceWith(t.returnStatement(path.node.expression));
}
}
const callee = this.get("callee");
callee.arrowFunctionToExpression();
if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t().FUNCTION_TYPES)) {
if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t.FUNCTION_TYPES)) {
callee.set("async", true);
this.replaceWith(t().awaitExpression(this.node));
this.replaceWith(t.awaitExpression(this.node));
}
return callee.get("body.body");