@barefootjs/jsx 0.31.3 → 0.31.4

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 (52) hide show
  1. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  2. package/dist/adapters/template-imports.d.ts +27 -15
  3. package/dist/adapters/template-imports.d.ts.map +1 -1
  4. package/dist/debug.d.ts.map +1 -1
  5. package/dist/identifier-pattern.d.ts +62 -0
  6. package/dist/identifier-pattern.d.ts.map +1 -0
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +226 -163
  10. package/dist/ir-to-client-js/collect-elements.d.ts +23 -2
  11. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  12. package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts.map +1 -1
  13. package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
  14. package/dist/ir-to-client-js/csr-substitute.d.ts +12 -1
  15. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  16. package/dist/ir-to-client-js/html-template.d.ts +20 -12
  17. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  18. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  19. package/dist/ir-to-client-js/prop-handling.d.ts +25 -2
  20. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  21. package/dist/ir-to-client-js/reactivity.d.ts +30 -2
  22. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  23. package/dist/ir-to-client-js/rewrite-props-object.d.ts.map +1 -1
  24. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  25. package/dist/jsx-to-ir.d.ts.map +1 -1
  26. package/dist/module-exports.d.ts.map +1 -1
  27. package/dist/relocate.d.ts.map +1 -1
  28. package/package.json +2 -2
  29. package/src/__tests__/binding-scope-ratchet.test.ts +1 -1
  30. package/src/__tests__/csr-materialize-loop-preamble-shadow.test.ts +76 -0
  31. package/src/__tests__/csr-substitute-enclosing-scope.test.ts +77 -0
  32. package/src/__tests__/identifier-pattern.test.ts +170 -0
  33. package/src/__tests__/loop-child-reactive-attr-const-shadow.test.ts +107 -0
  34. package/src/__tests__/rewrite-dynamic-imports.test.ts +98 -0
  35. package/src/adapters/jsx-adapter.ts +2 -1
  36. package/src/adapters/template-imports.ts +93 -0
  37. package/src/debug.ts +4 -3
  38. package/src/identifier-pattern.ts +79 -0
  39. package/src/index.ts +1 -1
  40. package/src/ir-to-client-js/collect-elements.ts +44 -15
  41. package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +2 -1
  42. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +2 -1
  43. package/src/ir-to-client-js/csr-substitute.ts +19 -2
  44. package/src/ir-to-client-js/html-template.ts +37 -31
  45. package/src/ir-to-client-js/imports.ts +2 -1
  46. package/src/ir-to-client-js/prop-handling.ts +28 -1
  47. package/src/ir-to-client-js/reactivity.ts +54 -4
  48. package/src/ir-to-client-js/rewrite-props-object.ts +2 -1
  49. package/src/ir-to-client-js/utils.ts +9 -8
  50. package/src/jsx-to-ir.ts +18 -9
  51. package/src/module-exports.ts +3 -2
  52. package/src/relocate.ts +2 -1
package/src/jsx-to-ir.ts CHANGED
@@ -63,6 +63,7 @@ import { reconstructAsSegments } from './strip-types.ts'
63
63
  import { templatePartsToJsExpr } from './template-parts.ts'
64
64
  import { toHTMLAttrName, decodeEntities } from '@barefootjs/shared'
65
65
  import { BindingScope } from './scope/binding-scope.ts'
66
+ import { identifierPattern, identifierCallPattern } from './identifier-pattern.ts'
66
67
 
67
68
  // =============================================================================
68
69
  // Transform Context
