svelte 3.43.1 → 3.44.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Svelte changelog
2
2
 
3
+ ## 3.44.2
4
+
5
+ * Fix overly restrictive preprocessor types ([#6904](https://github.com/sveltejs/svelte/pull/6904))
6
+ * More specific typing for crossfade function - returns a tuple, not an array ([#6926](https://github.com/sveltejs/svelte/issues/6926))
7
+ * Add `URLSearchParams` as a known global ([#6938](https://github.com/sveltejs/svelte/pull/6938))
8
+ * Add `types` field to `exports` map ([#6939](https://github.com/sveltejs/svelte/issues/6939))
9
+
10
+ ## 3.44.1
11
+
12
+ * Fix code generation when a multi-line `return` statement contains comments ([code-red#36](https://github.com/Rich-Harris/code-red/issues/36))
13
+ * Fix code generation when `for`/`if`/`while` statements have empty bodies ([#6884](https://github.com/sveltejs/svelte/issues/6884))
14
+
15
+ ## 3.44.0
16
+
17
+ * Add `enableSourcemap` compiler option ([#6835](https://github.com/sveltejs/svelte/pull/6835))
18
+
19
+ ## 3.43.2
20
+
21
+ * Fix regression where user-specified `import`s were not rewritten according to the `sveltePath` option ([#6834](https://github.com/sveltejs/svelte/issues/6834))
22
+
3
23
  ## 3.43.1
4
24
 
5
25
  * Prevent a rejecting promise used in `{#await}` during SSR from appearing as an unhandled rejection ([#6789](https://github.com/sveltejs/svelte/issues/6789))
package/README.md CHANGED
@@ -64,7 +64,7 @@ npm run test -- -g transition
64
64
 
65
65
  ## svelte.dev
66
66
 
67
- The source code for https://svelte.dev, including all the documentation, lives in the [site](site) directory. The site is built with [Sapper](https://sapper.svelte.dev).
67
+ The source code for https://svelte.dev, including all the documentation, lives in the [site](site) directory. The site is built with [SvelteKit](https://kit.svelte.dev).
68
68
 
69
69
  ### Is svelte.dev down?
70
70
 
package/compiler.js CHANGED
@@ -6498,7 +6498,7 @@
6498
6498
  }),
6499
6499
 
6500
6500
  EmptyStatement(node, state) {
6501
- return [];
6501
+ return [c(';')];
6502
6502
  },
6503
6503
 
6504
6504
  ParenthesizedExpression(node, state) {
@@ -6604,10 +6604,11 @@
6604
6604
 
6605
6605
  ReturnStatement(node, state) {
6606
6606
  if (node.argument) {
6607
+ const contains_comment = node.argument.leadingComments && node.argument.leadingComments.some((/** @type import('../utils/comments.js').CommentWithLocation */ comment) => comment.has_trailing_newline);
6607
6608
  return [
6608
- c('return '),
6609
+ c(contains_comment ? 'return (' : 'return '),
6609
6610
  ...handle(node.argument, state),
6610
- c(';')
6611
+ c(contains_comment ? ');' : ';')
6611
6612
  ];
6612
6613
  } else {
6613
6614
  return [c('return;')];
@@ -7961,7 +7962,7 @@
7961
7962
 
7962
7963
  const { enter, leave } = get_comment_handlers(comments, raw);
7963
7964
 
7964
- walk(node, {
7965
+ return walk(node, {
7965
7966
  enter,
7966
7967
 
7967
7968
  /** @param {any} node */
@@ -8063,7 +8064,6 @@
8063
8064
  node.update = node.update === EMPTY ? null : node.update;
8064
8065
  }
8065
8066
 
8066
- // @ts-ignore
8067
8067
  leave(node);
8068
8068
  }
8069
8069
  });
@@ -8082,11 +8082,11 @@
8082
8082
  const comments = [];
8083
8083
 
8084
8084
  try {
8085
- const ast = /** @type {any} */ (
8085
+ let ast = /** @type {any} */ (
8086
8086
  parse(str, acorn_opts(comments, str))
8087
8087
  );
8088
8088
 
8089
- inject(str, ast, values, comments);
8089
+ ast = inject(str, ast, values, comments);
8090
8090
 
8091
8091
  return ast.body;
8092
8092
  } catch (err) {
@@ -8107,7 +8107,7 @@
8107
8107
  const comments = [];
8108
8108
 
8109
8109
  try {
8110
- const expression =
8110
+ let expression =
8111
8111
  /** @type {Expression & { start: Number, end: number }} */ (
8112
8112
  parseExpressionAt(str, 0, acorn_opts(comments, str))
8113
8113
  );
@@ -8116,7 +8116,9 @@
8116
8116
  throw new Error(`Unexpected token '${match[0]}'`);
8117
8117
  }
8118
8118
 
8119
- inject(str, expression, values, comments);
8119
+ expression = /** @type {Expression & { start: Number, end: number }} */ (
8120
+ inject(str, expression, values, comments)
8121
+ );
8120
8122
 
8121
8123
  return expression;
8122
8124
  } catch (err) {
@@ -8137,11 +8139,11 @@
8137
8139
  const comments = [];
8138
8140
 
8139
8141
  try {
8140
- const expression = /** @type {any} */ (
8142
+ let expression = /** @type {any} */ (
8141
8143
  parseExpressionAt(str, 0, acorn_opts(comments, str))
8142
8144
  );
8143
8145
 
8144
- inject(str, expression, values, comments);
8146
+ expression = inject(str, expression, values, comments);
8145
8147
 
8146
8148
  return expression.properties[0];
8147
8149
  } catch (err) {
@@ -8210,6 +8212,8 @@
8210
8212
  });
8211
8213
 
8212
8214
  const whitespace = /[ \t\r\n]/;
8215
+ const start_whitespace = /^[ \t\r\n]*/;
8216
+ const end_whitespace = /[ \t\r\n]*$/;
8213
8217
  const dimensions = /^(?:offset|client)(?:Width|Height)$/;
8214
8218
 
8215
8219
  function list(items, conjunction = 'or') {
@@ -16396,6 +16400,7 @@
16396
16400
  'undefined',
16397
16401
  'URIError',
16398
16402
  'URL',
16403
+ 'URLSearchParams',
16399
16404
  'window'
16400
16405
  ]);
16401
16406
  const reserved = new Set([
@@ -17224,16 +17229,10 @@
17224
17229
  }
17225
17230
 
17226
17231
  function trim_start(str) {
17227
- let i = 0;
17228
- while (whitespace.test(str[i]))
17229
- i += 1;
17230
- return str.slice(i);
17232
+ return str.replace(start_whitespace, '');
17231
17233
  }
17232
17234
  function trim_end(str) {
17233
- let i = str.length;
17234
- while (whitespace.test(str[i - 1]))
17235
- i -= 1;
17236
- return str.slice(0, i);
17235
+ return str.replace(end_whitespace, '');
17237
17236
  }
17238
17237
 
17239
17238
  function to_string(node) {
@@ -24930,6 +24929,12 @@
24930
24929
  });
24931
24930
  }
24932
24931
 
24932
+ function check_enable_sourcemap(enable_sourcemap, namespace) {
24933
+ return typeof enable_sourcemap === 'boolean'
24934
+ ? enable_sourcemap
24935
+ : enable_sourcemap[namespace];
24936
+ }
24937
+
24933
24938
  function dom(component, options) {
24934
24939
  const { name } = component;
24935
24940
  const renderer = new Renderer(component, options);
@@ -24944,8 +24949,14 @@
24944
24949
  body.push(b `const ${renderer.file_var} = ${file};`);
24945
24950
  }
24946
24951
  const css = component.stylesheet.render(options.filename, !options.customElement);
24947
- css.map = apply_preprocessor_sourcemap(options.filename, css.map, options.sourcemap);
24948
- const styles = component.stylesheet.has_styles && options.dev
24952
+ const css_sourcemap_enabled = check_enable_sourcemap(options.enableSourcemap, 'css');
24953
+ if (css_sourcemap_enabled) {
24954
+ css.map = apply_preprocessor_sourcemap(options.filename, css.map, options.sourcemap);
24955
+ }
24956
+ else {
24957
+ css.map = null;
24958
+ }
24959
+ const styles = css_sourcemap_enabled && component.stylesheet.has_styles && options.dev
24949
24960
  ? `${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */`
24950
24961
  : css.code;
24951
24962
  const add_css = component.get_unique_name('add_css');
@@ -25351,7 +25362,7 @@
25351
25362
  constructor(options) {
25352
25363
  super();
25353
25364
 
25354
- ${css.code && b `this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
25365
+ ${css.code && b `this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${css_sourcemap_enabled && options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
25355
25366
 
25356
25367
  @init(this, { target: this.shadowRoot, props: ${init_props}, customElement: true }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, null, ${dirty});
25357
25368
 
@@ -27753,11 +27764,12 @@
27753
27764
  css.code && b `$$result.css.add(#css);`,
27754
27765
  main
27755
27766
  ].filter(Boolean);
27767
+ const css_sourcemap_enabled = check_enable_sourcemap(options.enableSourcemap, 'css');
27756
27768
  const js = b `
27757
27769
  ${css.code ? b `
27758
27770
  const #css = {
27759
27771
  code: "${css.code}",
27760
- map: ${css.map ? string_literal(css.map.toString()) : 'null'}
27772
+ map: ${css_sourcemap_enabled && css.map ? string_literal(css.map.toString()) : 'null'}
27761
27773
  };` : null}
27762
27774
 
27763
27775
  ${component.extract_javascript(component.ast.module)}
@@ -27842,12 +27854,15 @@
27842
27854
  };
27843
27855
  const internal_globals = get_internal_globals(globals, helpers);
27844
27856
  // edit user imports
27845
- imports.forEach(node => {
27846
- node.source.value = edit_source(node.source.value, sveltePath);
27847
- });
27848
- exports_from.forEach(node => {
27849
- node.source.value = edit_source(node.source.value, sveltePath);
27850
- });
27857
+ function rewrite_import(node) {
27858
+ const value = edit_source(node.source.value, sveltePath);
27859
+ if (node.source.value !== value) {
27860
+ node.source.value = value;
27861
+ node.source.raw = null;
27862
+ }
27863
+ }
27864
+ imports.forEach(rewrite_import);
27865
+ exports_from.forEach(rewrite_import);
27851
27866
  const exports = module_exports.length > 0 && {
27852
27867
  type: 'ExportNamedDeclaration',
27853
27868
  specifiers: module_exports.map(x => ({
@@ -30126,7 +30141,7 @@
30126
30141
  if (result) {
30127
30142
  const { compile_options, name } = this;
30128
30143
  const { format = 'esm' } = compile_options;
30129
- const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.43.1'}`;
30144
+ const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'3.44.2'}`;
30130
30145
  const program = { type: 'Program', body: result.js };
30131
30146
  walk(program, {
30132
30147
  enter: (node, parent, key) => {
@@ -30190,17 +30205,24 @@
30190
30205
  css = compile_options.customElement
30191
30206
  ? { code: null, map: null }
30192
30207
  : result.css;
30193
- const sourcemap_source_filename = get_sourcemap_source_filename(compile_options);
30194
- js = print(program, {
30195
- sourceMapSource: sourcemap_source_filename
30196
- });
30197
- js.map.sources = [
30198
- sourcemap_source_filename
30199
- ];
30200
- js.map.sourcesContent = [
30201
- this.source
30202
- ];
30203
- js.map = apply_preprocessor_sourcemap(sourcemap_source_filename, js.map, compile_options.sourcemap);
30208
+ const js_sourcemap_enabled = check_enable_sourcemap(compile_options.enableSourcemap, 'js');
30209
+ if (!js_sourcemap_enabled) {
30210
+ js = print(program);
30211
+ js.map = null;
30212
+ }
30213
+ else {
30214
+ const sourcemap_source_filename = get_sourcemap_source_filename(compile_options);
30215
+ js = print(program, {
30216
+ sourceMapSource: sourcemap_source_filename
30217
+ });
30218
+ js.map.sources = [
30219
+ sourcemap_source_filename
30220
+ ];
30221
+ js.map.sourcesContent = [
30222
+ this.source
30223
+ ];
30224
+ js.map = apply_preprocessor_sourcemap(sourcemap_source_filename, js.map, compile_options.sourcemap);
30225
+ }
30204
30226
  }
30205
30227
  return {
30206
30228
  js,
@@ -31248,6 +31270,7 @@
31248
31270
  'name',
31249
31271
  'filename',
31250
31272
  'sourcemap',
31273
+ 'enableSourcemap',
31251
31274
  'generate',
31252
31275
  'errorMode',
31253
31276
  'varsReport',
@@ -31311,7 +31334,7 @@
31311
31334
  }
31312
31335
  }
31313
31336
  function compile(source, options = {}) {
31314
- options = Object.assign({ generate: 'dom', dev: false }, options);
31337
+ options = Object.assign({ generate: 'dom', dev: false, enableSourcemap: true }, options);
31315
31338
  const stats = new Stats();
31316
31339
  const warnings = [];
31317
31340
  validate_options(options, warnings);
@@ -31565,10 +31588,10 @@
31565
31588
  const { string, map } = await replace_in_code(tag_regex, process_single_tag, source);
31566
31589
  return { string, map, dependencies };
31567
31590
  }
31568
- async function process_markup(filename, process, source) {
31591
+ async function process_markup(process, source) {
31569
31592
  const processed = await process({
31570
31593
  content: source.source,
31571
- filename
31594
+ filename: source.filename
31572
31595
  });
31573
31596
  if (processed) {
31574
31597
  return {
@@ -31587,7 +31610,6 @@
31587
31610
  }
31588
31611
  }
31589
31612
  async function preprocess(source, preprocessor, options) {
31590
- // @ts-ignore todo: doublecheck
31591
31613
  const filename = (options && options.filename) || preprocessor.filename; // legacy
31592
31614
  const preprocessors = preprocessor ? (Array.isArray(preprocessor) ? preprocessor : [preprocessor]) : [];
31593
31615
  const markup = preprocessors.map(p => p.markup).filter(Boolean);
@@ -31597,7 +31619,7 @@
31597
31619
  // TODO keep track: what preprocessor generated what sourcemap?
31598
31620
  // to make debugging easier = detect low-resolution sourcemaps in fn combine_mappings
31599
31621
  for (const process of markup) {
31600
- result.update_source(await process_markup(filename, process, result));
31622
+ result.update_source(await process_markup(process, result));
31601
31623
  }
31602
31624
  for (const process of script) {
31603
31625
  result.update_source(await process_tag('script', process, result));
@@ -31608,7 +31630,7 @@
31608
31630
  return result.to_processed();
31609
31631
  }
31610
31632
 
31611
- const VERSION = '3.43.1';
31633
+ const VERSION = '3.44.2';
31612
31634
 
31613
31635
  exports.VERSION = VERSION;
31614
31636
  exports.compile = compile;