ripple 0.3.68 → 0.3.70
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/CHANGELOG.md +57 -0
- package/package.json +3 -3
- package/src/jsx-runtime.d.ts +2 -2
- package/src/runtime/element.js +1 -1
- package/src/runtime/index-client.js +11 -11
- package/src/runtime/index-server.js +7 -4
- package/src/runtime/internal/client/bindings.js +1 -1
- package/src/runtime/internal/client/blocks.js +13 -4
- package/src/runtime/internal/client/component.js +55 -0
- package/src/runtime/internal/client/composite.js +4 -2
- package/src/runtime/internal/client/expression.js +65 -7
- package/src/runtime/internal/client/hmr.js +54 -43
- package/src/runtime/internal/client/index.js +5 -1
- package/src/runtime/internal/client/portal.js +70 -69
- package/src/runtime/internal/client/render.js +3 -0
- package/src/runtime/internal/server/index.js +92 -8
- package/tests/client/__snapshots__/html.test.tsrx.snap +3 -3
- package/tests/client/array/array.copy-within.test.tsrx +33 -31
- package/tests/client/array/array.derived.test.tsrx +186 -169
- package/tests/client/array/array.iteration.test.tsrx +40 -37
- package/tests/client/array/array.mutations.test.tsrx +113 -101
- package/tests/client/array/array.static.test.tsrx +119 -101
- package/tests/client/array/array.to-methods.test.tsrx +24 -21
- package/tests/client/async-suspend.test.tsrx +247 -246
- package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +0 -1
- package/tests/client/basic/basic.attributes.test.tsrx +428 -423
- package/tests/client/basic/basic.collections.test.tsrx +109 -102
- package/tests/client/basic/basic.components.test.tsrx +323 -205
- package/tests/client/basic/basic.errors.test.tsrx +91 -91
- package/tests/client/basic/basic.events.test.tsrx +114 -115
- package/tests/client/basic/basic.get-set.test.tsrx +97 -87
- package/tests/client/basic/basic.hmr.test.tsrx +19 -16
- package/tests/client/basic/basic.reactivity.test.tsrx +199 -191
- package/tests/client/basic/basic.rendering.test.tsrx +272 -182
- package/tests/client/basic/basic.styling.test.tsrx +23 -22
- package/tests/client/basic/basic.utilities.test.tsrx +10 -8
- package/tests/client/boundaries.test.tsrx +26 -26
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.rsrx.snap +5 -5
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.tsrx.snap +5 -5
- package/tests/client/compiler/compiler.assignments.test.tsrx +77 -81
- package/tests/client/compiler/compiler.attributes.test.tsrx +15 -15
- package/tests/client/compiler/compiler.basic.test.tsrx +322 -314
- package/tests/client/compiler/compiler.regex.test.tsrx +44 -47
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +38 -38
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
- package/tests/client/compiler/compiler.typescript.test.tsrx +2 -2
- package/tests/client/composite/composite.dynamic-components.test.tsrx +47 -48
- package/tests/client/composite/composite.generics.test.tsrx +168 -192
- package/tests/client/composite/composite.props.test.tsrx +97 -81
- package/tests/client/composite/composite.reactivity.test.tsrx +177 -147
- package/tests/client/composite/composite.render.test.tsrx +122 -105
- package/tests/client/computed-properties.test.tsrx +28 -28
- package/tests/client/context.test.tsrx +21 -21
- package/tests/client/css/global-additional-cases.test.tsrx +58 -58
- package/tests/client/css/global-advanced-selectors.test.tsrx +16 -16
- package/tests/client/css/global-at-rules.test.tsrx +10 -10
- package/tests/client/css/global-basic.test.tsrx +14 -14
- package/tests/client/css/global-classes-ids.test.tsrx +14 -14
- package/tests/client/css/global-combinators.test.tsrx +10 -10
- package/tests/client/css/global-complex-nesting.test.tsrx +14 -14
- package/tests/client/css/global-edge-cases.test.tsrx +18 -18
- package/tests/client/css/global-keyframes.test.tsrx +12 -12
- package/tests/client/css/global-nested.test.tsrx +10 -10
- package/tests/client/css/global-pseudo.test.tsrx +12 -12
- package/tests/client/css/global-scoping.test.tsrx +20 -20
- package/tests/client/css/style-identifier.test.tsrx +126 -259
- package/tests/client/date.test.tsrx +146 -133
- package/tests/client/dynamic-elements.test.tsrx +398 -365
- package/tests/client/events.test.tsrx +292 -290
- package/tests/client/for.test.tsrx +156 -153
- package/tests/client/head.test.tsrx +105 -96
- package/tests/client/html.test.tsrx +122 -26
- package/tests/client/input-value.test.tsrx +1361 -1314
- package/tests/client/lazy-array.test.tsrx +16 -13
- package/tests/client/lazy-destructuring.test.tsrx +257 -213
- package/tests/client/map.test.tsrx +65 -60
- package/tests/client/media-query.test.tsrx +22 -20
- package/tests/client/object.test.tsrx +87 -81
- package/tests/client/portal.test.tsrx +57 -51
- package/tests/client/ref.test.tsrx +233 -202
- package/tests/client/return.test.tsrx +71 -2560
- package/tests/client/set.test.tsrx +54 -45
- package/tests/client/svg.test.tsrx +216 -186
- package/tests/client/switch.test.tsrx +194 -193
- package/tests/client/track-async-hydration.test.tsrx +18 -14
- package/tests/client/tracked-index-access.test.tsrx +28 -18
- package/tests/client/try.test.tsrx +675 -548
- package/tests/client/tsx.test.tsrx +373 -311
- package/tests/client/typescript-generics.test.tsrx +145 -145
- package/tests/client/url/url.derived.test.tsrx +33 -28
- package/tests/client/url/url.parsing.test.tsrx +61 -51
- package/tests/client/url/url.partial-removal.test.tsrx +56 -48
- package/tests/client/url/url.reactivity.test.tsrx +142 -125
- package/tests/client/url/url.serialization.test.tsrx +13 -11
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +34 -29
- package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +25 -21
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +50 -45
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +111 -99
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +49 -43
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +14 -12
- package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +16 -14
- package/tests/hydration/basic.test.js +3 -3
- package/tests/hydration/compiled/client/basic.js +586 -651
- package/tests/hydration/compiled/client/composite.js +79 -104
- package/tests/hydration/compiled/client/events.js +140 -148
- package/tests/hydration/compiled/client/for.js +1005 -1018
- package/tests/hydration/compiled/client/head.js +124 -134
- package/tests/hydration/compiled/client/hmr.js +41 -48
- package/tests/hydration/compiled/client/html-in-template.js +38 -41
- package/tests/hydration/compiled/client/html.js +970 -1314
- package/tests/hydration/compiled/client/if-children.js +234 -249
- package/tests/hydration/compiled/client/if.js +182 -189
- package/tests/hydration/compiled/client/mixed-control-flow.js +347 -303
- package/tests/hydration/compiled/client/nested-control-flow.js +1084 -832
- package/tests/hydration/compiled/client/portal.js +65 -85
- package/tests/hydration/compiled/client/reactivity.js +84 -90
- package/tests/hydration/compiled/client/return.js +38 -1939
- package/tests/hydration/compiled/client/switch.js +218 -224
- package/tests/hydration/compiled/client/track-async-serialization.js +250 -259
- package/tests/hydration/compiled/client/try.js +123 -132
- package/tests/hydration/compiled/server/basic.js +773 -831
- package/tests/hydration/compiled/server/composite.js +166 -191
- package/tests/hydration/compiled/server/events.js +170 -184
- package/tests/hydration/compiled/server/for.js +851 -909
- package/tests/hydration/compiled/server/head.js +206 -216
- package/tests/hydration/compiled/server/hmr.js +64 -72
- package/tests/hydration/compiled/server/html-in-template.js +42 -76
- package/tests/hydration/compiled/server/html.js +1362 -1667
- package/tests/hydration/compiled/server/if-children.js +419 -445
- package/tests/hydration/compiled/server/if.js +194 -208
- package/tests/hydration/compiled/server/mixed-control-flow.js +249 -257
- package/tests/hydration/compiled/server/nested-control-flow.js +491 -515
- package/tests/hydration/compiled/server/portal.js +152 -160
- package/tests/hydration/compiled/server/reactivity.js +94 -106
- package/tests/hydration/compiled/server/return.js +28 -2172
- package/tests/hydration/compiled/server/switch.js +274 -286
- package/tests/hydration/compiled/server/track-async-serialization.js +340 -358
- package/tests/hydration/compiled/server/try.js +167 -185
- package/tests/hydration/components/basic.tsrx +320 -272
- package/tests/hydration/components/composite.tsrx +44 -32
- package/tests/hydration/components/events.tsrx +101 -91
- package/tests/hydration/components/for.tsrx +510 -452
- package/tests/hydration/components/head.tsrx +87 -80
- package/tests/hydration/components/hmr.tsrx +22 -17
- package/tests/hydration/components/html-in-template.tsrx +22 -17
- package/tests/hydration/components/html.tsrx +525 -443
- package/tests/hydration/components/if-children.tsrx +158 -148
- package/tests/hydration/components/if.tsrx +109 -95
- package/tests/hydration/components/mixed-control-flow.tsrx +100 -96
- package/tests/hydration/components/nested-control-flow.tsrx +215 -203
- package/tests/hydration/components/portal.tsrx +41 -34
- package/tests/hydration/components/reactivity.tsrx +37 -27
- package/tests/hydration/components/return.tsrx +12 -556
- package/tests/hydration/components/switch.tsrx +120 -114
- package/tests/hydration/components/track-async-serialization.tsrx +107 -91
- package/tests/hydration/components/try.tsrx +55 -40
- package/tests/hydration/html.test.js +4 -4
- package/tests/hydration/return.test.js +13 -532
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +264 -195
- package/tests/server/basic.components.test.tsrx +296 -169
- package/tests/server/basic.test.tsrx +300 -198
- package/tests/server/compiler.test.tsrx +62 -60
- package/tests/server/composite.props.test.tsrx +77 -63
- package/tests/server/composite.test.tsrx +168 -192
- package/tests/server/context.test.tsrx +18 -12
- package/tests/server/dynamic-elements.test.tsrx +197 -180
- package/tests/server/for.test.tsrx +85 -78
- package/tests/server/head.test.tsrx +50 -43
- package/tests/server/html-nesting-validation.test.tsrx +8 -8
- package/tests/server/if.test.tsrx +57 -51
- package/tests/server/lazy-destructuring.test.tsrx +366 -294
- package/tests/server/return.test.tsrx +76 -1355
- package/tests/server/streaming-ssr.test.tsrx +4 -75
- package/tests/server/style-identifier.test.tsrx +169 -131
- package/tests/server/switch.test.tsrx +91 -85
- package/tests/server/track-async-serialization.test.tsrx +105 -85
- package/tests/server/try.test.tsrx +374 -280
- package/tests/utils/compiler-compat-config.test.js +2 -2
- package/tests/utils/runtime-imports.test.js +10 -0
- package/types/index.d.ts +8 -0
- package/tests/client/__snapshots__/html.test.rsrx.snap +0 -40
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
describe('compiler > regex', () => {
|
|
2
2
|
it('renders without crashing using regex literals in method calls', () => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<span>{htmlTags}</span>
|
|
30
|
-
<span>{String(multiAngle)}</span>
|
|
31
|
-
</div>
|
|
3
|
+
function App() {
|
|
4
|
+
return <>
|
|
5
|
+
let text = 'Hello <span>world</span> and <div>content</div>';
|
|
6
|
+
// Test various regex patterns in method calls that previously failed
|
|
7
|
+
let matchResult = text.match(/<span>/);
|
|
8
|
+
let replaceResult = text.replace(/<div>/g, '[DIV]');
|
|
9
|
+
let searchResult = text.search(/<span>/);
|
|
10
|
+
// Test regex literals in variable assignments (should work)
|
|
11
|
+
let spanRegex = /<span>/g;
|
|
12
|
+
let divRegex = /<div.*?>/;
|
|
13
|
+
// Test more complex regex patterns
|
|
14
|
+
let complexMatch = text.match(/<[^>]*>/g);
|
|
15
|
+
let htmlTags = text.replace(/<(\/*)(\w+)[^>]*>/g, '[$1$2]');
|
|
16
|
+
// Test edge cases with multiple angle brackets
|
|
17
|
+
let multiAngle = '<<test>> <span>content</span>'.match(/<span>/);
|
|
18
|
+
<div>
|
|
19
|
+
<span>{String(matchResult)}</span>
|
|
20
|
+
<span>{replaceResult}</span>
|
|
21
|
+
<span>{String(searchResult)}</span>
|
|
22
|
+
<span>{String(spanRegex)}</span>
|
|
23
|
+
<span>{String(divRegex)}</span>
|
|
24
|
+
<span>{String(complexMatch)}</span>
|
|
25
|
+
<span>{htmlTags}</span>
|
|
26
|
+
<span>{String(multiAngle)}</span>
|
|
27
|
+
</div>
|
|
28
|
+
</>;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
render(App);
|
|
@@ -53,25 +50,25 @@ describe('compiler > regex', () => {
|
|
|
53
50
|
});
|
|
54
51
|
|
|
55
52
|
it('renders without crashing mixing regex and JSX syntax', () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
</
|
|
53
|
+
function App() {
|
|
54
|
+
return <>
|
|
55
|
+
let htmlString = '<p>Paragraph</p><div>Content</div>';
|
|
56
|
+
// Mix of regex parsing and legitimate JSX
|
|
57
|
+
let paragraphs = htmlString.match(/<p[^>]*>.*?<\/p>/g);
|
|
58
|
+
let cleaned = htmlString.replace(/<\/?[^>]+>/g, '');
|
|
59
|
+
let splitArray = htmlString.split(/<\/?\w+>/g).filter((s) => s.trim());
|
|
60
|
+
<div class="container">
|
|
61
|
+
<span class="result">{String(paragraphs)}</span>
|
|
62
|
+
<span class="cleaned">{cleaned}</span>
|
|
63
|
+
<p>{'This is real JSX'}</p>
|
|
64
|
+
<div>
|
|
65
|
+
<span>
|
|
66
|
+
{'Split result: '}
|
|
67
|
+
{splitArray.join(', ')}
|
|
68
|
+
</span>
|
|
69
|
+
</div>
|
|
73
70
|
</div>
|
|
74
|
-
|
|
71
|
+
</>;
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
render(App);
|
|
@@ -7,10 +7,10 @@ describe('Compiler: Tracked Object Direct Access Checks', () => {
|
|
|
7
7
|
it('should error on direct access to __v of a tracked object', () => {
|
|
8
8
|
const code = `
|
|
9
9
|
import { track } from 'ripple';
|
|
10
|
-
export default
|
|
10
|
+
export default function App() { return <>
|
|
11
11
|
let count = track(0);
|
|
12
12
|
console.log(count.__v);
|
|
13
|
-
}
|
|
13
|
+
</>; }
|
|
14
14
|
`;
|
|
15
15
|
expect(() => compile(code, 'test.tsrx')).toThrow(
|
|
16
16
|
/Directly accessing internal property "__v" of a tracked object is not allowed/,
|
|
@@ -20,10 +20,10 @@ import { track } from 'ripple';
|
|
|
20
20
|
it('should error on direct access to "a" (get/set config) of a tracked object', () => {
|
|
21
21
|
const code = `
|
|
22
22
|
import { track } from 'ripple';
|
|
23
|
-
export default
|
|
23
|
+
export default function App() { return <>
|
|
24
24
|
let myTracked = track(0);
|
|
25
25
|
console.log(myTracked.a);
|
|
26
|
-
}
|
|
26
|
+
</>; }
|
|
27
27
|
`;
|
|
28
28
|
expect(() => compile(code, 'test.tsrx')).toThrow(
|
|
29
29
|
/Directly accessing internal property "a" of a tracked object is not allowed/,
|
|
@@ -33,10 +33,10 @@ import { track } from 'ripple';
|
|
|
33
33
|
it('should error on direct access to "b" (block) of a tracked object', () => {
|
|
34
34
|
const code = `
|
|
35
35
|
import { track } from 'ripple';
|
|
36
|
-
export default
|
|
36
|
+
export default function App() { return <>
|
|
37
37
|
let myTracked = track(0);
|
|
38
38
|
console.log(myTracked.b);
|
|
39
|
-
}
|
|
39
|
+
</>; }
|
|
40
40
|
`;
|
|
41
41
|
expect(() => compile(code, 'test.tsrx')).toThrow(
|
|
42
42
|
/Directly accessing internal property "b" of a tracked object is not allowed/,
|
|
@@ -46,10 +46,10 @@ import { track } from 'ripple';
|
|
|
46
46
|
it('should error on direct access to "c" (clock) of a tracked object', () => {
|
|
47
47
|
const code = `
|
|
48
48
|
import { track } from 'ripple';
|
|
49
|
-
export default
|
|
49
|
+
export default function App() { return <>
|
|
50
50
|
let myTracked = track(0);
|
|
51
51
|
console.log(myTracked.c);
|
|
52
|
-
}
|
|
52
|
+
</>; }
|
|
53
53
|
`;
|
|
54
54
|
expect(() => compile(code, 'test.tsrx')).toThrow(
|
|
55
55
|
/Directly accessing internal property "c" of a tracked object is not allowed/,
|
|
@@ -59,10 +59,10 @@ import { track } from 'ripple';
|
|
|
59
59
|
it('should error on direct access to "f" (flags) of a tracked object', () => {
|
|
60
60
|
const code = `
|
|
61
61
|
import { track } from 'ripple';
|
|
62
|
-
export default
|
|
62
|
+
export default function App() { return <>
|
|
63
63
|
let myTracked = track(0);
|
|
64
64
|
console.log(myTracked.f);
|
|
65
|
-
}
|
|
65
|
+
</>; }
|
|
66
66
|
`;
|
|
67
67
|
expect(() => compile(code, 'test.tsrx')).toThrow(
|
|
68
68
|
/Directly accessing internal property "f" of a tracked object is not allowed/,
|
|
@@ -72,10 +72,10 @@ import { track } from 'ripple';
|
|
|
72
72
|
it('should compile successfully with correct @ syntax access', () => {
|
|
73
73
|
const code = `
|
|
74
74
|
import { track } from 'ripple';
|
|
75
|
-
export default
|
|
75
|
+
export default function App() { return <>
|
|
76
76
|
let &[count] = track(0);
|
|
77
77
|
console.log(count);
|
|
78
|
-
}
|
|
78
|
+
</>; }
|
|
79
79
|
`;
|
|
80
80
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
81
81
|
});
|
|
@@ -83,30 +83,30 @@ import { track } from 'ripple';
|
|
|
83
83
|
it('should compile successfully with correct value access', () => {
|
|
84
84
|
const code = `
|
|
85
85
|
import { track } from 'ripple';
|
|
86
|
-
export default
|
|
86
|
+
export default function App() { return <>
|
|
87
87
|
let count = track(0);
|
|
88
88
|
console.log(count.value);
|
|
89
|
-
}
|
|
89
|
+
</>; }
|
|
90
90
|
`;
|
|
91
91
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it('should not error on accessing __v of a non-tracked object', () => {
|
|
95
95
|
const code = `
|
|
96
|
-
export default
|
|
96
|
+
export default function App() { return <>
|
|
97
97
|
let obj = { __v: 123 };
|
|
98
98
|
console.log(obj.__v);
|
|
99
|
-
}
|
|
99
|
+
</>; }
|
|
100
100
|
`;
|
|
101
101
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
it('should not error on accessing __v of a non-tracked object (member expression)', () => {
|
|
105
105
|
const code = `
|
|
106
|
-
export default
|
|
106
|
+
export default function App() { return <>
|
|
107
107
|
let data = { value: { __v: 456 } };
|
|
108
108
|
console.log(data.value.__v);
|
|
109
|
-
}
|
|
109
|
+
</>; }
|
|
110
110
|
`;
|
|
111
111
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
112
112
|
});
|
|
@@ -115,11 +115,11 @@ import { track } from 'ripple';
|
|
|
115
115
|
'should not error on accessing a property named like an internal one on a non-tracked object',
|
|
116
116
|
() => {
|
|
117
117
|
const code = `
|
|
118
|
-
export default
|
|
118
|
+
export default function App() { return <>
|
|
119
119
|
let config = { a: 'some_value', b: 'another_value' };
|
|
120
120
|
console.log(config.a);
|
|
121
121
|
console.log(config.b);
|
|
122
|
-
}
|
|
122
|
+
</>; }
|
|
123
123
|
`;
|
|
124
124
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
125
125
|
},
|
|
@@ -128,10 +128,10 @@ import { track } from 'ripple';
|
|
|
128
128
|
it('should error on indexed [0] access on a tracked object', () => {
|
|
129
129
|
const code = `
|
|
130
130
|
import { track } from 'ripple';
|
|
131
|
-
export default
|
|
131
|
+
export default function App() { return <>
|
|
132
132
|
let count = track(0);
|
|
133
133
|
console.log(count[0]);
|
|
134
|
-
}
|
|
134
|
+
</>; }
|
|
135
135
|
`;
|
|
136
136
|
expect(() => compile(code, 'test.tsrx')).toThrow(value_message);
|
|
137
137
|
});
|
|
@@ -139,10 +139,10 @@ import { track } from 'ripple';
|
|
|
139
139
|
it('should error on indexed [1] access on a tracked object', () => {
|
|
140
140
|
const code = `
|
|
141
141
|
import { track } from 'ripple';
|
|
142
|
-
export default
|
|
142
|
+
export default function App() { return <>
|
|
143
143
|
let count = track(0);
|
|
144
144
|
let raw = count[1];
|
|
145
|
-
}
|
|
145
|
+
</>; }
|
|
146
146
|
`;
|
|
147
147
|
expect(() => compile(code, 'test.tsrx')).toThrow(reference_message);
|
|
148
148
|
});
|
|
@@ -150,10 +150,10 @@ import { track } from 'ripple';
|
|
|
150
150
|
it('should error on indexed [0] write on a tracked object', () => {
|
|
151
151
|
const code = `
|
|
152
152
|
import { track } from 'ripple';
|
|
153
|
-
export default
|
|
153
|
+
export default function App() { return <>
|
|
154
154
|
let count = track(0);
|
|
155
155
|
count[0] = 5;
|
|
156
|
-
}
|
|
156
|
+
</>; }
|
|
157
157
|
`;
|
|
158
158
|
expect(() => compile(code, 'test.tsrx')).toThrow(value_message);
|
|
159
159
|
});
|
|
@@ -161,11 +161,11 @@ import { track } from 'ripple';
|
|
|
161
161
|
it('collects tracked numeric index errors in loose mode', () => {
|
|
162
162
|
const code = `
|
|
163
163
|
import { track } from 'ripple';
|
|
164
|
-
export default
|
|
164
|
+
export default function App() { return <>
|
|
165
165
|
let count = track(0);
|
|
166
166
|
console.log(count[0]);
|
|
167
167
|
let raw = count[1];
|
|
168
|
-
}
|
|
168
|
+
</>; }
|
|
169
169
|
`;
|
|
170
170
|
const result = compile(code, 'test.tsrx', { loose: true });
|
|
171
171
|
|
|
@@ -180,10 +180,10 @@ import { track } from 'ripple';
|
|
|
180
180
|
it('should error on indexed access through a known tracked lazy ref binding', () => {
|
|
181
181
|
const code = `
|
|
182
182
|
import { track } from 'ripple';
|
|
183
|
-
export default
|
|
183
|
+
export default function App() { return <>
|
|
184
184
|
let &[value, tracked_ref] = track(0);
|
|
185
185
|
tracked_ref[0]++;
|
|
186
|
-
}
|
|
186
|
+
</>; }
|
|
187
187
|
`;
|
|
188
188
|
expect(() => compile(code, 'test.tsrx')).toThrow(value_message);
|
|
189
189
|
});
|
|
@@ -191,10 +191,10 @@ import { track } from 'ripple';
|
|
|
191
191
|
it('should allow lazy destructuring a tracked value', () => {
|
|
192
192
|
const code = `
|
|
193
193
|
import { track } from 'ripple';
|
|
194
|
-
export default
|
|
194
|
+
export default function App() { return <>
|
|
195
195
|
let &[value, tracked_ref] = track(0);
|
|
196
196
|
console.log(value, tracked_ref.value);
|
|
197
|
-
}
|
|
197
|
+
</>; }
|
|
198
198
|
`;
|
|
199
199
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
200
200
|
});
|
|
@@ -202,10 +202,10 @@ import { track } from 'ripple';
|
|
|
202
202
|
it('should allow .value read access on a tracked object', () => {
|
|
203
203
|
const code = `
|
|
204
204
|
import { track } from 'ripple';
|
|
205
|
-
export default
|
|
205
|
+
export default function App() { return <>
|
|
206
206
|
let count = track(0);
|
|
207
207
|
console.log(count.value);
|
|
208
|
-
}
|
|
208
|
+
</>; }
|
|
209
209
|
`;
|
|
210
210
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
211
211
|
});
|
|
@@ -213,10 +213,10 @@ import { track } from 'ripple';
|
|
|
213
213
|
it('should allow .value assignment on a tracked object', () => {
|
|
214
214
|
const code = `
|
|
215
215
|
import { track } from 'ripple';
|
|
216
|
-
export default
|
|
216
|
+
export default function App() { return <>
|
|
217
217
|
let count = track(0);
|
|
218
218
|
count.value = 5;
|
|
219
|
-
}
|
|
219
|
+
</>; }
|
|
220
220
|
`;
|
|
221
221
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
222
222
|
});
|
|
@@ -224,10 +224,10 @@ import { track } from 'ripple';
|
|
|
224
224
|
it('should allow .length read access on a tracked object', () => {
|
|
225
225
|
const code = `
|
|
226
226
|
import { track } from 'ripple';
|
|
227
|
-
export default
|
|
227
|
+
export default function App() { return <>
|
|
228
228
|
let count = track(0);
|
|
229
229
|
console.log(count.length);
|
|
230
|
-
}
|
|
230
|
+
</>; }
|
|
231
231
|
`;
|
|
232
232
|
expect(() => compile(code, 'test.tsrx')).not.toThrow();
|
|
233
233
|
});
|
|
@@ -18,7 +18,7 @@ function count_occurrences(string: string, sub_string: string): number {
|
|
|
18
18
|
|
|
19
19
|
describe('compiler > Volar transform does not duplicate try blocks from functions', () => {
|
|
20
20
|
it('try inside an async function', () => {
|
|
21
|
-
const source = `export
|
|
21
|
+
const source = `export function App() { return <>
|
|
22
22
|
async function doWork() {
|
|
23
23
|
try {
|
|
24
24
|
await fetch('/api');
|
|
@@ -27,7 +27,7 @@ describe('compiler > Volar transform does not duplicate try blocks from function
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
<div onclick={doWork}>{"click"}</div>
|
|
30
|
-
}`;
|
|
30
|
+
</>; }`;
|
|
31
31
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
32
32
|
|
|
33
33
|
expect(count_occurrences(result, 'try {')).toBe(1);
|
|
@@ -36,14 +36,14 @@ describe('compiler > Volar transform does not duplicate try blocks from function
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it('try inside an arrow function', () => {
|
|
39
|
-
const source = `export
|
|
39
|
+
const source = `export function App() { return <>
|
|
40
40
|
const doWork = async () => {
|
|
41
41
|
try {
|
|
42
42
|
await fetch('/api');
|
|
43
43
|
} catch (e) {}
|
|
44
44
|
};
|
|
45
45
|
<div onclick={doWork}>{"click"}</div>
|
|
46
|
-
}`;
|
|
46
|
+
</>; }`;
|
|
47
47
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
48
48
|
|
|
49
49
|
expect(count_occurrences(result, 'try {')).toBe(1);
|
|
@@ -51,7 +51,7 @@ describe('compiler > Volar transform does not duplicate try blocks from function
|
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it('try-catch-finally inside a function', () => {
|
|
54
|
-
const source = `export
|
|
54
|
+
const source = `export function App() { return <>
|
|
55
55
|
async function save() {
|
|
56
56
|
try {
|
|
57
57
|
await fetch('/save');
|
|
@@ -62,7 +62,7 @@ describe('compiler > Volar transform does not duplicate try blocks from function
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
<div onclick={save}>{"save"}</div>
|
|
65
|
-
}`;
|
|
65
|
+
</>; }`;
|
|
66
66
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
67
67
|
|
|
68
68
|
expect(count_occurrences(result, 'try {')).toBe(1);
|
|
@@ -72,12 +72,12 @@ describe('compiler > Volar transform does not duplicate try blocks from function
|
|
|
72
72
|
|
|
73
73
|
it('try at component top level is preserved', () => {
|
|
74
74
|
const source = `import { trackAsync } from 'ripple';
|
|
75
|
-
export
|
|
75
|
+
export function App() { return <>
|
|
76
76
|
try {
|
|
77
77
|
let &[data] = trackAsync(() => fetch('/api'));
|
|
78
78
|
} catch (e) {}
|
|
79
79
|
<div>{"hi"}</div>
|
|
80
|
-
}`;
|
|
80
|
+
</>; }`;
|
|
81
81
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
82
82
|
|
|
83
83
|
expect(count_occurrences(result, 'try {')).toBe(1);
|
|
@@ -86,7 +86,7 @@ export component App() {
|
|
|
86
86
|
|
|
87
87
|
it('component-level try and function-level try coexist without duplication', () => {
|
|
88
88
|
const source = `import { trackAsync } from 'ripple';
|
|
89
|
-
export
|
|
89
|
+
export function App() { return <>
|
|
90
90
|
try {
|
|
91
91
|
let &[data] = trackAsync(() => fetch('/init'));
|
|
92
92
|
} catch (e) {}
|
|
@@ -97,7 +97,7 @@ export component App() {
|
|
|
97
97
|
} catch (e) {}
|
|
98
98
|
}
|
|
99
99
|
<div onclick={refresh}>{"click"}</div>
|
|
100
|
-
}`;
|
|
100
|
+
</>; }`;
|
|
101
101
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
102
102
|
|
|
103
103
|
expect(count_occurrences(result, 'try {')).toBe(2);
|
|
@@ -106,7 +106,7 @@ export component App() {
|
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
it('try in nested functions', () => {
|
|
109
|
-
const source = `export
|
|
109
|
+
const source = `export function App() { return <>
|
|
110
110
|
function outer() {
|
|
111
111
|
async function inner() {
|
|
112
112
|
try {
|
|
@@ -115,7 +115,7 @@ export component App() {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
<div>{"hi"}</div>
|
|
118
|
-
}`;
|
|
118
|
+
</>; }`;
|
|
119
119
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
120
120
|
|
|
121
121
|
expect(count_occurrences(result, 'try {')).toBe(1);
|
|
@@ -123,7 +123,7 @@ export component App() {
|
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
it('multiple functions with try blocks each appear once', () => {
|
|
126
|
-
const source = `export
|
|
126
|
+
const source = `export function App() { return <>
|
|
127
127
|
async function load() {
|
|
128
128
|
try {
|
|
129
129
|
await fetch('/load');
|
|
@@ -135,7 +135,7 @@ export component App() {
|
|
|
135
135
|
} catch (e) {}
|
|
136
136
|
}
|
|
137
137
|
<div>{"hi"}</div>
|
|
138
|
-
}`;
|
|
138
|
+
</>; }`;
|
|
139
139
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
140
140
|
|
|
141
141
|
expect(count_occurrences(result, 'try {')).toBe(2);
|
|
@@ -143,7 +143,7 @@ export component App() {
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
it('try in object method', () => {
|
|
146
|
-
const source = `export
|
|
146
|
+
const source = `export function App() { return <>
|
|
147
147
|
const handlers = {
|
|
148
148
|
async onClick() {
|
|
149
149
|
try {
|
|
@@ -152,7 +152,7 @@ export component App() {
|
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
<div>{"hi"}</div>
|
|
155
|
-
}`;
|
|
155
|
+
</>; }`;
|
|
156
156
|
const result = compile_to_volar_mappings(source, 'test.tsrx').code;
|
|
157
157
|
|
|
158
158
|
expect(count_occurrences(result, 'try {')).toBe(1);
|
|
@@ -33,11 +33,11 @@ beforeAll(() => {
|
|
|
33
33
|
(global as any).count++;
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
function Test() { return <>
|
|
37
37
|
let toggle: { value: boolean } | undefined;
|
|
38
38
|
toggle!.value = false;
|
|
39
39
|
toggle!.value++;
|
|
40
|
-
}`;
|
|
40
|
+
</>; }`;
|
|
41
41
|
|
|
42
42
|
const { code } = compile(source, 'test.tsrx', { mode: 'client' });
|
|
43
43
|
|
|
@@ -2,14 +2,14 @@ import { flushSync, track } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('composite > dynamic components', () => {
|
|
4
4
|
it('supports rendering composite components using <@component> syntax', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
function App() {
|
|
6
|
+
return <>
|
|
7
|
+
function basic() {
|
|
8
|
+
return <><div>{'Basic Component'}</div></>;
|
|
9
|
+
}
|
|
10
|
+
const tracked_basic = track(() => basic);
|
|
11
|
+
<@tracked_basic />
|
|
12
|
+
</>;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
render(App);
|
|
@@ -19,19 +19,18 @@ describe('composite > dynamic components', () => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('supports rendering composite components from object properties', () => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<@comp />
|
|
22
|
+
function App() {
|
|
23
|
+
return <>
|
|
24
|
+
function basic() {
|
|
25
|
+
return <><div>{'Basic Component'}</div></>;
|
|
26
|
+
}
|
|
27
|
+
const tracked_basic = track(() => basic);
|
|
28
|
+
const obj = {
|
|
29
|
+
tracked_basic,
|
|
30
|
+
};
|
|
31
|
+
const comp = obj.tracked_basic;
|
|
32
|
+
<@comp />
|
|
33
|
+
</>;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
render(App);
|
|
@@ -41,21 +40,19 @@ describe('composite > dynamic components', () => {
|
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
it('supports rendering composite components from tracked object properties', () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const comp = inner.tracked_basic;
|
|
58
|
-
<@comp />
|
|
43
|
+
function App() {
|
|
44
|
+
return <>
|
|
45
|
+
function basic() {
|
|
46
|
+
return <><div>{'Basic Component'}</div></>;
|
|
47
|
+
}
|
|
48
|
+
const tracked_basic = track(() => basic);
|
|
49
|
+
const obj = {
|
|
50
|
+
tracked_basic,
|
|
51
|
+
};
|
|
52
|
+
let &[inner] = track(obj);
|
|
53
|
+
const comp = inner.tracked_basic;
|
|
54
|
+
<@comp />
|
|
55
|
+
</>;
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
render(App);
|
|
@@ -65,22 +62,24 @@ describe('composite > dynamic components', () => {
|
|
|
65
62
|
});
|
|
66
63
|
|
|
67
64
|
it('handles dynamic component switching', () => {
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
function Child1() {
|
|
66
|
+
return <><div>{'I am child 1'}</div></>;
|
|
70
67
|
}
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
function Child2() {
|
|
70
|
+
return <><div>{'I am child 2'}</div></>;
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
function App() {
|
|
74
|
+
return <>
|
|
75
|
+
let &[thing] = track(() => Child1);
|
|
76
|
+
<div id="container">
|
|
77
|
+
<@thing />
|
|
78
|
+
</div>
|
|
79
|
+
<button onClick={() => (thing = thing === Child1 ? Child2 : Child1)}>
|
|
80
|
+
{'Change Child'}
|
|
81
|
+
</button>
|
|
82
|
+
</>;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
render(App);
|