ripple 0.3.72 → 0.3.76
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 +116 -0
- package/package.json +3 -3
- package/src/jsx-runtime.d.ts +4 -10
- package/src/runtime/dynamic-client.js +33 -0
- package/src/runtime/dynamic-server.js +80 -0
- package/src/runtime/index-client.js +5 -13
- package/src/runtime/index-server.js +2 -0
- package/src/runtime/internal/client/blocks.js +6 -27
- package/src/runtime/internal/client/composite.js +11 -6
- package/src/runtime/internal/client/for.js +80 -5
- package/src/runtime/internal/client/index.js +0 -2
- package/src/runtime/internal/client/render.js +5 -2
- package/src/runtime/internal/client/types.d.ts +0 -10
- package/src/runtime/internal/server/index.js +8 -1
- package/tests/client/__snapshots__/computed-properties.test.tsrx.snap +8 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +22 -0
- package/tests/client/__snapshots__/html.test.tsrx.snap +4 -0
- package/tests/client/array/array.copy-within.test.tsrx +19 -19
- package/tests/client/array/array.derived.test.tsrx +97 -109
- package/tests/client/array/array.iteration.test.tsrx +28 -28
- package/tests/client/array/array.mutations.test.tsrx +68 -68
- package/tests/client/array/array.static.test.tsrx +82 -92
- package/tests/client/array/array.to-methods.test.tsrx +15 -15
- package/tests/client/async-suspend.test.tsrx +180 -179
- package/tests/client/basic/__snapshots__/basic.attributes.test.tsrx.snap +2 -0
- package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +4 -0
- package/tests/client/basic/basic.attributes.test.tsrx +273 -317
- package/tests/client/basic/basic.collections.test.tsrx +55 -61
- package/tests/client/basic/basic.components.test.tsrx +198 -220
- package/tests/client/basic/basic.errors.test.tsrx +70 -76
- package/tests/client/basic/basic.events.test.tsrx +80 -85
- package/tests/client/basic/basic.get-set.test.tsrx +54 -64
- package/tests/client/basic/basic.hmr.test.tsrx +15 -19
- package/tests/client/basic/basic.reactivity.test.tsrx +121 -135
- package/tests/client/basic/basic.rendering.test.tsrx +273 -178
- package/tests/client/basic/basic.styling.test.tsrx +16 -14
- package/tests/client/basic/basic.utilities.test.tsrx +8 -10
- package/tests/client/boundaries.test.tsrx +18 -18
- package/tests/client/compiler/compiler.assignments.test.tsrx +77 -76
- package/tests/client/compiler/compiler.attributes.test.tsrx +18 -14
- package/tests/client/compiler/compiler.basic.test.tsrx +357 -288
- package/tests/client/compiler/compiler.regex.test.tsrx +40 -44
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +57 -38
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
- package/tests/client/compiler/compiler.typescript.test.tsrx +4 -3
- package/tests/client/composite/composite.dynamic-components.test.tsrx +62 -47
- package/tests/client/composite/composite.generics.test.tsrx +165 -167
- package/tests/client/composite/composite.props.test.tsrx +66 -74
- package/tests/client/composite/composite.reactivity.test.tsrx +132 -166
- package/tests/client/composite/composite.render.test.tsrx +92 -101
- package/tests/client/computed-properties.test.tsrx +14 -18
- package/tests/client/context.test.tsrx +14 -18
- package/tests/client/css/global-additional-cases.test.tsrx +493 -439
- package/tests/client/css/global-advanced-selectors.test.tsrx +169 -153
- package/tests/client/css/global-at-rules.test.tsrx +71 -66
- package/tests/client/css/global-basic.test.tsrx +105 -98
- package/tests/client/css/global-classes-ids.test.tsrx +128 -114
- package/tests/client/css/global-combinators.test.tsrx +83 -78
- package/tests/client/css/global-complex-nesting.test.tsrx +134 -120
- package/tests/client/css/global-edge-cases.test.tsrx +138 -120
- package/tests/client/css/global-keyframes.test.tsrx +108 -96
- package/tests/client/css/global-nested.test.tsrx +88 -78
- package/tests/client/css/global-pseudo.test.tsrx +104 -98
- package/tests/client/css/global-scoping.test.tsrx +145 -125
- package/tests/client/css/style-identifier.test.tsrx +65 -72
- package/tests/client/date.test.tsrx +83 -83
- package/tests/client/dynamic-elements.test.tsrx +318 -299
- package/tests/client/events.test.tsrx +252 -266
- package/tests/client/for.test.tsrx +120 -127
- package/tests/client/head.test.tsrx +74 -48
- package/tests/client/html.test.tsrx +37 -49
- package/tests/client/input-value.test.tsrx +1125 -1354
- package/tests/client/lazy-array.test.tsrx +10 -16
- package/tests/client/lazy-destructuring.test.tsrx +169 -221
- package/tests/client/map.test.tsrx +39 -41
- package/tests/client/media-query.test.tsrx +15 -19
- package/tests/client/object.test.tsrx +46 -56
- package/tests/client/portal.test.tsrx +31 -37
- package/tests/client/ref.test.tsrx +173 -193
- package/tests/client/return.test.tsrx +62 -37
- package/tests/client/set.test.tsrx +33 -33
- package/tests/client/svg.test.tsrx +197 -216
- package/tests/client/switch.test.tsrx +201 -191
- package/tests/client/track-async-hydration.test.tsrx +14 -18
- package/tests/client/tracked-index-access.test.tsrx +18 -28
- package/tests/client/try.test.tsrx +494 -619
- package/tests/client/tsx.test.tsrx +286 -292
- package/tests/client/typescript-generics.test.tsrx +121 -129
- package/tests/client/url/url.derived.test.tsrx +21 -25
- package/tests/client/url/url.parsing.test.tsrx +35 -35
- package/tests/client/url/url.partial-removal.test.tsrx +32 -32
- package/tests/client/url/url.reactivity.test.tsrx +68 -72
- package/tests/client/url/url.serialization.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +21 -27
- package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +16 -16
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +37 -37
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +56 -60
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +32 -34
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +9 -9
- package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +10 -10
- package/tests/hydration/compiled/client/basic.js +390 -319
- package/tests/hydration/compiled/client/composite.js +52 -44
- package/tests/hydration/compiled/client/for.js +734 -604
- package/tests/hydration/compiled/client/head.js +183 -103
- package/tests/hydration/compiled/client/html.js +93 -86
- package/tests/hydration/compiled/client/if-children.js +95 -71
- package/tests/hydration/compiled/client/if.js +113 -89
- package/tests/hydration/compiled/client/mixed-control-flow.js +225 -209
- package/tests/hydration/compiled/client/nested-control-flow.js +94 -98
- package/tests/hydration/compiled/client/reactivity.js +26 -24
- package/tests/hydration/compiled/client/return.js +8 -42
- package/tests/hydration/compiled/client/switch.js +208 -173
- package/tests/hydration/compiled/client/track-async-serialization.js +176 -128
- package/tests/hydration/compiled/client/try.js +29 -21
- package/tests/hydration/compiled/server/basic.js +210 -221
- package/tests/hydration/compiled/server/composite.js +13 -14
- package/tests/hydration/compiled/server/for.js +427 -444
- package/tests/hydration/compiled/server/head.js +199 -189
- package/tests/hydration/compiled/server/html.js +33 -41
- package/tests/hydration/compiled/server/if-children.js +114 -117
- package/tests/hydration/compiled/server/if.js +77 -83
- package/tests/hydration/compiled/server/mixed-control-flow.js +145 -150
- package/tests/hydration/compiled/server/nested-control-flow.js +10 -0
- package/tests/hydration/compiled/server/reactivity.js +24 -22
- package/tests/hydration/compiled/server/return.js +6 -18
- package/tests/hydration/compiled/server/switch.js +179 -176
- package/tests/hydration/compiled/server/track-async-serialization.js +88 -70
- package/tests/hydration/compiled/server/try.js +31 -35
- package/tests/hydration/components/basic.tsrx +216 -258
- package/tests/hydration/components/composite.tsrx +32 -42
- package/tests/hydration/components/events.tsrx +81 -101
- package/tests/hydration/components/for.tsrx +270 -336
- package/tests/hydration/components/head.tsrx +43 -39
- package/tests/hydration/components/hmr.tsrx +16 -22
- package/tests/hydration/components/html-in-template.tsrx +15 -21
- package/tests/hydration/components/html.tsrx +442 -526
- package/tests/hydration/components/if-children.tsrx +107 -125
- package/tests/hydration/components/if.tsrx +68 -90
- package/tests/hydration/components/mixed-control-flow.tsrx +65 -72
- package/tests/hydration/components/nested-control-flow.tsrx +202 -216
- package/tests/hydration/components/portal.tsrx +33 -41
- package/tests/hydration/components/reactivity.tsrx +26 -34
- package/tests/hydration/components/return.tsrx +4 -6
- package/tests/hydration/components/switch.tsrx +73 -78
- package/tests/hydration/components/track-async-serialization.tsrx +83 -93
- package/tests/hydration/components/try.tsrx +37 -51
- package/tests/hydration/switch.test.js +8 -8
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +117 -162
- package/tests/server/basic.components.test.tsrx +164 -194
- package/tests/server/basic.test.tsrx +299 -199
- package/tests/server/compiler.test.tsrx +142 -72
- package/tests/server/composite.props.test.tsrx +54 -58
- package/tests/server/composite.test.tsrx +165 -167
- package/tests/server/context.test.tsrx +13 -17
- package/tests/server/dynamic-elements.test.tsrx +147 -148
- package/tests/server/for.test.tsrx +115 -84
- package/tests/server/head.test.tsrx +54 -31
- package/tests/server/html-nesting-validation.test.tsrx +16 -8
- package/tests/server/if.test.tsrx +49 -59
- package/tests/server/lazy-destructuring.test.tsrx +288 -366
- package/tests/server/return.test.tsrx +58 -36
- package/tests/server/streaming-ssr.test.tsrx +4 -4
- package/tests/server/style-identifier.test.tsrx +61 -69
- package/tests/server/switch.test.tsrx +89 -97
- package/tests/server/track-async-serialization.test.tsrx +85 -103
- package/tests/server/try.test.tsrx +275 -360
- package/tests/utils/ref-types.test.js +72 -0
- package/tests/utils/vite-plugin-config.test.js +41 -74
- package/types/index.d.ts +29 -4
- package/src/runtime/internal/client/compat.js +0 -40
- package/tests/utils/compiler-compat-config.test.js +0 -38
|
@@ -3,15 +3,17 @@ import { compile } from '@tsrx/ripple';
|
|
|
3
3
|
describe('CSS :global scoping verification', () => {
|
|
4
4
|
it('verifies scoped styles are isolated', () => {
|
|
5
5
|
const source = `
|
|
6
|
-
export function Test() {
|
|
7
|
-
|
|
6
|
+
export function Test() @{
|
|
7
|
+
<>
|
|
8
|
+
<div class="scoped">{'content'}</div>
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
<style>
|
|
11
|
+
.scoped {
|
|
12
|
+
color: red;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
</>
|
|
16
|
+
}`;
|
|
15
17
|
const { css } = compile(source, 'test.tsrx');
|
|
16
18
|
|
|
17
19
|
expect(css).toMatch(/\.scoped\.tsrx-[a-z0-9]+/);
|
|
@@ -20,15 +22,17 @@ export function Test() { return <>
|
|
|
20
22
|
|
|
21
23
|
it('verifies :global styles bypass scoping', () => {
|
|
22
24
|
const source = `
|
|
23
|
-
export function Test() {
|
|
24
|
-
|
|
25
|
+
export function Test() @{
|
|
26
|
+
<>
|
|
27
|
+
<div class="global">{'content'}</div>
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
<style>
|
|
30
|
+
:global(.global) {
|
|
31
|
+
color: red;
|
|
32
|
+
}
|
|
33
|
+
</style>
|
|
34
|
+
</>
|
|
35
|
+
}`;
|
|
32
36
|
const { css } = compile(source, 'test.tsrx');
|
|
33
37
|
|
|
34
38
|
expect(css).toContain('.global {');
|
|
@@ -37,33 +41,35 @@ export function Test() { return <>
|
|
|
37
41
|
|
|
38
42
|
it('verifies mixed local and global maintain proper scoping', () => {
|
|
39
43
|
const source = `
|
|
40
|
-
export function Test() {
|
|
41
|
-
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
export function Test() @{
|
|
45
|
+
<>
|
|
46
|
+
<div class="outer">
|
|
47
|
+
<span class="inner">{'content'}</span>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<style>
|
|
51
|
+
.outer {
|
|
52
|
+
color: red;
|
|
53
|
+
}
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
:global(.outer) {
|
|
56
|
+
color: blue;
|
|
57
|
+
}
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
.outer .inner {
|
|
60
|
+
color: green;
|
|
61
|
+
}
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
:global(.outer) .inner {
|
|
64
|
+
color: yellow;
|
|
65
|
+
}
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
.outer :global(.inner) {
|
|
68
|
+
color: purple;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
71
|
+
</>
|
|
72
|
+
}`;
|
|
67
73
|
const { css } = compile(source, 'test.tsrx');
|
|
68
74
|
|
|
69
75
|
expect(css).toMatch(/\.outer\.tsrx-[a-z0-9]+ {/);
|
|
@@ -75,29 +81,31 @@ export function Test() { return <>
|
|
|
75
81
|
|
|
76
82
|
it('verifies :global blocks scope all nested selectors globally', () => {
|
|
77
83
|
const source = `
|
|
78
|
-
export function Test() {
|
|
79
|
-
|
|
80
|
-
<
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
export function Test() @{
|
|
85
|
+
<>
|
|
86
|
+
<div>
|
|
87
|
+
<span>
|
|
88
|
+
<button>{'click'}</button>
|
|
89
|
+
</span>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<style>
|
|
93
|
+
:global {
|
|
94
|
+
div {
|
|
95
|
+
color: red;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
span {
|
|
99
|
+
color: blue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
button {
|
|
103
|
+
color: green;
|
|
104
|
+
}
|
|
97
105
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
</style>
|
|
107
|
+
</>
|
|
108
|
+
}`;
|
|
101
109
|
const { css } = compile(source, 'test.tsrx');
|
|
102
110
|
|
|
103
111
|
expect(css).toContain('div {');
|
|
@@ -110,27 +118,29 @@ export function Test() { return <>
|
|
|
110
118
|
|
|
111
119
|
it('verifies element selectors are scoped by default', () => {
|
|
112
120
|
const source = `
|
|
113
|
-
export function Test() {
|
|
114
|
-
|
|
115
|
-
<
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
export function Test() @{
|
|
122
|
+
<>
|
|
123
|
+
<div>
|
|
124
|
+
<span>
|
|
125
|
+
<button>{'click'}</button>
|
|
126
|
+
</span>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<style>
|
|
130
|
+
div {
|
|
131
|
+
color: red;
|
|
132
|
+
}
|
|
124
133
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
span {
|
|
135
|
+
color: blue;
|
|
136
|
+
}
|
|
128
137
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
button {
|
|
139
|
+
color: green;
|
|
140
|
+
}
|
|
141
|
+
</style>
|
|
142
|
+
</>
|
|
143
|
+
}`;
|
|
134
144
|
const { css } = compile(source, 'test.tsrx');
|
|
135
145
|
|
|
136
146
|
expect(css).toMatch(/div\.tsrx-[a-z0-9]+/);
|
|
@@ -140,19 +150,21 @@ export function Test() { return <>
|
|
|
140
150
|
|
|
141
151
|
it('verifies :global() escapes only the wrapped selector', () => {
|
|
142
152
|
const source = `
|
|
143
|
-
export function Test() {
|
|
144
|
-
|
|
145
|
-
<
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
export function Test() @{
|
|
154
|
+
<>
|
|
155
|
+
<div class="local">
|
|
156
|
+
<span class="global">
|
|
157
|
+
<button class="local">{'click'}</button>
|
|
158
|
+
</span>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<style>
|
|
162
|
+
.local :global(.global .local) {
|
|
163
|
+
color: red;
|
|
164
|
+
}
|
|
165
|
+
</style>
|
|
166
|
+
</>
|
|
167
|
+
}`;
|
|
156
168
|
const { css } = compile(source, 'test.tsrx');
|
|
157
169
|
|
|
158
170
|
expect(css).toMatch(/\.local\.tsrx-[a-z0-9]+ \.global \.local {/);
|
|
@@ -161,25 +173,29 @@ export function Test() { return <>
|
|
|
161
173
|
|
|
162
174
|
it('verifies multiple components have different scope hashes', () => {
|
|
163
175
|
const source1 = `
|
|
164
|
-
export function Test1() {
|
|
165
|
-
|
|
176
|
+
export function Test1() @{
|
|
177
|
+
<>
|
|
178
|
+
<div class="test">{'one'}</div>
|
|
166
179
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
180
|
+
<style>
|
|
181
|
+
.test {
|
|
182
|
+
color: red;
|
|
183
|
+
}
|
|
184
|
+
</style>
|
|
185
|
+
</>
|
|
186
|
+
}`;
|
|
173
187
|
const source2 = `
|
|
174
|
-
export function Test2() {
|
|
175
|
-
|
|
188
|
+
export function Test2() @{
|
|
189
|
+
<>
|
|
190
|
+
<div class="test">{'two'}</div>
|
|
176
191
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
<style>
|
|
193
|
+
.test {
|
|
194
|
+
color: blue;
|
|
195
|
+
}
|
|
196
|
+
</style>
|
|
197
|
+
</>
|
|
198
|
+
}`;
|
|
183
199
|
const { css: css1 } = compile(source1, 'test1.tsrx');
|
|
184
200
|
const { css: css2 } = compile(source2, 'test2.tsrx');
|
|
185
201
|
|
|
@@ -199,25 +215,29 @@ export function Test2() { return <>
|
|
|
199
215
|
|
|
200
216
|
it('verifies :global styles are consistent across components', () => {
|
|
201
217
|
const source1 = `
|
|
202
|
-
export function Test1() {
|
|
203
|
-
|
|
218
|
+
export function Test1() @{
|
|
219
|
+
<>
|
|
220
|
+
<div class="global">{'one'}</div>
|
|
204
221
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
222
|
+
<style>
|
|
223
|
+
:global(.global) {
|
|
224
|
+
color: red;
|
|
225
|
+
}
|
|
226
|
+
</style>
|
|
227
|
+
</>
|
|
228
|
+
}`;
|
|
211
229
|
const source2 = `
|
|
212
|
-
export function Test2() {
|
|
213
|
-
|
|
230
|
+
export function Test2() @{
|
|
231
|
+
<>
|
|
232
|
+
<div class="global">{'two'}</div>
|
|
214
233
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
234
|
+
<style>
|
|
235
|
+
:global(.global) {
|
|
236
|
+
color: blue;
|
|
237
|
+
}
|
|
238
|
+
</style>
|
|
239
|
+
</>
|
|
240
|
+
}`;
|
|
221
241
|
const { css: css1 } = compile(source1, 'test1.tsrx');
|
|
222
242
|
const { css: css2 } = compile(source2, 'test2.tsrx');
|
|
223
243
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { track } from 'ripple';
|
|
1
|
+
import { Dynamic, track } from 'ripple';
|
|
2
2
|
import { compile } from '@tsrx/ripple';
|
|
3
3
|
|
|
4
4
|
const external_styles = <style>
|
|
@@ -10,18 +10,18 @@ const external_styles = <style>
|
|
|
10
10
|
describe('style class maps', () => {
|
|
11
11
|
describe('basic usage with components', () => {
|
|
12
12
|
it('passes scoped classes to a child component via a style expression', () => {
|
|
13
|
-
function Child({ className }: { className: string }) {
|
|
14
|
-
|
|
13
|
+
function Child({ className }: { className: string }) @{
|
|
14
|
+
<div class={className}>{'styled child'}</div>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function Parent() {
|
|
17
|
+
function Parent() @{
|
|
18
18
|
const styles = <style>
|
|
19
19
|
.highlight {
|
|
20
20
|
color: red;
|
|
21
21
|
}
|
|
22
22
|
</style>;
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
<Child className={styles.highlight} />
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
render(Parent);
|
|
@@ -35,14 +35,14 @@ describe('style class maps', () => {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('passes multiple style expression classes to a child component', () => {
|
|
38
|
-
function Child({ primary, secondary }: { primary: string; secondary: string }) {
|
|
39
|
-
|
|
38
|
+
function Child({ primary, secondary }: { primary: string; secondary: string }) @{
|
|
39
|
+
<>
|
|
40
40
|
<div class={primary}>{'primary'}</div>
|
|
41
41
|
<span class={secondary}>{'secondary'}</span>
|
|
42
|
-
|
|
42
|
+
</>
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function Parent() {
|
|
45
|
+
function Parent() @{
|
|
46
46
|
const styles = <style>
|
|
47
47
|
.primary {
|
|
48
48
|
color: blue;
|
|
@@ -52,7 +52,7 @@ describe('style class maps', () => {
|
|
|
52
52
|
}
|
|
53
53
|
</style>;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
<Child primary={styles.primary} secondary={styles.secondary} />
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
render(Parent);
|
|
@@ -74,42 +74,38 @@ describe('style class maps', () => {
|
|
|
74
74
|
|
|
75
75
|
it('allows style expression classes on child components with children', () => {
|
|
76
76
|
const source = `
|
|
77
|
-
function Child({ className }) {
|
|
78
|
-
<div class={className}>
|
|
79
|
-
|
|
80
|
-
function App() {
|
|
77
|
+
function Child({ className }) @{
|
|
78
|
+
<div class={className}>hello world</div>
|
|
79
|
+
}
|
|
80
|
+
function App() @{
|
|
81
81
|
const styles = <style>
|
|
82
82
|
.container {
|
|
83
83
|
color: red;
|
|
84
84
|
}
|
|
85
85
|
</style>;
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
<Child className={styles.container}>"hello world"</Child>
|
|
89
|
-
</>;
|
|
87
|
+
<Child className={styles.container}>hello world</Child>
|
|
90
88
|
}`;
|
|
91
89
|
|
|
92
90
|
expect(() => compile(source, 'test.tsrx')).not.toThrow();
|
|
93
91
|
});
|
|
94
92
|
|
|
95
93
|
it('passes scoped classes to a dynamic child component via a style expression', () => {
|
|
96
|
-
function Child({ cls }: { cls: string }) {
|
|
97
|
-
|
|
94
|
+
function Child({ cls }: { cls: string }) @{
|
|
95
|
+
<span class={cls}>{'text'}</span>
|
|
98
96
|
}
|
|
99
97
|
|
|
100
|
-
function Parent() {
|
|
98
|
+
function Parent() @{
|
|
101
99
|
const styles = <style>
|
|
102
100
|
.text {
|
|
103
101
|
color: red;
|
|
104
102
|
}
|
|
105
103
|
</style>;
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
</div>
|
|
112
|
-
</>;
|
|
105
|
+
let dynamic = track(() => Child);
|
|
106
|
+
<div class="wrapper">
|
|
107
|
+
<Dynamic is={dynamic} cls={styles.text} />
|
|
108
|
+
</div>
|
|
113
109
|
}
|
|
114
110
|
|
|
115
111
|
render(Parent);
|
|
@@ -122,12 +118,12 @@ function App() {
|
|
|
122
118
|
});
|
|
123
119
|
|
|
124
120
|
it('passes style expression classes declared outside the component', () => {
|
|
125
|
-
function Child({ cls }: { cls: string }) {
|
|
126
|
-
|
|
121
|
+
function Child({ cls }: { cls: string }) @{
|
|
122
|
+
<span class={cls}>{'text'}</span>
|
|
127
123
|
}
|
|
128
124
|
|
|
129
|
-
function Parent() {
|
|
130
|
-
|
|
125
|
+
function Parent() @{
|
|
126
|
+
<Child cls={external_styles.external} />
|
|
131
127
|
}
|
|
132
128
|
|
|
133
129
|
render(Parent);
|
|
@@ -140,25 +136,25 @@ function App() {
|
|
|
140
136
|
});
|
|
141
137
|
|
|
142
138
|
it('child can combine its own classes with a parent style expression class', () => {
|
|
143
|
-
function Card({ className }: { className?: string }) {
|
|
144
|
-
|
|
139
|
+
function Card({ className }: { className?: string }) @{
|
|
140
|
+
<>
|
|
145
141
|
<div class={['card-base', className ?? '']}>{'card content'}</div>
|
|
146
142
|
<style>
|
|
147
143
|
.card-base {
|
|
148
144
|
border: 1px solid black;
|
|
149
145
|
}
|
|
150
146
|
</style>
|
|
151
|
-
|
|
147
|
+
</>
|
|
152
148
|
}
|
|
153
149
|
|
|
154
|
-
function App() {
|
|
150
|
+
function App() @{
|
|
155
151
|
const styles = <style>
|
|
156
152
|
.themed {
|
|
157
153
|
background: purple;
|
|
158
154
|
}
|
|
159
155
|
</style>;
|
|
160
156
|
|
|
161
|
-
|
|
157
|
+
<Card className={styles.themed} />
|
|
162
158
|
}
|
|
163
159
|
|
|
164
160
|
render(App);
|
|
@@ -171,11 +167,11 @@ function App() {
|
|
|
171
167
|
});
|
|
172
168
|
|
|
173
169
|
it('passes a standalone class even when it also appears in descendant context', () => {
|
|
174
|
-
function Child({ cls }: { cls: string }) {
|
|
175
|
-
|
|
170
|
+
function Child({ cls }: { cls: string }) @{
|
|
171
|
+
<span class={cls}>{'text'}</span>
|
|
176
172
|
}
|
|
177
173
|
|
|
178
|
-
function App() {
|
|
174
|
+
function App() @{
|
|
179
175
|
const styles = <style>
|
|
180
176
|
.dual {
|
|
181
177
|
color: blue;
|
|
@@ -185,11 +181,9 @@ function App() {
|
|
|
185
181
|
}
|
|
186
182
|
</style>;
|
|
187
183
|
|
|
188
|
-
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
</div>
|
|
192
|
-
</>;
|
|
184
|
+
<div class="parent">
|
|
185
|
+
<Child cls={styles.dual} />
|
|
186
|
+
</div>
|
|
193
187
|
}
|
|
194
188
|
|
|
195
189
|
render(App);
|
|
@@ -205,30 +199,33 @@ function App() {
|
|
|
205
199
|
describe('removed syntax', () => {
|
|
206
200
|
it('does not parse the old style directive in attributes', () => {
|
|
207
201
|
const source = `
|
|
208
|
-
function Child({ cls }) {
|
|
202
|
+
function Child({ cls }) @{
|
|
209
203
|
<div class={cls}>{'text'}</div>
|
|
210
|
-
|
|
211
|
-
function App() {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
204
|
+
}
|
|
205
|
+
function App() @{
|
|
206
|
+
<>
|
|
207
|
+
<Child cls={style 'highlight'} />
|
|
208
|
+
<style>
|
|
209
|
+
.highlight {
|
|
210
|
+
color: red;
|
|
211
|
+
}
|
|
212
|
+
</style>
|
|
213
|
+
</>
|
|
214
|
+
}`;
|
|
220
215
|
expect(() => compile(source, 'test.tsrx')).toThrow();
|
|
221
216
|
});
|
|
222
217
|
|
|
223
218
|
it('does not parse the old style directive as a child expression', () => {
|
|
224
|
-
const source = `function App() {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
const source = `function App() @{
|
|
220
|
+
<>
|
|
221
|
+
<div>{style 'foo'}</div>
|
|
222
|
+
<style>
|
|
223
|
+
.foo {
|
|
224
|
+
color: red;
|
|
225
|
+
}
|
|
226
|
+
</style>
|
|
227
|
+
</>
|
|
228
|
+
}`;
|
|
232
229
|
expect(() => compile(source, 'test.tsrx')).toThrow();
|
|
233
230
|
});
|
|
234
231
|
});
|
|
@@ -236,19 +233,17 @@ function App() { return <>
|
|
|
236
233
|
describe('compiler output', () => {
|
|
237
234
|
it('emits style class maps for client mode', () => {
|
|
238
235
|
const source = `
|
|
239
|
-
function Child({ cls }) {
|
|
236
|
+
function Child({ cls }) @{
|
|
240
237
|
<div class={cls}>{'text'}</div>
|
|
241
|
-
|
|
242
|
-
export function App() {
|
|
238
|
+
}
|
|
239
|
+
export function App() @{
|
|
243
240
|
const styles = <style>
|
|
244
241
|
.highlight {
|
|
245
242
|
color: red;
|
|
246
243
|
}
|
|
247
244
|
</style>;
|
|
248
245
|
|
|
249
|
-
return <>
|
|
250
246
|
<Child cls={styles.highlight} />
|
|
251
|
-
</>;
|
|
252
247
|
}`;
|
|
253
248
|
const { code } = compile(source, 'test.tsrx');
|
|
254
249
|
|
|
@@ -258,19 +253,17 @@ export function App() {
|
|
|
258
253
|
|
|
259
254
|
it('emits style class maps for server mode', () => {
|
|
260
255
|
const source = `
|
|
261
|
-
function Child({ cls }) {
|
|
256
|
+
function Child({ cls }) @{
|
|
262
257
|
<div class={cls}>{'text'}</div>
|
|
263
|
-
|
|
264
|
-
export function App() {
|
|
258
|
+
}
|
|
259
|
+
export function App() @{
|
|
265
260
|
const styles = <style>
|
|
266
261
|
.highlight {
|
|
267
262
|
color: red;
|
|
268
263
|
}
|
|
269
264
|
</style>;
|
|
270
265
|
|
|
271
|
-
return <>
|
|
272
266
|
<Child cls={styles.highlight} />
|
|
273
|
-
</>;
|
|
274
267
|
}`;
|
|
275
268
|
const { code } = compile(source, 'test.tsrx', { mode: 'server' });
|
|
276
269
|
|