Skip to content

Commit

Permalink
Merge branch 'master' into gh-984
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 30, 2018
2 parents 4a67542 + d010aff commit ac4ff53
Show file tree
Hide file tree
Showing 57 changed files with 310 additions and 430 deletions.
32 changes: 20 additions & 12 deletions src/compile/dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export default class Block {
}

toString() {
const { dev } = this.compiler.options;

let introing;
const hasIntros = !this.builders.intro.isEmpty();
if (hasIntros) {
Expand Down Expand Up @@ -177,10 +179,16 @@ export default class Block {
if (this.builders.create.isEmpty() && this.builders.hydrate.isEmpty()) {
properties.addBlock(`c: @noop,`);
} else {
const hydrate = !this.builders.hydrate.isEmpty() && (
this.compiler.options.hydratable
? `this.h()`
: this.builders.hydrate
);

properties.addBlock(deindent`
c: function create() {
${dev ? 'c: function create' : 'c'}() {
${this.builders.create}
${!this.builders.hydrate.isEmpty() && `this.h();`}
${hydrate}
},
`);
}
Expand All @@ -190,17 +198,17 @@ export default class Block {
properties.addBlock(`l: @noop,`);
} else {
properties.addBlock(deindent`
l: function claim(nodes) {
${dev ? 'l: function claim' : 'l'}(nodes) {
${this.builders.claim}
${!this.builders.hydrate.isEmpty() && `this.h();`}
},
`);
}
}

if (!this.builders.hydrate.isEmpty()) {
if (this.compiler.options.hydratable && !this.builders.hydrate.isEmpty()) {
properties.addBlock(deindent`
h: function hydrate() {
${dev ? 'h: function hydrate' : 'h'}() {
${this.builders.hydrate}
},
`);
Expand All @@ -210,7 +218,7 @@ export default class Block {
properties.addBlock(`m: @noop,`);
} else {
properties.addBlock(deindent`
m: function mount(#target, anchor) {
${dev ? 'm: function mount' : 'm'}(#target, anchor) {
${this.builders.mount}
},
`);
Expand All @@ -221,7 +229,7 @@ export default class Block {
properties.addBlock(`p: @noop,`);
} else {
properties.addBlock(deindent`
p: function update(changed, ${this.maintainContext ? '_ctx' : 'ctx'}) {
${dev ? 'p: function update' : 'p'}(changed, ${this.maintainContext ? '_ctx' : 'ctx'}) {
${this.maintainContext && `ctx = _ctx;`}
${this.builders.update}
},
Expand All @@ -232,7 +240,7 @@ export default class Block {
if (this.hasIntroMethod) {
if (hasIntros) {
properties.addBlock(deindent`
i: function intro(#target, anchor) {
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
if (${introing}) return;
${introing} = true;
${hasOutros && `${outroing} = false;`}
Expand All @@ -244,7 +252,7 @@ export default class Block {
`);
} else {
properties.addBlock(deindent`
i: function intro(#target, anchor) {
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
this.m(#target, anchor);
},
`);
Expand All @@ -254,7 +262,7 @@ export default class Block {
if (this.hasOutroMethod) {
if (hasOutros) {
properties.addBlock(deindent`
o: function outro(#outrocallback) {
${dev ? 'o: function outro' : 'o'}(#outrocallback) {
if (${outroing}) return;
${outroing} = true;
${hasIntros && `${introing} = false;`}
Expand All @@ -275,7 +283,7 @@ export default class Block {
properties.addBlock(`u: @noop,`);
} else {
properties.addBlock(deindent`
u: function unmount() {
${dev ? 'u: function unmount' : 'u'}() {
${this.builders.unmount}
},
`);
Expand All @@ -285,7 +293,7 @@ export default class Block {
properties.addBlock(`d: @noop`);
} else {
properties.addBlock(deindent`
d: function destroy() {
${dev ? 'd: function destroy' : 'd'}() {
${this.builders.destroy}
}
`);
Expand Down
12 changes: 4 additions & 8 deletions test/js/samples/action/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,24 @@ function create_main_fragment(component, ctx) {
var a, link_action;

return {
c: function create() {
c() {
a = createElement("a");
a.textContent = "Test";
this.h();
},

h: function hydrate() {
a.href = "#";
link_action = link.call(component, a) || {};
},

m: function mount(target, anchor) {
m(target, anchor) {
insertNode(a, target, anchor);
},

p: noop,

u: function unmount() {
u() {
detachNode(a);
},

d: function destroy$$1() {
d() {
if (typeof link_action.destroy === 'function') link_action.destroy.call(component);
}
};
Expand Down
12 changes: 4 additions & 8 deletions test/js/samples/action/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,24 @@ function create_main_fragment(component, ctx) {
var a, link_action;

return {
c: function create() {
c() {
a = createElement("a");
a.textContent = "Test";
this.h();
},

h: function hydrate() {
a.href = "#";
link_action = link.call(component, a) || {};
},

m: function mount(target, anchor) {
m(target, anchor) {
insertNode(a, target, anchor);
},

p: noop,

u: function unmount() {
u() {
detachNode(a);
},

d: function destroy() {
d() {
if (typeof link_action.destroy === 'function') link_action.destroy.call(component);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,24 @@ function create_main_fragment(component, ctx) {
var p, text;

return {
c: function create() {
c() {
p = createElement("p");
text = createText(ctx.foo);
this.h();
},

h: function hydrate() {
p.className = "svelte-1a7i8ec";
},

m: function mount(target, anchor) {
m(target, anchor) {
insertNode(p, target, anchor);
appendNode(text, p);
},

p: function update(changed, ctx) {
p(changed, ctx) {
if (changed.foo) {
text.data = ctx.foo;
}
},

u: function unmount() {
u() {
detachNode(p);
},

Expand Down
12 changes: 4 additions & 8 deletions test/js/samples/collapses-text-around-comments/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ function create_main_fragment(component, ctx) {
var p, text;

return {
c: function create() {
c() {
p = createElement("p");
text = createText(ctx.foo);
this.h();
},

h: function hydrate() {
p.className = "svelte-1a7i8ec";
},

m: function mount(target, anchor) {
m(target, anchor) {
insertNode(p, target, anchor);
appendNode(text, p);
},

p: function update(changed, ctx) {
p(changed, ctx) {
if (changed.foo) {
text.data = ctx.foo;
}
},

u: function unmount() {
u() {
detachNode(p);
},

Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/component-static-immutable/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ function create_main_fragment(component, ctx) {
});

return {
c: function create() {
c() {
nested._fragment.c();
},

m: function mount(target, anchor) {
m(target, anchor) {
nested._mount(target, anchor);
},

p: noop,

u: function unmount() {
u() {
nested._unmount();
},

d: function destroy$$1() {
d() {
nested.destroy(false);
}
};
Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/component-static-immutable/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ function create_main_fragment(component, ctx) {
});

return {
c: function create() {
c() {
nested._fragment.c();
},

m: function mount(target, anchor) {
m(target, anchor) {
nested._mount(target, anchor);
},

p: noop,

u: function unmount() {
u() {
nested._unmount();
},

d: function destroy() {
d() {
nested.destroy(false);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ function create_main_fragment(component, ctx) {
});

return {
c: function create() {
c() {
nested._fragment.c();
},

m: function mount(target, anchor) {
m(target, anchor) {
nested._mount(target, anchor);
},

p: noop,

u: function unmount() {
u() {
nested._unmount();
},

d: function destroy$$1() {
d() {
nested.destroy(false);
}
};
Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/component-static-immutable2/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ function create_main_fragment(component, ctx) {
});

return {
c: function create() {
c() {
nested._fragment.c();
},

m: function mount(target, anchor) {
m(target, anchor) {
nested._mount(target, anchor);
},

p: noop,

u: function unmount() {
u() {
nested._unmount();
},

d: function destroy() {
d() {
nested.destroy(false);
}
};
Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/component-static/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,21 @@ function create_main_fragment(component, ctx) {
});

return {
c: function create() {
c() {
nested._fragment.c();
},

m: function mount(target, anchor) {
m(target, anchor) {
nested._mount(target, anchor);
},

p: noop,

u: function unmount() {
u() {
nested._unmount();
},

d: function destroy$$1() {
d() {
nested.destroy(false);
}
};
Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/component-static/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ function create_main_fragment(component, ctx) {
});

return {
c: function create() {
c() {
nested._fragment.c();
},

m: function mount(target, anchor) {
m(target, anchor) {
nested._mount(target, anchor);
},

p: noop,

u: function unmount() {
u() {
nested._unmount();
},

d: function destroy() {
d() {
nested.destroy(false);
}
};
Expand Down
Loading

0 comments on commit ac4ff53

Please sign in to comment.