feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -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