Skip to content

Commit

Permalink
feat: provide AST node types with internal types stripped out
Browse files Browse the repository at this point in the history
Also hides the legacy AST types from the output

closes #12292
  • Loading branch information
dummdidumm committed Aug 22, 2024
1 parent 6fc80f0 commit 075ffe7
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 501 deletions.
4 changes: 2 additions & 2 deletions packages/svelte/src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function compileModule(source, options) {
* @overload
* @param {string} source
* @param {{ filename?: string; modern?: false }} [options]
* @returns {LegacyRoot}
* @returns {Record<string, any>}
*/

/**
Expand All @@ -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<string, any>}
*/
export function parse(source, { filename, rootDir, modern } = {}) {
state.reset_warning_filter(() => false);
Expand Down
40 changes: 40 additions & 0 deletions packages/svelte/src/compiler/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
16 changes: 8 additions & 8 deletions packages/svelte/src/compiler/types/template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export interface RenderTag extends BaseNode {
type Tag = ExpressionTag | HtmlTag | ConstTag | DebugTag | RenderTag;

/** An `animate:` directive */
interface AnimateDirective extends BaseNode {
export interface AnimateDirective extends BaseNode {
type: 'AnimateDirective';
/** The 'x' in `animate:x` */
name: string;
Expand Down Expand Up @@ -246,7 +246,7 @@ export interface StyleDirective extends BaseNode {

// TODO have separate in/out/transition directives
/** A `transition:`, `in:` or `out:` directive */
interface TransitionDirective extends BaseNode {
export interface TransitionDirective extends BaseNode {
type: 'TransitionDirective';
/** The 'x' in `transition:x` */
name: string;
Expand All @@ -260,7 +260,7 @@ interface TransitionDirective extends BaseNode {
}

/** A `use:` directive */
interface UseDirective extends BaseNode {
export interface UseDirective extends BaseNode {
type: 'UseDirective';
/** The 'x' in `use:x` */
name: string;
Expand Down Expand Up @@ -293,7 +293,7 @@ export interface Component extends BaseElement {
};
}

interface TitleElement extends BaseElement {
export interface TitleElement extends BaseElement {
type: 'TitleElement';
name: 'title';
}
Expand All @@ -317,7 +317,7 @@ export interface RegularElement extends BaseElement {
};
}

interface SvelteBody extends BaseElement {
export interface SvelteBody extends BaseElement {
type: 'SvelteBody';
name: 'svelte:body';
}
Expand All @@ -332,7 +332,7 @@ export interface SvelteComponent extends BaseElement {
};
}

interface SvelteDocument extends BaseElement {
export interface SvelteDocument extends BaseElement {
type: 'SvelteDocument';
name: 'svelte:document';
}
Expand Down Expand Up @@ -362,7 +362,7 @@ export interface SvelteFragment extends BaseElement {
name: 'svelte:fragment';
}

interface SvelteHead extends BaseElement {
export interface SvelteHead extends BaseElement {
type: 'SvelteHead';
name: 'svelte:head';
}
Expand All @@ -382,7 +382,7 @@ export interface SvelteSelf extends BaseElement {
};
}

interface SvelteWindow extends BaseElement {
export interface SvelteWindow extends BaseElement {
type: 'SvelteWindow';
name: 'svelte:window';
}
Expand Down
Loading

0 comments on commit 075ffe7

Please sign in to comment.