jsxpression 0.1.28 → 0.1.29

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.
Files changed (137) hide show
  1. package/README.md +155 -188
  2. package/lib/analyze/analysis-report.d.ts +2 -2
  3. package/lib/analyze/analysis-report.d.ts.map +1 -1
  4. package/lib/analyze/analysis-report.js +4 -0
  5. package/lib/analyze/analysis-report.js.map +1 -1
  6. package/lib/analyze/data/data-access.d.ts.map +1 -1
  7. package/lib/analyze/data/data-access.js +45 -82
  8. package/lib/analyze/data/data-access.js.map +1 -1
  9. package/lib/analyze/data/method-calls.d.ts.map +1 -1
  10. package/lib/analyze/data/method-calls.js +4 -3
  11. package/lib/analyze/data/method-calls.js.map +1 -1
  12. package/lib/analyze/data/utils.d.ts +2 -3
  13. package/lib/analyze/data/utils.d.ts.map +1 -1
  14. package/lib/analyze/data/utils.js +10 -36
  15. package/lib/analyze/data/utils.js.map +1 -1
  16. package/lib/analyze/jsx/element-attributes.d.ts +1 -1
  17. package/lib/analyze/jsx/element-attributes.d.ts.map +1 -1
  18. package/lib/analyze/jsx/element-attributes.js +13 -3
  19. package/lib/analyze/jsx/element-attributes.js.map +1 -1
  20. package/lib/analyze/jsx/element-children.d.ts +1 -1
  21. package/lib/analyze/jsx/element-children.d.ts.map +1 -1
  22. package/lib/analyze/jsx/element-children.js +16 -5
  23. package/lib/analyze/jsx/element-children.js.map +1 -1
  24. package/lib/analyze/jsx/element-tags.d.ts +1 -1
  25. package/lib/analyze/jsx/element-tags.d.ts.map +1 -1
  26. package/lib/analyze/jsx/element-tags.js +12 -2
  27. package/lib/analyze/jsx/element-tags.js.map +1 -1
  28. package/lib/analyze/security/analyze.d.ts.map +1 -1
  29. package/lib/analyze/security/analyze.js +2 -4
  30. package/lib/analyze/security/analyze.js.map +1 -1
  31. package/lib/analyze/security/call-expressions.d.ts +2 -2
  32. package/lib/analyze/security/call-expressions.d.ts.map +1 -1
  33. package/lib/analyze/security/call-expressions.js +21 -5
  34. package/lib/analyze/security/call-expressions.js.map +1 -1
  35. package/lib/analyze/security/declarations.d.ts +1 -1
  36. package/lib/analyze/security/declarations.d.ts.map +1 -1
  37. package/lib/analyze/security/declarations.js +22 -2
  38. package/lib/analyze/security/declarations.js.map +1 -1
  39. package/lib/analyze/security/expressions.d.ts.map +1 -1
  40. package/lib/analyze/security/expressions.js +10 -2
  41. package/lib/analyze/security/expressions.js.map +1 -1
  42. package/lib/analyze/security/identifiers.d.ts +2 -2
  43. package/lib/analyze/security/identifiers.d.ts.map +1 -1
  44. package/lib/analyze/security/identifiers.js +159 -19
  45. package/lib/analyze/security/identifiers.js.map +1 -1
  46. package/lib/builtins.d.ts.map +1 -1
  47. package/lib/builtins.js +5 -0
  48. package/lib/builtins.js.map +1 -1
  49. package/lib/compile/compile.d.ts.map +1 -1
  50. package/lib/compile/compile.js +131 -61
  51. package/lib/compile/compile.js.map +1 -1
  52. package/lib/evaluate/evaluate.d.ts +3 -3
  53. package/lib/evaluate/evaluate.d.ts.map +1 -1
  54. package/lib/evaluate/evaluate.js +28 -7
  55. package/lib/evaluate/evaluate.js.map +1 -1
  56. package/lib/jsx.d.ts +2 -19
  57. package/lib/jsx.d.ts.map +1 -1
  58. package/lib/jsx.js +0 -6
  59. package/lib/jsx.js.map +1 -1
  60. package/lib/parse/parse.d.ts.map +1 -1
  61. package/lib/parse/parse.js +4 -3
  62. package/lib/parse/parse.js.map +1 -1
  63. package/lib/render.d.ts +4 -4
  64. package/lib/render.d.ts.map +1 -1
  65. package/lib/render.js +7 -9
  66. package/lib/render.js.map +1 -1
  67. package/lib/schema.d.ts +2 -7
  68. package/lib/schema.d.ts.map +1 -1
  69. package/lib/schema.js +0 -43
  70. package/lib/schema.js.map +1 -1
  71. package/lib/traverse.d.ts +4 -4
  72. package/lib/traverse.d.ts.map +1 -1
  73. package/lib/traverse.js +118 -40
  74. package/lib/traverse.js.map +1 -1
  75. package/lib/validate.d.ts +1 -1
  76. package/lib/validate.js +1 -1
  77. package/package.json +4 -3
  78. package/src/analyze/analysis-report.ts +6 -2
  79. package/src/analyze/analyze.test.ts +108 -69
  80. package/src/analyze/data/data-access.ts +45 -90
  81. package/src/analyze/data/method-calls.ts +4 -3
  82. package/src/analyze/data/utils.ts +11 -40
  83. package/src/analyze/jsx/element-attributes.ts +24 -9
  84. package/src/analyze/jsx/element-children.ts +20 -6
  85. package/src/analyze/jsx/element-tags.ts +15 -3
  86. package/src/analyze/security/analyze.ts +1 -3
  87. package/src/analyze/security/call-expressions.ts +37 -17
  88. package/src/analyze/security/declarations.ts +35 -9
  89. package/src/analyze/security/expressions.ts +17 -3
  90. package/src/analyze/security/identifiers.ts +172 -28
  91. package/src/builtins.ts +6 -0
  92. package/src/codegen/generate-typescript-definitions.test.ts +16 -23
  93. package/src/compile/compile.test.ts +153 -30
  94. package/src/compile/compile.ts +163 -73
  95. package/src/evaluate/evaluate.test.ts +276 -14
  96. package/src/evaluate/evaluate.ts +34 -10
  97. package/src/jsx.ts +2 -31
  98. package/src/parse/parse.test.ts +4 -4
  99. package/src/parse/parse.ts +4 -3
  100. package/src/render.test.ts +476 -27
  101. package/src/render.ts +7 -14
  102. package/src/schema.ts +1 -55
  103. package/src/traverse.ts +135 -49
  104. package/src/validate.ts +1 -1
  105. package/LICENSE +0 -21
  106. package/lib/analyze/analyze.test.d.ts +0 -2
  107. package/lib/analyze/analyze.test.d.ts.map +0 -1
  108. package/lib/analyze/analyze.test.js +0 -763
  109. package/lib/analyze/analyze.test.js.map +0 -1
  110. package/lib/analyze/security/member-access.d.ts +0 -6
  111. package/lib/codegen/generate-typescript-definitions.test.d.ts +0 -2
  112. package/lib/codegen/generate-typescript-definitions.test.d.ts.map +0 -1
  113. package/lib/codegen/generate-typescript-definitions.test.js +0 -649
  114. package/lib/codegen/generate-typescript-definitions.test.js.map +0 -1
  115. package/lib/compile/compile.test.d.ts +0 -2
  116. package/lib/compile/compile.test.d.ts.map +0 -1
  117. package/lib/compile/compile.test.js +0 -146
  118. package/lib/compile/compile.test.js.map +0 -1
  119. package/lib/evaluate/evaluate.test.d.ts +0 -2
  120. package/lib/evaluate/evaluate.test.d.ts.map +0 -1
  121. package/lib/evaluate/evaluate.test.js +0 -260
  122. package/lib/evaluate/evaluate.test.js.map +0 -1
  123. package/lib/parse/parse.test.d.ts +0 -2
  124. package/lib/parse/parse.test.d.ts.map +0 -1
  125. package/lib/parse/parse.test.js +0 -80
  126. package/lib/parse/parse.test.js.map +0 -1
  127. package/lib/render.test.d.ts +0 -2
  128. package/lib/render.test.d.ts.map +0 -1
  129. package/lib/render.test.js +0 -301
  130. package/lib/render.test.js.map +0 -1
  131. package/lib/traverse.test.d.ts +0 -2
  132. package/lib/traverse.test.d.ts.map +0 -1
  133. package/lib/traverse.test.js +0 -84
  134. package/lib/traverse.test.js.map +0 -1
  135. package/lib/types.d.ts +0 -12
  136. package/src/analyze/security/member-access.ts +0 -35
  137. package/src/types.ts +0 -17
