svelte 3.30.0 → 3.31.2

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +1 -1
  3. package/compiler.js +349 -146
  4. package/compiler.js.map +1 -1
  5. package/compiler.mjs +349 -146
  6. package/compiler.mjs.map +1 -1
  7. package/index.js +12 -0
  8. package/index.mjs +1 -1
  9. package/internal/index.js +48 -4
  10. package/internal/index.mjs +48 -5
  11. package/package.json +8 -8
  12. package/transition/index.js +10 -10
  13. package/transition/index.mjs +10 -10
  14. package/types/compiler/compile/nodes/Action.d.ts +4 -1
  15. package/types/compiler/compile/nodes/Animation.d.ts +4 -1
  16. package/types/compiler/compile/nodes/Attribute.d.ts +2 -1
  17. package/types/compiler/compile/nodes/AwaitBlock.d.ts +1 -1
  18. package/types/compiler/compile/nodes/Binding.d.ts +5 -1
  19. package/types/compiler/compile/nodes/Body.d.ts +4 -1
  20. package/types/compiler/compile/nodes/Class.d.ts +4 -1
  21. package/types/compiler/compile/nodes/Comment.d.ts +4 -1
  22. package/types/compiler/compile/nodes/DebugTag.d.ts +5 -1
  23. package/types/compiler/compile/nodes/EachBlock.d.ts +3 -1
  24. package/types/compiler/compile/nodes/Element.d.ts +1 -1
  25. package/types/compiler/compile/nodes/ElseBlock.d.ts +4 -1
  26. package/types/compiler/compile/nodes/EventHandler.d.ts +4 -2
  27. package/types/compiler/compile/nodes/Fragment.d.ts +2 -1
  28. package/types/compiler/compile/nodes/Head.d.ts +4 -1
  29. package/types/compiler/compile/nodes/IfBlock.d.ts +5 -1
  30. package/types/compiler/compile/nodes/InlineComponent.d.ts +2 -1
  31. package/types/compiler/compile/nodes/KeyBlock.d.ts +5 -1
  32. package/types/compiler/compile/nodes/Let.d.ts +3 -1
  33. package/types/compiler/compile/nodes/PendingBlock.d.ts +5 -1
  34. package/types/compiler/compile/nodes/Slot.d.ts +2 -1
  35. package/types/compiler/compile/nodes/Text.d.ts +2 -1
  36. package/types/compiler/compile/nodes/Title.d.ts +3 -1
  37. package/types/compiler/compile/nodes/Transition.d.ts +4 -1
  38. package/types/compiler/compile/nodes/Window.d.ts +4 -1
  39. package/types/compiler/compile/nodes/shared/Expression.d.ts +2 -2
  40. package/types/compiler/compile/nodes/shared/Node.d.ts +2 -1
  41. package/types/compiler/compile/nodes/shared/is_contextual.d.ts +3 -0
  42. package/types/compiler/compile/render_dom/Block.d.ts +1 -0
  43. package/types/compiler/compile/render_dom/Renderer.d.ts +1 -0
  44. package/types/compiler/compile/render_dom/invalidate.d.ts +1 -0
  45. package/types/compiler/compile/render_dom/wrappers/EachBlock.d.ts +2 -2
  46. package/types/compiler/compile/utils/get_slot_data.d.ts +1 -1
  47. package/types/compiler/utils/string_with_sourcemap.d.ts +1 -1
  48. package/types/runtime/index.d.ts +1 -1
  49. package/types/runtime/internal/Component.d.ts +7 -4
  50. package/types/runtime/internal/dev.d.ts +63 -4
