ripple 0.3.61 → 0.3.63
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 +51 -0
- package/package.json +6 -13
- package/src/jsx-runtime.d.ts +10 -9
- package/src/runtime/internal/client/expression.js +98 -4
- package/src/runtime/internal/client/template.js +45 -0
- package/src/runtime/internal/server/index.js +21 -1
- package/tests/client/basic/basic.collections.test.tsrx +120 -0
- package/tests/client/compiler/compiler.basic.test.tsrx +82 -0
- package/tests/client/tsx.test.tsrx +102 -0
- package/tests/hydration/basic.test.js +127 -0
- package/tests/hydration/compiled/client/basic.js +591 -94
- package/tests/hydration/compiled/client/events.js +9 -9
- package/tests/hydration/compiled/client/for.js +31 -31
- package/tests/hydration/compiled/client/head.js +5 -5
- package/tests/hydration/compiled/client/html.js +8 -8
- package/tests/hydration/compiled/client/if-children.js +2 -2
- package/tests/hydration/compiled/client/mixed-control-flow.js +6 -6
- package/tests/hydration/compiled/client/nested-control-flow.js +23 -23
- package/tests/hydration/compiled/client/reactivity.js +7 -7
- package/tests/hydration/compiled/client/return.js +1 -1
- package/tests/hydration/compiled/client/track-async-serialization.js +12 -12
- package/tests/hydration/compiled/client/try.js +2 -2
- package/tests/hydration/compiled/server/basic.js +504 -2
- package/tests/hydration/components/basic.tsrx +187 -0
- package/tests/server/basic.test.tsrx +143 -0
- package/tests/server/compiler.test.tsrx +42 -0
|
@@ -55,6 +55,149 @@ second"</pre>
|
|
|
55
55
|
expect(body).toBeHtml('<div><span>Server</span></div>');
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
+
it('renders deeply nested tsx and tsrx expression values', async () => {
|
|
59
|
+
function makeFragment(label: string) {
|
|
60
|
+
return <tsrx>
|
|
61
|
+
<span class="label">{label}</span>
|
|
62
|
+
const test = <tsx>
|
|
63
|
+
{[1, 2, 3, 4].map(
|
|
64
|
+
(item) => <tsx>
|
|
65
|
+
{<tsrx>
|
|
66
|
+
<div class="helper-item">{item}</div>
|
|
67
|
+
</tsrx>}
|
|
68
|
+
</tsx>,
|
|
69
|
+
)}
|
|
70
|
+
</tsx>;
|
|
71
|
+
{test}
|
|
72
|
+
</tsrx>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
component Basic() {
|
|
76
|
+
{<tsx>{[1, 2, 3].map((item) => <div class="app-item">{item}</div>)}</tsx>}
|
|
77
|
+
{makeFragment('from helper')}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const { body } = await render(Basic);
|
|
81
|
+
|
|
82
|
+
expect(body).toBeHtml(
|
|
83
|
+
'<div class="app-item">1</div><div class="app-item">2</div><div class="app-item">3</div><span class="label">from helper</span><div class="helper-item">1</div><div class="helper-item">2</div><div class="helper-item">3</div><div class="helper-item">4</div>',
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('renders tsrx nested directly inside a top-level tsx expression value', async () => {
|
|
88
|
+
component Basic() {
|
|
89
|
+
const content = <tsx>
|
|
90
|
+
<section class="outer">
|
|
91
|
+
{<tsrx>
|
|
92
|
+
<div class="inner">{'from tsrx'}</div>
|
|
93
|
+
</tsrx>}
|
|
94
|
+
</section>
|
|
95
|
+
</tsx>;
|
|
96
|
+
|
|
97
|
+
{content}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { body } = await render(Basic);
|
|
101
|
+
|
|
102
|
+
expect(body).toBeHtml('<section class="outer"><div class="inner">from tsrx</div></section>');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('renders nested elements from tsrx inside a top-level tsx value', async () => {
|
|
106
|
+
component Basic() {
|
|
107
|
+
const content = <tsx>
|
|
108
|
+
<div class="wrapper">
|
|
109
|
+
{<tsrx>
|
|
110
|
+
<section class="native">
|
|
111
|
+
<span class="nested-tsrx">{'inside nested tsrx'}</span>
|
|
112
|
+
</section>
|
|
113
|
+
</tsrx>}
|
|
114
|
+
</div>
|
|
115
|
+
</tsx>;
|
|
116
|
+
|
|
117
|
+
{content}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const { body } = await render(Basic);
|
|
121
|
+
|
|
122
|
+
expect(body).toBeHtml(
|
|
123
|
+
'<div class="wrapper"><section class="native"><span class="nested-tsrx">inside nested tsrx</span></section></div>',
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('renders tsx declared inside tsrx nested from a top-level tsx value', async () => {
|
|
128
|
+
component Basic() {
|
|
129
|
+
const content = <tsx>
|
|
130
|
+
{<tsrx>
|
|
131
|
+
const nested = <tsx>
|
|
132
|
+
<span class="nested-tsx">
|
|
133
|
+
{'inside nested tsx'}
|
|
134
|
+
</span>
|
|
135
|
+
</tsx>;
|
|
136
|
+
<div class="native">{nested}</div>
|
|
137
|
+
</tsrx>}
|
|
138
|
+
</tsx>;
|
|
139
|
+
|
|
140
|
+
{content}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const { body } = await render(Basic);
|
|
144
|
+
|
|
145
|
+
expect(body).toBeHtml(
|
|
146
|
+
'<div class="native"><span class="nested-tsx">inside nested tsx</span></div>',
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('flattens nested primitive arrays inside mixed tsrx collections', async () => {
|
|
151
|
+
component Basic() {
|
|
152
|
+
<div>
|
|
153
|
+
{<tsx>
|
|
154
|
+
{[
|
|
155
|
+
'start:',
|
|
156
|
+
['one', 2, true, null, false],
|
|
157
|
+
<strong>
|
|
158
|
+
{'!'}
|
|
159
|
+
</strong>,
|
|
160
|
+
':end',
|
|
161
|
+
]}
|
|
162
|
+
</tsx>}
|
|
163
|
+
</div>
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const { body } = await render(Basic);
|
|
167
|
+
|
|
168
|
+
expect(body).toBeHtml('<div>start:one2truefalse<strong>!</strong>:end</div>');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('flattens direct primitive array expressions', async () => {
|
|
172
|
+
component Basic() {
|
|
173
|
+
const items = ['start:', ['one', 2], null, true, false, ':end'];
|
|
174
|
+
|
|
175
|
+
<div>{['start:', ['one', 2], null, true, false, ':end']}</div>
|
|
176
|
+
<div>{items}</div>
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const { body } = await render(Basic);
|
|
180
|
+
|
|
181
|
+
expect(body).toBeHtml('<div>start:one2truefalse:end</div><div>start:one2truefalse:end</div>');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('flattens conditional primitive array expressions', async () => {
|
|
185
|
+
component Basic() {
|
|
186
|
+
const condition = true;
|
|
187
|
+
const ternary_items = condition
|
|
188
|
+
? ['start:', ['one', 2], null, true, false, ':end']
|
|
189
|
+
: ['fallback'];
|
|
190
|
+
const logical_items = condition && ['start:', ['one', 2], null, true, false, ':end'];
|
|
191
|
+
|
|
192
|
+
<div>{ternary_items}</div>
|
|
193
|
+
<div>{logical_items}</div>
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const { body } = await render(Basic);
|
|
197
|
+
|
|
198
|
+
expect(body).toBeHtml('<div>start:one2truefalse:end</div><div>start:one2truefalse:end</div>');
|
|
199
|
+
});
|
|
200
|
+
|
|
58
201
|
it('renders tracked state updates', async () => {
|
|
59
202
|
component Counter() {
|
|
60
203
|
let &[count] = track(0);
|
|
@@ -168,6 +168,48 @@ export component App() {
|
|
|
168
168
|
expect((result.match(/children:/g) || []).length).toBe(1);
|
|
169
169
|
expect(result).toContain('children: _$_.tsrx_element(');
|
|
170
170
|
});
|
|
171
|
+
|
|
172
|
+
it('routes calls to functions with nested template returns through render_expression', () => {
|
|
173
|
+
const source = `
|
|
174
|
+
component App() {
|
|
175
|
+
function make(flag) {
|
|
176
|
+
if (flag) {
|
|
177
|
+
return <tsx><span>{'nested'}</span></tsx>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
<div>{make(true)}</div>
|
|
184
|
+
}
|
|
185
|
+
`;
|
|
186
|
+
|
|
187
|
+
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
188
|
+
|
|
189
|
+
expect(result).toContain('_$_.render_expression(make(true))');
|
|
190
|
+
expect(result).not.toContain('_$_.escape(make(true))');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('does not treat nested function template returns as outer function returns', () => {
|
|
194
|
+
const source = `
|
|
195
|
+
component App() {
|
|
196
|
+
function make() {
|
|
197
|
+
function nested() {
|
|
198
|
+
return <tsx><span>{'nested'}</span></tsx>;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return nested;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
<div>{make()}</div>
|
|
205
|
+
}
|
|
206
|
+
`;
|
|
207
|
+
|
|
208
|
+
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
209
|
+
|
|
210
|
+
expect(result).toContain('_$_.output_push(_$_.escape(make()))');
|
|
211
|
+
expect(result).not.toContain('_$_.render_expression(make())');
|
|
212
|
+
});
|
|
171
213
|
});
|
|
172
214
|
|
|
173
215
|
describe('compiler server module tests', () => {
|