Spaces:
Sleeping
Sleeping
File size: 4,844 Bytes
cc651f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.nodes = void 0;
var _t = require("@babel/types");
const {
FLIPPED_ALIAS_KEYS,
isArrayExpression,
isAssignmentExpression,
isBinary,
isBlockStatement,
isCallExpression,
isFunction,
isIdentifier,
isLiteral,
isMemberExpression,
isObjectExpression,
isOptionalCallExpression,
isOptionalMemberExpression,
isStringLiteral
} = _t;
function crawlInternal(node, state) {
if (!node) return state;
if (isMemberExpression(node) || isOptionalMemberExpression(node)) {
crawlInternal(node.object, state);
if (node.computed) crawlInternal(node.property, state);
} else if (isBinary(node) || isAssignmentExpression(node)) {
crawlInternal(node.left, state);
crawlInternal(node.right, state);
} else if (isCallExpression(node) || isOptionalCallExpression(node)) {
state.hasCall = true;
crawlInternal(node.callee, state);
} else if (isFunction(node)) {
state.hasFunction = true;
} else if (isIdentifier(node)) {
state.hasHelper = state.hasHelper || node.callee && isHelper(node.callee);
}
return state;
}
function crawl(node) {
return crawlInternal(node, {
hasCall: false,
hasFunction: false,
hasHelper: false
});
}
function isHelper(node) {
if (!node) return false;
if (isMemberExpression(node)) {
return isHelper(node.object) || isHelper(node.property);
} else if (isIdentifier(node)) {
return node.name === "require" || node.name.charCodeAt(0) === 95;
} else if (isCallExpression(node)) {
return isHelper(node.callee);
} else if (isBinary(node) || isAssignmentExpression(node)) {
return isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right);
} else {
return false;
}
}
function isType(node) {
return isLiteral(node) || isObjectExpression(node) || isArrayExpression(node) || isIdentifier(node) || isMemberExpression(node);
}
const nodes = exports.nodes = {
AssignmentExpression(node) {
const state = crawl(node.right);
if (state.hasCall && state.hasHelper || state.hasFunction) {
return state.hasFunction ? 1 | 2 : 2;
}
},
SwitchCase(node, parent) {
return (!!node.consequent.length || parent.cases[0] === node ? 1 : 0) | (!node.consequent.length && parent.cases[parent.cases.length - 1] === node ? 2 : 0);
},
LogicalExpression(node) {
if (isFunction(node.left) || isFunction(node.right)) {
return 2;
}
},
Literal(node) {
if (isStringLiteral(node) && node.value === "use strict") {
return 2;
}
},
CallExpression(node) {
if (isFunction(node.callee) || isHelper(node)) {
return 1 | 2;
}
},
OptionalCallExpression(node) {
if (isFunction(node.callee)) {
return 1 | 2;
}
},
VariableDeclaration(node) {
for (let i = 0; i < node.declarations.length; i++) {
const declar = node.declarations[i];
let enabled = isHelper(declar.id) && !isType(declar.init);
if (!enabled && declar.init) {
const state = crawl(declar.init);
enabled = isHelper(declar.init) && state.hasCall || state.hasFunction;
}
if (enabled) {
return 1 | 2;
}
}
},
IfStatement(node) {
if (isBlockStatement(node.consequent)) {
return 1 | 2;
}
}
};
nodes.ObjectProperty = nodes.ObjectTypeProperty = nodes.ObjectMethod = function (node, parent) {
if (parent.properties[0] === node) {
return 1;
}
};
nodes.ObjectTypeCallProperty = function (node, parent) {
var _parent$properties;
if (parent.callProperties[0] === node && !((_parent$properties = parent.properties) != null && _parent$properties.length)) {
return 1;
}
};
nodes.ObjectTypeIndexer = function (node, parent) {
var _parent$properties2, _parent$callPropertie;
if (parent.indexers[0] === node && !((_parent$properties2 = parent.properties) != null && _parent$properties2.length) && !((_parent$callPropertie = parent.callProperties) != null && _parent$callPropertie.length)) {
return 1;
}
};
nodes.ObjectTypeInternalSlot = function (node, parent) {
var _parent$properties3, _parent$callPropertie2, _parent$indexers;
if (parent.internalSlots[0] === node && !((_parent$properties3 = parent.properties) != null && _parent$properties3.length) && !((_parent$callPropertie2 = parent.callProperties) != null && _parent$callPropertie2.length) && !((_parent$indexers = parent.indexers) != null && _parent$indexers.length)) {
return 1;
}
};
[["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function ([type, amounts]) {
[type].concat(FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) {
const ret = amounts ? 1 | 2 : 0;
nodes[type] = () => ret;
});
});
//# sourceMappingURL=whitespace.js.map
|