Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add skipIntroByDefault compiler option #1448

Merged
merged 1 commit into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compile/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default function dom(
this._fragment.c();
this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(this.shadowRoot, null);

if (options.target) this._mount(options.target, options.anchor);
if (options.target) this._mount(options.target, options.anchor, ${options.skipIntroByDefault ? `options.intro` : 'true'});
` : deindent`
if (options.target) {
${compiler.options.hydratable
Expand All @@ -240,7 +240,7 @@ export default function dom(
${options.dev && `if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`}
this._fragment.c();
`}
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, ${options.skipIntroByDefault ? `options.intro` : 'true'});

${(compiler.hasComponents || target.hasComplexBindings || hasInitHooks || target.hasIntroTransitions) && deindent`
${compiler.hasComponents && `this._lock = true;`}
Expand Down
8 changes: 4 additions & 4 deletions src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export default class Component extends Node {

block.builders.mount.addBlock(deindent`
if (${name}) {
${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});
${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'}, ${compiler.options.skipIntroByDefault ? 'false' : 'true'});
${this.ref && `#component.refs.${this.ref} = ${name};`}
}
`);
Expand All @@ -405,7 +405,7 @@ export default class Component extends Node {
${name}._fragment.c();

${this.children.map(child => child.remount(name))}
${name}._mount(${updateMountNode}, ${anchor});
${name}._mount(${updateMountNode}, ${anchor}, ${compiler.options.skipIntroByDefault ? 'false' : 'true'});

${this.handlers.map(handler => deindent`
${name}.on("${handler.name}", ${handler.var});
Expand Down Expand Up @@ -464,7 +464,7 @@ export default class Component extends Node {
}

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

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

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

ssr() {
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export interface CompileOptions {

onerror?: (error: Error) => void;
onwarn?: (warning: Warning) => void;

// to remove in v3
skipIntroByDefault?: boolean;
}

export interface GenerateOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export function callAll(fns) {
while (fns && fns.length) fns.shift()();
}

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

export var PENDING = {};
Expand Down
8 changes: 4 additions & 4 deletions test/cli/samples/basic/expected/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.4.4 */
/* src/Main.html generated by Svelte v2.5.1 */

function create_main_fragment(component, ctx) {
var p;
Expand Down Expand Up @@ -31,7 +31,7 @@ function Main(options) {

if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, true);
}
}

Expand Down Expand Up @@ -149,8 +149,8 @@ function _set(newState) {
}
}

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

function _differs(a, b) {
Expand Down
8 changes: 4 additions & 4 deletions test/cli/samples/custom-element/expected/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.4.4 */
/* src/Main.html generated by Svelte v2.5.1 */

function create_main_fragment(component, ctx) {
var p;
Expand Down Expand Up @@ -37,7 +37,7 @@ class Main extends HTMLElement {
this._fragment.c();
this._fragment.m(this.shadowRoot, null);

if (options.target) this._mount(options.target, options.anchor);
if (options.target) this._mount(options.target, options.anchor, true);
}

static get observedAttributes() {
Expand Down Expand Up @@ -170,8 +170,8 @@ function _set(newState) {
}
}

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

function _differs(a, b) {
Expand Down
8 changes: 4 additions & 4 deletions test/cli/samples/dev/expected/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.4.4 */
/* src/Main.html generated by Svelte v2.5.1 */

function create_main_fragment(component, ctx) {
var p;
Expand Down Expand Up @@ -34,7 +34,7 @@ function Main(options) {
if (options.target) {
if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
this._fragment.c();
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, true);
}
}

Expand Down Expand Up @@ -153,8 +153,8 @@ function _set(newState) {
}
}

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

function _differs(a, b) {
Expand Down
10 changes: 5 additions & 5 deletions test/cli/samples/dir-sourcemap/expected/Main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/cli/samples/dir-sourcemap/expected/Widget.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions test/cli/samples/dir-subdir/expected/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.4.4 */
/* src/Main.html generated by Svelte v2.5.1 */
import Widget from './widget/Widget.html';


Expand All @@ -15,7 +15,7 @@ function create_main_fragment(component, ctx) {
},

m(target, anchor) {
widget._mount(target, anchor);
widget._mount(target, anchor, true);
},

p: noop,
Expand All @@ -40,7 +40,7 @@ function Main(options) {

if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, true);

this._lock = true;
callAll(this._beforecreate);
Expand Down Expand Up @@ -156,8 +156,8 @@ function _set(newState) {
}
}

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

function _differs(a, b) {
Expand Down
8 changes: 4 additions & 4 deletions test/cli/samples/dir-subdir/expected/widget/Widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/widget/Widget.html generated by Svelte v2.4.4 */
/* src/widget/Widget.html generated by Svelte v2.5.1 */

function create_main_fragment(component, ctx) {
var p;
Expand Down Expand Up @@ -31,7 +31,7 @@ function Widget(options) {

if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, true);
}
}

Expand Down Expand Up @@ -149,8 +149,8 @@ function _set(newState) {
}
}

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

function _differs(a, b) {
Expand Down
10 changes: 5 additions & 5 deletions test/cli/samples/dir/expected/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.4.4 */
/* src/Main.html generated by Svelte v2.5.1 */
import Widget from './Widget.html';


Expand All @@ -15,7 +15,7 @@ function create_main_fragment(component, ctx) {
},

m(target, anchor) {
widget._mount(target, anchor);
widget._mount(target, anchor, true);
},

p: noop,
Expand All @@ -40,7 +40,7 @@ function Main(options) {

if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, true);

this._lock = true;
callAll(this._beforecreate);
Expand Down Expand Up @@ -156,8 +156,8 @@ function _set(newState) {
}
}

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

function _differs(a, b) {
Expand Down
8 changes: 4 additions & 4 deletions test/cli/samples/dir/expected/Widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/Widget.html generated by Svelte v2.4.4 */
/* src/Widget.html generated by Svelte v2.5.1 */

function create_main_fragment(component, ctx) {
var p;
Expand Down Expand Up @@ -31,7 +31,7 @@ function Widget(options) {

if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, true);
}
}

Expand Down Expand Up @@ -149,8 +149,8 @@ function _set(newState) {
}
}

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

function _differs(a, b) {
Expand Down
8 changes: 4 additions & 4 deletions test/cli/samples/globals/expected/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.4.4 */
/* src/Main.html generated by Svelte v2.5.1 */
var Main = (function(answer) { "use strict";
answer = (answer && answer.__esModule) ? answer["default"] : answer;

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

if (options.target) {
this._fragment.c();
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor, true);
}
}

Expand Down Expand Up @@ -170,8 +170,8 @@ var Main = (function(answer) { "use strict";
}
}

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

function _differs(a, b) {
Expand Down
8 changes: 4 additions & 4 deletions test/cli/samples/sourcemap-inline/expected/Main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading