Skip to content

feat: update svelte to 5.0.0-next.115 && minor refactor #513

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

Merged
merged 5 commits into from
Apr 29, 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
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
},
"peerDependencies": {
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.112"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.115"
},
"peerDependenciesMeta": {
"svelte": {
Expand All @@ -68,16 +68,16 @@
"@ota-meshi/eslint-plugin": "^0.15.3",
"@types/benchmark": "^2.1.5",
"@types/chai": "^4.3.14",
"@types/eslint": "^8.56.7",
"@types/eslint": "^8.56.10",
"@types/eslint-scope": "^3.7.7",
"@types/eslint-visitor-keys": "^3.3.0",
"@types/estree": "^1.0.5",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.5",
"@types/node": "^20.12.7",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "~7.7.0",
"@typescript-eslint/types": "~7.7.0",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "~7.7.1",
"@typescript-eslint/types": "~7.7.1",
"benchmark": "^2.1.4",
"chai": "^4.4.1",
"env-cmd": "^10.1.0",
Expand All @@ -87,27 +87,27 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-json-schema-validator": "^5.1.0",
"eslint-plugin-jsonc": "^2.15.0",
"eslint-plugin-n": "^17.0.0",
"eslint-plugin-jsonc": "^2.15.1",
"eslint-plugin-n": "^17.3.1",
"eslint-plugin-node-dependencies": "^0.12.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-regexp": "^2.4.0",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-regexp": "^2.5.0",
"eslint-plugin-svelte": "^2.38.0",
"eslint-plugin-yml": "^1.14.0",
"estree-walker": "^3.0.3",
"locate-character": "^3.0.0",
"magic-string": "^0.30.9",
"magic-string": "^0.30.10",
"mocha": "^10.4.0",
"mocha-chai-jest-snapshot": "^1.1.4",
"nyc": "^15.1.0",
"prettier": "~3.2.5",
"prettier-plugin-pkg": "^0.18.1",
"prettier-plugin-svelte": "^3.2.2",
"prettier-plugin-svelte": "^3.2.3",
"rimraf": "^5.0.5",
"semver": "^7.6.0",
"svelte": "^5.0.0-next.112",
"svelte2tsx": "^0.7.6",
"typescript": "~5.4.4",
"svelte": "^5.0.0-next.115",
"svelte2tsx": "^0.7.7",
"typescript": "~5.4.5",
"typescript-eslint-parser-for-extra-files": "^0.6.0"
},
"publishConfig": {
Expand Down
58 changes: 13 additions & 45 deletions src/parser/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type ESTree from "estree";
import type * as SvAST from "./svelte-ast-types";
import type * as Compiler from "svelte/compiler";
import { parseAttributes } from "./html";

export type Child =
| Compiler.Text
Expand Down Expand Up @@ -31,16 +30,22 @@ export function getModuleFromRoot(
}
export function getOptionsFromRoot(
svelteAst: Compiler.Root | SvAST.AstLegacy,
code: string,
): Compiler.SvelteOptionsRaw | null {
const root = svelteAst as Compiler.Root;
if (root.options) {
if ((root.options as any).__raw__) {
return (root.options as any).__raw__;
}
// If there is no `__raw__` property in the `SvelteOptions` node,
// we will parse `<svelte:options>` ourselves.
return parseSvelteOptions(root.options, code);
return {
type: "SvelteOptions",
name: "svelte:options",
attributes: root.options.attributes,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SvelteOptions node now provides attributes so we don't have to parse it ourselves.

fragment: {
type: "Fragment",
nodes: [],
transparent: true,
},
start: root.options.start,
end: root.options.end,
parent: null as any,
};
}
return null;
}
Expand Down Expand Up @@ -239,40 +244,3 @@ export function getDeclaratorFromConstTag(
(node as SvAST.ConstTag).expression
);
}

function parseSvelteOptions(
options: Compiler.SvelteOptions,
code: string,
): Compiler.SvelteOptionsRaw {
const { start, end } = options;
const nameEndName = start + "<svelte:options".length;
const { attributes, index: tagEndIndex } = parseAttributes(
code,
nameEndName + 1,
);
const fragment: Compiler.Fragment = {
type: "Fragment",
nodes: [],
transparent: true,
};
if (code.startsWith(">", tagEndIndex)) {
const childEndIndex = code.indexOf("</svelte:options", tagEndIndex);
fragment.nodes.push({
type: "Text",
data: code.slice(tagEndIndex + 1, childEndIndex),
start: tagEndIndex + 1,
end: childEndIndex,
raw: code.slice(tagEndIndex + 1, childEndIndex),
parent: fragment,
});
}
return {
type: "SvelteOptions",
name: "svelte:options",
attributes,
fragment,
start,
end,
parent: null as any,
};
}
2 changes: 1 addition & 1 deletion src/parser/converts/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function convertSvelteRoot(
const fragment = getFragmentFromRoot(svelteAst);
if (fragment) {
let children = getChildren(fragment);
const options = getOptionsFromRoot(svelteAst, ctx.code);
const options = getOptionsFromRoot(svelteAst);
if (options) {
children = [...children];
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<svelte:options runes={true} ></svelte:options>
Loading
Loading