From cdc0270ef1c74c30a5610d8765fc66194ec8ce65 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Tue, 17 Mar 2020 00:10:20 +0800 Subject: [PATCH 01/19] fix deconflicting variable name for slot fallback (#4564) --- src/compiler/compile/render_dom/wrappers/Slot.ts | 2 +- .../samples/component-slot-fallback-3/Inner.svelte | 6 ++++++ .../runtime/samples/component-slot-fallback-3/_config.js | 6 ++++++ .../samples/component-slot-fallback-3/main.svelte | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/component-slot-fallback-3/Inner.svelte create mode 100644 test/runtime/samples/component-slot-fallback-3/_config.js create mode 100644 test/runtime/samples/component-slot-fallback-3/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/Slot.ts b/src/compiler/compile/render_dom/wrappers/Slot.ts index 37b10c2ea3..f287198132 100644 --- a/src/compiler/compile/render_dom/wrappers/Slot.ts +++ b/src/compiler/compile/render_dom/wrappers/Slot.ts @@ -38,6 +38,7 @@ export default class SlotWrapper extends Wrapper { name: this.renderer.component.get_unique_name(`fallback_block`), type: 'fallback' }); + renderer.blocks.push(this.fallback); } this.fragment = new FragmentWrapper( @@ -115,7 +116,6 @@ export default class SlotWrapper extends Wrapper { if (this.fallback) { this.fragment.render(this.fallback, null, x`#nodes` as Identifier); - renderer.blocks.push(this.fallback); } const slot = block.get_unique_name(`${sanitize(slot_name)}_slot`); diff --git a/test/runtime/samples/component-slot-fallback-3/Inner.svelte b/test/runtime/samples/component-slot-fallback-3/Inner.svelte new file mode 100644 index 0000000000..db2af272d2 --- /dev/null +++ b/test/runtime/samples/component-slot-fallback-3/Inner.svelte @@ -0,0 +1,6 @@ + +
Hello
+
world
+
Bye
+
World
+
diff --git a/test/runtime/samples/component-slot-fallback-3/_config.js b/test/runtime/samples/component-slot-fallback-3/_config.js new file mode 100644 index 0000000000..b5591fb5e0 --- /dev/null +++ b/test/runtime/samples/component-slot-fallback-3/_config.js @@ -0,0 +1,6 @@ +export default { + html: ` +
Hello World
+
Hello
world
Bye
World
+ `, +}; diff --git a/test/runtime/samples/component-slot-fallback-3/main.svelte b/test/runtime/samples/component-slot-fallback-3/main.svelte new file mode 100644 index 0000000000..eda7ea60e4 --- /dev/null +++ b/test/runtime/samples/component-slot-fallback-3/main.svelte @@ -0,0 +1,9 @@ + + + +
Hello World
+
+ + From e50ad1dcb6d7e9e5ff6d27f566f459369c51beba Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 16 Mar 2020 12:11:53 -0400 Subject: [PATCH 02/19] -> v3.20.1 --- CHANGELOG.md | 4 ++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ace7d8104..93a8262121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## 3.20.1 + +* Fix compiler regression with slots ([#4562](https://github.com/sveltejs/svelte/issues/4562)) + ## 3.20.0 * Allow destructuring in `{#await}` blocks ([#1851](https://github.com/sveltejs/svelte/issues/1851)) diff --git a/package-lock.json b/package-lock.json index 6dccee0d65..7c521bd93d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.20.0", + "version": "3.20.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4e52b15636..2053ebb76f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.20.0", + "version": "3.20.1", "description": "Cybernetically enhanced web apps", "module": "index.mjs", "main": "index", From e247de351b51db6189ca91e63a66f894e4a6699c Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 20 Mar 2020 08:44:24 -0400 Subject: [PATCH 03/19] site: bump sapper --- site/package-lock.json | 6 +++--- site/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/site/package-lock.json b/site/package-lock.json index 5ce377c88c..7ac3211a7e 100644 --- a/site/package-lock.json +++ b/site/package-lock.json @@ -3483,9 +3483,9 @@ } }, "sapper": { - "version": "0.27.8", - "resolved": "https://registry.npmjs.org/sapper/-/sapper-0.27.8.tgz", - "integrity": "sha512-78K+56yu9nGOEU0B0XjBvNchRuPEv4aHbAKK4D874S4aoapMAkHCT0bHtPK12S3P7JPxvvT8GzHaq/8NetMmbg==", + "version": "0.27.11", + "resolved": "https://registry.npmjs.org/sapper/-/sapper-0.27.11.tgz", + "integrity": "sha512-5EaPZhlc8OnyN3UCI6dRSM1Gz5sxyzLZG/1z5nMvZhg9Ng+rSvEvJx/rW/tSHcnQPa8or7+YcbfvQHKS5oPHiw==", "dev": true, "requires": { "html-minifier": "^4.0.0", diff --git a/site/package.json b/site/package.json index a94d264217..5ff40e1153 100644 --- a/site/package.json +++ b/site/package.json @@ -53,7 +53,7 @@ "rollup-plugin-replace": "^2.2.0", "rollup-plugin-svelte": "^5.1.0", "rollup-plugin-terser": "^5.1.1", - "sapper": "^0.27.8", + "sapper": "^0.27.11", "shelljs": "^0.8.3", "svelte": "^3.12.0" }, From a0749f6adb7f27144e81f3b06a29418411abdc61 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 22 Mar 2020 20:08:32 +0800 Subject: [PATCH 04/19] fix creating debugging comment for HTML comment (#4567) --- CHANGELOG.md | 4 ++++ .../render_dom/wrappers/shared/create_debugging_comment.ts | 2 +- test/runtime/samples/component-slot-fallback-4/Inner.svelte | 3 +++ test/runtime/samples/component-slot-fallback-4/_config.js | 5 +++++ test/runtime/samples/component-slot-fallback-4/main.svelte | 5 +++++ 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/component-slot-fallback-4/Inner.svelte create mode 100644 test/runtime/samples/component-slot-fallback-4/_config.js create mode 100644 test/runtime/samples/component-slot-fallback-4/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a8262121..cbab1872dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## Unreleased + +* Fix attaching of JS debugging comments to HTML comments ([#4565](https://github.com/sveltejs/svelte/issues/4565)) + ## 3.20.1 * Fix compiler regression with slots ([#4562](https://github.com/sveltejs/svelte/issues/4562)) diff --git a/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts b/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts index 11f1feb841..1bdc473df0 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.ts @@ -24,7 +24,7 @@ export default function create_debugging_comment( while (source[d] !== '>') d += 1; d += 1; } - } else if (node.type === 'Text') { + } else if (node.type === 'Text' || node.type === 'Comment') { d = node.end; } else { // @ts-ignore diff --git a/test/runtime/samples/component-slot-fallback-4/Inner.svelte b/test/runtime/samples/component-slot-fallback-4/Inner.svelte new file mode 100644 index 0000000000..9eb3ef1401 --- /dev/null +++ b/test/runtime/samples/component-slot-fallback-4/Inner.svelte @@ -0,0 +1,3 @@ + + + foobar \ No newline at end of file diff --git a/test/runtime/samples/component-slot-fallback-4/_config.js b/test/runtime/samples/component-slot-fallback-4/_config.js new file mode 100644 index 0000000000..b7c2b63ed6 --- /dev/null +++ b/test/runtime/samples/component-slot-fallback-4/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` + foobar + `, +}; diff --git a/test/runtime/samples/component-slot-fallback-4/main.svelte b/test/runtime/samples/component-slot-fallback-4/main.svelte new file mode 100644 index 0000000000..206ce21def --- /dev/null +++ b/test/runtime/samples/component-slot-fallback-4/main.svelte @@ -0,0 +1,5 @@ + + + From cc1f2c6c9ec8ea3b2b4878c5a866cfafd7d33172 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Mon, 23 Mar 2020 00:17:14 +0800 Subject: [PATCH 05/19] remove unneeded fragment block (#4568) --- src/compiler/compile/render_dom/Block.ts | 4 ++-- src/compiler/compile/render_dom/Renderer.ts | 4 ++++ .../render_dom/wrappers/InlineComponent/index.ts | 1 + src/compiler/compile/render_dom/wrappers/Slot.ts | 13 +++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index c843594599..f5c4281710 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -419,8 +419,8 @@ export default class Block { return body; } - has_content() { - return this.first || + has_content(): boolean { + return !!this.first || this.event_listeners.length > 0 || this.chunks.intro.length > 0 || this.chunks.outro.length > 0 || diff --git a/src/compiler/compile/render_dom/Renderer.ts b/src/compiler/compile/render_dom/Renderer.ts index e933faf97a..ca93c51060 100644 --- a/src/compiler/compile/render_dom/Renderer.ts +++ b/src/compiler/compile/render_dom/Renderer.ts @@ -284,4 +284,8 @@ export default class Renderer { return node; } + + remove_block(block: Block | Node | Node[]) { + this.blocks.splice(this.blocks.indexOf(block), 1); + } } diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index 8c8bd70696..4b1e787cbe 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -155,6 +155,7 @@ export default class InlineComponentWrapper extends Wrapper { // removing empty slot for (const slot of this.slots.keys()) { if (!this.slots.get(slot).block.has_content()) { + this.renderer.remove_block(this.slots.get(slot).block); this.slots.delete(slot); } } diff --git a/src/compiler/compile/render_dom/wrappers/Slot.ts b/src/compiler/compile/render_dom/wrappers/Slot.ts index f287198132..1111a7cffe 100644 --- a/src/compiler/compile/render_dom/wrappers/Slot.ts +++ b/src/compiler/compile/render_dom/wrappers/Slot.ts @@ -114,18 +114,23 @@ export default class SlotWrapper extends Wrapper { get_slot_context_fn = 'null'; } + let has_fallback = !!this.fallback; if (this.fallback) { this.fragment.render(this.fallback, null, x`#nodes` as Identifier); + has_fallback = this.fallback.has_content(); + if (!has_fallback) { + renderer.remove_block(this.fallback); + } } const slot = block.get_unique_name(`${sanitize(slot_name)}_slot`); const slot_definition = block.get_unique_name(`${sanitize(slot_name)}_slot_template`); - const slot_or_fallback = this.fallback ? block.get_unique_name(`${sanitize(slot_name)}_slot_or_fallback`) : slot; + const slot_or_fallback = has_fallback ? block.get_unique_name(`${sanitize(slot_name)}_slot_or_fallback`) : slot; block.chunks.init.push(b` const ${slot_definition} = ${renderer.reference('$$slots')}.${slot_name}; const ${slot} = @create_slot(${slot_definition}, #ctx, ${renderer.reference('$$scope')}, ${get_slot_context_fn}); - ${this.fallback ? b`const ${slot_or_fallback} = ${slot} || ${this.fallback.name}(#ctx);` : null} + ${has_fallback ? b`const ${slot_or_fallback} = ${slot} || ${this.fallback.name}(#ctx);` : null} `); block.chunks.create.push( @@ -161,7 +166,7 @@ export default class SlotWrapper extends Wrapper { const dynamic_dependencies = Array.from(this.dependencies).filter(is_dependency_dynamic); - const fallback_dynamic_dependencies = this.fallback + const fallback_dynamic_dependencies = has_fallback ? Array.from(this.fallback.dependencies).filter(is_dependency_dynamic) : []; @@ -173,7 +178,7 @@ export default class SlotWrapper extends Wrapper { ); } `; - const fallback_update = this.fallback && fallback_dynamic_dependencies.length > 0 && b` + const fallback_update = has_fallback && fallback_dynamic_dependencies.length > 0 && b` if (${slot_or_fallback} && ${slot_or_fallback}.p && ${renderer.dirty(fallback_dynamic_dependencies)}) { ${slot_or_fallback}.p(#ctx, #dirty); } From aa3dcc06d6b0fcb079ccd993fa6e3455242a2a96 Mon Sep 17 00:00:00 2001 From: Jongkeun Hong Date: Tue, 24 Mar 2020 22:29:19 +0900 Subject: [PATCH 06/19] add .vscode to .gitignore (#4595) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7a14244929..f7fac04eba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea .DS_Store .nyc_output +.vscode node_modules *.map /src/compiler/compile/internal_exports.ts From 89f30dae3692fd8d013bd33f0342c7d58f195aea Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Mon, 6 Apr 2020 20:45:27 +1000 Subject: [PATCH 07/19] docs: Fix simple typo, specificy -> specify (#4637) --- site/content/docs/03-run-time.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 0bbae24185..85661bd3b9 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -804,7 +804,7 @@ You can see a full example on the [animations tutorial](tutorial/animate) ### `svelte/easing` -Easing functions specificy the rate of change over time and are useful when working with Svelte's built-in transitions and animations as well as the tweened and spring utilities. `svelte/easing` contains 31 named exports, a `linear` ease and 3 variants of 10 different easing functions: `in`, `out` and `inOut`. +Easing functions specify the rate of change over time and are useful when working with Svelte's built-in transitions and animations as well as the tweened and spring utilities. `svelte/easing` contains 31 named exports, a `linear` ease and 3 variants of 10 different easing functions: `in`, `out` and `inOut`. You can explore the various eases using the [ease visualiser](examples#easing) in the [examples section](examples). From 085897c799dba914e553fcfac83aa3416ab23bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=A4=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 6 Apr 2020 14:01:02 +0300 Subject: [PATCH 08/19] feat(internal): Support globalThis in modern environments (#4628) --- src/runtime/internal/globals.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/internal/globals.ts b/src/runtime/internal/globals.ts index 664093d2e4..b97f81ab9f 100644 --- a/src/runtime/internal/globals.ts +++ b/src/runtime/internal/globals.ts @@ -1,3 +1,7 @@ declare const global: any; -export const globals = (typeof window !== 'undefined' ? window : global) as unknown as typeof globalThis; +export const globals = (typeof window !== 'undefined' + ? window + : typeof globalThis !== 'undefined' + ? globalThis + : global) as unknown as typeof globalThis; From d7497deaecc043f799ce81bb86298010605d2b99 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 6 Apr 2020 07:04:40 -0400 Subject: [PATCH 09/19] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbab1872dc..80db122cb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* Try using `globalThis` rather than `globals` for the benefit of non-Node servers and web workers ([#3561](https://github.com/sveltejs/svelte/issues/3561), [#4545](https://github.com/sveltejs/svelte/issues/4545)) * Fix attaching of JS debugging comments to HTML comments ([#4565](https://github.com/sveltejs/svelte/issues/4565)) ## 3.20.1 From df3ae85b42b6fa2d6a07cdb1073c9ebd8c9f8a71 Mon Sep 17 00:00:00 2001 From: Robin Cussol Date: Tue, 7 Apr 2020 15:30:33 +0200 Subject: [PATCH 10/19] fix(examples): use correct URL for Ask HN posts (#4640) --- .../examples/21-miscellaneous/01-hacker-news/Item.svelte | 6 ++++-- .../examples/21-miscellaneous/01-hacker-news/Summary.svelte | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/site/content/examples/21-miscellaneous/01-hacker-news/Item.svelte b/site/content/examples/21-miscellaneous/01-hacker-news/Item.svelte index e9cd617e96..802ab437f7 100644 --- a/site/content/examples/21-miscellaneous/01-hacker-news/Item.svelte +++ b/site/content/examples/21-miscellaneous/01-hacker-news/Item.svelte @@ -3,6 +3,8 @@ export let item; export let returnTo; + + $: url = !item.domain ? `https://news.ycombinator.com/${item.url}` : item.url;