Skip to content

Commit 6b3618e

Browse files
committed
Merge branch 'main' into better-ssr-hydration-error
2 parents e39c425 + e97bc79 commit 6b3618e

File tree

61 files changed

+744
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+744
-234
lines changed

.changeset/eight-pianos-raise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: add backwards-compat for old warning codes in legacy mode

.changeset/eighty-lizards-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
chore: improve runtime overhead of creating comment templates

.changeset/empty-flowers-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: replicate Svelte 4 props update detection in legacy mode

.changeset/good-roses-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: correctly handle falsy values of style directives in SSR mode

.changeset/plenty-zoos-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: improve handling of lazy image elements

.changeset/popular-apes-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: skip deriveds for props with known safe calls

.changeset/pre.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,18 @@
9898
"early-ads-tie",
9999
"early-months-whisper",
100100
"eight-hornets-punch",
101+
"eight-pianos-raise",
101102
"eight-steaks-shout",
102103
"eighty-bikes-camp",
103104
"eighty-days-cheat",
105+
"eighty-lizards-notice",
104106
"eleven-beers-yell",
105107
"eleven-cycles-applaud",
106108
"empty-bags-heal",
107109
"empty-bulldogs-exercise",
108110
"empty-coins-build",
109111
"empty-crabs-think",
112+
"empty-flowers-change",
110113
"empty-geckos-pretend",
111114
"empty-tools-share",
112115
"fair-bags-smoke",
@@ -152,6 +155,7 @@
152155
"gentle-sheep-hug",
153156
"gentle-spies-happen",
154157
"gentle-toys-chew",
158+
"gentle-trees-exercise",
155159
"giant-bananas-turn",
156160
"giant-moons-own",
157161
"giant-planets-shake",
@@ -163,6 +167,7 @@
163167
"good-pianos-jump",
164168
"good-plums-type",
165169
"good-rivers-yawn",
170+
"good-roses-argue",
166171
"gorgeous-monkeys-carry",
167172
"gorgeous-singers-rest",
168173
"great-fans-unite",
@@ -302,12 +307,14 @@
302307
"pink-goats-promise",
303308
"pink-mayflies-tie",
304309
"plenty-starfishes-dress",
310+
"plenty-zoos-fix",
305311
"polite-dolphins-care",
306312
"polite-pumpkins-guess",
307313
"polite-ravens-study",
308314
"poor-eggs-enjoy",
309315
"poor-hats-design",
310316
"poor-seahorses-flash",
317+
"popular-apes-bathe",
311318
"popular-ligers-perform",
312319
"popular-mangos-rest",
313320
"popular-walls-hunt",

eslint.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ export default [
4343
'documentation',
4444
// contains a fork of the REPL which doesn't adhere to eslint rules
4545
'sites/svelte-5-preview/**',
46+
'playgrounds/demo/src/**',
47+
'tmp/**',
4648
// wasn't checked previously, reenable at some point
47-
'sites/svelte.dev/**',
48-
'tmp/**'
49+
'sites/svelte.dev/**'
4950
]
5051
}
5152
];

packages/svelte/CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# svelte
22

