svelte 4.2.4 → 4.2.5

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/compiler.cjs CHANGED
@@ -13010,8 +13010,9 @@ function tag(parser) {
13010
13010
  * @type {Set<string>}
13011
13011
  */
13012
13012
  const unique_names = new Set();
13013
+ const is_top_level_script_or_style = specials.has(name) && parser.stack.length === 1;
13013
13014
  let attribute;
13014
- while ((attribute = read_attribute(parser, unique_names))) {
13015
+ while ((attribute = read_attribute(parser, unique_names, is_top_level_script_or_style))) {
13015
13016
  element.attributes.push(attribute);
13016
13017
  parser.allow_whitespace();
13017
13018
  }
@@ -13045,8 +13046,7 @@ function tag(parser) {
13045
13046
  }
13046
13047
  element.tag = definition.value[0].data || definition.value[0].expression;
13047
13048
  }
13048
- // special cases – top-level <script> and <style>
13049
- if (specials.has(name) && parser.stack.length === 1) {
13049
+ if (is_top_level_script_or_style) {
13050
13050
  const special = specials.get(name);
13051
13051
  parser.eat('>', true);
13052
13052
  const content = special.read(parser, start, element.attributes);
@@ -13129,8 +13129,9 @@ const regex_starts_with_quote_characters = /^["']/;
13129
13129
  /**
13130
13130
  * @param {import('../index.js').Parser} parser
13131
13131
  * @param {Set<string>} unique_names
13132
+ * @param {boolean} is_static If `true`, `{` and `}` are not treated as delimiters for expressions
13132
13133
  */
13133
- function read_attribute(parser, unique_names) {
13134
+ function read_attribute(parser, unique_names, is_static) {
13134
13135
  const start = parser.index;
13135
13136
 
13136
13137
  /**
@@ -13142,7 +13143,7 @@ function read_attribute(parser, unique_names) {
13142
13143
  }
13143
13144
  unique_names.add(name);
13144
13145
  }
13145
- if (parser.eat('{')) {
13146
+ if (!is_static && parser.eat('{')) {
13146
13147
  parser.allow_whitespace();
13147
13148
  if (parser.eat('...')) {
13148
13149
  const expression = read_expression(parser);
@@ -13197,12 +13198,12 @@ function read_attribute(parser, unique_names) {
13197
13198
  let value = true;
13198
13199
  if (parser.eat('=')) {
13199
13200
  parser.allow_whitespace();
13200
- value = read_attribute_value(parser);
13201
+ value = read_attribute_value(parser, is_static);
13201
13202
  end = parser.index;
13202
13203
  } else if (parser.match_regex(regex_starts_with_quote_characters)) {
13203
13204
  parser.error(parser_errors.unexpected_token('='), parser.index);
13204
13205
  }
13205
- if (type) {
13206
+ if (!is_static && type) {
13206
13207
  const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
13207
13208
  if (directive_name === '') {
13208
13209
  parser.error(parser_errors.empty_directive_name(type), start + colon_index + 1);
@@ -13285,10 +13286,37 @@ function get_directive_type(name) {
13285
13286
  if (name === 'in' || name === 'out' || name === 'transition') return 'Transition';
13286
13287
  }
13287
13288
 
13289
+ const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]))/;
13290
+
13288
13291
  /**
13289
13292
  * @param {import('../index.js').Parser} parser
13293
+ * @param {boolean} is_static If `true`, `{` and `}` are not treated as delimiters for expressions
13290
13294
  */
13291
- function read_attribute_value(parser) {
13295
+ function read_attribute_value(parser, is_static) {
13296
+ if (is_static) {
13297
+ let value = parser.match_regex(regex_attribute_value);
13298
+ if (!value) {
13299
+ parser.error(parser_errors.missing_attribute_value);
13300
+ }
13301
+
13302
+ parser.index += value.length;
13303
+
13304
+ const quoted = value[0] === '"' || value[0] === "'";
13305
+ if (quoted) {
13306
+ value = value.slice(1, -1);
13307
+ }
13308
+
13309
+ return [
13310
+ {
13311
+ start: parser.index - value.length - (quoted ? 1 : 0),
13312
+ end: quoted ? parser.index - 1 : parser.index,
13313
+ type: 'Text',
13314
+ raw: value,
13315
+ data: decode_character_references(value, true)
13316
+ }
13317
+ ];
13318
+ }
13319
+
13292
13320
  const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
13293
13321
  if (quote_mark && parser.eat(quote_mark)) {
13294
13322
  return [
@@ -43636,7 +43664,7 @@ function is_used_as_reference(node, parent) {
43636
43664
  * https://svelte.dev/docs/svelte-compiler#svelte-version
43637
43665
  * @type {string}
43638
43666
  */
43639
- const VERSION = '4.2.4';
43667
+ const VERSION = '4.2.5';
43640
43668
 
43641
43669
  const regex_leading_directory_separator = /^[/\\]/;
43642
43670
  const regex_starts_with_term_export = /^Export/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte",
3
- "version": "4.2.4",
3
+ "version": "4.2.5",
4
4
  "description": "Cybernetically enhanced web apps",
5
5
  "type": "module",
6
6
  "module": "src/runtime/index.js",
@@ -161,8 +161,9 @@ export default function tag(parser) {
161
161
  * @type {Set<string>}
162
162
  */
163
163
  const unique_names = new Set();
164
+ const is_top_level_script_or_style = specials.has(name) && parser.stack.length === 1;
164
165
  let attribute;
165
- while ((attribute = read_attribute(parser, unique_names))) {
166
+ while ((attribute = read_attribute(parser, unique_names, is_top_level_script_or_style))) {
166
167
  element.attributes.push(attribute);
167
168
  parser.allow_whitespace();
168
169
  }
@@ -196,8 +197,7 @@ export default function tag(parser) {
196
197
  }
197
198
  element.tag = definition.value[0].data || definition.value[0].expression;
198
199
  }
199
- // special cases – top-level <script> and <style>
200
- if (specials.has(name) && parser.stack.length === 1) {
200
+ if (is_top_level_script_or_style) {
201
201
  const special = specials.get(name);
202
202
  parser.eat('>', true);
203
203
  const content = special.read(parser, start, element.attributes);
@@ -280,8 +280,9 @@ const regex_starts_with_quote_characters = /^["']/;
280
280
  /**
281
281
  * @param {import('../index.js').Parser} parser
282
282
  * @param {Set<string>} unique_names
283
+ * @param {boolean} is_static If `true`, `{` and `}` are not treated as delimiters for expressions
283
284
  */
284
- function read_attribute(parser, unique_names) {
285
+ function read_attribute(parser, unique_names, is_static) {
285
286
  const start = parser.index;
286
287
 
287
288
  /**
@@ -293,7 +294,7 @@ function read_attribute(parser, unique_names) {
293
294
  }
294
295
  unique_names.add(name);
295
296
  }
296
- if (parser.eat('{')) {
297
+ if (!is_static && parser.eat('{')) {
297
298
  parser.allow_whitespace();
298
299
  if (parser.eat('...')) {
299
300
  const expression = read_expression(parser);
@@ -348,12 +349,12 @@ function read_attribute(parser, unique_names) {
348
349
  let value = true;
349
350
  if (parser.eat('=')) {
350
351
  parser.allow_whitespace();
351
- value = read_attribute_value(parser);
352
+ value = read_attribute_value(parser, is_static);
352
353
  end = parser.index;
353
354
  } else if (parser.match_regex(regex_starts_with_quote_characters)) {
354
355
  parser.error(parser_errors.unexpected_token('='), parser.index);
355
356
  }
356
- if (type) {
357
+ if (!is_static && type) {
357
358
  const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
358
359
  if (directive_name === '') {
359
360
  parser.error(parser_errors.empty_directive_name(type), start + colon_index + 1);
@@ -436,10 +437,37 @@ function get_directive_type(name) {
436
437
  if (name === 'in' || name === 'out' || name === 'transition') return 'Transition';
437
438
  }
438
439
 
440
+ const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]))/;
441
+
439
442
  /**
440
443
  * @param {import('../index.js').Parser} parser
444
+ * @param {boolean} is_static If `true`, `{` and `}` are not treated as delimiters for expressions
441
445
  */
442
- function read_attribute_value(parser) {
446
+ function read_attribute_value(parser, is_static) {
447
+ if (is_static) {
448
+ let value = parser.match_regex(regex_attribute_value);
449
+ if (!value) {
450
+ parser.error(parser_errors.missing_attribute_value);
451
+ }
452
+
453
+ parser.index += value.length;
454
+
455
+ const quoted = value[0] === '"' || value[0] === "'";
456
+ if (quoted) {
457
+ value = value.slice(1, -1);
458
+ }
459
+
460
+ return [
461
+ {
462
+ start: parser.index - value.length - (quoted ? 1 : 0),
463
+ end: quoted ? parser.index - 1 : parser.index,
464
+ type: 'Text',
465
+ raw: value,
466
+ data: decode_character_references(value, true)
467
+ }
468
+ ];
469
+ }
470
+
443
471
  const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
444
472
  if (quote_mark && parser.eat(quote_mark)) {
445
473
  return [
@@ -6,5 +6,5 @@
6
6
  * https://svelte.dev/docs/svelte-compiler#svelte-version
7
7
  * @type {string}
8
8
  */
9
- export const VERSION = '4.2.4';
9
+ export const VERSION = '4.2.5';
10
10
  export const PUBLIC_VERSION = '4';