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

@ -38,9 +38,11 @@ const {
isMethod,
isModuleDeclaration,
isModuleSpecifier,
isNullLiteral,
isObjectExpression,
isProperty,
isPureish,
isRegExpLiteral,
isSuper,
isTaggedTemplateExpression,
isTemplateLiteral,
@ -53,7 +55,13 @@ const {
toIdentifier,
unaryExpression,
variableDeclaration,
variableDeclarator
variableDeclarator,
isRecordExpression,
isTupleExpression,
isObjectProperty,
isTopicReference,
isMetaProperty,
isPrivateName
} = _t;
function gatherNodeParts(node, parts) {
@ -69,7 +77,7 @@ function gatherNodeParts(node, parts) {
}
} else if (isModuleSpecifier(node)) {
gatherNodeParts(node.local, parts);
} else if (isLiteral(node)) {
} else if (isLiteral(node) && !isNullLiteral(node) && !isRegExpLiteral(node) && !isTemplateLiteral(node)) {
parts.push(node.value);
}
@ -179,7 +187,7 @@ function gatherNodeParts(node, parts) {
break;
case "JSXOpeningElement":
parts.push(node.name);
gatherNodeParts(node.name, parts);
break;
case "JSXFragment":
@ -362,9 +370,9 @@ class Scope {
path = this.path;
do {
const isKey = path.key === "key";
const shouldSkip = path.key === "key" || path.listKey === "decorators";
path = path.parentPath;
if (isKey && path.isMethod()) path = path.parentPath;
if (shouldSkip && path.isMethod()) path = path.parentPath;
if (path && path.isScope()) parent = path;
} while (path && !parent);
@ -430,7 +438,7 @@ class Scope {
}
isStatic(node) {
if (isThisExpression(node) || isSuper(node)) {
if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) {
return true;
}
@ -682,11 +690,19 @@ class Scope {
if (!binding) return false;
if (constantsOnly) return binding.constant;
return true;
} else if (isThisExpression(node) || isMetaProperty(node) || isTopicReference(node) || isPrivateName(node)) {
return true;
} else if (isClass(node)) {
var _node$decorators;
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
return false;
}
if (((_node$decorators = node.decorators) == null ? void 0 : _node$decorators.length) > 0) {
return false;
}
return this.isPure(node.body, constantsOnly);
} else if (isClassBody(node)) {
for (const method of node.body) {
@ -696,25 +712,44 @@ class Scope {
return true;
} else if (isBinary(node)) {
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
} else if (isArrayExpression(node)) {
} else if (isArrayExpression(node) || isTupleExpression(node)) {
for (const elem of node.elements) {
if (!this.isPure(elem, constantsOnly)) return false;
if (elem !== null && !this.isPure(elem, constantsOnly)) return false;
}
return true;
} else if (isObjectExpression(node)) {
} else if (isObjectExpression(node) || isRecordExpression(node)) {
for (const prop of node.properties) {
if (!this.isPure(prop, constantsOnly)) return false;
}
return true;
} else if (isMethod(node)) {
var _node$decorators2;
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
if (node.kind === "get" || node.kind === "set") return false;
if (((_node$decorators2 = node.decorators) == null ? void 0 : _node$decorators2.length) > 0) {
return false;
}
return true;
} else if (isProperty(node)) {
var _node$decorators3;
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
return this.isPure(node.value, constantsOnly);
if (((_node$decorators3 = node.decorators) == null ? void 0 : _node$decorators3.length) > 0) {
return false;
}
if (isObjectProperty(node) || node.static) {
if (node.value !== null && !this.isPure(node.value, constantsOnly)) {
return false;
}
}
return true;
} else if (isUnaryExpression(node)) {
return this.isPure(node.argument, constantsOnly);
} else if (isTaggedTemplateExpression(node)) {
@ -821,7 +856,9 @@ class Scope {
push(opts) {
let path = this.path;
if (!path.isBlockStatement() && !path.isProgram()) {
if (path.isPattern()) {
path = this.getPatternParent().path;
} else if (!path.isBlockStatement() && !path.isProgram()) {
path = this.getBlockParent().path;
}
@ -848,8 +885,8 @@ class Scope {
}
const declarator = variableDeclarator(opts.id, opts.init);
declarPath.node.declarations.push(declarator);
this.registerBinding(kind, declarPath.get("declarations").pop());
const len = declarPath.node.declarations.push(declarator);
path.scope.registerBinding(kind, declarPath.get("declarations")[len - 1]);
}
getProgramParent() {
@ -888,6 +925,18 @@ class Scope {
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
}
getPatternParent() {
let scope = this;
do {
if (!scope.path.isPattern()) {
return scope.getBlockParent();
}
} while (scope = scope.parent.parent);
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
}
getAllBindings() {
const ids = Object.create(null);
let scope = this;

View File

@ -9,16 +9,10 @@ var _binding = require("../binding");
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
var _t = require("@babel/types");
var t = require("@babel/types");
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
const {
VISITOR_KEYS,
assignmentExpression,
identifier,
toExpression,
variableDeclaration,
variableDeclarator
} = _t;
const renameVisitor = {
ReferencedIdentifier({
node
@ -30,7 +24,11 @@ const renameVisitor = {
Scope(path, state) {
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
skipAllButComputedMethodKey(path);
path.skip();
if (path.isMethod()) {
(0, _helperEnvironmentVisitor.requeueComputedKeyAndDecorators)(path);
}
}
},
@ -59,7 +57,17 @@ class Renamer {
return;
}
if (maybeExportDeclar.isExportDefaultDeclaration() && !maybeExportDeclar.get("declaration").node.id) {
if (maybeExportDeclar.isExportDefaultDeclaration()) {
const {
declaration
} = maybeExportDeclar.node;
if (t.isDeclaration(declaration) && !declaration.id) {
return;
}
}
if (maybeExportDeclar.isExportAllDeclaration()) {
return;
}
@ -67,23 +75,11 @@ class Renamer {
}
maybeConvertFromClassFunctionDeclaration(path) {
return;
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
if (this.binding.kind !== "hoisted") return;
path.node.id = identifier(this.oldName);
path.node._blockHoist = 3;
path.replaceWith(variableDeclaration("let", [variableDeclarator(identifier(this.newName), toExpression(path.node))]));
return path;
}
maybeConvertFromClassFunctionExpression(path) {
return;
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
if (this.binding.kind !== "local") return;
path.node.id = identifier(this.oldName);
this.binding.scope.parent.push({
id: identifier(this.newName)
});
path.replaceWith(assignmentExpression("=", identifier(this.newName), path.node));
return path;
}
rename(block) {
@ -123,24 +119,11 @@ class Renamer {
}
if (parentDeclar) {
this.maybeConvertFromClassFunctionDeclaration(parentDeclar);
this.maybeConvertFromClassFunctionExpression(parentDeclar);
this.maybeConvertFromClassFunctionDeclaration(path);
this.maybeConvertFromClassFunctionExpression(path);
}
}
}
exports.default = Renamer;
function skipAllButComputedMethodKey(path) {
if (!path.isMethod() || !path.node.computed) {
path.skip();
return;
}
const keys = VISITOR_KEYS[path.type];
for (const key of keys) {
if (key !== "key") path.skipKey(key);
}
}
exports.default = Renamer;