Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update return type of parse function #13438

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/little-ties-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: update return type of `parse` function
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function compileModule(source, options) {
* @overload
* @param {string} source
* @param {{ filename?: string; modern?: false }} [options]
* @returns {Record<string, any>}
* @returns {LegacyRoot}
*/

/**
Expand Down
253 changes: 251 additions & 2 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ declare module 'svelte/animate' {
}

declare module 'svelte/compiler' {
import type { Expression, Identifier, ArrayExpression, ArrowFunctionExpression, VariableDeclaration, VariableDeclarator, MemberExpression, ObjectExpression, Pattern, Program, ChainExpression, SimpleCallExpression } from 'estree';
import type { Expression, Identifier, ArrayExpression, ArrowFunctionExpression, VariableDeclaration, VariableDeclarator, MemberExpression, ObjectExpression, Pattern, Program, ChainExpression, SimpleCallExpression, AssignmentExpression } from 'estree';
import type { SourceMap } from 'magic-string';
import type { Location } from 'locate-character';
/**
Expand Down Expand Up @@ -607,7 +607,7 @@ declare module 'svelte/compiler' {
export function parse(source: string, options?: {
filename?: string;
modern?: false;
} | undefined): Record<string, any>;
} | undefined): LegacyRoot;
/**
* @deprecated Replace this with `import { walk } from 'estree-walker'`
* */
Expand Down Expand Up @@ -1267,6 +1267,255 @@ declare module 'svelte/compiler' {
export function migrate(source: string): {
code: string;
};
interface BaseNode {
type: string;
start: number;
end: number;
}

interface BaseElement extends BaseNode {
name: string;
attributes: Array<LegacyAttributeLike>;
children: Array<LegacyElementLike>;
}

interface LegacyRoot extends BaseNode {
html: LegacySvelteNode;
css?: any;
instance?: any;
module?: any;
}

interface LegacyAction extends BaseNode {
type: 'Action';
/** The 'x' in `use:x` */
name: string;
/** The 'y' in `use:x={y}` */
expression: null | Expression;
}

interface LegacyAnimation extends BaseNode {
type: 'Animation';
/** The 'x' in `animate:x` */
name: string;
/** The y in `animate:x={y}` */
expression: null | Expression;
}

interface LegacyBinding extends BaseNode {
type: 'Binding';
/** The 'x' in `bind:x` */
name: string;
/** The y in `bind:x={y}` */
expression: Identifier | MemberExpression;
}

interface LegacyBody extends BaseElement {
type: 'Body';
name: 'svelte:body';
}

interface LegacyAttribute extends BaseNode {
type: 'Attribute';
name: string;
value: true | Array<AST.Text | LegacyMustacheTag | LegacyAttributeShorthand>;
}

interface LegacyAttributeShorthand extends BaseNode {
type: 'AttributeShorthand';
expression: Expression;
}

interface LegacyLet extends BaseNode {
type: 'Let';
/** The 'x' in `let:x` */
name: string;
/** The 'y' in `let:x={y}` */
expression: null | Identifier | ArrayExpression | ObjectExpression;
}

interface LegacyCatchBlock extends BaseNode {
type: 'CatchBlock';
children: LegacySvelteNode[];
skip: boolean;
}

interface LegacyClass extends BaseNode {
type: 'Class';
/** The 'x' in `class:x` */
name: 'class';
/** The 'y' in `class:x={y}`, or the `x` in `class:x` */
expression: Expression;
}

interface LegacyDocument extends BaseElement {
type: 'Document';
}

interface LegacyElement {
type: 'Element';
}

interface LegacyEventHandler extends BaseNode {
type: 'EventHandler';
/** The 'x' in `on:x` */
name: string;
/** The 'y' in `on:x={y}` */
expression: null | Expression;
modifiers: string[];
}

interface LegacyHead extends BaseElement {
type: 'Head';
}

interface LegacyInlineComponent extends BaseElement {
type: 'InlineComponent';
/** Set if this is a `<svelte:component>` */
expression?: Expression;
}

interface LegacyMustacheTag extends BaseNode {
type: 'MustacheTag';
expression: Expression;
}

interface LegacyOptions {
type: 'Options';
name: 'svelte:options';
attributes: Array<any>;
}

interface LegacyPendingBlock extends BaseNode {
type: 'PendingBlock';
children: LegacySvelteNode[];
skip: boolean;
}

interface LegacyRawMustacheTag extends BaseNode {
type: 'RawMustacheTag';
expression: Expression;
}

interface LegacySpread extends BaseNode {
type: 'Spread';
expression: Expression;
}

interface LegacySlot extends BaseElement {
type: 'Slot';
}

interface LegacySlotTemplate extends BaseElement {
type: 'SlotTemplate';
}

interface LegacyThenBlock extends BaseNode {
type: 'ThenBlock';
children: LegacySvelteNode[];
skip: boolean;
}

interface LegacyTitle extends BaseElement {
type: 'Title';
name: 'title';
}

interface LegacyConstTag extends BaseNode {
type: 'ConstTag';
expression: AssignmentExpression;
}

interface LegacyTransition extends BaseNode {
type: 'Transition';
/** The 'x' in `transition:x` */
name: string;
/** The 'y' in `transition:x={y}` */
expression: null | Expression;
modifiers: Array<'local' | 'global'>;
/** True if this is a `transition:` or `in:` directive */
intro: boolean;
/** True if this is a `transition:` or `out:` directive */
outro: boolean;
}

/** A `style:` directive */
interface LegacyStyleDirective extends BaseNode {
type: 'StyleDirective';
/** The 'x' in `style:x` */
name: string;
/** The 'y' in `style:x={y}` */
value: true | Array<AST.ExpressionTag | AST.Text>;
modifiers: Array<'important'>;
}

interface LegacyWindow extends BaseElement {
type: 'Window';
}

interface LegacyComment extends BaseNode {
type: 'Comment';
/** the contents of the comment */
data: string;
/** any svelte-ignore directives — <!-- svelte-ignore a b c --> would result in ['a', 'b', 'c'] */
ignores: string[];
}

type LegacyDirective =
| LegacyAnimation
| LegacyBinding
| LegacyClass
| LegacyLet
| LegacyEventHandler
| LegacyStyleDirective
| LegacyTransition
| LegacyAction;

type LegacyAttributeLike = LegacyAttribute | LegacySpread | LegacyDirective;

type LegacyElementLike =
| LegacyBody
| LegacyCatchBlock
| LegacyComment
| LegacyDocument
| LegacyElement
| LegacyHead
| LegacyInlineComponent
| LegacyMustacheTag
| LegacyOptions
| LegacyPendingBlock
| LegacyRawMustacheTag
| LegacySlot
| LegacySlotTemplate
| LegacyThenBlock
| LegacyTitle
| LegacyWindow;

interface LegacyStyle extends BaseNode {
type: 'Style';
attributes: any[];
content: {
start: number;
end: number;
styles: string;
};
children: any[];
}

interface LegacySelector extends BaseNode {
type: 'Selector';
children: Array<Css.Combinator | Css.SimpleSelector>;
}

type LegacyCssNode = LegacyStyle | LegacySelector;

type LegacySvelteNode =
| LegacyConstTag
| LegacyElementLike
| LegacyAttributeLike
| LegacyAttributeShorthand
| LegacyCssNode
| AST.Text;
namespace Css {
export interface BaseNode {
start: number;
Expand Down