react-state-basis 0.2.3 → 0.3.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.
package/dist/plugin.js CHANGED
@@ -4,10 +4,18 @@
4
4
  var path = require("path");
5
5
  module.exports = function(babel) {
6
6
  const { types: t } = babel;
7
+ const isIgnoredFile = (comments) => comments && comments.some((c) => /@?basis-ignore/.test(c.value));
7
8
  return {
8
9
  name: "babel-plugin-basis-transform",
9
10
  visitor: {
11
+ Program(path2, state) {
12
+ if (isIgnoredFile(path2.container.comments)) {
13
+ state.basisDisabled = true;
14
+ return;
15
+ }
16
+ },
10
17
  CallExpression(p, state) {
18
+ if (state.basisDisabled) return;
11
19
  let calleeName = "";
12
20
  if (t.isIdentifier(p.node.callee)) {
13
21
  calleeName = p.node.callee.name;
@@ -45,21 +53,20 @@ module.exports = function(babel) {
45
53
  } else if (t.isIdentifier(id)) {
46
54
  varName = id.name;
47
55
  }
48
- } else if (calleeName === "useEffect" || calleeName === "useLayoutEffect" || calleeName === "useInsertionEffect") {
56
+ } else if (["useEffect", "useLayoutEffect", "useInsertionEffect"].includes(calleeName)) {
49
57
  varName = `effect_L${p.node.loc?.start.line || "unknown"}`;
50
58
  }
51
59
  const uniqueLabel = `${fileName} -> ${varName}`;
52
60
  const args = p.node.arguments;
53
- if (["useState", "createContext", "useRef", "useId", "useDebugValue", "useDeferredValue", "useTransition"].includes(calleeName)) {
61
+ if (["useState", "createContext", "useRef", "useId", "useDebugValue", "useDeferredValue", "useTransition", "useOptimistic"].includes(calleeName)) {
54
62
  if (args.length === 0) args.push(t.identifier("undefined"));
55
63
  if (args.length === 1) args.push(t.stringLiteral(uniqueLabel));
56
64
  } else if (["useEffect", "useMemo", "useLayoutEffect", "useInsertionEffect", "useCallback"].includes(calleeName)) {
57
65
  if (args.length === 1) args.push(t.identifier("undefined"));
58
66
  if (args.length === 2) args.push(t.stringLiteral(uniqueLabel));
59
- } else if (calleeName === "useReducer") {
60
- if (args.length === 2 || args.length === 3) {
61
- args.push(t.stringLiteral(uniqueLabel));
62
- }
67
+ } else if (["useReducer", "useActionState"].includes(calleeName)) {
68
+ if (args.length === 2) args.push(t.identifier("undefined"));
69
+ if (args.length === 3) args.push(t.stringLiteral(uniqueLabel));
63
70
  } else if (["useSyncExternalStore", "useImperativeHandle"].includes(calleeName)) {
64
71
  if (args.length === 2) args.push(t.identifier("undefined"));
65
72
  if (args.length === 3) args.push(t.stringLiteral(uniqueLabel));
@@ -0,0 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ declare function basis(): Plugin;
4
+
5
+ export { basis };
@@ -0,0 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ declare function basis(): Plugin;
4
+
5
+ export { basis };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/vite-plugin.ts
21
+ var vite_plugin_exports = {};
22
+ __export(vite_plugin_exports, {
23
+ basis: () => basis
24
+ });
25
+ module.exports = __toCommonJS(vite_plugin_exports);
26
+ function basis() {
27
+ return {
28
+ name: "vite-plugin-react-state-basis",
29
+ enforce: "pre",
30
+ resolveId(source, importer) {
31
+ if (source === "react" || source === "react-dom" || source === "react-dom/client") {
32
+ const isLibraryCore = importer && ((importer.includes("react-state-basis/src") || importer.includes("react-state-basis/dist")) && !importer.includes("react-state-basis/example"));
33
+ const isYalc = importer && importer.includes(".yalc");
34
+ if (isLibraryCore || isYalc) {
35
+ return null;
36
+ }
37
+ const mapping = {
38
+ "react": "react-state-basis",
39
+ "react-dom": "react-state-basis",
40
+ "react-dom/client": "react-state-basis/client"
41
+ };
42
+ return this.resolve(mapping[source], importer, { skipSelf: true });
43
+ }
44
+ return null;
45
+ }
46
+ };
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ basis
51
+ });
52
+ //# sourceMappingURL=vite-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vite-plugin.ts"],"sourcesContent":["// src/vite-plugin.ts\n\nimport type { Plugin } from 'vite';\n\nexport function basis(): Plugin {\n return {\n name: 'vite-plugin-react-state-basis',\n enforce: 'pre',\n\n resolveId(source, importer) {\n if (source === 'react' || source === 'react-dom' || source === 'react-dom/client') {\n \n const isLibraryCore = importer && (\n (importer.includes('react-state-basis/src') || importer.includes('react-state-basis/dist')) &&\n !importer.includes('react-state-basis/example')\n );\n\n const isYalc = importer && importer.includes('.yalc');\n\n if (isLibraryCore || isYalc) {\n return null;\n }\n\n const mapping: Record<string, string> = {\n 'react': 'react-state-basis',\n 'react-dom': 'react-state-basis',\n 'react-dom/client': 'react-state-basis/client'\n };\n\n return this.resolve(mapping[source], importer, { skipSelf: true });\n }\n return null;\n }\n };\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,QAAgB;AAC9B,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,UAAU,QAAQ,UAAU;AAC1B,UAAI,WAAW,WAAW,WAAW,eAAe,WAAW,oBAAoB;AAEjF,cAAM,gBAAgB,cACnB,SAAS,SAAS,uBAAuB,KAAK,SAAS,SAAS,wBAAwB,MACzF,CAAC,SAAS,SAAS,2BAA2B;AAGhD,cAAM,SAAS,YAAY,SAAS,SAAS,OAAO;AAEpD,YAAI,iBAAiB,QAAQ;AAC3B,iBAAO;AAAA,QACT;AAEA,cAAM,UAAkC;AAAA,UACtC,SAAS;AAAA,UACT,aAAa;AAAA,UACb,oBAAoB;AAAA,QACtB;AAEA,eAAO,KAAK,QAAQ,QAAQ,MAAM,GAAG,UAAU,EAAE,UAAU,KAAK,CAAC;AAAA,MACnE;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ basis
3
+ } from "./chunk-GEHMQPV4.mjs";
4
+ export {
5
+ basis
6
+ };
7
+ //# sourceMappingURL=vite-plugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-state-basis",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "A linear algebra-powered React architectural tool that detects redundant state and synchronization anti-patterns by modeling state transitions as vectors in a basis.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -21,6 +21,16 @@
21
21
  },
22
22
  "default": "./dist/production.mjs"
23
23
  },
24
+ "./client": {
25
+ "types": "./dist/client.d.ts",
26
+ "import": "./dist/client.mjs",
27
+ "require": "./dist/client.js"
28
+ },
29
+ "./vite": {
30
+ "types": "./dist/vite-plugin.d.ts",
31
+ "import": "./dist/vite-plugin.mjs",
32
+ "require": "./dist/vite-plugin.js"
33
+ },
24
34
  "./jsx-runtime": {
25
35
  "import": "./dist/jsx-runtime.mjs",
26
36
  "require": "./dist/jsx-runtime.js"