@@ -681,19 +682,19 @@ function createTransformContext(analyzer: AnalyzerContext): TransformContext {
681
682
  patterns: {
682
683
  signals: analyzer.signals.map(s => ({
683
684
  getter: s.getter,
684
- pattern: new RegExp(`\\b${s.getter}\\s*\\(`),
685
+ pattern: identifierCallPattern(s.getter),
685
686
  })),
686
687
  memos: analyzer.memos.map(m => ({
687
688
  name: m.name,
688
- pattern: new RegExp(`\\b${m.name}\\s*\\(`),
689
+ pattern: identifierCallPattern(m.name),
689
690
  })),
690
691
  props: analyzer.propsParams
691
692
  .filter(p => p.name !== 'children')
692
- .map(p => ({ name: p.name, pattern: new RegExp(`\\b${p.name}\\b`) })),
693
+ .map(p => ({ name: p.name, pattern: identifierPattern(p.name) })),
693
694
  constants: analyzer.localConstants.map(c => ({
694
695
  name: c.name,
695
696
  value: c.value,
696
- pattern: new RegExp(`\\b${c.name}\\b`),
697
+ pattern: identifierPattern(c.name),
697
698
  })),
698
699
  },
699
700
  getJS(node: ts.Node): string {
@@ -2201,7 +2202,7 @@ function transformExpressionInner(
2201
2202
  // (#2482 Stage 1a Commit 2).
2202
2203
  const scopeValueNames = ctx.scope.valueBoundNames()
2203
2204
  const refsLoopParam = scopeValueNames.size > 0
2204
- && Array.from(scopeValueNames).some(p => new RegExp(`\\b${p}\\b`).test(exprText))
2205
+ && Array.from(scopeValueNames).some(p => identifierPattern(p).test(exprText))
2205
2206
 
2206
2207
  // Compute AST-derived flags. `callsReactive` recognises signal-getter / memo
2207
2208
  // calls even inside deeper expressions (e.g., `format(count())`); `hasCalls`
@@ -2267,7 +2268,11 @@ function transformJsxFunctionCall(
2267
2268
  const substitutedGetJS = (node: ts.Node) => {
2268
2269
  let text = baseGetJS(node)
2269
2270
  for (const [paramName, argExpr] of substitutions) {
2270
- text = text.replace(new RegExp(`\\b${paramName}\\b`, 'g'), argExpr)
2271
+ // Replacer function, not the string form: `argExpr` is arbitrary
2272
+ // caller-supplied JS text and may itself contain `$` sequences
2273
+ // (`$&`, `$1`, …) that `String.replace`'s string-replacement form
2274
+ // would interpret specially instead of inserting literally (#2592).
2275
+ text = text.replace(identifierPattern(paramName, 'g'), () => argExpr)
2271
2276
  }
2272
2277
  return text
2273
2278
  }
@@ -2319,7 +2324,11 @@ function transformMultiReturnJsxFunctionCall(
2319
2324
  const substitutedGetJS = (node: ts.Node) => {
2320
2325
  let text = baseGetJS(node)
2321
2326
  for (const [paramName, argExpr] of substitutions) {
2322
- text = text.replace(new RegExp(`\\b${paramName}\\b`, 'g'), argExpr)
2327
+ // Replacer function, not the string form: `argExpr` is arbitrary
2328
+ // caller-supplied JS text and may itself contain `$` sequences
2329
+ // (`$&`, `$1`, …) that `String.replace`'s string-replacement form
2330
+ // would interpret specially instead of inserting literally (#2592).
2331
+ text = text.replace(identifierPattern(paramName, 'g'), () => argExpr)
2323
2332
  }
2324
2333
  return text
2325
2334
  }
@@ -7104,7 +7113,7 @@ function referencesLoopParam(expr: string, ctx: TransformContext): boolean {
7104
7113
  const boundNames = ctx.scope.valueBoundNames()
7105
7114
  if (boundNames.size === 0) return false
7106
7115
  for (const p of boundNames) {
7107
- if (new RegExp(`\\b${p}\\b`).test(expr)) return true
7116
+ if (identifierPattern(p).test(expr)) return true
7108
7117
  }
7109
7118
  return false
7110
7119
  }
@@ -7238,7 +7247,7 @@ function hasReactiveAttributes(attrs: IRAttribute[], ctx: TransformContext): boo
7238
7247
  const scopeValueNames = ctx.scope.valueBoundNames()
7239
7248
  if (scopeValueNames.size > 0) {
7240
7249
  for (const p of scopeValueNames) {
7241
- if (new RegExp(`\\b${p}\\b`).test(valueToCheck)) return true
7250
+ if (identifierPattern(p).test(valueToCheck)) return true
7242
7251
  }
7243
7252
  }
7244
7253
  }
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import type { ComponentIR, ParamInfo } from './types.ts'
9
+ import { identifierPattern } from './identifier-pattern.ts'
9
10
 
10
11
  /**
11
12
  * Emit module-level exports for local declarations and `export { ... } [from '...']`
@@ -140,7 +141,7 @@ export function findReachableNames(
140
141
  const queue: string[] = []
141
142
 
142
143
  for (const name of allNames) {
143
- if (new RegExp(`\\b${name}\\b`).test(primaryRefs)) {
144
+ if (identifierPattern(name).test(primaryRefs)) {
144
145
  reachable.add(name)
145
146
  queue.push(name)
146
147
  }
@@ -150,7 +151,7 @@ export function findReachableNames(
150
151
  const current = queue.shift()!
151
152
  const body = bodyMap.get(current) || ''
152
153
  for (const name of allNames) {
153
- if (!reachable.has(name) && new RegExp(`\\b${name}\\b`).test(body)) {
154
+ if (!reachable.has(name) && identifierPattern(name).test(body)) {
154
155
  reachable.add(name)
155
156
  queue.push(name)
156
157
  }
package/src/relocate.ts CHANGED
@@ -22,6 +22,7 @@ import type {
22
22
  } from './adapters/interface.ts'
23
23
  import { tsNodeToParsedExpr, type ParsedExpr } from './expression-parser.ts'
24
24
  import { prepareLoweringMatchers, type LoweringMatcher } from './lowering-registry.ts'
25
+ import { identifierPattern } from './identifier-pattern.ts'
25
26
 
26
27
  export interface RelocateEnv {
27
28
  /**
@@ -713,7 +714,7 @@ function scanRefsByName(
713
714
  ): Map<string, ts.Identifier[]> {
714
715
  const result = new Map<string, ts.Identifier[]>()
715
716
  for (const name of bindings.keys()) {
716
- const re = new RegExp(`\\b${name}\\b`)
717
+ const re = identifierPattern(name)
717
718
  if (re.test(text)) result.set(name, [])
718
719
  }
719
720
  return result