summaryrefslogtreecommitdiff
path: root/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-05-18 23:10:59 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-05-18 23:41:44 +0800
commitfc87c009806dcc98867f6b58efe29b042aa01dee (patch)
tree8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js
parent3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff)
node: updatemain
Diffstat (limited to 'node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js')
-rw-r--r--node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js109
1 files changed, 0 insertions, 109 deletions
diff --git a/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js b/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js
deleted file mode 100644
index 008b34a2..00000000
--- a/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js
+++ /dev/null
@@ -1,109 +0,0 @@
-"use strict";
-
-module.exports = function ({
- types: t
-}) {
- // custom implementation of getTypeAnnotation that fixes
- // the type information that is lost during sequence expression transformation
- // https://github.com/babel/minify/issues/323
- function customTypeAnnotation(path) {
- if (path.typeAnnotation) {
- return path.typeAnnotation;
- } // We are not handling the case of literals and other base types
- // since they are already handled via getTypeAnnotation
-
-
- const node = path.node;
- const binding = path.parentPath.scope.getBinding(node.name);
- const types = [];
-
- if (binding && binding.constantViolations) {
- if (binding.identifier.typeAnnotation) {
- return binding.identifier.typeAnnotation;
- }
-
- if (binding.constantViolations) {
- const violations = binding.constantViolations;
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
-
- try {
- for (var _iterator = violations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- let violation = _step.value;
- types.push(violation.getTypeAnnotation());
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- }
- }
-
- if (types.length > 0) {
- return t.createUnionTypeAnnotation(types);
- }
-
- return types;
- } // Based on the type inference in Babel
-
-
- function baseTypeStrictlyMatches(left, right) {
- let leftTypes, rightTypes;
-
- if (t.isIdentifier(left)) {
- leftTypes = customTypeAnnotation(left);
- } else if (t.isIdentifier(right)) {
- rightTypes = customTypeAnnotation(right);
- } // Early exit
-
-
- if (t.isAnyTypeAnnotation(leftTypes) || t.isAnyTypeAnnotation(rightTypes)) {
- return false;
- }
-
- leftTypes = [].concat(leftTypes, left.getTypeAnnotation());
- rightTypes = [].concat(rightTypes, right.getTypeAnnotation());
- leftTypes = t.createUnionTypeAnnotation(leftTypes);
- rightTypes = t.createUnionTypeAnnotation(rightTypes);
-
- if (!t.isAnyTypeAnnotation(leftTypes) && t.isFlowBaseAnnotation(leftTypes)) {
- return leftTypes.type === rightTypes.type;
- }
- }
-
- return {
- name: "transform-simplify-comparison-operators",
- visitor: {
- // simplify comparison operations if we're 100% certain
- // that each value will always be of the same type
- BinaryExpression(path) {
- const node = path.node;
- const op = node.operator;
-
- if (op !== "===" && op !== "!==") {
- return;
- }
-
- const left = path.get("left");
- const right = path.get("right");
- const strictMatch = baseTypeStrictlyMatches(left, right);
-
- if (strictMatch) {
- node.operator = node.operator.slice(0, -1);
- }
- }
-
- }
- };
-}; \ No newline at end of file