From 75ae49312f5532360c29136462f808d5188a0482 Mon Sep 17 00:00:00 2001 From: Eddy Date: Wed, 29 Apr 2020 21:14:55 +0200 Subject: [PATCH 01/10] docs: fix link to transition section (#4748) --- 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 85661bd3b9..e393dfc1ab 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -521,7 +521,7 @@ $: $size = big ? 100 : 10; ### `svelte/transition` -The `svelte/transition` module exports six functions: `fade`, `fly`, `slide`, `scale`, `draw` and `crossfade`. They are for use with svelte [`transitions`](docs#Transitions). +The `svelte/transition` module exports six functions: `fade`, `fly`, `slide`, `scale`, `draw` and `crossfade`. They are for use with Svelte [`transitions`](docs#transition_fn). #### `fade` From 35a910eea21d73f871a10335f1059c9dcb154eb5 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Apr 2020 15:17:29 -0400 Subject: [PATCH 02/10] docs: fix link to animate section --- 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 e393dfc1ab..fc21abb20d 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -758,7 +758,7 @@ The `speed` parameter is a means of setting the duration of the transition relat ### `svelte/animate` -The `svelte/animate` module exports one function for use with svelte [animations](docs#Animations). +The `svelte/animate` module exports one function for use with Svelte [animations](docs#animate_fn). #### `flip` From 0e61e51358039527bc153bf577ddc46feb082ce8 Mon Sep 17 00:00:00 2001 From: Antony Jones Date: Wed, 29 Apr 2020 20:38:58 +0100 Subject: [PATCH 03/10] docs: add v2 site link (#4745) --- site/content/docs/00-introduction.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site/content/docs/00-introduction.md b/site/content/docs/00-introduction.md index 15fdffbde2..2ca82a8698 100644 --- a/site/content/docs/00-introduction.md +++ b/site/content/docs/00-introduction.md @@ -6,4 +6,6 @@ This page contains detailed API reference documentation. It's intended to be a r If that's not you (yet), you may prefer to visit the [interactive tutorial](tutorial) or the [examples](examples) before consulting this reference. -Don't be shy about asking for help in the [Discord chatroom](chat). \ No newline at end of file +Don't be shy about asking for help in the [Discord chatroom](chat). + +Using an older version of Svelte? Have a look at the [v2 docs](https://v2.svelte.dev). \ No newline at end of file From 4ac2ea3cef95c95c46141bbb615b38f585d941df Mon Sep 17 00:00:00 2001 From: Olubisi Idris Ayinde Date: Wed, 29 Apr 2020 20:39:55 +0100 Subject: [PATCH 04/10] contributing.md: add missing punctuation (#4746) --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7df9770db..c3eff81da3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -93,7 +93,7 @@ Test samples are kept in `/test/xxx/samples` folder. #### Running tests -1. To run test, run `npm run test` +1. To run test, run `npm run test`. 1. To run test for a specific feature, you can use the `-g` (aka `--grep`) option. For example, to only run test involving transitions, run `npm run test -- -g transition`. ##### Running solo test @@ -130,7 +130,7 @@ The core Svelte team will be monitoring for pull requests. Do help us by making ### Code conventions -- `snake_case` for internal variable names and methods +- `snake_case` for internal variable names and methods. - `camelCase` for public variable names and methods. ## License From 07242f994c00970724525633ed318f8acbbd4d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lins?= Date: Wed, 29 Apr 2020 16:42:11 -0300 Subject: [PATCH 05/10] a11y: do not warn about / (#4739) --- src/compiler/compile/nodes/Element.ts | 31 ++++++++++++------- .../samples/a11y-anchor-is-valid/input.svelte | 6 +++- .../a11y-anchor-is-valid/warnings.json | 30 ++++++++++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index f64da919c6..f7f3cc55bc 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -423,22 +423,29 @@ export default class Element extends Node { // handle special cases if (this.name === 'a') { - const attribute = attribute_map.get('href') || attribute_map.get('xlink:href'); - - if (attribute) { - const value = attribute.get_static_value(); - - if (value === '' || value === '#' || /^\W*javascript:/i.test(value)) { - component.warn(attribute, { + const href_attribute = attribute_map.get('href') || attribute_map.get('xlink:href'); + const id_attribute = attribute_map.get('id'); + const name_attribute = attribute_map.get('name'); + + if (href_attribute) { + const href_value = href_attribute.get_static_value(); + + if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) { + component.warn(href_attribute, { code: `a11y-invalid-attribute`, - message: `A11y: '${value}' is not a valid ${attribute.name} attribute` + message: `A11y: '${href_value}' is not a valid ${href_attribute.name} attribute` }); } } else { - component.warn(this, { - code: `a11y-missing-attribute`, - message: `A11y: element should have an href attribute` - }); + const id_attribute_valid = id_attribute && id_attribute.get_static_value() !== ''; + const name_attribute_valid = name_attribute && name_attribute.get_static_value() !== ''; + + if (!id_attribute_valid && !name_attribute_valid) { + component.warn(this, { + code: `a11y-missing-attribute`, + message: `A11y: element should have an href attribute` + }); + } } } diff --git a/test/validator/samples/a11y-anchor-is-valid/input.svelte b/test/validator/samples/a11y-anchor-is-valid/input.svelte index 6d0f77a308..8933bd7560 100644 --- a/test/validator/samples/a11y-anchor-is-valid/input.svelte +++ b/test/validator/samples/a11y-anchor-is-valid/input.svelte @@ -1,4 +1,8 @@ not actually a link invalid invalid -invalid \ No newline at end of file +invalid +invalid +invalid +valid +valid \ No newline at end of file diff --git a/test/validator/samples/a11y-anchor-is-valid/warnings.json b/test/validator/samples/a11y-anchor-is-valid/warnings.json index 9438a74f5b..f04c6f1593 100644 --- a/test/validator/samples/a11y-anchor-is-valid/warnings.json +++ b/test/validator/samples/a11y-anchor-is-valid/warnings.json @@ -58,5 +58,35 @@ "character": 102 }, "pos": 77 + }, + { + "code": "a11y-missing-attribute", + "message": "A11y: element should have an href attribute", + "start": { + "line": 5, + "column": 0, + "character": 115 + }, + "end": { + "line": 5, + "column": 22, + "character": 137 + }, + "pos": 115 + }, + { + "code": "a11y-missing-attribute", + "message": "A11y: element should have an href attribute", + "start": { + "line": 6, + "column": 0, + "character": 138 + }, + "end": { + "line": 6, + "column": 20, + "character": 158 + }, + "pos": 138 } ] From 5604954f1514e92ea2b84907562d3c6193810224 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Apr 2020 15:43:37 -0400 Subject: [PATCH 06/10] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459cf656c7..25f4e12f20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix misaligned line numbers in source maps ([#3906](https://github.com/sveltejs/svelte/issues/3906)) * Fix reactivity with imported values that are then mutated ([#4555](https://github.com/sveltejs/svelte/issues/4555)) +* Do not display a11y warning about missing `href` for `` with `name` or `id` ([#4697](https://github.com/sveltejs/svelte/issues/4697)) * Display a11y warning for `href="javascript:..."` ([#4733](https://github.com/sveltejs/svelte/pull/4733)) ## 3.21.0 From edeeb05a6cd2130755cd47a7aa309c95f1124ce4 Mon Sep 17 00:00:00 2001 From: MichalBednarczyk <48881661+majkelbed@users.noreply.github.com> Date: Wed, 29 Apr 2020 21:48:45 +0200 Subject: [PATCH 07/10] docs: {#each} with key but without index (#4721) --- site/content/docs/02-template-syntax.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index 3ee5b1dad1..165dd86106 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -206,6 +206,9 @@ Additional conditions can be added with `{:else if expression}`, optionally endi {#each expression as name, index}...{/each} ``` ```sv +{#each expression as name (key)}...{/each} +``` +```sv {#each expression as name, index (key)}...{/each} ``` ```sv @@ -242,6 +245,11 @@ An each block can also specify an *index*, equivalent to the second argument in If a *key* expression is provided — which must uniquely identify each list item — Svelte will use it to diff the list when data changes, rather than adding or removing items at the end. The key can be any object, but strings and numbers are recommended since they allow identity to persist when the objects themselves change. ```html +{#each items as item (item.id)} +
  • {item.name} x {item.qty}
  • +{/each} + + {#each items as item, i (item.id)}
  • {i + 1}: {item.name} x {item.qty}
  • {/each} From 3d811311b713a0ffd92d62012d7582f9d4cb6da0 Mon Sep 17 00:00:00 2001 From: Billy Levin Date: Wed, 29 Apr 2020 22:14:01 +0100 Subject: [PATCH 08/10] disable loop protection inside generators (#4716) --- src/compiler/compile/Component.ts | 16 +++++++++++++--- .../loop-protect-generator-opt-out/_config.js | 6 ++++++ .../loop-protect-generator-opt-out/main.svelte | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/loop-protect-generator-opt-out/_config.js create mode 100644 test/runtime/samples/loop-protect-generator-opt-out/main.svelte diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index c83f8153a0..a5a31c8070 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -205,7 +205,7 @@ export default class Component { const variable = this.var_lookup.get(subscribable_name); if (variable) { - variable.referenced = true; + variable.referenced = true; variable.subscribable = true; } } else { @@ -714,8 +714,14 @@ export default class Component { }; let scope_updated = false; + let generator_count = 0; + walk(content, { enter(node: Node, parent, prop, index) { + if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') && node.generator === true) { + generator_count++; + } + if (map.has(node)) { scope = map.get(node); } @@ -742,8 +748,12 @@ export default class Component { }, leave(node: Node) { + if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') && node.generator === true) { + generator_count--; + } + // do it on leave, to prevent infinite loop - if (component.compile_options.dev && component.compile_options.loopGuardTimeout > 0) { + if (component.compile_options.dev && component.compile_options.loopGuardTimeout > 0 && generator_count <= 0) { const to_replace_for_loop_protect = component.loop_protect(node, scope, component.compile_options.loopGuardTimeout); if (to_replace_for_loop_protect) { this.replace(to_replace_for_loop_protect); @@ -1259,7 +1269,7 @@ export default class Component { const add_declaration = declaration => { if (this.reactive_declarations.includes(declaration)) return; - + declaration.dependencies.forEach(name => { if (declaration.assignees.has(name)) return; const earlier_declarations = lookup.get(name); diff --git a/test/runtime/samples/loop-protect-generator-opt-out/_config.js b/test/runtime/samples/loop-protect-generator-opt-out/_config.js new file mode 100644 index 0000000000..9b6a24b513 --- /dev/null +++ b/test/runtime/samples/loop-protect-generator-opt-out/_config.js @@ -0,0 +1,6 @@ +export default { + compileOptions: { + dev: true, + loopGuardTimeout: 1, + }, +}; diff --git a/test/runtime/samples/loop-protect-generator-opt-out/main.svelte b/test/runtime/samples/loop-protect-generator-opt-out/main.svelte new file mode 100644 index 0000000000..a7aa790681 --- /dev/null +++ b/test/runtime/samples/loop-protect-generator-opt-out/main.svelte @@ -0,0 +1,14 @@ + \ No newline at end of file From fe0a008a6a59f5377582ca85d1b97ea7e93087e2 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Apr 2020 17:15:35 -0400 Subject: [PATCH 09/10] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25f4e12f20..78487a8d1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Fix misaligned line numbers in source maps ([#3906](https://github.com/sveltejs/svelte/issues/3906)) * Fix reactivity with imported values that are then mutated ([#4555](https://github.com/sveltejs/svelte/issues/4555)) * Do not display a11y warning about missing `href` for `
    ` with `name` or `id` ([#4697](https://github.com/sveltejs/svelte/issues/4697)) +* Disable infinite loop guard inside generators ([#4698](https://github.com/sveltejs/svelte/issues/4698)) * Display a11y warning for `href="javascript:..."` ([#4733](https://github.com/sveltejs/svelte/pull/4733)) ## 3.21.0 From b3364424d7d454640045f352314eec63b73bf040 Mon Sep 17 00:00:00 2001 From: JocelynLi Date: Thu, 30 Apr 2020 06:19:21 +0900 Subject: [PATCH 10/10] docs: tweak tutorial/default-values wording (#4600) --- site/content/tutorial/03-props/02-default-values/text.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/tutorial/03-props/02-default-values/text.md b/site/content/tutorial/03-props/02-default-values/text.md index 1532407380..17b486d0ad 100644 --- a/site/content/tutorial/03-props/02-default-values/text.md +++ b/site/content/tutorial/03-props/02-default-values/text.md @@ -2,7 +2,7 @@ title: Default values --- -We can easily specify default values for props: +We can easily specify default values for props in `Nested.svelte`: ```html