From d27dbae51c85d09a4f60fce6dec42839ac3a423a Mon Sep 17 00:00:00 2001 From: pk Date: Mon, 29 Oct 2018 12:50:48 +0100 Subject: [PATCH 01/11] move resize handler from _beforecreate to _after.. (fixes #1743) --- src/compile/render-dom/wrappers/Element/index.ts | 2 +- test/js/samples/bind-width-height/expected.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index 47c1bc57f3..290c1b0d6e 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -529,7 +529,7 @@ export default class ElementWrapper extends Wrapper { renderer.hasComplexBindings = true; block.builders.hydrate.addLine( - `#component.root._beforecreate.push(${handler});` + `#component.root._aftercreate.push(${handler});` ); } }); diff --git a/test/js/samples/bind-width-height/expected.js b/test/js/samples/bind-width-height/expected.js index bb2bf2554a..a401dbce11 100644 --- a/test/js/samples/bind-width-height/expected.js +++ b/test/js/samples/bind-width-height/expected.js @@ -12,7 +12,7 @@ function create_main_fragment(component, ctx) { c() { div = createElement("div"); div.textContent = "some content"; - component.root._beforecreate.push(div_resize_handler); + component.root._aftercreate.push(div_resize_handler); }, m(target, anchor) { From fd9dc300887ca9565d3b6dda5da73168f895e598 Mon Sep 17 00:00:00 2001 From: pk Date: Sun, 4 Nov 2018 20:25:57 +0100 Subject: [PATCH 02/11] Failing test for #1743 global.getComputedStyle and global.navigator are needed for addResizeListener in shared/dom --- test/helpers.js | 2 ++ .../_config.js | 8 ++++++++ .../main.html | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/_config.js create mode 100644 test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/main.html diff --git a/test/helpers.js b/test/helpers.js index 7a04ff0262..7b1f08bb45 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -48,6 +48,8 @@ export function tryToReadFile(file) { export const virtualConsole = new jsdom.VirtualConsole(); const { window } = new jsdom.JSDOM('
', {virtualConsole}); global.document = window.document; +global.getComputedStyle = window.getComputedStyle; +global.navigator = {userAgent: 'fake'}; export function env() { window._svelteTransitionManager = null; diff --git a/test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/_config.js b/test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/_config.js new file mode 100644 index 0000000000..ff2b87b712 --- /dev/null +++ b/test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/_config.js @@ -0,0 +1,8 @@ +export default { + 'skip-ssr': true, + + test(assert, component, target) { + assert.ok(component.onstateRanBeforeOncreate); + assert.ok(!component.onupdateRanBeforeOncreate); + } +}; diff --git a/test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/main.html b/test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/main.html new file mode 100644 index 0000000000..d930bbcbbb --- /dev/null +++ b/test/runtime/samples/onupdate-after-concreate-using-bind-offsetWidth/main.html @@ -0,0 +1,17 @@ +
+ From bf319915d4f78dc5a9f526bf37a0ee8875260bcb Mon Sep 17 00:00:00 2001 From: Cameron Stitt Date: Thu, 8 Nov 2018 18:58:57 +1000 Subject: [PATCH 03/11] Update cli spec to include --customElement option --- src/cli/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli/index.ts b/src/cli/index.ts index 82d19c18f0..d3a64e7d5d 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -17,6 +17,7 @@ prog .option('--no-css', `Don't include CSS (useful with SSR)`) .option('--immutable', 'Support immutable data structures') .option('--shared', 'Don\'t include shared helpers') + .option('--customElement', 'Generate a custom element') .example('compile App.html > App.js') .example('compile src -o dest') From a4bc7c5a2619c43b901511c1cf7dbbea5149cac5 Mon Sep 17 00:00:00 2001 From: Dominik Winkelbauer Date: Wed, 14 Nov 2018 11:21:12 +0100 Subject: [PATCH 04/11] Fixes setting custom element data to zero --- src/shared/dom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/dom.js b/src/shared/dom.js index 1411a7693e..ec69875ef5 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -101,7 +101,7 @@ export function setAttributes(node, attributes) { export function setCustomElementData(node, prop, value) { if (prop in node) { node[prop] = value; - } else if (value) { + } else if (value != null) { setAttribute(node, prop, value); } else { node.removeAttribute(prop); From 0e586e39e38da807f8abb4734c53aaaf864eaf47 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 20 Nov 2018 10:25:49 -0800 Subject: [PATCH 05/11] added test for async block ordering (#1440) --- .../samples/await-then-catch-order/_config.js | 27 +++++++++++++++++++ .../samples/await-then-catch-order/main.html | 11 ++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/runtime/samples/await-then-catch-order/_config.js create mode 100644 test/runtime/samples/await-then-catch-order/main.html diff --git a/test/runtime/samples/await-then-catch-order/_config.js b/test/runtime/samples/await-then-catch-order/_config.js new file mode 100644 index 0000000000..4a8f4df77c --- /dev/null +++ b/test/runtime/samples/await-then-catch-order/_config.js @@ -0,0 +1,27 @@ +let fulfil; + +let thePromise = new Promise(f => { + fulfil = f; +}); + +export default { + data: { + thePromise + }, + + html: ` +

loading...

true!

+ `, + + test(assert, component, target) { + fulfil(42); + + return thePromise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

the value is 42

true!

+ `); + }); + + } +}; diff --git a/test/runtime/samples/await-then-catch-order/main.html b/test/runtime/samples/await-then-catch-order/main.html new file mode 100644 index 0000000000..87b37bf27d --- /dev/null +++ b/test/runtime/samples/await-then-catch-order/main.html @@ -0,0 +1,11 @@ +{#await thePromise} +

loading...

+{:then theValue} +

the value is {theValue}

+{:catch theError} +

oh no! {theError.message}

+{/await} + +{#if true} +

true!

+{/if} From 05fa286d7b2f1fdc6b0e62ddf73c61182e790a4f Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 20 Nov 2018 12:54:55 -0800 Subject: [PATCH 06/11] fixes #1440 --- src/compile/render-dom/wrappers/AwaitBlock.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compile/render-dom/wrappers/AwaitBlock.ts b/src/compile/render-dom/wrappers/AwaitBlock.ts index bfd3143333..50320ee8b6 100644 --- a/src/compile/render-dom/wrappers/AwaitBlock.ts +++ b/src/compile/render-dom/wrappers/AwaitBlock.ts @@ -174,6 +174,9 @@ export default class AwaitBlockWrapper extends Wrapper { block.builders.mount.addBlock(deindent` ${info}.block.${hasTransitions ? 'i' : 'm'}(${initialMountNode}, ${info}.anchor = ${anchorNode}); ${info}.mount = () => ${updateMountNode}; + if (${info}.anchor == null) { + ${info}.anchor = ${anchor}; + } `); const conditions = []; From 68c2a34bda4151cf08e7c0586e5b224dee425bb3 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 20 Nov 2018 13:28:31 -0800 Subject: [PATCH 07/11] fix transition-js-await-block test --- test/runtime/samples/transition-js-await-block/_config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/runtime/samples/transition-js-await-block/_config.js b/test/runtime/samples/transition-js-await-block/_config.js index ff9888c88b..6c482afe45 100644 --- a/test/runtime/samples/transition-js-await-block/_config.js +++ b/test/runtime/samples/transition-js-await-block/_config.js @@ -26,10 +26,10 @@ export default { return promise.then(() => { raf.tick(80); let ps = document.querySelectorAll('p'); - assert.equal(ps[0].className, 'pending'); - assert.equal(ps[1].className, 'then'); - assert.equal(ps[0].foo, 0.2); - assert.equal(ps[1].foo, 0.3); + assert.equal(ps[1].className, 'pending'); + assert.equal(ps[0].className, 'then'); + assert.equal(ps[1].foo, 0.2); + assert.equal(ps[0].foo, 0.3); }); } }; From d236a4ad0b6f87c2e6e61563f800b01c8731700e Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 8 Dec 2018 21:04:36 -0600 Subject: [PATCH 08/11] fix: #1859 (multiple window bindings not supported) --- src/compile/render-dom/wrappers/Window.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compile/render-dom/wrappers/Window.ts b/src/compile/render-dom/wrappers/Window.ts index c26cf5ecb1..a7f3b9c79f 100644 --- a/src/compile/render-dom/wrappers/Window.ts +++ b/src/compile/render-dom/wrappers/Window.ts @@ -148,7 +148,7 @@ export default class WindowWrapper extends Wrapper { ${component.options.dev && `component._updatingReadonlyProperty = true;`} #component.set({ - ${props.map(prop => `${prop.name}: this.${prop.value}`)} + ${props.map(prop => `${prop.name}: this.${prop.value},`)} }); ${component.options.dev && `component._updatingReadonlyProperty = false;`} From e5ae97b9c9fbde4879352ddb50ba7f4cd16238d4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 15 Dec 2018 17:45:17 -0500 Subject: [PATCH 09/11] use helper for combining window binding props --- src/compile/render-dom/wrappers/Window.ts | 5 ++--- test/js/samples/action/expected.js | 2 +- test/js/samples/window-binding-scroll/expected.js | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/compile/render-dom/wrappers/Window.ts b/src/compile/render-dom/wrappers/Window.ts index a7f3b9c79f..05ab485256 100644 --- a/src/compile/render-dom/wrappers/Window.ts +++ b/src/compile/render-dom/wrappers/Window.ts @@ -3,6 +3,7 @@ import Block from '../Block'; import Node from '../../nodes/shared/Node'; import Wrapper from './shared/Wrapper'; import deindent from '../../../utils/deindent'; +import stringifyProps from '../../../utils/stringifyProps'; const associatedEvents = { innerWidth: 'resize', @@ -147,9 +148,7 @@ export default class WindowWrapper extends Wrapper { `} ${component.options.dev && `component._updatingReadonlyProperty = true;`} - #component.set({ - ${props.map(prop => `${prop.name}: this.${prop.value},`)} - }); + #component.set(${stringifyProps(props.map(prop => `${prop.name}: this.${prop.value}`))}); ${component.options.dev && `component._updatingReadonlyProperty = false;`} ${event === 'scroll' && `${lock} = false;`} diff --git a/test/js/samples/action/expected.js b/test/js/samples/action/expected.js index 83a668acd5..eac96a80c5 100644 --- a/test/js/samples/action/expected.js +++ b/test/js/samples/action/expected.js @@ -2,7 +2,7 @@ import { assign, createElement, detachNode, init, insert, noop, proto } from "svelte/shared.js"; function link(node) { - + function onClick(event) { event.preventDefault(); history.pushState(null, null, event.target.href); diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index 6fc66443b9..671550a27d 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -8,9 +8,7 @@ function create_main_fragment(component, ctx) { if (window_updating) return; window_updating = true; - component.set({ - y: this.pageYOffset - }); + component.set({ y: this.pageYOffset }); window_updating = false; } window.addEventListener("scroll", onwindowscroll); From d55e85dcdf58b3612d7298e18b60363d203f06b7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 15 Dec 2018 18:07:46 -0500 Subject: [PATCH 10/11] remove redundant if statement --- src/compile/render-dom/wrappers/AwaitBlock.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/compile/render-dom/wrappers/AwaitBlock.ts b/src/compile/render-dom/wrappers/AwaitBlock.ts index 50320ee8b6..137e34b23e 100644 --- a/src/compile/render-dom/wrappers/AwaitBlock.ts +++ b/src/compile/render-dom/wrappers/AwaitBlock.ts @@ -174,9 +174,7 @@ export default class AwaitBlockWrapper extends Wrapper { block.builders.mount.addBlock(deindent` ${info}.block.${hasTransitions ? 'i' : 'm'}(${initialMountNode}, ${info}.anchor = ${anchorNode}); ${info}.mount = () => ${updateMountNode}; - if (${info}.anchor == null) { - ${info}.anchor = ${anchor}; - } + ${info}.anchor = ${anchor}; `); const conditions = []; From 61302412123fc37a07d82ec2def28f6102159ec8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 15 Dec 2018 18:11:30 -0500 Subject: [PATCH 11/11] rely in setAttribute behaviour inside setCustomElementData --- src/shared/dom.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/shared/dom.js b/src/shared/dom.js index 662824f925..d5165ed803 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -101,10 +101,8 @@ export function setAttributes(node, attributes) { export function setCustomElementData(node, prop, value) { if (prop in node) { node[prop] = value; - } else if (value != null) { - setAttribute(node, prop, value); } else { - node.removeAttribute(prop); + setAttribute(node, prop, value); } }