@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.
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/adapters/template-imports.d.ts +27 -15
- package/dist/adapters/template-imports.d.ts.map +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/identifier-pattern.d.ts +62 -0
- package/dist/identifier-pattern.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +226 -163
- package/dist/ir-to-client-js/collect-elements.d.ts +23 -2
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts +12 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +20 -12
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts +25 -2
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +30 -2
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/rewrite-props-object.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/module-exports.d.ts.map +1 -1
- package/dist/relocate.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/binding-scope-ratchet.test.ts +1 -1
- package/src/__tests__/csr-materialize-loop-preamble-shadow.test.ts +76 -0
- package/src/__tests__/csr-substitute-enclosing-scope.test.ts +77 -0
- package/src/__tests__/identifier-pattern.test.ts +170 -0
- package/src/__tests__/loop-child-reactive-attr-const-shadow.test.ts +107 -0
- package/src/__tests__/rewrite-dynamic-imports.test.ts +98 -0
- package/src/adapters/jsx-adapter.ts +2 -1
- package/src/adapters/template-imports.ts +93 -0
- package/src/debug.ts +4 -3
- package/src/identifier-pattern.ts +79 -0
- package/src/index.ts +1 -1
- package/src/ir-to-client-js/collect-elements.ts +44 -15
- package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +2 -1
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +2 -1
- package/src/ir-to-client-js/csr-substitute.ts +19 -2
- package/src/ir-to-client-js/html-template.ts +37 -31
- package/src/ir-to-client-js/imports.ts +2 -1
- package/src/ir-to-client-js/prop-handling.ts +28 -1
- package/src/ir-to-client-js/reactivity.ts +54 -4
- package/src/ir-to-client-js/rewrite-props-object.ts +2 -1
- package/src/ir-to-client-js/utils.ts +9 -8
- package/src/jsx-to-ir.ts +18 -9
- package/src/module-exports.ts +3 -2
- 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:
|
|
685
|
+
pattern: identifierCallPattern(s.getter),
|
|
685
686
|
})),
|
|
686
687
|
memos: analyzer.memos.map(m => ({
|
|
687
688
|
name: m.name,
|
|
688
|
-
pattern:
|
|
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:
|
|
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:
|
|
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 =>
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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 (
|
|
7250
|
+
if (identifierPattern(p).test(valueToCheck)) return true
|
|
7242
7251
|
}
|
|
7243
7252
|
}
|
|
7244
7253
|
}
|
package/src/module-exports.ts
CHANGED
|
@@ -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 (
|
|
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) &&
|
|
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 =
|
|
717
|
+
const re = identifierPattern(name)
|
|
717
718
|
if (re.test(text)) result.set(name, [])
|
|
718
719
|
}
|
|
719
720
|
return result
|