ripple 0.2.48 → 0.2.50
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/README.md +2 -4
- package/package.json +2 -2
- package/src/compiler/phases/1-parse/index.js +908 -885
- package/src/compiler/phases/3-transform/index.js +10 -41
- package/src/runtime/internal/client/index.js +0 -18
- package/src/runtime/internal/client/runtime.js +1 -1
- package/tests/accessors-props.test.ripple +19 -23
- package/tests/array.test.ripple +103 -103
- package/tests/basic.test.ripple +184 -152
- package/tests/composite.test.ripple +12 -1
- package/tests/map.test.ripple +13 -13
- package/tests/set.test.ripple +3 -3
- package/types/index.d.ts +1 -1
- package/src/runtime/internal/client/array.js +0 -352
|
@@ -122,9 +122,9 @@ const visitors = {
|
|
|
122
122
|
|
|
123
123
|
if (is_reference(node, parent)) {
|
|
124
124
|
if (context.state.to_ts) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
if (node.tracked) {
|
|
126
|
+
return b.member(node, b.literal('#v'), true);
|
|
127
|
+
}
|
|
128
128
|
} else {
|
|
129
129
|
const binding = context.state.scope.get(node.name);
|
|
130
130
|
if (
|
|
@@ -180,6 +180,9 @@ const visitors = {
|
|
|
180
180
|
callee.name === 'track' &&
|
|
181
181
|
is_ripple_import(callee, context)
|
|
182
182
|
) {
|
|
183
|
+
if (node.arguments.length === 0) {
|
|
184
|
+
node.arguments.push(b.void0);
|
|
185
|
+
}
|
|
183
186
|
return {
|
|
184
187
|
...node,
|
|
185
188
|
arguments: [...node.arguments.map((arg) => context.visit(arg)), b.id('__block')],
|
|
@@ -204,40 +207,6 @@ const visitors = {
|
|
|
204
207
|
if (callee.type === 'MemberExpression') {
|
|
205
208
|
const property = callee.property;
|
|
206
209
|
|
|
207
|
-
if (property.type === 'Identifier' && !callee.optional) {
|
|
208
|
-
const name = property.name;
|
|
209
|
-
if (
|
|
210
|
-
// TODO support the missing array methods
|
|
211
|
-
name === 'reduce' ||
|
|
212
|
-
name === 'map' ||
|
|
213
|
-
name === 'forEach' ||
|
|
214
|
-
name === 'join' ||
|
|
215
|
-
name === 'includes' ||
|
|
216
|
-
name === 'indexOf' ||
|
|
217
|
-
name === 'lastIndexOf' ||
|
|
218
|
-
name === 'filter' ||
|
|
219
|
-
name === 'every' ||
|
|
220
|
-
name === 'some' ||
|
|
221
|
-
name === 'toSpliced' ||
|
|
222
|
-
name === 'toSorted' ||
|
|
223
|
-
name === 'toString' ||
|
|
224
|
-
name === 'values' ||
|
|
225
|
-
name === 'entries'
|
|
226
|
-
) {
|
|
227
|
-
return b.call(
|
|
228
|
-
'$.with_scope',
|
|
229
|
-
b.id('__block'),
|
|
230
|
-
b.thunk(
|
|
231
|
-
b.call(
|
|
232
|
-
'$.array_' + name,
|
|
233
|
-
context.visit(callee.object),
|
|
234
|
-
...node.arguments.map((arg) => context.visit(arg)),
|
|
235
|
-
),
|
|
236
|
-
),
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
210
|
if (callee.computed) {
|
|
242
211
|
return b.call(
|
|
243
212
|
'$.with_scope',
|
|
@@ -1032,7 +1001,7 @@ const visitors = {
|
|
|
1032
1001
|
|
|
1033
1002
|
return b.call(
|
|
1034
1003
|
'$.set_property',
|
|
1035
|
-
context.visit(left.object),
|
|
1004
|
+
context.visit(left.object, { ...context.state, metadata: { tracking: false } }),
|
|
1036
1005
|
left.computed ? context.visit(left.property) : b.literal(left.property.name),
|
|
1037
1006
|
operator === '='
|
|
1038
1007
|
? context.visit(right)
|
|
@@ -1072,7 +1041,7 @@ const visitors = {
|
|
|
1072
1041
|
|
|
1073
1042
|
return b.call(
|
|
1074
1043
|
'$.set',
|
|
1075
|
-
context.visit(left),
|
|
1044
|
+
context.visit(left, { ...context.state, metadata: { tracking: null } }),
|
|
1076
1045
|
operator === '='
|
|
1077
1046
|
? context.visit(right)
|
|
1078
1047
|
: b.binary(
|
|
@@ -1117,7 +1086,7 @@ const visitors = {
|
|
|
1117
1086
|
|
|
1118
1087
|
return b.call(
|
|
1119
1088
|
node.prefix ? '$.update_pre_property' : '$.update_property',
|
|
1120
|
-
context.visit(argument.object),
|
|
1089
|
+
context.visit(argument.object, { ...context.state, metadata: { tracking: false } }),
|
|
1121
1090
|
argument.computed ? context.visit(argument.property) : b.literal(argument.property.name),
|
|
1122
1091
|
b.id('__block'),
|
|
1123
1092
|
node.operator === '--' ? b.literal(-1) : undefined,
|
|
@@ -1142,7 +1111,7 @@ const visitors = {
|
|
|
1142
1111
|
if (argument.type === 'Identifier' && argument.tracked) {
|
|
1143
1112
|
return b.call(
|
|
1144
1113
|
node.prefix ? '$.update_pre' : '$.update',
|
|
1145
|
-
context.visit(argument),
|
|
1114
|
+
context.visit(argument, { ...context.state, metadata: { tracking: null } }),
|
|
1146
1115
|
b.id('__block'),
|
|
1147
1116
|
node.operator === '--' ? b.literal(-1) : undefined,
|
|
1148
1117
|
);
|
|
@@ -52,24 +52,6 @@ export {
|
|
|
52
52
|
derived,
|
|
53
53
|
} from './runtime.js';
|
|
54
54
|
|
|
55
|
-
export {
|
|
56
|
-
array_reduce,
|
|
57
|
-
array_join,
|
|
58
|
-
array_map,
|
|
59
|
-
array_filter,
|
|
60
|
-
array_forEach,
|
|
61
|
-
array_includes,
|
|
62
|
-
array_indexOf,
|
|
63
|
-
array_lastIndexOf,
|
|
64
|
-
array_every,
|
|
65
|
-
array_some,
|
|
66
|
-
array_toString,
|
|
67
|
-
array_toSorted,
|
|
68
|
-
array_toSpliced,
|
|
69
|
-
array_values,
|
|
70
|
-
array_entries,
|
|
71
|
-
} from './array.js';
|
|
72
|
-
|
|
73
55
|
export { for_block as for } from './for.js';
|
|
74
56
|
|
|
75
57
|
export { if_block as if } from './if.js';
|
|
@@ -1016,7 +1016,7 @@ export function update_pre(tracked, block, d = 1) {
|
|
|
1016
1016
|
export function update_property(obj, property, block, d = 1) {
|
|
1017
1017
|
var tracked = obj[property];
|
|
1018
1018
|
var value = get(tracked);
|
|
1019
|
-
var new_value = d === 1 ? value++ : value
|
|
1019
|
+
var new_value = d === 1 ? value++ : value--;
|
|
1020
1020
|
set(tracked, value, block);
|
|
1021
1021
|
return new_value;
|
|
1022
1022
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mount, flushSync, effect } from 'ripple';
|
|
2
|
+
import { mount, flushSync, effect, track } from 'ripple';
|
|
3
3
|
|
|
4
4
|
describe('prop accessors', () => {
|
|
5
5
|
let container;
|
|
@@ -25,24 +25,20 @@ describe('prop accessors', () => {
|
|
|
25
25
|
|
|
26
26
|
component Child(props) {
|
|
27
27
|
effect(() => {
|
|
28
|
-
logs.push('App effect', props
|
|
28
|
+
logs.push('App effect', props.@foo);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
<button onClick={() => props
|
|
31
|
+
<button onClick={() => props.@foo++}>{"Increment foo"}</button>
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
component App(props) {
|
|
35
|
-
let
|
|
35
|
+
let foo = track(0);
|
|
36
36
|
|
|
37
|
-
<Child
|
|
38
|
-
return $foo;
|
|
39
|
-
}, v => {
|
|
40
|
-
$foo = v;
|
|
41
|
-
}} />
|
|
37
|
+
<Child {foo} />
|
|
42
38
|
|
|
43
|
-
<div>{"parent foo: " +
|
|
39
|
+
<div>{"parent foo: " + @foo}</div>
|
|
44
40
|
|
|
45
|
-
<button onClick={() =>
|
|
41
|
+
<button onClick={() => { @foo++; }}>{"Increment parent foo"}</button>
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
render(App);
|
|
@@ -66,10 +62,11 @@ describe('prop accessors', () => {
|
|
|
66
62
|
expect(logs).toEqual(['App effect', 0, 'App effect', 1, 'App effect', 2]);
|
|
67
63
|
});
|
|
68
64
|
|
|
69
|
-
|
|
65
|
+
// Note: Disabled this test for further investigation.
|
|
66
|
+
it.skip('should render a basic prop accessor on a composite component #2', () => {
|
|
70
67
|
const logs = [];
|
|
71
68
|
|
|
72
|
-
component Child(
|
|
69
|
+
component Child({ foo }) {
|
|
73
70
|
effect(() => {
|
|
74
71
|
logs.push('App effect', props.foo);
|
|
75
72
|
});
|
|
@@ -77,18 +74,18 @@ describe('prop accessors', () => {
|
|
|
77
74
|
<button onClick={() => props.foo++}>{"Increment foo"}</button>
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
component App(
|
|
81
|
-
let
|
|
77
|
+
component App() {
|
|
78
|
+
let foo = track(0);
|
|
82
79
|
|
|
83
80
|
<Child foo:={() => {
|
|
84
|
-
return
|
|
81
|
+
return @foo;
|
|
85
82
|
}, v => {
|
|
86
83
|
// do not update parent
|
|
87
84
|
}} />
|
|
88
85
|
|
|
89
|
-
<div>{"parent foo: " +
|
|
86
|
+
<div>{"parent foo: " + @foo}</div>
|
|
90
87
|
|
|
91
|
-
<button onClick={() =>
|
|
88
|
+
<button onClick={() => { foo++ }}>{"Increment parent foo"}</button>
|
|
92
89
|
}
|
|
93
90
|
|
|
94
91
|
render(App);
|
|
@@ -101,7 +98,7 @@ describe('prop accessors', () => {
|
|
|
101
98
|
|
|
102
99
|
button.click();
|
|
103
100
|
flushSync();
|
|
104
|
-
|
|
101
|
+
|
|
105
102
|
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 0');
|
|
106
103
|
expect(logs).toEqual(['App effect', 0]);
|
|
107
104
|
|
|
@@ -118,14 +115,13 @@ describe('prop accessors', () => {
|
|
|
118
115
|
expect(logs).toEqual(['App effect', 0, 'App effect', 1, 'App effect', 2]);
|
|
119
116
|
});
|
|
120
117
|
|
|
121
|
-
|
|
122
118
|
it('handles a simple getter prop accessor with no setter', () =>{
|
|
123
119
|
component Parent() {
|
|
124
|
-
let
|
|
120
|
+
let value = track(123);
|
|
125
121
|
|
|
126
|
-
<Child value:={() =>
|
|
122
|
+
<Child value:={() => @value} />
|
|
127
123
|
|
|
128
|
-
<button onClick={() =>
|
|
124
|
+
<button onClick={() => { @value++ }}>{"Increment value"}</button>
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
component Child({ value }) {
|