diff --git a/.prettierrc b/.prettierrc index 0fd4cd0a2cc1..d471ce49e239 100644 --- a/.prettierrc +++ b/.prettierrc @@ -27,8 +27,8 @@ "**/build/**", "**/test-results/**", "documentation/**/*.md", - "packages/package/test/fixtures/**/expected/**/*", - "packages/package/test/watch/expected/**/*", + "packages/package/test/fixtures/**/expected*/**/*", + "packages/package/test/watch/expected*/**/*", "packages/package/test/watch/package/**/*", "packages/kit/src/core/postbuild/fixtures/**/*" ], diff --git a/packages/package/package.json b/packages/package/package.json index 1ab629b29654..368ba1dba622 100644 --- a/packages/package/package.json +++ b/packages/package/package.json @@ -31,6 +31,7 @@ "@types/node": "^18.19.48", "@types/semver": "^7.5.6", "prettier": "^3.1.1", + "semver": "^7.6.3", "svelte": "^5.2.9", "svelte-preprocess": "^6.0.0", "typescript": "^5.3.3", diff --git a/packages/package/test/fixtures/javascript/expected ^4/Test.svelte b/packages/package/test/fixtures/javascript/expected ^4/Test.svelte new file mode 100644 index 000000000000..e60789af6a74 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/package/test/fixtures/javascript/expected ^4/Test.svelte.d.ts b/packages/package/test/fixtures/javascript/expected ^4/Test.svelte.d.ts new file mode 100644 index 000000000000..8b3f3a1b705c --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/Test.svelte.d.ts @@ -0,0 +1,42 @@ +/** @typedef {typeof __propDef.props} TestProps */ +/** @typedef {typeof __propDef.events} TestEvents */ +/** @typedef {typeof __propDef.slots} TestSlots */ +export default class Test extends SvelteComponent< + { + astring?: string; + }, + { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }, + { + default: { + astring: string; + }; + } +> { + get astring(): string; +} +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + astring?: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; + exports?: {}; + bindings?: string; +}; +export {}; \ No newline at end of file diff --git a/packages/package/test/fixtures/javascript/expected ^4/Test2.svelte b/packages/package/test/fixtures/javascript/expected ^4/Test2.svelte new file mode 100644 index 000000000000..852fe8cd5dbc --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/Test2.svelte @@ -0,0 +1,6 @@ + diff --git a/packages/package/test/fixtures/javascript/expected ^4/Test2.svelte.d.ts b/packages/package/test/fixtures/javascript/expected ^4/Test2.svelte.d.ts new file mode 100644 index 000000000000..a3a776a2d5bb --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/Test2.svelte.d.ts @@ -0,0 +1,28 @@ +/** @typedef {typeof __propDef.props} Test2Props */ +/** @typedef {typeof __propDef.events} Test2Events */ +/** @typedef {typeof __propDef.slots} Test2Slots */ +export default class Test2 extends SvelteComponent< + { + foo: import('./foo').Foo; + }, + { + [evt: string]: CustomEvent; + }, + {} +> {} +export type Test2Props = typeof __propDef.props; +export type Test2Events = typeof __propDef.events; +export type Test2Slots = typeof __propDef.slots; +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + foo: import('./foo').Foo; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; + exports?: {}; + bindings?: string; +}; +export {}; diff --git a/packages/package/test/fixtures/javascript/expected ^4/foo.d.ts b/packages/package/test/fixtures/javascript/expected ^4/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/package/test/fixtures/javascript/expected ^4/index.d.ts b/packages/package/test/fixtures/javascript/expected ^4/index.d.ts new file mode 100644 index 000000000000..ed60fe04da25 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/index.d.ts @@ -0,0 +1,2 @@ +export { default as Test } from './Test.svelte'; +export { default as Internal } from './internal/Test.svelte'; diff --git a/packages/package/test/fixtures/javascript/expected ^4/index.js b/packages/package/test/fixtures/javascript/expected ^4/index.js new file mode 100644 index 000000000000..ed60fe04da25 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/index.js @@ -0,0 +1,2 @@ +export { default as Test } from './Test.svelte'; +export { default as Internal } from './internal/Test.svelte'; diff --git a/packages/package/test/fixtures/javascript/expected ^4/internal/Test.svelte b/packages/package/test/fixtures/javascript/expected ^4/internal/Test.svelte new file mode 100644 index 000000000000..852fe8cd5dbc --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/internal/Test.svelte @@ -0,0 +1,6 @@ + diff --git a/packages/package/test/fixtures/javascript/expected ^4/internal/Test.svelte.d.ts b/packages/package/test/fixtures/javascript/expected ^4/internal/Test.svelte.d.ts new file mode 100644 index 000000000000..26d2d35798d0 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/internal/Test.svelte.d.ts @@ -0,0 +1,28 @@ +/** @typedef {typeof __propDef.props} TestProps */ +/** @typedef {typeof __propDef.events} TestEvents */ +/** @typedef {typeof __propDef.slots} TestSlots */ +export default class Test extends SvelteComponent< + { + foo: import('./foo').Foo; + }, + { + [evt: string]: CustomEvent; + }, + {} +> {} +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + foo: import('./foo').Foo; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; + exports?: {}; + bindings?: string; +}; +export {}; \ No newline at end of file diff --git a/packages/package/test/fixtures/javascript/expected ^4/internal/foo.d.ts b/packages/package/test/fixtures/javascript/expected ^4/internal/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/internal/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/package/test/fixtures/javascript/expected ^4/internal/index.d.ts b/packages/package/test/fixtures/javascript/expected ^4/internal/index.d.ts new file mode 100644 index 000000000000..69325fd26bd1 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/internal/index.d.ts @@ -0,0 +1,2 @@ +export const foo: 'bar'; +export { x } from "./runes.svelte.js"; diff --git a/packages/package/test/fixtures/javascript/expected ^4/internal/index.js b/packages/package/test/fixtures/javascript/expected ^4/internal/index.js new file mode 100644 index 000000000000..b7dfdd870f1b --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/internal/index.js @@ -0,0 +1,2 @@ +export const foo = 'bar'; +export { x } from './runes.svelte.js'; diff --git a/packages/package/test/fixtures/javascript/expected ^4/internal/runes.svelte.d.ts b/packages/package/test/fixtures/javascript/expected ^4/internal/runes.svelte.d.ts new file mode 100644 index 000000000000..ce5b9032906e --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/internal/runes.svelte.d.ts @@ -0,0 +1 @@ +export const x: true; diff --git a/packages/package/test/fixtures/javascript/expected ^4/internal/runes.svelte.js b/packages/package/test/fixtures/javascript/expected ^4/internal/runes.svelte.js new file mode 100644 index 000000000000..30dc55a73230 --- /dev/null +++ b/packages/package/test/fixtures/javascript/expected ^4/internal/runes.svelte.js @@ -0,0 +1 @@ +export const x = true; diff --git a/packages/package/test/fixtures/javascript/expected ^4/utils.d.ts b/packages/package/test/fixtures/javascript/expected ^4/utils.d.ts new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/package/test/fixtures/javascript/expected ^4/utils.js b/packages/package/test/fixtures/javascript/expected ^4/utils.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/Test.svelte b/packages/package/test/fixtures/resolve-alias/expected ^4/Test.svelte new file mode 100644 index 000000000000..fcf1788036de --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/Test.svelte @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/Test.svelte.d.ts b/packages/package/test/fixtures/resolve-alias/expected ^4/Test.svelte.d.ts new file mode 100644 index 000000000000..118eac96760a --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/Test.svelte.d.ts @@ -0,0 +1,17 @@ +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + bar?: import('./sub/foo').Foo; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; + exports?: {}; + bindings?: string; +}; +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +export default class Test extends SvelteComponent {} +export {}; \ No newline at end of file diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/baz.d.ts b/packages/package/test/fixtures/resolve-alias/expected ^4/baz.d.ts new file mode 100644 index 000000000000..85f482c14ba7 --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/baz.d.ts @@ -0,0 +1,4 @@ +export interface Baz { + baz: string; +} +export declare const baz: Baz; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/baz.js b/packages/package/test/fixtures/resolve-alias/expected ^4/baz.js new file mode 100644 index 000000000000..844535e7bc66 --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/baz.js @@ -0,0 +1 @@ +export const baz = { baz: 'baz' }; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/index.d.ts b/packages/package/test/fixtures/resolve-alias/expected ^4/index.d.ts new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/index.d.ts @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/index.js b/packages/package/test/fixtures/resolve-alias/expected ^4/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/sub/bar.d.ts b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/bar.d.ts new file mode 100644 index 000000000000..9f1a49e9dfd6 --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/bar.d.ts @@ -0,0 +1,2 @@ +export declare const bar1: import('./foo').Foo; +export declare const bar2: import('../baz').Baz; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/sub/bar.js b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/bar.js new file mode 100644 index 000000000000..17941b746387 --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/bar.js @@ -0,0 +1,4 @@ +import { baz } from '../baz'; +import { foo } from './foo'; +export const bar1 = foo; +export const bar2 = baz; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/sub/foo.d.ts b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/foo.d.ts new file mode 100644 index 000000000000..b5b3928ab61d --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/foo.d.ts @@ -0,0 +1,4 @@ +export interface Foo { + foo: string; +} +export declare const foo: Foo; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/sub/foo.js b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/foo.js new file mode 100644 index 000000000000..aaae90ec5bfc --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/sub/foo.js @@ -0,0 +1 @@ +export const foo = { foo: 'foo' }; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/utils/index.d.ts b/packages/package/test/fixtures/resolve-alias/expected ^4/utils/index.d.ts new file mode 100644 index 000000000000..5f6cf235961a --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/utils/index.d.ts @@ -0,0 +1 @@ +export declare const util: () => void; diff --git a/packages/package/test/fixtures/resolve-alias/expected ^4/utils/index.js b/packages/package/test/fixtures/resolve-alias/expected ^4/utils/index.js new file mode 100644 index 000000000000..bf331fdbac9d --- /dev/null +++ b/packages/package/test/fixtures/resolve-alias/expected ^4/utils/index.js @@ -0,0 +1 @@ +export const util = () => { }; diff --git a/packages/package/test/fixtures/svelte-3-types/expected ^4/Test.svelte b/packages/package/test/fixtures/svelte-3-types/expected ^4/Test.svelte new file mode 100644 index 000000000000..a02c0339976a --- /dev/null +++ b/packages/package/test/fixtures/svelte-3-types/expected ^4/Test.svelte @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/packages/package/test/fixtures/svelte-3-types/expected ^4/Test.svelte.d.ts b/packages/package/test/fixtures/svelte-3-types/expected ^4/Test.svelte.d.ts new file mode 100644 index 000000000000..1d2d93df5582 --- /dev/null +++ b/packages/package/test/fixtures/svelte-3-types/expected ^4/Test.svelte.d.ts @@ -0,0 +1,23 @@ +import { SvelteComponentTyped } from 'svelte'; +declare const __propDef: { + props: { + astring?: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; +}; +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +export default class Test extends SvelteComponentTyped { + get astring(): string; +} +export {}; diff --git a/packages/package/test/fixtures/svelte-3-types/expected ^4/index.d.ts b/packages/package/test/fixtures/svelte-3-types/expected ^4/index.d.ts new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/svelte-3-types/expected ^4/index.d.ts @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/svelte-3-types/expected ^4/index.js b/packages/package/test/fixtures/svelte-3-types/expected ^4/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/svelte-3-types/expected ^4/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/svelte-kit/expected ^4/Test.svelte b/packages/package/test/fixtures/svelte-kit/expected ^4/Test.svelte new file mode 100644 index 000000000000..e60789af6a74 --- /dev/null +++ b/packages/package/test/fixtures/svelte-kit/expected ^4/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/package/test/fixtures/svelte-kit/expected ^4/Test.svelte.d.ts b/packages/package/test/fixtures/svelte-kit/expected ^4/Test.svelte.d.ts new file mode 100644 index 000000000000..8b3f3a1b705c --- /dev/null +++ b/packages/package/test/fixtures/svelte-kit/expected ^4/Test.svelte.d.ts @@ -0,0 +1,42 @@ +/** @typedef {typeof __propDef.props} TestProps */ +/** @typedef {typeof __propDef.events} TestEvents */ +/** @typedef {typeof __propDef.slots} TestSlots */ +export default class Test extends SvelteComponent< + { + astring?: string; + }, + { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }, + { + default: { + astring: string; + }; + } +> { + get astring(): string; +} +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + astring?: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; + exports?: {}; + bindings?: string; +}; +export {}; \ No newline at end of file diff --git a/packages/package/test/fixtures/svelte-kit/expected ^4/foo.d.ts b/packages/package/test/fixtures/svelte-kit/expected ^4/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/package/test/fixtures/svelte-kit/expected ^4/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/package/test/fixtures/svelte-kit/expected ^4/index.d.ts b/packages/package/test/fixtures/svelte-kit/expected ^4/index.d.ts new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/svelte-kit/expected ^4/index.d.ts @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/svelte-kit/expected ^4/index.js b/packages/package/test/fixtures/svelte-kit/expected ^4/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/svelte-kit/expected ^4/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/Plain.svelte b/packages/package/test/fixtures/typescript-esnext/expected ^4/Plain.svelte new file mode 100644 index 000000000000..f46e78994ae5 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/Plain.svelte @@ -0,0 +1,17 @@ + + + + + diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/Plain.svelte.d.ts b/packages/package/test/fixtures/typescript-esnext/expected ^4/Plain.svelte.d.ts new file mode 100644 index 000000000000..bce6209444f5 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/Plain.svelte.d.ts @@ -0,0 +1,28 @@ +/** @typedef {typeof __propDef.props} PlainProps */ +/** @typedef {typeof __propDef.events} PlainEvents */ +/** @typedef {typeof __propDef.slots} PlainSlots */ +export default class Plain extends SvelteComponent< + { + foo: import('./foo').Foo; + }, + { + [evt: string]: CustomEvent; + }, + {} +> {} +export type PlainProps = typeof __propDef.props; +export type PlainEvents = typeof __propDef.events; +export type PlainSlots = typeof __propDef.slots; +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + foo: import('./foo').Foo; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; + exports?: {}; + bindings?: string; +}; +export {}; diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/Test.svelte b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test.svelte new file mode 100644 index 000000000000..661b1b8276b0 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test.svelte @@ -0,0 +1,8 @@ + + + diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/Test.svelte.d.ts b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test.svelte.d.ts new file mode 100644 index 000000000000..773ce92a30b9 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test.svelte.d.ts @@ -0,0 +1,25 @@ +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + astring?: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; + exports?: {}; + bindings?: string; +}; +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +export default class Test extends SvelteComponent { + get astring(): string; +} +export {}; \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/Test2.svelte b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test2.svelte new file mode 100644 index 000000000000..8754c5335039 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test2.svelte @@ -0,0 +1,3 @@ + diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/Test2.svelte.d.ts b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test2.svelte.d.ts new file mode 100644 index 000000000000..ef0d6a643bc5 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/Test2.svelte.d.ts @@ -0,0 +1,18 @@ +import { SvelteComponent } from 'svelte'; +import type { Foo } from './foo'; +declare const __propDef: { + props: { + foo: Foo; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; + exports?: {}; + bindings?: string; +}; +export type Test2Props = typeof __propDef.props; +export type Test2Events = typeof __propDef.events; +export type Test2Slots = typeof __propDef.slots; +export default class Test2 extends SvelteComponent {} +export {}; \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/foo.d.ts b/packages/package/test/fixtures/typescript-esnext/expected ^4/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/index.d.ts b/packages/package/test/fixtures/typescript-esnext/expected ^4/index.d.ts new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/index.d.ts @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/index.js b/packages/package/test/fixtures/typescript-esnext/expected ^4/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/runes.svelte.d.ts b/packages/package/test/fixtures/typescript-esnext/expected ^4/runes.svelte.d.ts new file mode 100644 index 000000000000..2b17805f4351 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/runes.svelte.d.ts @@ -0,0 +1 @@ +export declare const x = true; diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/runes.svelte.js b/packages/package/test/fixtures/typescript-esnext/expected ^4/runes.svelte.js new file mode 100644 index 000000000000..30dc55a73230 --- /dev/null +++ b/packages/package/test/fixtures/typescript-esnext/expected ^4/runes.svelte.js @@ -0,0 +1 @@ +export const x = true; diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/utils.d.ts b/packages/package/test/fixtures/typescript-esnext/expected ^4/utils.d.ts new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/package/test/fixtures/typescript-esnext/expected ^4/utils.js b/packages/package/test/fixtures/typescript-esnext/expected ^4/utils.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/package/test/fixtures/typescript-nodenext/expected ^4/Test.svelte b/packages/package/test/fixtures/typescript-nodenext/expected ^4/Test.svelte new file mode 100644 index 000000000000..661b1b8276b0 --- /dev/null +++ b/packages/package/test/fixtures/typescript-nodenext/expected ^4/Test.svelte @@ -0,0 +1,8 @@ + + + diff --git a/packages/package/test/fixtures/typescript-nodenext/expected ^4/Test.svelte.d.ts b/packages/package/test/fixtures/typescript-nodenext/expected ^4/Test.svelte.d.ts new file mode 100644 index 000000000000..773ce92a30b9 --- /dev/null +++ b/packages/package/test/fixtures/typescript-nodenext/expected ^4/Test.svelte.d.ts @@ -0,0 +1,25 @@ +import { SvelteComponent } from 'svelte'; +declare const __propDef: { + props: { + astring?: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; + exports?: {}; + bindings?: string; +}; +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +export default class Test extends SvelteComponent { + get astring(): string; +} +export {}; \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-nodenext/expected ^4/index.d.ts b/packages/package/test/fixtures/typescript-nodenext/expected ^4/index.d.ts new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/typescript-nodenext/expected ^4/index.d.ts @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/typescript-nodenext/expected ^4/index.js b/packages/package/test/fixtures/typescript-nodenext/expected ^4/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/typescript-nodenext/expected ^4/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/typescript-nodenext/expected ^4/runes.svelte.d.ts b/packages/package/test/fixtures/typescript-nodenext/expected ^4/runes.svelte.d.ts new file mode 100644 index 000000000000..2b17805f4351 --- /dev/null +++ b/packages/package/test/fixtures/typescript-nodenext/expected ^4/runes.svelte.d.ts @@ -0,0 +1 @@ +export declare const x = true; diff --git a/packages/package/test/fixtures/typescript-nodenext/expected ^4/runes.svelte.js b/packages/package/test/fixtures/typescript-nodenext/expected ^4/runes.svelte.js new file mode 100644 index 000000000000..30dc55a73230 --- /dev/null +++ b/packages/package/test/fixtures/typescript-nodenext/expected ^4/runes.svelte.js @@ -0,0 +1 @@ +export const x = true; diff --git a/packages/package/test/index.js b/packages/package/test/index.js index 45903ecb0b23..1fd1af09f929 100644 --- a/packages/package/test/index.js +++ b/packages/package/test/index.js @@ -4,6 +4,8 @@ import { join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import prettier from 'prettier'; +import * as semver from 'semver'; +import * as svelte from 'svelte/compiler'; import { test } from 'uvu'; import * as assert from 'uvu/assert'; @@ -21,7 +23,7 @@ const __dirname = join(__filename, '..'); */ async function test_make_package(path, options) { const cwd = join(__dirname, 'fixtures', path); - const ewd = join(cwd, 'expected'); + const ewd = join(cwd, get_expected_dir(cwd)); const output = join(cwd, 'dist'); const config = await load_config({ cwd }); @@ -80,6 +82,25 @@ async function format(file, content) { }); } +/** + * adapted from https://github.com/Rich-Harris/dts-buddy/blob/94d4ff35f48a487c081a3a48ceb3d9124712b84e/test/test.js#L52-L61 + * @param {string} cwd + * @returns {string} + */ +function get_expected_dir(cwd) { + let expected_dir = 'expected'; + for (const candidate of fs.readdirSync(cwd)) { + if (!candidate.startsWith('expected ')) continue; + const range = candidate.slice(8); + + if (semver.satisfies(svelte.VERSION.split('-')[0], range)) { + expected_dir = candidate; + break; + } + } + return expected_dir; +} + for (const dir of fs.readdirSync(join(__dirname, 'errors'))) { test(`package error [${dir}]`, async () => { const cwd = join(__dirname, 'errors', dir); @@ -173,7 +194,7 @@ if (!process.env.CI) { /** @param {string} file */ function compare(file) { - assert.equal(read(`package/${file}`), read(`expected/${file}`)); + assert.equal(read(`package/${file}`), read(`${get_expected_dir(cwd)}/${file}`)); } /** @param {string} file */ diff --git a/packages/package/test/watch/expected ^4/Test.svelte b/packages/package/test/watch/expected ^4/Test.svelte new file mode 100644 index 000000000000..8f19b8ec1674 --- /dev/null +++ b/packages/package/test/watch/expected ^4/Test.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/package/test/watch/expected ^4/Test.svelte.d.ts b/packages/package/test/watch/expected ^4/Test.svelte.d.ts new file mode 100644 index 000000000000..fecde1b0e9cb --- /dev/null +++ b/packages/package/test/watch/expected ^4/Test.svelte.d.ts @@ -0,0 +1,18 @@ +import { SvelteComponent } from "svelte"; +declare const __propDef: { + props: { + answer: number; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; + exports?: {}; + bindings?: string; +}; +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +export default class Test extends SvelteComponent { +} +export {}; diff --git a/packages/package/test/watch/expected ^4/a.d.ts b/packages/package/test/watch/expected ^4/a.d.ts new file mode 100644 index 000000000000..8ae31dde3a46 --- /dev/null +++ b/packages/package/test/watch/expected ^4/a.d.ts @@ -0,0 +1 @@ +export const a: "a"; diff --git a/packages/package/test/watch/expected ^4/a.js b/packages/package/test/watch/expected ^4/a.js new file mode 100644 index 000000000000..737869aa3ae5 --- /dev/null +++ b/packages/package/test/watch/expected ^4/a.js @@ -0,0 +1 @@ +export const a = 'a'; \ No newline at end of file diff --git a/packages/package/test/watch/expected ^4/b.d.ts b/packages/package/test/watch/expected ^4/b.d.ts new file mode 100644 index 000000000000..17fcba0d170e --- /dev/null +++ b/packages/package/test/watch/expected ^4/b.d.ts @@ -0,0 +1 @@ +export declare const b = "b"; diff --git a/packages/package/test/watch/expected ^4/b.js b/packages/package/test/watch/expected ^4/b.js new file mode 100644 index 000000000000..137b8ce6429a --- /dev/null +++ b/packages/package/test/watch/expected ^4/b.js @@ -0,0 +1 @@ +export const b = 'b'; diff --git a/packages/package/test/watch/expected ^4/index.js b/packages/package/test/watch/expected ^4/index.js new file mode 100644 index 000000000000..ec0ffd5d4721 --- /dev/null +++ b/packages/package/test/watch/expected ^4/index.js @@ -0,0 +1 @@ +console.log('index.js'); diff --git a/packages/package/test/watch/expected ^4/package.json b/packages/package/test/watch/expected ^4/package.json new file mode 100644 index 000000000000..dd85b1921837 --- /dev/null +++ b/packages/package/test/watch/expected ^4/package.json @@ -0,0 +1,9 @@ +{ + "type": "module", + "exports": { + "./package.json": "./package.json", + "./Test.svelte": "./Test.svelte", + ".": "./index.js" + }, + "svelte": "./index.js" +} \ No newline at end of file diff --git a/packages/package/test/watch/expected ^4/post-error.svelte b/packages/package/test/watch/expected ^4/post-error.svelte new file mode 100644 index 000000000000..c2f280254f99 --- /dev/null +++ b/packages/package/test/watch/expected ^4/post-error.svelte @@ -0,0 +1 @@ + \ No newline at end of file