From 503092200d9fefac5f5034f8f29d35a530ce3bde Mon Sep 17 00:00:00 2001 From: xeho91 Date: Sat, 11 May 2024 00:53:55 +0800 Subject: [PATCH 1/3] fix: replace `modern` to `modernAst` Add missing `modernAst` in `validate_component_options`. --- packages/svelte/src/compiler/index.js | 20 +++++++++---------- .../svelte/src/compiler/validate-options.js | 2 ++ packages/svelte/tests/parser-modern/test.ts | 2 +- packages/svelte/types/index.d.ts | 12 +++++------ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/svelte/src/compiler/index.js b/packages/svelte/src/compiler/index.js index ba312a1a639e..e4c7ac000ce1 100644 --- a/packages/svelte/src/compiler/index.js +++ b/packages/svelte/src/compiler/index.js @@ -107,38 +107,38 @@ function handle_compile_error(error, filename, source) { /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * @overload * @param {string} source - * @param {{ filename?: string; modern: true }} options + * @param {{ filename?: string; modernAst: true }} options * @returns {import('#compiler').Root} */ /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * @overload * @param {string} source - * @param {{ filename?: string; modern?: false }} [options] + * @param {{ filename?: string; modernAst?: false }} [options] * @returns {import('./types/legacy-nodes.js').LegacyRoot} */ /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * @param {string} source - * @param {{ filename?: string; modern?: boolean }} [options] + * @param {{ filename?: string; modernAst?: boolean }} [options] * @returns {import('#compiler').Root | import('./types/legacy-nodes.js').LegacyRoot} */ export function parse(source, options = {}) { @@ -154,7 +154,7 @@ export function parse(source, options = {}) { throw e; } - return to_public_ast(source, ast, options.modern); + return to_public_ast(source, ast, options.modernAst); } /** diff --git a/packages/svelte/src/compiler/validate-options.js b/packages/svelte/src/compiler/validate-options.js index e58b5deff324..a55258550d4d 100644 --- a/packages/svelte/src/compiler/validate-options.js +++ b/packages/svelte/src/compiler/validate-options.js @@ -83,6 +83,8 @@ export const validate_component_options = namespace: list(['html', 'svg', 'foreign']), + modernAst: boolean(false), + outputFilename: string(undefined), preserveComments: boolean(false), diff --git a/packages/svelte/tests/parser-modern/test.ts b/packages/svelte/tests/parser-modern/test.ts index 7576bddfe483..1a8256488ba5 100644 --- a/packages/svelte/tests/parser-modern/test.ts +++ b/packages/svelte/tests/parser-modern/test.ts @@ -15,7 +15,7 @@ const { test, run } = suite(async (config, cwd) => { const actual = JSON.parse( JSON.stringify( parse(input, { - modern: true + modernAst: true }) ) ); diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 3a26e79e91d7..7421954c3c5e 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -504,26 +504,26 @@ declare module 'svelte/compiler' { /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * */ export function parse(source: string, options: { filename?: string; - modern: true; + modernAst: true; }): Root; /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * */ export function parse(source: string, options?: { filename?: string | undefined; - modern?: false | undefined; + modernAst?: false | undefined; } | undefined): LegacyRoot; /** * @deprecated Replace this with `import { walk } from 'estree-walker'` From a9eed9da1d0f9fff1f3011dc03972b2e82f6ebaf Mon Sep 17 00:00:00 2001 From: xeho91 Date: Sat, 11 May 2024 03:55:20 +0800 Subject: [PATCH 2/3] Revert changes unrelated to `compile` --- packages/svelte/src/compiler/index.js | 20 ++++---- packages/svelte/tests/parser-modern/test.ts | 2 +- packages/svelte/types/index.d.ts | 56 ++++++++++----------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/svelte/src/compiler/index.js b/packages/svelte/src/compiler/index.js index e4c7ac000ce1..ba312a1a639e 100644 --- a/packages/svelte/src/compiler/index.js +++ b/packages/svelte/src/compiler/index.js @@ -107,38 +107,38 @@ function handle_compile_error(error, filename, source) { /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * @overload * @param {string} source - * @param {{ filename?: string; modernAst: true }} options + * @param {{ filename?: string; modern: true }} options * @returns {import('#compiler').Root} */ /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * @overload * @param {string} source - * @param {{ filename?: string; modernAst?: false }} [options] + * @param {{ filename?: string; modern?: false }} [options] * @returns {import('./types/legacy-nodes.js').LegacyRoot} */ /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * @param {string} source - * @param {{ filename?: string; modernAst?: boolean }} [options] + * @param {{ filename?: string; modern?: boolean }} [options] * @returns {import('#compiler').Root | import('./types/legacy-nodes.js').LegacyRoot} */ export function parse(source, options = {}) { @@ -154,7 +154,7 @@ export function parse(source, options = {}) { throw e; } - return to_public_ast(source, ast, options.modernAst); + return to_public_ast(source, ast, options.modern); } /** diff --git a/packages/svelte/tests/parser-modern/test.ts b/packages/svelte/tests/parser-modern/test.ts index 1a8256488ba5..7576bddfe483 100644 --- a/packages/svelte/tests/parser-modern/test.ts +++ b/packages/svelte/tests/parser-modern/test.ts @@ -15,7 +15,7 @@ const { test, run } = suite(async (config, cwd) => { const actual = JSON.parse( JSON.stringify( parse(input, { - modernAst: true + modern: true }) ) ); diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 7421954c3c5e..7fdba21ab661 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -504,26 +504,26 @@ declare module 'svelte/compiler' { /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * */ export function parse(source: string, options: { filename?: string; - modernAst: true; + modern: true; }): Root; /** * The parse function parses a component, returning only its abstract syntax tree. * - * The `modernAst` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. - * `modernAst` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. + * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. + * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * https://svelte.dev/docs/svelte-compiler#svelte-parse * */ export function parse(source: string, options?: { filename?: string | undefined; - modernAst?: false | undefined; + modern?: false | undefined; } | undefined): LegacyRoot; /** * @deprecated Replace this with `import { walk } from 'estree-walker'` @@ -1051,15 +1051,15 @@ declare module 'svelte/compiler' { filename?: string | undefined; } | undefined): Promise; export class CompileError extends Error { - + constructor(code: string, message: string, position: [number, number] | undefined); - + filename: CompileError_1['filename']; - + position: CompileError_1['position']; - + start: CompileError_1['start']; - + end: CompileError_1['end']; code: string; } @@ -1078,9 +1078,9 @@ declare module 'svelte/compiler' { code: string; }; class Scope { - + constructor(root: ScopeRoot, parent: Scope | null, porous: boolean); - + root: ScopeRoot; /** * The immediate parent scope @@ -1108,25 +1108,25 @@ declare module 'svelte/compiler' { * which is usually an error. Block statements do not increase this value */ function_depth: number; - + declare(node: import('estree').Identifier, kind: Binding['kind'], declaration_kind: DeclarationKind, initial?: null | import('estree').Expression | import('estree').FunctionDeclaration | import('estree').ClassDeclaration | import('estree').ImportDeclaration | EachBlock): Binding; child(porous?: boolean): Scope; - + generate(preferred_name: string): string; - + get(name: string): Binding | null; - + get_bindings(node: import('estree').VariableDeclarator | LetDirective): Binding[]; - + owner(name: string): Scope | null; - + reference(node: import('estree').Identifier, path: SvelteNode[]): void; #private; } class ScopeRoot { - + conflicts: Set; - + unique(preferred_name: string): import("estree").Identifier; } namespace Css { @@ -2032,21 +2032,21 @@ declare module 'svelte/motion' { declare module 'svelte/reactivity' { class ReactiveDate extends Date { - + constructor(...values: any[]); #private; } class ReactiveSet extends Set { - + constructor(value?: Iterable | null | undefined); - + add(value: T): this; #private; } class ReactiveMap extends Map { - + constructor(value?: Iterable | null | undefined); - + set(key: K, value: V): this; #private; } @@ -2055,7 +2055,7 @@ declare module 'svelte/reactivity' { #private; } class ReactiveURLSearchParams extends URLSearchParams { - + [REPLACE](params: URLSearchParams): void; #private; } @@ -2877,4 +2877,4 @@ declare function $inspect( */ declare function $host(): El; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file +//# sourceMappingURL=index.d.ts.map From f56e1a11cc96d8b9a9e0ad4fed569a69dad25d96 Mon Sep 17 00:00:00 2001 From: xeho91 Date: Sat, 11 May 2024 04:07:31 +0800 Subject: [PATCH 3/3] Fix format issue --- packages/svelte/types/index.d.ts | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 7fdba21ab661..3a26e79e91d7 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -1051,15 +1051,15 @@ declare module 'svelte/compiler' { filename?: string | undefined; } | undefined): Promise; export class CompileError extends Error { - + constructor(code: string, message: string, position: [number, number] | undefined); - + filename: CompileError_1['filename']; - + position: CompileError_1['position']; - + start: CompileError_1['start']; - + end: CompileError_1['end']; code: string; } @@ -1078,9 +1078,9 @@ declare module 'svelte/compiler' { code: string; }; class Scope { - + constructor(root: ScopeRoot, parent: Scope | null, porous: boolean); - + root: ScopeRoot; /** * The immediate parent scope @@ -1108,25 +1108,25 @@ declare module 'svelte/compiler' { * which is usually an error. Block statements do not increase this value */ function_depth: number; - + declare(node: import('estree').Identifier, kind: Binding['kind'], declaration_kind: DeclarationKind, initial?: null | import('estree').Expression | import('estree').FunctionDeclaration | import('estree').ClassDeclaration | import('estree').ImportDeclaration | EachBlock): Binding; child(porous?: boolean): Scope; - + generate(preferred_name: string): string; - + get(name: string): Binding | null; - + get_bindings(node: import('estree').VariableDeclarator | LetDirective): Binding[]; - + owner(name: string): Scope | null; - + reference(node: import('estree').Identifier, path: SvelteNode[]): void; #private; } class ScopeRoot { - + conflicts: Set; - + unique(preferred_name: string): import("estree").Identifier; } namespace Css { @@ -2032,21 +2032,21 @@ declare module 'svelte/motion' { declare module 'svelte/reactivity' { class ReactiveDate extends Date { - + constructor(...values: any[]); #private; } class ReactiveSet extends Set { - + constructor(value?: Iterable | null | undefined); - + add(value: T): this; #private; } class ReactiveMap extends Map { - + constructor(value?: Iterable | null | undefined); - + set(key: K, value: V): this; #private; } @@ -2055,7 +2055,7 @@ declare module 'svelte/reactivity' { #private; } class ReactiveURLSearchParams extends URLSearchParams { - + [REPLACE](params: URLSearchParams): void; #private; } @@ -2877,4 +2877,4 @@ declare function $inspect( */ declare function $host(): El; -//# sourceMappingURL=index.d.ts.map +//# sourceMappingURL=index.d.ts.map \ No newline at end of file