Skip to content

Commit

Permalink
update type generation script (#8712)
Browse files Browse the repository at this point in the history
* chore: playground (#8648)

* initialize playground

* pnpm up

* tidy up git ignore

* remove fluff

* format

* rm readme

* fix jsconfig error

* add skip-worktree instructions

* reload hack

* simplify

* use rollup

* ughh

* add flag for SSR

* ...

* simplify further

* configure launch.json

* add debugger info to readme

* remove vm modules flag

* use replaceAll instead of replace

* tidy up

* fix: make it run

* add watch to launch config

* Generate type declarations with `dts-buddy` (#8702)

* use dts-buddy

* remove debug output

* remove existing type generation script

* fix package.json

* update gitignore

* bump dts-buddy

* remove unused action entry point

* add svelte/compiler and svelte/types/compiler/preprocess modules

* bump dts-buddy

* annoying

* changeset

* bump dts-buddy

* get rid of .d.ts files

* another one

* Update packages/svelte/package.json

Co-authored-by: gtmnayan <50981692+gtm-nayan@users.noreply.github.com>

---------

Co-authored-by: Rich Harris <git@rich-harris.dev>
Co-authored-by: gtmnayan <50981692+gtm-nayan@users.noreply.github.com>

* fix: export ComponentType (#8694)

* fix: export ComponentType

* ughh

* changeset

* fix: derived types (#8700)

* fix: derived store types

* changeset

* Version Packages (next) (#8709)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* update type generation script

* remove unused stuff

* fix: changeset publish script isn't called release anymore (#8711)

* chore: remove prepare script (#8713)

* chore: fix release workflow (#8716)

* More readable, Fix $$_attributes

* Fix types (#8727)

* put comment in right place

* bump dts-buddy

---------

Co-authored-by: Rich Harris <git@rich-harris.dev>

* build types

* add svelte/compiler types

* remove prepare script

* fix

* typo

* squelch errors

* Add svelte and kit to twoslash's types field

* squelch more stuff

* Add errors to account for new types

* Remove deps

* formatting tweak

* fix linting, maybe

* the hell

* gah

* Fix types a bit

* bump dts-buddy

* pnpm generate in dev mode

* Cache again

* reduce index

* bump dts-buddy

* remove comment

---------

Co-authored-by: gtmnayan <50981692+gtm-nayan@users.noreply.github.com>
Co-authored-by: Rich Harris <git@rich-harris.dev>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dominik G <dominik.goepel@gmx.de>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Puru Vijay <devpuruvj@gmail.com>
  • Loading branch information
8 people committed Jun 14, 2023
1 parent 744c596 commit b1cafc4
Show file tree
Hide file tree
Showing 25 changed files with 104 additions and 353 deletions.
2 changes: 1 addition & 1 deletion documentation/docs/03-runtime/02-svelte-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ declare global {
export {};

// @filename: index.ts
// @errors: 18046
// @errors: 18046 2769 7006
// ---cut---
import { derived } from 'svelte/store';

Expand Down
3 changes: 2 additions & 1 deletion documentation/docs/03-runtime/07-svelte-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Sometimes actions emit custom events and apply custom attributes to the element
<!--- file: App.svelte --->
<script>
/**
* @type {import('svelte/action').Action<HTMLDivElement, { prop: any }, { 'on:emit': (e: CustomEvent<string>) => void }>} */
* @type {import('svelte/action').Action<HTMLDivElement, { prop: any }, { 'on:emit': (e: CustomEvent<string>) => void }>}
*/
function foo(node, { prop }) {
// the node has been mounted in the DOM
Expand Down
5 changes: 5 additions & 0 deletions documentation/docs/04-compiler-and-api/01-svelte-compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ Multiple preprocessors can be used together. The output of the first becomes the
> In Svelte 3, all `markup` functions ran first, then all `script` and then all `style` preprocessors. This order was changed in Svelte 4.
```js
// @errors: 2322
// @filename: ambient.d.ts
declare global {
var source: string;
Expand Down Expand Up @@ -398,3 +399,7 @@ The current version, as set in package.json.
import { VERSION } from 'svelte/compiler';
console.log(`running svelte version ${VERSION}`);
```
## Types
> TYPES: svelte/compiler
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ title: 'Client-side component API'
## Creating a component

```ts
// @filename: ambiend.d.ts
// @errors: 2554
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -14,14 +15,16 @@ declare global {
}

// @filename: index.ts
// @errors: 2554
// ---cut---
const component = new Component(options);
```

A client-side component — that is, a component compiled with `generate: 'dom'` (or the `generate` option left unspecified) is a JavaScript class.

```ts
// @filename: ambiend.d.ts
// @errors: 2554
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare module './App.svelte' {
Expand All @@ -30,6 +33,7 @@ declare module './App.svelte' {
}

// @filename: index.ts
// @errors: 2554
// ---cut---
import App from './App.svelte';

Expand Down Expand Up @@ -63,7 +67,7 @@ Whereas children of `target` are normally left alone, `hydrate: true` will cause
The existing DOM doesn't need to match the component — Svelte will 'repair' the DOM as it goes.

```ts
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare module './App.svelte' {
Expand All @@ -72,7 +76,7 @@ declare module './App.svelte' {
}

// @filename: index.ts
// @errors: 2322
// @errors: 2322 2554
// ---cut---
import App from './App.svelte';

Expand All @@ -85,7 +89,7 @@ const app = new App({
## `$set`

```ts
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -106,7 +110,7 @@ Programmatically sets props on an instance. `component.$set({ x: 1 })` is equiva
Calling this method schedules an update for the next microtask — the DOM is _not_ updated synchronously.

```ts
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -124,7 +128,7 @@ component.$set({ answer: 42 });
## `$on`

```ts
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -146,7 +150,7 @@ Causes the `callback` function to be called whenever the component dispatches an
A function is returned that will remove the event listener when called.

```ts
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -168,7 +172,7 @@ off();
## `$destroy`

```js
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -188,7 +192,7 @@ Removes a component from the DOM and triggers any `onDestroy` handlers.
## Component props

```js
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -199,12 +203,13 @@ declare global {
export {}

// @filename: index.ts
// @errors: 2339
// ---cut---
component.prop;
```

```js
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -216,6 +221,7 @@ declare global {
export {}

// @filename: index.ts
// @errors: 2339
// ---cut---
component.prop = value;
```
Expand All @@ -225,7 +231,7 @@ If a component is compiled with `accessors: true`, each instance will have gette
By default, `accessors` is `false`, unless you're compiling as a custom element.

```js
// @filename: ambiend.d.ts
// @filename: ambient.d.ts
import { SvelteComponent, ComponentConstructorOptions } from 'svelte';

declare global {
Expand All @@ -237,6 +243,7 @@ declare global {
export {}

// @filename: index.ts
// @errors: 2339
// ---cut---
console.log(component.count);
component.count += 1;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"test": "pnpm test -r --filter=./packages/*",
"build": "pnpm -r build",
"check": "pnpm -r check",
"check": "cd packages/svelte && pnpm build && cd ../../ && pnpm -r check",
"lint": "pnpm -r lint",
"format": "pnpm -r format",
"changeset:version": "changeset version && pnpm -r generate:version && git add --all",
Expand All @@ -30,4 +30,4 @@
"prettier-plugin-svelte": "^2.10.0"
},
"packageManager": "pnpm@8.6.0"
}
}
4 changes: 2 additions & 2 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"agadoo": "^3.0.0",
"dts-buddy": "^0.1.2",
"dts-buddy": "^0.1.6",
"esbuild": "^0.17.19",
"happy-dom": "^9.18.3",
"jsdom": "^21.1.1",
Expand All @@ -137,4 +137,4 @@
"util": "^0.12.5",
"vitest": "^0.31.1"
}
}
}
12 changes: 6 additions & 6 deletions packages/svelte/src/runtime/action/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
* ```ts
* interface Attributes {
* newprop?: string;
* 'on:event': (e: CustomEvent<boolean>) => void;
* 'on:event': (e: CustomEvent<boolean>) => void;
* }
*
* export function myAction(node: HTMLElement, parameter: Parameter): ActionReturn<Parameter, Attributes> {
* // ...
* return {
* update: (updatedParameter) => {...},
* destroy: () => {...}
* };
* // ...
* return {
* update: (updatedParameter) => {...},
* destroy: () => {...}
* };
* }
* ```
*
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/runtime/internal/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export function construct_svelte_component_dev(component, props) {
*
* Can be used to create strongly typed Svelte components.
*
* ### Example:
* #### Example:
*
* You have component library on npm called `component-library`, from which
* you export a component called `MyComponent`. For Svelte+TypeScript users,
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/runtime/internal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function subscribe(store, ...callbacks) {
}

/**
* Get the current value from a store by subscribing and immediately unsubscribing.
* @template T
* @param {import('../store/public.js').Readable<T>} store
* @returns {T}
Expand Down
6 changes: 0 additions & 6 deletions packages/svelte/src/runtime/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,4 @@ export function readonly(store) {
};
}

/**
* Get the current value from a store by subscribing and immediately unsubscribing.
* @template T
* @param {import('./public.js').Readable<T>} store readable
* @returns {T}
*/
export { get_store_value as get };
Loading

0 comments on commit b1cafc4

Please sign in to comment.