Skip to content

Commit d89d54d

Browse files
committed
merge conflict
2 parents e1cfa14 + 3e3ae92 commit d89d54d

File tree

23 files changed

+173
-103
lines changed

23 files changed

+173
-103
lines changed

.changeset/kind-eagles-join.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 children to element typings

.changeset/pre.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"itchy-lions-wash",
3939
"khaki-mails-draw",
4040
"kind-deers-lay",
41+
"kind-eagles-join",
4142
"lazy-spiders-think",
4243
"light-pens-watch",
4344
"long-crews-return",
@@ -76,6 +77,7 @@
7677
"thirty-impalas-repair",
7778
"thirty-wombats-relax",
7879
"tiny-kings-whisper",
80+
"twelve-onions-juggle",
7981
"two-falcons-buy",
8082
"wet-games-fly",
8183
"wicked-clouds-exercise",

.changeset/twelve-onions-juggle.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: handle ts expressions when dealing with runes

CONTRIBUTING.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The maintainers meet on the final Saturday of each month. While these meetings a
4343

4444
### Prioritization
4545

46-
We do our best to review PRs and RFCs as they are sent, but it is difficult to keep up. We welcome help in reviewing PRs, RFC, and issues. If an item aligns with the current priority on our [roadmap](https://svelte.dev/roadmap), it is more likely to be reviewed quickly. PRs to the most important and active ones repositories get reviewed more quickly while PRs to smaller inactive repos may sit for a bit before we periodically come by and review the pending PRs in a batch.
46+
We do our best to review PRs and RFCs as they are sent, but it is difficult to keep up. We welcome help in reviewing PRs, RFCs, and issues. If an item aligns with the current priority on our [roadmap](https://svelte.dev/roadmap), it is more likely to be reviewed quickly. PRs to the most important and active ones repositories get reviewed more quickly while PRs to smaller inactive repos may sit for a bit before we periodically come by and review the pending PRs in a batch.
4747

4848
## Bugs
4949

@@ -74,10 +74,11 @@ Small pull requests are much easier to review and more likely to get merged.
7474

7575
### Installation
7676

77-
1. Ensure you have [pnpm](https://pnpm.io/installation) installed
78-
1. After cloning the repository, run `pnpm install`. You can do this in the root directory or in the `svelte` project
79-
1. Move into the `svelte` directory with `cd packages/svelte`
80-
1. To compile in watch mode, run `pnpm dev`
77+
Ensure you have [pnpm](https://pnpm.io/installation) installed. After cloning the repository, run `pnpm install`.
78+
79+
### Developing
80+
81+
To build the UMD version of `svelte/compiler` (this is only necessary for CommonJS consumers, or in-browser use), run `pnpm build` inside `packages/svelte`. To rebuild whenever source files change, run `pnpm dev`.
8182

8283
### Creating a branch
8384

@@ -100,18 +101,28 @@ Test samples are kept in `/test/xxx/samples` folder.
100101
> PREREQUISITE: Install chromium via playwright by running `pnpm playwright install chromium`
101102
102103
1. To run test, run `pnpm test`.
103-
1. To run test for a specific feature, you can use the `-g` (aka `--grep`) option. For example, to only run test involving transitions, run `pnpm test -- -g transition`.
104+
1. To run a particular test suite, use `pnpm test <suite-name>`, for example:
105+
106+
```bash
107+
pnpm test validator
108+
```
104109

105-
##### Running solo test
110+
1. To filter tests _within_ a test suite, use `pnpm test <suite-name> -- -t <test-name>`, for example:
106111

107-
1. To run only one test, rename the test sample folder to end with `.solo`. For example, to run the `test/js/samples/action` only, rename it to `test/js/samples/action.solo`.
108-
1. To run only one test suite, rename the test suite folder to end with `.solo`. For example, to run the `test/js` test suite only, rename it to `test/js.solo`.
109-
1. Remember to rename the test folder back. The CI will fail if there's a solo test.
112+
```bash
113+
pnpm test validator -- -t a11y-alt-text
114+
```
115+
116+
(You can also do `FILTER=<test-name> pnpm test <suite-name>` which removes other tests rather than simply skipping them — this will result in faster and more compact test results, but it's non-idiomatic. Choose your fighter.)
110117

111118
##### Updating `.expected` files
112119

113-
1. Tests suites like `css`, `js`, `server-side-rendering` asserts that the generated output has to match the content in the `.expected` file. For example, in the `js` test suites, the generated js code is compared against the content in `expected.js`.
114-
1. To update the content of the `.expected` file, run the test with `--update` flag. (`pnpm test --update`)
120+
1. Tests suites like `snapshot` and `parser` assert that the generated output matches the existing snapshot.
121+
1. To update these snapshots, run `UPDATE_SNAPSHOTS=true pnpm test`.
122+
123+
### Typechecking
124+
125+
To typecheck the codebase, run `pnpm check` inside `packages/svelte`. To typecheck in watch mode, run `pnpm check:watch`.
115126

116127
### Style guide
117128

README.md

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,7 @@ You may view [our roadmap](https://svelte.dev/roadmap) if you'd like to see what
2222

2323
## Contributing
2424

25-
Please see the [Contributing Guide](CONTRIBUTING.md) and [svelte package](packages/svelte) for contributing to Svelte.
26-
27-
### Development
28-
29-
Pull requests are encouraged and always welcome. [Pick an issue](https://github.com/sveltejs/svelte/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) and help us out!
30-
31-
To install and work on Svelte locally:
32-
33-
```bash
34-
git clone https://github.com/sveltejs/svelte.git
35-
cd svelte
36-
pnpm install
37-
```
38-
39-
> Do not use Yarn to install the dependencies, as the specific package versions in `pnpm-lock.json` are used to build and test Svelte.
40-
41-
To build the compiler and all the other modules included in the package:
42-
43-
```bash
44-
pnpm build
45-
```
46-
47-
To watch for changes and continually rebuild the package (this is useful if you're using [`pnpm link`](https://pnpm.io/cli/link) to test out changes in a project locally):
48-
49-
```bash
50-
pnpm dev
51-
```
52-
53-
The compiler is written in JavaScript and uses [JSDoc](https://jsdoc.app/index.html) comments for type-checking.
54-
55-
### Running Tests
56-
57-
```bash
58-
pnpm test
59-
```
60-
61-
To filter tests, use `-g` (aka `--grep`). For example, to only run tests involving transitions:
62-
63-
```bash
64-
pnpm test -- -g transition
65-
```
25+
Please see the [Contributing Guide](CONTRIBUTING.md) and the [`svelte`](packages/svelte) package for information on contributing to Svelte.
6626

6727
### svelte.dev
6828

packages/svelte/CHANGELOG.md

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

3+
## 5.0.0-next.15
4+
5+
### Patch Changes
6+
7+
- fix: add children to element typings ([#9679](https://github.com/sveltejs/svelte/pull/9679))
8+
9+
- fix: handle ts expressions when dealing with runes ([#9681](https://github.com/sveltejs/svelte/pull/9681))
10+
311
## 5.0.0-next.14
412

513
### Patch Changes

packages/svelte/elements.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export type MessageEventHandler<T extends EventTarget> = EventHandler<MessageEve
6464
// ----------------------------------------------------------------------
6565

6666
export interface DOMAttributes<T extends EventTarget> {
67+
// Implicit children prop every element has
68+
// Add this here so that libraries doing `$props<HTMLButtonAttributes>()` don't need a separate interface
69+
children?: import('svelte').Snippet<any>;
70+
6771
// Clipboard Events
6872
'on:copy'?: ClipboardEventHandler<T> | undefined | null;
6973
oncopy?: ClipboardEventHandler<T> | undefined | null;

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.0.0-next.14",
5+
"version": "5.0.0-next.15",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {
@@ -91,7 +91,7 @@
9191
],
9292
"scripts": {
9393
"build": "rollup -c && node scripts/build.js && node scripts/check-treeshakeability.js",
94-
"watch": "rollup -cw",
94+
"dev": "rollup -cw",
9595
"check": "tsc && cd ./tests/types && tsc",
9696
"check:watch": "tsc --watch",
9797
"generate:version": "node ./scripts/generate-version.js",

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
extract_paths,
88
is_event_attribute,
99
is_text_attribute,
10-
object
10+
object,
11+
unwrap_ts_expression
1112
} from '../../utils/ast.js';
1213
import * as b from '../../utils/builders.js';
1314
import { ReservedKeywords, Runes, SVGElements } from '../constants.js';
@@ -668,10 +669,11 @@ const runes_scope_tweaker = {
668669
}
669670
},
670671
VariableDeclarator(node, { state }) {
671-
if (node.init?.type !== 'CallExpression') return;
672-
if (get_rune(node.init, state.scope) === null) return;
672+
const init = unwrap_ts_expression(node.init);
673+
if (!init || init.type !== 'CallExpression') return;
674+
if (get_rune(init, state.scope) === null) return;
673675

674-
const callee = node.init.callee;
676+
const callee = init.callee;
675677
if (callee.type !== 'Identifier') return;
676678

677679
const name = callee.name;

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { error } from '../../errors.js';
2-
import { extract_identifiers, is_text_attribute } from '../../utils/ast.js';
2+
import {
3+
extract_identifiers,
4+
get_parent,
5+
is_text_attribute,
6+
unwrap_ts_expression
7+
} from '../../utils/ast.js';
38
import { warn } from '../../warnings.js';
49
import fuzzymatch from '../1-parse/utils/fuzzymatch.js';
510
import { binding_properties } from '../bindings.js';
@@ -491,7 +496,7 @@ function validate_call_expression(node, scope, path) {
491496
const rune = get_rune(node, scope);
492497
if (rune === null) return;
493498

494-
const parent = /** @type {import('#compiler').SvelteNode} */ (path.at(-1));
499+
const parent = /** @type {import('#compiler').SvelteNode} */ (get_parent(path, -1));
495500

496501
if (rune === '$props') {
497502
if (parent.type === 'VariableDeclarator') return;
@@ -703,7 +708,7 @@ export const validation_runes = merge(validation, a11y_validators, {
703708
next({ ...state });
704709
},
705710
VariableDeclarator(node, { state }) {
706-
const init = node.init;
711+
const init = unwrap_ts_expression(node.init);
707712
const rune = get_rune(init, state.scope);
708713

709714
if (rune === null) return;

packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { is_hoistable_function } from '../../utils.js';
33
import * as b from '../../../../utils/builders.js';
44
import * as assert from '../../../../utils/assert.js';
55
import { create_state_declarators, get_props_method } from '../utils.js';
6+
import { unwrap_ts_expression } from '../../../../utils/ast.js';
67

78
/** @type {import('../types.js').ComponentVisitors} */
89
export const javascript_visitors_runes = {
@@ -133,7 +134,7 @@ export const javascript_visitors_runes = {
133134
const declarations = [];
134135

135136
for (const declarator of node.declarations) {
136-
const init = declarator.init;
137+
const init = unwrap_ts_expression(declarator.init);
137138
const rune = get_rune(init, state.scope);
138139
if (
139140
!rune ||
@@ -213,7 +214,8 @@ export const javascript_visitors_runes = {
213214
// TODO
214215
continue;
215216
}
216-
const args = /** @type {import('estree').CallExpression} */ (declarator.init).arguments;
217+
218+
const args = /** @type {import('estree').CallExpression} */ (init).arguments;
217219
const value =
218220
args.length === 0
219221
? b.id('undefined')

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { walk } from 'zimmerframe';
22
import { set_scope, get_rune } from '../../scope.js';
3-
import { extract_identifiers, extract_paths, is_event_attribute } from '../../../utils/ast.js';
3+
import {
4+
extract_identifiers,
5+
extract_paths,
6+
is_event_attribute,
7+
unwrap_ts_expression
8+
} from '../../../utils/ast.js';
49
import * as b from '../../../utils/builders.js';
510
import is_reference from 'is-reference';
611
import {
@@ -568,7 +573,8 @@ const javascript_visitors_runes = {
568573
const declarations = [];
569574

570575
for (const declarator of node.declarations) {
571-
const rune = get_rune(declarator.init, state.scope);
576+
const init = unwrap_ts_expression(declarator.init);
577+
const rune = get_rune(init, state.scope);
572578
if (!rune || rune === '$effect.active' || rune.startsWith('$log')) {
573579
declarations.push(/** @type {import('estree').VariableDeclarator} */ (visit(declarator)));
574580
continue;
@@ -579,7 +585,7 @@ const javascript_visitors_runes = {
579585
continue;
580586
}
581587

582-
const args = /** @type {import('estree').CallExpression} */ (declarator.init).arguments;
588+
const args = /** @type {import('estree').CallExpression} */ (init).arguments;
583589
const value =
584590
args.length === 0
585591
? b.id('undefined')

packages/svelte/src/compiler/utils/ast.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,42 @@ function _extract_paths(assignments = [], param, expression, update_expression)
265265

266266
return assignments;
267267
}
268+
269+
/**
270+
* The Acorn TS plugin defines `foo!` as a `TSNonNullExpression` node, and
271+
* `foo as Bar` as a `TSAsExpression` node. This function unwraps those.
272+
*
273+
* @template {import('#compiler').SvelteNode | undefined | null} T
274+
* @param {T} node
275+
* @returns {T}
276+
*/
277+
export function unwrap_ts_expression(node) {
278+
if (!node) {
279+
return node;
280+
}
281+
282+
// @ts-expect-error these types don't exist on the base estree types
283+
if (node.type === 'TSNonNullExpression' || node.type === 'TSAsExpression') {
284+
// @ts-expect-error
285+
return node.expression;
286+
}
287+
288+
return node;
289+
}
290+
291+
/**
292+
* Like `path.at(x)`, but skips over `TSNonNullExpression` and `TSAsExpression` nodes and eases assertions a bit
293+
* by removing the `| undefined` from the resulting type.
294+
*
295+
* @template {import('#compiler').SvelteNode} T
296+
* @param {T[]} path
297+
* @param {number} at
298+
*/
299+
export function get_parent(path, at) {
300+
let node = path.at(at);
301+
// @ts-expect-error
302+
if (node.type === 'TSNonNullExpression' || node.type === 'TSAsExpression') {
303+
return /** @type {T} */ (path.at(at < 0 ? at - 1 : at + 1));
304+
}
305+
return /** @type {T} */ (node);
306+
}

packages/svelte/src/internal/client/render.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,6 +2918,7 @@ export function unwrap(value) {
29182918
* @param {{
29192919
* target: Node;
29202920
* props?: Props;
2921+
* events?: Events;
29212922
* context?: Map<any, any>;
29222923
* intro?: boolean;
29232924
* immutable?: boolean;

packages/svelte/src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* https://svelte.dev/docs/svelte-compiler#svelte-version
77
* @type {string}
88
*/
9-
export const VERSION = '5.0.0-next.14';
9+
export const VERSION = '5.0.0-next.15';
1010
export const PUBLIC_VERSION = '5';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: '1 2'
5+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script lang="ts">
2+
let count = $state(1) as number;
3+
let double = $derived(count as number * 2) as number;
4+
</script>
5+
6+
{count as number} {double as number}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: '1 2'
5+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script lang="ts">
2+
let count = $state(1)!;
3+
let double = $derived(count! * 2)!;
4+
</script>
5+
6+
{count!} {double!}

0 commit comments

Comments
 (0)