Skip to content

Commit 58cbd9e

Browse files
committed
merge main
2 parents d77120a + cd56c1d commit 58cbd9e

File tree

28 files changed

+195
-110
lines changed

28 files changed

+195
-110
lines changed

packages/svelte/CHANGELOG.md

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

3+
## 5.22.1
4+
5+
### Patch Changes
6+
7+
- chore: switch acorn-typescript plugin ([#15393](https://github.com/sveltejs/svelte/pull/15393))
8+
9+
## 5.22.0
10+
11+
### Minor Changes
12+
13+
- feat: Add `idPrefix` option to `render` ([#15428](https://github.com/sveltejs/svelte/pull/15428))
14+
15+
### Patch Changes
16+
17+
- fix: make dialog element and role interactive ([#15429](https://github.com/sveltejs/svelte/pull/15429))
18+
319
## 5.21.0
420

521
### Minor Changes

packages/svelte/package.json

Lines changed: 2 additions & 2 deletions
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.21.0",
5+
"version": "5.22.1",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {
@@ -150,7 +150,7 @@
150150
"@jridgewell/sourcemap-codec": "^1.5.0",
151151
"@types/estree": "^1.0.5",
152152
"acorn": "^8.12.1",
153-
"acorn-typescript": "^1.4.13",
153+
"@sveltejs/acorn-typescript": "^1.0.5",
154154
"aria-query": "^5.3.1",
155155
"axobject-query": "^4.1.0",
156156
"clsx": "^2.1.1",

packages/svelte/src/compiler/phases/1-parse/acorn.js

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/** @import { Comment, Program } from 'estree' */
2-
/** @import { Node } from 'acorn' */
32
import * as acorn from 'acorn';
43
import { walk } from 'zimmerframe';
5-
import { tsPlugin } from 'acorn-typescript';
6-
import { locator } from '../../state.js';
4+
import { tsPlugin } from '@sveltejs/acorn-typescript';
75

8-
const ParserWithTS = acorn.Parser.extend(tsPlugin({ allowSatisfies: true }));
6+
const ParserWithTS = acorn.Parser.extend(tsPlugin());
97

108
/**
119
* @param {string} source
@@ -48,7 +46,6 @@ export function parse(source, typescript, is_script) {
4846
}
4947
}
5048

51-
if (typescript) amend(source, ast);
5249
add_comments(ast);
5350

5451
return /** @type {Program} */ (ast);
@@ -71,7 +68,6 @@ export function parse_expression_at(source, typescript, index) {
7168
locations: true
7269
});
7370

74-
if (typescript) amend(source, ast);
7571
add_comments(ast);
7672

7773
return ast;
@@ -173,42 +169,3 @@ function get_comment_handlers(source) {
173169
}
174170
};
175171
}
176-
177-
/**
178-
* Tidy up some stuff left behind by acorn-typescript
179-
* @param {string} source
180-
* @param {Node} node
181-
*/
182-
function amend(source, node) {
183-
return walk(node, null, {
184-
_(node, context) {
185-
// @ts-expect-error
186-
delete node.loc.start.index;
187-
// @ts-expect-error
188-
delete node.loc.end.index;
189-
190-
if (typeof node.loc?.end === 'number') {
191-
const loc = locator(node.loc.end);
192-
if (loc) {
193-
node.loc.end = {
194-
line: loc.line,
195-
column: loc.column
196-
};
197-
}
198-
}
199-
200-
if (
201-
/** @type {any} */ (node).typeAnnotation &&
202-
(node.end === undefined || node.end < node.start)
203-
) {
204-
// i think there might be a bug in acorn-typescript that prevents
205-
// `end` from being assigned when there's a type annotation
206-
let end = /** @type {any} */ (node).typeAnnotation.start;
207-
while (/\s/.test(source[end - 1])) end -= 1;
208-
node.end = end;
209-
}
210-
211-
context.next();
212-
}
213-
});
214-
}

packages/svelte/src/compiler/phases/1-parse/ambient.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const non_interactive_roles = non_abstract_roles
3030
// 'generic' is meant to have no semantic meaning.
3131
// 'cell' is treated as CellRole by the AXObject which is interactive, so we treat 'cell' it as interactive as well.
3232
!['toolbar', 'tabpanel', 'generic', 'cell'].includes(name) &&
33-
!role?.superClass.some((classes) => classes.includes('widget'))
33+
!role?.superClass.some((classes) => classes.includes('widget') || classes.includes('window'))
3434
);
3535
})
3636
.concat(

packages/svelte/src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ComponentConstructorOptions<
1919
intro?: boolean;
2020
recover?: boolean;
2121
sync?: boolean;
22+
idPrefix?: string;
2223
$$inline?: boolean;
2324
}
2425

packages/svelte/src/internal/client/dom/template.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,6 @@ export function append(anchor, dom) {
250250
anchor.before(/** @type {Node} */ (dom));
251251
}
252252

253-
let uid = 1;
254-
255-
export function reset_props_id() {
256-
uid = 1;
257-
}
258-
259253
/**
260254
* Create (or hydrate) an unique UID for the component instance.
261255
*/
@@ -264,12 +258,16 @@ export function props_id() {
264258
hydrating &&
265259
hydrate_node &&
266260
hydrate_node.nodeType === 8 &&
267-
hydrate_node.textContent?.startsWith('#s')
261+
hydrate_node.textContent?.startsWith(`#`)
268262
) {
269263
const id = hydrate_node.textContent.substring(1);
270264
hydrate_next();
271265
return id;
272266
}
273267

274-
return 'c' + uid++;
268+
// @ts-expect-error This way we ensure the id is unique even across Svelte runtimes
269+
(window.__svelte ??= {}).uid ??= 1;
270+
271+
// @ts-expect-error
272+
return `c${window.__svelte.uid++}`;
275273
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { PUBLIC_VERSION } from '../version.js';
22

3-
if (typeof window !== 'undefined')
4-
// @ts-ignore
5-
(window.__svelte ||= { v: new Set() }).v.add(PUBLIC_VERSION);
3+
if (typeof window !== 'undefined') {
4+
// @ts-expect-error
5+
((window.__svelte ??= {}).v ??= new Set()).add(PUBLIC_VERSION);
6+
}

packages/svelte/src/internal/server/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,26 @@ export function element(payload, tag, attributes_fn = noop, children_fn = noop)
8686
*/
8787
export let on_destroy = [];
8888

89-
function props_id_generator() {
89+
/**
90+
* Creates an ID generator
91+
* @param {string} prefix
92+
* @returns {() => string}
93+
*/
94+
function props_id_generator(prefix) {
9095
let uid = 1;
91-
return () => 's' + uid++;
96+
return () => `${prefix}s${uid++}`;
9297
}
9398

9499
/**
95100
* Only available on the server and when compiling with the `server` option.
96101
* Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
97102
* @template {Record<string, any>} Props
98103
* @param {import('svelte').Component<Props> | ComponentType<SvelteComponent<Props>>} component
99-
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }} [options]
104+
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string }} [options]
100105
* @returns {RenderOutput}
101106
*/
102107
export function render(component, options = {}) {
103-
const uid = props_id_generator();
108+
const uid = props_id_generator(options.idPrefix ? options.idPrefix + '-' : '');
104109
/** @type {Payload} */
105110
const payload = {
106111
out: '',

packages/svelte/src/server/index.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ export function render<
1212
...args: {} extends Props
1313
? [
1414
component: Comp extends SvelteComponent<any> ? ComponentType<Comp> : Comp,
15-
options?: { props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }
15+
options?: {
16+
props?: Omit<Props, '$$slots' | '$$events'>;
17+
context?: Map<any, any>;
18+
idPrefix?: string;
19+
}
1620
]
1721
: [
1822
component: Comp extends SvelteComponent<any> ? ComponentType<Comp> : Comp,
19-
options: { props: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }
23+
options: {
24+
props: Omit<Props, '$$slots' | '$$events'>;
25+
context?: Map<any, any>;
26+
idPrefix?: string;
27+
}
2028
]
2129
): RenderOutput;

0 commit comments

Comments
 (0)