mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 12:20:04 +02:00
add some packages
This commit is contained in:
54
node_modules/babel-plugin-minify-simplify/lib/helpers.js
generated
vendored
Normal file
54
node_modules/babel-plugin-minify-simplify/lib/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
|
||||
const VOID_0 = t => t.unaryExpression("void", t.numericLiteral(0), true); // Types as Symbols - for comparing types
|
||||
|
||||
|
||||
const types = {}; // This is a test key which is used to avoid Object.keys check
|
||||
// Object.keys() check is really expensive
|
||||
// https://gist.github.com/vigneshshanmugam/c766550ecd02292dcdfbf0bf013b9d3d
|
||||
|
||||
const testKey = "Expression";
|
||||
|
||||
const typeSymbols = t => {
|
||||
// don't recompute
|
||||
if (types[testKey] !== undefined) {
|
||||
return types;
|
||||
}
|
||||
|
||||
t.TYPES.forEach(type => {
|
||||
types[type] = Symbol.for(type);
|
||||
});
|
||||
return types;
|
||||
};
|
||||
|
||||
const isNodeOfType = (t, node, typeSymbol) => typeof typeSymbol !== "symbol" ? false : t["is" + Symbol.keyFor(typeSymbol)](node);
|
||||
|
||||
const isPatternMatchesPath = t => function _isPatternMatchesPath(patternValue, inputPath) {
|
||||
if (Array.isArray(patternValue)) {
|
||||
for (let i = 0; i < patternValue.length; i++) {
|
||||
if (_isPatternMatchesPath(patternValue[i], inputPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof patternValue === "function") {
|
||||
return patternValue(inputPath);
|
||||
}
|
||||
|
||||
if (isNodeOfType(t, inputPath.node, patternValue)) return true;
|
||||
const evalResult = inputPath.evaluate();
|
||||
if (!evalResult.confident || !inputPath.isPure()) return false;
|
||||
return evalResult.value === patternValue;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
VOID_0,
|
||||
// Types as Symbols
|
||||
typeSymbols,
|
||||
// This is required for resolving type aliases
|
||||
isNodeOfType,
|
||||
isPatternMatchesPath
|
||||
};
|
Reference in New Issue
Block a user