mirror of
https://github.com/cachix/install-nix-action.git
synced 2025-06-09 02:14:28 +00:00
v7
This commit is contained in:
parent
033d472283
commit
49df04613e
6774 changed files with 1602535 additions and 1 deletions
134
node_modules/@babel/traverse/lib/path/inference/index.js
generated
vendored
Normal file
134
node_modules/@babel/traverse/lib/path/inference/index.js
generated
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getTypeAnnotation = getTypeAnnotation;
|
||||
exports._getTypeAnnotation = _getTypeAnnotation;
|
||||
exports.isBaseType = isBaseType;
|
||||
exports.couldBeBaseType = couldBeBaseType;
|
||||
exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
|
||||
exports.isGenericType = isGenericType;
|
||||
|
||||
var inferers = _interopRequireWildcard(require("./inferers"));
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 getTypeAnnotation() {
|
||||
if (this.typeAnnotation) return this.typeAnnotation;
|
||||
let type = this._getTypeAnnotation() || t().anyTypeAnnotation();
|
||||
if (t().isTypeAnnotation(type)) type = type.typeAnnotation;
|
||||
return this.typeAnnotation = type;
|
||||
}
|
||||
|
||||
function _getTypeAnnotation() {
|
||||
const node = this.node;
|
||||
|
||||
if (!node) {
|
||||
if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
|
||||
const declar = this.parentPath.parentPath;
|
||||
const declarParent = declar.parentPath;
|
||||
|
||||
if (declar.key === "left" && declarParent.isForInStatement()) {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
if (declar.key === "left" && declarParent.isForOfStatement()) {
|
||||
return t().anyTypeAnnotation();
|
||||
}
|
||||
|
||||
return t().voidTypeAnnotation();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.typeAnnotation) {
|
||||
return node.typeAnnotation;
|
||||
}
|
||||
|
||||
let inferer = inferers[node.type];
|
||||
|
||||
if (inferer) {
|
||||
return inferer.call(this, node);
|
||||
}
|
||||
|
||||
inferer = inferers[this.parentPath.type];
|
||||
|
||||
if (inferer && inferer.validParent) {
|
||||
return this.parentPath.getTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function isBaseType(baseName, soft) {
|
||||
return _isBaseType(baseName, this.getTypeAnnotation(), soft);
|
||||
}
|
||||
|
||||
function _isBaseType(baseName, type, soft) {
|
||||
if (baseName === "string") {
|
||||
return t().isStringTypeAnnotation(type);
|
||||
} else if (baseName === "number") {
|
||||
return t().isNumberTypeAnnotation(type);
|
||||
} else if (baseName === "boolean") {
|
||||
return t().isBooleanTypeAnnotation(type);
|
||||
} else if (baseName === "any") {
|
||||
return t().isAnyTypeAnnotation(type);
|
||||
} else if (baseName === "mixed") {
|
||||
return t().isMixedTypeAnnotation(type);
|
||||
} else if (baseName === "empty") {
|
||||
return t().isEmptyTypeAnnotation(type);
|
||||
} else if (baseName === "void") {
|
||||
return t().isVoidTypeAnnotation(type);
|
||||
} else {
|
||||
if (soft) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Error(`Unknown base type ${baseName}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function couldBeBaseType(name) {
|
||||
const type = this.getTypeAnnotation();
|
||||
if (t().isAnyTypeAnnotation(type)) return true;
|
||||
|
||||
if (t().isUnionTypeAnnotation(type)) {
|
||||
for (const type2 of type.types) {
|
||||
if (t().isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return _isBaseType(name, type, true);
|
||||
}
|
||||
}
|
||||
|
||||
function baseTypeStrictlyMatches(right) {
|
||||
const left = this.getTypeAnnotation();
|
||||
right = right.getTypeAnnotation();
|
||||
|
||||
if (!t().isAnyTypeAnnotation(left) && t().isFlowBaseAnnotation(left)) {
|
||||
return right.type === left.type;
|
||||
}
|
||||
}
|
||||
|
||||
function isGenericType(genericName) {
|
||||
const type = this.getTypeAnnotation();
|
||||
return t().isGenericTypeAnnotation(type) && t().isIdentifier(type.id, {
|
||||
name: genericName
|
||||
});
|
||||
}
|
183
node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
Normal file
183
node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
Normal file
|
@ -0,0 +1,183 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 _default(node) {
|
||||
if (!this.isReferenced()) return;
|
||||
const binding = this.scope.getBinding(node.name);
|
||||
|
||||
if (binding) {
|
||||
if (binding.identifier.typeAnnotation) {
|
||||
return binding.identifier.typeAnnotation;
|
||||
} else {
|
||||
return getTypeAnnotationBindingConstantViolations(binding, this, node.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.name === "undefined") {
|
||||
return t().voidTypeAnnotation();
|
||||
} else if (node.name === "NaN" || node.name === "Infinity") {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (node.name === "arguments") {}
|
||||
}
|
||||
|
||||
function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
||||
const types = [];
|
||||
const functionConstantViolations = [];
|
||||
let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations);
|
||||
const testType = getConditionalAnnotation(binding, path, name);
|
||||
|
||||
if (testType) {
|
||||
const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
|
||||
constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0);
|
||||
types.push(testType.typeAnnotation);
|
||||
}
|
||||
|
||||
if (constantViolations.length) {
|
||||
constantViolations = constantViolations.concat(functionConstantViolations);
|
||||
|
||||
for (const violation of constantViolations) {
|
||||
types.push(violation.getTypeAnnotation());
|
||||
}
|
||||
}
|
||||
|
||||
if (types.length) {
|
||||
return t().createUnionTypeAnnotation(types);
|
||||
}
|
||||
}
|
||||
|
||||
function getConstantViolationsBefore(binding, path, functions) {
|
||||
const violations = binding.constantViolations.slice();
|
||||
violations.unshift(binding.path);
|
||||
return violations.filter(violation => {
|
||||
violation = violation.resolve();
|
||||
|
||||
const status = violation._guessExecutionStatusRelativeTo(path);
|
||||
|
||||
if (functions && status === "unknown") functions.push(violation);
|
||||
return status === "before";
|
||||
});
|
||||
}
|
||||
|
||||
function inferAnnotationFromBinaryExpression(name, path) {
|
||||
const operator = path.node.operator;
|
||||
const right = path.get("right").resolve();
|
||||
const left = path.get("left").resolve();
|
||||
let target;
|
||||
|
||||
if (left.isIdentifier({
|
||||
name
|
||||
})) {
|
||||
target = right;
|
||||
} else if (right.isIdentifier({
|
||||
name
|
||||
})) {
|
||||
target = left;
|
||||
}
|
||||
|
||||
if (target) {
|
||||
if (operator === "===") {
|
||||
return target.getTypeAnnotation();
|
||||
}
|
||||
|
||||
if (t().BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().numberTypeAnnotation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (operator !== "===" && operator !== "==") return;
|
||||
let typeofPath;
|
||||
let typePath;
|
||||
|
||||
if (left.isUnaryExpression({
|
||||
operator: "typeof"
|
||||
})) {
|
||||
typeofPath = left;
|
||||
typePath = right;
|
||||
} else if (right.isUnaryExpression({
|
||||
operator: "typeof"
|
||||
})) {
|
||||
typeofPath = right;
|
||||
typePath = left;
|
||||
}
|
||||
|
||||
if (!typeofPath) return;
|
||||
if (!typeofPath.get("argument").isIdentifier({
|
||||
name
|
||||
})) return;
|
||||
typePath = typePath.resolve();
|
||||
if (!typePath.isLiteral()) return;
|
||||
const typeValue = typePath.node.value;
|
||||
if (typeof typeValue !== "string") return;
|
||||
return t().createTypeAnnotationBasedOnTypeof(typeValue);
|
||||
}
|
||||
|
||||
function getParentConditionalPath(binding, path, name) {
|
||||
let parentPath;
|
||||
|
||||
while (parentPath = path.parentPath) {
|
||||
if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
|
||||
if (path.key === "test") {
|
||||
return;
|
||||
}
|
||||
|
||||
return parentPath;
|
||||
}
|
||||
|
||||
if (parentPath.isFunction()) {
|
||||
if (parentPath.parentPath.scope.getBinding(name) !== binding) return;
|
||||
}
|
||||
|
||||
path = parentPath;
|
||||
}
|
||||
}
|
||||
|
||||
function getConditionalAnnotation(binding, path, name) {
|
||||
const ifStatement = getParentConditionalPath(binding, path, name);
|
||||
if (!ifStatement) return;
|
||||
const test = ifStatement.get("test");
|
||||
const paths = [test];
|
||||
const types = [];
|
||||
|
||||
for (let i = 0; i < paths.length; i++) {
|
||||
const path = paths[i];
|
||||
|
||||
if (path.isLogicalExpression()) {
|
||||
if (path.node.operator === "&&") {
|
||||
paths.push(path.get("left"));
|
||||
paths.push(path.get("right"));
|
||||
}
|
||||
} else if (path.isBinaryExpression()) {
|
||||
const type = inferAnnotationFromBinaryExpression(name, path);
|
||||
if (type) types.push(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (types.length) {
|
||||
return {
|
||||
typeAnnotation: t().createUnionTypeAnnotation(types),
|
||||
ifStatement
|
||||
};
|
||||
}
|
||||
|
||||
return getConditionalAnnotation(ifStatement, name);
|
||||
}
|
229
node_modules/@babel/traverse/lib/path/inference/inferers.js
generated
vendored
Normal file
229
node_modules/@babel/traverse/lib/path/inference/inferers.js
generated
vendored
Normal file
|
@ -0,0 +1,229 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.VariableDeclarator = VariableDeclarator;
|
||||
exports.TypeCastExpression = TypeCastExpression;
|
||||
exports.NewExpression = NewExpression;
|
||||
exports.TemplateLiteral = TemplateLiteral;
|
||||
exports.UnaryExpression = UnaryExpression;
|
||||
exports.BinaryExpression = BinaryExpression;
|
||||
exports.LogicalExpression = LogicalExpression;
|
||||
exports.ConditionalExpression = ConditionalExpression;
|
||||
exports.SequenceExpression = SequenceExpression;
|
||||
exports.ParenthesizedExpression = ParenthesizedExpression;
|
||||
exports.AssignmentExpression = AssignmentExpression;
|
||||
exports.UpdateExpression = UpdateExpression;
|
||||
exports.StringLiteral = StringLiteral;
|
||||
exports.NumericLiteral = NumericLiteral;
|
||||
exports.BooleanLiteral = BooleanLiteral;
|
||||
exports.NullLiteral = NullLiteral;
|
||||
exports.RegExpLiteral = RegExpLiteral;
|
||||
exports.ObjectExpression = ObjectExpression;
|
||||
exports.ArrayExpression = ArrayExpression;
|
||||
exports.RestElement = RestElement;
|
||||
exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
|
||||
exports.CallExpression = CallExpression;
|
||||
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
||||
Object.defineProperty(exports, "Identifier", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _infererReference.default;
|
||||
}
|
||||
});
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _infererReference = _interopRequireDefault(require("./inferer-reference"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
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; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { 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 VariableDeclarator() {
|
||||
const id = this.get("id");
|
||||
if (!id.isIdentifier()) return;
|
||||
const init = this.get("init");
|
||||
let type = init.getTypeAnnotation();
|
||||
|
||||
if (type && type.type === "AnyTypeAnnotation") {
|
||||
if (init.isCallExpression() && init.get("callee").isIdentifier({
|
||||
name: "Array"
|
||||
}) && !init.scope.hasBinding("Array", true)) {
|
||||
type = ArrayExpression();
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function TypeCastExpression(node) {
|
||||
return node.typeAnnotation;
|
||||
}
|
||||
|
||||
TypeCastExpression.validParent = true;
|
||||
|
||||
function NewExpression(node) {
|
||||
if (this.get("callee").isIdentifier()) {
|
||||
return t().genericTypeAnnotation(node.callee);
|
||||
}
|
||||
}
|
||||
|
||||
function TemplateLiteral() {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
function UnaryExpression(node) {
|
||||
const operator = node.operator;
|
||||
|
||||
if (operator === "void") {
|
||||
return t().voidTypeAnnotation();
|
||||
} else if (t().NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (t().STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().stringTypeAnnotation();
|
||||
} else if (t().BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().booleanTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function BinaryExpression(node) {
|
||||
const operator = node.operator;
|
||||
|
||||
if (t().NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (t().BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().booleanTypeAnnotation();
|
||||
} else if (operator === "+") {
|
||||
const right = this.get("right");
|
||||
const left = this.get("left");
|
||||
|
||||
if (left.isBaseType("number") && right.isBaseType("number")) {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
return t().unionTypeAnnotation([t().stringTypeAnnotation(), t().numberTypeAnnotation()]);
|
||||
}
|
||||
}
|
||||
|
||||
function LogicalExpression() {
|
||||
return t().createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]);
|
||||
}
|
||||
|
||||
function ConditionalExpression() {
|
||||
return t().createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]);
|
||||
}
|
||||
|
||||
function SequenceExpression() {
|
||||
return this.get("expressions").pop().getTypeAnnotation();
|
||||
}
|
||||
|
||||
function ParenthesizedExpression() {
|
||||
return this.get("expression").getTypeAnnotation();
|
||||
}
|
||||
|
||||
function AssignmentExpression() {
|
||||
return this.get("right").getTypeAnnotation();
|
||||
}
|
||||
|
||||
function UpdateExpression(node) {
|
||||
const operator = node.operator;
|
||||
|
||||
if (operator === "++" || operator === "--") {
|
||||
return t().numberTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function StringLiteral() {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
function NumericLiteral() {
|
||||
return t().numberTypeAnnotation();
|
||||
}
|
||||
|
||||
function BooleanLiteral() {
|
||||
return t().booleanTypeAnnotation();
|
||||
}
|
||||
|
||||
function NullLiteral() {
|
||||
return t().nullLiteralTypeAnnotation();
|
||||
}
|
||||
|
||||
function RegExpLiteral() {
|
||||
return t().genericTypeAnnotation(t().identifier("RegExp"));
|
||||
}
|
||||
|
||||
function ObjectExpression() {
|
||||
return t().genericTypeAnnotation(t().identifier("Object"));
|
||||
}
|
||||
|
||||
function ArrayExpression() {
|
||||
return t().genericTypeAnnotation(t().identifier("Array"));
|
||||
}
|
||||
|
||||
function RestElement() {
|
||||
return ArrayExpression();
|
||||
}
|
||||
|
||||
RestElement.validParent = true;
|
||||
|
||||
function Func() {
|
||||
return t().genericTypeAnnotation(t().identifier("Function"));
|
||||
}
|
||||
|
||||
const isArrayFrom = t().buildMatchMemberExpression("Array.from");
|
||||
const isObjectKeys = t().buildMatchMemberExpression("Object.keys");
|
||||
const isObjectValues = t().buildMatchMemberExpression("Object.values");
|
||||
const isObjectEntries = t().buildMatchMemberExpression("Object.entries");
|
||||
|
||||
function CallExpression() {
|
||||
const {
|
||||
callee
|
||||
} = this.node;
|
||||
|
||||
if (isObjectKeys(callee)) {
|
||||
return t().arrayTypeAnnotation(t().stringTypeAnnotation());
|
||||
} else if (isArrayFrom(callee) || isObjectValues(callee)) {
|
||||
return t().arrayTypeAnnotation(t().anyTypeAnnotation());
|
||||
} else if (isObjectEntries(callee)) {
|
||||
return t().arrayTypeAnnotation(t().tupleTypeAnnotation([t().stringTypeAnnotation(), t().anyTypeAnnotation()]));
|
||||
}
|
||||
|
||||
return resolveCall(this.get("callee"));
|
||||
}
|
||||
|
||||
function TaggedTemplateExpression() {
|
||||
return resolveCall(this.get("tag"));
|
||||
}
|
||||
|
||||
function resolveCall(callee) {
|
||||
callee = callee.resolve();
|
||||
|
||||
if (callee.isFunction()) {
|
||||
if (callee.is("async")) {
|
||||
if (callee.is("generator")) {
|
||||
return t().genericTypeAnnotation(t().identifier("AsyncIterator"));
|
||||
} else {
|
||||
return t().genericTypeAnnotation(t().identifier("Promise"));
|
||||
}
|
||||
} else {
|
||||
if (callee.node.returnType) {
|
||||
return callee.node.returnType;
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue