v3 new release (#84)

swap to graphql
This commit is contained in:
github-actions[bot]
2022-07-11 13:48:02 -04:00
committed by GitHub
parent 20d2b4f98d
commit e4f3964f67
1492 changed files with 63799 additions and 63001 deletions

View File

@ -129,7 +129,11 @@ function stop() {
function setScope() {
if (this.opts && this.opts.noScope) return;
let path = this.parentPath;
if (this.key === "key" && path.isMethod()) path = path.parentPath;
if ((this.key === "key" || this.listKey === "decorators") && path.isMethod()) {
path = path.parentPath;
}
let target;
while (path && !target) {
@ -177,7 +181,10 @@ function _resyncParent() {
function _resyncKey() {
if (!this.container) return;
if (this.node === this.container[this.key]) return;
if (this.node === this.container[this.key]) {
return;
}
if (Array.isArray(this.container)) {
for (let i = 0; i < this.container.length; i++) {

View File

@ -251,10 +251,11 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []);
flatSuperProps.forEach(superProp => {
const key = superProp.node.computed ? "" : superProp.get("property").node.name;
const isAssignment = superProp.parentPath.isAssignmentExpression({
const superParentPath = superProp.parentPath;
const isAssignment = superParentPath.isAssignmentExpression({
left: superProp.node
});
const isCall = superProp.parentPath.isCallExpression({
const isCall = superParentPath.isCallExpression({
callee: superProp.node
});
const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
@ -265,18 +266,18 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
}
if (isAssignment) {
const value = superProp.parentPath.node.right;
const value = superParentPath.node.right;
args.push(value);
}
const call = callExpression(identifier(superBinding), args);
if (isCall) {
superProp.parentPath.unshiftContainer("arguments", thisExpression());
superParentPath.unshiftContainer("arguments", thisExpression());
superProp.replaceWith(memberExpression(call, identifier("call")));
thisPaths.push(superProp.parentPath.get("arguments.0"));
thisPaths.push(superParentPath.get("arguments.0"));
} else if (isAssignment) {
superProp.parentPath.replaceWith(call);
superParentPath.replaceWith(call);
} else {
superProp.replaceWith(call);
}

View File

@ -8,6 +8,14 @@ exports.evaluateTruthy = evaluateTruthy;
const VALID_CALLEES = ["String", "Number", "Math"];
const INVALID_METHODS = ["random"];
function isValidCallee(val) {
return VALID_CALLEES.includes(val);
}
function isInvalidMethod(val) {
return INVALID_METHODS.includes(val);
}
function evaluateTruthy() {
const res = this.evaluate();
if (res.confident) return !!res.value;
@ -336,7 +344,7 @@ function _evaluate(path, state) {
let context;
let func;
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && isValidCallee(callee.node.name)) {
func = global[callee.node.name];
}
@ -344,7 +352,7 @@ function _evaluate(path, state) {
const object = callee.get("object");
const property = callee.get("property");
if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) {
if (object.isIdentifier() && property.isIdentifier() && isValidCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
context = global[object.node.name];
func = context[property.node.name];
}

View File

@ -135,6 +135,10 @@ class NodePath {
return val;
}
hasNode() {
return this.node != null;
}
buildCodeFrameError(msg, Error = SyntaxError) {
return this.hub.buildError(this.node, msg, Error);
}
@ -223,6 +227,9 @@ class NodePath {
}
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
{
NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
}
for (const type of t.TYPES) {
const typeKey = `is${type}`;

View File

@ -33,10 +33,16 @@ const {
} = _t;
function getTypeAnnotation() {
if (this.typeAnnotation) return this.typeAnnotation;
let type = this._getTypeAnnotation() || anyTypeAnnotation();
let type = this.getData("typeAnnotation");
if (type != null) {
return type;
}
type = this._getTypeAnnotation() || anyTypeAnnotation();
if (isTypeAnnotation(type)) type = type.typeAnnotation;
return this.typeAnnotation = type;
this.setData("typeAnnotation", type);
return type;
}
const typeAnnotationInferringNodes = new WeakSet();

View File

@ -202,5 +202,5 @@ function getConditionalAnnotation(binding, path, name) {
};
}
return getConditionalAnnotation(ifStatement, name);
return getConditionalAnnotation(binding, ifStatement, name);
}

View File

@ -87,7 +87,7 @@ function TypeCastExpression(node) {
TypeCastExpression.validParent = true;
function NewExpression(node) {
if (this.get("callee").isIdentifier()) {
if (node.callee.type === "Identifier") {
return genericTypeAnnotation(node.callee);
}
}

View File

@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
exports._resolve = _resolve;
exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
@ -94,9 +93,12 @@ function isCompletionRecord(allowInsideFunction) {
let first = true;
do {
const container = path.container;
const {
type,
container
} = path;
if (path.isFunction() && !first) {
if (!first && (path.isFunction() || type === "StaticBlock")) {
return !!allowInsideFunction;
}
@ -105,7 +107,7 @@ function isCompletionRecord(allowInsideFunction) {
if (Array.isArray(container) && path.key !== container.length - 1) {
return false;
}
} while ((path = path.parentPath) && !path.isProgram());
} while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
return true;
}
@ -120,7 +122,7 @@ function isStatementOrBlock() {
function referencesImport(moduleSource, importName) {
if (!this.isReferencedIdentifier()) {
if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
if (this.isJSXMemberExpression() && this.node.property.name === importName || (this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
value: importName
}) : this.node.property.name === importName)) {
const object = this.get("object");
@ -229,20 +231,24 @@ function isExecutionUncertainInList(paths, maxIndex) {
}
function _guessExecutionStatusRelativeTo(target) {
return _guessExecutionStatusRelativeToCached(this, target, new Map());
}
function _guessExecutionStatusRelativeToCached(base, target, cache) {
const funcParent = {
this: getOuterFunction(this),
this: getOuterFunction(base),
target: getOuterFunction(target)
};
if (funcParent.target.node !== funcParent.this.node) {
return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
}
const paths = {
target: target.getAncestry(),
this: this.getAncestry()
this: base.getAncestry()
};
if (paths.target.indexOf(this) >= 0) return "after";
if (paths.target.indexOf(base) >= 0) return "after";
if (paths.this.indexOf(target) >= 0) return "before";
let commonPath;
const commonIndex = {
@ -286,9 +292,9 @@ function _guessExecutionStatusRelativeTo(target) {
return keyPosition.target > keyPosition.this ? "before" : "after";
}
const executionOrderCheckedNodes = new WeakSet();
const executionOrderCheckedNodes = new Set();
function _guessExecutionStatusRelativeToDifferentFunctions(target) {
function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
return "unknown";
}
@ -309,20 +315,37 @@ function _guessExecutionStatusRelativeToDifferentFunctions(target) {
if (executionOrderCheckedNodes.has(path.node)) continue;
executionOrderCheckedNodes.add(path.node);
const status = this._guessExecutionStatusRelativeTo(path);
try {
const status = _guessExecutionStatusRelativeToCached(base, path, cache);
executionOrderCheckedNodes.delete(path.node);
if (allStatus && allStatus !== status) {
return "unknown";
} else {
allStatus = status;
if (allStatus && allStatus !== status) {
return "unknown";
} else {
allStatus = status;
}
} finally {
executionOrderCheckedNodes.delete(path.node);
}
}
return allStatus;
}
function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) {
let nodeMap = cache.get(base.node);
if (!nodeMap) {
cache.set(base.node, nodeMap = new Map());
} else if (nodeMap.has(target.node)) {
return nodeMap.get(target.node);
}
const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache);
nodeMap.set(target.node, result);
return result;
}
function resolve(dangerous, resolved) {
return this._resolve(dangerous, resolved) || this;
}

View File

@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hooks = void 0;
var _ = require("..");
const hooks = [function (self, parent) {
const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();

View File

@ -164,8 +164,8 @@ const Generated = {
};
exports.Generated = Generated;
const Pure = {
checkPath(path, opts) {
return path.scope.isPure(path.node, opts);
checkPath(path, constantsOnly) {
return path.scope.isPure(path.node, constantsOnly);
}
};

View File

@ -30,7 +30,13 @@ const {
callExpression,
cloneNode,
expressionStatement,
isExpression
isAssignmentExpression,
isCallExpression,
isExpression,
isIdentifier,
isSequenceExpression,
isSuper,
thisExpression
} = _t;
function insertBefore(nodes_) {
@ -96,9 +102,28 @@ function _containerInsertAfter(nodes) {
return this._containerInsert(this.key + 1, nodes);
}
const last = arr => arr[arr.length - 1];
function isHiddenInSequenceExpression(path) {
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
}
function isAlmostConstantAssignment(node, scope) {
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
return false;
}
const blockScope = scope.getBlockParent();
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
}
function insertAfter(nodes_) {
this._assertUnremoved();
if (this.isSequenceExpression()) {
return last(this.get("expressions")).insertAfter(nodes_);
}
const nodes = this._verifyNodeList(nodes_);
const {
@ -123,16 +148,28 @@ function insertAfter(nodes_) {
return [this];
}
if (parentPath.isMethod({
computed: true,
key: node
})) {
scope = scope.parent;
}
if (isHiddenInSequenceExpression(this)) {
nodes.unshift(node);
} else if (isCallExpression(node) && isSuper(node.callee)) {
nodes.unshift(node);
nodes.push(thisExpression());
} else if (isAlmostConstantAssignment(node, scope)) {
nodes.unshift(node);
nodes.push(cloneNode(node.left));
} else if (scope.isPure(node, true)) {
nodes.push(node);
} else {
if (parentPath.isMethod({
computed: true,
key: node
})) {
scope = scope.parent;
}
const temp = scope.generateDeclaredUidIdentifier();
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
nodes.push(expressionStatement(cloneNode(temp)));
const temp = scope.generateDeclaredUidIdentifier();
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
nodes.push(expressionStatement(cloneNode(temp)));
}
}
return this.replaceExpressionWithStatements(nodes);

View File

@ -69,10 +69,11 @@ function replaceWithMultiple(nodes) {
function replaceWithSourceString(replacement) {
this.resync();
let ast;
try {
replacement = `(${replacement})`;
replacement = (0, _parser.parse)(replacement);
ast = (0, _parser.parse)(replacement);
} catch (err) {
const loc = err.loc;
@ -89,23 +90,21 @@ function replaceWithSourceString(replacement) {
throw err;
}
replacement = replacement.program.body[0].expression;
const expressionAST = ast.program.body[0].expression;
_index.default.removeProperties(replacement);
_index.default.removeProperties(expressionAST);
return this.replaceWith(replacement);
return this.replaceWith(expressionAST);
}
function replaceWith(replacement) {
function replaceWith(replacementPath) {
this.resync();
if (this.removed) {
throw new Error("You can't replace this node, we've already removed it");
}
if (replacement instanceof _index2.default) {
replacement = replacement.node;
}
let replacement = replacementPath instanceof _index2.default ? replacementPath.node : replacementPath;
if (!replacement) {
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");