Skip to content

Commit d010aff

Browse files
authored
Merge pull request #1388 from sveltejs/collapse-hydrate-logic
Collapse hydrate logic
2 parents 1130556 + da2a45a commit d010aff

File tree

57 files changed

+310
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+310
-430
lines changed

src/compile/dom/Block.ts

+20-12
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export default class Block {
140140
}
141141

142142
toString() {
143+
const { dev } = this.compiler.options;
144+
143145
let introing;
144146
const hasIntros = !this.builders.intro.isEmpty();
145147
if (hasIntros) {
@@ -177,10 +179,16 @@ export default class Block {
177179
if (this.builders.create.isEmpty() && this.builders.hydrate.isEmpty()) {
178180
properties.addBlock(`c: @noop,`);
179181
} else {
182+
const hydrate = !this.builders.hydrate.isEmpty() && (
183+
this.compiler.options.hydratable
184+
? `this.h()`
185+
: this.builders.hydrate
186+
);
187+
180188
properties.addBlock(deindent`
181-
c: function create() {
189+
${dev ? 'c: function create' : 'c'}() {
182190
${this.builders.create}
183-
${!this.builders.hydrate.isEmpty() && `this.h();`}
191+
${hydrate}
184192
},
185193
`);
186194
}
@@ -190,17 +198,17 @@ export default class Block {
190198
properties.addBlock(`l: @noop,`);
191199
} else {
192200
properties.addBlock(deindent`
193-
l: function claim(nodes) {
201+
${dev ? 'l: function claim' : 'l'}(nodes) {
194202
${this.builders.claim}
195203
${!this.builders.hydrate.isEmpty() && `this.h();`}
196204
},
197205
`);
198206
}
199207
}
200208

201-
if (!this.builders.hydrate.isEmpty()) {
209+
if (this.compiler.options.hydratable && !this.builders.hydrate.isEmpty()) {
202210
properties.addBlock(deindent`
203-
h: function hydrate() {
211+
${dev ? 'h: function hydrate' : 'h'}() {
204212
${this.builders.hydrate}
205213
},
206214
`);
@@ -210,7 +218,7 @@ export default class Block {
210218
properties.addBlock(`m: @noop,`);
211219
} else {
212220
properties.addBlock(deindent`
213-
m: function mount(#target, anchor) {
221+
${dev ? 'm: function mount' : 'm'}(#target, anchor) {
214222
${this.builders.mount}
215223
},
216224
`);
@@ -221,7 +229,7 @@ export default class Block {
221229
properties.addBlock(`p: @noop,`);
222230
} else {
223231
properties.addBlock(deindent`
224-
p: function update(changed, ${this.maintainContext ? '_ctx' : 'ctx'}) {
232+
${dev ? 'p: function update' : 'p'}(changed, ${this.maintainContext ? '_ctx' : 'ctx'}) {
225233
${this.maintainContext && `ctx = _ctx;`}
226234
${this.builders.update}
227235
},
@@ -232,7 +240,7 @@ export default class Block {
232240
if (this.hasIntroMethod) {
233241
if (hasIntros) {
234242
properties.addBlock(deindent`
235-
i: function intro(#target, anchor) {
243+
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
236244
if (${introing}) return;
237245
${introing} = true;
238246
${hasOutros && `${outroing} = false;`}
@@ -244,7 +252,7 @@ export default class Block {
244252
`);
245253
} else {
246254
properties.addBlock(deindent`
247-
i: function intro(#target, anchor) {
255+
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
248256
this.m(#target, anchor);
249257
},
250258
`);
@@ -254,7 +262,7 @@ export default class Block {
254262
if (this.hasOutroMethod) {
255263
if (hasOutros) {
256264
properties.addBlock(deindent`
257-
o: function outro(#outrocallback) {
265+
${dev ? 'o: function outro' : 'o'}(#outrocallback) {
258266
if (${outroing}) return;
259267
${outroing} = true;
260268
${hasIntros && `${introing} = false;`}
@@ -275,7 +283,7 @@ export default class Block {
275283
properties.addBlock(`u: @noop,`);
276284
} else {
277285
properties.addBlock(deindent`
278-
u: function unmount() {
286+
${dev ? 'u: function unmount' : 'u'}() {
279287
${this.builders.unmount}
280288
},
281289
`);
@@ -285,7 +293,7 @@ export default class Block {
285293
properties.addBlock(`d: @noop`);
286294
} else {
287295
properties.addBlock(deindent`
288-
d: function destroy() {
296+
${dev ? 'd: function destroy' : 'd'}() {
289297
${this.builders.destroy}
290298
}
291299
`);

test/js/samples/action/expected-bundle.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -154,28 +154,24 @@ function create_main_fragment(component, ctx) {
154154
var a, link_action;
155155

156156
return {
157-
c: function create() {
157+
c() {
158158
a = createElement("a");
159159
a.textContent = "Test";
160-
this.h();
161-
},
162-
163-
h: function hydrate() {
164160
a.href = "#";
165161
link_action = link.call(component, a) || {};
166162
},
167163

168-
m: function mount(target, anchor) {
164+
m(target, anchor) {
169165
insertNode(a, target, anchor);
170166
},
171167

172168
p: noop,
173169

174-
u: function unmount() {
170+
u() {
175171
detachNode(a);
176172
},
177173

178-
d: function destroy$$1() {
174+
d() {
179175
if (typeof link_action.destroy === 'function') link_action.destroy.call(component);
180176
}
181177
};

test/js/samples/action/expected.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,24 @@ function create_main_fragment(component, ctx) {
2121
var a, link_action;
2222

2323
return {
24-
c: function create() {
24+
c() {
2525
a = createElement("a");
2626
a.textContent = "Test";
27-
this.h();
28-
},
29-
30-
h: function hydrate() {
3127
a.href = "#";
3228
link_action = link.call(component, a) || {};
3329
},
3430

35-
m: function mount(target, anchor) {
31+
m(target, anchor) {
3632
insertNode(a, target, anchor);
3733
},
3834

3935
p: noop,
4036

41-
u: function unmount() {
37+
u() {
4238
detachNode(a);
4339
},
4440

45-
d: function destroy() {
41+
d() {
4642
if (typeof link_action.destroy === 'function') link_action.destroy.call(component);
4743
}
4844
};

test/js/samples/collapses-text-around-comments/expected-bundle.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -157,28 +157,24 @@ function create_main_fragment(component, ctx) {
157157
var p, text;
158158

159159
return {
160-
c: function create() {
160+
c() {
161161
p = createElement("p");
162162
text = createText(ctx.foo);
163-
this.h();
164-
},
165-
166-
h: function hydrate() {
167163
p.className = "svelte-1a7i8ec";
168164
},
169165

170-
m: function mount(target, anchor) {
166+
m(target, anchor) {
171167
insertNode(p, target, anchor);
172168
appendNode(text, p);
173169
},
174170

175-
p: function update(changed, ctx) {
171+
p(changed, ctx) {
176172
if (changed.foo) {
177173
text.data = ctx.foo;
178174
}
179175
},
180176

181-
u: function unmount() {
177+
u() {
182178
detachNode(p);
183179
},
184180

test/js/samples/collapses-text-around-comments/expected.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,24 @@ function create_main_fragment(component, ctx) {
1616
var p, text;
1717

1818
return {
19-
c: function create() {
19+
c() {
2020
p = createElement("p");
2121
text = createText(ctx.foo);
22-
this.h();
23-
},
24-
25-
h: function hydrate() {
2622
p.className = "svelte-1a7i8ec";
2723
},
2824

29-
m: function mount(target, anchor) {
25+
m(target, anchor) {
3026
insertNode(p, target, anchor);
3127
appendNode(text, p);
3228
},
3329

34-
p: function update(changed, ctx) {
30+
p(changed, ctx) {
3531
if (changed.foo) {
3632
text.data = ctx.foo;
3733
}
3834
},
3935

40-
u: function unmount() {
36+
u() {
4137
detachNode(p);
4238
},
4339

test/js/samples/component-static-immutable/expected-bundle.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@ function create_main_fragment(component, ctx) {
138138
});
139139

140140
return {
141-
c: function create() {
141+
c() {
142142
nested._fragment.c();
143143
},
144144

145-
m: function mount(target, anchor) {
145+
m(target, anchor) {
146146
nested._mount(target, anchor);
147147
},
148148

149149
p: noop,
150150

151-
u: function unmount() {
151+
u() {
152152
nested._unmount();
153153
},
154154

155-
d: function destroy$$1() {
155+
d() {
156156
nested.destroy(false);
157157
}
158158
};

test/js/samples/component-static-immutable/expected.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ function create_main_fragment(component, ctx) {
1212
});
1313

1414
return {
15-
c: function create() {
15+
c() {
1616
nested._fragment.c();
1717
},
1818

19-
m: function mount(target, anchor) {
19+
m(target, anchor) {
2020
nested._mount(target, anchor);
2121
},
2222

2323
p: noop,
2424

25-
u: function unmount() {
25+
u() {
2626
nested._unmount();
2727
},
2828

29-
d: function destroy() {
29+
d() {
3030
nested.destroy(false);
3131
}
3232
};

test/js/samples/component-static-immutable2/expected-bundle.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@ function create_main_fragment(component, ctx) {
138138
});
139139

140140
return {
141-
c: function create() {
141+
c() {
142142
nested._fragment.c();
143143
},
144144

145-
m: function mount(target, anchor) {
145+
m(target, anchor) {
146146
nested._mount(target, anchor);
147147
},
148148

149149
p: noop,
150150

151-
u: function unmount() {
151+
u() {
152152
nested._unmount();
153153
},
154154

155-
d: function destroy$$1() {
155+
d() {
156156
nested.destroy(false);
157157
}
158158
};

test/js/samples/component-static-immutable2/expected.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ function create_main_fragment(component, ctx) {
1212
});
1313

1414
return {
15-
c: function create() {
15+
c() {
1616
nested._fragment.c();
1717
},
1818

19-
m: function mount(target, anchor) {
19+
m(target, anchor) {
2020
nested._mount(target, anchor);
2121
},
2222

2323
p: noop,
2424

25-
u: function unmount() {
25+
u() {
2626
nested._unmount();
2727
},
2828

29-
d: function destroy() {
29+
d() {
3030
nested.destroy(false);
3131
}
3232
};

test/js/samples/component-static/expected-bundle.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ function create_main_fragment(component, ctx) {
134134
});
135135

136136
return {
137-
c: function create() {
137+
c() {
138138
nested._fragment.c();
139139
},
140140

141-
m: function mount(target, anchor) {
141+
m(target, anchor) {
142142
nested._mount(target, anchor);
143143
},
144144

145145
p: noop,
146146

147-
u: function unmount() {
147+
u() {
148148
nested._unmount();
149149
},
150150

151-
d: function destroy$$1() {
151+
d() {
152152
nested.destroy(false);
153153
}
154154
};

test/js/samples/component-static/expected.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ function create_main_fragment(component, ctx) {
1212
});
1313

1414
return {
15-
c: function create() {
15+
c() {
1616
nested._fragment.c();
1717
},
1818

19-
m: function mount(target, anchor) {
19+
m(target, anchor) {
2020
nested._mount(target, anchor);
2121
},
2222

2323
p: noop,
2424

25-
u: function unmount() {
25+
u() {
2626
nested._unmount();
2727
},
2828

29-
d: function destroy() {
29+
d() {
3030
nested.destroy(false);
3131
}
3232
};

0 commit comments

Comments
 (0)