diff --git a/package.json b/package.json index 649998f..3baf70a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "prettier": "^3.0.0", "rollup": "2.36.0", "rollup-plugin-typescript": "1.0.1", - "svelte": "^5.0.0-next.106", + "svelte": "file:../svelte/packages/svelte", "ts-node": "^10.1.1", "tslib": "^2.6.0", "typescript": "5.1.3" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 301e54d..dc86497 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,8 +35,8 @@ devDependencies: specifier: 1.0.1 version: 1.0.1(tslib@2.6.2)(typescript@5.1.3) svelte: - specifier: ^5.0.0-next.106 - version: 5.0.0-next.106 + specifier: file:../svelte/packages/svelte + version: file:../svelte/packages/svelte ts-node: specifier: ^10.1.1 version: 10.9.2(@types/node@14.18.63)(typescript@5.1.3) @@ -1380,9 +1380,8 @@ packages: sourcemap-codec: 1.4.8 dev: true - /magic-string@0.30.9: - resolution: {integrity: sha512-S1+hd+dIrC8EZqKyT9DstTH/0Z+f76kmmvZnkfQVmOpDEF9iVgdYif3Q/pIWHmCoo59bQVGW0kVL3e2nl+9+Sw==} - engines: {node: '>=12'} + /magic-string@0.30.10: + resolution: {integrity: sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==} dependencies: '@jridgewell/sourcemap-codec': 1.4.15 dev: true @@ -2017,25 +2016,6 @@ packages: engines: {node: '>= 0.4'} dev: true - /svelte@5.0.0-next.106: - resolution: {integrity: sha512-Izi9mQT2otnplBHHpfno/hvlS194YnxicT+0hi6QccuLqdCB3R9hmZIJEfCoaqz5xwONwCF0Xa5KkfK0YoPHIw==} - engines: {node: '>=18'} - dependencies: - '@ampproject/remapping': 2.3.0 - '@jridgewell/sourcemap-codec': 1.4.15 - '@types/estree': 1.0.5 - acorn: 8.11.3 - acorn-typescript: 1.4.13(acorn@8.11.3) - aria-query: 5.3.0 - axobject-query: 4.0.0 - esm-env: 1.0.0 - esrap: 1.2.1 - is-reference: 3.0.2 - locate-character: 3.0.0 - magic-string: 0.30.9 - zimmerframe: 1.1.2 - dev: true - /temp-dir@2.0.0: resolution: {integrity: sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==} engines: {node: '>=8'} @@ -2259,3 +2239,23 @@ packages: /zimmerframe@1.1.2: resolution: {integrity: sha512-rAbqEGa8ovJy4pyBxZM70hg4pE6gDgaQ0Sl9M3enG3I0d6H4XSAM3GeNGLKnsBpuijUow064sf7ww1nutC5/3w==} dev: true + + file:../svelte/packages/svelte: + resolution: {directory: ../svelte/packages/svelte, type: directory} + name: svelte + engines: {node: '>=18'} + dependencies: + '@ampproject/remapping': 2.3.0 + '@jridgewell/sourcemap-codec': 1.4.15 + '@types/estree': 1.0.5 + acorn: 8.11.3 + acorn-typescript: 1.4.13(acorn@8.11.3) + aria-query: 5.3.0 + axobject-query: 4.0.0 + esm-env: 1.0.0 + esrap: 1.2.1 + is-reference: 3.0.2 + locate-character: 3.0.0 + magic-string: 0.30.10 + zimmerframe: 1.1.2 + dev: true diff --git a/src/embed.ts b/src/embed.ts index 9f73507..b4aa463 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -27,7 +27,6 @@ import { RegularElement, SvelteElement, } from './print/nodes'; -import { extractAttributes } from './lib/extractAttributes'; import { base64ToString } from './base64-string'; const { @@ -67,13 +66,6 @@ export function embed(path: AstPath, _options: Options) { assignCommentsToNodes(node); if (node.options) { node.options.type = 'SvelteOptions'; - node.options.attributes = extractAttributes(getText(node.options, options)); - } - if (node.module) { - node.module.attributes = extractAttributes(getText(node.module, options)); - } - if (node.instance) { - node.instance.attributes = extractAttributes(getText(node.instance, options)); } if (node.css) { node.css.content.type = 'StyleProgram'; diff --git a/src/lib/extractAttributes.ts b/src/lib/extractAttributes.ts deleted file mode 100644 index f98bd74..0000000 --- a/src/lib/extractAttributes.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { AttributeNode, Text } from '../print/nodes'; - -const extractAttributesRegex = - /<[a-z]+(?::[a-z]+)?((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)\/?>/im; -const attributeRegex = /([^\s=]+)(?:=(?:(?:("|')([\s\S]*?)\2)|(?:([^>\s]+?)(?:\s|>|$))))?/gim; - -export function extractAttributes(html: string): AttributeNode[] { - const [, attributesString] = html.match(extractAttributesRegex)!; - - const attrs: AttributeNode[] = []; - - let match: RegExpMatchArray | null; - while ((match = attributeRegex.exec(attributesString))) { - const [all, name, quotes, valueQuoted, valueUnquoted] = match; - const value = valueQuoted || valueUnquoted; - const attrStart = match.index!; - - let valueNode: AttributeNode['value']; - if (!value) { - valueNode = true; - } else { - let valueStart = attrStart + name.length; - if (quotes) { - valueStart += 2; - } - - valueNode = [ - { - type: 'Text', - data: value, - start: valueStart, - end: valueStart + value.length, - } as Text, - ]; - } - - attrs.push({ - type: 'Attribute', - name, - value: valueNode, - start: attrStart, - end: attrStart + all.length, - }); - } - - return attrs; -}