svelte 3.44.3 → 3.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # Svelte changelog
2
2
 
3
+ ## 3.45.0
4
+
5
+ * Fix non-boolean attribute rendering in SSR to render truthy values as-is ([#6121](https://github.com/sveltejs/svelte/issues/6121))
6
+ * Fix binding to a member expression also invalidating the member property ([#6921](https://github.com/sveltejs/svelte/issues/6921))
7
+ * Fix default values in `{#each}`/etc. destructurings not being considered references for the purposes of compiler warnings ([#6964](https://github.com/sveltejs/svelte/issues/6964))
8
+ * Fix `{:else if}` value incorrectly being cached ([#7043](https://github.com/sveltejs/svelte/pull/7043))
9
+ * Add `a11y-no-redundant-roles` warning ([#7067](https://github.com/sveltejs/svelte/pull/7067))
10
+ * Fix code generation error with arrow functions whose bodies are object destructuring assignments ([#7087](https://github.com/sveltejs/svelte/issues/7087))
11
+
3
12
  ## 3.44.3
4
13
 
5
14
  * Fix `bind:this` binding inside `onMount` for manually instantiated component ([#6760](https://github.com/sveltejs/svelte/issues/6760))
6
- * Prevent cursor jumps for other `type="text"`-like `<input>`s ([#6914](https://github.com/sveltejs/svelte/issues/6914))
15
+ * Prevent cursor jumps with one-way binding for other `type="text"`-like `<input>`s ([#6941](https://github.com/sveltejs/svelte/pull/6941))
7
16
  * Exclude `async` loops from `loopGuardTimeout` ([#6945](https://github.com/sveltejs/svelte/issues/6945))
8
17
 
9
18
  ## 3.44.2
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016-21 [these people](https://github.com/sveltejs/svelte/graphs/contributors)
1
+ Copyright (c) 2016-22 [these people](https://github.com/sveltejs/svelte/graphs/contributors)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/compiler.js CHANGED
@@ -6999,7 +6999,10 @@
6999
6999
 
7000
7000
  chunks.push(c(' => '));
7001
7001
 
7002
- if (node.body.type === 'ObjectExpression') {
7002
+ if (
7003
+ node.body.type === 'ObjectExpression' ||
7004
+ (node.body.type === 'AssignmentExpression' && node.body.left.type === 'ObjectPattern')
7005
+ ) {
7003
7006
  chunks.push(
7004
7007
  c('('),
7005
7008
  ...handle(node.body, state),
@@ -19223,7 +19226,7 @@
19223
19226
 
19224
19227
  // The `foreign` namespace covers all DOM implementations that aren't HTML5.
19225
19228
  // It opts out of HTML5-specific a11y checks and case-insensitive attribute names.
19226
- const foreign = 'https://svelte.dev/docs#svelte_options';
19229
+ const foreign = 'https://svelte.dev/docs#template-syntax-svelte-options';
19227
19230
  const html = 'http://www.w3.org/1999/xhtml';
19228
19231
  const mathml = 'http://www.w3.org/1998/Math/MathML';
19229
19232
  const svg = 'http://www.w3.org/2000/svg';
@@ -19855,6 +19858,28 @@
19855
19858
  });
19856
19859
  return dependencies;
19857
19860
  }
19861
+ get_update_dependencies() {
19862
+ const object = this.object;
19863
+ const dependencies = new Set();
19864
+ if (this.node.expression.template_scope.names.has(object)) {
19865
+ this.node.expression.template_scope.dependencies_for_name
19866
+ .get(object)
19867
+ .forEach((name) => dependencies.add(name));
19868
+ }
19869
+ else {
19870
+ dependencies.add(object);
19871
+ }
19872
+ const result = new Set(dependencies);
19873
+ dependencies.forEach((dependency) => {
19874
+ const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(dependency);
19875
+ if (indirect_dependencies) {
19876
+ indirect_dependencies.forEach(indirect_dependency => {
19877
+ result.add(indirect_dependency);
19878
+ });
19879
+ }
19880
+ });
19881
+ return result;
19882
+ }
19858
19883
  is_readonly_media_attribute() {
19859
19884
  return this.node.is_readonly_media_attribute();
19860
19885
  }
@@ -20146,7 +20171,7 @@
20146
20171
  block.renderer.add_to_context(fn.name);
20147
20172
  const callee = block.renderer.reference(fn.name);
20148
20173
  const { contextual_dependencies, mutation } = binding.handler;
20149
- const dependencies = binding.get_dependencies();
20174
+ const dependencies = binding.get_update_dependencies();
20150
20175
  const body = b `
20151
20176
  ${mutation}
20152
20177
  ${Array.from(dependencies)
@@ -21458,7 +21483,7 @@
21458
21483
  const contextual_dependencies = new Set();
21459
21484
  binding_group.bindings.forEach(binding => {
21460
21485
  // TODO this is a mess
21461
- add_to_set(dependencies, binding.get_dependencies());
21486
+ add_to_set(dependencies, binding.get_update_dependencies());
21462
21487
  add_to_set(contextual_dependencies, binding.handler.contextual_dependencies);
21463
21488
  binding.render(block, lock);
21464
21489
  });
@@ -22063,12 +22088,13 @@
22063
22088
  if (this.needs_update) {
22064
22089
  block.chunks.init.push(b `
22065
22090
  function ${select_block_type}(#ctx, #dirty) {
22066
- ${this.branches.map(({ dependencies, condition, snippet, block }) => condition
22091
+ ${this.branches.map(({ dependencies, condition, snippet }) => {
22092
+ return b `${snippet && dependencies.length > 0 ? b `if (${block.renderer.dirty(dependencies)}) ${condition} = null;` : null}`;
22093
+ })}
22094
+ ${this.branches.map(({ condition, snippet, block }) => condition
22067
22095
  ? b `
22068
- ${snippet && (dependencies.length > 0
22069
- ? b `if (${condition} == null || ${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
22070
- : b `if (${condition} == null) ${condition} = !!${snippet}`)}
22071
- if (${condition}) return ${block.name};`
22096
+ ${snippet && b `if (${condition} == null) ${condition} = !!${snippet}`}
22097
+ if (${condition}) return ${block.name};`
22072
22098
  : b `return ${block.name};`)}
22073
22099
  }
22074
22100
  `);
@@ -22166,11 +22192,12 @@
22166
22192
  ${this.needs_update
22167
22193
  ? b `
22168
22194
  function ${select_block_type}(#ctx, #dirty) {
22169
- ${this.branches.map(({ dependencies, condition, snippet }, i) => condition
22195
+ ${this.branches.map(({ dependencies, condition, snippet }) => {
22196
+ return b `${snippet && dependencies.length > 0 ? b `if (${block.renderer.dirty(dependencies)}) ${condition} = null;` : null}`;
22197
+ })}
22198
+ ${this.branches.map(({ condition, snippet }, i) => condition
22170
22199
  ? b `
22171
- ${snippet && (dependencies.length > 0
22172
- ? b `if (${condition} == null || ${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
22173
- : b `if (${condition} == null) ${condition} = !!${snippet}`)}
22200
+ ${snippet && b `if (${condition} == null) ${condition} = !!${snippet}`}
22174
22201
  if (${condition}) return ${i};`
22175
22202
  : b `return ${i};`)}
22176
22203
  ${!has_else && b `return -1;`}
@@ -22644,6 +22671,10 @@
22644
22671
  code: 'a11y-unknown-role',
22645
22672
  message: `A11y: Unknown role '${role}'` + (suggestion ? ` (did you mean '${suggestion}'?)` : '')
22646
22673
  }),
22674
+ a11y_no_redundant_roles: (role) => ({
22675
+ code: 'a11y-no-redundant-roles',
22676
+ message: `A11y: Redundant role '${role}'`
22677
+ }),
22647
22678
  a11y_accesskey: {
22648
22679
  code: 'a11y-accesskey',
22649
22680
  message: 'A11y: Avoid using accesskey'
@@ -25977,7 +26008,7 @@
25977
26008
  }
25978
26009
  }
25979
26010
 
25980
- function unpack_destructuring(contexts, node, modifier = node => node, default_modifier = node => node) {
26011
+ function unpack_destructuring({ contexts, node, modifier = (node) => node, default_modifier = (node) => node, scope, component }) {
25981
26012
  if (!node)
25982
26013
  return;
25983
26014
  if (node.type === 'Identifier') {
@@ -25997,14 +26028,36 @@
25997
26028
  else if (node.type === 'ArrayPattern') {
25998
26029
  node.elements.forEach((element, i) => {
25999
26030
  if (element && element.type === 'RestElement') {
26000
- unpack_destructuring(contexts, element, node => x `${modifier(node)}.slice(${i})`, default_modifier);
26031
+ unpack_destructuring({
26032
+ contexts,
26033
+ node: element,
26034
+ modifier: (node) => x `${modifier(node)}.slice(${i})`,
26035
+ default_modifier,
26036
+ scope,
26037
+ component
26038
+ });
26001
26039
  }
26002
26040
  else if (element && element.type === 'AssignmentPattern') {
26003
26041
  const n = contexts.length;
26004
- unpack_destructuring(contexts, element.left, node => x `${modifier(node)}[${i}]`, (node, to_ctx) => x `${node} !== undefined ? ${node} : ${update_reference(contexts, n, element.right, to_ctx)}`);
26042
+ mark_referenced(element.right, scope, component);
26043
+ unpack_destructuring({
26044
+ contexts,
26045
+ node: element.left,
26046
+ modifier: (node) => x `${modifier(node)}[${i}]`,
26047
+ default_modifier: (node, to_ctx) => x `${node} !== undefined ? ${node} : ${update_reference(contexts, n, element.right, to_ctx)}`,
26048
+ scope,
26049
+ component
26050
+ });
26005
26051
  }
26006
26052
  else {
26007
- unpack_destructuring(contexts, element, node => x `${modifier(node)}[${i}]`, default_modifier);
26053
+ unpack_destructuring({
26054
+ contexts,
26055
+ node: element,
26056
+ modifier: (node) => x `${modifier(node)}[${i}]`,
26057
+ default_modifier,
26058
+ scope,
26059
+ component
26060
+ });
26008
26061
  }
26009
26062
  });
26010
26063
  }
@@ -26012,7 +26065,14 @@
26012
26065
  const used_properties = [];
26013
26066
  node.properties.forEach((property) => {
26014
26067
  if (property.type === 'RestElement') {
26015
- unpack_destructuring(contexts, property.argument, node => x `@object_without_properties(${modifier(node)}, [${used_properties}])`, default_modifier);
26068
+ unpack_destructuring({
26069
+ contexts,
26070
+ node: property.argument,
26071
+ modifier: (node) => x `@object_without_properties(${modifier(node)}, [${used_properties}])`,
26072
+ default_modifier,
26073
+ scope,
26074
+ component
26075
+ });
26016
26076
  }
26017
26077
  else {
26018
26078
  const key = property.key;
@@ -26020,10 +26080,25 @@
26020
26080
  used_properties.push(x `"${key.name}"`);
26021
26081
  if (value.type === 'AssignmentPattern') {
26022
26082
  const n = contexts.length;
26023
- unpack_destructuring(contexts, value.left, node => x `${modifier(node)}.${key.name}`, (node, to_ctx) => x `${node} !== undefined ? ${node} : ${update_reference(contexts, n, value.right, to_ctx)}`);
26083
+ mark_referenced(value.right, scope, component);
26084
+ unpack_destructuring({
26085
+ contexts,
26086
+ node: value.left,
26087
+ modifier: (node) => x `${modifier(node)}.${key.name}`,
26088
+ default_modifier: (node, to_ctx) => x `${node} !== undefined ? ${node} : ${update_reference(contexts, n, value.right, to_ctx)}`,
26089
+ scope,
26090
+ component
26091
+ });
26024
26092
  }
26025
26093
  else {
26026
- unpack_destructuring(contexts, value, node => x `${modifier(node)}.${key.name}`, default_modifier);
26094
+ unpack_destructuring({
26095
+ contexts,
26096
+ node: value,
26097
+ modifier: (node) => x `${modifier(node)}.${key.name}`,
26098
+ default_modifier,
26099
+ scope,
26100
+ component
26101
+ });
26027
26102
  }
26028
26103
  }
26029
26104
  });
@@ -26054,6 +26129,18 @@
26054
26129
  });
26055
26130
  return expression;
26056
26131
  }
26132
+ function mark_referenced(node, scope, component) {
26133
+ walk(node, {
26134
+ enter(node, parent) {
26135
+ if (is_reference(node, parent)) {
26136
+ const { name } = flatten_reference(node);
26137
+ if (!scope.is_let(name) && !scope.names.has(name)) {
26138
+ component.add_reference(name);
26139
+ }
26140
+ }
26141
+ }
26142
+ });
26143
+ }
26057
26144
 
26058
26145
  class AwaitBlock$1 extends Node$1 {
26059
26146
  constructor(component, parent, scope, info) {
@@ -26063,11 +26150,11 @@
26063
26150
  this.catch_node = info.error;
26064
26151
  if (this.then_node) {
26065
26152
  this.then_contexts = [];
26066
- unpack_destructuring(this.then_contexts, info.value);
26153
+ unpack_destructuring({ contexts: this.then_contexts, node: info.value, scope, component });
26067
26154
  }
26068
26155
  if (this.catch_node) {
26069
26156
  this.catch_contexts = [];
26070
- unpack_destructuring(this.catch_contexts, info.error);
26157
+ unpack_destructuring({ contexts: this.catch_contexts, node: info.error, scope, component });
26071
26158
  }
26072
26159
  this.pending = new PendingBlock(component, this, scope, info.pending);
26073
26160
  this.then = new ThenBlock(component, this, scope, info.then);
@@ -26163,7 +26250,7 @@
26163
26250
  this.index = info.index;
26164
26251
  this.scope = scope.child();
26165
26252
  this.contexts = [];
26166
- unpack_destructuring(this.contexts, info.context);
26253
+ unpack_destructuring({ contexts: this.contexts, node: info.context, scope, component });
26167
26254
  this.contexts.forEach(context => {
26168
26255
  this.scope.add(context.key.name, this.expression.dependencies, this);
26169
26256
  });
@@ -26498,6 +26585,44 @@
26498
26585
  'select',
26499
26586
  'textarea'
26500
26587
  ]);
26588
+ const a11y_nested_implicit_semantics = new Map([
26589
+ ['header', 'banner'],
26590
+ ['footer', 'contentinfo']
26591
+ ]);
26592
+ const a11y_implicit_semantics = new Map([
26593
+ ['a', 'link'],
26594
+ ['aside', 'complementary'],
26595
+ ['body', 'document'],
26596
+ ['datalist', 'listbox'],
26597
+ ['dd', 'definition'],
26598
+ ['dfn', 'term'],
26599
+ ['details', 'group'],
26600
+ ['dt', 'term'],
26601
+ ['fieldset', 'group'],
26602
+ ['form', 'form'],
26603
+ ['h1', 'heading'],
26604
+ ['h2', 'heading'],
26605
+ ['h3', 'heading'],
26606
+ ['h4', 'heading'],
26607
+ ['h5', 'heading'],
26608
+ ['h6', 'heading'],
26609
+ ['hr', 'separator'],
26610
+ ['li', 'listitem'],
26611
+ ['menu', 'list'],
26612
+ ['nav', 'navigation'],
26613
+ ['ol', 'list'],
26614
+ ['optgroup', 'group'],
26615
+ ['output', 'status'],
26616
+ ['progress', 'progressbar'],
26617
+ ['section', 'region'],
26618
+ ['summary', 'button'],
26619
+ ['tbody', 'rowgroup'],
26620
+ ['textarea', 'textbox'],
26621
+ ['tfoot', 'rowgroup'],
26622
+ ['thead', 'rowgroup'],
26623
+ ['tr', 'row'],
26624
+ ['ul', 'list']
26625
+ ]);
26501
26626
  const invisible_elements = new Set(['meta', 'html', 'script', 'style']);
26502
26627
  const valid_modifiers = new Set([
26503
26628
  'preventDefault',
@@ -26521,6 +26646,21 @@
26521
26646
  ['htmlFor', 'for']
26522
26647
  ]);
26523
26648
  const attributes_to_compact_whitespace = ['class', 'style'];
26649
+ function is_parent(parent, elements) {
26650
+ let check = false;
26651
+ while (parent) {
26652
+ const parent_name = parent.name;
26653
+ if (elements.includes(parent_name)) {
26654
+ check = true;
26655
+ break;
26656
+ }
26657
+ if (parent.type === 'Element') {
26658
+ break;
26659
+ }
26660
+ parent = parent.parent;
26661
+ }
26662
+ return check;
26663
+ }
26524
26664
  function get_namespace(parent, element, explicit_namespace) {
26525
26665
  const parent_element = parent.find_nearest(/^Element/);
26526
26666
  if (!parent_element) {
@@ -26726,6 +26866,19 @@
26726
26866
  const match = fuzzymatch(value, aria_roles);
26727
26867
  component.warn(attribute, compiler_warnings.a11y_unknown_role(value, match));
26728
26868
  }
26869
+ // no-redundant-roles
26870
+ const has_redundant_role = value === a11y_implicit_semantics.get(this.name);
26871
+ if (this.name === value || has_redundant_role) {
26872
+ component.warn(attribute, compiler_warnings.a11y_no_redundant_roles(value));
26873
+ }
26874
+ // Footers and headers are special cases, and should not have redundant roles unless they are the children of sections or articles.
26875
+ const is_parent_section_or_article = is_parent(this.parent, ['section', 'article']);
26876
+ if (!is_parent_section_or_article) {
26877
+ const has_nested_redundant_role = value === a11y_nested_implicit_semantics.get(this.name);
26878
+ if (has_nested_redundant_role) {
26879
+ component.warn(attribute, compiler_warnings.a11y_no_redundant_roles(value));
26880
+ }
26881
+ }
26729
26882
  }
26730
26883
  // no-access-key
26731
26884
  if (name === 'accesskey') {
@@ -30155,7 +30308,7 @@
30155
30308
  if (result) {
30156
30309
  const { compile_options, name } = this;
30157
30310
  const { format = 'esm' } = compile_options;
30158
- const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.44.3'}`;
30311
+ const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.45.0'}`;
30159
30312
  const program = { type: 'Program', body: result.js };
30160
30313
  walk(program, {
30161
30314
  enter: (node, parent, key) => {
@@ -31646,7 +31799,7 @@
31646
31799
  return result.to_processed();
31647
31800
  }
31648
31801
 
31649
- const VERSION = '3.44.3';
31802
+ const VERSION = '3.45.0';
31650
31803
 
31651
31804
  exports.VERSION = VERSION;
31652
31805
  exports.compile = compile;