feat: refactoring project
This commit is contained in:
26
node_modules/@babel/generator/lib/node/index.js
generated
vendored
26
node_modules/@babel/generator/lib/node/index.js
generated
vendored
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.TokenContext = void 0;
|
||||
exports.isLastChild = isLastChild;
|
||||
exports.needsParens = needsParens;
|
||||
exports.needsWhitespace = needsWhitespace;
|
||||
exports.needsWhitespaceAfter = needsWhitespaceAfter;
|
||||
@@ -13,6 +14,7 @@ var parens = require("./parentheses.js");
|
||||
var _t = require("@babel/types");
|
||||
const {
|
||||
FLIPPED_ALIAS_KEYS,
|
||||
VISITOR_KEYS,
|
||||
isCallExpression,
|
||||
isDecorator,
|
||||
isExpressionStatement,
|
||||
@@ -33,9 +35,9 @@ function expandAliases(obj) {
|
||||
const map = new Map();
|
||||
function add(type, func) {
|
||||
const fn = map.get(type);
|
||||
map.set(type, fn ? function (node, parent, stack, inForInit) {
|
||||
map.set(type, fn ? function (node, parent, stack, inForInit, getRawIdentifier) {
|
||||
var _fn;
|
||||
return (_fn = fn(node, parent, stack, inForInit)) != null ? _fn : func(node, parent, stack, inForInit);
|
||||
return (_fn = fn(node, parent, stack, inForInit, getRawIdentifier)) != null ? _fn : func(node, parent, stack, inForInit, getRawIdentifier);
|
||||
} : func);
|
||||
}
|
||||
for (const type of Object.keys(obj)) {
|
||||
@@ -76,7 +78,7 @@ function needsWhitespaceBefore(node, parent) {
|
||||
function needsWhitespaceAfter(node, parent) {
|
||||
return needsWhitespace(node, parent, 2);
|
||||
}
|
||||
function needsParens(node, parent, tokenContext, inForInit) {
|
||||
function needsParens(node, parent, tokenContext, inForInit, getRawIdentifier) {
|
||||
var _expandedParens$get;
|
||||
if (!parent) return false;
|
||||
if (isNewExpression(parent) && parent.callee === node) {
|
||||
@@ -85,7 +87,7 @@ function needsParens(node, parent, tokenContext, inForInit) {
|
||||
if (isDecorator(parent)) {
|
||||
return !isDecoratorMemberExpression(node) && !(isCallExpression(node) && isDecoratorMemberExpression(node.callee)) && !isParenthesizedExpression(node);
|
||||
}
|
||||
return (_expandedParens$get = expandedParens.get(node.type)) == null ? void 0 : _expandedParens$get(node, parent, tokenContext, inForInit);
|
||||
return (_expandedParens$get = expandedParens.get(node.type)) == null ? void 0 : _expandedParens$get(node, parent, tokenContext, inForInit, getRawIdentifier);
|
||||
}
|
||||
function isDecoratorMemberExpression(node) {
|
||||
switch (node.type) {
|
||||
@@ -97,5 +99,21 @@ function isDecoratorMemberExpression(node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isLastChild(parent, child) {
|
||||
const visitorKeys = VISITOR_KEYS[parent.type];
|
||||
for (let i = visitorKeys.length - 1; i >= 0; i--) {
|
||||
const val = parent[visitorKeys[i]];
|
||||
if (val === child) {
|
||||
return true;
|
||||
} else if (Array.isArray(val)) {
|
||||
let j = val.length - 1;
|
||||
while (j >= 0 && val[j] === null) j--;
|
||||
return j >= 0 && val[j] === child;
|
||||
} else if (val) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
|
||||
2
node_modules/@babel/generator/lib/node/index.js.map
generated
vendored
2
node_modules/@babel/generator/lib/node/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
42
node_modules/@babel/generator/lib/node/parentheses.js
generated
vendored
42
node_modules/@babel/generator/lib/node/parentheses.js
generated
vendored
@@ -3,12 +3,11 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
||||
exports.AssignmentExpression = AssignmentExpression;
|
||||
exports.Binary = Binary;
|
||||
exports.BinaryExpression = BinaryExpression;
|
||||
exports.ClassExpression = ClassExpression;
|
||||
exports.ConditionalExpression = ConditionalExpression;
|
||||
exports.ArrowFunctionExpression = exports.ConditionalExpression = ConditionalExpression;
|
||||
exports.DoExpression = DoExpression;
|
||||
exports.FunctionExpression = FunctionExpression;
|
||||
exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
|
||||
@@ -33,13 +32,13 @@ const {
|
||||
isArrayTypeAnnotation,
|
||||
isBinaryExpression,
|
||||
isCallExpression,
|
||||
isExportDeclaration,
|
||||
isForOfStatement,
|
||||
isIndexedAccessType,
|
||||
isMemberExpression,
|
||||
isObjectPattern,
|
||||
isOptionalMemberExpression,
|
||||
isYieldExpression
|
||||
isYieldExpression,
|
||||
isStatement
|
||||
} = _t;
|
||||
const PRECEDENCE = new Map([["||", 0], ["??", 0], ["|>", 0], ["&&", 1], ["|", 2], ["^", 3], ["&", 4], ["==", 5], ["===", 5], ["!=", 5], ["!==", 5], ["<", 6], [">", 6], ["<=", 6], [">=", 6], ["in", 6], ["instanceof", 6], [">>", 7], ["<<", 7], [">>>", 7], ["+", 8], ["-", 8], ["*", 9], ["/", 9], ["%", 9], ["**", 10]]);
|
||||
function getBinaryPrecedence(node, nodeType) {
|
||||
@@ -66,14 +65,18 @@ function NullableTypeAnnotation(node, parent) {
|
||||
}
|
||||
function FunctionTypeAnnotation(node, parent, tokenContext) {
|
||||
const parentType = parent.type;
|
||||
return parentType === "UnionTypeAnnotation" || parentType === "IntersectionTypeAnnotation" || parentType === "ArrayTypeAnnotation" || Boolean(tokenContext & _index.TokenContext.arrowFlowReturnType);
|
||||
return (parentType === "UnionTypeAnnotation" || parentType === "IntersectionTypeAnnotation" || parentType === "ArrayTypeAnnotation" || Boolean(tokenContext & _index.TokenContext.arrowFlowReturnType)
|
||||
);
|
||||
}
|
||||
function UpdateExpression(node, parent) {
|
||||
return hasPostfixPart(node, parent) || isClassExtendsClause(node, parent);
|
||||
}
|
||||
function ObjectExpression(node, parent, tokenContext) {
|
||||
function needsParenBeforeExpressionBrace(tokenContext) {
|
||||
return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.arrowBody));
|
||||
}
|
||||
function ObjectExpression(node, parent, tokenContext) {
|
||||
return needsParenBeforeExpressionBrace(tokenContext);
|
||||
}
|
||||
function DoExpression(node, parent, tokenContext) {
|
||||
return !node.async && Boolean(tokenContext & _index.TokenContext.expressionStatement);
|
||||
}
|
||||
@@ -115,7 +118,7 @@ function TSAsExpression(node, parent) {
|
||||
}
|
||||
function TSUnionType(node, parent) {
|
||||
const parentType = parent.type;
|
||||
return parentType === "TSArrayType" || parentType === "TSOptionalType" || parentType === "TSIntersectionType" || parentType === "TSUnionType" || parentType === "TSRestType";
|
||||
return parentType === "TSArrayType" || parentType === "TSOptionalType" || parentType === "TSIntersectionType" || parentType === "TSRestType";
|
||||
}
|
||||
function TSInferType(node, parent) {
|
||||
const parentType = parent.type;
|
||||
@@ -130,10 +133,19 @@ function BinaryExpression(node, parent, tokenContext, inForStatementInit) {
|
||||
}
|
||||
function SequenceExpression(node, parent) {
|
||||
const parentType = parent.type;
|
||||
if (parentType === "ForStatement" || parentType === "ThrowStatement" || parentType === "ReturnStatement" || parentType === "IfStatement" && parent.test === node || parentType === "WhileStatement" && parent.test === node || parentType === "ForInStatement" && parent.right === node || parentType === "SwitchStatement" && parent.discriminant === node || parentType === "ExpressionStatement" && parent.expression === node) {
|
||||
if (parentType === "SequenceExpression" || parentType === "ParenthesizedExpression" || parentType === "MemberExpression" && parent.property === node || parentType === "OptionalMemberExpression" && parent.property === node || parentType === "TemplateLiteral") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (parentType === "ClassDeclaration") {
|
||||
return true;
|
||||
}
|
||||
if (parentType === "ForOfStatement") {
|
||||
return parent.right === node;
|
||||
}
|
||||
if (parentType === "ExportDefaultDeclaration") {
|
||||
return true;
|
||||
}
|
||||
return !isStatement(parent);
|
||||
}
|
||||
function YieldExpression(node, parent) {
|
||||
const parentType = parent.type;
|
||||
@@ -148,9 +160,6 @@ function UnaryLike(node, parent) {
|
||||
function FunctionExpression(node, parent, tokenContext) {
|
||||
return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.exportDefault));
|
||||
}
|
||||
function ArrowFunctionExpression(node, parent) {
|
||||
return isExportDeclaration(parent) || ConditionalExpression(node, parent);
|
||||
}
|
||||
function ConditionalExpression(node, parent) {
|
||||
const parentType = parent.type;
|
||||
if (parentType === "UnaryExpression" || parentType === "SpreadElement" || parentType === "BinaryExpression" || parentType === "LogicalExpression" || parentType === "ConditionalExpression" && parent.test === node || parentType === "AwaitExpression" || isTSTypeExpression(parentType)) {
|
||||
@@ -161,8 +170,8 @@ function ConditionalExpression(node, parent) {
|
||||
function OptionalMemberExpression(node, parent) {
|
||||
return isCallExpression(parent) && parent.callee === node || isMemberExpression(parent) && parent.object === node;
|
||||
}
|
||||
function AssignmentExpression(node, parent) {
|
||||
if (isObjectPattern(node.left)) {
|
||||
function AssignmentExpression(node, parent, tokenContext) {
|
||||
if (needsParenBeforeExpressionBrace(tokenContext) && isObjectPattern(node.left)) {
|
||||
return true;
|
||||
} else {
|
||||
return ConditionalExpression(node, parent);
|
||||
@@ -181,7 +190,7 @@ function LogicalExpression(node, parent) {
|
||||
return parent.operator !== "??";
|
||||
}
|
||||
}
|
||||
function Identifier(node, parent, tokenContext) {
|
||||
function Identifier(node, parent, tokenContext, _inForInit, getRawIdentifier) {
|
||||
var _node$extra;
|
||||
const parentType = parent.type;
|
||||
if ((_node$extra = node.extra) != null && _node$extra.parenthesized && parentType === "AssignmentExpression" && parent.left === node) {
|
||||
@@ -190,6 +199,9 @@ function Identifier(node, parent, tokenContext) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (getRawIdentifier && getRawIdentifier(node) !== node.name) {
|
||||
return false;
|
||||
}
|
||||
if (node.name === "let") {
|
||||
const isFollowedByBracket = isMemberExpression(parent, {
|
||||
object: node,
|
||||
|
||||
2
node_modules/@babel/generator/lib/node/parentheses.js.map
generated
vendored
2
node_modules/@babel/generator/lib/node/parentheses.js.map
generated
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user