react-native-boost 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,17 +42,23 @@ const isIgnoredFile = (path, ignores) => {
42
42
  }
43
43
  return false;
44
44
  };
45
+ const isForcedLine = (path) => {
46
+ return hasDecoratorComment(path, "@boost-force");
47
+ };
45
48
  const isIgnoredLine = (path) => {
49
+ return hasDecoratorComment(path, "@boost-ignore");
50
+ };
51
+ function hasDecoratorComment(path, decorator) {
46
52
  var _a, _b, _c;
47
- if ((_a = path.node.leadingComments) == null ? void 0 : _a.some((comment) => comment.value.includes("@boost-ignore"))) {
53
+ if ((_a = path.node.leadingComments) == null ? void 0 : _a.some((comment) => comment.value.includes(decorator))) {
48
54
  return true;
49
55
  }
50
56
  const jsxElementPath = path.parentPath;
51
- if ((_b = jsxElementPath.node.leadingComments) == null ? void 0 : _b.some((comment) => comment.value.includes("@boost-ignore"))) {
57
+ if ((_b = jsxElementPath.node.leadingComments) == null ? void 0 : _b.some((comment) => comment.value.includes(decorator))) {
52
58
  return true;
53
59
  }
54
60
  const propertyPath = jsxElementPath.parentPath;
55
- if (propertyPath && propertyPath.isObjectProperty() && ((_c = propertyPath.node.leadingComments) == null ? void 0 : _c.some((comment) => comment.value.includes("@boost-ignore")))) {
61
+ if (propertyPath && propertyPath.isObjectProperty() && ((_c = propertyPath.node.leadingComments) == null ? void 0 : _c.some((comment) => comment.value.includes(decorator)))) {
56
62
  return true;
57
63
  }
58
64
  if (!jsxElementPath.parentPath) return false;
@@ -73,18 +79,18 @@ const isIgnoredLine = (path) => {
73
79
  ...expression.node.trailingComments || [],
74
80
  ...expression.node.innerComments || []
75
81
  ].map((comment) => comment.value.trim());
76
- if (comments.some((comment) => comment.includes("@boost-ignore"))) {
82
+ if (comments.some((comment) => comment.includes(decorator))) {
77
83
  return true;
78
84
  }
79
85
  }
80
86
  }
81
- if (sibling.node.leadingComments && sibling.node.leadingComments.some((comment) => comment.value.includes("@boost-ignore"))) {
87
+ if (sibling.node.leadingComments && sibling.node.leadingComments.some((comment) => comment.value.includes(decorator))) {
82
88
  return true;
83
89
  }
84
90
  break;
85
91
  }
86
92
  return false;
87
- };
93
+ }
88
94
  const isValidJSXComponent = (path, componentName) => {
89
95
  if (!core.types.isJSXIdentifier(path.node.name)) return false;
90
96
  const parent = path.parent;
@@ -738,16 +744,10 @@ const textBlacklistedProperties = /* @__PURE__ */ new Set([
738
744
  ]);
739
745
  const textOptimizer = (path, logger) => {
740
746
  if (!isValidJSXComponent(path, "Text")) return;
747
+ if (!isReactNativeImport(path, "Text")) return;
741
748
  const parent = path.parent;
742
- const skipReason = getFirstBailoutReason([
743
- {
744
- reason: "line is marked with @boost-ignore",
745
- shouldBail: () => isIgnoredLine(path)
746
- },
747
- {
748
- reason: "Text is not imported from react-native",
749
- shouldBail: () => !isReactNativeImport(path, "Text")
750
- },
749
+ const forced = isForcedLine(path);
750
+ const overridableChecks = [
751
751
  {
752
752
  reason: "contains blacklisted props",
753
753
  shouldBail: () => hasBlacklistedProperty(path, textBlacklistedProperties)
@@ -760,14 +760,24 @@ const textOptimizer = (path, logger) => {
760
760
  reason: "contains non-string children",
761
761
  shouldBail: () => hasInvalidChildren(path, parent)
762
762
  }
763
- ]);
764
- if (skipReason) {
765
- logger.skipped({
766
- component: "Text",
767
- path,
768
- reason: skipReason
769
- });
770
- return;
763
+ ];
764
+ if (forced) {
765
+ const overriddenReason = getFirstBailoutReason(overridableChecks);
766
+ if (overriddenReason) {
767
+ logger.forced({ component: "Text", path, reason: overriddenReason });
768
+ }
769
+ } else {
770
+ const skipReason = getFirstBailoutReason([
771
+ {
772
+ reason: "line is marked with @boost-ignore",
773
+ shouldBail: () => isIgnoredLine(path)
774
+ },
775
+ ...overridableChecks
776
+ ]);
777
+ if (skipReason) {
778
+ logger.skipped({ component: "Text", path, reason: skipReason });
779
+ return;
780
+ }
771
781
  }
772
782
  const hub = path.hub;
773
783
  const file = typeof hub === "object" && hub !== null && "file" in hub ? hub.file : void 0;
@@ -872,11 +882,14 @@ const ANSI_RESET = "\x1B[0m";
872
882
  const ANSI_GREEN = "\x1B[32m";
873
883
  const ANSI_YELLOW = "\x1B[33m";
874
884
  const ANSI_MAGENTA = "\x1B[35m";
885
+ const ANSI_RED = "\x1B[31m";
875
886
  const noopLogger = {
876
887
  optimized() {
877
888
  },
878
889
  skipped() {
879
890
  },
891
+ forced() {
892
+ },
880
893
  warning() {
881
894
  }
882
895
  };
@@ -890,6 +903,12 @@ const createLogger = ({ verbose, silent }) => {
890
903
  if (!verbose) return;
891
904
  writeLog("skipped", `Skipped ${payload.component} in ${formatPathLocation(payload.path)} (${payload.reason})`);
892
905
  },
906
+ forced(payload) {
907
+ writeLog(
908
+ "forced",
909
+ `Force-optimized ${payload.component} in ${formatPathLocation(payload.path)} (skipped bailout: ${payload.reason})`
910
+ );
911
+ },
893
912
  warning(payload) {
894
913
  const context = formatWarningContext(payload);
895
914
  const message = context.length > 0 ? `${context}: ${payload.message}` : payload.message;
@@ -918,6 +937,9 @@ function formatLevel(level) {
918
937
  if (level === "skipped") {
919
938
  return colorize("[skipped]", ANSI_YELLOW);
920
939
  }
940
+ if (level === "forced") {
941
+ return colorize("[forced]", ANSI_RED);
942
+ }
921
943
  return colorize("[warning]", ANSI_MAGENTA);
922
944
  }
923
945
  function colorize(value, colorCode) {
@@ -969,6 +991,7 @@ const viewBlacklistedProperties = /* @__PURE__ */ new Set([
969
991
  ]);
970
992
  const viewOptimizer = (path, logger, options) => {
971
993
  if (!isValidJSXComponent(path, "View")) return;
994
+ if (!isReactNativeImport(path, "View")) return;
972
995
  let ancestorClassification;
973
996
  const getAncestorClassification = () => {
974
997
  if (!ancestorClassification) {
@@ -976,15 +999,8 @@ const viewOptimizer = (path, logger, options) => {
976
999
  }
977
1000
  return ancestorClassification;
978
1001
  };
979
- const skipReason = getFirstBailoutReason([
980
- {
981
- reason: "line is marked with @boost-ignore",
982
- shouldBail: () => isIgnoredLine(path)
983
- },
984
- {
985
- reason: "View is not imported from react-native",
986
- shouldBail: () => !isReactNativeImport(path, "View")
987
- },
1002
+ const forced = isForcedLine(path);
1003
+ const overridableChecks = [
988
1004
  {
989
1005
  reason: "contains blacklisted props",
990
1006
  shouldBail: () => hasBlacklistedProperty(path, viewBlacklistedProperties)
@@ -997,14 +1013,24 @@ const viewOptimizer = (path, logger, options) => {
997
1013
  reason: "has unresolved ancestor and dangerous optimization is disabled",
998
1014
  shouldBail: () => getAncestorClassification() === "unknown" && (options == null ? void 0 : options.dangerouslyOptimizeViewWithUnknownAncestors) !== true
999
1015
  }
1000
- ]);
1001
- if (skipReason) {
1002
- logger.skipped({
1003
- component: "View",
1004
- path,
1005
- reason: skipReason
1006
- });
1007
- return;
1016
+ ];
1017
+ if (forced) {
1018
+ const overriddenReason = getFirstBailoutReason(overridableChecks);
1019
+ if (overriddenReason) {
1020
+ logger.forced({ component: "View", path, reason: overriddenReason });
1021
+ }
1022
+ } else {
1023
+ const skipReason = getFirstBailoutReason([
1024
+ {
1025
+ reason: "line is marked with @boost-ignore",
1026
+ shouldBail: () => isIgnoredLine(path)
1027
+ },
1028
+ ...overridableChecks
1029
+ ]);
1030
+ if (skipReason) {
1031
+ logger.skipped({ component: "View", path, reason: skipReason });
1032
+ return;
1033
+ }
1008
1034
  }
1009
1035
  const hub = path.hub;
1010
1036
  const file = typeof hub === "object" && hub !== null && "file" in hub ? hub.file : void 0;