@@ -1,8 +1,8 @@
1
- import { describe, it, expect } from "vitest";
2
- import { analyze } from "./analyze.js";
3
- import { parse } from "../parse/index.js";
4
- import { type Schema } from "../schema.js";
1
+ import { describe, expect, it } from "vitest";
5
2
  import { getBuiltins } from "../builtins.js";
3
+ import { parse } from "../parse/index.js";
4
+ import type { Schema } from "../schema.js";
5
+ import { analyze } from "./analyze.js";
6
6
 
7
7
  describe("analyze - consolidated tests", () => {
8
8
  const baseSchema = {
@@ -75,66 +75,66 @@ describe("analyze - consolidated tests", () => {
75
75
  describe("data access validation", () => {
76
76
  describe("basic data access", () => {
77
77
  it("should allow valid data access", () => {
78
- const ast = parse("<Text>{data.user.name}</Text>");
78
+ const ast = parse("<Text>{user.name}</Text>");
79
79
  const result = analyze(ast, baseSchema);
80
80
  expect(result.hasErrors).toBe(false);
81
81
  });
82
82
 
83
83
  it("should allow nested object access", () => {
84
- const ast = parse("<Text>{data.user.profile.avatar}</Text>");
84
+ const ast = parse("<Text>{user.profile.avatar}</Text>");
85
85
  const result = analyze(ast, baseSchema);
86
86
  expect(result.hasErrors).toBe(false);
87
87
  });
88
88
 
89
89
  it("should block invalid data properties", () => {
90
- const ast = parse("<Text>{data.user.invalid}</Text>");
90
+ const ast = parse("<Text>{user.invalid}</Text>");
91
91
  const result = analyze(ast, baseSchema);
92
92
  expect(result.hasErrors).toBe(true);
93
- expect(result.errors[0].message).toContain("Property 'data.user.invalid' does not exist in schema");
93
+ expect(result.errors[0].message).toContain("Property 'user.invalid' does not exist in schema");
94
94
  });
95
95
 
96
96
  it("should block invalid nested properties", () => {
97
- const ast = parse("<Text>{data.user.profile.invalid}</Text>");
97
+ const ast = parse("<Text>{user.profile.invalid}</Text>");
98
98
  const result = analyze(ast, baseSchema);
99
99
  expect(result.hasErrors).toBe(true);
100
- expect(result.errors[0].message).toContain("Property 'data.user.profile.invalid' does not exist in schema");
100
+ expect(result.errors[0].message).toContain("Property 'user.profile.invalid' does not exist in schema");
101
101
  });
102
102
  });
103
103
 
104
104
  describe("array access", () => {
105
105
  it("should allow array access with valid methods", () => {
106
- const ast = parse("<Text>{data.items.map(item => item)}</Text>");
106
+ const ast = parse("<Text>{items.map(item => item)}</Text>");
107
107
  const result = analyze(ast, baseSchema);
108
108
  expect(result.hasErrors).toBe(false);
109
109
  });
110
110
 
111
111
  it("should allow numeric array index access", () => {
112
- const ast = parse("<Text>{data.items[0]}</Text>");
112
+ const ast = parse("<Text>{items[0]}</Text>");
113
113
  const result = analyze(ast, baseSchema);
114
114
  expect(result.hasErrors).toBe(false);
115
115
  });
116
116
 
117
117
  it("should allow various numeric array indices", () => {
118
- const ast = parse("<Text>{data.items[42]} and {data.numbers[1]}</Text>");
118
+ const ast = parse("<Text>{items[42]} and {numbers[1]}</Text>");
119
119
  const result = analyze(ast, baseSchema);
120
120
  expect(result.hasErrors).toBe(false);
121
121
  });
122
122
 
123
123
  it("should allow nested array access with indices", () => {
124
- const ast = parse("<Text>{data.products[0].tags[1]}</Text>");
124
+ const ast = parse("<Text>{products[0].tags[1]}</Text>");
125
125
  const result = analyze(ast, baseSchema);
126
126
  expect(result.hasErrors).toBe(false);
127
127
  });
128
128
 
129
129
  it("should require array indices for nested object access", () => {
130
- const ast = parse("<Text>{data.products.tags}</Text>");
130
+ const ast = parse("<Text>{products.tags}</Text>");
131
131
  const result = analyze(ast, baseSchema);
132
132
  expect(result.hasErrors).toBe(true);
133
- expect(result.errors[0].message).toContain("data.products.tags");
133
+ expect(result.errors[0].message).toContain("products.tags");
134
134
  });
135
135
 
136
136
  it("should detect typos on array properties", () => {
137
- const ast = parse("<Text>{data.departments.lengdth}</Text>");
137
+ const ast = parse("<Text>{departments.lengdth}</Text>");
138
138
  const result = analyze(ast, baseSchema);
139
139
  expect(result.hasErrors).toBe(true);
140
140
  expect(result.errors[0].code).toBe("INVALID_DATA_ACCESS");
@@ -142,31 +142,31 @@ describe("analyze - consolidated tests", () => {
142
142
  });
143
143
 
144
144
  it("should allow string members on array elements", () => {
145
- const ast = parse("<Text>{data.items[0].length}</Text>");
145
+ const ast = parse("<Text>{items[0].length}</Text>");
146
146
  const result = analyze(ast, baseSchema);
147
147
  expect(result.hasErrors).toBe(false);
148
148
  });
149
149
 
150
150
  it("should allow array.at() method with positive index", () => {
151
- const ast = parse("<Text>{data.items.at(0)}</Text>");
151
+ const ast = parse("<Text>{items.at(0)}</Text>");
152
152
  const result = analyze(ast, baseSchema);
153
153
  expect(result.hasErrors).toBe(false);
154
154
  });
155
155
 
156
156
  it("should allow array.at() method with negative index", () => {
157
- const ast = parse("<Text>{data.items.at(-1)}</Text>");
157
+ const ast = parse("<Text>{items.at(-1)}</Text>");
158
158
  const result = analyze(ast, baseSchema);
159
159
  expect(result.hasErrors).toBe(false);
160
160
  });
161
161
 
162
162
  it("should allow array.at() method in complex expressions", () => {
163
- const ast = parse("<Text>{data.products.at(-1).name}</Text>");
163
+ const ast = parse("<Text>{products.at(-1).name}</Text>");
164
164
  const result = analyze(ast, baseSchema);
165
165
  expect(result.hasErrors).toBe(false);
166
166
  });
167
167
 
168
168
  it("should block dynamic array access with variables", () => {
169
- const ast = parse("<Text>{data.items[variable]}</Text>");
169
+ const ast = parse("<Text>{items[variable]}</Text>");
170
170
  const result = analyze(ast, baseSchema);
171
171
  expect(result.hasErrors).toBe(true);
172
172
  expect(result.errors.some((e) => e.message.includes("variable") || e.message.includes("not allowed"))).toBe(
@@ -175,55 +175,55 @@ describe("analyze - consolidated tests", () => {
175
175
  });
176
176
 
177
177
  it("should block string-based computed access on objects", () => {
178
- const ast = parse("<Text>{data.user['name']}</Text>");
178
+ const ast = parse("<Text>{user['name']}</Text>");
179
179
  const result = analyze(ast, baseSchema);
180
180
  expect(result.hasErrors).toBe(true);
181
181
  expect(result.errors.some((e) => e.message.includes("computed member access not allowed"))).toBe(true);
182
182
  });
183
183
 
184
184
  it("should block mutating array methods", () => {
185
- const ast = parse("<Text>{data.items.push('new')}</Text>");
185
+ const ast = parse("<Text>{items.push('new')}</Text>");
186
186
  const result = analyze(ast, baseSchema);
187
187
  expect(result.hasErrors).toBe(true);
188
- expect(result.errors[0].message).toContain("method .push not allowed");
188
+ expect(result.errors[0].message).toContain("method items.push not allowed");
189
189
  });
190
190
  });
191
191
 
192
192
  describe("arrow function parameter validation", () => {
193
193
  it("should validate arrow function parameters - valid access", () => {
194
- const ast = parse("<Text>{data.products.map((product, i) => product.name)}</Text>");
194
+ const ast = parse("<Text>{products.map((product, i) => product.name)}</Text>");
195
195
  const result = analyze(ast, baseSchema);
196
196
  expect(result.hasErrors).toBe(false);
197
197
  });
198
198
 
199
199
  it("should validate arrow function parameters - invalid property", () => {
200
- const ast = parse("<Text>{data.products.map((product, i) => product.invalid)}</Text>");
200
+ const ast = parse("<Text>{products.map((product, i) => product.invalid)}</Text>");
201
201
  const result = analyze(ast, baseSchema);
202
202
  expect(result.hasErrors).toBe(true);
203
203
  expect(result.errors[0].message).toContain("Property 'invalid' does not exist on parameter 'product'");
204
204
  });
205
205
 
206
206
  it("should validate nested arrow functions", () => {
207
- const ast = parse("<Text>{data.products.map(product => product.tags.map(tag => tag))}</Text>");
207
+ const ast = parse("<Text>{products.map(product => product.tags.map(tag => tag))}</Text>");
208
208
  const result = analyze(ast, baseSchema);
209
209
  expect(result.hasErrors).toBe(false);
210
210
  });
211
211
 
212
212
  it("should catch errors in nested arrow functions", () => {
213
- const ast = parse("<Text>{data.products.map(product => product.tags.map(tag => tag.invalid))}</Text>");
213
+ const ast = parse("<Text>{products.map(product => product.tags.map(tag => tag.invalid))}</Text>");
214
214
  const result = analyze(ast, baseSchema);
215
215
  expect(result.hasErrors).toBe(true);
216
216
  expect(result.errors[0].message).toContain("Cannot access property 'invalid' on string type");
217
217
  });
218
218
 
219
219
  it("should validate index parameters", () => {
220
- const ast = parse("<Text>{data.items.map((item, i) => i + 1)}</Text>");
220
+ const ast = parse("<Text>{items.map((item, i) => i + 1)}</Text>");
221
221
  const result = analyze(ast, baseSchema);
222
222
  expect(result.hasErrors).toBe(false);
223
223
  });
224
224
 
225
225
  it("should catch invalid index parameter access", () => {
226
- const ast = parse("<Text>{data.items.map((item, i) => i.invalid)}</Text>");
226
+ const ast = parse("<Text>{items.map((item, i) => i.invalid)}</Text>");
227
227
  const result = analyze(ast, baseSchema);
228
228
  expect(result.hasErrors).toBe(true);
229
229
  expect(result.errors[0].message).toContain("Cannot access property 'invalid' on number type");
@@ -231,7 +231,7 @@ describe("analyze - consolidated tests", () => {
231
231
 
232
232
  it("should handle complex nested scenarios", () => {
233
233
  const ast = parse(
234
- "<Text>{data.departments.map((dept) => dept.employees.map((employee) => employee.salary))}</Text>"
234
+ "<Text>{departments.map((dept) => dept.employees.map((employee) => employee.salary))}</Text>"
235
235
  );
236
236
  const result = analyze(ast, baseSchema);
237
237
  expect(result.hasErrors).toBe(false);
@@ -239,7 +239,7 @@ describe("analyze - consolidated tests", () => {
239
239
 
240
240
  it("should detect typos in complex nested scenarios", () => {
241
241
  const ast = parse(
242
- "<Text>{data.departments.map((dept) => dept.employees.map((employee) => employee.saladry))}</Text>"
242
+ "<Text>{departments.map((dept) => dept.employees.map((employee) => employee.saladry))}</Text>"
243
243
  );
244
244
  const result = analyze(ast, baseSchema);
245
245
  expect(result.hasErrors).toBe(true);
@@ -277,39 +277,39 @@ describe("analyze - consolidated tests", () => {
277
277
  } else if (objectName === "Array.prototype") {
278
278
  // Array methods
279
279
  if (methodName === "map" || methodName === "filter") {
280
- testExpression = `<Text>{data.items.${methodName}(x => x)}</Text>`;
280
+ testExpression = `<Text>{items.${methodName}(x => x)}</Text>`;
281
281
  } else if (methodName === "reduce") {
282
- testExpression = `<Text>{data.numbers.${methodName}((a, b) => a + b, 0)}</Text>`;
282
+ testExpression = `<Text>{numbers.${methodName}((a, b) => a + b, 0)}</Text>`;
283
283
  } else if (methodName === "slice") {
284
- testExpression = `<Text>{data.items.${methodName}(0, 2)}</Text>`;
284
+ testExpression = `<Text>{items.${methodName}(0, 2)}</Text>`;
285
285
  } else if (methodName === "join") {
286
- testExpression = `<Text>{data.items.${methodName}(", ")}</Text>`;
286
+ testExpression = `<Text>{items.${methodName}(", ")}</Text>`;
287
287
  } else if (methodName === "includes" || methodName === "indexOf") {
288
- testExpression = `<Text>{data.items.${methodName}("test")}</Text>`;
288
+ testExpression = `<Text>{items.${methodName}("test")}</Text>`;
289
289
  } else if (methodName === "find" || methodName === "some" || methodName === "every") {
290
290
  // These methods need proper boolean-returning callbacks
291
- testExpression = `<Text>{data.items.${methodName}(x => x === "test")}</Text>`;
291
+ testExpression = `<Text>{items.${methodName}(x => x === "test")}</Text>`;
292
292
  } else {
293
293
  // Other array methods with basic usage
294
- testExpression = `<Text>{data.items.${methodName}(x => x.length > 0)}</Text>`;
294
+ testExpression = `<Text>{items.${methodName}(x => x.length > 0)}</Text>`;
295
295
  }
296
296
  } else if (objectName === "String.prototype") {
297
297
  // String methods
298
298
  if (methodName === "charAt" || methodName === "charCodeAt") {
299
- testExpression = `<Text>{data.text.${methodName}(0)}</Text>`;
299
+ testExpression = `<Text>{text.${methodName}(0)}</Text>`;
300
300
  } else if (methodName === "slice" || methodName === "substring") {
301
- testExpression = `<Text>{data.text.${methodName}(0, 5)}</Text>`;
301
+ testExpression = `<Text>{text.${methodName}(0, 5)}</Text>`;
302
302
  } else if (methodName === "indexOf" || methodName === "lastIndexOf") {
303
- testExpression = `<Text>{data.text.${methodName}("test")}</Text>`;
303
+ testExpression = `<Text>{text.${methodName}("test")}</Text>`;
304
304
  } else if (methodName === "split") {
305
- testExpression = `<Text>{data.text.${methodName}(",")}</Text>`;
305
+ testExpression = `<Text>{text.${methodName}(",")}</Text>`;
306
306
  } else if (methodName === "concat") {
307
- testExpression = `<Text>{data.text.${methodName}(" world")}</Text>`;
307
+ testExpression = `<Text>{text.${methodName}(" world")}</Text>`;
308
308
  } else if (methodName === "includes" || methodName === "startsWith" || methodName === "endsWith") {
309
- testExpression = `<Text>{data.text.${methodName}("test")}</Text>`;
309
+ testExpression = `<Text>{text.${methodName}("test")}</Text>`;
310
310
  } else {
311
311
  // Methods with no parameters like trim, toLowerCase
312
- testExpression = `<Text>{data.text.${methodName}()}</Text>`;
312
+ testExpression = `<Text>{text.${methodName}()}</Text>`;
313
313
  }
314
314
  } else {
315
315
  // Fallback
@@ -332,9 +332,9 @@ describe("analyze - consolidated tests", () => {
332
332
  if (objectName === "Math") {
333
333
  testExpression = `<Text>{Math.${methodName}()}</Text>`;
334
334
  } else if (objectName === "Array.prototype") {
335
- testExpression = `<Text>{data.items.${methodName}()}</Text>`;
335
+ testExpression = `<Text>{items.${methodName}()}</Text>`;
336
336
  } else if (objectName === "String.prototype") {
337
- testExpression = `<Text>{data.text.${methodName}()}</Text>`;
337
+ testExpression = `<Text>{text.${methodName}()}</Text>`;
338
338
  } else {
339
339
  testExpression = `<Text>{${objectName}.${methodName}()}</Text>`;
340
340
  }
@@ -363,12 +363,12 @@ describe("analyze - consolidated tests", () => {
363
363
  testExpression = `<Text>{Math.${methodName}(${extraParams})}</Text>`;
364
364
  } else if (objectName === "Array.prototype") {
365
365
  if (methodName === "map" || methodName === "filter") {
366
- testExpression = `<Text>{data.items.${methodName}(x => x, {}, ${extraParams})}</Text>`;
366
+ testExpression = `<Text>{items.${methodName}(x => x, {}, ${extraParams})}</Text>`;
367
367
  } else {
368
- testExpression = `<Text>{data.items.${methodName}(${extraParams})}</Text>`;
368
+ testExpression = `<Text>{items.${methodName}(${extraParams})}</Text>`;
369
369
  }
370
370
  } else if (objectName === "String.prototype") {
371
- testExpression = `<Text>{data.text.${methodName}(${extraParams})}</Text>`;
371
+ testExpression = `<Text>{text.${methodName}(${extraParams})}</Text>`;
372
372
  } else {
373
373
  testExpression = `<Text>{${objectName}.${methodName}(${extraParams})}</Text>`;
374
374
  }
@@ -396,9 +396,9 @@ describe("analyze - consolidated tests", () => {
396
396
  let testExpression: string;
397
397
 
398
398
  if (objectName === "Array.prototype") {
399
- testExpression = `<Text>{data.items.${propName}}</Text>`;
399
+ testExpression = `<Text>{items.${propName}}</Text>`;
400
400
  } else if (objectName === "String.prototype") {
401
- testExpression = `<Text>{data.text.${propName}}</Text>`;
401
+ testExpression = `<Text>{text.${propName}}</Text>`;
402
402
  } else {
403
403
  testExpression = `<Text>{${objectName}.${propName}}</Text>`;
404
404
  }
@@ -417,10 +417,10 @@ describe("analyze - consolidated tests", () => {
417
417
  const blockedMethods = ["push", "pop", "shift", "unshift", "splice", "reverse", "sort"];
418
418
 
419
419
  blockedMethods.forEach((method) => {
420
- const ast = parse(`<Text>{data.items.${method}()}</Text>`);
420
+ const ast = parse(`<Text>{items.${method}()}</Text>`);
421
421
  const result = analyze(ast, baseSchema);
422
422
  expect(result.hasErrors).toBe(true);
423
- expect(result.errors[0].message).toContain(`method .${method} not allowed`);
423
+ expect(result.errors[0].message).toContain(`method items.${method} not allowed`);
424
424
  });
425
425
  });
426
426
 
@@ -451,12 +451,12 @@ describe("analyze - consolidated tests", () => {
451
451
  };
452
452
 
453
453
  // Math.max should work with default builtins
454
- const ast1 = parse("<Text>{Math.max(data.value, 10)}</Text>");
454
+ const ast1 = parse("<Text>{Math.max(value, 10)}</Text>");
455
455
  const result1 = analyze(ast1, customSchema);
456
456
  expect(result1.hasErrors).toBe(false);
457
457
 
458
458
  // Math.min should also work since we use BUILTINS
459
- const ast2 = parse("<Text>{Math.min(data.value, 10)}</Text>");
459
+ const ast2 = parse("<Text>{Math.min(value, 10)}</Text>");
460
460
  const result2 = analyze(ast2, customSchema);
461
461
  expect(result2.hasErrors).toBe(false);
462
462
  });
@@ -471,11 +471,11 @@ describe("analyze - consolidated tests", () => {
471
471
  },
472
472
  };
473
473
 
474
- const ast1 = parse("<Text>{data.text.toUpperCase()}</Text>");
474
+ const ast1 = parse("<Text>{text.toUpperCase()}</Text>");
475
475
  const result1 = analyze(ast1, customSchema);
476
476
  expect(result1.hasErrors).toBe(false);
477
477
 
478
- const ast2 = parse("<Text>{data.text.toLowerCase()}</Text>");
478
+ const ast2 = parse("<Text>{text.toLowerCase()}</Text>");
479
479
  const result2 = analyze(ast2, customSchema);
480
480
  expect(result2.hasErrors).toBe(false);
481
481
  });
@@ -492,7 +492,7 @@ describe("analyze - consolidated tests", () => {
492
492
  };
493
493
 
494
494
  // Should work with default builtin schema
495
- const ast = parse("<Text>{Math.max(data.x, 10)}</Text>");
495
+ const ast = parse("<Text>{Math.max(x, 10)}</Text>");
496
496
  const result = analyze(ast, schemaWithoutBuiltins);
497
497
  expect(result.hasErrors).toBe(false);
498
498
  });
@@ -587,7 +587,7 @@ describe("analyze - consolidated tests", () => {
587
587
  },
588
588
  };
589
589
 
590
- const ast = parse("<Card {...data.props} />");
590
+ const ast = parse("<Card {...props} />");
591
591
  const result = analyze(ast, schema);
592
592
  expect(result.hasErrors).toBe(false);
593
593
  });
@@ -618,7 +618,7 @@ describe("analyze - consolidated tests", () => {
618
618
  },
619
619
  };
620
620
 
621
- const ast = parse("<Text {...data.user.attributes} />");
621
+ const ast = parse("<Text {...user.attributes} />");
622
622
  const result = analyze(ast, schema);
623
623
  expect(result.hasErrors).toBe(false);
624
624
  });
@@ -656,7 +656,7 @@ describe("analyze - consolidated tests", () => {
656
656
  },
657
657
  };
658
658
 
659
- const ast = parse("<div>{data.items.map(item => <Item {...item.props} />)}</div>");
659
+ const ast = parse("<div>{items.map(item => <Item {...item.props} />)}</div>");
660
660
  const result = analyze(ast, schema);
661
661
  expect(result.hasErrors).toBe(false);
662
662
  });
@@ -688,7 +688,7 @@ describe("analyze - consolidated tests", () => {
688
688
  },
689
689
  };
690
690
 
691
- const ast = parse("<div>{data.items.map(item => <Item {...item} />)}</div>");
691
+ const ast = parse("<div>{items.map(item => <Item {...item} />)}</div>");
692
692
  const result = analyze(ast, schema);
693
693
  expect(result.hasErrors).toBe(false);
694
694
  });
@@ -713,7 +713,7 @@ describe("analyze - consolidated tests", () => {
713
713
  },
714
714
  };
715
715
 
716
- const ast = parse("<Card {...data.props} highlighted={true} />");
716
+ const ast = parse("<Card {...props} highlighted={true} />");
717
717
  const result = analyze(ast, schema);
718
718
  expect(result.hasErrors).toBe(false);
719
719
  });
@@ -744,7 +744,7 @@ describe("analyze - consolidated tests", () => {
744
744
  },
745
745
  };
746
746
 
747
- const ast = parse("<Card {...data.baseProps} {...data.extraProps} />");
747
+ const ast = parse("<Card {...baseProps} {...extraProps} />");
748
748
  const result = analyze(ast, schema);
749
749
  expect(result.hasErrors).toBe(false);
750
750
  });
@@ -764,7 +764,7 @@ describe("analyze - consolidated tests", () => {
764
764
  });
765
765
 
766
766
  it("should allow empty expressions mixed with content in children", () => {
767
- const ast = parse("<Text>Hello {}{data.user.name}{} World</Text>");
767
+ const ast = parse("<Text>Hello {}{user.name}{} World</Text>");
768
768
  const result = analyze(ast, baseSchema);
769
769
  expect(result.hasErrors).toBe(false);
770
770
  });
@@ -817,7 +817,7 @@ describe("analyze - consolidated tests", () => {
817
817
  it("should catch multiple errors in complex expressions", () => {
818
818
  const ast = parse(`
819
819
  <InvalidElement>
820
- <Text>{data.user.invalid}</Text>
820
+ <Text>{user.invalid}</Text>
821
821
  <span>{window.location}</span>
822
822
  </InvalidElement>
823
823
  `);
@@ -826,4 +826,43 @@ describe("analyze - consolidated tests", () => {
826
826
  expect(result.errors.length).toBeGreaterThan(1);
827
827
  });
828
828
  });
829
+
830
+ describe("return requirement", () => {
831
+ it("should allow bare JSX without return (no declarations)", () => {
832
+ const ast = parse("<Text>hello</Text>");
833
+ const result = analyze(ast, baseSchema);
834
+ expect(result.issues.filter((i) => i.code === "RETURN_REQUIRED")).toHaveLength(0);
835
+ });
836
+
837
+ it("should require return when const is present", () => {
838
+ const ast = parse("const x = 1;\n<Text>hello</Text>");
839
+ const result = analyze(ast, baseSchema);
840
+ expect(result.issues.some((i) => i.code === "RETURN_REQUIRED")).toBe(true);
841
+ });
842
+
843
+ it("should allow const + return", () => {
844
+ const ast = parse("const x = 1\nreturn <Text>hello</Text>");
845
+ const result = analyze(ast, baseSchema);
846
+ expect(result.issues.filter((i) => i.code === "RETURN_REQUIRED")).toHaveLength(0);
847
+ });
848
+
849
+ it("should require return when function is present", () => {
850
+ const ast = parse("function Foo() {\n return <Text>hi</Text>\n}\n<Foo />");
851
+ const result = analyze(ast, baseSchema);
852
+ expect(result.issues.some((i) => i.code === "RETURN_REQUIRED")).toBe(true);
853
+ });
854
+
855
+ it("should allow function + return", () => {
856
+ const ast = parse("function Foo() {\n return <Text>hi</Text>\n}\nreturn <Foo />");
857
+ const result = analyze(ast, baseSchema);
858
+ expect(result.issues.filter((i) => i.code === "RETURN_REQUIRED")).toHaveLength(0);
859
+ });
860
+
861
+ it("should give helpful message for bare JSX after declarations", () => {
862
+ const ast = parse("const x = 1;\n<Text>hello</Text>");
863
+ const result = analyze(ast, baseSchema);
864
+ const issue = result.issues.find((i) => i.code === "RETURN_REQUIRED");
865
+ expect(issue?.message).toContain("Add 'return' before the JSX");
866
+ });
867
+ });
829
868
  });