@depup/svelte 5.53.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +7 -0
- package/README.md +41 -0
- package/action.d.ts +1 -0
- package/animate.d.ts +1 -0
- package/compiler/index.js +1 -0
- package/compiler/package.json +3 -0
- package/compiler.d.ts +1 -0
- package/easing.d.ts +1 -0
- package/elements.d.ts +2078 -0
- package/index.d.ts +1 -0
- package/legacy.d.ts +1 -0
- package/motion.d.ts +1 -0
- package/package.json +185 -0
- package/src/animate/index.js +78 -0
- package/src/attachments/index.js +113 -0
- package/src/compiler/errors.js +1719 -0
- package/src/compiler/index.js +198 -0
- package/src/compiler/legacy.js +637 -0
- package/src/compiler/migrate/index.js +1996 -0
- package/src/compiler/phases/1-parse/acorn.js +198 -0
- package/src/compiler/phases/1-parse/index.js +326 -0
- package/src/compiler/phases/1-parse/read/context.js +116 -0
- package/src/compiler/phases/1-parse/read/expression.js +93 -0
- package/src/compiler/phases/1-parse/read/options.js +263 -0
- package/src/compiler/phases/1-parse/read/script.js +97 -0
- package/src/compiler/phases/1-parse/read/style.js +637 -0
- package/src/compiler/phases/1-parse/remove_typescript_nodes.js +180 -0
- package/src/compiler/phases/1-parse/state/element.js +937 -0
- package/src/compiler/phases/1-parse/state/fragment.js +17 -0
- package/src/compiler/phases/1-parse/state/tag.js +751 -0
- package/src/compiler/phases/1-parse/state/text.js +23 -0
- package/src/compiler/phases/1-parse/utils/bracket.js +213 -0
- package/src/compiler/phases/1-parse/utils/create.js +16 -0
- package/src/compiler/phases/1-parse/utils/entities.js +2234 -0
- package/src/compiler/phases/1-parse/utils/fuzzymatch.js +281 -0
- package/src/compiler/phases/1-parse/utils/html.js +127 -0
- package/src/compiler/phases/2-analyze/css/css-analyze.js +331 -0
- package/src/compiler/phases/2-analyze/css/css-prune.js +1206 -0
- package/src/compiler/phases/2-analyze/css/css-warn.js +47 -0
- package/src/compiler/phases/2-analyze/css/utils.js +177 -0
- package/src/compiler/phases/2-analyze/index.js +1300 -0
- package/src/compiler/phases/2-analyze/utils/check_graph_for_cycles.js +47 -0
- package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +15 -0
- package/src/compiler/phases/2-analyze/visitors/ArrowFunctionExpression.js +11 -0
- package/src/compiler/phases/2-analyze/visitors/AssignmentExpression.js +31 -0
- package/src/compiler/phases/2-analyze/visitors/AttachTag.js +17 -0
- package/src/compiler/phases/2-analyze/visitors/Attribute.js +66 -0
- package/src/compiler/phases/2-analyze/visitors/AwaitBlock.js +48 -0
- package/src/compiler/phases/2-analyze/visitors/AwaitExpression.js +150 -0
- package/src/compiler/phases/2-analyze/visitors/BindDirective.js +280 -0
- package/src/compiler/phases/2-analyze/visitors/CallExpression.js +339 -0
- package/src/compiler/phases/2-analyze/visitors/ClassBody.js +156 -0
- package/src/compiler/phases/2-analyze/visitors/ClassDeclaration.js +25 -0
- package/src/compiler/phases/2-analyze/visitors/ClassDirective.js +13 -0
- package/src/compiler/phases/2-analyze/visitors/Component.js +26 -0
- package/src/compiler/phases/2-analyze/visitors/ConstTag.js +45 -0
- package/src/compiler/phases/2-analyze/visitors/DebugTag.js +15 -0
- package/src/compiler/phases/2-analyze/visitors/EachBlock.js +97 -0
- package/src/compiler/phases/2-analyze/visitors/ExportDefaultDeclaration.js +20 -0
- package/src/compiler/phases/2-analyze/visitors/ExportNamedDeclaration.js +70 -0
- package/src/compiler/phases/2-analyze/visitors/ExportSpecifier.js +30 -0
- package/src/compiler/phases/2-analyze/visitors/ExpressionStatement.js +38 -0
- package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +26 -0
- package/src/compiler/phases/2-analyze/visitors/Fragment.js +10 -0
- package/src/compiler/phases/2-analyze/visitors/FunctionDeclaration.js +16 -0
- package/src/compiler/phases/2-analyze/visitors/FunctionExpression.js +11 -0
- package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +19 -0
- package/src/compiler/phases/2-analyze/visitors/Identifier.js +194 -0
- package/src/compiler/phases/2-analyze/visitors/IfBlock.js +46 -0
- package/src/compiler/phases/2-analyze/visitors/ImportDeclaration.js +31 -0
- package/src/compiler/phases/2-analyze/visitors/KeyBlock.js +21 -0
- package/src/compiler/phases/2-analyze/visitors/LabeledStatement.js +95 -0
- package/src/compiler/phases/2-analyze/visitors/LetDirective.js +24 -0
- package/src/compiler/phases/2-analyze/visitors/Literal.js +14 -0
- package/src/compiler/phases/2-analyze/visitors/MemberExpression.js +28 -0
- package/src/compiler/phases/2-analyze/visitors/NewExpression.js +17 -0
- package/src/compiler/phases/2-analyze/visitors/OnDirective.js +28 -0
- package/src/compiler/phases/2-analyze/visitors/PropertyDefinition.js +21 -0
- package/src/compiler/phases/2-analyze/visitors/RegularElement.js +240 -0
- package/src/compiler/phases/2-analyze/visitors/RenderTag.js +68 -0
- package/src/compiler/phases/2-analyze/visitors/SlotElement.js +42 -0
- package/src/compiler/phases/2-analyze/visitors/SnippetBlock.js +113 -0
- package/src/compiler/phases/2-analyze/visitors/SpreadAttribute.js +13 -0
- package/src/compiler/phases/2-analyze/visitors/SpreadElement.js +16 -0
- package/src/compiler/phases/2-analyze/visitors/StyleDirective.js +39 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +22 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteBoundary.js +30 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteComponent.js +18 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +24 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +78 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteFragment.js +27 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +18 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteSelf.js +36 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +24 -0
- package/src/compiler/phases/2-analyze/visitors/TaggedTemplateExpression.js +16 -0
- package/src/compiler/phases/2-analyze/visitors/TemplateElement.js +12 -0
- package/src/compiler/phases/2-analyze/visitors/Text.js +52 -0
- package/src/compiler/phases/2-analyze/visitors/TitleElement.js +21 -0
- package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +19 -0
- package/src/compiler/phases/2-analyze/visitors/UpdateExpression.js +29 -0
- package/src/compiler/phases/2-analyze/visitors/UseDirective.js +18 -0
- package/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js +160 -0
- package/src/compiler/phases/2-analyze/visitors/shared/a11y/constants.js +334 -0
- package/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js +981 -0
- package/src/compiler/phases/2-analyze/visitors/shared/attribute.js +125 -0
- package/src/compiler/phases/2-analyze/visitors/shared/component.js +177 -0
- package/src/compiler/phases/2-analyze/visitors/shared/element.js +160 -0
- package/src/compiler/phases/2-analyze/visitors/shared/fragment.js +15 -0
- package/src/compiler/phases/2-analyze/visitors/shared/function.js +24 -0
- package/src/compiler/phases/2-analyze/visitors/shared/snippets.js +17 -0
- package/src/compiler/phases/2-analyze/visitors/shared/special-element.js +16 -0
- package/src/compiler/phases/2-analyze/visitors/shared/utils.js +301 -0
- package/src/compiler/phases/3-transform/client/transform-client.js +719 -0
- package/src/compiler/phases/3-transform/client/transform-template/fix-attribute-casing.js +18 -0
- package/src/compiler/phases/3-transform/client/transform-template/index.js +67 -0
- package/src/compiler/phases/3-transform/client/transform-template/template.js +164 -0
- package/src/compiler/phases/3-transform/client/utils.js +181 -0
- package/src/compiler/phases/3-transform/client/visitors/AnimateDirective.js +38 -0
- package/src/compiler/phases/3-transform/client/visitors/ArrowFunctionExpression.js +11 -0
- package/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js +247 -0
- package/src/compiler/phases/3-transform/client/visitors/AttachTag.js +26 -0
- package/src/compiler/phases/3-transform/client/visitors/Attribute.js +14 -0
- package/src/compiler/phases/3-transform/client/visitors/AwaitBlock.js +124 -0
- package/src/compiler/phases/3-transform/client/visitors/AwaitExpression.js +25 -0
- package/src/compiler/phases/3-transform/client/visitors/BinaryExpression.js +34 -0
- package/src/compiler/phases/3-transform/client/visitors/BindDirective.js +290 -0
- package/src/compiler/phases/3-transform/client/visitors/BlockStatement.js +32 -0
- package/src/compiler/phases/3-transform/client/visitors/BreakStatement.js +20 -0
- package/src/compiler/phases/3-transform/client/visitors/CallExpression.js +136 -0
- package/src/compiler/phases/3-transform/client/visitors/ClassBody.js +111 -0
- package/src/compiler/phases/3-transform/client/visitors/Comment.js +11 -0
- package/src/compiler/phases/3-transform/client/visitors/Component.js +12 -0
- package/src/compiler/phases/3-transform/client/visitors/ConstTag.js +134 -0
- package/src/compiler/phases/3-transform/client/visitors/DebugTag.js +28 -0
- package/src/compiler/phases/3-transform/client/visitors/EachBlock.js +362 -0
- package/src/compiler/phases/3-transform/client/visitors/ExportNamedDeclaration.js +19 -0
- package/src/compiler/phases/3-transform/client/visitors/ExpressionStatement.js +20 -0
- package/src/compiler/phases/3-transform/client/visitors/ForOfStatement.js +25 -0
- package/src/compiler/phases/3-transform/client/visitors/Fragment.js +186 -0
- package/src/compiler/phases/3-transform/client/visitors/FunctionDeclaration.js +12 -0
- package/src/compiler/phases/3-transform/client/visitors/FunctionExpression.js +11 -0
- package/src/compiler/phases/3-transform/client/visitors/HtmlTag.js +53 -0
- package/src/compiler/phases/3-transform/client/visitors/Identifier.js +45 -0
- package/src/compiler/phases/3-transform/client/visitors/IfBlock.js +131 -0
- package/src/compiler/phases/3-transform/client/visitors/KeyBlock.js +45 -0
- package/src/compiler/phases/3-transform/client/visitors/LabeledStatement.js +64 -0
- package/src/compiler/phases/3-transform/client/visitors/LetDirective.js +55 -0
- package/src/compiler/phases/3-transform/client/visitors/MemberExpression.js +23 -0
- package/src/compiler/phases/3-transform/client/visitors/OnDirective.js +38 -0
- package/src/compiler/phases/3-transform/client/visitors/Program.js +153 -0
- package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +725 -0
- package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +95 -0
- package/src/compiler/phases/3-transform/client/visitors/SlotElement.js +94 -0
- package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +94 -0
- package/src/compiler/phases/3-transform/client/visitors/SpreadAttribute.js +10 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteBody.js +11 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +126 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js +13 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteDocument.js +11 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteElement.js +161 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteFragment.js +17 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteHead.js +23 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteSelf.js +13 -0
- package/src/compiler/phases/3-transform/client/visitors/SvelteWindow.js +11 -0
- package/src/compiler/phases/3-transform/client/visitors/TitleElement.js +48 -0
- package/src/compiler/phases/3-transform/client/visitors/TransitionDirective.js +41 -0
- package/src/compiler/phases/3-transform/client/visitors/UpdateExpression.js +55 -0
- package/src/compiler/phases/3-transform/client/visitors/UseDirective.js +49 -0
- package/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +422 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/component.js +536 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/declarations.js +53 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/element.js +263 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/events.js +180 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +185 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/function.js +17 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/special_element.js +22 -0
- package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +513 -0
- package/src/compiler/phases/3-transform/css/index.js +479 -0
- package/src/compiler/phases/3-transform/index.js +118 -0
- package/src/compiler/phases/3-transform/server/transform-server.js +428 -0
- package/src/compiler/phases/3-transform/server/visitors/AssignmentExpression.js +124 -0
- package/src/compiler/phases/3-transform/server/visitors/AwaitBlock.js +36 -0
- package/src/compiler/phases/3-transform/server/visitors/AwaitExpression.js +40 -0
- package/src/compiler/phases/3-transform/server/visitors/CallExpression.js +71 -0
- package/src/compiler/phases/3-transform/server/visitors/ClassBody.js +81 -0
- package/src/compiler/phases/3-transform/server/visitors/Component.js +13 -0
- package/src/compiler/phases/3-transform/server/visitors/ConstTag.js +49 -0
- package/src/compiler/phases/3-transform/server/visitors/DebugTag.js +24 -0
- package/src/compiler/phases/3-transform/server/visitors/EachBlock.js +76 -0
- package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +23 -0
- package/src/compiler/phases/3-transform/server/visitors/Fragment.js +53 -0
- package/src/compiler/phases/3-transform/server/visitors/HtmlTag.js +25 -0
- package/src/compiler/phases/3-transform/server/visitors/Identifier.js +24 -0
- package/src/compiler/phases/3-transform/server/visitors/IfBlock.js +48 -0
- package/src/compiler/phases/3-transform/server/visitors/KeyBlock.js +22 -0
- package/src/compiler/phases/3-transform/server/visitors/LabeledStatement.js +24 -0
- package/src/compiler/phases/3-transform/server/visitors/MemberExpression.js +19 -0
- package/src/compiler/phases/3-transform/server/visitors/Program.js +25 -0
- package/src/compiler/phases/3-transform/server/visitors/PropertyDefinition.js +37 -0
- package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +216 -0
- package/src/compiler/phases/3-transform/server/visitors/RenderTag.js +45 -0
- package/src/compiler/phases/3-transform/server/visitors/SlotElement.js +68 -0
- package/src/compiler/phases/3-transform/server/visitors/SnippetBlock.js +29 -0
- package/src/compiler/phases/3-transform/server/visitors/SpreadAttribute.js +10 -0
- package/src/compiler/phases/3-transform/server/visitors/SvelteBoundary.js +139 -0
- package/src/compiler/phases/3-transform/server/visitors/SvelteComponent.js +12 -0
- package/src/compiler/phases/3-transform/server/visitors/SvelteElement.js +89 -0
- package/src/compiler/phases/3-transform/server/visitors/SvelteFragment.js +11 -0
- package/src/compiler/phases/3-transform/server/visitors/SvelteHead.js +25 -0
- package/src/compiler/phases/3-transform/server/visitors/SvelteSelf.js +12 -0
- package/src/compiler/phases/3-transform/server/visitors/TitleElement.js +21 -0
- package/src/compiler/phases/3-transform/server/visitors/UpdateExpression.js +35 -0
- package/src/compiler/phases/3-transform/server/visitors/VariableDeclaration.js +247 -0
- package/src/compiler/phases/3-transform/server/visitors/shared/component.js +359 -0
- package/src/compiler/phases/3-transform/server/visitors/shared/element.js +557 -0
- package/src/compiler/phases/3-transform/server/visitors/shared/utils.js +408 -0
- package/src/compiler/phases/3-transform/shared/assignments.js +92 -0
- package/src/compiler/phases/3-transform/shared/transform-async.js +114 -0
- package/src/compiler/phases/3-transform/utils.js +451 -0
- package/src/compiler/phases/bindings.js +227 -0
- package/src/compiler/phases/css.js +14 -0
- package/src/compiler/phases/nodes.js +258 -0
- package/src/compiler/phases/patterns.js +27 -0
- package/src/compiler/phases/scope.js +1432 -0
- package/src/compiler/preprocess/decode_sourcemap.js +96 -0
- package/src/compiler/preprocess/index.js +368 -0
- package/src/compiler/preprocess/replace_in_code.js +72 -0
- package/src/compiler/print/index.js +911 -0
- package/src/compiler/state.js +144 -0
- package/src/compiler/utils/assert.js +9 -0
- package/src/compiler/utils/ast.js +639 -0
- package/src/compiler/utils/builders.js +698 -0
- package/src/compiler/utils/compile_diagnostic.js +107 -0
- package/src/compiler/utils/extract_svelte_ignore.js +104 -0
- package/src/compiler/utils/mapped_code.js +454 -0
- package/src/compiler/utils/push_array.js +13 -0
- package/src/compiler/utils/sanitize_template_string.js +7 -0
- package/src/compiler/utils/slot.js +20 -0
- package/src/compiler/utils/string.js +9 -0
- package/src/compiler/validate-options.js +324 -0
- package/src/compiler/warnings.js +845 -0
- package/src/constants.js +66 -0
- package/src/easing/index.js +286 -0
- package/src/escaping.js +26 -0
- package/src/events/index.js +1 -0
- package/src/html-tree-validation.js +238 -0
- package/src/index-client.js +255 -0
- package/src/index-server.js +56 -0
- package/src/internal/client/constants.js +77 -0
- package/src/internal/client/context.js +258 -0
- package/src/internal/client/dev/assign.js +79 -0
- package/src/internal/client/dev/console-log.js +37 -0
- package/src/internal/client/dev/css.js +31 -0
- package/src/internal/client/dev/debug.js +500 -0
- package/src/internal/client/dev/elements.js +63 -0
- package/src/internal/client/dev/equality.js +101 -0
- package/src/internal/client/dev/hmr.js +89 -0
- package/src/internal/client/dev/inspect.js +72 -0
- package/src/internal/client/dev/legacy.js +25 -0
- package/src/internal/client/dev/ownership.js +81 -0
- package/src/internal/client/dev/tracing.js +162 -0
- package/src/internal/client/dev/validation.js +16 -0
- package/src/internal/client/dom/blocks/async.js +71 -0
- package/src/internal/client/dom/blocks/await.js +142 -0
- package/src/internal/client/dom/blocks/boundary.js +534 -0
- package/src/internal/client/dom/blocks/branches.js +227 -0
- package/src/internal/client/dom/blocks/css-props.js +28 -0
- package/src/internal/client/dom/blocks/each.js +723 -0
- package/src/internal/client/dom/blocks/html.js +128 -0
- package/src/internal/client/dom/blocks/if.js +82 -0
- package/src/internal/client/dom/blocks/key.js +40 -0
- package/src/internal/client/dom/blocks/slot.js +44 -0
- package/src/internal/client/dom/blocks/snippet.js +103 -0
- package/src/internal/client/dom/blocks/svelte-component.js +61 -0
- package/src/internal/client/dom/blocks/svelte-element.js +152 -0
- package/src/internal/client/dom/blocks/svelte-head.js +61 -0
- package/src/internal/client/dom/css.js +33 -0
- package/src/internal/client/dom/elements/actions.js +43 -0
- package/src/internal/client/dom/elements/attachments.js +33 -0
- package/src/internal/client/dom/elements/attributes.js +657 -0
- package/src/internal/client/dom/elements/bindings/document.js +17 -0
- package/src/internal/client/dom/elements/bindings/input.js +312 -0
- package/src/internal/client/dom/elements/bindings/media.js +233 -0
- package/src/internal/client/dom/elements/bindings/navigator.js +11 -0
- package/src/internal/client/dom/elements/bindings/props.js +22 -0
- package/src/internal/client/dom/elements/bindings/select.js +159 -0
- package/src/internal/client/dom/elements/bindings/shared.js +76 -0
- package/src/internal/client/dom/elements/bindings/size.js +107 -0
- package/src/internal/client/dom/elements/bindings/this.js +61 -0
- package/src/internal/client/dom/elements/bindings/universal.js +75 -0
- package/src/internal/client/dom/elements/bindings/window.js +66 -0
- package/src/internal/client/dom/elements/class.js +51 -0
- package/src/internal/client/dom/elements/custom-element.js +344 -0
- package/src/internal/client/dom/elements/customizable-select.js +99 -0
- package/src/internal/client/dom/elements/events.js +355 -0
- package/src/internal/client/dom/elements/misc.js +58 -0
- package/src/internal/client/dom/elements/style.js +57 -0
- package/src/internal/client/dom/elements/transitions.js +471 -0
- package/src/internal/client/dom/hydration.js +125 -0
- package/src/internal/client/dom/legacy/event-modifiers.js +127 -0
- package/src/internal/client/dom/legacy/lifecycle.js +82 -0
- package/src/internal/client/dom/legacy/misc.js +68 -0
- package/src/internal/client/dom/operations.js +293 -0
- package/src/internal/client/dom/reconciler.js +25 -0
- package/src/internal/client/dom/task.js +42 -0
- package/src/internal/client/dom/template.js +401 -0
- package/src/internal/client/error-handling.js +118 -0
- package/src/internal/client/errors.js +510 -0
- package/src/internal/client/hydratable.js +33 -0
- package/src/internal/client/index.js +183 -0
- package/src/internal/client/legacy.js +46 -0
- package/src/internal/client/loop.js +48 -0
- package/src/internal/client/proxy.js +432 -0
- package/src/internal/client/reactivity/async.js +306 -0
- package/src/internal/client/reactivity/batch.js +1057 -0
- package/src/internal/client/reactivity/deriveds.js +426 -0
- package/src/internal/client/reactivity/effects.js +718 -0
- package/src/internal/client/reactivity/equality.js +31 -0
- package/src/internal/client/reactivity/props.js +430 -0
- package/src/internal/client/reactivity/sources.js +370 -0
- package/src/internal/client/reactivity/status.js +25 -0
- package/src/internal/client/reactivity/store.js +203 -0
- package/src/internal/client/reactivity/utils.js +40 -0
- package/src/internal/client/render.js +335 -0
- package/src/internal/client/runtime.js +827 -0
- package/src/internal/client/timing.js +16 -0
- package/src/internal/client/validate.js +54 -0
- package/src/internal/client/warnings.js +271 -0
- package/src/internal/disclose-version.js +6 -0
- package/src/internal/flags/async.js +3 -0
- package/src/internal/flags/index.js +23 -0
- package/src/internal/flags/legacy.js +3 -0
- package/src/internal/flags/tracing.js +3 -0
- package/src/internal/index.js +5 -0
- package/src/internal/server/abort-signal.js +13 -0
- package/src/internal/server/blocks/html.js +11 -0
- package/src/internal/server/blocks/snippet.js +24 -0
- package/src/internal/server/context.js +132 -0
- package/src/internal/server/crypto.js +45 -0
- package/src/internal/server/dev.js +115 -0
- package/src/internal/server/errors.js +131 -0
- package/src/internal/server/hydratable.js +142 -0
- package/src/internal/server/hydration.js +6 -0
- package/src/internal/server/index.js +544 -0
- package/src/internal/server/render-context.js +86 -0
- package/src/internal/server/renderer.js +923 -0
- package/src/internal/server/warnings.js +29 -0
- package/src/internal/shared/attributes.js +225 -0
- package/src/internal/shared/clone.js +137 -0
- package/src/internal/shared/dev.js +65 -0
- package/src/internal/shared/errors.js +134 -0
- package/src/internal/shared/utils.js +144 -0
- package/src/internal/shared/validate.js +47 -0
- package/src/internal/shared/warnings.js +40 -0
- package/src/legacy/legacy-client.js +281 -0
- package/src/legacy/legacy-server.js +112 -0
- package/src/motion/index.js +32 -0
- package/src/motion/spring.js +369 -0
- package/src/motion/tweened.js +306 -0
- package/src/motion/utils.js +7 -0
- package/src/reactivity/create-subscriber.js +95 -0
- package/src/reactivity/date.js +118 -0
- package/src/reactivity/index-client.js +7 -0
- package/src/reactivity/index-server.js +23 -0
- package/src/reactivity/map.js +273 -0
- package/src/reactivity/media-query.js +55 -0
- package/src/reactivity/reactive-value.js +24 -0
- package/src/reactivity/set.js +213 -0
- package/src/reactivity/url-search-params.js +174 -0
- package/src/reactivity/url.js +205 -0
- package/src/reactivity/window/index.js +161 -0
- package/src/server/index.js +1 -0
- package/src/store/index-client.js +169 -0
- package/src/store/index-server.js +101 -0
- package/src/store/shared/index.js +209 -0
- package/src/store/utils.js +36 -0
- package/src/transition/index.js +300 -0
- package/src/utils.js +504 -0
- package/src/version.js +8 -0
- package/store.d.ts +1 -0
- package/svelte-html.d.ts +245 -0
- package/transition.d.ts +1 -0
- package/types/compiler/interfaces.d.ts +1 -0
- package/types/compiler/preprocess.d.ts +1 -0
- package/types/index.d.ts +3744 -0
- package/types/index.d.ts.map +280 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** @import { Location } from 'locate-character' */
|
|
2
|
+
import * as state from '../state.js';
|
|
3
|
+
|
|
4
|
+
const regex_tabs = /^\t+/;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} str
|
|
8
|
+
*/
|
|
9
|
+
function tabs_to_spaces(str) {
|
|
10
|
+
return str.replace(regex_tabs, (match) => match.split('\t').join(' '));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} source
|
|
15
|
+
* @param {number} line
|
|
16
|
+
* @param {number} column
|
|
17
|
+
*/
|
|
18
|
+
function get_code_frame(source, line, column) {
|
|
19
|
+
const lines = source.split('\n');
|
|
20
|
+
const frame_start = Math.max(0, line - 2);
|
|
21
|
+
const frame_end = Math.min(line + 3, lines.length);
|
|
22
|
+
const digits = String(frame_end + 1).length;
|
|
23
|
+
return lines
|
|
24
|
+
.slice(frame_start, frame_end)
|
|
25
|
+
.map((str, i) => {
|
|
26
|
+
const is_error_line = frame_start + i === line;
|
|
27
|
+
const line_num = String(i + frame_start + 1).padStart(digits, ' ');
|
|
28
|
+
if (is_error_line) {
|
|
29
|
+
const indicator =
|
|
30
|
+
' '.repeat(digits + 2 + tabs_to_spaces(str.slice(0, column)).length) + '^';
|
|
31
|
+
return `${line_num}: ${tabs_to_spaces(str)}\n${indicator}`;
|
|
32
|
+
}
|
|
33
|
+
return `${line_num}: ${tabs_to_spaces(str)}`;
|
|
34
|
+
})
|
|
35
|
+
.join('\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {{
|
|
40
|
+
* code: string;
|
|
41
|
+
* message: string;
|
|
42
|
+
* stack?: string;
|
|
43
|
+
* filename?: string;
|
|
44
|
+
* start?: Location;
|
|
45
|
+
* end?: Location;
|
|
46
|
+
* position?: [number, number];
|
|
47
|
+
* frame?: string;
|
|
48
|
+
* }} ICompileDiagnostic
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/** @implements {ICompileDiagnostic} */
|
|
52
|
+
export class CompileDiagnostic {
|
|
53
|
+
name = 'CompileDiagnostic';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} code
|
|
57
|
+
* @param {string} message
|
|
58
|
+
* @param {[number, number] | undefined} position
|
|
59
|
+
*/
|
|
60
|
+
constructor(code, message, position) {
|
|
61
|
+
this.code = code;
|
|
62
|
+
this.message = message;
|
|
63
|
+
|
|
64
|
+
if (state.filename !== state.UNKNOWN_FILENAME) {
|
|
65
|
+
this.filename = state.filename;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (position) {
|
|
69
|
+
this.position = position;
|
|
70
|
+
this.start = state.locator(position[0]);
|
|
71
|
+
this.end = state.locator(position[1]);
|
|
72
|
+
if (this.start && this.end) {
|
|
73
|
+
this.frame = get_code_frame(state.source, this.start.line - 1, this.end.column);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
toString() {
|
|
79
|
+
let out = `${this.code}: ${this.message}`;
|
|
80
|
+
|
|
81
|
+
if (this.filename) {
|
|
82
|
+
out += `\n${this.filename}`;
|
|
83
|
+
|
|
84
|
+
if (this.start) {
|
|
85
|
+
out += `:${this.start.line}:${this.start.column}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (this.frame) {
|
|
90
|
+
out += `\n${this.frame}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
toJSON() {
|
|
97
|
+
return {
|
|
98
|
+
code: this.code,
|
|
99
|
+
message: this.message,
|
|
100
|
+
filename: this.filename,
|
|
101
|
+
start: this.start,
|
|
102
|
+
end: this.end,
|
|
103
|
+
position: this.position,
|
|
104
|
+
frame: this.frame
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { IGNORABLE_RUNTIME_WARNINGS } from '../../constants.js';
|
|
2
|
+
import fuzzymatch from '../phases/1-parse/utils/fuzzymatch.js';
|
|
3
|
+
import * as w from '../warnings.js';
|
|
4
|
+
|
|
5
|
+
const regex_svelte_ignore = /^\s*svelte-ignore\s/;
|
|
6
|
+
|
|
7
|
+
/** @type {Record<string, string>} Map of legacy code -> new code */
|
|
8
|
+
const replacements = {
|
|
9
|
+
'non-top-level-reactive-declaration': 'reactive_declaration_invalid_placement',
|
|
10
|
+
'module-script-reactive-declaration': 'reactive_declaration_module_script',
|
|
11
|
+
'empty-block': 'block_empty',
|
|
12
|
+
'avoid-is': 'attribute_avoid_is',
|
|
13
|
+
'invalid-html-attribute': 'attribute_invalid_property_name',
|
|
14
|
+
'a11y-structure': 'a11y_figcaption_parent',
|
|
15
|
+
'illegal-attribute-character': 'attribute_illegal_colon',
|
|
16
|
+
'invalid-rest-eachblock-binding': 'bind_invalid_each_rest',
|
|
17
|
+
'unused-export-let': 'export_let_unused'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const codes = w.codes.concat(IGNORABLE_RUNTIME_WARNINGS);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {number} offset
|
|
24
|
+
* @param {string} text
|
|
25
|
+
* @param {boolean} runes
|
|
26
|
+
* @returns {string[]}
|
|
27
|
+
*/
|
|
28
|
+
export function extract_svelte_ignore(offset, text, runes) {
|
|
29
|
+
const match = regex_svelte_ignore.exec(text);
|
|
30
|
+
if (!match) return [];
|
|
31
|
+
|
|
32
|
+
let length = match[0].length;
|
|
33
|
+
offset += length;
|
|
34
|
+
|
|
35
|
+
/** @type {string[]} */
|
|
36
|
+
const ignores = [];
|
|
37
|
+
|
|
38
|
+
if (runes) {
|
|
39
|
+
// Warnings have to be separated by commas, everything after is interpreted as prose
|
|
40
|
+
for (const match of text.slice(length).matchAll(/([\w$-]+)(,)?/gm)) {
|
|
41
|
+
const code = match[1];
|
|
42
|
+
|
|
43
|
+
if (codes.includes(code)) {
|
|
44
|
+
ignores.push(code);
|
|
45
|
+
} else {
|
|
46
|
+
const replacement = replacements[code] ?? code.replace(/-/g, '_');
|
|
47
|
+
|
|
48
|
+
// The type cast is for some reason necessary to pass the type check in CI
|
|
49
|
+
const start = offset + /** @type {number} */ (match.index);
|
|
50
|
+
const end = start + code.length;
|
|
51
|
+
|
|
52
|
+
if (codes.includes(replacement)) {
|
|
53
|
+
w.legacy_code({ start, end }, code, replacement);
|
|
54
|
+
} else {
|
|
55
|
+
const suggestion = fuzzymatch(code, codes);
|
|
56
|
+
w.unknown_code({ start, end }, code, suggestion);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!match[2]) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// Non-runes mode: lax parsing, backwards compat with old codes
|
|
66
|
+
for (const match of text.slice(length).matchAll(/[\w$-]+/gm)) {
|
|
67
|
+
const code = match[0];
|
|
68
|
+
|
|
69
|
+
ignores.push(code);
|
|
70
|
+
|
|
71
|
+
if (!codes.includes(code)) {
|
|
72
|
+
const replacement = replacements[code] ?? code.replace(/-/g, '_');
|
|
73
|
+
|
|
74
|
+
if (codes.includes(replacement)) {
|
|
75
|
+
ignores.push(replacement);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return ignores;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Replaces legacy svelte-ignore codes with new codes.
|
|
86
|
+
* @param {string} text
|
|
87
|
+
* @returns {string}
|
|
88
|
+
*/
|
|
89
|
+
export function migrate_svelte_ignore(text) {
|
|
90
|
+
const match = regex_svelte_ignore.exec(text);
|
|
91
|
+
if (!match) return text;
|
|
92
|
+
|
|
93
|
+
const length = match[0].length;
|
|
94
|
+
return (
|
|
95
|
+
text.substring(0, length) +
|
|
96
|
+
text.substring(length).replace(/\w+-\w+(-\w+)*/g, (code, _, idx) => {
|
|
97
|
+
let replacement = replacements[code] ?? code.replace(/-/g, '_');
|
|
98
|
+
if (/\w+-\w+/.test(text.substring(length + idx + code.length))) {
|
|
99
|
+
replacement += ',';
|
|
100
|
+
}
|
|
101
|
+
return replacement;
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/** @import { ValidatedCompileOptions } from '#compiler' */
|
|
2
|
+
/** @import { Processed } from '../preprocess/public.js' */
|
|
3
|
+
/** @import { SourceMap } from 'magic-string' */
|
|
4
|
+
/** @import { Source } from '../preprocess/private.js' */
|
|
5
|
+
/** @import { DecodedSourceMap, SourceMapSegment, RawSourceMap } from '@jridgewell/remapping' */
|
|
6
|
+
import remapping from '@jridgewell/remapping';
|
|
7
|
+
import { push_array } from './push_array.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} s
|
|
11
|
+
*/
|
|
12
|
+
function last_line_length(s) {
|
|
13
|
+
return s.length - s.lastIndexOf('\n') - 1;
|
|
14
|
+
}
|
|
15
|
+
// mutate map in-place
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {DecodedSourceMap} map
|
|
19
|
+
* @param {{ line: number; column: number; }} offset
|
|
20
|
+
* @param {number} source_index
|
|
21
|
+
*/
|
|
22
|
+
export function sourcemap_add_offset(map, offset, source_index) {
|
|
23
|
+
if (map.mappings.length == 0) return;
|
|
24
|
+
for (let line = 0; line < map.mappings.length; line++) {
|
|
25
|
+
const segment_list = map.mappings[line];
|
|
26
|
+
for (let segment = 0; segment < segment_list.length; segment++) {
|
|
27
|
+
const seg = segment_list[segment];
|
|
28
|
+
// shift only segments that belong to component source file
|
|
29
|
+
if (seg[1] === source_index) {
|
|
30
|
+
// also ensures that seg.length >= 4
|
|
31
|
+
// shift column if it points at the first line
|
|
32
|
+
if (seg[2] === 0) {
|
|
33
|
+
/** @type {any} */ (seg[3]) += offset.column;
|
|
34
|
+
}
|
|
35
|
+
// shift line
|
|
36
|
+
/** @type {any} */ (seg[2]) += offset.line;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @template T
|
|
44
|
+
* @param {T[]} this_table
|
|
45
|
+
* @param {T[]} other_table
|
|
46
|
+
* @returns {[T[], number[], boolean, boolean]}
|
|
47
|
+
*/
|
|
48
|
+
function merge_tables(this_table, other_table) {
|
|
49
|
+
const new_table = this_table.slice();
|
|
50
|
+
const idx_map = [];
|
|
51
|
+
other_table = other_table || [];
|
|
52
|
+
let val_changed = false;
|
|
53
|
+
for (const [other_idx, other_val] of other_table.entries()) {
|
|
54
|
+
const this_idx = this_table.indexOf(other_val);
|
|
55
|
+
if (this_idx >= 0) {
|
|
56
|
+
idx_map[other_idx] = this_idx;
|
|
57
|
+
} else {
|
|
58
|
+
const new_idx = new_table.length;
|
|
59
|
+
new_table[new_idx] = other_val;
|
|
60
|
+
idx_map[other_idx] = new_idx;
|
|
61
|
+
val_changed = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let idx_changed = val_changed;
|
|
65
|
+
if (val_changed) {
|
|
66
|
+
if (idx_map.find((val, idx) => val != idx) === undefined) {
|
|
67
|
+
// idx_map is identity map [0, 1, 2, 3, 4, ....]
|
|
68
|
+
idx_changed = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return [new_table, idx_map, val_changed, idx_changed];
|
|
72
|
+
}
|
|
73
|
+
const regex_line_token = /([^\w\s]|\s+)/g;
|
|
74
|
+
/** */
|
|
75
|
+
export class MappedCode {
|
|
76
|
+
/**
|
|
77
|
+
* @type {string}
|
|
78
|
+
*/
|
|
79
|
+
string = /** @type {any} */ (undefined);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @type {DecodedSourceMap}
|
|
83
|
+
*/
|
|
84
|
+
map = /** @type {any} */ (undefined);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} string
|
|
88
|
+
* @param {DecodedSourceMap | null} map
|
|
89
|
+
*/
|
|
90
|
+
constructor(string = '', map = null) {
|
|
91
|
+
this.string = string;
|
|
92
|
+
if (map) {
|
|
93
|
+
this.map = map;
|
|
94
|
+
} else {
|
|
95
|
+
this.map = {
|
|
96
|
+
version: 3,
|
|
97
|
+
mappings: [],
|
|
98
|
+
sources: [],
|
|
99
|
+
names: []
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* concat in-place (mutable), return this (chainable)
|
|
105
|
+
* will also mutate the `other` object
|
|
106
|
+
* @param {MappedCode} other
|
|
107
|
+
* @returns {MappedCode}
|
|
108
|
+
*/
|
|
109
|
+
concat(other) {
|
|
110
|
+
// noop: if one is empty, return the other
|
|
111
|
+
if (other.string == '') return this;
|
|
112
|
+
if (this.string == '') {
|
|
113
|
+
this.string = other.string;
|
|
114
|
+
this.map = other.map;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
// compute last line length before mutating
|
|
118
|
+
const column_offset = last_line_length(this.string);
|
|
119
|
+
this.string += other.string;
|
|
120
|
+
const m1 = this.map;
|
|
121
|
+
const m2 = other.map;
|
|
122
|
+
if (m2.mappings.length == 0) return this;
|
|
123
|
+
// combine sources and names
|
|
124
|
+
const [sources, new_source_idx, sources_changed, sources_idx_changed] = merge_tables(
|
|
125
|
+
m1.sources,
|
|
126
|
+
m2.sources
|
|
127
|
+
);
|
|
128
|
+
const [names, new_name_idx, names_changed, names_idx_changed] = merge_tables(
|
|
129
|
+
m1.names,
|
|
130
|
+
m2.names
|
|
131
|
+
);
|
|
132
|
+
if (sources_changed) m1.sources = sources;
|
|
133
|
+
if (names_changed) m1.names = names;
|
|
134
|
+
// unswitched loops are faster
|
|
135
|
+
if (sources_idx_changed && names_idx_changed) {
|
|
136
|
+
for (let line = 0; line < m2.mappings.length; line++) {
|
|
137
|
+
const segment_list = m2.mappings[line];
|
|
138
|
+
for (let segment = 0; segment < segment_list.length; segment++) {
|
|
139
|
+
const seg = segment_list[segment];
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
if (seg[1] >= 0) seg[1] = new_source_idx[seg[1]];
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
if (seg[4] >= 0) seg[4] = new_name_idx[seg[4]];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} else if (sources_idx_changed) {
|
|
147
|
+
for (let line = 0; line < m2.mappings.length; line++) {
|
|
148
|
+
const segment_list = m2.mappings[line];
|
|
149
|
+
for (let segment = 0; segment < segment_list.length; segment++) {
|
|
150
|
+
const seg = segment_list[segment];
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
if (seg[1] >= 0) seg[1] = new_source_idx[seg[1]];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else if (names_idx_changed) {
|
|
156
|
+
for (let line = 0; line < m2.mappings.length; line++) {
|
|
157
|
+
const segment_list = m2.mappings[line];
|
|
158
|
+
for (let segment = 0; segment < segment_list.length; segment++) {
|
|
159
|
+
const seg = segment_list[segment];
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
if (seg[4] >= 0) seg[4] = new_name_idx[seg[4]];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// combine the mappings
|
|
166
|
+
// combine
|
|
167
|
+
// 1. last line of first map
|
|
168
|
+
// 2. first line of second map
|
|
169
|
+
// columns of 2 must be shifted
|
|
170
|
+
if (m2.mappings.length > 0 && column_offset > 0) {
|
|
171
|
+
const first_line = m2.mappings[0];
|
|
172
|
+
for (let i = 0; i < first_line.length; i++) {
|
|
173
|
+
first_line[i][0] += column_offset;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// combine last line + first line
|
|
177
|
+
push_array(
|
|
178
|
+
m1.mappings[m1.mappings.length - 1],
|
|
179
|
+
/** @type {SourceMapSegment[]} */ (m2.mappings.shift())
|
|
180
|
+
);
|
|
181
|
+
// append other lines
|
|
182
|
+
push_array(m1.mappings, m2.mappings);
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @static
|
|
188
|
+
* @param {string} string
|
|
189
|
+
* @param {DecodedSourceMap} [map]
|
|
190
|
+
* @returns {MappedCode}
|
|
191
|
+
*/
|
|
192
|
+
static from_processed(string, map) {
|
|
193
|
+
const line_count = string.split('\n').length;
|
|
194
|
+
if (map) {
|
|
195
|
+
// ensure that count of source map mappings lines
|
|
196
|
+
// is equal to count of generated code lines
|
|
197
|
+
// (some tools may produce less)
|
|
198
|
+
const missing_lines = line_count - map.mappings.length;
|
|
199
|
+
for (let i = 0; i < missing_lines; i++) {
|
|
200
|
+
map.mappings.push([]);
|
|
201
|
+
}
|
|
202
|
+
return new MappedCode(string, map);
|
|
203
|
+
}
|
|
204
|
+
if (string == '') return new MappedCode();
|
|
205
|
+
map = { version: 3, names: [], sources: [], mappings: [] };
|
|
206
|
+
// add empty SourceMapSegment[] for every line
|
|
207
|
+
for (let i = 0; i < line_count; i++) map.mappings.push([]);
|
|
208
|
+
return new MappedCode(string, map);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @static
|
|
213
|
+
* @param {Source} opts
|
|
214
|
+
* @returns {MappedCode}
|
|
215
|
+
*/
|
|
216
|
+
static from_source({ source, file_basename, get_location }) {
|
|
217
|
+
/**
|
|
218
|
+
* @type {{ line: number; column: number; }}
|
|
219
|
+
*/
|
|
220
|
+
let offset = get_location(0);
|
|
221
|
+
if (!offset) offset = { line: 0, column: 0 };
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @type {DecodedSourceMap}
|
|
225
|
+
*/
|
|
226
|
+
const map = { version: 3, names: [], sources: [file_basename], mappings: [] };
|
|
227
|
+
if (source == '') return new MappedCode(source, map);
|
|
228
|
+
// we create a high resolution identity map here,
|
|
229
|
+
// we know that it will eventually be merged with svelte's map,
|
|
230
|
+
// at which stage the resolution will decrease.
|
|
231
|
+
const line_list = source.split('\n');
|
|
232
|
+
for (let line = 0; line < line_list.length; line++) {
|
|
233
|
+
map.mappings.push([]);
|
|
234
|
+
const token_list = line_list[line].split(regex_line_token);
|
|
235
|
+
for (let token = 0, column = 0; token < token_list.length; token++) {
|
|
236
|
+
if (token_list[token] == '') continue;
|
|
237
|
+
map.mappings[line].push([column, 0, offset.line + line, column]);
|
|
238
|
+
column += token_list[token].length;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// shift columns in first line
|
|
242
|
+
const segment_list = map.mappings[0];
|
|
243
|
+
for (let segment = 0; segment < segment_list.length; segment++) {
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
segment_list[segment][3] += offset.column;
|
|
246
|
+
}
|
|
247
|
+
return new MappedCode(source, map);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// browser vs node.js
|
|
252
|
+
const b64enc =
|
|
253
|
+
typeof window !== 'undefined' && typeof btoa === 'function'
|
|
254
|
+
? /** @param {string} str */ (str) => btoa(unescape(encodeURIComponent(str)))
|
|
255
|
+
: /** @param {string} str */ (str) => Buffer.from(str).toString('base64');
|
|
256
|
+
const b64dec =
|
|
257
|
+
typeof window !== 'undefined' && typeof atob === 'function'
|
|
258
|
+
? atob
|
|
259
|
+
: /** @param {any} a */ (a) => Buffer.from(a, 'base64').toString();
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @param {string} filename Basename of the input file
|
|
263
|
+
* @param {Array<DecodedSourceMap | RawSourceMap>} sourcemap_list
|
|
264
|
+
*/
|
|
265
|
+
export function combine_sourcemaps(filename, sourcemap_list) {
|
|
266
|
+
if (sourcemap_list.length == 0) return null;
|
|
267
|
+
let map_idx = 1;
|
|
268
|
+
const map =
|
|
269
|
+
sourcemap_list.slice(0, -1).find((m) => m.sources.length !== 1) === undefined
|
|
270
|
+
? remapping(
|
|
271
|
+
// use array interface
|
|
272
|
+
// only the oldest sourcemap can have multiple sources
|
|
273
|
+
sourcemap_list,
|
|
274
|
+
() => null,
|
|
275
|
+
true // skip optional field `sourcesContent`
|
|
276
|
+
)
|
|
277
|
+
: remapping(
|
|
278
|
+
// use loader interface
|
|
279
|
+
sourcemap_list[0], // last map
|
|
280
|
+
(sourcefile) => {
|
|
281
|
+
// TODO the equality check assumes that the preprocessor map has the input file as a relative path in sources,
|
|
282
|
+
// e.g. when the input file is `src/foo/bar.svelte`, then sources is expected to contain just `bar.svelte`.
|
|
283
|
+
// Therefore filename also needs to be the basename of the path. This feels brittle, investigate how we can
|
|
284
|
+
// harden this (without breaking other tooling that assumes this behavior).
|
|
285
|
+
if (sourcefile === filename && sourcemap_list[map_idx]) {
|
|
286
|
+
return sourcemap_list[map_idx++]; // idx 1, 2, ...
|
|
287
|
+
// bundle file = branch node
|
|
288
|
+
} else {
|
|
289
|
+
return null; // source file = leaf node
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
true
|
|
293
|
+
);
|
|
294
|
+
if (!map.file) delete map.file; // skip optional field `file`
|
|
295
|
+
// When source maps are combined and the leading map is empty, sources is not set.
|
|
296
|
+
// Add the filename to the empty array in this case.
|
|
297
|
+
// Further improvements to remapping may help address this as well https://github.com/ampproject/remapping/issues/116
|
|
298
|
+
if (!map.sources.length) map.sources = [filename];
|
|
299
|
+
return map;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* @param {string} filename
|
|
304
|
+
* @param {SourceMap} svelte_map
|
|
305
|
+
* @param {string | DecodedSourceMap | RawSourceMap} preprocessor_map_input
|
|
306
|
+
* @returns {SourceMap}
|
|
307
|
+
*/
|
|
308
|
+
function apply_preprocessor_sourcemap(filename, svelte_map, preprocessor_map_input) {
|
|
309
|
+
if (!svelte_map || !preprocessor_map_input) return svelte_map;
|
|
310
|
+
const preprocessor_map =
|
|
311
|
+
typeof preprocessor_map_input === 'string'
|
|
312
|
+
? JSON.parse(preprocessor_map_input)
|
|
313
|
+
: preprocessor_map_input;
|
|
314
|
+
const result_map = combine_sourcemaps(filename, [svelte_map, preprocessor_map]);
|
|
315
|
+
// Svelte expects a SourceMap which includes toUrl and toString. Instead of wrapping our output in a class,
|
|
316
|
+
// we just tack on the extra properties.
|
|
317
|
+
Object.defineProperties(result_map, {
|
|
318
|
+
toString: {
|
|
319
|
+
enumerable: false,
|
|
320
|
+
value: function toString() {
|
|
321
|
+
return JSON.stringify(this);
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
toUrl: {
|
|
325
|
+
enumerable: false,
|
|
326
|
+
value: function toUrl() {
|
|
327
|
+
return 'data:application/json;charset=utf-8;base64,' + b64enc(this.toString());
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
return /** @type {any} */ (result_map);
|
|
332
|
+
}
|
|
333
|
+
const regex_data_uri = /data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(\S*)/;
|
|
334
|
+
// parse attached sourcemap in processed.code
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @param {Processed} processed
|
|
338
|
+
* @param {'script' | 'style'} tag_name
|
|
339
|
+
* @returns {void}
|
|
340
|
+
*/
|
|
341
|
+
export function parse_attached_sourcemap(processed, tag_name) {
|
|
342
|
+
const r_in = '[#@]\\s*sourceMappingURL\\s*=\\s*(\\S*)';
|
|
343
|
+
const regex =
|
|
344
|
+
tag_name == 'script'
|
|
345
|
+
? new RegExp('(?://' + r_in + ')|(?:/\\*' + r_in + '\\s*\\*/)$')
|
|
346
|
+
: new RegExp('/\\*' + r_in + '\\s*\\*/$');
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* @param {any} message
|
|
350
|
+
*/
|
|
351
|
+
function log_warning(message) {
|
|
352
|
+
// code_start: help to find preprocessor
|
|
353
|
+
const code_start =
|
|
354
|
+
processed.code.length < 100 ? processed.code : processed.code.slice(0, 100) + ' [...]';
|
|
355
|
+
// eslint-disable-next-line no-console
|
|
356
|
+
console.warn(`warning: ${message}. processed.code = ${JSON.stringify(code_start)}`);
|
|
357
|
+
}
|
|
358
|
+
processed.code = processed.code.replace(regex, (_, match1, match2) => {
|
|
359
|
+
const map_url = tag_name == 'script' ? match1 || match2 : match1;
|
|
360
|
+
const map_data = (map_url.match(regex_data_uri) || [])[1];
|
|
361
|
+
if (map_data) {
|
|
362
|
+
// sourceMappingURL is data URL
|
|
363
|
+
if (processed.map) {
|
|
364
|
+
log_warning(
|
|
365
|
+
'Not implemented. ' +
|
|
366
|
+
'Found sourcemap in both processed.code and processed.map. ' +
|
|
367
|
+
'Please update your preprocessor to return only one sourcemap.'
|
|
368
|
+
);
|
|
369
|
+
// ignore attached sourcemap
|
|
370
|
+
return '';
|
|
371
|
+
}
|
|
372
|
+
processed.map = b64dec(map_data); // use attached sourcemap
|
|
373
|
+
return ''; // remove from processed.code
|
|
374
|
+
}
|
|
375
|
+
// sourceMappingURL is path or URL
|
|
376
|
+
if (!processed.map) {
|
|
377
|
+
log_warning(
|
|
378
|
+
`Found sourcemap path ${JSON.stringify(
|
|
379
|
+
map_url
|
|
380
|
+
)} in processed.code, but no sourcemap data. ` +
|
|
381
|
+
'Please update your preprocessor to return sourcemap data directly.'
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
// ignore sourcemap path
|
|
385
|
+
return ''; // remove from processed.code
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* @param {{ code: string, map: SourceMap}} result
|
|
391
|
+
* @param {ValidatedCompileOptions} options
|
|
392
|
+
* @param {string} source_name
|
|
393
|
+
*/
|
|
394
|
+
export function merge_with_preprocessor_map(result, options, source_name) {
|
|
395
|
+
if (options.sourcemap) {
|
|
396
|
+
const file_basename = get_basename(options.filename);
|
|
397
|
+
// The preprocessor map is expected to contain `sources: [basename_of_filename]`, but our own
|
|
398
|
+
// map may contain a different file name. Patch our map beforehand to align sources so merging
|
|
399
|
+
// with the preprocessor map works correctly.
|
|
400
|
+
result.map.sources = [file_basename];
|
|
401
|
+
Object.assign(
|
|
402
|
+
result.map,
|
|
403
|
+
apply_preprocessor_sourcemap(
|
|
404
|
+
file_basename,
|
|
405
|
+
result.map,
|
|
406
|
+
/** @type {any} */ (options.sourcemap)
|
|
407
|
+
)
|
|
408
|
+
);
|
|
409
|
+
// After applying the preprocessor map, we need to do the inverse and make the sources
|
|
410
|
+
// relative to the input file again in case the output code is in a different directory.
|
|
411
|
+
if (file_basename !== source_name) {
|
|
412
|
+
result.map.sources = result.map.sources.map(
|
|
413
|
+
/** @param {string} source */ (source) => get_relative_path(source_name, source)
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @param {string} from
|
|
421
|
+
* @param {string} to
|
|
422
|
+
*/
|
|
423
|
+
function get_relative_path(from, to) {
|
|
424
|
+
// Don't use node's utils here to ensure the compiler is usable in a browser environment
|
|
425
|
+
const from_parts = from.split(/[/\\]/);
|
|
426
|
+
const to_parts = to.split(/[/\\]/);
|
|
427
|
+
from_parts.pop(); // get dirname
|
|
428
|
+
while (from_parts[0] === to_parts[0]) {
|
|
429
|
+
from_parts.shift();
|
|
430
|
+
to_parts.shift();
|
|
431
|
+
}
|
|
432
|
+
if (from_parts.length) {
|
|
433
|
+
let i = from_parts.length;
|
|
434
|
+
while (i--) from_parts[i] = '..';
|
|
435
|
+
}
|
|
436
|
+
return from_parts.concat(to_parts).join('/');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Like node's `basename`, but doesn't use it to ensure the compiler is usable in a browser environment
|
|
441
|
+
* @param {string} filename
|
|
442
|
+
*/
|
|
443
|
+
export function get_basename(filename) {
|
|
444
|
+
return /** @type {string} */ (filename.split(/[/\\]/).pop());
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* @param {string} filename
|
|
449
|
+
* @param {string | undefined} output_filename
|
|
450
|
+
* @param {string} fallback
|
|
451
|
+
*/
|
|
452
|
+
export function get_source_name(filename, output_filename, fallback) {
|
|
453
|
+
return output_filename ? get_relative_path(output_filename, filename) : get_basename(filename);
|
|
454
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pushes all `items` into `array` using `push`, therefore mutating the array.
|
|
3
|
+
* We do this for memory and perf reasons, and because `array.push(...items)` would
|
|
4
|
+
* run into a "max call stack size exceeded" error with too many items (~65k).
|
|
5
|
+
* @template T
|
|
6
|
+
* @param {T[]} array
|
|
7
|
+
* @param {T[]} items
|
|
8
|
+
*/
|
|
9
|
+
export function push_array(array, items) {
|
|
10
|
+
for (let i = 0; i < items.length; i++) {
|
|
11
|
+
array.push(items[i]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @import { AST } from '#compiler' */
|
|
2
|
+
import { is_element_node } from '../phases/nodes.js';
|
|
3
|
+
import { is_text_attribute } from './ast.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {AST.SvelteNode} node
|
|
7
|
+
*/
|
|
8
|
+
export function determine_slot(node) {
|
|
9
|
+
if (!is_element_node(node)) return null;
|
|
10
|
+
|
|
11
|
+
for (const attribute of node.attributes) {
|
|
12
|
+
if (attribute.type !== 'Attribute') continue;
|
|
13
|
+
if (attribute.name !== 'slot') continue;
|
|
14
|
+
if (!is_text_attribute(attribute)) continue;
|
|
15
|
+
|
|
16
|
+
return /** @type {string} */ (attribute.value[0].data);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
}
|