ripple 0.2.69 → 0.2.71
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 +1 -1
- package/src/compiler/phases/3-transform/index.js +8 -12
- package/src/runtime/internal/client/for.js +2 -2
- package/src/runtime/internal/client/render.js +1 -1
- package/src/runtime/internal/client/runtime.js +5 -0
- package/tests/__snapshots__/composite.test.ripple.snap +14 -0
- package/tests/composite.test.ripple +17 -0
package/package.json
CHANGED
|
@@ -680,7 +680,7 @@ const visitors = {
|
|
|
680
680
|
const update = [];
|
|
681
681
|
|
|
682
682
|
if (!is_void) {
|
|
683
|
-
transform_children(node.children, {
|
|
683
|
+
transform_children(node.children, node, {
|
|
684
684
|
visit,
|
|
685
685
|
state: { ...state, init, update, namespace: child_namespace },
|
|
686
686
|
root: false,
|
|
@@ -1454,7 +1454,7 @@ function transform_ts_child(node, context) {
|
|
|
1454
1454
|
}
|
|
1455
1455
|
}
|
|
1456
1456
|
|
|
1457
|
-
function transform_children(children, context) {
|
|
1457
|
+
function transform_children(children, element, context) {
|
|
1458
1458
|
const { visit, state, root } = context;
|
|
1459
1459
|
const normalized = [];
|
|
1460
1460
|
|
|
@@ -1576,6 +1576,8 @@ function transform_children(children, context) {
|
|
|
1576
1576
|
|
|
1577
1577
|
prev = flush_node;
|
|
1578
1578
|
|
|
1579
|
+
const is_controlled = normalized.length === 1 && element !== null;
|
|
1580
|
+
|
|
1579
1581
|
if (node.type === 'Element') {
|
|
1580
1582
|
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1581
1583
|
} else if (node.type === 'Text') {
|
|
@@ -1593,13 +1595,10 @@ function transform_children(children, context) {
|
|
|
1593
1595
|
if (expression.type === 'Literal') {
|
|
1594
1596
|
state.template.push(escape_html(expression.value));
|
|
1595
1597
|
} else {
|
|
1596
|
-
const id =
|
|
1598
|
+
const id = flush_node();
|
|
1597
1599
|
state.template.push(' ');
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
b.assignment('=', b.member(b.call('_$_.child', id), b.id('nodeValue')), expression),
|
|
1601
|
-
),
|
|
1602
|
-
);
|
|
1600
|
+
// avoid set_text overhead for single text nodes
|
|
1601
|
+
state.init.push(b.stmt(b.assignment('=', b.member(id, b.id('nodeValue')), expression)));
|
|
1603
1602
|
}
|
|
1604
1603
|
} else {
|
|
1605
1604
|
// Handle Text nodes in fragments
|
|
@@ -1611,15 +1610,12 @@ function transform_children(children, context) {
|
|
|
1611
1610
|
}
|
|
1612
1611
|
}
|
|
1613
1612
|
} else if (node.type === 'ForOfStatement') {
|
|
1614
|
-
const is_controlled = normalized.length === 1;
|
|
1615
1613
|
node.is_controlled = is_controlled;
|
|
1616
1614
|
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1617
1615
|
} else if (node.type === 'IfStatement') {
|
|
1618
|
-
const is_controlled = normalized.length === 1;
|
|
1619
1616
|
node.is_controlled = is_controlled;
|
|
1620
1617
|
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1621
1618
|
} else if (node.type === 'TryStatement') {
|
|
1622
|
-
const is_controlled = normalized.length === 1;
|
|
1623
1619
|
node.is_controlled = is_controlled;
|
|
1624
1620
|
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1625
1621
|
} else {
|
|
@@ -1656,7 +1652,7 @@ function transform_body(body, { visit, state }) {
|
|
|
1656
1652
|
namespace: state.namespace || 'html', // Preserve namespace context
|
|
1657
1653
|
};
|
|
1658
1654
|
|
|
1659
|
-
transform_children(body, { visit, state: body_state, root: true });
|
|
1655
|
+
transform_children(body, null, { visit, state: body_state, root: true });
|
|
1660
1656
|
|
|
1661
1657
|
if (body_state.update.length > 0) {
|
|
1662
1658
|
body_state.init.push(b.stmt(b.call('_$_.render', b.thunk(b.block(body_state.update)))));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IS_CONTROLLED, IS_INDEXED } from '../../../constants.js';
|
|
2
2
|
import { branch, destroy_block, destroy_block_children, render } from './blocks.js';
|
|
3
3
|
import { FOR_BLOCK, TRACKED_ARRAY } from './constants.js';
|
|
4
|
-
import { create_text } from './operations.js';
|
|
4
|
+
import { create_text, next_sibling } from './operations.js';
|
|
5
5
|
import { active_block, set, tracked, untrack } from './runtime.js';
|
|
6
6
|
import { array_from, is_array } from './utils.js';
|
|
7
7
|
|
|
@@ -40,7 +40,7 @@ function move(block, anchor) {
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
while (node !== end) {
|
|
43
|
-
var next_node = /** @type {TemplateNode} */ (
|
|
43
|
+
var next_node = /** @type {TemplateNode} */ (next_sibling(node));
|
|
44
44
|
anchor.before(node);
|
|
45
45
|
node = next_node;
|
|
46
46
|
}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { get } from './runtime.js';
|
|
16
16
|
|
|
17
17
|
export function set_text(text, value) {
|
|
18
|
-
// For objects, we apply string coercion
|
|
18
|
+
// For objects, we apply string coercion
|
|
19
19
|
var str = value == null ? '' : typeof value === 'object' ? value + '' : value;
|
|
20
20
|
// @ts-expect-error
|
|
21
21
|
if (str !== (text.__t ??= text.nodeValue)) {
|
|
@@ -667,6 +667,11 @@ export function get_derived(computed) {
|
|
|
667
667
|
* @param {Derived | Tracked} tracked
|
|
668
668
|
*/
|
|
669
669
|
export function get(tracked) {
|
|
670
|
+
// reflect back the value if it's not boxed
|
|
671
|
+
if (!is_tracked_object(tracked)) {
|
|
672
|
+
return tracked;
|
|
673
|
+
}
|
|
674
|
+
|
|
670
675
|
return (tracked.f & DERIVED) !== 0
|
|
671
676
|
? get_derived(/** @type {Derived} */ (tracked))
|
|
672
677
|
: get_tracked(tracked);
|
|
@@ -21,3 +21,17 @@ exports[`composite components > correct handles passing through component props
|
|
|
21
21
|
|
|
22
22
|
</div>
|
|
23
23
|
`;
|
|
24
|
+
|
|
25
|
+
exports[`composite components > render simple text as children 1`] = `
|
|
26
|
+
<div>
|
|
27
|
+
<!---->
|
|
28
|
+
<button
|
|
29
|
+
class="my-button"
|
|
30
|
+
>
|
|
31
|
+
Click Me
|
|
32
|
+
<!---->
|
|
33
|
+
</button>
|
|
34
|
+
<!---->
|
|
35
|
+
|
|
36
|
+
</div>
|
|
37
|
+
`;
|
|
@@ -647,4 +647,21 @@ describe('composite components', () => {
|
|
|
647
647
|
|
|
648
648
|
expect(container.textContent).toBe('Basic Component');
|
|
649
649
|
});
|
|
650
|
+
|
|
651
|
+
it('render simple text as children', () => {
|
|
652
|
+
component App() {
|
|
653
|
+
let name = 'Click Me';
|
|
654
|
+
|
|
655
|
+
<Child
|
|
656
|
+
class="my-button"
|
|
657
|
+
>{name}</Child>;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
component Child({children, ...rest}) {
|
|
661
|
+
<button {...rest}><children /></button>
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
render(App);
|
|
665
|
+
expect(container).toMatchSnapshot();
|
|
666
|
+
})
|
|
650
667
|
});
|