mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-04 04:40:05 +02:00
add some babel stuff
This commit is contained in:
196
node_modules/@babel/traverse/lib/path/lib/hoister.js
generated
vendored
Normal file
196
node_modules/@babel/traverse/lib/path/lib/hoister.js
generated
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
var referenceVisitor = {
|
||||
ReferencedIdentifier: function ReferencedIdentifier(path, state) {
|
||||
if (path.isJSXIdentifier() && t().react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (path.node.name === "this") {
|
||||
var scope = path.scope;
|
||||
|
||||
do {
|
||||
if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
|
||||
break;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
|
||||
if (scope) state.breakOnScopePaths.push(scope.path);
|
||||
}
|
||||
|
||||
var binding = path.scope.getBinding(path.node.name);
|
||||
if (!binding) return;
|
||||
if (binding !== state.scope.getBinding(path.node.name)) return;
|
||||
state.bindings[path.node.name] = binding;
|
||||
}
|
||||
};
|
||||
|
||||
var PathHoister = function () {
|
||||
function PathHoister(path, scope) {
|
||||
this.breakOnScopePaths = [];
|
||||
this.bindings = {};
|
||||
this.scopes = [];
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
this.attachAfter = false;
|
||||
}
|
||||
|
||||
var _proto = PathHoister.prototype;
|
||||
|
||||
_proto.isCompatibleScope = function isCompatibleScope(scope) {
|
||||
for (var key in this.bindings) {
|
||||
var binding = this.bindings[key];
|
||||
|
||||
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
_proto.getCompatibleScopes = function getCompatibleScopes() {
|
||||
var scope = this.path.scope;
|
||||
|
||||
do {
|
||||
if (this.isCompatibleScope(scope)) {
|
||||
this.scopes.push(scope);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
|
||||
break;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
};
|
||||
|
||||
_proto.getAttachmentPath = function getAttachmentPath() {
|
||||
var path = this._getAttachmentPath();
|
||||
|
||||
if (!path) return;
|
||||
var targetScope = path.scope;
|
||||
|
||||
if (targetScope.path === path) {
|
||||
targetScope = path.scope.parent;
|
||||
}
|
||||
|
||||
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
|
||||
for (var name in this.bindings) {
|
||||
if (!targetScope.hasOwnBinding(name)) continue;
|
||||
var binding = this.bindings[name];
|
||||
|
||||
if (binding.kind === "param" || binding.path.parentKey === "params") {
|
||||
continue;
|
||||
}
|
||||
|
||||
var bindingParentPath = this.getAttachmentParentForPath(binding.path);
|
||||
|
||||
if (bindingParentPath.key >= path.key) {
|
||||
this.attachAfter = true;
|
||||
path = binding.path;
|
||||
var _arr = binding.constantViolations;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var violationPath = _arr[_i];
|
||||
|
||||
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
|
||||
path = violationPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
_proto._getAttachmentPath = function _getAttachmentPath() {
|
||||
var scopes = this.scopes;
|
||||
var scope = scopes.pop();
|
||||
if (!scope) return;
|
||||
|
||||
if (scope.path.isFunction()) {
|
||||
if (this.hasOwnParamBindings(scope)) {
|
||||
if (this.scope === scope) return;
|
||||
var bodies = scope.path.get("body").get("body");
|
||||
|
||||
for (var i = 0; i < bodies.length; i++) {
|
||||
if (bodies[i].node._blockHoist) continue;
|
||||
return bodies[i];
|
||||
}
|
||||
} else {
|
||||
return this.getNextScopeAttachmentParent();
|
||||
}
|
||||
} else if (scope.path.isProgram()) {
|
||||
return this.getNextScopeAttachmentParent();
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getNextScopeAttachmentParent = function getNextScopeAttachmentParent() {
|
||||
var scope = this.scopes.pop();
|
||||
if (scope) return this.getAttachmentParentForPath(scope.path);
|
||||
};
|
||||
|
||||
_proto.getAttachmentParentForPath = function getAttachmentParentForPath(path) {
|
||||
do {
|
||||
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
||||
return path;
|
||||
}
|
||||
} while (path = path.parentPath);
|
||||
};
|
||||
|
||||
_proto.hasOwnParamBindings = function hasOwnParamBindings(scope) {
|
||||
for (var name in this.bindings) {
|
||||
if (!scope.hasOwnBinding(name)) continue;
|
||||
var binding = this.bindings[name];
|
||||
if (binding.kind === "param" && binding.constant) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
_proto.run = function run() {
|
||||
this.path.traverse(referenceVisitor, this);
|
||||
this.getCompatibleScopes();
|
||||
var attachTo = this.getAttachmentPath();
|
||||
if (!attachTo) return;
|
||||
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
||||
var uid = attachTo.scope.generateUidIdentifier("ref");
|
||||
var declarator = t().variableDeclarator(uid, this.path.node);
|
||||
var insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
||||
|
||||
var _attachTo$insertFn = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t().variableDeclaration("var", [declarator])]),
|
||||
attached = _attachTo$insertFn[0];
|
||||
|
||||
var parent = this.path.parentPath;
|
||||
|
||||
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
||||
uid = t().JSXExpressionContainer(uid);
|
||||
}
|
||||
|
||||
this.path.replaceWith(t().cloneNode(uid));
|
||||
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
||||
};
|
||||
|
||||
return PathHoister;
|
||||
}();
|
||||
|
||||
exports.default = PathHoister;
|
38
node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
generated
vendored
Normal file
38
node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.hooks = void 0;
|
||||
var hooks = [function (self, parent) {
|
||||
var removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
|
||||
|
||||
if (removeParent) {
|
||||
parent.remove();
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
|
||||
parent.replaceWith(parent.node.expressions[0]);
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isBinary()) {
|
||||
if (self.key === "left") {
|
||||
parent.replaceWith(parent.node.right);
|
||||
} else {
|
||||
parent.replaceWith(parent.node.left);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isIfStatement() && (self.key === "consequent" || self.key === "alternate") || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
|
||||
self.replaceWith({
|
||||
type: "BlockStatement",
|
||||
body: []
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}];
|
||||
exports.hooks = hooks;
|
182
node_modules/@babel/traverse/lib/path/lib/virtual-types.js
generated
vendored
Normal file
182
node_modules/@babel/traverse/lib/path/lib/virtual-types.js
generated
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
var ReferencedIdentifier = {
|
||||
types: ["Identifier", "JSXIdentifier"],
|
||||
checkPath: function checkPath(_ref, opts) {
|
||||
var node = _ref.node,
|
||||
parent = _ref.parent;
|
||||
|
||||
if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) {
|
||||
if (t().isJSXIdentifier(node, opts)) {
|
||||
if (t().react.isCompatTag(node.name)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return t().isReferenced(node, parent);
|
||||
}
|
||||
};
|
||||
exports.ReferencedIdentifier = ReferencedIdentifier;
|
||||
var ReferencedMemberExpression = {
|
||||
types: ["MemberExpression"],
|
||||
checkPath: function checkPath(_ref2) {
|
||||
var node = _ref2.node,
|
||||
parent = _ref2.parent;
|
||||
return t().isMemberExpression(node) && t().isReferenced(node, parent);
|
||||
}
|
||||
};
|
||||
exports.ReferencedMemberExpression = ReferencedMemberExpression;
|
||||
var BindingIdentifier = {
|
||||
types: ["Identifier"],
|
||||
checkPath: function checkPath(_ref3) {
|
||||
var node = _ref3.node,
|
||||
parent = _ref3.parent;
|
||||
return t().isIdentifier(node) && t().isBinding(node, parent);
|
||||
}
|
||||
};
|
||||
exports.BindingIdentifier = BindingIdentifier;
|
||||
var Statement = {
|
||||
types: ["Statement"],
|
||||
checkPath: function checkPath(_ref4) {
|
||||
var node = _ref4.node,
|
||||
parent = _ref4.parent;
|
||||
|
||||
if (t().isStatement(node)) {
|
||||
if (t().isVariableDeclaration(node)) {
|
||||
if (t().isForXStatement(parent, {
|
||||
left: node
|
||||
})) return false;
|
||||
if (t().isForStatement(parent, {
|
||||
init: node
|
||||
})) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.Statement = Statement;
|
||||
var Expression = {
|
||||
types: ["Expression"],
|
||||
checkPath: function checkPath(path) {
|
||||
if (path.isIdentifier()) {
|
||||
return path.isReferencedIdentifier();
|
||||
} else {
|
||||
return t().isExpression(path.node);
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.Expression = Expression;
|
||||
var Scope = {
|
||||
types: ["Scopable"],
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isScope(path.node, path.parent);
|
||||
}
|
||||
};
|
||||
exports.Scope = Scope;
|
||||
var Referenced = {
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isReferenced(path.node, path.parent);
|
||||
}
|
||||
};
|
||||
exports.Referenced = Referenced;
|
||||
var BlockScoped = {
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isBlockScoped(path.node);
|
||||
}
|
||||
};
|
||||
exports.BlockScoped = BlockScoped;
|
||||
var Var = {
|
||||
types: ["VariableDeclaration"],
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isVar(path.node);
|
||||
}
|
||||
};
|
||||
exports.Var = Var;
|
||||
var User = {
|
||||
checkPath: function checkPath(path) {
|
||||
return path.node && !!path.node.loc;
|
||||
}
|
||||
};
|
||||
exports.User = User;
|
||||
var Generated = {
|
||||
checkPath: function checkPath(path) {
|
||||
return !path.isUser();
|
||||
}
|
||||
};
|
||||
exports.Generated = Generated;
|
||||
var Pure = {
|
||||
checkPath: function checkPath(path, opts) {
|
||||
return path.scope.isPure(path.node, opts);
|
||||
}
|
||||
};
|
||||
exports.Pure = Pure;
|
||||
var Flow = {
|
||||
types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
|
||||
checkPath: function checkPath(_ref5) {
|
||||
var node = _ref5.node;
|
||||
|
||||
if (t().isFlow(node)) {
|
||||
return true;
|
||||
} else if (t().isImportDeclaration(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else if (t().isExportDeclaration(node)) {
|
||||
return node.exportKind === "type";
|
||||
} else if (t().isImportSpecifier(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.Flow = Flow;
|
||||
var RestProperty = {
|
||||
types: ["RestElement"],
|
||||
checkPath: function checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectPattern();
|
||||
}
|
||||
};
|
||||
exports.RestProperty = RestProperty;
|
||||
var SpreadProperty = {
|
||||
types: ["RestElement"],
|
||||
checkPath: function checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectExpression();
|
||||
}
|
||||
};
|
||||
exports.SpreadProperty = SpreadProperty;
|
||||
var ExistentialTypeParam = {
|
||||
types: ["ExistsTypeAnnotation"]
|
||||
};
|
||||
exports.ExistentialTypeParam = ExistentialTypeParam;
|
||||
var NumericLiteralTypeAnnotation = {
|
||||
types: ["NumberLiteralTypeAnnotation"]
|
||||
};
|
||||
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
|
||||
var ForAwaitStatement = {
|
||||
types: ["ForOfStatement"],
|
||||
checkPath: function checkPath(_ref6) {
|
||||
var node = _ref6.node;
|
||||
return node.await === true;
|
||||
}
|
||||
};
|
||||
exports.ForAwaitStatement = ForAwaitStatement;
|
Reference in New Issue
Block a user