mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-06 05:30:06 +02:00
add some packages
This commit is contained in:
56
node_modules/babel-helper-mark-eval-scopes/src/index.js
generated
vendored
Normal file
56
node_modules/babel-helper-mark-eval-scopes/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
const EVAL_SCOPE_MARKER = Symbol("evalInScope");
|
||||
|
||||
module.exports = {
|
||||
EVAL_SCOPE_MARKER,
|
||||
getEvalScopes,
|
||||
markEvalScopes,
|
||||
isMarked,
|
||||
hasEval
|
||||
};
|
||||
|
||||
function getEvalScopes(path) {
|
||||
const evalScopes = new Set();
|
||||
|
||||
function add(scope) {
|
||||
let evalScope = scope;
|
||||
do {
|
||||
evalScopes.add(evalScope);
|
||||
} while ((evalScope = evalScope.parent));
|
||||
}
|
||||
|
||||
path.traverse({
|
||||
CallExpression(evalPath) {
|
||||
const callee = evalPath.get("callee");
|
||||
|
||||
if (
|
||||
callee.isIdentifier() &&
|
||||
callee.node.name === "eval" &&
|
||||
!callee.scope.getBinding("eval")
|
||||
) {
|
||||
add(callee.scope);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return evalScopes;
|
||||
}
|
||||
|
||||
function markEvalScopes(path, key = EVAL_SCOPE_MARKER) {
|
||||
const evalScopes = getEvalScopes(path);
|
||||
[...evalScopes].forEach(scope => {
|
||||
scope[key] = true;
|
||||
});
|
||||
}
|
||||
|
||||
function isMarked(scope, key = EVAL_SCOPE_MARKER) {
|
||||
return Object.prototype.hasOwnProperty.call(scope, key);
|
||||
}
|
||||
|
||||
function hasEval(scope, key = EVAL_SCOPE_MARKER) {
|
||||
if (!isMarked(scope, key)) {
|
||||
markEvalScopes(scope, key);
|
||||
}
|
||||
return scope[key];
|
||||
}
|
Reference in New Issue
Block a user