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.js CHANGED
@@ -15924,6 +15924,7 @@
15924
15924
  class Block$1 {
15925
15925
  constructor(options) {
15926
15926
  this.dependencies = new Set();
15927
+ this.binding_group_initialised = new Set();
15927
15928
  this.event_listeners = [];
15928
15929
  this.variables = new Map();
15929
15930
  this.has_update_method = false;
@@ -16998,8 +16999,9 @@
16998
16999
  ? '@outro_and_destroy_block'
16999
17000
  : '@destroy_block';
17000
17001
  if (this.dependencies.size) {
17002
+ this.block.maintain_context = true;
17001
17003
  this.updates.push(b `
17002
- const ${this.vars.each_block_value} = ${snippet};
17004
+ ${this.vars.each_block_value} = ${snippet};
17003
17005
  ${this.renderer.options.dev && b `@validate_each_argument(${this.vars.each_block_value});`}
17004
17006
 
17005
17007
  ${this.block.has_outros && b `@group_outros();`}
@@ -17749,10 +17751,18 @@
17749
17751
  }
17750
17752
  });
17751
17753
  if (binding.name === 'group') {
17754
+ const add_index_binding = (name) => {
17755
+ const each_block = parent.node.scope.get_owner(name);
17756
+ if (each_block.type === 'EachBlock') {
17757
+ each_block.has_index_binding = true;
17758
+ for (const dep of each_block.expression.contextual_dependencies) {
17759
+ add_index_binding(dep);
17760
+ }
17761
+ }
17762
+ };
17752
17763
  // for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index`
17753
17764
  for (const name of binding.expression.contextual_dependencies) {
17754
- const each_block = parent.node.scope.get_owner(name);
17755
- each_block.has_index_binding = true;
17765
+ add_index_binding(name);
17756
17766
  }
17757
17767
  }
17758
17768
  }
@@ -17820,9 +17830,9 @@
17820
17830
  switch (this.node.name) {
17821
17831
  case 'group':
17822
17832
  {
17823
- const { binding_group, is_context, contexts, index } = get_binding_group(parent.renderer, this.node, block);
17833
+ const { binding_group, is_context, contexts, index, keypath } = get_binding_group(parent.renderer, this.node, block);
17824
17834
  block.renderer.add_to_context('$$binding_groups');
17825
- if (is_context) {
17835
+ if (is_context && !block.binding_group_initialised.has(keypath)) {
17826
17836
  if (contexts.length > 1) {
17827
17837
  let binding_group = x `${block.renderer.reference('$$binding_groups')}[${index}]`;
17828
17838
  for (const name of contexts.slice(0, -1)) {
@@ -17831,6 +17841,7 @@
17831
17841
  }
17832
17842
  }
17833
17843
  block.chunks.init.push(b `${binding_group(true)} = [];`);
17844
+ block.binding_group_initialised.add(keypath);
17834
17845
  }
17835
17846
  block.chunks.hydrate.push(b `${binding_group(true)}.push(${parent.var});`);
17836
17847
  block.chunks.destroy.push(b `${binding_group(true)}.splice(${binding_group(true)}.indexOf(${parent.var}), 1);`);
@@ -17926,7 +17937,21 @@
17926
17937
  const { parts } = flatten_reference(value.raw_expression);
17927
17938
  let keypath = parts.join('.');
17928
17939
  const contexts = [];
17940
+ const contextual_dependencies = new Set();
17941
+ const { template_scope } = value.expression;
17942
+ const add_contextual_dependency = (dep) => {
17943
+ contextual_dependencies.add(dep);
17944
+ const owner = template_scope.get_owner(dep);
17945
+ if (owner.type === 'EachBlock') {
17946
+ for (const dep of owner.expression.contextual_dependencies) {
17947
+ add_contextual_dependency(dep);
17948
+ }
17949
+ }
17950
+ };
17929
17951
  for (const dep of value.expression.contextual_dependencies) {
17952
+ add_contextual_dependency(dep);
17953
+ }
17954
+ for (const dep of contextual_dependencies) {
17930
17955
  const context = block.bindings.get(dep);
17931
17956
  let key;
17932
17957
  let name;
@@ -17967,7 +17992,8 @@
17967
17992
  },
17968
17993
  is_context: contexts.length > 0,
17969
17994
  contexts,
17970
- index
17995
+ index,
17996
+ keypath
17971
17997
  });
17972
17998
  }
17973
17999
  return renderer.binding_groups.get(keypath);
@@ -18038,11 +18064,30 @@
18038
18064
  return x `this.${name}`;
18039
18065
  }
18040
18066
 
18067
+ const reserved_keywords = new Set(['$$props', '$$restProps', '$$slots']);
18068
+ function is_reserved_keyword(name) {
18069
+ return reserved_keywords.has(name);
18070
+ }
18071
+
18072
+ function is_contextual(component, scope, name) {
18073
+ if (is_reserved_keyword(name))
18074
+ return true;
18075
+ // if it's a name below root scope, it's contextual
18076
+ if (!scope.is_top_level(name))
18077
+ return true;
18078
+ const variable = component.var_lookup.get(name);
18079
+ // hoistables, module declarations, and imports are non-contextual
18080
+ if (!variable || variable.hoistable)
18081
+ return false;
18082
+ // assume contextual
18083
+ return true;
18084
+ }
18085
+
18041
18086
  function add_actions(block, target, actions) {
18042
18087
  actions.forEach(action => add_action(block, target, action));
18043
18088
  }
18044
18089
  function add_action(block, target, action) {
18045
- const { expression } = action;
18090
+ const { expression, template_scope } = action;
18046
18091
  let snippet;
18047
18092
  let dependencies;
18048
18093
  if (expression) {
@@ -18052,9 +18097,12 @@
18052
18097
  const id = block.get_unique_name(`${action.name.replace(/[^a-zA-Z0-9_$]/g, '_')}_action`);
18053
18098
  block.add_variable(id);
18054
18099
  const [obj, ...properties] = action.name.split('.');
18055
- const fn = block.renderer.reference(obj);
18100
+ const fn = is_contextual(action.component, template_scope, obj)
18101
+ ? block.renderer.reference(obj)
18102
+ : obj;
18056
18103
  if (properties.length) {
18057
- block.event_listeners.push(x `@action_destroyer(${id} = ${fn}.${properties.join('.')}(${target}, ${snippet}))`);
18104
+ const member_expression = properties.reduce((lhs, rhs) => x `${lhs}.${rhs}`, fn);
18105
+ block.event_listeners.push(x `@action_destroyer(${id} = ${member_expression}(${target}, ${snippet}))`);
18058
18106
  }
18059
18107
  else {
18060
18108
  block.event_listeners.push(x `@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))`);
@@ -18215,11 +18263,6 @@
18215
18263
  return analyze(expression);
18216
18264
  }
18217
18265
 
18218
- const reserved_keywords = new Set(['$$props', '$$restProps', '$$slots']);
18219
- function is_reserved_keyword(name) {
18220
- return reserved_keywords.has(name);
18221
- }
18222
-
18223
18266
  function is_dynamic$1(variable) {
18224
18267
  if (variable) {
18225
18268
  if (variable.mutated || variable.reassigned)
@@ -18285,7 +18328,7 @@
18285
18328
  if (main_execution_context && !variable.subscribable && variable.name[0] !== '$') {
18286
18329
  return node;
18287
18330
  }
18288
- return renderer.invalidate(variable.name, undefined, main_execution_context);
18331
+ return renderer_invalidate(renderer, variable.name, undefined, main_execution_context);
18289
18332
  }
18290
18333
  if (!head) {
18291
18334
  return node;
@@ -18322,6 +18365,55 @@
18322
18365
  }
18323
18366
  return invalidate;
18324
18367
  }
18368
+ function renderer_invalidate(renderer, name, value, main_execution_context = false) {
18369
+ const variable = renderer.component.var_lookup.get(name);
18370
+ if (variable && (variable.subscribable && (variable.reassigned || variable.export_name))) {
18371
+ if (main_execution_context) {
18372
+ return x `${`$$subscribe_${name}`}(${value || name})`;
18373
+ }
18374
+ else {
18375
+ const member = renderer.context_lookup.get(name);
18376
+ return x `${`$$subscribe_${name}`}($$invalidate(${member.index}, ${value || name}))`;
18377
+ }
18378
+ }
18379
+ if (name[0] === '$' && name[1] !== '$') {
18380
+ return x `${name.slice(1)}.set(${value || name})`;
18381
+ }
18382
+ if (variable && (variable.module || (!variable.referenced &&
18383
+ !variable.is_reactive_dependency &&
18384
+ !variable.export_name &&
18385
+ !name.startsWith('$$')))) {
18386
+ return value || name;
18387
+ }
18388
+ if (value) {
18389
+ if (main_execution_context) {
18390
+ return x `${value}`;
18391
+ }
18392
+ else {
18393
+ const member = renderer.context_lookup.get(name);
18394
+ return x `$$invalidate(${member.index}, ${value})`;
18395
+ }
18396
+ }
18397
+ if (main_execution_context)
18398
+ return;
18399
+ // if this is a reactive declaration, invalidate dependencies recursively
18400
+ const deps = new Set([name]);
18401
+ deps.forEach(name => {
18402
+ const reactive_declarations = renderer.component.reactive_declarations.filter(x => x.assignees.has(name));
18403
+ reactive_declarations.forEach(declaration => {
18404
+ declaration.dependencies.forEach(name => {
18405
+ deps.add(name);
18406
+ });
18407
+ });
18408
+ });
18409
+ // TODO ideally globals etc wouldn't be here in the first place
18410
+ const filtered = Array.from(deps).filter(n => renderer.context_lookup.has(n));
18411
+ if (!filtered.length)
18412
+ return null;
18413
+ return filtered
18414
+ .map(n => x `$$invalidate(${renderer.context_lookup.get(n).index}, ${n})`)
18415
+ .reduce((lhs, rhs) => x `${lhs}, ${rhs}`);
18416
+ }
18325
18417
 
18326
18418
  class Expression {
18327
18419
  constructor(component, owner, template_scope, info, lazy) {
@@ -18648,19 +18740,6 @@
18648
18740
  }
18649
18741
  return 'func';
18650
18742
  }
18651
- function is_contextual(component, scope, name) {
18652
- if (is_reserved_keyword(name))
18653
- return true;
18654
- // if it's a name below root scope, it's contextual
18655
- if (!scope.is_top_level(name))
18656
- return true;
18657
- const variable = component.var_lookup.get(name);
18658
- // hoistables, module declarations, and imports are non-contextual
18659
- if (!variable || variable.hoistable)
18660
- return false;
18661
- // assume contextual
18662
- return true;
18663
- }
18664
18743
 
18665
18744
  class Action extends Node$1 {
18666
18745
  constructor(component, parent, scope, info) {
@@ -18672,6 +18751,7 @@
18672
18751
  this.expression = info.expression
18673
18752
  ? new Expression(component, this, scope, info.expression)
18674
18753
  : null;
18754
+ this.template_scope = scope;
18675
18755
  this.uses_context = this.expression && this.expression.uses_context;
18676
18756
  }
18677
18757
  }
@@ -19527,7 +19607,20 @@
19527
19607
  ${stop_animation}();
19528
19608
  ${outro && b `@add_transform(${this.var}, ${rect});`}
19529
19609
  `);
19530
- const params = this.node.animation.expression ? this.node.animation.expression.manipulate(block) : x `{}`;
19610
+ let params;
19611
+ if (this.node.animation.expression) {
19612
+ params = this.node.animation.expression.manipulate(block);
19613
+ if (this.node.animation.expression.dynamic_dependencies().length) {
19614
+ // if `params` is dynamic, calculate params ahead of time in the `.r()` method
19615
+ const params_var = block.get_unique_name('params');
19616
+ block.add_variable(params_var);
19617
+ block.chunks.measure.push(b `${params_var} = ${params};`);
19618
+ params = params_var;
19619
+ }
19620
+ }
19621
+ else {
19622
+ params = x `{}`;
19623
+ }
19531
19624
  const name = this.renderer.reference(this.node.animation.name);
19532
19625
  block.chunks.animate.push(b `
19533
19626
  ${stop_animation}();
@@ -19957,7 +20050,7 @@
19957
20050
  ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
19958
20051
  ${name}.c();
19959
20052
  } else {
19960
- ${name}.p(#ctx, #dirty);
20053
+ ${dynamic && b `${name}.p(#ctx, #dirty);`}
19961
20054
  }
19962
20055
  ${has_transitions && b `@transition_in(${name}, 1);`}
19963
20056
  ${name}.m(${update_mount_node}, ${anchor});
@@ -19979,10 +20072,12 @@
19979
20072
  ${name} = null;
19980
20073
  }
19981
20074
  `;
20075
+ block.chunks.update.push(b `
20076
+ let ${previous_block_index} = ${current_block_type_index};
20077
+ ${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
20078
+ `);
19982
20079
  if (dynamic) {
19983
20080
  block.chunks.update.push(b `
19984
- let ${previous_block_index} = ${current_block_type_index};
19985
- ${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
19986
20081
  if (${current_block_type_index} === ${previous_block_index}) {
19987
20082
  ${if_current_block_type_index(b `${if_blocks}[${current_block_type_index}].p(#ctx, #dirty);`)}
19988
20083
  } else {
@@ -19992,8 +20087,6 @@
19992
20087
  }
19993
20088
  else {
19994
20089
  block.chunks.update.push(b `
19995
- let ${previous_block_index} = ${current_block_type_index};
19996
- ${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
19997
20090
  if (${current_block_type_index} !== ${previous_block_index}) {
19998
20091
  ${change_block}
19999
20092
  }
@@ -20870,11 +20963,13 @@
20870
20963
  add_actions(block, '@_window', this.node.actions);
20871
20964
  add_event_handlers(block, '@_window', this.handlers);
20872
20965
  this.node.bindings.forEach(binding => {
20966
+ // TODO: what if it's a MemberExpression?
20967
+ const binding_name = binding.expression.node.name;
20873
20968
  // in dev mode, throw if read-only values are written to
20874
20969
  if (readonly.has(binding.name)) {
20875
- renderer.readonly.add(binding.expression.node.name);
20970
+ renderer.readonly.add(binding_name);
20876
20971
  }
20877
- bindings[binding.name] = binding.expression.node.name;
20972
+ bindings[binding.name] = binding_name;
20878
20973
  // bind:online is a special case, we need to listen for two separate events
20879
20974
  if (binding.name === 'online')
20880
20975
  return;
@@ -20883,7 +20978,7 @@
20883
20978
  if (!events[associated_event])
20884
20979
  events[associated_event] = [];
20885
20980
  events[associated_event].push({
20886
- name: binding.expression.node.name,
20981
+ name: binding_name,
20887
20982
  value: property
20888
20983
  });
20889
20984
  });
@@ -21192,42 +21287,7 @@
21192
21287
  return member;
21193
21288
  }
21194
21289
  invalidate(name, value, main_execution_context = false) {
21195
- const variable = this.component.var_lookup.get(name);
21196
- const member = this.context_lookup.get(name);
21197
- if (variable && (variable.subscribable && (variable.reassigned || variable.export_name))) {
21198
- return main_execution_context
21199
- ? x `${`$$subscribe_${name}`}(${value || name})`
21200
- : x `${`$$subscribe_${name}`}($$invalidate(${member.index}, ${value || name}))`;
21201
- }
21202
- if (name[0] === '$' && name[1] !== '$') {
21203
- return x `${name.slice(1)}.set(${value || name})`;
21204
- }
21205
- if (variable && (variable.module || (!variable.referenced &&
21206
- !variable.is_reactive_dependency &&
21207
- !variable.export_name &&
21208
- !name.startsWith('$$')))) {
21209
- return value || name;
21210
- }
21211
- if (value) {
21212
- return x `$$invalidate(${member.index}, ${value})`;
21213
- }
21214
- // if this is a reactive declaration, invalidate dependencies recursively
21215
- const deps = new Set([name]);
21216
- deps.forEach(name => {
21217
- const reactive_declarations = this.component.reactive_declarations.filter(x => x.assignees.has(name));
21218
- reactive_declarations.forEach(declaration => {
21219
- declaration.dependencies.forEach(name => {
21220
- deps.add(name);
21221
- });
21222
- });
21223
- });
21224
- // TODO ideally globals etc wouldn't be here in the first place
21225
- const filtered = Array.from(deps).filter(n => this.context_lookup.has(n));
21226
- if (!filtered.length)
21227
- return null;
21228
- return filtered
21229
- .map(n => x `$$invalidate(${this.context_lookup.get(n).index}, ${n})`)
21230
- .reduce((lhs, rhs) => x `${lhs}, ${rhs}`);
21290
+ return renderer_invalidate(this, name, value, main_execution_context);
21231
21291
  }
21232
21292
  dirty(names, is_reactive_declaration = false) {
21233
21293
  const renderer = this;
@@ -22083,23 +22143,22 @@
22083
22143
  return s.length - s.lastIndexOf('\n') - 1;
22084
22144
  }
22085
22145
  // mutate map in-place
22086
- function sourcemap_add_offset(map, offset) {
22146
+ function sourcemap_add_offset(map, offset, source_index) {
22087
22147
  if (map.mappings.length == 0)
22088
- return map;
22089
- // shift columns in first line
22090
- const segment_list = map.mappings[0];
22091
- for (let segment = 0; segment < segment_list.length; segment++) {
22092
- const seg = segment_list[segment];
22093
- if (seg[3])
22094
- seg[3] += offset.column;
22095
- }
22096
- // shift lines
22148
+ return;
22097
22149
  for (let line = 0; line < map.mappings.length; line++) {
22098
22150
  const segment_list = map.mappings[line];
22099
22151
  for (let segment = 0; segment < segment_list.length; segment++) {
22100
22152
  const seg = segment_list[segment];
22101
- if (seg[2])
22153
+ // shift only segments that belong to component source file
22154
+ if (seg[1] === source_index) { // also ensures that seg.length >= 4
22155
+ // shift column if it points at the first line
22156
+ if (seg[2] === 0) {
22157
+ seg[3] += offset.column;
22158
+ }
22159
+ // shift line
22102
22160
  seg[2] += offset.line;
22161
+ }
22103
22162
  }
22104
22163
  }
22105
22164
  }
@@ -22164,6 +22223,8 @@
22164
22223
  this.map = other.map;
22165
22224
  return this;
22166
22225
  }
22226
+ // compute last line length before mutating
22227
+ const column_offset = last_line_length(this.string);
22167
22228
  this.string += other.string;
22168
22229
  const m1 = this.map;
22169
22230
  const m2 = other.map;
@@ -22182,9 +22243,9 @@
22182
22243
  const segment_list = m2.mappings[line];
22183
22244
  for (let segment = 0; segment < segment_list.length; segment++) {
22184
22245
  const seg = segment_list[segment];
22185
- if (seg[1])
22246
+ if (seg[1] >= 0)
22186
22247
  seg[1] = new_source_idx[seg[1]];
22187
- if (seg[4])
22248
+ if (seg[4] >= 0)
22188
22249
  seg[4] = new_name_idx[seg[4]];
22189
22250
  }
22190
22251
  }
@@ -22194,7 +22255,7 @@
22194
22255
  const segment_list = m2.mappings[line];
22195
22256
  for (let segment = 0; segment < segment_list.length; segment++) {
22196
22257
  const seg = segment_list[segment];
22197
- if (seg[1])
22258
+ if (seg[1] >= 0)
22198
22259
  seg[1] = new_source_idx[seg[1]];
22199
22260
  }
22200
22261
  }
@@ -22204,7 +22265,7 @@
22204
22265
  const segment_list = m2.mappings[line];
22205
22266
  for (let segment = 0; segment < segment_list.length; segment++) {
22206
22267
  const seg = segment_list[segment];
22207
- if (seg[4])
22268
+ if (seg[4] >= 0)
22208
22269
  seg[4] = new_name_idx[seg[4]];
22209
22270
  }
22210
22271
  }
@@ -22214,7 +22275,6 @@
22214
22275
  // 1. last line of first map
22215
22276
  // 2. first line of second map
22216
22277
  // columns of 2 must be shifted
22217
- const column_offset = last_line_length(this.string);
22218
22278
  if (m2.mappings.length > 0 && column_offset > 0) {
22219
22279
  const first_line = m2.mappings[0];
22220
22280
  for (let i = 0; i < first_line.length; i++) {
@@ -22228,13 +22288,21 @@
22228
22288
  return this;
22229
22289
  }
22230
22290
  static from_processed(string, map) {
22231
- if (map)
22291
+ const line_count = string.split('\n').length;
22292
+ if (map) {
22293
+ // ensure that count of source map mappings lines
22294
+ // is equal to count of generated code lines
22295
+ // (some tools may produce less)
22296
+ const missing_lines = line_count - map.mappings.length;
22297
+ for (let i = 0; i < missing_lines; i++) {
22298
+ map.mappings.push([]);
22299
+ }
22232
22300
  return new StringWithSourcemap(string, map);
22301
+ }
22233
22302
  if (string == '')
22234
22303
  return new StringWithSourcemap();
22235
22304
  map = { version: 3, names: [], sources: [], mappings: [] };
22236
22305
  // add empty SourceMapSegment[] for every line
22237
- const line_count = (string.match(/\n/g) || '').length;
22238
22306
  for (let i = 0; i < line_count; i++)
22239
22307
  map.mappings.push([]);
22240
22308
  return new StringWithSourcemap(string, map);
@@ -22653,6 +22721,8 @@
22653
22721
  };
22654
22722
  body.push(b `
22655
22723
  function ${definition}(${args}) {
22724
+ ${injected.map(name => b `let ${name};`)}
22725
+
22656
22726
  ${rest}
22657
22727
 
22658
22728
  ${reactive_store_declarations}
@@ -22679,8 +22749,6 @@
22679
22749
 
22680
22750
  ${inject_state && b `$$self.$inject_state = ${inject_state};`}
22681
22751
 
22682
- ${injected.map(name => b `let ${name};`)}
22683
-
22684
22752
  ${ /* before reactive declarations */props_inject}
22685
22753
 
22686
22754
  ${reactive_declarations.length > 0 && b `
@@ -23122,7 +23190,7 @@
23122
23190
  }
23123
23191
 
23124
23192
  function Head (node, renderer, options) {
23125
- const head_options = Object.assign({}, options, { head_id: node.id });
23193
+ const head_options = Object.assign(Object.assign({}, options), { head_id: node.id });
23126
23194
  renderer.push();
23127
23195
  renderer.render(node.children, head_options);
23128
23196
  const result = renderer.pop();
@@ -23382,21 +23450,71 @@
23382
23450
  const uses_slots = component.var_lookup.has('$$slots');
23383
23451
  const slots = uses_slots ? b `let $$slots = @compute_slots(#slots);` : null;
23384
23452
  const reactive_stores = component.vars.filter(variable => variable.name[0] === '$' && variable.name[1] !== '$');
23385
- const reactive_store_values = reactive_stores
23453
+ const reactive_store_subscriptions = reactive_stores
23454
+ .filter(store => {
23455
+ const variable = component.var_lookup.get(store.name.slice(1));
23456
+ return !variable || variable.hoistable;
23457
+ })
23458
+ .map(({ name }) => {
23459
+ const store_name = name.slice(1);
23460
+ return b `
23461
+ ${component.compile_options.dev && b `@validate_store(${store_name}, '${store_name}');`}
23462
+ ${`$$unsubscribe_${store_name}`} = @subscribe(${store_name}, #value => ${name} = #value)
23463
+ ${store_name}.subscribe($$value => ${name} = $$value);
23464
+ `;
23465
+ });
23466
+ const reactive_store_unsubscriptions = reactive_stores.map(({ name }) => b `${`$$unsubscribe_${name.slice(1)}`}()`);
23467
+ const reactive_store_declarations = reactive_stores
23386
23468
  .map(({ name }) => {
23387
23469
  const store_name = name.slice(1);
23388
23470
  const store = component.var_lookup.get(store_name);
23389
- if (store && store.hoistable)
23390
- return null;
23391
- const assignment = b `${name} = @get_store_value(${store_name});`;
23392
- return component.compile_options.dev
23393
- ? b `@validate_store(${store_name}, '${store_name}'); ${assignment}`
23394
- : assignment;
23395
- })
23396
- .filter(Boolean);
23397
- component.rewrite_props(({ name }) => {
23471
+ if (store && store.reassigned) {
23472
+ const unsubscribe = `$$unsubscribe_${store_name}`;
23473
+ const subscribe = `$$subscribe_${store_name}`;
23474
+ return b `let ${name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${store_name}, $$value => ${name} = $$value), ${store_name})`;
23475
+ }
23476
+ return b `let ${name}, ${`$$unsubscribe_${store_name}`};`;
23477
+ });
23478
+ // instrument get/set store value
23479
+ if (component.ast.instance) {
23480
+ let scope = component.instance_scope;
23481
+ const map = component.instance_scope_map;
23482
+ walk(component.ast.instance.content, {
23483
+ enter(node) {
23484
+ if (map.has(node)) {
23485
+ scope = map.get(node);
23486
+ }
23487
+ },
23488
+ leave(node) {
23489
+ if (map.has(node)) {
23490
+ scope = scope.parent;
23491
+ }
23492
+ if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') {
23493
+ const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument;
23494
+ const names = new Set(extract_names(assignee));
23495
+ const to_invalidate = new Set();
23496
+ for (const name of names) {
23497
+ const variable = component.var_lookup.get(name);
23498
+ if (variable &&
23499
+ !variable.hoistable &&
23500
+ !variable.global &&
23501
+ !variable.module &&
23502
+ (variable.subscribable || variable.name[0] === '$')) {
23503
+ to_invalidate.add(variable.name);
23504
+ }
23505
+ }
23506
+ if (to_invalidate.size) {
23507
+ this.replace(invalidate({ component }, scope, node, to_invalidate, true));
23508
+ }
23509
+ }
23510
+ }
23511
+ });
23512
+ }
23513
+ component.rewrite_props(({ name, reassigned }) => {
23398
23514
  const value = `$${name}`;
23399
- let insert = b `${value} = @get_store_value(${name})`;
23515
+ let insert = reassigned
23516
+ ? b `${`$$subscribe_${name}`}()`
23517
+ : b `${`$$unsubscribe_${name}`} = @subscribe(${name}, #value => $${value} = #value)`;
23400
23518
  if (component.compile_options.dev) {
23401
23519
  insert = b `@validate_store(${name}, '${name}'); ${insert}`;
23402
23520
  }
@@ -23431,36 +23549,27 @@
23431
23549
  do {
23432
23550
  $$settled = true;
23433
23551
 
23434
- ${reactive_store_values}
23435
-
23436
- ${injected.map(name => b `let ${name};`)}
23437
-
23438
23552
  ${reactive_declarations}
23439
23553
 
23440
23554
  $$rendered = ${literal};
23441
23555
  } while (!$$settled);
23442
23556
 
23557
+ ${reactive_store_unsubscriptions}
23558
+
23443
23559
  return $$rendered;
23444
23560
  `
23445
23561
  : b `
23446
- ${reactive_store_values}
23447
-
23448
- ${injected.map(name => b `let ${name};`)}
23449
-
23450
23562
  ${reactive_declarations}
23451
23563
 
23564
+ ${reactive_store_unsubscriptions}
23565
+
23452
23566
  return ${literal};`;
23453
23567
  const blocks = [
23568
+ ...injected.map(name => b `let ${name};`),
23454
23569
  rest,
23455
23570
  slots,
23456
- ...reactive_stores.map(({ name }) => {
23457
- const store_name = name.slice(1);
23458
- const store = component.var_lookup.get(store_name);
23459
- if (store && store.hoistable) {
23460
- return b `let ${name} = @get_store_value(${store_name});`;
23461
- }
23462
- return b `let ${name};`;
23463
- }),
23571
+ ...reactive_store_declarations,
23572
+ ...reactive_store_subscriptions,
23464
23573
  instance_javascript,
23465
23574
  ...parent_bindings,
23466
23575
  css.code && b `$$result.css.add(#css);`,
@@ -25719,7 +25828,7 @@
25719
25828
  constructor(component, parent, scope, info) {
25720
25829
  super(component, parent, scope, info);
25721
25830
  this.handlers = [];
25722
- info.attributes.forEach(node => {
25831
+ info.attributes.forEach((node) => {
25723
25832
  if (node.type === 'EventHandler') {
25724
25833
  this.handlers.push(new EventHandler(component, this, scope, node));
25725
25834
  }
@@ -25928,15 +26037,19 @@
25928
26037
  }
25929
26038
  }
25930
26039
  const type = parent.get_static_attribute_value('type');
25931
- this.is_readonly = (dimensions.test(this.name) ||
25932
- (parent.is_media_node && parent.is_media_node() && read_only_media_attributes.has(this.name)) ||
25933
- (parent.name === 'input' && type === 'file') // TODO others?
25934
- );
26040
+ this.is_readonly =
26041
+ dimensions.test(this.name) ||
26042
+ (isElement(parent) &&
26043
+ ((parent.is_media_node() && read_only_media_attributes.has(this.name)) ||
26044
+ (parent.name === 'input' && type === 'file')) /* TODO others? */);
25935
26045
  }
25936
26046
  is_readonly_media_attribute() {
25937
26047
  return read_only_media_attributes.has(this.name);
25938
26048
  }
25939
26049
  }
26050
+ function isElement(node) {
26051
+ return !!node.is_media_node;
26052
+ }
25940
26053
 
25941
26054
  class Transition extends Node$1 {
25942
26055
  constructor(component, parent, scope, info) {
@@ -26079,7 +26192,7 @@
26079
26192
  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)$/;
26080
26193
  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(' ');
26081
26194
  const aria_attribute_set = new Set(aria_attributes);
26082
- 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(' ');
26195
+ 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(' ');
26083
26196
  const aria_role_set = new Set(aria_roles);
26084
26197
  const a11y_required_attributes = {
26085
26198
  a: ['href'],
@@ -26137,6 +26250,10 @@
26137
26250
  'touchend',
26138
26251
  'touchcancel'
26139
26252
  ]);
26253
+ const react_attributes = new Map([
26254
+ ['className', 'class'],
26255
+ ['htmlFor', 'for']
26256
+ ]);
26140
26257
  function get_namespace(parent, element, explicit_namespace) {
26141
26258
  const parent_element = parent.find_nearest(/^Element/);
26142
26259
  if (!parent_element) {
@@ -26433,6 +26550,12 @@
26433
26550
  message: 'The \'is\' attribute is not supported cross-browser and should be avoided'
26434
26551
  });
26435
26552
  }
26553
+ if (react_attributes.has(attribute.name)) {
26554
+ component.warn(attribute, {
26555
+ code: 'invalid-html-attribute',
26556
+ message: `'${attribute.name}' is not a valid HTML attribute. Did you mean '${react_attributes.get(attribute.name)}'?`
26557
+ });
26558
+ }
26436
26559
  attribute_map.set(attribute.name, attribute);
26437
26560
  });
26438
26561
  }
@@ -26965,7 +27088,7 @@
26965
27088
  class DebugTag$1 extends Node$1 {
26966
27089
  constructor(component, parent, scope, info) {
26967
27090
  super(component, parent, scope, info);
26968
- this.expressions = info.identifiers.map(node => {
27091
+ this.expressions = info.identifiers.map((node) => {
26969
27092
  return new Expression(component, parent, scope, node);
26970
27093
  });
26971
27094
  }
@@ -27194,7 +27317,7 @@
27194
27317
  }
27195
27318
 
27196
27319
  // This file is automatically generated
27197
- 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"]);
27320
+ 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"]);
27198
27321
 
27199
27322
  function is_used_as_reference(node, parent) {
27200
27323
  if (!isReference(node, parent)) {
@@ -27389,7 +27512,7 @@
27389
27512
  if (result) {
27390
27513
  const { compile_options, name } = this;
27391
27514
  const { format = 'esm' } = compile_options;
27392
- const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.30.0'}`;
27515
+ const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.31.2'}`;
27393
27516
  const program = { type: 'Program', body: result.js };
27394
27517
  walk(program, {
27395
27518
  enter: (node, parent, key) => {
@@ -28536,7 +28659,10 @@
28536
28659
  });
28537
28660
  return attrs;
28538
28661
  }
28539
- async function replace_async(filename, source, get_location, re, func) {
28662
+ function get_file_basename(filename) {
28663
+ return filename.split(/[/\\]/).pop();
28664
+ }
28665
+ async function replace_async(file_basename, source, get_location, re, func) {
28540
28666
  const replacements = [];
28541
28667
  source.replace(re, (...args) => {
28542
28668
  replacements.push(func(...args).then(res => ({
@@ -28550,21 +28676,86 @@
28550
28676
  let last_end = 0;
28551
28677
  for (const { offset, length, replacement } of await Promise.all(replacements)) {
28552
28678
  // content = unchanged source characters before the replaced segment
28553
- const content = StringWithSourcemap.from_source(filename, source.slice(last_end, offset), get_location(last_end));
28679
+ const content = StringWithSourcemap.from_source(file_basename, source.slice(last_end, offset), get_location(last_end));
28554
28680
  out.concat(content).concat(replacement);
28555
28681
  last_end = offset + length;
28556
28682
  }
28557
28683
  // final_content = unchanged source characters after last replaced segment
28558
- const final_content = StringWithSourcemap.from_source(filename, source.slice(last_end), get_location(last_end));
28684
+ const final_content = StringWithSourcemap.from_source(file_basename, source.slice(last_end), get_location(last_end));
28559
28685
  return out.concat(final_content);
28560
28686
  }
28687
+ /**
28688
+ * Import decoded sourcemap from mozilla/source-map/SourceMapGenerator
28689
+ * Forked from source-map/lib/source-map-generator.js
28690
+ * from methods _serializeMappings and toJSON.
28691
+ * We cannot use source-map.d.ts types, because we access hidden properties.
28692
+ */
28693
+ function decoded_sourcemap_from_generator(generator) {
28694
+ let previous_generated_line = 1;
28695
+ const converted_mappings = [[]];
28696
+ let result_line;
28697
+ let result_segment;
28698
+ let mapping;
28699
+ const source_idx = generator._sources.toArray()
28700
+ .reduce((acc, val, idx) => (acc[val] = idx, acc), {});
28701
+ const name_idx = generator._names.toArray()
28702
+ .reduce((acc, val, idx) => (acc[val] = idx, acc), {});
28703
+ const mappings = generator._mappings.toArray();
28704
+ result_line = converted_mappings[0];
28705
+ for (let i = 0, len = mappings.length; i < len; i++) {
28706
+ mapping = mappings[i];
28707
+ if (mapping.generatedLine > previous_generated_line) {
28708
+ while (mapping.generatedLine > previous_generated_line) {
28709
+ converted_mappings.push([]);
28710
+ previous_generated_line++;
28711
+ }
28712
+ result_line = converted_mappings[mapping.generatedLine - 1]; // line is one-based
28713
+ }
28714
+ else if (i > 0) {
28715
+ const previous_mapping = mappings[i - 1];
28716
+ if (
28717
+ // sorted by selectivity
28718
+ mapping.generatedColumn === previous_mapping.generatedColumn &&
28719
+ mapping.originalColumn === previous_mapping.originalColumn &&
28720
+ mapping.name === previous_mapping.name &&
28721
+ mapping.generatedLine === previous_mapping.generatedLine &&
28722
+ mapping.originalLine === previous_mapping.originalLine &&
28723
+ mapping.source === previous_mapping.source) {
28724
+ continue;
28725
+ }
28726
+ }
28727
+ result_line.push([mapping.generatedColumn]);
28728
+ result_segment = result_line[result_line.length - 1];
28729
+ if (mapping.source != null) {
28730
+ result_segment.push(...[
28731
+ source_idx[mapping.source],
28732
+ mapping.originalLine - 1,
28733
+ mapping.originalColumn
28734
+ ]);
28735
+ if (mapping.name != null) {
28736
+ result_segment.push(name_idx[mapping.name]);
28737
+ }
28738
+ }
28739
+ }
28740
+ const map = {
28741
+ version: generator._version,
28742
+ sources: generator._sources.toArray(),
28743
+ names: generator._names.toArray(),
28744
+ mappings: converted_mappings
28745
+ };
28746
+ if (generator._file != null) {
28747
+ map.file = generator._file;
28748
+ }
28749
+ // not needed: map.sourcesContent and map.sourceRoot
28750
+ return map;
28751
+ }
28561
28752
  /**
28562
28753
  * Convert a preprocessor output and its leading prefix and trailing suffix into StringWithSourceMap
28563
28754
  */
28564
- function get_replacement(filename, offset, get_location, original, processed, prefix, suffix) {
28755
+ function get_replacement(file_basename, offset, get_location, original, processed, prefix, suffix) {
28565
28756
  // Convert the unchanged prefix and suffix to StringWithSourcemap
28566
- const prefix_with_map = StringWithSourcemap.from_source(filename, prefix, get_location(offset));
28567
- const suffix_with_map = StringWithSourcemap.from_source(filename, suffix, get_location(offset + prefix.length + original.length));
28757
+ const prefix_with_map = StringWithSourcemap.from_source(file_basename, prefix, get_location(offset));
28758
+ const suffix_with_map = StringWithSourcemap.from_source(file_basename, suffix, get_location(offset + prefix.length + original.length));
28568
28759
  // Convert the preprocessed code and its sourcemap to a StringWithSourcemap
28569
28760
  let decoded_map;
28570
28761
  if (processed.map) {
@@ -28572,7 +28763,15 @@
28572
28763
  if (typeof (decoded_map.mappings) === 'string') {
28573
28764
  decoded_map.mappings = decode(decoded_map.mappings);
28574
28765
  }
28575
- sourcemap_add_offset(decoded_map, get_location(offset + prefix.length));
28766
+ if (decoded_map._mappings && decoded_map.constructor.name === 'SourceMapGenerator') {
28767
+ // import decoded sourcemap from mozilla/source-map/SourceMapGenerator
28768
+ decoded_map = decoded_sourcemap_from_generator(decoded_map);
28769
+ }
28770
+ // offset only segments pointing at original component source
28771
+ const source_index = decoded_map.sources.indexOf(file_basename);
28772
+ if (source_index !== -1) {
28773
+ sourcemap_add_offset(decoded_map, get_location(offset + prefix.length), source_index);
28774
+ }
28576
28775
  }
28577
28776
  const processed_with_map = StringWithSourcemap.from_processed(processed.code, decoded_map);
28578
28777
  // Surround the processed code with the prefix and suffix, retaining valid sourcemappings
@@ -28582,6 +28781,8 @@
28582
28781
  // @ts-ignore todo: doublecheck
28583
28782
  const filename = (options && options.filename) || preprocessor.filename; // legacy
28584
28783
  const dependencies = [];
28784
+ // preprocess source must be relative to itself or equal null
28785
+ const file_basename = filename == null ? null : get_file_basename(filename);
28585
28786
  const preprocessors = preprocessor
28586
28787
  ? Array.isArray(preprocessor) ? preprocessor : [preprocessor]
28587
28788
  : [];
@@ -28612,11 +28813,11 @@
28612
28813
  }
28613
28814
  async function preprocess_tag_content(tag_name, preprocessor) {
28614
28815
  const get_location = getLocator(source);
28615
- const tag_regex = tag_name == 'style'
28816
+ const tag_regex = tag_name === 'style'
28616
28817
  ? /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi
28617
28818
  : /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi;
28618
- const res = await replace_async(filename, source, get_location, tag_regex, async (match, attributes = '', content = '', offset) => {
28619
- const no_change = () => StringWithSourcemap.from_source(filename, match, get_location(offset));
28819
+ const res = await replace_async(file_basename, source, get_location, tag_regex, async (match, attributes = '', content = '', offset) => {
28820
+ const no_change = () => StringWithSourcemap.from_source(file_basename, match, get_location(offset));
28620
28821
  if (!attributes && !content) {
28621
28822
  return no_change();
28622
28823
  }
@@ -28628,11 +28829,13 @@
28628
28829
  attributes: parse_attributes(attributes),
28629
28830
  filename
28630
28831
  });
28631
- if (!processed)
28632
- return no_change();
28633
- if (processed.dependencies)
28832
+ if (processed && processed.dependencies) {
28634
28833
  dependencies.push(...processed.dependencies);
28635
- return get_replacement(filename, offset, get_location, content, processed, `<${tag_name}${attributes}>`, `</${tag_name}>`);
28834
+ }
28835
+ if (!processed || !processed.map && processed.code === content) {
28836
+ return no_change();
28837
+ }
28838
+ return get_replacement(file_basename, offset, get_location, content, processed, `<${tag_name}${attributes}>`, `</${tag_name}>`);
28636
28839
  });
28637
28840
  source = res.string;
28638
28841
  sourcemap_list.unshift(res.map);
@@ -28644,7 +28847,7 @@
28644
28847
  await preprocess_tag_content('style', fn);
28645
28848
  }
28646
28849
  // Combine all the source maps for each preprocessor function into one
28647
- const map = combine_sourcemaps(filename, sourcemap_list);
28850
+ const map = combine_sourcemaps(file_basename, sourcemap_list);
28648
28851
  return {
28649
28852
  // TODO return separated output, in future version where svelte.compile supports it:
28650
28853
  // style: { code: styleCode, map: styleMap },
@@ -28659,7 +28862,7 @@
28659
28862
  };
28660
28863
  }
28661
28864
 
28662
- const VERSION = '3.30.0';
28865
+ const VERSION = '3.31.2';
28663
28866
 
28664
28867
  exports.VERSION = VERSION;
28665
28868
  exports.compile = compile;