@multiplatform.one/config 9.2.0 → 9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/config",
3
- "version": "9.2.0",
3
+ "version": "9.3.0",
4
4
  "description": "Shared build and test configuration presets for multiplatform.one",
5
5
  "keywords": [
6
6
  "config",
@@ -122,7 +122,7 @@
122
122
  "@babel/parser": "^7.29.9",
123
123
  "@babel/plugin-transform-block-scoping": "^7.29.7",
124
124
  "@babel/traverse": "^7.29.10",
125
- "@multiplatform.one/utils": "^9.2.0",
125
+ "@multiplatform.one/utils": "^9.3.0",
126
126
  "@tamagui/vite-plugin": "2.7.6",
127
127
  "@vitejs/plugin-react": "^6.1.2",
128
128
  "dotenv": "^17.4.2",
package/press-lint.mjs CHANGED
@@ -51,21 +51,33 @@ function unwrap(expr) {
51
51
  return current;
52
52
  }
53
53
 
54
+ const wrapperMethods = new Set(["styleable", "extractable"]);
55
+
54
56
  /**
55
- * `styled(Base, {...})`, also under `.styleable(...)` and friends.
56
- * @param {ts.Expression} expr
57
- * @returns {ts.CallExpression | undefined}
57
+ * Where a component's styling comes from: a `styled(Base, {...})` call (also
58
+ * under `.styleable(...)` and friends), or the name of a styled base it wraps
59
+ * (`Frame.styleable(fn)`, `createStyledHOC(Frame, fn)`, a bare alias), which
60
+ * is resolved later against the file's declarations.
61
+ * @param {ts.Expression | undefined} expr
62
+ * @returns {{ call?: ts.CallExpression, base?: string }}
58
63
  */
59
- function styledCall(expr) {
60
- let current = unwrap(expr);
61
- while (ts.isCallExpression(current)) {
64
+ function styledSource(expr) {
65
+ let current = expr && unwrap(expr);
66
+ while (current && ts.isCallExpression(current)) {
62
67
  const callee = current.expression;
63
- if (ts.isIdentifier(callee) && callee.text === "styled") return current;
64
- if (ts.isPropertyAccessExpression(callee) && ts.isCallExpression(callee.expression))
65
- current = callee.expression;
66
- else return undefined;
68
+ if (ts.isIdentifier(callee) && callee.text === "styled") return { call: current };
69
+ if (ts.isIdentifier(callee) && callee.text === "createStyledHOC")
70
+ current = current.arguments[0] && unwrap(current.arguments[0]);
71
+ else if (ts.isPropertyAccessExpression(callee) && wrapsBase(callee))
72
+ current = unwrap(callee.expression);
73
+ else return {};
67
74
  }
68
- return undefined;
75
+ return current && ts.isIdentifier(current) ? { base: current.text } : {};
76
+ }
77
+
78
+ /** @param {ts.PropertyAccessExpression} callee */
79
+ function wrapsBase(callee) {
80
+ return ts.isCallExpression(callee.expression) || wrapperMethods.has(callee.name.text);
69
81
  }
70
82
 
71
83
  /**
@@ -82,8 +94,8 @@ function parse(source, filename) {
82
94
  );
83
95
  /** @type {Map<string, ts.Expression>} */
84
96
  const objects = new Map();
85
- /** @type {Map<string, ts.CallExpression>} */
86
- const styledCalls = new Map();
97
+ /** @type {Map<string, ts.Expression>} */
98
+ const styledInits = new Map();
87
99
  /** @type {Set<string>} */
88
100
  const exported = new Set();
89
101
  /** @type {Set<string>} */
@@ -93,8 +105,8 @@ function parse(source, filename) {
93
105
  if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
94
106
  const init = unwrap(node.initializer);
95
107
  if (ts.isObjectLiteralExpression(init)) objects.set(node.name.text, init);
96
- const call = styledCall(init);
97
- if (call) styledCalls.set(node.name.text, call);
108
+ const source = styledSource(init);
109
+ if (source.call || source.base) styledInits.set(node.name.text, init);
98
110
  const statement = node.parent?.parent;
99
111
  if (
100
112
  statement &&
@@ -135,6 +147,18 @@ function parse(source, filename) {
135
147
 
136
148
  /** @type {Map<string, boolean>} */
137
149
  const cache = new Map();
150
+ /**
151
+ * @param {ts.Expression | undefined} expr
152
+ * @param {Set<string>} imported
153
+ * @returns {boolean}
154
+ */
155
+ function claims(expr, imported) {
156
+ const { call, base } = styledSource(expr);
157
+ if (base) return isClaimant(base, imported);
158
+ if (!call) return false;
159
+ const [inner, ...configs] = call.arguments;
160
+ return configs.some((config) => carriesClaim(config)) || claims(inner, imported);
161
+ }
138
162
  /**
139
163
  * @param {string} name
140
164
  * @param {Set<string>} imported claimant names other files export
@@ -143,25 +167,22 @@ function parse(source, filename) {
143
167
  function isClaimant(name, imported) {
144
168
  if (cache.has(name)) return /** @type {boolean} */ (cache.get(name));
145
169
  cache.set(name, false);
146
- const call = styledCalls.get(name);
147
- let result = false;
148
- if (call) {
149
- const [base, ...configs] = call.arguments;
150
- result =
151
- configs.some((config) => carriesClaim(config)) ||
152
- (!!base && ts.isIdentifier(base) && isClaimant(base.text, imported));
153
- } else if (importedNames.has(name) && imported.has(name)) {
154
- result = true;
155
- }
170
+ const init = styledInits.get(name);
171
+ const result = init ? claims(init, imported) : importedNames.has(name) && imported.has(name);
156
172
  cache.set(name, result);
157
173
  return result;
158
174
  }
159
175
  /** @param {string} name */
176
+ function baseName(name) {
177
+ let { call, base } = styledSource(styledInits.get(name));
178
+ for (let hops = 0; call && hops < 8; hops++) ({ call, base } = styledSource(call.arguments[0]));
179
+ return base ?? "";
180
+ }
181
+ /** @param {string} name */
160
182
  function isInput(name) {
161
183
  for (let current = name, hops = 0; current && hops < 8; hops++) {
162
184
  if (inputTag.test(current)) return true;
163
- const base = styledCalls.get(current)?.arguments[0];
164
- current = base && ts.isIdentifier(base) ? base.text : "";
185
+ current = baseName(current);
165
186
  }
166
187
  return false;
167
188
  }
@@ -118,6 +118,53 @@ describe("exportedPressClaimants", () => {
118
118
  export { Ring };`;
119
119
  expect(exportedPressClaimants(source, "Fixture.tsx").sort()).toEqual(["Pill", "Ring"]);
120
120
  });
121
+
122
+ it("follows a named styled base under .styleable() and createStyledHOC (FZ-10909)", () => {
123
+ const source = `
124
+ const Frame = styled(View, { name: "F", pressStyle: { opacity: 0.5 } });
125
+ export const Styleable = Frame.styleable((props, ref) => <Frame {...props} ref={ref} />);
126
+ export const Typed = Frame.styleable<{ on?: boolean }>((props, ref) => <Frame ref={ref} />);
127
+ export const Hoc = createStyledHOC(Frame, (props, ref) => <Frame {...props} ref={ref} />);
128
+ const Plain = styled(View, { name: "P" });
129
+ export const Quiet = Plain.styleable((props, ref) => <Plain ref={ref} />);`;
130
+ expect(exportedPressClaimants(source, "Fixture.tsx").sort()).toEqual([
131
+ "Hoc",
132
+ "Styleable",
133
+ "Typed",
134
+ ]);
135
+ });
136
+
137
+ it("resolves a base chain two hops deep behind a named frame (FZ-10909)", () => {
138
+ const source = `
139
+ const Inner = styled(View, { focusVisibleStyle: { outlineWidth: 2 } });
140
+ const Frame = styled(Inner, { name: "F" });
141
+ export const Named = Frame.styleable((props, ref) => <Frame ref={ref} />);
142
+ const Nested = styled(styled(View, { pressStyle: { opacity: 0.5 } }), { name: "N" });
143
+ export const Inline = createStyledHOC(Nested, (props, ref) => <Nested ref={ref} />);`;
144
+ expect(exportedPressClaimants(source, "Fixture.tsx").sort()).toEqual(["Inline", "Named"]);
145
+ });
146
+
147
+ it("still skips an input reached through a named base (FZ-10909)", () => {
148
+ const source = `
149
+ const FieldFrame = styled(TextInput, { focusVisibleStyle: { outlineWidth: 2 } });
150
+ export const Field = FieldFrame.styleable((props, ref) => <FieldFrame ref={ref} />);
151
+ const AreaFrame = styled(styled(TextArea, { pressStyle: { opacity: 0.5 } }), {});
152
+ export const Area = createStyledHOC(AreaFrame, (props, ref) => <AreaFrame ref={ref} />);`;
153
+ expect(exportedPressClaimants(source, "Fixture.tsx")).toEqual([]);
154
+ });
155
+
156
+ it("flags a named-base wrapper nested in a pressable, in its file and where it is imported (FZ-10909)", () => {
157
+ const source = `
158
+ const Frame = styled(View, { pressStyle: { opacity: 0.5 } });
159
+ export const Ring = Frame.styleable((props, ref) => <Frame ref={ref} />);
160
+ export const A = () => <View onPress={go}><Ring /></View>;`;
161
+ expect(find(source)).toEqual(["Ring<View"]);
162
+ const imported = new Set<string>(exportedPressClaimants(source, "Ring.tsx"));
163
+ const consumer = `
164
+ import { Ring } from "./Ring";
165
+ export const B = () => <Pressable onPress={go}><Ring /></Pressable>;`;
166
+ expect(find(consumer, imported)).toEqual(["Ring<Pressable"]);
167
+ });
121
168
  });
122
169
 
123
170
  describe("findNativeFocusWithin (FZ-8991 NATIVE-FOCUS-WITHIN)", () => {