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: add missing modernAst in validate_component_options #11542

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions packages/svelte/src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand All @@ -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);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/src/compiler/validate-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export const validate_component_options =

namespace: list(['html', 'svg', 'foreign']),

modernAst: boolean(false),
xeho91 marked this conversation as resolved.
Show resolved Hide resolved

outputFilename: string(undefined),

preserveComments: boolean(false),
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/tests/parser-modern/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { test, run } = suite<ParserTest>(async (config, cwd) => {
const actual = JSON.parse(
JSON.stringify(
parse(input, {
modern: true
modernAst: true
})
)
);
Expand Down
12 changes: 6 additions & 6 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'`
Expand Down