svelte 5.44.0 → 5.45.0
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/index.js +1 -1
- package/package.json +2 -2
- package/src/compiler/index.js +1 -0
- package/src/compiler/migrate/index.js +2 -2
- package/src/compiler/phases/1-parse/remove_typescript_nodes.js +10 -0
- package/src/compiler/phases/3-transform/client/visitors/ConstTag.js +11 -5
- package/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +1 -1
- package/src/compiler/phases/3-transform/server/visitors/ConstTag.js +8 -1
- package/src/compiler/phases/3-transform/server/visitors/VariableDeclaration.js +1 -1
- package/src/compiler/phases/3-transform/shared/transform-async.js +15 -16
- package/src/compiler/print/index.js +865 -0
- package/src/internal/client/dev/debug.js +25 -2
- package/src/internal/client/dom/blocks/each.js +14 -2
- package/src/internal/client/dom/elements/bindings/this.js +1 -1
- package/src/internal/client/dom/elements/misc.js +1 -1
- package/src/version.js +1 -1
- package/types/index.d.ts +18 -1
- package/types/index.d.ts.map +7 -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.
|
|
5
|
+
"version": "5.45.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
8
8
|
"engines": {
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
"clsx": "^2.1.1",
|
|
166
166
|
"devalue": "^5.5.0",
|
|
167
167
|
"esm-env": "^1.2.1",
|
|
168
|
-
"esrap": "^2.
|
|
168
|
+
"esrap": "^2.2.0",
|
|
169
169
|
"is-reference": "^3.0.3",
|
|
170
170
|
"locate-character": "^3.0.0",
|
|
171
171
|
"magic-string": "^0.30.11",
|
package/src/compiler/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { transform_component, transform_module } from './phases/3-transform/inde
|
|
|
10
10
|
import { validate_component_options, validate_module_options } from './validate-options.js';
|
|
11
11
|
import * as state from './state.js';
|
|
12
12
|
export { default as preprocess } from './preprocess/index.js';
|
|
13
|
+
export { print } from './print/index.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* `compile` converts your `.svelte` source code into a JavaScript module that exports a component
|
|
@@ -604,7 +604,7 @@ const instance_script = {
|
|
|
604
604
|
'Encountered an export declaration pattern that is not supported for automigration.'
|
|
605
605
|
);
|
|
606
606
|
// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
|
|
607
|
-
// means that foo and bar are the props (i.e. the
|
|
607
|
+
// means that foo and bar are the props (i.e. the leaves are the prop names), not x and z.
|
|
608
608
|
// const tmp = b.id(state.scope.generate('tmp'));
|
|
609
609
|
// const paths = extract_paths(declarator.id, tmp);
|
|
610
610
|
// state.props_pre.push(
|
|
@@ -1812,7 +1812,7 @@ function handle_events(element, state) {
|
|
|
1812
1812
|
}
|
|
1813
1813
|
|
|
1814
1814
|
/**
|
|
1815
|
-
* Returns start and end of the node. If the start is
|
|
1815
|
+
* Returns start and end of the node. If the start is preceded with white-space-only before a line break,
|
|
1816
1816
|
* the start will be the start of the line.
|
|
1817
1817
|
* @param {string} source
|
|
1818
1818
|
* @param {LabeledStatement} node
|
|
@@ -27,6 +27,9 @@ const visitors = {
|
|
|
27
27
|
delete n.typeArguments;
|
|
28
28
|
delete n.returnType;
|
|
29
29
|
delete n.accessibility;
|
|
30
|
+
delete n.readonly;
|
|
31
|
+
delete n.definite;
|
|
32
|
+
delete n.override;
|
|
30
33
|
},
|
|
31
34
|
Decorator(node) {
|
|
32
35
|
e.typescript_invalid_feature(node, 'decorators (related TSC proposal is not stage 4 yet)');
|
|
@@ -132,7 +135,14 @@ const visitors = {
|
|
|
132
135
|
if (node.declare) {
|
|
133
136
|
return b.empty;
|
|
134
137
|
}
|
|
138
|
+
delete node.abstract;
|
|
135
139
|
delete node.implements;
|
|
140
|
+
delete node.superTypeArguments;
|
|
141
|
+
return context.next();
|
|
142
|
+
},
|
|
143
|
+
ClassExpression(node, context) {
|
|
144
|
+
delete node.implements;
|
|
145
|
+
delete node.superTypeArguments;
|
|
136
146
|
return context.next();
|
|
137
147
|
},
|
|
138
148
|
MethodDefinition(node, context) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @import { Pattern } from 'estree' */
|
|
2
2
|
/** @import { AST } from '#compiler' */
|
|
3
3
|
/** @import { ComponentContext } from '../types' */
|
|
4
|
+
/** @import { ExpressionMetadata } from '../../../nodes.js' */
|
|
4
5
|
import { dev } from '../../../../state.js';
|
|
5
6
|
import { extract_identifiers } from '../../../../utils/ast.js';
|
|
6
7
|
import * as b from '#compiler/builders';
|
|
@@ -30,7 +31,7 @@ export function ConstTag(node, context) {
|
|
|
30
31
|
context.state,
|
|
31
32
|
declaration.id,
|
|
32
33
|
expression,
|
|
33
|
-
node.metadata.expression
|
|
34
|
+
node.metadata.expression,
|
|
34
35
|
context.state.scope.get_bindings(declaration)
|
|
35
36
|
);
|
|
36
37
|
} else {
|
|
@@ -73,7 +74,7 @@ export function ConstTag(node, context) {
|
|
|
73
74
|
context.state,
|
|
74
75
|
tmp,
|
|
75
76
|
expression,
|
|
76
|
-
node.metadata.expression
|
|
77
|
+
node.metadata.expression,
|
|
77
78
|
context.state.scope.get_bindings(declaration)
|
|
78
79
|
);
|
|
79
80
|
|
|
@@ -89,15 +90,18 @@ export function ConstTag(node, context) {
|
|
|
89
90
|
* @param {ComponentContext['state']} state
|
|
90
91
|
* @param {import('estree').Identifier} id
|
|
91
92
|
* @param {import('estree').Expression} expression
|
|
92
|
-
* @param {
|
|
93
|
+
* @param {ExpressionMetadata} metadata
|
|
93
94
|
* @param {import('#compiler').Binding[]} bindings
|
|
94
95
|
*/
|
|
95
|
-
function add_const_declaration(state, id, expression,
|
|
96
|
+
function add_const_declaration(state, id, expression, metadata, bindings) {
|
|
96
97
|
// we need to eagerly evaluate the expression in order to hit any
|
|
97
98
|
// 'Cannot access x before initialization' errors
|
|
98
99
|
const after = dev ? [b.stmt(b.call('$.get', id))] : [];
|
|
99
100
|
|
|
100
|
-
|
|
101
|
+
const has_await = metadata.has_await;
|
|
102
|
+
const blockers = [...metadata.dependencies].map((dep) => dep.blocker).filter((b) => b !== null);
|
|
103
|
+
|
|
104
|
+
if (has_await || state.async_consts || blockers.length > 0) {
|
|
101
105
|
const run = (state.async_consts ??= {
|
|
102
106
|
id: b.id(state.scope.generate('promises')),
|
|
103
107
|
thunks: []
|
|
@@ -108,6 +112,8 @@ function add_const_declaration(state, id, expression, has_await, bindings) {
|
|
|
108
112
|
const assignment = b.assignment('=', id, expression);
|
|
109
113
|
const body = after.length === 0 ? assignment : b.block([b.stmt(assignment), ...after]);
|
|
110
114
|
|
|
115
|
+
if (blockers.length > 0) run.thunks.push(b.thunk(b.call('Promise.all', b.array(blockers))));
|
|
116
|
+
|
|
111
117
|
run.thunks.push(b.thunk(body, has_await));
|
|
112
118
|
|
|
113
119
|
const blocker = b.member(run.id, b.literal(run.thunks.length - 1), true);
|
|
@@ -305,7 +305,7 @@ export function VariableDeclaration(node, context) {
|
|
|
305
305
|
if (has_props) {
|
|
306
306
|
if (declarator.id.type !== 'Identifier') {
|
|
307
307
|
// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
|
|
308
|
-
// means that foo and bar are the props (i.e. the
|
|
308
|
+
// means that foo and bar are the props (i.e. the leaves are the prop names), not x and z.
|
|
309
309
|
const tmp = b.id(context.state.scope.generate('tmp'));
|
|
310
310
|
const { inserts, paths } = extract_paths(declarator.id, tmp);
|
|
311
311
|
|
|
@@ -13,8 +13,11 @@ export function ConstTag(node, context) {
|
|
|
13
13
|
const id = /** @type {Pattern} */ (context.visit(declaration.id));
|
|
14
14
|
const init = /** @type {Expression} */ (context.visit(declaration.init));
|
|
15
15
|
const has_await = node.metadata.expression.has_await;
|
|
16
|
+
const blockers = [...node.metadata.expression.dependencies]
|
|
17
|
+
.map((dep) => dep.blocker)
|
|
18
|
+
.filter((b) => b !== null);
|
|
16
19
|
|
|
17
|
-
if (has_await || context.state.async_consts) {
|
|
20
|
+
if (has_await || context.state.async_consts || blockers.length > 0) {
|
|
18
21
|
const run = (context.state.async_consts ??= {
|
|
19
22
|
id: b.id(context.state.scope.generate('promises')),
|
|
20
23
|
thunks: []
|
|
@@ -27,6 +30,10 @@ export function ConstTag(node, context) {
|
|
|
27
30
|
context.state.init.push(b.let(identifier.name));
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
if (blockers.length > 0) {
|
|
34
|
+
run.thunks.push(b.thunk(b.call('Promise.all', b.array(blockers))));
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
const assignment = b.assignment('=', id, init);
|
|
31
38
|
run.thunks.push(b.thunk(b.block([b.stmt(assignment)]), has_await));
|
|
32
39
|
|
|
@@ -119,7 +119,7 @@ export function VariableDeclaration(node, context) {
|
|
|
119
119
|
if (has_props) {
|
|
120
120
|
if (declarator.id.type !== 'Identifier') {
|
|
121
121
|
// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
|
|
122
|
-
// means that foo and bar are the props (i.e. the
|
|
122
|
+
// means that foo and bar are the props (i.e. the leaves are the prop names), not x and z.
|
|
123
123
|
const tmp = b.id(context.state.scope.generate('tmp'));
|
|
124
124
|
const { inserts, paths } = extract_paths(declarator.id, tmp);
|
|
125
125
|
|
|
@@ -35,7 +35,7 @@ export function transform_body(instance_body, runner, transform) {
|
|
|
35
35
|
(node) => /** @type {ESTree.Statement | ESTree.VariableDeclaration} */ (transform(node))
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
-
// Declarations for the await expressions (they will
|
|
38
|
+
// Declarations for the await expressions (they will assign to them; need to be hoisted to be available in whole instance scope)
|
|
39
39
|
if (instance_body.declarations.length > 0) {
|
|
40
40
|
statements.push(
|
|
41
41
|
b.declaration(
|
|
@@ -53,23 +53,22 @@ export function transform_body(instance_body, runner, transform) {
|
|
|
53
53
|
transform(b.var(s.node.id, s.node.init))
|
|
54
54
|
);
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
const statements = visited.declarations.map((node) => {
|
|
57
|
+
if (node.id.type === 'Identifier' && node.id.name.startsWith('$$d')) {
|
|
58
|
+
// this is an intermediate declaration created in VariableDeclaration.js;
|
|
59
|
+
// subsequent statements depend on it
|
|
60
|
+
return b.var(node.id, node.init);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return b.stmt(b.assignment('=', node.id, node.init ?? b.void0));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (statements.length === 1) {
|
|
67
|
+
const statement = /** @type {ESTree.ExpressionStatement} */ (statements[0]);
|
|
68
|
+
return b.thunk(statement.expression, s.has_await);
|
|
61
69
|
}
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
return b.thunk(
|
|
65
|
-
b.block([
|
|
66
|
-
b.var(visited.declarations[0].id, visited.declarations[0].init),
|
|
67
|
-
...visited.declarations
|
|
68
|
-
.slice(1)
|
|
69
|
-
.map((d) => b.stmt(b.assignment('=', d.id, d.init ?? b.void0)))
|
|
70
|
-
]),
|
|
71
|
-
s.has_await
|
|
72
|
-
);
|
|
71
|
+
return b.thunk(b.block(statements), s.has_await);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
if (s.node.type === 'ClassDeclaration') {
|