Skip to content

Commit 338c856

Browse files
authored
Merge pull request #1448 from sveltejs/gh-547
add skipIntroByDefault compiler option
2 parents 3c1bcfa + 44bb2da commit 338c856

File tree

94 files changed

+282
-224
lines changed

Some content is hidden

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

94 files changed

+282
-224
lines changed

src/compile/dom/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export default function dom(
227227
this._fragment.c();
228228
this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(this.shadowRoot, null);
229229
230-
if (options.target) this._mount(options.target, options.anchor);
230+
if (options.target) this._mount(options.target, options.anchor, ${options.skipIntroByDefault ? `options.intro` : 'true'});
231231
` : deindent`
232232
if (options.target) {
233233
${compiler.options.hydratable
@@ -240,7 +240,7 @@ export default function dom(
240240
${options.dev && `if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`}
241241
this._fragment.c();
242242
`}
243-
this._mount(options.target, options.anchor);
243+
this._mount(options.target, options.anchor, ${options.skipIntroByDefault ? `options.intro` : 'true'});
244244
245245
${(compiler.hasComponents || target.hasComplexBindings || hasInitHooks || target.hasIntroTransitions) && deindent`
246246
${compiler.hasComponents && `this._lock = true;`}

src/compile/nodes/Component.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export default class Component extends Node {
383383

384384
block.builders.mount.addBlock(deindent`
385385
if (${name}) {
386-
${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});
386+
${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'}, ${compiler.options.skipIntroByDefault ? 'false' : 'true'});
387387
${this.ref && `#component.refs.${this.ref} = ${name};`}
388388
}
389389
`);
@@ -405,7 +405,7 @@ export default class Component extends Node {
405405
${name}._fragment.c();
406406
407407
${this.children.map(child => child.remount(name))}
408-
${name}._mount(${updateMountNode}, ${anchor});
408+
${name}._mount(${updateMountNode}, ${anchor}, ${compiler.options.skipIntroByDefault ? 'false' : 'true'});
409409
410410
${this.handlers.map(handler => deindent`
411411
${name}.on("${handler.name}", ${handler.var});
@@ -464,7 +464,7 @@ export default class Component extends Node {
464464
}
465465

466466
block.builders.mount.addLine(
467-
`${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});`
467+
`${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'}, ${compiler.options.skipIntroByDefault ? 'false' : 'true'});`
468468
);
469469

470470
if (updates.length) {
@@ -483,7 +483,7 @@ export default class Component extends Node {
483483
}
484484

485485
remount(name: string) {
486-
return `${this.var}._mount(${name}._slotted.default, null);`;
486+
return `${this.var}._mount(${name}._slotted.default, null, ${this.compiler.options.skipIntroByDefault ? 'false' : 'true'});`;
487487
}
488488

489489
ssr() {

src/interfaces.ts

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export interface CompileOptions {
6464

6565
onerror?: (error: Error) => void;
6666
onwarn?: (warning: Warning) => void;
67+
68+
// to remove in v3
69+
skipIntroByDefault?: boolean;
6770
}
6871

6972
export interface GenerateOptions {

src/shared/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ export function callAll(fns) {
128128
while (fns && fns.length) fns.shift()();
129129
}
130130

131-
export function _mount(target, anchor) {
132-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
131+
export function _mount(target, anchor, intro) {
132+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
133133
}
134134

135135
export var PENDING = {};

test/cli/samples/basic/expected/Main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/Main.html generated by Svelte v2.4.4 */
1+
/* src/Main.html generated by Svelte v2.5.1 */
22

33
function create_main_fragment(component, ctx) {
44
var p;
@@ -31,7 +31,7 @@ function Main(options) {
3131

3232
if (options.target) {
3333
this._fragment.c();
34-
this._mount(options.target, options.anchor);
34+
this._mount(options.target, options.anchor, true);
3535
}
3636
}
3737

@@ -149,8 +149,8 @@ function _set(newState) {
149149
}
150150
}
151151

152-
function _mount(target, anchor) {
153-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
152+
function _mount(target, anchor, intro) {
153+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
154154
}
155155

156156
function _differs(a, b) {

test/cli/samples/custom-element/expected/Main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/Main.html generated by Svelte v2.4.4 */
1+
/* src/Main.html generated by Svelte v2.5.1 */
22

33
function create_main_fragment(component, ctx) {
44
var p;
@@ -37,7 +37,7 @@ class Main extends HTMLElement {
3737
this._fragment.c();
3838
this._fragment.m(this.shadowRoot, null);
3939

40-
if (options.target) this._mount(options.target, options.anchor);
40+
if (options.target) this._mount(options.target, options.anchor, true);
4141
}
4242

4343
static get observedAttributes() {
@@ -170,8 +170,8 @@ function _set(newState) {
170170
}
171171
}
172172

173-
function _mount(target, anchor) {
174-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
173+
function _mount(target, anchor, intro) {
174+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
175175
}
176176

177177
function _differs(a, b) {

test/cli/samples/dev/expected/Main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/Main.html generated by Svelte v2.4.4 */
1+
/* src/Main.html generated by Svelte v2.5.1 */
22

33
function create_main_fragment(component, ctx) {
44
var p;
@@ -34,7 +34,7 @@ function Main(options) {
3434
if (options.target) {
3535
if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
3636
this._fragment.c();
37-
this._mount(options.target, options.anchor);
37+
this._mount(options.target, options.anchor, true);
3838
}
3939
}
4040

@@ -153,8 +153,8 @@ function _set(newState) {
153153
}
154154
}
155155

156-
function _mount(target, anchor) {
157-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
156+
function _mount(target, anchor, intro) {
157+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
158158
}
159159

160160
function _differs(a, b) {

test/cli/samples/dir-sourcemap/expected/Main.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cli/samples/dir-sourcemap/expected/Widget.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cli/samples/dir-subdir/expected/Main.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/Main.html generated by Svelte v2.4.4 */
1+
/* src/Main.html generated by Svelte v2.5.1 */
22
import Widget from './widget/Widget.html';
33

44

@@ -15,7 +15,7 @@ function create_main_fragment(component, ctx) {
1515
},
1616

1717
m(target, anchor) {
18-
widget._mount(target, anchor);
18+
widget._mount(target, anchor, true);
1919
},
2020

2121
p: noop,
@@ -40,7 +40,7 @@ function Main(options) {
4040

4141
if (options.target) {
4242
this._fragment.c();
43-
this._mount(options.target, options.anchor);
43+
this._mount(options.target, options.anchor, true);
4444

4545
this._lock = true;
4646
callAll(this._beforecreate);
@@ -156,8 +156,8 @@ function _set(newState) {
156156
}
157157
}
158158

159-
function _mount(target, anchor) {
160-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
159+
function _mount(target, anchor, intro) {
160+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
161161
}
162162

163163
function _differs(a, b) {

test/cli/samples/dir-subdir/expected/widget/Widget.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/widget/Widget.html generated by Svelte v2.4.4 */
1+
/* src/widget/Widget.html generated by Svelte v2.5.1 */
22

33
function create_main_fragment(component, ctx) {
44
var p;
@@ -31,7 +31,7 @@ function Widget(options) {
3131

3232
if (options.target) {
3333
this._fragment.c();
34-
this._mount(options.target, options.anchor);
34+
this._mount(options.target, options.anchor, true);
3535
}
3636
}
3737

@@ -149,8 +149,8 @@ function _set(newState) {
149149
}
150150
}
151151

152-
function _mount(target, anchor) {
153-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
152+
function _mount(target, anchor, intro) {
153+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
154154
}
155155

156156
function _differs(a, b) {

test/cli/samples/dir/expected/Main.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/Main.html generated by Svelte v2.4.4 */
1+
/* src/Main.html generated by Svelte v2.5.1 */
22
import Widget from './Widget.html';
33

44

@@ -15,7 +15,7 @@ function create_main_fragment(component, ctx) {
1515
},
1616

1717
m(target, anchor) {
18-
widget._mount(target, anchor);
18+
widget._mount(target, anchor, true);
1919
},
2020

2121
p: noop,
@@ -40,7 +40,7 @@ function Main(options) {
4040

4141
if (options.target) {
4242
this._fragment.c();
43-
this._mount(options.target, options.anchor);
43+
this._mount(options.target, options.anchor, true);
4444

4545
this._lock = true;
4646
callAll(this._beforecreate);
@@ -156,8 +156,8 @@ function _set(newState) {
156156
}
157157
}
158158

159-
function _mount(target, anchor) {
160-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
159+
function _mount(target, anchor, intro) {
160+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
161161
}
162162

163163
function _differs(a, b) {

test/cli/samples/dir/expected/Widget.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/Widget.html generated by Svelte v2.4.4 */
1+
/* src/Widget.html generated by Svelte v2.5.1 */
22

33
function create_main_fragment(component, ctx) {
44
var p;
@@ -31,7 +31,7 @@ function Widget(options) {
3131

3232
if (options.target) {
3333
this._fragment.c();
34-
this._mount(options.target, options.anchor);
34+
this._mount(options.target, options.anchor, true);
3535
}
3636
}
3737

@@ -149,8 +149,8 @@ function _set(newState) {
149149
}
150150
}
151151

152-
function _mount(target, anchor) {
153-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
152+
function _mount(target, anchor, intro) {
153+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
154154
}
155155

156156
function _differs(a, b) {

test/cli/samples/globals/expected/Main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* src/Main.html generated by Svelte v2.4.4 */
1+
/* src/Main.html generated by Svelte v2.5.1 */
22
var Main = (function(answer) { "use strict";
33
answer = (answer && answer.__esModule) ? answer["default"] : answer;
44

@@ -46,7 +46,7 @@ var Main = (function(answer) { "use strict";
4646

4747
if (options.target) {
4848
this._fragment.c();
49-
this._mount(options.target, options.anchor);
49+
this._mount(options.target, options.anchor, true);
5050
}
5151
}
5252

@@ -170,8 +170,8 @@ var Main = (function(answer) { "use strict";
170170
}
171171
}
172172

173-
function _mount(target, anchor) {
174-
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
173+
function _mount(target, anchor, intro) {
174+
this._fragment[intro && this._fragment.i ? 'i' : 'm'](target, anchor || null);
175175
}
176176

177177
function _differs(a, b) {

test/cli/samples/sourcemap-inline/expected/Main.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)