3+
## 5.0.0-next.133
4+
5+
### Patch Changes
6+
7+
- fix: add backwards-compat for old warning codes in legacy mode ([#11607](https://github.com/sveltejs/svelte/pull/11607))
8+
9+
## 5.0.0-next.132
10+
11+
### Patch Changes
12+
13+
- chore: improve runtime overhead of creating comment templates ([#11591](https://github.com/sveltejs/svelte/pull/11591))
14+
15+
- fix: replicate Svelte 4 props update detection in legacy mode ([#11577](https://github.com/sveltejs/svelte/pull/11577))
16+
17+
- fix: allow for non optional chain call expression in render ([#11578](https://github.com/sveltejs/svelte/pull/11578))
18+
19+
- fix: correctly handle falsy values of style directives in SSR mode ([#11583](https://github.com/sveltejs/svelte/pull/11583))
20+
21+
- fix: improve handling of lazy image elements ([#11593](https://github.com/sveltejs/svelte/pull/11593))
22+
23+
- fix: skip deriveds for props with known safe calls ([#11595](https://github.com/sveltejs/svelte/pull/11595))
24+
325
## 5.0.0-next.131
426

527
### Patch Changes
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## legacy_code
2+
3+
> `%code%` is no longer valid — please use `%suggestion%` instead
4+
5+
## unknown_code
6+
7+
> `%code%` is not a recognised code
8+
9+
> `%code%` is not a recognised code (did you mean `%suggestion%`?)

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.0.0-next.131",
5+
"version": "5.0.0-next.133",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/scripts/process-messages/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function transform(name, dest) {
6161

6262
const comments = [];
6363

64-
const ast = acorn.parse(source, {
64+
let ast = acorn.parse(source, {
6565
ecmaVersion: 'latest',
6666
sourceType: 'module',
6767
onComment: (block, value, start, end) => {
@@ -80,7 +80,7 @@ function transform(name, dest) {
8080
}
8181
});
8282

83-
walk(ast, null, {
83+
ast = walk(ast, null, {
8484
_(node, { next }) {
8585
let comment;
8686

@@ -100,6 +100,18 @@ function transform(name, dest) {
100100
node.trailingComments = [comments.shift()];
101101
}
102102
}
103+
},
104+
// @ts-expect-error
105+
Identifier(node, context) {
106+
if (node.name === 'CODES') {
107+
return {
108+
type: 'ArrayExpression',
109+
elements: Object.keys(messages[name]).map((code) => ({
110+
type: 'Literal',
111+
value: code
112+
}))
113+
};
114+
}
103115
}
104116
});
105117

packages/svelte/scripts/process-messages/templates/compile-warnings.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
1-
import { getLocator } from 'locate-character';
1+
import { filename, locator, warnings, ignore_stack } from './state.js';
22

33
/** @typedef {{ start?: number, end?: number }} NodeLike */
44

5-
/** @type {import('#compiler').Warning[]} */
6-
let warnings = [];
7-
8-
/** @type {string | undefined} */
9-
let filename;
10-
11-
let locator = getLocator('', { offsetLine: 1 });
12-
13-
/**
14-
* @param {{
15-
* source: string;
16-
* filename: string | undefined;
17-
* }} options
18-
* @returns {import('#compiler').Warning[]}
19-
*/
20-
export function reset_warnings(options) {
21-
filename = options.filename;
22-
locator = getLocator(options.source, { offsetLine: 1 });
23-
24-
return (warnings = []);
25-
}
26-
275
/**
286
* @param {null | NodeLike} node
297
* @param {string} code
308
* @param {string} message
319
*/
3210
function w(node, code, message) {
33-
// @ts-expect-error
34-
if (node?.ignores?.has(code)) return;
11+
if (ignore_stack.at(-1)?.has(code)) return;
3512

3613
warnings.push({
3714
code,
@@ -42,6 +19,8 @@ function w(node, code, message) {
4219
});
4320
}
4421

22+
export const codes = CODES;
23+
4524
/**
4625
* MESSAGE
4726
* @param {null | NodeLike} node

packages/svelte/src/compiler/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getLocator } from 'locate-character';
21
import { walk as zimmerframe_walk } from 'zimmerframe';
32
import { CompileError } from './errors.js';
43
import { convert } from './legacy.js';
@@ -8,7 +7,7 @@ import { remove_typescript_nodes } from './phases/1-parse/remove_typescript_node
87
import { analyze_component, analyze_module } from './phases/2-analyze/index.js';
98
import { transform_component, transform_module } from './phases/3-transform/index.js';
109
import { validate_component_options, validate_module_options } from './validate-options.js';
11-
import { reset_warnings } from './warnings.js';
10+
import * as state from './state.js';
1211
export { default as preprocess } from './preprocess/index.js';
1312

1413
/**
@@ -21,7 +20,8 @@ export { default as preprocess } from './preprocess/index.js';
2120
*/
2221
export function compile(source, options) {
2322
try {
24-
const warnings = reset_warnings({ source, filename: options.filename });
23+
state.reset({ source, filename: options.filename });
24+
2525
const validated = validate_component_options(options, '');
2626
let parsed = _parse(source);
2727

@@ -44,9 +44,7 @@ export function compile(source, options) {
4444
}
4545

4646
const analysis = analyze_component(parsed, source, combined_options);
47-
4847
const result = transform_component(analysis, source, combined_options);
49-
result.warnings = warnings;
5048
result.ast = to_public_ast(source, parsed, options.modernAst);
5149
return result;
5250
} catch (e) {
@@ -68,11 +66,11 @@ export function compile(source, options) {
6866
*/
6967
export function compileModule(source, options) {
7068
try {
71-
const warnings = reset_warnings({ source, filename: options.filename });
69+
state.reset({ source, filename: options.filename });
70+
7271
const validated = validate_module_options(options, '');
7372
const analysis = analyze_module(parse_acorn(source, false), validated);
7473
const result = transform_module(analysis, source, validated);
75-
result.warnings = warnings;
7674
return result;
7775
} catch (e) {
7876
if (e instanceof CompileError) {
@@ -92,10 +90,8 @@ function handle_compile_error(error, filename, source) {
9290
error.filename = filename;
9391

9492
if (error.position) {
95-
// TODO this is reused with warnings — DRY out
96-
const locator = getLocator(source, { offsetLine: 1 });
97-
const start = locator(error.position[0]);
98-
const end = locator(error.position[1]);
93+
const start = state.locator(error.position[0]);
94+
const end = state.locator(error.position[1]);
9995

10096
error.start = start;
10197
error.end = end;
@@ -142,6 +138,8 @@ function handle_compile_error(error, filename, source) {
142138
* @returns {import('#compiler').Root | import('./types/legacy-nodes.js').LegacyRoot}
143139
*/
144140
export function parse(source, options = {}) {
141+
state.reset({ source, filename: options.filename });
142+
145143
/** @type {import('#compiler').Root} */
146144
let ast;
147145
try {

packages/svelte/src/compiler/legacy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export function convert(source, ast) {
201201
Comment(node) {
202202
return {
203203
...node,
204-
ignores: extract_svelte_ignore(node.data)
204+
ignores: extract_svelte_ignore(node.start, node.data, false)
205205
};
206206
},
207207
ComplexSelector(node) {

packages/svelte/src/compiler/migrate/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { parse } from '../phases/1-parse/index.js';
44
import { analyze_component } from '../phases/2-analyze/index.js';
55
import { validate_component_options } from '../validate-options.js';
66
import { get_rune } from '../phases/scope.js';
7-
import { reset_warnings } from '../warnings.js';
7+
import { reset } from '../state.js';
88
import { extract_identifiers } from '../utils/ast.js';
99
import { regex_is_valid_identifier } from '../phases/patterns.js';
10+
import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
1011

1112
/**
1213
* Does a best-effort migration of Svelte code towards using runes, event attributes and render tags.
@@ -17,7 +18,7 @@ import { regex_is_valid_identifier } from '../phases/patterns.js';
1718
*/
1819
export function migrate(source) {
1920
try {
20-
reset_warnings({ source, filename: 'migrate.svelte' });
21+
reset({ source, filename: 'migrate.svelte' });
2122

2223
let parsed = parse(source);
2324

@@ -174,6 +175,21 @@ export function migrate(source) {
174175

175176
/** @type {import('zimmerframe').Visitors<import('../types/template.js').SvelteNode, State>} */
176177
const instance_script = {
178+
_(node, { state, next }) {
179+
// @ts-expect-error
180+
const comments = node.leadingComments;
181+
if (comments) {
182+
for (const comment of comments) {
183+
if (comment.type === 'Line') {
184+
const migrated = migrate_svelte_ignore(comment.value);
185+
if (migrated !== comment.value) {
186+
state.str.overwrite(comment.start + '//'.length, comment.end, migrated);
187+
}
188+
}
189+
}
190+
}
191+
next();
192+
},
177193
Identifier(node, { state }) {
178194
handle_identifier(node, state);
179195
},
@@ -474,6 +490,12 @@ const template = {
474490
} else {
475491
state.str.update(node.start, node.end, `{@render ${name}?.(${slot_props})}`);
476492
}
493+
},
494+
Comment(node, { state }) {
495+
const migrated = migrate_svelte_ignore(node.data);
496+
if (migrated !== node.data) {
497+
state.str.overwrite(node.start + '<!--'.length, node.end - '-->'.length, migrated);
498+
}
477499
}
478500
};
479501

0 commit comments

Comments
 (0)