Skip to content

Commit 8560d8b

Browse files
dummdidummtrueadm
authored andcommitted
fix: make more types from svelte/compiler public (#12189)
The types generation script used the wrong entry point, as a consequence not all types that should've been exposed where actually made public
1 parent 9ef14a3 commit 8560d8b

File tree

5 files changed

+85
-77
lines changed

5 files changed

+85
-77
lines changed

.changeset/curly-cooks-cheer.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: make more types from `svelte/compiler` public

packages/svelte/scripts/generate-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ await createBundle({
2525
[pkg.name]: `${dir}/src/index.d.ts`,
2626
[`${pkg.name}/action`]: `${dir}/src/action/public.d.ts`,
2727
[`${pkg.name}/animate`]: `${dir}/src/animate/public.d.ts`,
28-
[`${pkg.name}/compiler`]: `${dir}/src/compiler/index.js`,
28+
[`${pkg.name}/compiler`]: `${dir}/src/compiler/public.d.ts`,
2929
[`${pkg.name}/easing`]: `${dir}/src/easing/index.js`,
3030
[`${pkg.name}/legacy`]: `${dir}/src/legacy/legacy-client.js`,
3131
[`${pkg.name}/motion`]: `${dir}/src/motion/public.d.ts`,

packages/svelte/src/compiler/preprocess/public.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface PreprocessorGroup {
6969
}
7070

7171
/**
72-
* Utility type to extract the type of a preprocessor from a preprocessor group
72+
* @description Utility type to extract the type of a preprocessor from a preprocessor group
7373
* @deprecated Create this utility type yourself instead
7474
*/
7575
export interface SveltePreprocessor<
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
export type { Preprocessor, PreprocessorGroup } from './preprocess/public';
2-
3-
export type { CompileOptions } from './types/index';
4-
51
export * from './index.js';
2+
export type {
3+
MarkupPreprocessor,
4+
Preprocessor,
5+
PreprocessorGroup,
6+
Processed
7+
} from './preprocess/public';
8+
export type { CompileOptions, ModuleCompileOptions } from './types/index';

packages/svelte/types/index.d.ts

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,75 @@ declare module 'svelte/compiler' {
606606
* @deprecated Replace this with `import { walk } from 'estree-walker'`
607607
* */
608608
function walk(): never;
609+
/**
610+
* The result of a preprocessor run. If the preprocessor does not return a result, it is assumed that the code is unchanged.
611+
*/
612+
interface Processed {
613+
/**
614+
* The new code
615+
*/
616+
code: string;
617+
/**
618+
* A source map mapping back to the original code
619+
*/
620+
map?: string | object; // we are opaque with the type here to avoid dependency on the remapping module for our public types.
621+
/**
622+
* A list of additional files to watch for changes
623+
*/
624+
dependencies?: string[];
625+
/**
626+
* Only for script/style preprocessors: The updated attributes to set on the tag. If undefined, attributes stay unchanged.
627+
*/
628+
attributes?: Record<string, string | boolean>;
629+
toString?: () => string;
630+
}
631+
632+
/**
633+
* A markup preprocessor that takes a string of code and returns a processed version.
634+
*/
635+
type MarkupPreprocessor = (options: {
636+
/**
637+
* The whole Svelte file content
638+
*/
639+
content: string;
640+
/**
641+
* The filename of the Svelte file
642+
*/
643+
filename?: string;
644+
}) => Processed | void | Promise<Processed | void>;
645+
646+
/**
647+
* A script/style preprocessor that takes a string of code and returns a processed version.
648+
*/
649+
type Preprocessor = (options: {
650+
/**
651+
* The script/style tag content
652+
*/
653+
content: string;
654+
/**
655+
* The attributes on the script/style tag
656+
*/
657+
attributes: Record<string, string | boolean>;
658+
/**
659+
* The whole Svelte file content
660+
*/
661+
markup: string;
662+
/**
663+
* The filename of the Svelte file
664+
*/
665+
filename?: string;
666+
}) => Processed | void | Promise<Processed | void>;
667+
668+
/**
669+
* A preprocessor group is a set of preprocessors that are applied to a Svelte file.
670+
*/
671+
interface PreprocessorGroup {
672+
/** Name of the preprocessor. Will be a required option in the next major version */
673+
name?: string;
674+
markup?: MarkupPreprocessor;
675+
style?: Preprocessor;
676+
script?: Preprocessor;
677+
}
609678
/** The return value of `compile` from `svelte/compiler` */
610679
interface CompileResult {
611680
/** The compiled JavaScript */
@@ -1823,77 +1892,8 @@ declare module 'svelte/compiler' {
18231892
content: Program;
18241893
attributes: Attribute[];
18251894
}
1826-
/**
1827-
* The result of a preprocessor run. If the preprocessor does not return a result, it is assumed that the code is unchanged.
1828-
*/
1829-
interface Processed {
1830-
/**
1831-
* The new code
1832-
*/
1833-
code: string;
1834-
/**
1835-
* A source map mapping back to the original code
1836-
*/
1837-
map?: string | object; // we are opaque with the type here to avoid dependency on the remapping module for our public types.
1838-
/**
1839-
* A list of additional files to watch for changes
1840-
*/
1841-
dependencies?: string[];
1842-
/**
1843-
* Only for script/style preprocessors: The updated attributes to set on the tag. If undefined, attributes stay unchanged.
1844-
*/
1845-
attributes?: Record<string, string | boolean>;
1846-
toString?: () => string;
1847-
}
1848-
1849-
/**
1850-
* A markup preprocessor that takes a string of code and returns a processed version.
1851-
*/
1852-
type MarkupPreprocessor = (options: {
1853-
/**
1854-
* The whole Svelte file content
1855-
*/
1856-
content: string;
1857-
/**
1858-
* The filename of the Svelte file
1859-
*/
1860-
filename?: string;
1861-
}) => Processed | void | Promise<Processed | void>;
1862-
1863-
/**
1864-
* A script/style preprocessor that takes a string of code and returns a processed version.
1865-
*/
1866-
type Preprocessor = (options: {
1867-
/**
1868-
* The script/style tag content
1869-
*/
1870-
content: string;
1871-
/**
1872-
* The attributes on the script/style tag
1873-
*/
1874-
attributes: Record<string, string | boolean>;
1875-
/**
1876-
* The whole Svelte file content
1877-
*/
1878-
markup: string;
1879-
/**
1880-
* The filename of the Svelte file
1881-
*/
1882-
filename?: string;
1883-
}) => Processed | void | Promise<Processed | void>;
1884-
1885-
/**
1886-
* A preprocessor group is a set of preprocessors that are applied to a Svelte file.
1887-
*/
1888-
interface PreprocessorGroup {
1889-
/** Name of the preprocessor. Will be a required option in the next major version */
1890-
name?: string;
1891-
markup?: MarkupPreprocessor;
1892-
style?: Preprocessor;
1893-
script?: Preprocessor;
1894-
}
18951895

1896-
export { compile, compileModule, parse, walk, preprocess, CompileError, VERSION, migrate };
1896+
export { MarkupPreprocessor, Preprocessor, PreprocessorGroup, Processed, CompileOptions, ModuleCompileOptions, compile, compileModule, parse, walk, preprocess, CompileError, VERSION, migrate };
18971897
}
18981898

18991899
declare module 'svelte/easing' {
@@ -2510,7 +2510,7 @@ declare module 'svelte/types/compiler/preprocess' {
25102510
}
25112511

25122512
/**
2513-
* Utility type to extract the type of a preprocessor from a preprocessor group
2513+
* @description Utility type to extract the type of a preprocessor from a preprocessor group
25142514
* @deprecated Create this utility type yourself instead
25152515
*/
25162516
interface SveltePreprocessor_1<

0 commit comments

Comments
 (0)