svelte 5.59.1 → 5.59.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/LICENSE.md +1 -1
- package/compiler/index.js +1 -1
- package/package.json +4 -4
- package/src/compiler/legacy.js +2 -2
- package/src/compiler/phases/1-parse/acorn.js +13 -1
- package/src/compiler/phases/1-parse/index.js +50 -7
- package/src/compiler/phases/1-parse/read/context.js +1 -1
- package/src/compiler/phases/1-parse/read/style.js +9 -8
- package/src/compiler/phases/1-parse/state/tag.js +28 -2
- package/src/compiler/phases/2-analyze/index.js +2 -1
- package/src/compiler/phases/2-analyze/visitors/BindDirective.js +4 -8
- package/src/compiler/phases/3-transform/client/transform-client.js +2 -0
- package/src/compiler/phases/3-transform/client/visitors/StaticBlock.js +12 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +10 -7
- package/src/compiler/phases/3-transform/css/index.js +35 -26
- package/src/compiler/phases/patterns.js +2 -0
- package/src/compiler/phases/scope.js +8 -1
- package/src/compiler/print/index.js +18 -9
- package/src/compiler/validate-options.js +1 -1
- package/src/internal/client/custom-renderer/cross.js +4 -4
- package/src/internal/client/dev/elements.js +18 -7
- package/src/internal/client/dom/blocks/await.js +5 -0
- package/src/internal/client/dom/blocks/boundary.js +2 -2
- package/src/internal/client/dom/blocks/branches.js +3 -3
- package/src/internal/client/dom/blocks/each.js +16 -13
- package/src/internal/client/dom/blocks/html.js +8 -8
- package/src/internal/client/dom/blocks/slot.js +8 -13
- package/src/internal/client/dom/blocks/snippet.js +6 -7
- package/src/internal/client/dom/blocks/svelte-element.js +9 -13
- package/src/internal/client/dom/blocks/svelte-head.js +2 -2
- package/src/internal/client/dom/css.js +1 -1
- package/src/internal/client/dom/elements/attributes.js +15 -2
- package/src/internal/client/dom/elements/bindings/select.js +1 -1
- package/src/internal/client/dom/elements/transitions.js +88 -83
- package/src/internal/client/dom/operations.js +36 -8
- package/src/internal/client/dom/template.js +4 -2
- package/src/internal/client/proxy.js +19 -11
- package/src/internal/client/reactivity/batch.js +58 -18
- package/src/internal/client/reactivity/sources.js +39 -6
- package/src/internal/client/render.js +2 -2
- package/src/internal/client/runtime.js +3 -0
- package/src/internal/server/hydratable.js +21 -7
- package/src/internal/shared/utils.js +10 -4
- package/src/reactivity/create-subscriber.js +1 -1
- package/src/reactivity/date.js +3 -2
- package/src/reactivity/map.js +26 -11
- package/src/reactivity/set.js +23 -10
- package/src/reactivity/url-search-params.js +18 -6
- package/src/reactivity/url.js +30 -20
- package/src/version.js +1 -1
- package/types/index.d.ts +24 -16
- package/types/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "svelte",
|
|
3
3
|
"description": "Cybernetically enhanced web apps",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "5.59.
|
|
5
|
+
"version": "5.59.2",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
8
8
|
"engines": {
|
|
@@ -165,14 +165,14 @@
|
|
|
165
165
|
"@types/aria-query": "^5.0.4",
|
|
166
166
|
"@types/node": "^20.11.5",
|
|
167
167
|
"@types/trusted-types": "^2.0.7",
|
|
168
|
-
"baseline-browser-mapping": "^2.
|
|
168
|
+
"baseline-browser-mapping": "^2.11.0",
|
|
169
169
|
"dts-buddy": "^0.5.5",
|
|
170
170
|
"esbuild": "^0.28.1",
|
|
171
171
|
"rollup": "^4.59.0",
|
|
172
172
|
"source-map": "^0.7.4",
|
|
173
173
|
"tinyglobby": "^0.2.12",
|
|
174
174
|
"typescript": "^5.5.4",
|
|
175
|
-
"vitest": "^4.1.
|
|
175
|
+
"vitest": "^4.1.11",
|
|
176
176
|
"web-features": "^3.29.0"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
@@ -184,7 +184,7 @@
|
|
|
184
184
|
"aria-query": "5.3.1",
|
|
185
185
|
"axobject-query": "^4.1.0",
|
|
186
186
|
"clsx": "^2.1.1",
|
|
187
|
-
"devalue": "^
|
|
187
|
+
"devalue": "^6.0.4",
|
|
188
188
|
"esm-env": "^1.2.1",
|
|
189
189
|
"esrap": "^2.4.2",
|
|
190
190
|
"is-reference": "^3.0.3",
|
package/src/compiler/legacy.js
CHANGED
|
@@ -359,8 +359,8 @@ export function convert(source, ast) {
|
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
const start = node.elseif
|
|
362
|
-
? node.consequent.nodes[0]?.start ??
|
|
363
|
-
source.lastIndexOf('{', /** @type {number} */ (node.end) - 1)
|
|
362
|
+
? (node.consequent.nodes[0]?.start ??
|
|
363
|
+
source.lastIndexOf('{', /** @type {number} */ (node.end) - 1))
|
|
364
364
|
: node.start;
|
|
365
365
|
|
|
366
366
|
remove_surrounding_whitespace_nodes(node.consequent.nodes);
|
|
@@ -172,7 +172,19 @@ function handle_parse_error(err) {
|
|
|
172
172
|
export function remove_parens(node) {
|
|
173
173
|
return walk(node, null, {
|
|
174
174
|
ParenthesizedExpression(node, context) {
|
|
175
|
-
|
|
175
|
+
const expression = /** @type {any} */ (context.visit(node.expression));
|
|
176
|
+
const { leadingComments, trailingComments } = /** @type {any} */ (node);
|
|
177
|
+
|
|
178
|
+
// keep the comments attached to the parentheses, like `/* a */` in `{/* a */ (value)}`
|
|
179
|
+
if (leadingComments) {
|
|
180
|
+
expression.leadingComments = [...leadingComments, ...(expression.leadingComments ?? [])];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (trailingComments) {
|
|
184
|
+
expression.trailingComments = [...(expression.trailingComments ?? []), ...trailingComments];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return expression;
|
|
176
188
|
}
|
|
177
189
|
});
|
|
178
190
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
/** @import { AST } from '#compiler' */
|
|
1
|
+
/** @import { AST, CompileError } from '#compiler' */
|
|
2
2
|
/** @import { Location } from 'locate-character' */
|
|
3
3
|
/** @import * as ESTree from 'estree' */
|
|
4
4
|
// @ts-expect-error acorn type definitions are borked in the release we use
|
|
5
5
|
import { isIdentifierStart, isIdentifierChar } from 'acorn';
|
|
6
6
|
import fragment from './state/fragment.js';
|
|
7
7
|
import * as e from '../../errors.js';
|
|
8
|
+
import * as w from '../../warnings.js';
|
|
9
|
+
import { walk } from 'zimmerframe';
|
|
8
10
|
import { create_fragment, disallow_children } from '../nodes.js';
|
|
9
11
|
import read_options from './read/options.js';
|
|
10
12
|
import { is_reserved } from '../../../utils.js';
|
|
@@ -77,8 +79,9 @@ export class Parser {
|
|
|
77
79
|
/**
|
|
78
80
|
* @param {string} template
|
|
79
81
|
* @param {boolean} loose
|
|
82
|
+
* @param {boolean} [ts] Force TypeScript parsing when checking for a missing `lang="ts"`
|
|
80
83
|
*/
|
|
81
|
-
constructor(template, loose) {
|
|
84
|
+
constructor(template, loose, ts = false) {
|
|
82
85
|
if (typeof template !== 'string') {
|
|
83
86
|
throw new TypeError('Template must be a string');
|
|
84
87
|
}
|
|
@@ -94,7 +97,7 @@ export class Parser {
|
|
|
94
97
|
|
|
95
98
|
regex_lang_attribute.lastIndex = 0; // reset matched index to pass tests - otherwise declare the regex inside the constructor
|
|
96
99
|
|
|
97
|
-
this.ts = match_lang?.[2] === 'ts';
|
|
100
|
+
this.ts = ts || match_lang?.[2] === 'ts';
|
|
98
101
|
|
|
99
102
|
this.root = {
|
|
100
103
|
css: null,
|
|
@@ -116,10 +119,50 @@ export class Parser {
|
|
|
116
119
|
this.fragments.push(this.root.fragment);
|
|
117
120
|
|
|
118
121
|
/** @type {ParserState} */
|
|
119
|
-
let
|
|
122
|
+
let next = fragment;
|
|
120
123
|
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
try {
|
|
125
|
+
while (this.index < this.template.length) {
|
|
126
|
+
next = next(this) || fragment;
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
const err = /** @type {CompileError} */ (error);
|
|
130
|
+
|
|
131
|
+
if (
|
|
132
|
+
!this.ts &&
|
|
133
|
+
!loose &&
|
|
134
|
+
(err?.code === 'js_parse_error' || err?.code === 'expected_token')
|
|
135
|
+
) {
|
|
136
|
+
// Only suggest `lang="ts"` if it would make the component parse successfully.
|
|
137
|
+
// Suppress warnings during the retry, including calls to the user's warningFilter.
|
|
138
|
+
state.ignore_stack.push(new Set(w.codes));
|
|
139
|
+
let ts = false;
|
|
140
|
+
try {
|
|
141
|
+
walk(/** @type {any} */ (new Parser(template, false, true).root), null, {
|
|
142
|
+
_(node, { next }) {
|
|
143
|
+
// Acorn also accepts Flow-style casts, which aren't valid TypeScript.
|
|
144
|
+
if (node.type === 'TSTypeCastExpression') throw error;
|
|
145
|
+
if (node.type.startsWith('TS')) ts = true;
|
|
146
|
+
next();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
} catch {
|
|
150
|
+
throw error;
|
|
151
|
+
} finally {
|
|
152
|
+
state.ignore_stack.pop();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!ts) throw error;
|
|
156
|
+
|
|
157
|
+
const message =
|
|
158
|
+
err.code === 'js_parse_error' ? err.message.split('\n')[0] : 'Unexpected token';
|
|
159
|
+
e.js_parse_error(
|
|
160
|
+
err.position?.[0] ?? null,
|
|
161
|
+
`${message} (did you forget to add \`lang="ts"\`?)`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
throw error;
|
|
123
166
|
}
|
|
124
167
|
|
|
125
168
|
if (this.stack.length > 1) {
|
|
@@ -136,7 +179,7 @@ export class Parser {
|
|
|
136
179
|
}
|
|
137
180
|
}
|
|
138
181
|
|
|
139
|
-
if (
|
|
182
|
+
if (next !== fragment) {
|
|
140
183
|
e.unexpected_eof(this.index);
|
|
141
184
|
}
|
|
142
185
|
|
|
@@ -57,7 +57,7 @@ function read_body(parser, finished) {
|
|
|
57
57
|
/** @type {Array<AST.CSS.Rule | AST.CSS.Atrule>} */
|
|
58
58
|
const children = [];
|
|
59
59
|
|
|
60
|
-
while ((allow_comment_or_whitespace(parser), !finished(parser))) {
|
|
60
|
+
while ((allow_comment_or_whitespace(parser, true, true), !finished(parser))) {
|
|
61
61
|
if (parser.match('@')) {
|
|
62
62
|
children.push(read_at_rule(parser));
|
|
63
63
|
} else {
|
|
@@ -649,18 +649,19 @@ function read_identifier(parser) {
|
|
|
649
649
|
/**
|
|
650
650
|
* @param {Parser} parser
|
|
651
651
|
* @param {boolean} [capture_comments]
|
|
652
|
+
* @param {boolean} [top_level]
|
|
652
653
|
*/
|
|
653
|
-
function allow_comment_or_whitespace(parser, capture_comments = true) {
|
|
654
|
+
function allow_comment_or_whitespace(parser, capture_comments = true, top_level = false) {
|
|
654
655
|
parser.allow_whitespace();
|
|
655
|
-
while (
|
|
656
|
+
while (true) {
|
|
656
657
|
if (parser.match('/*')) {
|
|
657
658
|
const comment = read_comment(parser);
|
|
658
659
|
if (capture_comments) parser.css_comments.push(comment);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
660
|
+
} else if (top_level && (parser.eat('<!--') || parser.eat('-->'))) {
|
|
661
|
+
// `<!--` and `-->` are not comments in CSS. They are single tokens
|
|
662
|
+
// that are ignored at the top level of a stylesheet, and only there
|
|
663
|
+
} else {
|
|
664
|
+
break;
|
|
664
665
|
}
|
|
665
666
|
|
|
666
667
|
parser.allow_whitespace();
|
|
@@ -710,6 +710,33 @@ function close(parser) {
|
|
|
710
710
|
parser.pop();
|
|
711
711
|
}
|
|
712
712
|
|
|
713
|
+
/**
|
|
714
|
+
* The parser is past the parens wrapping `init`, but `init.end` is not. The parser
|
|
715
|
+
* is also past any comments after them, which are not part of the declarator.
|
|
716
|
+
* @param {Parser} parser
|
|
717
|
+
* @param {Expression} init
|
|
718
|
+
*/
|
|
719
|
+
function get_declarator_end(parser, init) {
|
|
720
|
+
const init_end = /** @type {number} */ (init.end);
|
|
721
|
+
const comments = parser.root.comments;
|
|
722
|
+
let end = parser.index;
|
|
723
|
+
let i = comments.length - 1;
|
|
724
|
+
|
|
725
|
+
while (end > init_end) {
|
|
726
|
+
while (i >= 0 && comments[i].end > end) i -= 1;
|
|
727
|
+
|
|
728
|
+
if (i >= 0 && comments[i].end === end && comments[i].start >= init_end) {
|
|
729
|
+
end = comments[i].start;
|
|
730
|
+
} else if (/\s/.test(parser.template[end - 1])) {
|
|
731
|
+
end -= 1;
|
|
732
|
+
} else {
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
return end;
|
|
738
|
+
}
|
|
739
|
+
|
|
713
740
|
/** @param {Parser} parser */
|
|
714
741
|
function special(parser) {
|
|
715
742
|
let start = parser.index;
|
|
@@ -785,8 +812,7 @@ function special(parser) {
|
|
|
785
812
|
|
|
786
813
|
const expression_start = parser.index;
|
|
787
814
|
const init = read_expression(parser);
|
|
788
|
-
|
|
789
|
-
const declarator_end = parser.index;
|
|
815
|
+
const declarator_end = get_declarator_end(parser, init);
|
|
790
816
|
if (
|
|
791
817
|
init.type === 'SequenceExpression' &&
|
|
792
818
|
!parser.template.substring(expression_start, init.start).includes('(')
|
|
@@ -492,7 +492,8 @@ export function analyze_component(root, source, options) {
|
|
|
492
492
|
const custom_element = options.customElementOptions ?? custom_element_from_option;
|
|
493
493
|
const is_custom_element = !!options.customElementOptions || custom_element_from_option;
|
|
494
494
|
|
|
495
|
-
|
|
495
|
+
// `$`-prefixed names are reserved for internal bindings like `$`, `$$props` and `$$css`
|
|
496
|
+
const name = module.scope.generate((options.name ?? component_name).replace(/^\$/, '_$'));
|
|
496
497
|
|
|
497
498
|
state.adjust({
|
|
498
499
|
component_name: name,
|
|
@@ -140,18 +140,14 @@ export function BindDirective(node, context) {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
let i = /** @type {number} */ (node.expression.start);
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
const leading_comments = /** @type {any[]} */ (
|
|
144
|
+
/** @type {any} */ (node.expression).leadingComments ?? []
|
|
145
|
+
);
|
|
145
146
|
while (context.state.analysis.source[--i] !== '{') {
|
|
146
147
|
if (
|
|
147
148
|
context.state.analysis.source[i] === '(' &&
|
|
148
149
|
// if the parenthesis is in a leading comment we don't need to throw the error
|
|
149
|
-
!(
|
|
150
|
-
leading_comments_start &&
|
|
151
|
-
leading_comments_end &&
|
|
152
|
-
i <= leading_comments_end &&
|
|
153
|
-
i >= leading_comments_start
|
|
154
|
-
)
|
|
150
|
+
!leading_comments.some((comment) => comment.start <= i && i < comment.end)
|
|
155
151
|
) {
|
|
156
152
|
e.bind_invalid_parens(node, node.name);
|
|
157
153
|
}
|
|
@@ -45,6 +45,7 @@ import { RenderTag } from './visitors/RenderTag.js';
|
|
|
45
45
|
import { SlotElement } from './visitors/SlotElement.js';
|
|
46
46
|
import { SnippetBlock } from './visitors/SnippetBlock.js';
|
|
47
47
|
import { SpreadAttribute } from './visitors/SpreadAttribute.js';
|
|
48
|
+
import { StaticBlock } from './visitors/StaticBlock.js';
|
|
48
49
|
import { SvelteBody } from './visitors/SvelteBody.js';
|
|
49
50
|
import { SvelteComponent } from './visitors/SvelteComponent.js';
|
|
50
51
|
import { SvelteDocument } from './visitors/SvelteDocument.js';
|
|
@@ -110,6 +111,7 @@ const visitors = {
|
|
|
110
111
|
SlotElement,
|
|
111
112
|
SnippetBlock,
|
|
112
113
|
SpreadAttribute,
|
|
114
|
+
StaticBlock,
|
|
113
115
|
SvelteBody,
|
|
114
116
|
SvelteComponent,
|
|
115
117
|
SvelteDocument,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @import { StaticBlock } from 'estree' */
|
|
2
|
+
/** @import { ComponentContext } from '../types' */
|
|
3
|
+
import { add_state_transformers } from './shared/declarations.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {StaticBlock} node
|
|
7
|
+
* @param {ComponentContext} context
|
|
8
|
+
*/
|
|
9
|
+
export function StaticBlock(node, context) {
|
|
10
|
+
add_state_transformers(context);
|
|
11
|
+
context.next();
|
|
12
|
+
}
|
|
@@ -6,7 +6,7 @@ import { walk } from 'zimmerframe';
|
|
|
6
6
|
import { object } from '../../../../../utils/ast.js';
|
|
7
7
|
import * as b from '#compiler/builders';
|
|
8
8
|
import { sanitize_template_string } from '../../../../../utils/sanitize_template_string.js';
|
|
9
|
-
import { regex_is_valid_identifier } from '../../../../patterns.js';
|
|
9
|
+
import { regex_directive_name_separator, regex_is_valid_identifier } from '../../../../patterns.js';
|
|
10
10
|
import is_reference from 'is-reference';
|
|
11
11
|
import { dev, is_ignored, locator, component_name } from '../../../../../state.js';
|
|
12
12
|
import { async_thunk, build_getter, is_state_source } from '../../utils.js';
|
|
@@ -221,16 +221,19 @@ export function build_render_statement(state) {
|
|
|
221
221
|
* @param {string} name
|
|
222
222
|
*/
|
|
223
223
|
export function parse_directive_name(name) {
|
|
224
|
-
// this
|
|
225
|
-
const
|
|
226
|
-
let part = /** @type {string} */ (parts.shift());
|
|
224
|
+
// this allows accessing members of an object, with `.` or `?.`
|
|
225
|
+
const [first, ...rest] = name.split(regex_directive_name_separator);
|
|
227
226
|
|
|
228
227
|
/** @type {Identifier | MemberExpression} */
|
|
229
|
-
let expression = b.id(
|
|
228
|
+
let expression = b.id(first);
|
|
229
|
+
|
|
230
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
231
|
+
const optional = rest[i] === '?.';
|
|
232
|
+
const part = rest[i + 1];
|
|
233
|
+
if (!part) break;
|
|
230
234
|
|
|
231
|
-
while ((part = /** @type {string} */ (parts.shift()))) {
|
|
232
235
|
const computed = !regex_is_valid_identifier.test(part);
|
|
233
|
-
expression = b.member(expression, computed ? b.literal(part) : b.id(part), computed);
|
|
236
|
+
expression = b.member(expression, computed ? b.literal(part) : b.id(part), computed, optional);
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
return expression;
|
|
@@ -182,6 +182,7 @@ const visitors = {
|
|
|
182
182
|
} else {
|
|
183
183
|
state.code.prependRight(node.start, '/* ');
|
|
184
184
|
state.code.appendLeft(node.block.start + 1, '*/');
|
|
185
|
+
escape_comment_close({ start: node.start, end: node.block.start + 1 }, state.code);
|
|
185
186
|
|
|
186
187
|
state.code.prependRight(node.block.end - 1, '/*');
|
|
187
188
|
state.code.appendLeft(node.block.end, '*/');
|
|
@@ -215,19 +216,20 @@ const visitors = {
|
|
|
215
216
|
|
|
216
217
|
if (selector.metadata.used === pruning) {
|
|
217
218
|
if (pruning) {
|
|
218
|
-
|
|
219
|
-
while (state.code.original[i] !== ',') i--;
|
|
219
|
+
const i = find_comma(state.code.original, last);
|
|
220
220
|
|
|
221
221
|
if (state.minify) {
|
|
222
222
|
state.code.remove(prune_start, has_previous_used ? i : i + 1);
|
|
223
223
|
} else {
|
|
224
|
-
|
|
224
|
+
const end = has_previous_used ? i : i + 1;
|
|
225
|
+
state.code.appendRight(end, '*/');
|
|
226
|
+
escape_comment_close({ start: prune_start, end }, state.code);
|
|
225
227
|
}
|
|
226
228
|
} else {
|
|
229
|
+
prune_start = selector.start;
|
|
230
|
+
|
|
227
231
|
if (i === 0) {
|
|
228
|
-
if (state.minify) {
|
|
229
|
-
prune_start = selector.start;
|
|
230
|
-
} else {
|
|
232
|
+
if (!state.minify) {
|
|
231
233
|
state.code.prependRight(selector.start, '/* (unused) ');
|
|
232
234
|
}
|
|
233
235
|
} else {
|
|
@@ -254,6 +256,7 @@ const visitors = {
|
|
|
254
256
|
state.code.remove(prune_start, last);
|
|
255
257
|
} else {
|
|
256
258
|
state.code.appendLeft(last, '*/');
|
|
259
|
+
escape_comment_close({ start: prune_start, end: last }, state.code);
|
|
257
260
|
}
|
|
258
261
|
}
|
|
259
262
|
}
|
|
@@ -458,29 +461,35 @@ function is_used(rule) {
|
|
|
458
461
|
}
|
|
459
462
|
|
|
460
463
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* @param {
|
|
464
|
+
* Finds the comma between two selectors in a list. It skips comments like
|
|
465
|
+
* the parser does, because they can contain commas too
|
|
466
|
+
* @param {string} css
|
|
467
|
+
* @param {number} start the end of the previous selector
|
|
464
468
|
*/
|
|
465
|
-
function
|
|
466
|
-
let
|
|
467
|
-
let in_comment = false;
|
|
469
|
+
function find_comma(css, start) {
|
|
470
|
+
let i = start;
|
|
468
471
|
|
|
469
|
-
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
+
while (css[i] !== ',') {
|
|
473
|
+
if (css.startsWith('/*', i)) {
|
|
474
|
+
i = css.indexOf('*/', i + 2) + 2;
|
|
472
475
|
} else {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
476
|
+
i++;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return i;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Escape all comment terminators in text that will be wrapped in a generated comment.
|
|
485
|
+
* CSS strings and escapes have no meaning inside that comment.
|
|
486
|
+
* @param {{ start: number; end: number }} node
|
|
487
|
+
* @param {MagicString} code
|
|
488
|
+
*/
|
|
489
|
+
function escape_comment_close(node, code) {
|
|
490
|
+
for (let i = node.start; i < node.end - 1; i++) {
|
|
491
|
+
if (code.original[i] === '*' && code.original[i + 1] === '/') {
|
|
492
|
+
code.prependRight(++i, '\\');
|
|
484
493
|
}
|
|
485
494
|
}
|
|
486
495
|
}
|
|
@@ -14,6 +14,8 @@ export const regex_only_whitespaces = /^[ \t\n\r\f]+$/;
|
|
|
14
14
|
export const regex_not_newline_characters = /[^\n]/g;
|
|
15
15
|
|
|
16
16
|
export const regex_is_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
17
|
+
/** Splits a directive name like `a?.b.c` into its parts, keeping each `.` or `?.` */
|
|
18
|
+
export const regex_directive_name_separator = /(\?\.|\.)/;
|
|
17
19
|
// used in replace all to remove all invalid chars from a literal identifier
|
|
18
20
|
export const regex_invalid_identifier_chars = /(^[^a-zA-Z_$]|[^a-zA-Z0-9_$])/g;
|
|
19
21
|
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from '../utils/ast.js';
|
|
15
15
|
import { is_reserved, is_rune } from '../../utils.js';
|
|
16
16
|
import { determine_slot } from '../utils/slot.js';
|
|
17
|
+
import { regex_directive_name_separator } from './patterns.js';
|
|
17
18
|
|
|
18
19
|
const UNKNOWN = Symbol('unknown');
|
|
19
20
|
/** Includes `BigInt` */
|
|
@@ -1019,7 +1020,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
|
|
|
1019
1020
|
* @type {Visitor<AST.AnimateDirective | AST.TransitionDirective | AST.UseDirective, State, AST.SvelteNode>}
|
|
1020
1021
|
*/
|
|
1021
1022
|
const SvelteDirective = (node, { state, path, visit }) => {
|
|
1022
|
-
state.scope.reference(b.id(node.name.split(
|
|
1023
|
+
state.scope.reference(b.id(node.name.split(regex_directive_name_separator)[0]), path);
|
|
1023
1024
|
|
|
1024
1025
|
if (node.expression) {
|
|
1025
1026
|
visit(node.expression);
|
|
@@ -1192,6 +1193,12 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
|
|
|
1192
1193
|
next();
|
|
1193
1194
|
},
|
|
1194
1195
|
|
|
1196
|
+
StaticBlock(node, { state, next }) {
|
|
1197
|
+
const scope = state.scope.child();
|
|
1198
|
+
scopes.set(node, scope);
|
|
1199
|
+
next({ scope });
|
|
1200
|
+
},
|
|
1201
|
+
|
|
1195
1202
|
VariableDeclaration(node, { state, path, next }) {
|
|
1196
1203
|
const is_parent_const_tag = path.at(-1)?.type === 'ConstTag';
|
|
1197
1204
|
for (const declarator of node.declarations) {
|
|
@@ -537,6 +537,17 @@ function css_visitors(comments, js_comments) {
|
|
|
537
537
|
};
|
|
538
538
|
}
|
|
539
539
|
|
|
540
|
+
/**
|
|
541
|
+
* Attribute values are printed inside double quotes, but the raw text is
|
|
542
|
+
* preserved as written — and can contain `"` if the source used single quotes.
|
|
543
|
+
* @param {AST.Text} node
|
|
544
|
+
* @returns {AST.Text}
|
|
545
|
+
*/
|
|
546
|
+
function escape_attribute_text(node) {
|
|
547
|
+
if (!node.raw.includes('"')) return node;
|
|
548
|
+
return { ...node, raw: node.raw.replaceAll('"', '"') };
|
|
549
|
+
}
|
|
550
|
+
|
|
540
551
|
/**
|
|
541
552
|
* @param {AST.JSComment[]} comments
|
|
542
553
|
* @param {{ preserve_whitespace: number }} state
|
|
@@ -720,7 +731,7 @@ const svelte_visitors = (comments, state) => ({
|
|
|
720
731
|
}
|
|
721
732
|
|
|
722
733
|
for (const chunk of node.value) {
|
|
723
|
-
context.visit(chunk);
|
|
734
|
+
context.visit(chunk.type === 'Text' ? escape_attribute_text(chunk) : chunk);
|
|
724
735
|
}
|
|
725
736
|
|
|
726
737
|
if (node.value.length > 1 || node.value[0].type === 'Text') {
|
|
@@ -934,13 +945,11 @@ const svelte_visitors = (comments, state) => ({
|
|
|
934
945
|
}
|
|
935
946
|
|
|
936
947
|
if (node.alternate !== null) {
|
|
937
|
-
if (
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
)
|
|
943
|
-
) {
|
|
948
|
+
if (!(
|
|
949
|
+
node.alternate.nodes.length === 1 &&
|
|
950
|
+
node.alternate.nodes[0].type === 'IfBlock' &&
|
|
951
|
+
node.alternate.nodes[0].elseif
|
|
952
|
+
)) {
|
|
944
953
|
context.write('{:else}');
|
|
945
954
|
block(context, node.alternate, state.preserve_whitespace > 0);
|
|
946
955
|
} else {
|
|
@@ -1041,7 +1050,7 @@ const svelte_visitors = (comments, state) => ({
|
|
|
1041
1050
|
context.write('"');
|
|
1042
1051
|
|
|
1043
1052
|
for (const tag of node.value) {
|
|
1044
|
-
context.visit(tag);
|
|
1053
|
+
context.visit(tag.type === 'Text' ? escape_attribute_text(tag) : tag);
|
|
1045
1054
|
}
|
|
1046
1055
|
|
|
1047
1056
|
context.write('"');
|
|
@@ -121,7 +121,7 @@ const component_options = {
|
|
|
121
121
|
),
|
|
122
122
|
|
|
123
123
|
cssHash: fun(({ css, filename, hash }) => {
|
|
124
|
-
return `svelte-${hash(filename === '(unknown)' ? css : filename ?? css)}`;
|
|
124
|
+
return `svelte-${hash(filename === '(unknown)' ? css : (filename ?? css))}`;
|
|
125
125
|
}),
|
|
126
126
|
|
|
127
127
|
// TODO this is a sourcemap option, would be good to put under a sourcemap namespace
|
|
@@ -4,7 +4,7 @@ import { branch, teardown } from '../reactivity/effects.js';
|
|
|
4
4
|
import { assign_nodes } from '../dom/template.js';
|
|
5
5
|
import {
|
|
6
6
|
append_child,
|
|
7
|
-
|
|
7
|
+
create_anchor,
|
|
8
8
|
get_next_sibling,
|
|
9
9
|
get_parent_node,
|
|
10
10
|
insert_before,
|
|
@@ -61,7 +61,7 @@ export function cross(renderer, anchor, render) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// the host side of the crossing: a single node, inserted using the host renderer
|
|
64
|
-
var host_node = /** @type {TemplateNode} */ (connection.node ??
|
|
64
|
+
var host_node = /** @type {TemplateNode} */ (connection.node ?? create_anchor());
|
|
65
65
|
insert_before(anchor, host_node);
|
|
66
66
|
assign_nodes(host_node, host_node);
|
|
67
67
|
|
|
@@ -86,8 +86,8 @@ export function cross(renderer, anchor, render) {
|
|
|
86
86
|
|
|
87
87
|
try {
|
|
88
88
|
// the guest side: markers inside the container, inserted using the guest renderer
|
|
89
|
-
var first =
|
|
90
|
-
var last =
|
|
89
|
+
var first = create_anchor();
|
|
90
|
+
var last = create_anchor();
|
|
91
91
|
var container = /** @type {Node} */ (connection.container);
|
|
92
92
|
append_child(container, first);
|
|
93
93
|
append_child(container, last);
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
/** @import { SourceLocation } from '#client' */
|
|
1
|
+
/** @import { DevStackEntry, SourceLocation } from '#client' */
|
|
2
2
|
import { COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, ELEMENT_NODE } from '#client/constants';
|
|
3
3
|
import { HYDRATION_END, HYDRATION_START } from '../../../constants.js';
|
|
4
4
|
import { hydrating } from '../dom/hydration.js';
|
|
5
5
|
import { component_context, dev_stack } from '../context.js';
|
|
6
6
|
import { get_first_child, get_next_sibling, get_node_value, node_type } from '../dom/operations.js';
|
|
7
|
+
import { define_property } from '../../shared/utils.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Element} element
|
|
11
|
+
* @param {{ file: string, line: number, column: number }} loc
|
|
12
|
+
* @param {DevStackEntry | null} parent
|
|
13
|
+
*/
|
|
14
|
+
export function set_dev_metadata(element, loc, parent = dev_stack) {
|
|
15
|
+
// Keep structural comparisons of elements from traversing the component graph.
|
|
16
|
+
define_property(element, '__svelte_meta', {
|
|
17
|
+
value: { parent, loc, component: component_context },
|
|
18
|
+
enumerable: false,
|
|
19
|
+
writable: true,
|
|
20
|
+
configurable: true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
7
23
|
|
|
8
24
|
/**
|
|
9
25
|
* Assign locations immediately after cloning, before blocks or child components insert elements.
|
|
@@ -42,12 +58,7 @@ export function add_locations(fn, filename, locations) {
|
|
|
42
58
|
* @param {SourceLocation} location
|
|
43
59
|
*/
|
|
44
60
|
function assign_location(element, filename, location) {
|
|
45
|
-
|
|
46
|
-
element.__svelte_meta = {
|
|
47
|
-
parent: dev_stack,
|
|
48
|
-
loc: { file: filename, line: location[0], column: location[1] },
|
|
49
|
-
component: component_context
|
|
50
|
-
};
|
|
61
|
+
set_dev_metadata(element, { file: filename, line: location[0], column: location[1] });
|
|
51
62
|
|
|
52
63
|
if (location[2]) {
|
|
53
64
|
assign_locations(get_first_child(element), filename, location[2]);
|
|
@@ -19,6 +19,7 @@ import { BranchManager } from './branches.js';
|
|
|
19
19
|
import { capture, merge_target, unset_context } from '../../reactivity/async.js';
|
|
20
20
|
import { DEV } from 'esm-env';
|
|
21
21
|
import { active_effect } from '../../runtime.js';
|
|
22
|
+
import { invoke_error_boundary } from '../../error-handling.js';
|
|
22
23
|
|
|
23
24
|
const PENDING = 0;
|
|
24
25
|
const THEN = 1;
|
|
@@ -161,6 +162,8 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
|
|
|
161
162
|
|
|
162
163
|
try {
|
|
163
164
|
fn((source, v) => /** @type {Batch} */ (target).capture(source, v, source.equals(v)));
|
|
165
|
+
} catch (error) {
|
|
166
|
+
invoke_error_boundary(error, effect);
|
|
164
167
|
} finally {
|
|
165
168
|
unset_context(false);
|
|
166
169
|
target.flush();
|
|
@@ -186,6 +189,8 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
|
|
|
186
189
|
|
|
187
190
|
try {
|
|
188
191
|
fn(internal_set);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
invoke_error_boundary(error, effect);
|
|
189
194
|
} finally {
|
|
190
195
|
unset_context(false);
|
|
191
196
|
|