Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b41c4d1

Browse files
committed
refactor(core): rename internal core modules for clarity
1 parent e86dada commit b41c4d1

File tree

10 files changed

+26
-25
lines changed

10 files changed

+26
-25
lines changed

‎package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
"types": "svelte-check",
7373
"types:legacy": "svelte-check --tsconfig tsconfig.legacy.json",
7474
"validate": "npm-run-all test:vitest:* test:jest types build",
75-
"build": "tsc -p tsconfig.build.json && cp src/component-types.d.ts types",
75+
"build": "npm-run-all build:*",
76+
"build:tsc": "tsc -p tsconfig.build.json",
77+
"build:copy-dts": "cp src/core/types.d.ts types/core",
7678
"contributors:add": "all-contributors add",
7779
"contributors:generate": "all-contributors generate",
7880
"preview-release": "./scripts/preview-release",

‎src/__tests__/render-runes.test-d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ describe('types', () => {
2929
test('render result has container and component', () => {
3030
const result = subject.render(Component, { name: 'Alice', count: 42 })
3131

32-
expectTypeOf(result).toMatchTypeOf<{
32+
expectTypeOf(result).toExtend<{
3333
container: HTMLElement
34+
baseElement: HTMLElement
3435
component: { hello: string }
3536
debug: (el?: HTMLElement) => void
3637
rerender: (props: { name?: string; count?: number }) => Promise<void>
@@ -55,7 +56,7 @@ describe('legacy component types', () => {
5556
count: 42,
5657
})
5758

58-
expectTypeOf(component).toMatchTypeOf<{ hello: string }>()
59+
expectTypeOf(component).toExtend<{ hello: string }>()
5960

6061
// @ts-expect-error: Svelte 5 mount does not return `$set`
6162
component.$on('greeting', onGreeting)

‎src/__tests__/render-utilities.test-d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('render query and utility types', () => {
88
test('render result has default queries', () => {
99
const result = subject.render(Component, { name: 'Alice' })
1010

11-
expectTypeOf(result.getByRole).parameters.toMatchTypeOf<
11+
expectTypeOf(result.getByRole).parameters.toExtend<
1212
[role: subject.ByRoleMatcher, options?: subject.ByRoleOptions]
1313
>()
1414
})
@@ -27,25 +27,25 @@ describe('render query and utility types', () => {
2727
{ queries: { getByVibes } }
2828
)
2929

30-
expectTypeOf(result.getByVibes).parameters.toMatchTypeOf<[vibes: string]>()
30+
expectTypeOf(result.getByVibes).parameters.toExtend<[vibes: string]>()
3131
})
3232

3333
test('act is an async function', () => {
34-
expectTypeOf(subject.act).toMatchTypeOf<() => Promise<void>>()
34+
expectTypeOf(subject.act).toExtend<() => Promise<void>>()
3535
})
3636

3737
test('act accepts a sync function', () => {
38-
expectTypeOf(subject.act).toMatchTypeOf<(fn: () => void) => Promise<void>>()
38+
expectTypeOf(subject.act).toExtend<(fn: () => void) => Promise<void>>()
3939
})
4040

4141
test('act accepts an async function', () => {
42-
expectTypeOf(subject.act).toMatchTypeOf<
42+
expectTypeOf(subject.act).toExtend<
4343
(fn: () => Promise<void>) => Promise<void>
4444
>()
4545
})
4646

4747
test('fireEvent is an async function', () => {
48-
expectTypeOf(subject.fireEvent).toMatchTypeOf<
48+
expectTypeOf(subject.fireEvent).toExtend<
4949
(
5050
element: Element | Node | Document | Window,
5151
event: Event
@@ -54,7 +54,7 @@ describe('render query and utility types', () => {
5454
})
5555

5656
test('fireEvent[eventName] is an async function', () => {
57-
expectTypeOf(subject.fireEvent.click).toMatchTypeOf<
57+
expectTypeOf(subject.fireEvent.click).toExtend<
5858
(
5959
element: Element | Node | Document | Window,
6060
// eslint-disable-next-line @typescript-eslint/no-empty-object-type

‎src/__tests__/render.test-d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ describe('types', () => {
3737
test('render result has container and component', () => {
3838
const result = subject.render(Component, { name: 'Alice', count: 42 })
3939

40-
expectTypeOf(result).toMatchTypeOf<{
40+
expectTypeOf(result).toExtend<{
4141
container: HTMLElement
42+
baseElement: HTMLElement
4243
component: { hello: string }
4344
debug: (el?: HTMLElement) => void
4445
rerender: (props: { name?: string; count?: number }) => Promise<void>

‎src/core/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
* Will switch to legacy, class-based mounting logic
66
* if it looks like we're in a Svelte <= 4 environment.
77
*/
8-
import * as LegacyCore from './legacy.js'
9-
import * as ModernCore from './modern.svelte.js'
10-
import {
11-
createValidateOptions,
12-
UnknownSvelteOptionsError,
13-
} from './validate-options.js'
8+
import * as MountLegacy from './mount-legacy.js'
9+
import * as MountModern from './mount-modern.svelte.js'
10+
import { createValidateOptions, UnknownSvelteOptionsError } from './prepare.js'
1411

1512
const { mount, unmount, updateProps, allowedOptions } =
16-
ModernCore.IS_MODERN_SVELTE ? ModernCore : LegacyCore
13+
MountModern.IS_MODERN_SVELTE ? MountModern : MountLegacy
1714

1815
/** Validate component options. */
1916
const validateOptions = createValidateOptions(allowedOptions)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎src/pure.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const componentCache = new Set()
1313
/**
1414
* Customize how Svelte renders the component.
1515
*
16-
* @template {import('./component-types.js').Component} C
17-
* @typedef {import('./component-types.js').Props<C> | Partial<import('./component-types.js').MountOptions<C>>} SvelteComponentOptions
16+
* @template {import('./core/types.js').Component} C
17+
* @typedef {import('./core/types.js').Props<C> | Partial<import('./core/types.js').MountOptions<C>>} SvelteComponentOptions
1818
*/
1919

2020
/**
@@ -30,15 +30,15 @@ const componentCache = new Set()
3030
/**
3131
* The rendered component and bound testing functions.
3232
*
33-
* @template {import('./component-types.js').Component} C
33+
* @template {import('./core/types.js').Component} C
3434
* @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
3535
*
3636
* @typedef {{
3737
* container: HTMLElement
3838
* baseElement: HTMLElement
39-
* component: import('./component-types.js').Exports<C>
39+
* component: import('./core/types.js').Exports<C>
4040
* debug: (el?: HTMLElement | DocumentFragment) => void
41-
* rerender: (props: Partial<import('./component-types.js').Props<C>>) => Promise<void>
41+
* rerender: (props: Partial<import('./core/types.js').Props<C>>) => Promise<void>
4242
* unmount: () => void
4343
* } & {
4444
* [P in keyof Q]: import('@testing-library/dom').BoundFunction<Q[P]>
@@ -48,10 +48,10 @@ const componentCache = new Set()
4848
/**
4949
* Render a component into the document.
5050
*
51-
* @template {import('./component-types.js').Component} C
51+
* @template {import('./core/types.js').Component} C
5252
* @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
5353
*
54-
* @param {import('./component-types.js').ComponentType<C>} Component - The component to render.
54+
* @param {import('./core/types.js').ComponentType<C>} Component - The component to render.
5555
* @param {SvelteComponentOptions<C>} options - Customize how Svelte renders the component.
5656
* @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
5757
* @returns {RenderResult<C, Q>} The rendered component and bound testing functions.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /