sinwan-compiler 0.2.6 → 0.2.8
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/{chunk-m4rk009c.js → chunk-v4zrz7j7.js} +19 -11
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/transform.d.ts +3 -3
- package/docs/README.md +1 -0
- package/docs/transform.md +7 -2
- package/package.json +1 -1
|
@@ -43,8 +43,17 @@ function isBuiltinReactiveProp(componentName, attrName) {
|
|
|
43
43
|
return false;
|
|
44
44
|
return entry.reactiveProps.has(attrName);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
46
|
+
function isReactiveContainerPassThrough(expr, scope) {
|
|
47
|
+
let node = expr;
|
|
48
|
+
while (t.isTSNonNullExpression(node)) {
|
|
49
|
+
node = node.expression;
|
|
50
|
+
}
|
|
51
|
+
if (!t.isIdentifier(node))
|
|
52
|
+
return false;
|
|
53
|
+
const binding = scope.bindings.get(node.name);
|
|
54
|
+
if (!binding)
|
|
55
|
+
return false;
|
|
56
|
+
return binding.kind === "mutable" || binding.kind === "prop";
|
|
48
57
|
}
|
|
49
58
|
function trackReactiveImports2(ast) {
|
|
50
59
|
const names = {
|
|
@@ -611,6 +620,10 @@ function createBindingDescriptor(expr, exprPath, options) {
|
|
|
611
620
|
wrapExpression(expr)
|
|
612
621
|
]);
|
|
613
622
|
}
|
|
623
|
+
const compInfo = getComponentExpressionInfo(exprPath);
|
|
624
|
+
if (t.isIdentifier(expr, { name: "children" }) || compInfo.isComponent && compInfo.attributeName === null) {
|
|
625
|
+
return wrapExpression(expr);
|
|
626
|
+
}
|
|
614
627
|
return t.callExpression(t.identifier("_$bindText"), [wrapExpression(expr)]);
|
|
615
628
|
}
|
|
616
629
|
function collectComponentFunctions2(ast, ccNames) {
|
|
@@ -1047,15 +1060,10 @@ function wrapReactiveExpressions2(ast, options = {}) {
|
|
|
1047
1060
|
JSXExpressionContainer(exprPath) {
|
|
1048
1061
|
const expr = exprPath.node.expression;
|
|
1049
1062
|
const compInfo = getComponentExpressionInfo(exprPath);
|
|
1050
|
-
if (compInfo.isComponent) {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
}
|
|
1055
|
-
} else {
|
|
1056
|
-
if (!isBuiltinControlFlowComponent(compInfo.componentName)) {
|
|
1057
|
-
return;
|
|
1058
|
-
}
|
|
1063
|
+
if (compInfo.isComponent && compInfo.attributeName !== null) {
|
|
1064
|
+
const knownProp = !!compInfo.componentName && isReactiveComponentProp(compInfo.componentName, compInfo.attributeName, componentNames, reactiveProps, importedReactiveProps);
|
|
1065
|
+
if (!knownProp && (!shouldWrap(expr, scope) || isReactiveContainerPassThrough(expr, scope))) {
|
|
1066
|
+
return;
|
|
1059
1067
|
}
|
|
1060
1068
|
}
|
|
1061
1069
|
if (shouldWrap(expr, scope)) {
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/dist/transform.d.ts
CHANGED
|
@@ -19,9 +19,9 @@ export interface TransformOptions {
|
|
|
19
19
|
/**
|
|
20
20
|
* Resolves an import source (e.g. "./Child") to an absolute file path,
|
|
21
21
|
* relative to the file being transformed. Used to look up reactive-prop
|
|
22
|
-
* metadata for components imported from other modules
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* metadata for components imported from other modules. Derived reads
|
|
23
|
+
* (`title={n.value}`) wrap even without metadata; bare signal/store
|
|
24
|
+
* identifiers stay unwrapped.
|
|
25
25
|
*/
|
|
26
26
|
resolveImport?: (source: string, fromFile: string) => string | null;
|
|
27
27
|
}
|
package/docs/README.md
CHANGED
package/docs/transform.md
CHANGED
|
@@ -22,6 +22,8 @@ The compiler turns the child into a lazy getter:
|
|
|
22
22
|
<p>{() => count.value}</p>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
The same wrap applies to **user-component children**. `<Label>{checked.value ? "On" : "Off"}</Label>` becomes `{() => checked.value ? "On" : "Off"}` so a one-shot `cc()` parent does not snapshot the string.
|
|
26
|
+
|
|
25
27
|
The runtime runs that function inside an effect and updates the text when `count` changes.
|
|
26
28
|
|
|
27
29
|
## Automatic `cc()` wrapping
|
|
@@ -83,9 +85,12 @@ Not wrapped:
|
|
|
83
85
|
|
|
84
86
|
**Native elements** (`div`, `p`, `button`, …): wrap reactive children and attributes.
|
|
85
87
|
|
|
86
|
-
**User components** (`<Child title={…} />`):
|
|
88
|
+
**User components** (`<Label>`, `<Child title={…} />`):
|
|
89
|
+
|
|
90
|
+
- **Children:** wrap reactive reads the same way as DOM text (`{count.value}`, `{checked.value ? "On" : "Off"}`) so `cc()` parents do not snapshot the value. Use a getter (`() => …`), never `_$bindText`, because the child may render nodes as well as strings. Render-prop functions (`{(v) => …}`) stay untouched.
|
|
91
|
+
- **Props:** wrap a prop if it is known-reactive for that component (built-in registry, local call graph, analyzer metadata). For *unknown* imported components, still wrap **derived reads** (`htmlFor={id.value}`, `disabled={off.value}`) and leave **container pass-through** alone (`checked={checked}`, `user={user}`) so the child receives the signal or store proxy.
|
|
87
92
|
|
|
88
|
-
**Built-in control-flow** components wrap specific props, and they
|
|
93
|
+
**Built-in control-flow** components wrap specific props, and they wrap reactive expression children (those children render directly):
|
|
89
94
|
|
|
90
95
|
| Component | Reactive props |
|
|
91
96
|
| --------- | -------------- |
|