diff --git a/.changeset/young-feet-double.md b/.changeset/young-feet-double.md new file mode 100644 index 000000000000..c1de0a948c1a --- /dev/null +++ b/.changeset/young-feet-double.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +feat: provide AST node types with internal types stripped out diff --git a/packages/svelte/scripts/generate-types.js b/packages/svelte/scripts/generate-types.js index ed9009df6a22..7678ed35b1c9 100644 --- a/packages/svelte/scripts/generate-types.js +++ b/packages/svelte/scripts/generate-types.js @@ -21,6 +21,10 @@ fs.writeFileSync(`${dir}/types/compiler/interfaces.d.ts`, "import '../index.js'; await createBundle({ output: `${dir}/types/index.d.ts`, + compilerOptions: { + // so that types/properties with `@internal` (and its dependencies) are removed from the output + stripInternal: true + }, modules: { [pkg.name]: `${dir}/src/index.d.ts`, [`${pkg.name}/action`]: `${dir}/src/action/public.d.ts`, diff --git a/packages/svelte/src/compiler/index.js b/packages/svelte/src/compiler/index.js index e18c3c2ec3fb..88cc9880ee4d 100644 --- a/packages/svelte/src/compiler/index.js +++ b/packages/svelte/src/compiler/index.js @@ -90,7 +90,7 @@ export function compileModule(source, options) { * @overload * @param {string} source * @param {{ filename?: string; modern?: false }} [options] - * @returns {LegacyRoot} + * @returns {Record} */ /** @@ -102,7 +102,7 @@ export function compileModule(source, options) { * https://svelte.dev/docs/svelte-compiler#svelte-parse * @param {string} source * @param {{ filename?: string; rootDir?: string; modern?: boolean }} [options] - * @returns {Root | LegacyRoot} + * @returns {Root | Record} */ export function parse(source, { filename, rootDir, modern } = {}) { state.reset_warning_filter(() => false); diff --git a/packages/svelte/src/compiler/public.d.ts b/packages/svelte/src/compiler/public.d.ts index b7bd39200127..ec7d0be9a62a 100644 --- a/packages/svelte/src/compiler/public.d.ts +++ b/packages/svelte/src/compiler/public.d.ts @@ -12,3 +12,43 @@ export type { CompileResult, Warning } from './types/index'; + +export type { + AnimateDirective, + Attribute, + AwaitBlock, + BindDirective, + ClassDirective, + Comment, + Component, + ConstTag, + DebugTag, + EachBlock, + ExpressionTag, + Fragment, + HtmlTag, + IfBlock, + KeyBlock, + LetDirective, + OnDirective, + RegularElement, + RenderTag, + Root, + Script, + SlotElement, + StyleDirective, + SvelteBody, + SvelteComponent, + SvelteDocument, + SvelteElement, + SvelteFragment, + SvelteHead, + SvelteWindow, + SvelteSelf, + SnippetBlock, + SpreadAttribute, + Text, + TitleElement, + TransitionDirective, + UseDirective +} from './types/template'; diff --git a/packages/svelte/src/compiler/types/template.d.ts b/packages/svelte/src/compiler/types/template.d.ts index a4480ce2f12b..74ce5659c24a 100644 --- a/packages/svelte/src/compiler/types/template.d.ts +++ b/packages/svelte/src/compiler/types/template.d.ts @@ -22,13 +22,14 @@ export interface BaseNode { type: string; start: number; end: number; - /** This is set during parsing on elements/components/expressions/text (but not attributes etc) */ + /** @internal This is set during parsing on elements/components/expressions/text (but not attributes etc) */ parent: SvelteNode | null; } export interface Fragment { type: 'Fragment'; nodes: Array; + /** @internal */ metadata: { /** * Fragments declare their own scopes. A transparent fragment is one whose scope @@ -63,6 +64,7 @@ export interface Root extends BaseNode { instance: Script | null; /** The parsed `