diff --git a/explorer-v2/package.json b/explorer-v2/package.json index 520ea877..fa3a783f 100644 --- a/explorer-v2/package.json +++ b/explorer-v2/package.json @@ -12,27 +12,27 @@ "preview": "vite preview" }, "dependencies": { - "@fontsource/fira-mono": "^5.0.13", - "@typescript-eslint/parser": "^7.13.1", + "@fontsource/fira-mono": "^5.1.0", + "@typescript-eslint/parser": "^7.18.0", "eslint": "^8.57.0", "eslint-scope": "^7.2.2", - "esquery": "^1.5.0", + "esquery": "^1.6.0", "pako": "^2.1.0", - "svelte": "^5.0.0-next.160", + "svelte": "^5.0.0-next.245", "svelte-eslint-parser": "link:..", - "tslib": "^2.6.3" + "tslib": "^2.7.0" }, "devDependencies": { - "@sveltejs/adapter-static": "^3.0.2", - "@sveltejs/kit": "^2.5.17", - "@sveltejs/vite-plugin-svelte": "^3.1.1", + "@sveltejs/adapter-static": "^3.0.4", + "@sveltejs/kit": "^2.5.26", + "@sveltejs/vite-plugin-svelte": "^3.1.2", "monaco-editor": "^0.50.0", - "prettier": "^3.3.2", - "prettier-plugin-svelte": "^3.2.4", + "prettier": "^3.3.3", + "prettier-plugin-svelte": "^3.2.6", "string-replace-loader": "^3.1.0", - "typescript": "^5.4.5", - "vite": "^5.3.1", - "webpack": "^5.92.1", + "typescript": "^5.6.2", + "vite": "^5.4.4", + "webpack": "^5.94.0", "webpack-cli": "^5.1.4", "wrapper-webpack-plugin": "^2.2.2" } diff --git a/explorer-v2/src/lib/MonacoEditor.svelte b/explorer-v2/src/lib/MonacoEditor.svelte index 1b9edf52..200764c4 100644 --- a/explorer-v2/src/lib/MonacoEditor.svelte +++ b/explorer-v2/src/lib/MonacoEditor.svelte @@ -1,4 +1,4 @@ - diff --git a/package.json b/package.json index 314ecbe0..9263f6db 100644 --- a/package.json +++ b/package.json @@ -63,51 +63,51 @@ }, "devDependencies": { "@changesets/changelog-github": "^0.5.0", - "@changesets/cli": "^2.27.7", - "@changesets/get-release-plan": "^4.0.3", + "@changesets/cli": "^2.27.8", + "@changesets/get-release-plan": "^4.0.4", "@ota-meshi/eslint-plugin": "^0.15.3", "@types/benchmark": "^2.1.5", - "@types/chai": "^4.3.16", - "@types/eslint": "^9.0.0", + "@types/chai": "^4.3.19", + "@types/eslint": "^9.6.1", "@types/eslint-scope": "^3.7.7", "@types/eslint-visitor-keys": "^3.3.0", "@types/estree": "^1.0.5", - "@types/mocha": "^10.0.7", - "@types/node": "^20.14.11", + "@types/mocha": "^10.0.8", + "@types/node": "^20.16.5", "@types/semver": "^7.5.8", - "@typescript-eslint/eslint-plugin": "^7.16.1", + "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "~7.18.0", "@typescript-eslint/types": "~7.18.0", "benchmark": "^2.1.4", - "chai": "^4.4.1", + "chai": "^4.5.0", "env-cmd": "^10.1.0", - "esbuild": "^0.23.0", - "esbuild-register": "^3.5.0", + "esbuild": "^0.23.1", + "esbuild-register": "^3.6.0", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-json-schema-validator": "^5.1.2", "eslint-plugin-jsonc": "^2.16.0", - "eslint-plugin-n": "^17.9.0", + "eslint-plugin-n": "^17.10.2", "eslint-plugin-node-dependencies": "^0.12.0", "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-regexp": "^2.6.0", - "eslint-plugin-svelte": "^2.42.0", + "eslint-plugin-svelte": "^2.43.0", "eslint-plugin-yml": "^1.14.0", "estree-walker": "^3.0.3", "locate-character": "^3.0.0", - "magic-string": "^0.30.10", - "mocha": "^10.6.0", - "mocha-chai-jest-snapshot": "^1.1.4", + "magic-string": "^0.30.11", + "mocha": "^10.7.3", + "mocha-chai-jest-snapshot": "^1.1.6", "nyc": "^17.0.0", "prettier": "~3.3.3", "prettier-plugin-pkg": "^0.18.1", "prettier-plugin-svelte": "^3.2.6", "rimraf": "^6.0.1", "semver": "^7.6.3", - "svelte": "^5.0.0-next.191", - "svelte2tsx": "^0.7.13", - "typescript": "~5.5.3", + "svelte": "^5.0.0-next.245", + "svelte2tsx": "^0.7.19", + "typescript": "~5.6.2", "typescript-eslint-parser-for-extra-files": "^0.7.0" }, "publishConfig": { diff --git a/src/parser/compat.ts b/src/parser/compat.ts index 13f24b1b..7aa30d7f 100644 --- a/src/parser/compat.ts +++ b/src/parser/compat.ts @@ -40,11 +40,9 @@ export function getOptionsFromRoot( fragment: { type: "Fragment", nodes: [], - transparent: true, }, start: root.options.start, end: root.options.end, - parent: null as any, }; } return null; diff --git a/src/parser/html.ts b/src/parser/html.ts index 72ff4030..a4b43072 100644 --- a/src/parser/html.ts +++ b/src/parser/html.ts @@ -86,8 +86,6 @@ function parseAttribute(state: State): Compiler.Attribute { value: true, start, end: keyEnd, - metadata: null as any, - parent: null, }; } state.skipSpaces(); @@ -98,8 +96,6 @@ function parseAttribute(state: State): Compiler.Attribute { value: true, start, end: keyEnd, - metadata: null as any, - parent: null, }; } // parse value @@ -110,8 +106,6 @@ function parseAttribute(state: State): Compiler.Attribute { value: [value], start, end: state.index, - metadata: null as any, - parent: null, }; } @@ -149,8 +143,6 @@ function parseAttributeValue( expression, start, end, - metadata: null as any, - parent: null, }; } } @@ -164,7 +156,6 @@ function parseAttributeValue( raw: quote, start, end: state.index, - parent: null, }; } let c: string | undefined; @@ -179,7 +170,6 @@ function parseAttributeValue( raw: data, start: start + 1, end: end - 1, - parent: null, }; } } @@ -198,7 +188,6 @@ function parseAttributeValue( raw: data, start, end, - parent: null, }; } diff --git a/src/parser/svelte-ast-types-for-v5.ts b/src/parser/svelte-ast-types-for-v5.ts index 9dea265b..5e34c998 100644 --- a/src/parser/svelte-ast-types-for-v5.ts +++ b/src/parser/svelte-ast-types-for-v5.ts @@ -1,85 +1,49 @@ -// FIXME Since the node type is not provided by "svelte/compiler", -// we work around this by extracting the type from the parse function. -// See also https://github.com/sveltejs/svelte/issues/12292 +import type { AST } from "svelte/compiler"; -import type { parse } from "svelte/compiler"; +export type Root = AST.Root; +export type Fragment = AST.Fragment; +export type SvelteOptions = AST.SvelteOptions; +export type Script = AST.Script; -export type Root = ModernParseReturnType; -export type Fragment = Root["fragment"]; -export type SvelteOptions = Root["options"]; -export type Script = Root["instance"]; -type FragmentChild = Fragment["nodes"][number]; +export type Text = AST.Text; -export type Text = Extract; +export type ExpressionTag = AST.ExpressionTag; +export type HtmlTag = AST.HtmlTag; +export type ConstTag = AST.ConstTag; +export type DebugTag = AST.DebugTag; +export type RenderTag = AST.RenderTag; -export type ExpressionTag = Extract; -export type HtmlTag = Extract; -export type ConstTag = Extract; -export type DebugTag = Extract; -export type RenderTag = Extract; +export type Component = AST.Component; +export type TitleElement = AST.TitleElement; +export type SlotElement = AST.SlotElement; +export type RegularElement = AST.RegularElement; +export type SvelteBody = AST.SvelteBody; +export type SvelteComponent = AST.SvelteComponent; +export type SvelteDocument = AST.SvelteDocument; +export type SvelteElement = AST.SvelteElement; +export type SvelteFragment = AST.SvelteFragment; +export type SvelteHead = AST.SvelteHead; +export type SvelteOptionsRaw = AST.SvelteOptionsRaw; +export type SvelteSelf = AST.SvelteSelf; +export type SvelteWindow = AST.SvelteWindow; -export type Component = Extract; -export type TitleElement = Extract; -export type SlotElement = Extract; -export type RegularElement = Extract; -export type SvelteBody = Extract; -export type SvelteComponent = Extract< - FragmentChild, - { type: "SvelteComponent" } ->; -export type SvelteDocument = Extract; -export type SvelteElement = Extract; -export type SvelteFragment = Extract; -export type SvelteHead = Extract; -export type SvelteOptionsRaw = Extract< - FragmentChild, - { type: "SvelteOptions" } ->; -export type SvelteSelf = Extract; -export type SvelteWindow = Extract; +export type IfBlock = AST.IfBlock; +export type EachBlock = AST.EachBlock; +export type AwaitBlock = AST.AwaitBlock; +export type KeyBlock = AST.KeyBlock; +export type SnippetBlock = AST.SnippetBlock; -export type IfBlock = Extract; -export type EachBlock = Extract; -export type AwaitBlock = Extract; -export type KeyBlock = Extract; -export type SnippetBlock = Extract; - -export type Comment = Extract; -type ComponentAttribute = Component["attributes"][number]; -export type Attribute = Extract; -export type SpreadAttribute = Extract< - ComponentAttribute, - { type: "SpreadAttribute" } ->; -export type AnimateDirective = Extract< - ComponentAttribute, - { type: "AnimateDirective" } ->; -export type BindDirective = Extract< - ComponentAttribute, - { type: "BindDirective" } ->; -export type ClassDirective = Extract< - ComponentAttribute, - { type: "ClassDirective" } ->; -export type LetDirective = Extract< - ComponentAttribute, - { type: "LetDirective" } ->; -export type OnDirective = Extract; -export type StyleDirective = Extract< - ComponentAttribute, - { type: "StyleDirective" } ->; -export type TransitionDirective = Extract< - ComponentAttribute, - { type: "TransitionDirective" } ->; -export type UseDirective = Extract< - ComponentAttribute, - { type: "UseDirective" } ->; +export type Comment = AST.Comment; +export type Attribute = AST.Attribute; +export type SpreadAttribute = AST.SpreadAttribute; +export type AnimateDirective = AST.AnimateDirective; +export type BindDirective = AST.BindDirective; +export type ClassDirective = AST.ClassDirective; +export type LetDirective = AST.LetDirective; +export type OnDirective = AST.OnDirective; +export type StyleDirective = AST.StyleDirective; +export type TransitionDirective = AST.TransitionDirective; +export type UseDirective = AST.UseDirective; export type Tag = ExpressionTag | HtmlTag | ConstTag | DebugTag | RenderTag; export type ElementLike = @@ -107,10 +71,3 @@ export type Directive = | StyleDirective | TransitionDirective | UseDirective; - -type ModernParseReturnType = T extends { - (source: string, options: { filename?: string; modern: true }): infer R; - (...args: any[]): any; -} - ? R - : any; diff --git a/tests/fixtures/parser/ast/self-closing-style01-requirements.json b/tests/fixtures/parser/ast/self-closing-style01-requirements.json new file mode 100644 index 00000000..30d7612a --- /dev/null +++ b/tests/fixtures/parser/ast/self-closing-style01-requirements.json @@ -0,0 +1,5 @@ +{ + "parse": { + "svelte": "^4 || ^3" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte index d992f19b..2009d36a 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/10-typing-snippets-type-output.svelte @@ -11,12 +11,12 @@ {#if children} - {@render children()} + {@render children()} {/if} {#each data as d} - {@render row(d)} + {@render row(d)} {/each}
diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte index 4c5b05d6..204db6f5 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/11-typing-snippets-type-output.svelte @@ -11,12 +11,12 @@ {#if children} - {@render children()} + {@render children()} {/if} {#each data as d} - {@render row(d)} + {@render row(d)} {/each}
diff --git a/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte b/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte index 3490d02c..9511f75b 100644 --- a/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte +++ b/tests/fixtures/parser/ast/svelte5/generics01-snippets-type-output.svelte @@ -12,12 +12,12 @@ {#if children} - {@render children()} + {@render children()} {/if} {#each data as d} - {@render row(d)} + {@render row(d)} {/each}
diff --git a/tests/fixtures/parser/style-context/self-closing-style-element-requirements.json b/tests/fixtures/parser/style-context/self-closing-style-element-requirements.json new file mode 100644 index 00000000..30d7612a --- /dev/null +++ b/tests/fixtures/parser/style-context/self-closing-style-element-requirements.json @@ -0,0 +1,5 @@ +{ + "parse": { + "svelte": "^4 || ^3" + } +} \ No newline at end of file diff --git a/tests/src/parser/__snapshots__/html.ts.snap b/tests/src/parser/__snapshots__/html.ts.snap index 56794774..344231d9 100644 --- a/tests/src/parser/__snapshots__/html.ts.snap +++ b/tests/src/parser/__snapshots__/html.ts.snap @@ -12,16 +12,13 @@ Object { "attributes": Array [ Object { "end": 17, - "metadata": null, "name": "lang", - "parent": null, "start": 8, "type": "Attribute", "value": Array [ Object { "data": "ts", "end": 16, - "parent": null, "raw": "ts", "start": 14, "type": "Text", @@ -38,16 +35,13 @@ Object { "attributes": Array [ Object { "end": 17, - "metadata": null, "name": "lang", - "parent": null, "start": 8, "type": "Attribute", "value": Array [ Object { "data": "ts", "end": 16, - "parent": null, "raw": "ts", "start": 14, "type": "Text", @@ -64,16 +58,13 @@ Object { "attributes": Array [ Object { "end": 15, - "metadata": null, "name": "lang", - "parent": null, "start": 8, "type": "Attribute", "value": Array [ Object { "data": "ts", "end": 15, - "parent": null, "raw": "ts", "start": 13, "type": "Text", @@ -90,9 +81,7 @@ Object { "attributes": Array [ Object { "end": 13, - "metadata": null, "name": "global", - "parent": null, "start": 7, "type": "Attribute", "value": true, @@ -107,9 +96,7 @@ Object { "attributes": Array [ Object { "end": 13, - "metadata": null, "name": "global", - "parent": null, "start": 7, "type": "Attribute", "value": true, @@ -124,9 +111,7 @@ Object { "attributes": Array [ Object { "end": 4, - "metadata": null, "name": "attr", - "parent": null, "start": 0, "type": "Attribute", "value": true, @@ -141,16 +126,13 @@ Object { "attributes": Array [ Object { "end": 16, - "metadata": null, "name": "attr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ Object { "data": "value", "end": 15, - "parent": null, "raw": "value", "start": 10, "type": "Text", @@ -167,9 +149,7 @@ Object { "attributes": Array [ Object { "end": 4, - "metadata": null, "name": "attr", - "parent": null, "start": 0, "type": "Attribute", "value": true, @@ -184,16 +164,13 @@ Object { "attributes": Array [ Object { "end": 12, - "metadata": null, "name": "attr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ Object { "data": "value", "end": 11, - "parent": null, "raw": "value", "start": 6, "type": "Text", @@ -210,16 +187,13 @@ Object { "attributes": Array [ Object { "end": 8, - "metadata": null, "name": "empty", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ Object { "data": "", "end": 7, - "parent": null, "raw": "", "start": 7, "type": "Text", @@ -236,16 +210,13 @@ Object { "attributes": Array [ Object { "end": 8, - "metadata": null, "name": "empty", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ Object { "data": "", "end": 7, - "parent": null, "raw": "", "start": 7, "type": "Text", @@ -262,9 +233,7 @@ Object { "attributes": Array [ Object { "end": 13, - "metadata": null, "name": "expr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ @@ -278,8 +247,6 @@ Object { "type": "Literal", "value": true, }, - "metadata": null, - "parent": null, "start": 5, "type": "ExpressionTag", }, @@ -295,9 +262,7 @@ Object { "attributes": Array [ Object { "end": 13, - "metadata": null, "name": "expr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ @@ -311,8 +276,6 @@ Object { "type": "Literal", "value": true, }, - "metadata": null, - "parent": null, "start": 5, "type": "ExpressionTag", }, @@ -328,9 +291,7 @@ Object { "attributes": Array [ Object { "end": 10, - "metadata": null, "name": "expr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ @@ -344,8 +305,6 @@ Object { "type": "Literal", "value": "}", }, - "metadata": null, - "parent": null, "start": 5, "type": "ExpressionTag", }, @@ -361,9 +320,7 @@ Object { "attributes": Array [ Object { "end": 10, - "metadata": null, "name": "expr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ @@ -377,8 +334,6 @@ Object { "type": "Literal", "value": "s", }, - "metadata": null, - "parent": null, "start": 5, "type": "ExpressionTag", }, @@ -394,9 +349,7 @@ Object { "attributes": Array [ Object { "end": 15, - "metadata": null, "name": "expr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ @@ -417,8 +370,6 @@ Object { "type": "Literal", "value": "}", }, - "metadata": null, - "parent": null, "start": 5, "type": "ExpressionTag", }, @@ -435,9 +386,7 @@ Object { "attributes": Array [ Object { "end": 19, - "metadata": null, "name": "expr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ @@ -464,8 +413,6 @@ Object { "type": "Literal", "value": "}", }, - "metadata": null, - "parent": null, "start": 5, "type": "ExpressionTag", }, @@ -481,9 +428,7 @@ Object { "attributes": Array [ Object { "end": 11, - "metadata": null, "name": "expr", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ @@ -497,8 +442,6 @@ Object { "type": "Literal", "value": true, }, - "metadata": null, - "parent": null, "start": 5, "type": "ExpressionTag", }, @@ -514,16 +457,13 @@ Object { "attributes": Array [ Object { "end": 9, - "metadata": null, "name": "quote", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ Object { "data": "'", "end": 8, - "parent": null, "raw": "'", "start": 7, "type": "Text", @@ -540,16 +480,13 @@ Object { "attributes": Array [ Object { "end": 9, - "metadata": null, "name": "quote", - "parent": null, "start": 0, "type": "Attribute", "value": Array [ Object { "data": "\\"", "end": 8, - "parent": null, "raw": "\\"", "start": 7, "type": "Text", diff --git a/tests/src/parser/style-context.ts b/tests/src/parser/style-context.ts index 87aee31a..109e71e8 100644 --- a/tests/src/parser/style-context.ts +++ b/tests/src/parser/style-context.ts @@ -26,6 +26,9 @@ describe("Check for AST.", () => { config, meetRequirements, } of listupFixtures(STYLE_CONTEXT_FIXTURE_ROOT)) { + if (!meetRequirements("parse")) { + continue; + } describe(inputFileName, () => { let result: any; diff --git a/tools/update-fixtures.ts b/tools/update-fixtures.ts index 2099969a..cc43ee7e 100644 --- a/tools/update-fixtures.ts +++ b/tools/update-fixtures.ts @@ -135,9 +135,16 @@ for (const { input, inputFileName, outputFileName, config } of listupFixtures( } } -for (const { input, inputFileName, outputFileName, config } of listupFixtures( - STYLE_CONTEXT_FIXTURE_ROOT, -)) { +for (const { + input, + inputFileName, + outputFileName, + config, + meetRequirements, +} of listupFixtures(STYLE_CONTEXT_FIXTURE_ROOT)) { + if (!meetRequirements("parse")) { + continue; + } const result = parse(input, inputFileName, config); const styleContext = result.services.getStyleContext(); fs.writeFileSync( @@ -147,9 +154,16 @@ for (const { input, inputFileName, outputFileName, config } of listupFixtures( ); } -for (const { input, inputFileName, outputFileName, config } of listupFixtures( - STYLE_LOCATION_FIXTURE_ROOT, -)) { +for (const { + input, + inputFileName, + outputFileName, + config, + meetRequirements, +} of listupFixtures(STYLE_LOCATION_FIXTURE_ROOT)) { + if (!meetRequirements("parse")) { + continue; + } const services = parse(input, inputFileName, config).services; if (!services.isSvelte) continue; const styleContext = services.getStyleContext();