package/compiler.mjs CHANGED
@@ -15918,6 +15918,7 @@ function is_head(node) {
15918
15918
  class Block$1 {
15919
15919
  constructor(options) {
15920
15920
  this.dependencies = new Set();
15921
+ this.binding_group_initialised = new Set();
15921
15922
  this.event_listeners = [];
15922
15923
  this.variables = new Map();
15923
15924
  this.has_update_method = false;
@@ -16992,8 +16993,9 @@ class EachBlockWrapper extends Wrapper {
16992
16993
  ? '@outro_and_destroy_block'
16993
16994
  : '@destroy_block';
16994
16995
  if (this.dependencies.size) {
16996
+ this.block.maintain_context = true;
16995
16997
  this.updates.push(b `
16996
- const ${this.vars.each_block_value} = ${snippet};
16998
+ ${this.vars.each_block_value} = ${snippet};
16997
16999
  ${this.renderer.options.dev && b `@validate_each_argument(${this.vars.each_block_value});`}
16998
17000
 
16999
17001
  ${this.block.has_outros && b `@group_outros();`}
@@ -17743,10 +17745,18 @@ function mark_each_block_bindings(parent, binding) {
17743
17745
  }
17744
17746
  });
17745
17747
  if (binding.name === 'group') {
17748
+ const add_index_binding = (name) => {
17749
+ const each_block = parent.node.scope.get_owner(name);
17750
+ if (each_block.type === 'EachBlock') {
17751
+ each_block.has_index_binding = true;
17752
+ for (const dep of each_block.expression.contextual_dependencies) {
17753
+ add_index_binding(dep);
17754
+ }
17755
+ }
17756
+ };
17746
17757
  // for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index`
17747
17758
  for (const name of binding.expression.contextual_dependencies) {
17748
- const each_block = parent.node.scope.get_owner(name);
17749
- each_block.has_index_binding = true;
17759
+ add_index_binding(name);
17750
17760
  }
17751
17761
  }
17752
17762
  }
@@ -17814,9 +17824,9 @@ class BindingWrapper {
17814
17824
  switch (this.node.name) {
17815
17825
  case 'group':
17816
17826
  {
17817
- const { binding_group, is_context, contexts, index } = get_binding_group(parent.renderer, this.node, block);
17827
+ const { binding_group, is_context, contexts, index, keypath } = get_binding_group(parent.renderer, this.node, block);
17818
17828
  block.renderer.add_to_context('$$binding_groups');
17819
- if (is_context) {
17829
+ if (is_context && !block.binding_group_initialised.has(keypath)) {
17820
17830
  if (contexts.length > 1) {
17821
17831
  let binding_group = x `${block.renderer.reference('$$binding_groups')}[${index}]`;
17822
17832
  for (const name of contexts.slice(0, -1)) {
@@ -17825,6 +17835,7 @@ class BindingWrapper {
17825
17835
  }
17826
17836
  }
17827
17837
  block.chunks.init.push(b `${binding_group(true)} = [];`);
17838
+ block.binding_group_initialised.add(keypath);
17828
17839
  }
17829
17840
  block.chunks.hydrate.push(b `${binding_group(true)}.push(${parent.var});`);
17830
17841
  block.chunks.destroy.push(b `${binding_group(true)}.splice(${binding_group(true)}.indexOf(${parent.var}), 1);`);
@@ -17920,7 +17931,21 @@ function get_binding_group(renderer, value, block) {
17920
17931
  const { parts } = flatten_reference(value.raw_expression);
17921
17932
  let keypath = parts.join('.');
17922
17933
  const contexts = [];
17934
+ const contextual_dependencies = new Set();
17935
+ const { template_scope } = value.expression;
17936
+ const add_contextual_dependency = (dep) => {
17937
+ contextual_dependencies.add(dep);
17938
+ const owner = template_scope.get_owner(dep);
17939
+ if (owner.type === 'EachBlock') {
17940
+ for (const dep of owner.expression.contextual_dependencies) {
17941
+ add_contextual_dependency(dep);
17942
+ }
17943
+ }
17944
+ };
17923
17945
  for (const dep of value.expression.contextual_dependencies) {
17946
+ add_contextual_dependency(dep);
17947
+ }
17948
+ for (const dep of contextual_dependencies) {
17924
17949
  const context = block.bindings.get(dep);
17925
17950
  let key;
17926
17951
  let name;
@@ -17961,7 +17986,8 @@ function get_binding_group(renderer, value, block) {
17961
17986
  },
17962
17987
  is_context: contexts.length > 0,
17963
17988
  contexts,
17964
- index
17989
+ index,
17990
+ keypath
17965
17991
  });
17966
17992
  }
17967
17993
  return renderer.binding_groups.get(keypath);
@@ -18032,11 +18058,30 @@ function get_value_from_dom(renderer, element, binding, block, contextual_depend
18032
18058
  return x `this.${name}`;
18033
18059
  }
18034
18060
 
18061
+ const reserved_keywords = new Set(['$$props', '$$restProps', '$$slots']);
18062
+ function is_reserved_keyword(name) {
18063
+ return reserved_keywords.has(name);
18064
+ }
18065
+
18066
+ function is_contextual(component, scope, name) {
18067
+ if (is_reserved_keyword(name))
18068
+ return true;
18069
+ // if it's a name below root scope, it's contextual
18070
+ if (!scope.is_top_level(name))
18071
+ return true;
18072
+ const variable = component.var_lookup.get(name);
18073
+ // hoistables, module declarations, and imports are non-contextual
18074
+ if (!variable || variable.hoistable)
18075
+ return false;
18076
+ // assume contextual
18077
+ return true;
18078
+ }
18079
+
18035
18080
  function add_actions(block, target, actions) {
18036
18081
  actions.forEach(action => add_action(block, target, action));
18037
18082
  }
18038
18083
  function add_action(block, target, action) {
18039
- const { expression } = action;
18084
+ const { expression, template_scope } = action;
18040
18085
  let snippet;
18041
18086
  let dependencies;
18042
18087
  if (expression) {
@@ -18046,9 +18091,12 @@ function add_action(block, target, action) {
18046
18091
  const id = block.get_unique_name(`${action.name.replace(/[^a-zA-Z0-9_$]/g, '_')}_action`);
18047
18092
  block.add_variable(id);
18048
18093
  const [obj, ...properties] = action.name.split('.');
18049
- const fn = block.renderer.reference(obj);
18094
+ const fn = is_contextual(action.component, template_scope, obj)
18095
+ ? block.renderer.reference(obj)
18096
+ : obj;
18050
18097
  if (properties.length) {
18051
- block.event_listeners.push(x `@action_destroyer(${id} = ${fn}.${properties.join('.')}(${target}, ${snippet}))`);
18098
+ const member_expression = properties.reduce((lhs, rhs) => x `${lhs}.${rhs}`, fn);
18099
+ block.event_listeners.push(x `@action_destroyer(${id} = ${member_expression}(${target}, ${snippet}))`);
18052
18100
  }
18053
18101
  else {
18054
18102
  block.event_listeners.push(x `@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))`);
@@ -18209,11 +18257,6 @@ function create_scopes(expression) {
18209
18257
  return analyze(expression);
18210
18258
  }
18211
18259
 
18212
- const reserved_keywords = new Set(['$$props', '$$restProps', '$$slots']);
18213
- function is_reserved_keyword(name) {
18214
- return reserved_keywords.has(name);
18215
- }
18216
-
18217
18260
  function is_dynamic$1(variable) {
18218
18261
  if (variable) {
18219
18262
  if (variable.mutated || variable.reassigned)
@@ -18279,7 +18322,7 @@ function invalidate(renderer, scope, node, names, main_execution_context = false
18279
18322
  if (main_execution_context && !variable.subscribable && variable.name[0] !== '$') {
18280
18323
  return node;
18281
18324
  }
18282
- return renderer.invalidate(variable.name, undefined, main_execution_context);
18325
+ return renderer_invalidate(renderer, variable.name, undefined, main_execution_context);
18283
18326
  }
18284
18327
  if (!head) {
18285
18328
  return node;
@@ -18316,6 +18359,55 @@ function invalidate(renderer, scope, node, names, main_execution_context = false
18316
18359
  }
18317
18360
  return invalidate;
18318
18361
  }
18362
+ function renderer_invalidate(renderer, name, value, main_execution_context = false) {
18363
+ const variable = renderer.component.var_lookup.get(name);
18364
+ if (variable && (variable.subscribable && (variable.reassigned || variable.export_name))) {
18365
+ if (main_execution_context) {
18366
+ return x `${`$$subscribe_${name}`}(${value || name})`;
18367
+ }
18368
+ else {
18369
+ const member = renderer.context_lookup.get(name);
18370
+ return x `${`$$subscribe_${name}`}($$invalidate(${member.index}, ${value || name}))`;
18371
+ }
18372
+ }
18373
+ if (name[0] === '$' && name[1] !== '$') {
18374
+ return x `${name.slice(1)}.set(${value || name})`;
18375
+ }
18376
+ if (variable && (variable.module || (!variable.referenced &&
18377
+ !variable.is_reactive_dependency &&
18378
+ !variable.export_name &&
18379
+ !name.startsWith('$$')))) {
18380
+ return value || name;
18381
+ }
18382
+ if (value) {
18383
+ if (main_execution_context) {
18384
+ return x `${value}`;
18385
+ }
18386
+ else {
18387
+ const member = renderer.context_lookup.get(name);
18388
+ return x `$$invalidate(${member.index}, ${value})`;
18389
+ }
18390
+ }
18391
+ if (main_execution_context)
18392
+ return;
18393
+ // if this is a reactive declaration, invalidate dependencies recursively
18394
+ const deps = new Set([name]);
18395
+ deps.forEach(name => {
18396
+ const reactive_declarations = renderer.component.reactive_declarations.filter(x => x.assignees.has(name));
18397
+ reactive_declarations.forEach(declaration => {
18398
+ declaration.dependencies.forEach(name => {
18399
+ deps.add(name);
18400
+ });
18401
+ });
18402
+ });
18403
+ // TODO ideally globals etc wouldn't be here in the first place
18404
+ const filtered = Array.from(deps).filter(n => renderer.context_lookup.has(n));
18405
+ if (!filtered.length)
18406
+ return null;
18407
+ return filtered
18408
+ .map(n => x `$$invalidate(${renderer.context_lookup.get(n).index}, ${n})`)
18409
+ .reduce((lhs, rhs) => x `${lhs}, ${rhs}`);
18410
+ }
18319
18411
 
18320
18412
  class Expression {
18321
18413
  constructor(component, owner, template_scope, info, lazy) {
@@ -18642,19 +18734,6 @@ function get_function_name(_node, parent) {
18642
18734
  }
18643
18735
  return 'func';
18644
18736
  }
18645
- function is_contextual(component, scope, name) {
18646
- if (is_reserved_keyword(name))
18647
- return true;
18648
- // if it's a name below root scope, it's contextual
18649
- if (!scope.is_top_level(name))
18650
- return true;
18651
- const variable = component.var_lookup.get(name);
18652
- // hoistables, module declarations, and imports are non-contextual
18653
- if (!variable || variable.hoistable)
18654
- return false;
18655
- // assume contextual
18656
- return true;
18657
- }
18658
18737
 
18659
18738
  class Action extends Node$1 {
18660
18739
  constructor(component, parent, scope, info) {
@@ -18666,6 +18745,7 @@ class Action extends Node$1 {
18666
18745
  this.expression = info.expression
18667
18746
  ? new Expression(component, this, scope, info.expression)
18668
18747
  : null;
18748
+ this.template_scope = scope;
18669
18749
  this.uses_context = this.expression && this.expression.uses_context;
18670
18750
  }
18671
18751
  }
@@ -19521,7 +19601,20 @@ class ElementWrapper extends Wrapper {
19521
19601
  ${stop_animation}();
19522
19602
  ${outro && b `@add_transform(${this.var}, ${rect});`}
19523
19603
  `);
19524
- const params = this.node.animation.expression ? this.node.animation.expression.manipulate(block) : x `{}`;
19604
+ let params;
19605
+ if (this.node.animation.expression) {
19606
+ params = this.node.animation.expression.manipulate(block);
19607
+ if (this.node.animation.expression.dynamic_dependencies().length) {
19608
+ // if `params` is dynamic, calculate params ahead of time in the `.r()` method
19609
+ const params_var = block.get_unique_name('params');
19610
+ block.add_variable(params_var);
19611
+ block.chunks.measure.push(b `${params_var} = ${params};`);
19612
+ params = params_var;
19613
+ }
19614
+ }
19615
+ else {
19616
+ params = x `{}`;
19617
+ }
19525
19618
  const name = this.renderer.reference(this.node.animation.name);
19526
19619
  block.chunks.animate.push(b `
19527
19620
  ${stop_animation}();
@@ -19951,7 +20044,7 @@ class IfBlockWrapper extends Wrapper {
19951
20044
  ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
19952
20045
  ${name}.c();
19953
20046
  } else {
19954
- ${name}.p(#ctx, #dirty);
20047
+ ${dynamic && b `${name}.p(#ctx, #dirty);`}
19955
20048
  }
19956
20049
  ${has_transitions && b `@transition_in(${name}, 1);`}
19957
20050
  ${name}.m(${update_mount_node}, ${anchor});
@@ -19973,10 +20066,12 @@ class IfBlockWrapper extends Wrapper {
19973
20066
  ${name} = null;
19974
20067
  }
19975
20068
  `;
20069
+ block.chunks.update.push(b `
20070
+ let ${previous_block_index} = ${current_block_type_index};
20071
+ ${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
20072
+ `);
19976
20073
  if (dynamic) {
19977
20074
  block.chunks.update.push(b `
19978
- let ${previous_block_index} = ${current_block_type_index};
19979
- ${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
19980
20075
  if (${current_block_type_index} === ${previous_block_index}) {
19981
20076
  ${if_current_block_type_index(b `${if_blocks}[${current_block_type_index}].p(#ctx, #dirty);`)}
19982
20077
  } else {
@@ -19986,8 +20081,6 @@ class IfBlockWrapper extends Wrapper {
19986
20081
  }
19987
20082
  else {
19988
20083
  block.chunks.update.push(b `
19989
- let ${previous_block_index} = ${current_block_type_index};
19990
- ${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
19991
20084
  if (${current_block_type_index} !== ${previous_block_index}) {
19992
20085
  ${change_block}
19993
20086
  }
@@ -20864,11 +20957,13 @@ class WindowWrapper extends Wrapper {
20864
20957
  add_actions(block, '@_window', this.node.actions);
20865
20958
  add_event_handlers(block, '@_window', this.handlers);
20866
20959
  this.node.bindings.forEach(binding => {
20960
+ // TODO: what if it's a MemberExpression?
20961
+ const binding_name = binding.expression.node.name;
20867
20962
  // in dev mode, throw if read-only values are written to
20868
20963
  if (readonly.has(binding.name)) {
20869
- renderer.readonly.add(binding.expression.node.name);
20964
+ renderer.readonly.add(binding_name);
20870
20965
  }
20871
- bindings[binding.name] = binding.expression.node.name;
20966
+ bindings[binding.name] = binding_name;
20872
20967
  // bind:online is a special case, we need to listen for two separate events
20873
20968
  if (binding.name === 'online')
20874
20969
  return;
@@ -20877,7 +20972,7 @@ class WindowWrapper extends Wrapper {
20877
20972
  if (!events[associated_event])
20878
20973
  events[associated_event] = [];
20879
20974
  events[associated_event].push({
20880
- name: binding.expression.node.name,
20975
+ name: binding_name,
20881
20976
  value: property
20882
20977
  });
20883
20978
  });
@@ -21186,42 +21281,7 @@ class Renderer {
21186
21281
  return member;
21187
21282
  }
21188
21283
  invalidate(name, value, main_execution_context = false) {
21189
- const variable = this.component.var_lookup.get(name);
21190
- const member = this.context_lookup.get(name);
21191
- if (variable && (variable.subscribable && (variable.reassigned || variable.export_name))) {
21192
- return main_execution_context
21193
- ? x `${`$$subscribe_${name}`}(${value || name})`
21194
- : x `${`$$subscribe_${name}`}($$invalidate(${member.index}, ${value || name}))`;
21195
- }
21196
- if (name[0] === '$' && name[1] !== '$') {
21197
- return x `${name.slice(1)}.set(${value || name})`;
21198
- }
21199
- if (variable && (variable.module || (!variable.referenced &&
21200
- !variable.is_reactive_dependency &&
21201
- !variable.export_name &&
21202
- !name.startsWith('$$')))) {
21203
- return value || name;
21204
- }
21205
- if (value) {
21206
- return x `$$invalidate(${member.index}, ${value})`;
21207
- }
21208
- // if this is a reactive declaration, invalidate dependencies recursively
21209
- const deps = new Set([name]);
21210
- deps.forEach(name => {
21211
- const reactive_declarations = this.component.reactive_declarations.filter(x => x.assignees.has(name));
21212
- reactive_declarations.forEach(declaration => {
21213
- declaration.dependencies.forEach(name => {
21214
- deps.add(name);
21215
- });
21216
- });
21217
- });
21218
- // TODO ideally globals etc wouldn't be here in the first place
21219
- const filtered = Array.from(deps).filter(n => this.context_lookup.has(n));
21220
- if (!filtered.length)
21221
- return null;
21222
- return filtered
21223
- .map(n => x `$$invalidate(${this.context_lookup.get(n).index}, ${n})`)
21224
- .reduce((lhs, rhs) => x `${lhs}, ${rhs}`);
21284
+ return renderer_invalidate(this, name, value, main_execution_context);
21225
21285
  }
21226
21286
  dirty(names, is_reactive_declaration = false) {
21227
21287
  const renderer = this;
@@ -22077,23 +22137,22 @@ function last_line_length(s) {
22077
22137
  return s.length - s.lastIndexOf('\n') - 1;
22078
22138
  }
22079
22139
  // mutate map in-place
22080
- function sourcemap_add_offset(map, offset) {
22140
+ function sourcemap_add_offset(map, offset, source_index) {
22081
22141
  if (map.mappings.length == 0)
22082
- return map;
22083
- // shift columns in first line
22084
- const segment_list = map.mappings[0];
22085
- for (let segment = 0; segment < segment_list.length; segment++) {
22086
- const seg = segment_list[segment];
22087
- if (seg[3])
22088
- seg[3] += offset.column;
22089
- }
22090
- // shift lines
22142
+ return;
22091
22143
  for (let line = 0; line < map.mappings.length; line++) {
22092
22144
  const segment_list = map.mappings[line];
22093
22145
  for (let segment = 0; segment < segment_list.length; segment++) {
22094
22146
  const seg = segment_list[segment];
22095
- if (seg[2])
22147
+ // shift only segments that belong to component source file
22148
+ if (seg[1] === source_index) { // also ensures that seg.length >= 4
22149
+ // shift column if it points at the first line
22150
+ if (seg[2] === 0) {
22151
+ seg[3] += offset.column;
22152
+ }
22153
+ // shift line
22096
22154
  seg[2] += offset.line;
22155
+ }
22097
22156
  }
22098
22157
  }
22099
22158
  }
@@ -22158,6 +22217,8 @@ class StringWithSourcemap {
22158
22217
  this.map = other.map;
22159
22218
  return this;
22160
22219
  }
22220
+ // compute last line length before mutating
22221
+ const column_offset = last_line_length(this.string);
22161
22222
  this.string += other.string;
22162
22223
  const m1 = this.map;
22163
22224
  const m2 = other.map;
@@ -22176,9 +22237,9 @@ class StringWithSourcemap {
22176
22237
  const segment_list = m2.mappings[line];
22177
22238
  for (let segment = 0; segment < segment_list.length; segment++) {
22178
22239
  const seg = segment_list[segment];
22179
- if (seg[1])
22240
+ if (seg[1] >= 0)
22180
22241
  seg[1] = new_source_idx[seg[1]];
22181
- if (seg[4])
22242
+ if (seg[4] >= 0)
22182
22243
  seg[4] = new_name_idx[seg[4]];
22183
22244
  }
22184
22245
  }
@@ -22188,7 +22249,7 @@ class StringWithSourcemap {
22188
22249
  const segment_list = m2.mappings[line];
22189
22250
  for (let segment = 0; segment < segment_list.length; segment++) {
22190
22251
  const seg = segment_list[segment];
22191
- if (seg[1])
22252
+ if (seg[1] >= 0)
22192
22253
  seg[1] = new_source_idx[seg[1]];
22193
22254
  }
22194
22255
  }
@@ -22198,7 +22259,7 @@ class StringWithSourcemap {
22198
22259
  const segment_list = m2.mappings[line];
22199
22260
  for (let segment = 0; segment < segment_list.length; segment++) {
22200
22261
  const seg = segment_list[segment];
22201
- if (seg[4])
22262
+ if (seg[4] >= 0)
22202
22263
  seg[4] = new_name_idx[seg[4]];
22203
22264
  }
22204
22265
  }
@@ -22208,7 +22269,6 @@ class StringWithSourcemap {
22208
22269
  // 1. last line of first map
22209
22270
  // 2. first line of second map
22210
22271
  // columns of 2 must be shifted
22211
- const column_offset = last_line_length(this.string);
22212
22272
  if (m2.mappings.length > 0 && column_offset > 0) {
22213
22273
  const first_line = m2.mappings[0];
22214
22274
  for (let i = 0; i < first_line.length; i++) {
@@ -22222,13 +22282,21 @@ class StringWithSourcemap {
22222
22282
  return this;
22223
22283
  }
22224
22284
  static from_processed(string, map) {
22225
- if (map)
22285
+ const line_count = string.split('\n').length;
22286
+ if (map) {
22287
+ // ensure that count of source map mappings lines
22288
+ // is equal to count of generated code lines
22289
+ // (some tools may produce less)
22290
+ const missing_lines = line_count - map.mappings.length;
22291
+ for (let i = 0; i < missing_lines; i++) {
22292
+ map.mappings.push([]);
22293
+ }
22226
22294
  return new StringWithSourcemap(string, map);
22295
+ }
22227
22296
  if (string == '')
22228
22297
  return new StringWithSourcemap();
22229
22298
  map = { version: 3, names: [], sources: [], mappings: [] };
22230
22299
  // add empty SourceMapSegment[] for every line
22231
- const line_count = (string.match(/\n/g) || '').length;
22232
22300
  for (let i = 0; i < line_count; i++)
22233
22301
  map.mappings.push([]);
22234
22302
  return new StringWithSourcemap(string, map);
@@ -22647,6 +22715,8 @@ function dom(component, options) {
22647
22715
  };
22648
22716
  body.push(b `
22649
22717
  function ${definition}(${args}) {
22718
+ ${injected.map(name => b `let ${name};`)}
22719
+
22650
22720
  ${rest}
22651
22721
 
22652
22722
  ${reactive_store_declarations}
@@ -22673,8 +22743,6 @@ function dom(component, options) {
22673
22743
 
22674
22744
  ${inject_state && b `$$self.$inject_state = ${inject_state};`}
22675
22745
 
22676
- ${injected.map(name => b `let ${name};`)}
22677
-
22678
22746
  ${ /* before reactive declarations */props_inject}
22679
22747
 
22680
22748
  ${reactive_declarations.length > 0 && b `
@@ -23116,7 +23184,7 @@ function Element (node, renderer, options) {
23116
23184
  }
23117
23185
 
23118
23186
  function Head (node, renderer, options) {
23119
- const head_options = Object.assign({}, options, { head_id: node.id });
23187
+ const head_options = Object.assign(Object.assign({}, options), { head_id: node.id });
23120
23188
  renderer.push();
23121
23189
  renderer.render(node.children, head_options);
23122
23190
  const result = renderer.pop();
@@ -23376,21 +23444,71 @@ function ssr(component, options) {
23376
23444
  const uses_slots = component.var_lookup.has('$$slots');
23377
23445
  const slots = uses_slots ? b `let $$slots = @compute_slots(#slots);` : null;
23378
23446
  const reactive_stores = component.vars.filter(variable => variable.name[0] === '$' && variable.name[1] !== '$');
23379
- const reactive_store_values = reactive_stores
23447
+ const reactive_store_subscriptions = reactive_stores
23448
+ .filter(store => {
23449
+ const variable = component.var_lookup.get(store.name.slice(1));
23450
+ return !variable || variable.hoistable;
23451
+ })
23452
+ .map(({ name }) => {
23453
+ const store_name = name.slice(1);
23454
+ return b `
23455
+ ${component.compile_options.dev && b `@validate_store(${store_name}, '${store_name}');`}
23456
+ ${`$$unsubscribe_${store_name}`} = @subscribe(${store_name}, #value => ${name} = #value)
23457
+ ${store_name}.subscribe($$value => ${name} = $$value);
23458
+ `;
23459
+ });
23460
+ const reactive_store_unsubscriptions = reactive_stores.map(({ name }) => b `${`$$unsubscribe_${name.slice(1)}`}()`);
23461
+ const reactive_store_declarations = reactive_stores
23380
23462
  .map(({ name }) => {
23381
23463
  const store_name = name.slice(1);
23382
23464
  const store = component.var_lookup.get(store_name);
23383
- if (store && store.hoistable)
23384
- return null;
23385
- const assignment = b `${name} = @get_store_value(${store_name});`;
23386
- return component.compile_options.dev
23387
- ? b `@validate_store(${store_name}, '${store_name}'); ${assignment}`
23388
- : assignment;
23389
- })
23390
- .filter(Boolean);
23391
- component.rewrite_props(({ name }) => {
23465
+ if (store && store.reassigned) {
23466
+ const unsubscribe = `$$unsubscribe_${store_name}`;
23467
+ const subscribe = `$$subscribe_${store_name}`;
23468
+ return b `let ${name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${store_name}, $$value => ${name} = $$value), ${store_name})`;
23469
+ }
23470
+ return b `let ${name}, ${`$$unsubscribe_${store_name}`};`;
23471
+ });
23472
+ // instrument get/set store value
23473
+ if (component.ast.instance) {
23474
+ let scope = component.instance_scope;
23475
+ const map = component.instance_scope_map;
23476
+ walk(component.ast.instance.content, {
23477
+ enter(node) {
23478
+ if (map.has(node)) {
23479
+ scope = map.get(node);
23480
+ }
23481
+ },
23482
+ leave(node) {
23483
+ if (map.has(node)) {
23484
+ scope = scope.parent;
23485
+ }
23486
+ if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') {
23487
+ const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument;
23488
+ const names = new Set(extract_names(assignee));
23489
+ const to_invalidate = new Set();
23490
+ for (const name of names) {
23491
+ const variable = component.var_lookup.get(name);
23492
+ if (variable &&
23493
+ !variable.hoistable &&
23494
+ !variable.global &&
23495
+ !variable.module &&
23496
+ (variable.subscribable || variable.name[0] === '$')) {
23497
+ to_invalidate.add(variable.name);
23498
+ }
23499
+ }
23500
+ if (to_invalidate.size) {
23501
+ this.replace(invalidate({ component }, scope, node, to_invalidate, true));
23502
+ }
23503
+ }
23504
+ }
23505
+ });
23506
+ }
23507
+ component.rewrite_props(({ name, reassigned }) => {
23392
23508
  const value = `$${name}`;
23393
- let insert = b `${value} = @get_store_value(${name})`;
23509
+ let insert = reassigned
23510
+ ? b `${`$$subscribe_${name}`}()`
23511
+ : b `${`$$unsubscribe_${name}`} = @subscribe(${name}, #value => $${value} = #value)`;
23394
23512
  if (component.compile_options.dev) {
23395
23513
  insert = b `@validate_store(${name}, '${name}'); ${insert}`;
23396
23514
  }
@@ -23425,36 +23543,27 @@ function ssr(component, options) {
23425
23543
  do {
23426
23544
  $$settled = true;
23427
23545
 
23428
- ${reactive_store_values}
23429
-
23430
- ${injected.map(name => b `let ${name};`)}
23431
-
23432
23546
  ${reactive_declarations}
23433
23547
 
23434
23548
  $$rendered = ${literal};
23435
23549
  } while (!$$settled);
23436
23550
 
23551
+ ${reactive_store_unsubscriptions}
23552
+
23437
23553
  return $$rendered;
23438
23554
  `
23439
23555
  : b `
23440
- ${reactive_store_values}
23441
-
23442
- ${injected.map(name => b `let ${name};`)}
23443
-
23444
23556
  ${reactive_declarations}
23445
23557
 
23558
+ ${reactive_store_unsubscriptions}
23559
+
23446
23560
  return ${literal};`;
23447
23561
  const blocks = [
23562
+ ...injected.map(name => b `let ${name};`),
23448
23563
  rest,
23449
23564
  slots,
23450
- ...reactive_stores.map(({ name }) => {
23451
- const store_name = name.slice(1);
23452
- const store = component.var_lookup.get(store_name);
23453
- if (store && store.hoistable) {
23454
- return b `let ${name} = @get_store_value(${store_name});`;
23455
- }
23456
- return b `let ${name};`;
23457
- }),
23565
+ ...reactive_store_declarations,
23566
+ ...reactive_store_subscriptions,
23458
23567
  instance_javascript,
23459
23568
  ...parent_bindings,
23460
23569
  css.code && b `$$result.css.add(#css);`,
@@ -25713,7 +25822,7 @@ class Body extends Node$1 {
25713
25822
  constructor(component, parent, scope, info) {
25714
25823
  super(component, parent, scope, info);
25715
25824
  this.handlers = [];
25716
- info.attributes.forEach(node => {
25825
+ info.attributes.forEach((node) => {
25717
25826
  if (node.type === 'EventHandler') {
25718
25827
  this.handlers.push(new EventHandler(component, this, scope, node));
25719
25828
  }
@@ -25922,15 +26031,19 @@ class Binding extends Node$1 {
25922
26031
  }
25923
26032
  }
25924
26033
  const type = parent.get_static_attribute_value('type');
25925
- this.is_readonly = (dimensions.test(this.name) ||
25926
- (parent.is_media_node && parent.is_media_node() && read_only_media_attributes.has(this.name)) ||
25927
- (parent.name === 'input' && type === 'file') // TODO others?
25928
- );
26034
+ this.is_readonly =
26035
+ dimensions.test(this.name) ||
26036
+ (isElement(parent) &&
26037
+ ((parent.is_media_node() && read_only_media_attributes.has(this.name)) ||
26038
+ (parent.name === 'input' && type === 'file')) /* TODO others? */);
25929
26039
  }
25930
26040
  is_readonly_media_attribute() {
25931
26041
  return read_only_media_attributes.has(this.name);
25932
26042
  }
25933
26043
  }
26044
+ function isElement(node) {
26045
+ return !!node.is_media_node;
26046
+ }
25934
26047
 
25935
26048
  class Transition extends Node$1 {
25936
26049
  constructor(component, parent, scope, info) {
@@ -26073,7 +26186,7 @@ class Let extends Node$1 {
26073
26186
  const svg$1 = /^(?:altGlyph|altGlyphDef|altGlyphItem|animate|animateColor|animateMotion|animateTransform|circle|clipPath|color-profile|cursor|defs|desc|discard|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|foreignObject|g|glyph|glyphRef|hatch|hatchpath|hkern|image|line|linearGradient|marker|mask|mesh|meshgradient|meshpatch|meshrow|metadata|missing-glyph|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|solidcolor|stop|svg|switch|symbol|text|textPath|tref|tspan|unknown|use|view|vkern)$/;
26074
26187
  const aria_attributes = 'activedescendant atomic autocomplete busy checked colcount colindex colspan controls current describedby details disabled dropeffect errormessage expanded flowto grabbed haspopup hidden invalid keyshortcuts label labelledby level live modal multiline multiselectable orientation owns placeholder posinset pressed readonly relevant required roledescription rowcount rowindex rowspan selected setsize sort valuemax valuemin valuenow valuetext'.split(' ');
26075
26188
  const aria_attribute_set = new Set(aria_attributes);
26076
- const aria_roles = 'alert alertdialog application article banner blockquote button caption cell checkbox code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form generic grid gridcell group heading img link list listbox listitem log main marquee math meter menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option paragraph presentation progressbar radio radiogroup region row rowgroup rowheader scrollbar search searchbox separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term textbox time timer toolbar tooltip tree treegrid treeitem'.split(' ');
26189
+ const aria_roles = 'alert alertdialog application article banner blockquote button caption cell checkbox code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form generic graphics-document graphics-object graphics-symbol grid gridcell group heading img link list listbox listitem log main marquee math meter menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option paragraph presentation progressbar radio radiogroup region row rowgroup rowheader scrollbar search searchbox separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term textbox time timer toolbar tooltip tree treegrid treeitem'.split(' ');
26077
26190
  const aria_role_set = new Set(aria_roles);
26078
26191
  const a11y_required_attributes = {
26079
26192
  a: ['href'],
@@ -26131,6 +26244,10 @@ const passive_events = new Set([
26131
26244
  'touchend',
26132
26245
  'touchcancel'
26133
26246
  ]);
26247
+ const react_attributes = new Map([
26248
+ ['className', 'class'],
26249
+ ['htmlFor', 'for']
26250
+ ]);
26134
26251
  function get_namespace(parent, element, explicit_namespace) {
26135
26252
  const parent_element = parent.find_nearest(/^Element/);
26136
26253
  if (!parent_element) {
@@ -26427,6 +26544,12 @@ class Element$1 extends Node$1 {
26427
26544
  message: 'The \'is\' attribute is not supported cross-browser and should be avoided'
26428
26545
  });
26429
26546
  }
26547
+ if (react_attributes.has(attribute.name)) {
26548
+ component.warn(attribute, {
26549
+ code: 'invalid-html-attribute',
26550
+ message: `'${attribute.name}' is not a valid HTML attribute. Did you mean '${react_attributes.get(attribute.name)}'?`
26551
+ });
26552
+ }
26430
26553
  attribute_map.set(attribute.name, attribute);
26431
26554
  });
26432
26555
  }
@@ -26959,7 +27082,7 @@ class RawMustacheTag extends Tag$2 {
26959
27082
  class DebugTag$1 extends Node$1 {
26960
27083
  constructor(component, parent, scope, info) {
26961
27084
  super(component, parent, scope, info);
26962
- this.expressions = info.identifiers.map(node => {
27085
+ this.expressions = info.identifiers.map((node) => {
26963
27086
  return new Expression(component, parent, scope, node);
26964
27087
  });
26965
27088
  }
@@ -27188,7 +27311,7 @@ class Fragment extends Node$1 {
27188
27311
  }
27189
27312
 
27190
27313
  // This file is automatically generated
27191
- var internal_exports = new Set(["HtmlTag", "SvelteComponent", "SvelteComponentDev", "SvelteElement", "action_destroyer", "add_attribute", "add_classes", "add_flush_callback", "add_location", "add_render_callback", "add_resize_listener", "add_transform", "afterUpdate", "append", "append_dev", "assign", "attr", "attr_dev", "attribute_to_object", "beforeUpdate", "bind", "binding_callbacks", "blank_object", "bubble", "check_outros", "children", "claim_component", "claim_element", "claim_space", "claim_text", "clear_loops", "component_subscribe", "compute_rest_props", "compute_slots", "createEventDispatcher", "create_animation", "create_bidirectional_transition", "create_component", "create_in_transition", "create_out_transition", "create_slot", "create_ssr_component", "current_component", "custom_event", "dataset_dev", "debug", "destroy_block", "destroy_component", "destroy_each", "detach", "detach_after_dev", "detach_before_dev", "detach_between_dev", "detach_dev", "dirty_components", "dispatch_dev", "each", "element", "element_is", "empty", "escape", "escaped", "exclude_internal_props", "fix_and_destroy_block", "fix_and_outro_and_destroy_block", "fix_position", "flush", "getContext", "get_binding_group_value", "get_current_component", "get_custom_elements_slots", "get_slot_changes", "get_slot_context", "get_spread_object", "get_spread_update", "get_store_value", "globals", "group_outros", "handle_promise", "hasContext", "has_prop", "identity", "init", "insert", "insert_dev", "intros", "invalid_attribute_name_character", "is_client", "is_crossorigin", "is_empty", "is_function", "is_promise", "listen", "listen_dev", "loop", "loop_guard", "missing_component", "mount_component", "noop", "not_equal", "now", "null_to_empty", "object_without_properties", "onDestroy", "onMount", "once", "outro_and_destroy_block", "prevent_default", "prop_dev", "query_selector_all", "raf", "run", "run_all", "safe_not_equal", "schedule_update", "select_multiple_value", "select_option", "select_options", "select_value", "self", "setContext", "set_attributes", "set_current_component", "set_custom_element_data", "set_data", "set_data_dev", "set_input_type", "set_input_value", "set_now", "set_raf", "set_store_value", "set_style", "set_svg_attributes", "space", "spread", "stop_propagation", "subscribe", "svg_element", "text", "tick", "time_ranges_to_array", "to_number", "toggle_class", "transition_in", "transition_out", "update_keyed_each", "update_slot", "update_slot_spread", "validate_component", "validate_each_argument", "validate_each_keys", "validate_slots", "validate_store", "xlink_attr"]);
27314
+ var internal_exports = new Set(["HtmlTag", "SvelteComponent", "SvelteComponentDev", "SvelteComponentTyped", "SvelteElement", "action_destroyer", "add_attribute", "add_classes", "add_flush_callback", "add_location", "add_render_callback", "add_resize_listener", "add_transform", "afterUpdate", "append", "append_dev", "assign", "attr", "attr_dev", "attribute_to_object", "beforeUpdate", "bind", "binding_callbacks", "blank_object", "bubble", "check_outros", "children", "claim_component", "claim_element", "claim_space", "claim_text", "clear_loops", "component_subscribe", "compute_rest_props", "compute_slots", "createEventDispatcher", "create_animation", "create_bidirectional_transition", "create_component", "create_in_transition", "create_out_transition", "create_slot", "create_ssr_component", "current_component", "custom_event", "dataset_dev", "debug", "destroy_block", "destroy_component", "destroy_each", "detach", "detach_after_dev", "detach_before_dev", "detach_between_dev", "detach_dev", "dirty_components", "dispatch_dev", "each", "element", "element_is", "empty", "escape", "escaped", "exclude_internal_props", "fix_and_destroy_block", "fix_and_outro_and_destroy_block", "fix_position", "flush", "getContext", "get_binding_group_value", "get_current_component", "get_custom_elements_slots", "get_slot_changes", "get_slot_context", "get_spread_object", "get_spread_update", "get_store_value", "globals", "group_outros", "handle_promise", "hasContext", "has_prop", "identity", "init", "insert", "insert_dev", "intros", "invalid_attribute_name_character", "is_client", "is_crossorigin", "is_empty", "is_function", "is_promise", "listen", "listen_dev", "loop", "loop_guard", "missing_component", "mount_component", "noop", "not_equal", "now", "null_to_empty", "object_without_properties", "onDestroy", "onMount", "once", "outro_and_destroy_block", "prevent_default", "prop_dev", "query_selector_all", "raf", "run", "run_all", "safe_not_equal", "schedule_update", "select_multiple_value", "select_option", "select_options", "select_value", "self", "setContext", "set_attributes", "set_current_component", "set_custom_element_data", "set_data", "set_data_dev", "set_input_type", "set_input_value", "set_now", "set_raf", "set_store_value", "set_style", "set_svg_attributes", "space", "spread", "stop_propagation", "subscribe", "svg_element", "text", "tick", "time_ranges_to_array", "to_number", "toggle_class", "transition_in", "transition_out", "update_keyed_each", "update_slot", "update_slot_spread", "validate_component", "validate_each_argument", "validate_each_keys", "validate_slots", "validate_store", "xlink_attr"]);
27192
27315
 
27193
27316
  function is_used_as_reference(node, parent) {
27194
27317
  if (!isReference(node, parent)) {
@@ -27383,7 +27506,7 @@ class Component {
27383
27506
  if (result) {
27384
27507
  const { compile_options, name } = this;
27385
27508
  const { format = 'esm' } = compile_options;
27386
- const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.30.0'}`;
27509
+ const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.31.2'}`;
27387
27510
  const program = { type: 'Program', body: result.js };
27388
27511
  walk(program, {
27389
27512
  enter: (node, parent, key) => {
@@ -28530,7 +28653,10 @@ function parse_attributes(str) {
28530
28653
  });
28531
28654
  return attrs;
28532
28655
  }
28533
- async function replace_async(filename, source, get_location, re, func) {
28656
+ function get_file_basename(filename) {
28657
+ return filename.split(/[/\\]/).pop();
28658
+ }
28659
+ async function replace_async(file_basename, source, get_location, re, func) {
28534
28660
  const replacements = [];
28535
28661
  source.replace(re, (...args) => {
28536
28662
  replacements.push(func(...args).then(res => ({
@@ -28544,21 +28670,86 @@ async function replace_async(filename, source, get_location, re, func) {
28544
28670
  let last_end = 0;
28545
28671
  for (const { offset, length, replacement } of await Promise.all(replacements)) {
28546
28672
  // content = unchanged source characters before the replaced segment
28547
- const content = StringWithSourcemap.from_source(filename, source.slice(last_end, offset), get_location(last_end));
28673
+ const content = StringWithSourcemap.from_source(file_basename, source.slice(last_end, offset), get_location(last_end));
28548
28674
  out.concat(content).concat(replacement);
28549
28675
  last_end = offset + length;
28550
28676
  }
28551
28677
  // final_content = unchanged source characters after last replaced segment
28552
- const final_content = StringWithSourcemap.from_source(filename, source.slice(last_end), get_location(last_end));
28678
+ const final_content = StringWithSourcemap.from_source(file_basename, source.slice(last_end), get_location(last_end));
28553
28679
  return out.concat(final_content);
28554
28680
  }
28681
+ /**
28682
+ * Import decoded sourcemap from mozilla/source-map/SourceMapGenerator
28683
+ * Forked from source-map/lib/source-map-generator.js
28684
+ * from methods _serializeMappings and toJSON.
28685
+ * We cannot use source-map.d.ts types, because we access hidden properties.
28686
+ */
28687
+ function decoded_sourcemap_from_generator(generator) {
28688
+ let previous_generated_line = 1;
28689
+ const converted_mappings = [[]];
28690
+ let result_line;
28691
+ let result_segment;
28692
+ let mapping;
28693
+ const source_idx = generator._sources.toArray()
28694
+ .reduce((acc, val, idx) => (acc[val] = idx, acc), {});
28695
+ const name_idx = generator._names.toArray()
28696
+ .reduce((acc, val, idx) => (acc[val] = idx, acc), {});
28697
+ const mappings = generator._mappings.toArray();
28698
+ result_line = converted_mappings[0];
28699
+ for (let i = 0, len = mappings.length; i < len; i++) {
28700
+ mapping = mappings[i];
28701
+ if (mapping.generatedLine > previous_generated_line) {
28702
+ while (mapping.generatedLine > previous_generated_line) {
28703
+ converted_mappings.push([]);
28704
+ previous_generated_line++;
28705
+ }
28706
+ result_line = converted_mappings[mapping.generatedLine - 1]; // line is one-based
28707
+ }
28708
+ else if (i > 0) {
28709
+ const previous_mapping = mappings[i - 1];
28710
+ if (
28711
+ // sorted by selectivity
28712
+ mapping.generatedColumn === previous_mapping.generatedColumn &&
28713
+ mapping.originalColumn === previous_mapping.originalColumn &&
28714
+ mapping.name === previous_mapping.name &&
28715
+ mapping.generatedLine === previous_mapping.generatedLine &&
28716
+ mapping.originalLine === previous_mapping.originalLine &&
28717
+ mapping.source === previous_mapping.source) {
28718
+ continue;
28719
+ }
28720
+ }
28721
+ result_line.push([mapping.generatedColumn]);
28722
+ result_segment = result_line[result_line.length - 1];
28723
+ if (mapping.source != null) {
28724
+ result_segment.push(...[
28725
+ source_idx[mapping.source],
28726
+ mapping.originalLine - 1,
28727
+ mapping.originalColumn
28728
+ ]);
28729
+ if (mapping.name != null) {
28730
+ result_segment.push(name_idx[mapping.name]);
28731
+ }
28732
+ }
28733
+ }
28734
+ const map = {
28735
+ version: generator._version,
28736
+ sources: generator._sources.toArray(),
28737
+ names: generator._names.toArray(),
28738
+ mappings: converted_mappings
28739
+ };
28740
+ if (generator._file != null) {
28741
+ map.file = generator._file;
28742
+ }
28743
+ // not needed: map.sourcesContent and map.sourceRoot
28744
+ return map;
28745
+ }
28555
28746
  /**
28556
28747
  * Convert a preprocessor output and its leading prefix and trailing suffix into StringWithSourceMap
28557
28748
  */
28558
- function get_replacement(filename, offset, get_location, original, processed, prefix, suffix) {
28749
+ function get_replacement(file_basename, offset, get_location, original, processed, prefix, suffix) {
28559
28750
  // Convert the unchanged prefix and suffix to StringWithSourcemap
28560
- const prefix_with_map = StringWithSourcemap.from_source(filename, prefix, get_location(offset));
28561
- const suffix_with_map = StringWithSourcemap.from_source(filename, suffix, get_location(offset + prefix.length + original.length));
28751
+ const prefix_with_map = StringWithSourcemap.from_source(file_basename, prefix, get_location(offset));
28752
+ const suffix_with_map = StringWithSourcemap.from_source(file_basename, suffix, get_location(offset + prefix.length + original.length));
28562
28753
  // Convert the preprocessed code and its sourcemap to a StringWithSourcemap
28563
28754
  let decoded_map;
28564
28755
  if (processed.map) {
@@ -28566,7 +28757,15 @@ function get_replacement(filename, offset, get_location, original, processed, pr
28566
28757
  if (typeof (decoded_map.mappings) === 'string') {
28567
28758
  decoded_map.mappings = decode(decoded_map.mappings);
28568
28759
  }
28569
- sourcemap_add_offset(decoded_map, get_location(offset + prefix.length));
28760
+ if (decoded_map._mappings && decoded_map.constructor.name === 'SourceMapGenerator') {
28761
+ // import decoded sourcemap from mozilla/source-map/SourceMapGenerator
28762
+ decoded_map = decoded_sourcemap_from_generator(decoded_map);
28763
+ }
28764
+ // offset only segments pointing at original component source
28765
+ const source_index = decoded_map.sources.indexOf(file_basename);
28766
+ if (source_index !== -1) {
28767
+ sourcemap_add_offset(decoded_map, get_location(offset + prefix.length), source_index);
28768
+ }
28570
28769
  }
28571
28770
  const processed_with_map = StringWithSourcemap.from_processed(processed.code, decoded_map);
28572
28771
  // Surround the processed code with the prefix and suffix, retaining valid sourcemappings
@@ -28576,6 +28775,8 @@ async function preprocess(source, preprocessor, options) {
28576
28775
  // @ts-ignore todo: doublecheck
28577
28776
  const filename = (options && options.filename) || preprocessor.filename; // legacy
28578
28777
  const dependencies = [];
28778
+ // preprocess source must be relative to itself or equal null
28779
+ const file_basename = filename == null ? null : get_file_basename(filename);
28579
28780
  const preprocessors = preprocessor
28580
28781
  ? Array.isArray(preprocessor) ? preprocessor : [preprocessor]
28581
28782
  : [];
@@ -28606,11 +28807,11 @@ async function preprocess(source, preprocessor, options) {
28606
28807
  }
28607
28808
  async function preprocess_tag_content(tag_name, preprocessor) {
28608
28809
  const get_location = getLocator(source);
28609
- const tag_regex = tag_name == 'style'
28810
+ const tag_regex = tag_name === 'style'
28610
28811
  ? /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi
28611
28812
  : /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi;
28612
- const res = await replace_async(filename, source, get_location, tag_regex, async (match, attributes = '', content = '', offset) => {
28613
- const no_change = () => StringWithSourcemap.from_source(filename, match, get_location(offset));
28813
+ const res = await replace_async(file_basename, source, get_location, tag_regex, async (match, attributes = '', content = '', offset) => {
28814
+ const no_change = () => StringWithSourcemap.from_source(file_basename, match, get_location(offset));
28614
28815
  if (!attributes && !content) {
28615
28816
  return no_change();
28616
28817
  }
@@ -28622,11 +28823,13 @@ async function preprocess(source, preprocessor, options) {
28622
28823
  attributes: parse_attributes(attributes),
28623
28824
  filename
28624
28825
  });
28625
- if (!processed)
28626
- return no_change();
28627
- if (processed.dependencies)
28826
+ if (processed && processed.dependencies) {
28628
28827
  dependencies.push(...processed.dependencies);
28629
- return get_replacement(filename, offset, get_location, content, processed, `<${tag_name}${attributes}>`, `</${tag_name}>`);
28828
+ }
28829
+ if (!processed || !processed.map && processed.code === content) {
28830
+ return no_change();
28831
+ }
28832
+ return get_replacement(file_basename, offset, get_location, content, processed, `<${tag_name}${attributes}>`, `</${tag_name}>`);
28630
28833
  });
28631
28834
  source = res.string;
28632
28835
  sourcemap_list.unshift(res.map);
@@ -28638,7 +28841,7 @@ async function preprocess(source, preprocessor, options) {
28638
28841
  await preprocess_tag_content('style', fn);
28639
28842
  }
28640
28843
  // Combine all the source maps for each preprocessor function into one
28641
- const map = combine_sourcemaps(filename, sourcemap_list);
28844
+ const map = combine_sourcemaps(file_basename, sourcemap_list);
28642
28845
  return {
28643
28846
  // TODO return separated output, in future version where svelte.compile supports it:
28644
28847
  // style: { code: styleCode, map: styleMap },
@@ -28653,7 +28856,7 @@ async function preprocess(source, preprocessor, options) {
28653
28856
  };
28654
28857
  }
28655
28858
 
28656
- const VERSION = '3.30.0';
28859
+ const VERSION = '3.31.2';
28657
28860
 
28658
28861
  export { VERSION, compile, parse$3 as parse, preprocess, walk };
28659
28862
  //# sourceMappingURL=compiler.mjs.map