@vigla/svelte 0.0.0-stage → 5.57.4
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/action.d.ts +2 -0
- package/animate.d.ts +2 -0
- package/compiler/index.js +43266 -0
- package/compiler/index.js.map +1 -0
- package/compiler/package.json +3 -0
- package/compiler.d.ts +2 -0
- package/dist/compiler/diagnostics.d.ts +70 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +166 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/index.d.ts +72 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +178 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/options.d.ts +7 -0
- package/dist/compiler/options.d.ts.map +1 -0
- package/dist/compiler/options.js +126 -0
- package/dist/compiler/options.js.map +1 -0
- package/dist/compiler/preprocess/decode.d.ts +3 -0
- package/dist/compiler/preprocess/decode.d.ts.map +1 -0
- package/dist/compiler/preprocess/decode.js +60 -0
- package/dist/compiler/preprocess/decode.js.map +1 -0
- package/dist/compiler/preprocess/index.d.ts +27 -0
- package/dist/compiler/preprocess/index.d.ts.map +1 -0
- package/dist/compiler/preprocess/index.js +208 -0
- package/dist/compiler/preprocess/index.js.map +1 -0
- package/dist/compiler/preprocess/mapped.d.ts +25 -0
- package/dist/compiler/preprocess/mapped.d.ts.map +1 -0
- package/dist/compiler/preprocess/mapped.js +129 -0
- package/dist/compiler/preprocess/mapped.js.map +1 -0
- package/dist/compiler/proxy.d.ts +3 -0
- package/dist/compiler/proxy.d.ts.map +1 -0
- package/dist/compiler/proxy.js +133 -0
- package/dist/compiler/proxy.js.map +1 -0
- package/dist/entries/action.d.ts +2 -0
- package/dist/entries/action.d.ts.map +1 -0
- package/dist/entries/action.js +1 -0
- package/dist/entries/action.js.map +1 -0
- package/dist/entries/animate.d.ts +2 -0
- package/dist/entries/animate.d.ts.map +1 -0
- package/dist/entries/animate.js +2 -0
- package/dist/entries/animate.js.map +1 -0
- package/dist/entries/attachments.d.ts +2 -0
- package/dist/entries/attachments.d.ts.map +1 -0
- package/dist/entries/attachments.js +2 -0
- package/dist/entries/attachments.js.map +1 -0
- package/dist/entries/context.d.ts +15 -0
- package/dist/entries/context.d.ts.map +1 -0
- package/dist/entries/context.js +32 -0
- package/dist/entries/context.js.map +1 -0
- package/dist/entries/easing.d.ts +2 -0
- package/dist/entries/easing.d.ts.map +1 -0
- package/dist/entries/easing.js +2 -0
- package/dist/entries/easing.js.map +1 -0
- package/dist/entries/events.d.ts +2 -0
- package/dist/entries/events.d.ts.map +1 -0
- package/dist/entries/events.js +2 -0
- package/dist/entries/events.js.map +1 -0
- package/dist/entries/index-server.d.ts +4 -0
- package/dist/entries/index-server.d.ts.map +1 -0
- package/dist/entries/index-server.js +11 -0
- package/dist/entries/index-server.js.map +1 -0
- package/dist/entries/index.d.ts +10 -0
- package/dist/entries/index.d.ts.map +1 -0
- package/dist/entries/index.js +24 -0
- package/dist/entries/index.js.map +1 -0
- package/dist/entries/internal/client.d.ts +4 -0
- package/dist/entries/internal/client.d.ts.map +1 -0
- package/dist/entries/internal/client.js +9 -0
- package/dist/entries/internal/client.js.map +1 -0
- package/dist/entries/internal/disclose-version.d.ts +2 -0
- package/dist/entries/internal/disclose-version.d.ts.map +1 -0
- package/dist/entries/internal/disclose-version.js +4 -0
- package/dist/entries/internal/disclose-version.js.map +1 -0
- package/dist/entries/internal/index.d.ts +2 -0
- package/dist/entries/internal/index.d.ts.map +1 -0
- package/dist/entries/internal/index.js +2 -0
- package/dist/entries/internal/index.js.map +1 -0
- package/dist/entries/internal/server.d.ts +2 -0
- package/dist/entries/internal/server.d.ts.map +1 -0
- package/dist/entries/internal/server.js +7 -0
- package/dist/entries/internal/server.js.map +1 -0
- package/dist/entries/internal/tracing.d.ts +2 -0
- package/dist/entries/internal/tracing.d.ts.map +1 -0
- package/dist/entries/internal/tracing.js +2 -0
- package/dist/entries/internal/tracing.js.map +1 -0
- package/dist/entries/motion-server.d.ts +2 -0
- package/dist/entries/motion-server.d.ts.map +1 -0
- package/dist/entries/motion-server.js +2 -0
- package/dist/entries/motion-server.js.map +1 -0
- package/dist/entries/motion.d.ts +2 -0
- package/dist/entries/motion.d.ts.map +1 -0
- package/dist/entries/motion.js +2 -0
- package/dist/entries/motion.js.map +1 -0
- package/dist/entries/proxy.d.ts +6 -0
- package/dist/entries/proxy.d.ts.map +1 -0
- package/dist/entries/proxy.js +77 -0
- package/dist/entries/proxy.js.map +1 -0
- package/dist/entries/reactivity-server.d.ts +2 -0
- package/dist/entries/reactivity-server.d.ts.map +1 -0
- package/dist/entries/reactivity-server.js +2 -0
- package/dist/entries/reactivity-server.js.map +1 -0
- package/dist/entries/reactivity.d.ts +2 -0
- package/dist/entries/reactivity.d.ts.map +1 -0
- package/dist/entries/reactivity.js +2 -0
- package/dist/entries/reactivity.js.map +1 -0
- package/dist/entries/report.d.ts +3 -0
- package/dist/entries/report.d.ts.map +1 -0
- package/dist/entries/report.js +66 -0
- package/dist/entries/report.js.map +1 -0
- package/dist/entries/server.d.ts +8 -0
- package/dist/entries/server.d.ts.map +1 -0
- package/dist/entries/server.js +48 -0
- package/dist/entries/server.js.map +1 -0
- package/dist/entries/store-client.d.ts +12 -0
- package/dist/entries/store-client.d.ts.map +1 -0
- package/dist/entries/store-client.js +63 -0
- package/dist/entries/store-client.js.map +1 -0
- package/dist/entries/store-server.d.ts +12 -0
- package/dist/entries/store-server.d.ts.map +1 -0
- package/dist/entries/store-server.js +30 -0
- package/dist/entries/store-server.js.map +1 -0
- package/dist/entries/store.d.ts +25 -0
- package/dist/entries/store.d.ts.map +1 -0
- package/dist/entries/store.js +139 -0
- package/dist/entries/store.js.map +1 -0
- package/dist/entries/transition.d.ts +2 -0
- package/dist/entries/transition.d.ts.map +1 -0
- package/dist/entries/transition.js +2 -0
- package/dist/entries/transition.js.map +1 -0
- package/dist/entries/window-server.d.ts +2 -0
- package/dist/entries/window-server.d.ts.map +1 -0
- package/dist/entries/window-server.js +2 -0
- package/dist/entries/window-server.js.map +1 -0
- package/dist/entries/window.d.ts +2 -0
- package/dist/entries/window.d.ts.map +1 -0
- package/dist/entries/window.js +2 -0
- package/dist/entries/window.js.map +1 -0
- package/dist/front/ast.d.ts +290 -0
- package/dist/front/ast.d.ts.map +1 -0
- package/dist/front/ast.js +1 -0
- package/dist/front/ast.js.map +1 -0
- package/dist/front/diagnostics.d.ts +13 -0
- package/dist/front/diagnostics.d.ts.map +1 -0
- package/dist/front/diagnostics.js +38 -0
- package/dist/front/diagnostics.js.map +1 -0
- package/dist/front/ignores.d.ts +12 -0
- package/dist/front/ignores.d.ts.map +1 -0
- package/dist/front/ignores.js +75 -0
- package/dist/front/ignores.js.map +1 -0
- package/dist/front/index.d.ts +17 -0
- package/dist/front/index.d.ts.map +1 -0
- package/dist/front/index.js +65 -0
- package/dist/front/index.js.map +1 -0
- package/dist/front/legacy.d.ts +5 -0
- package/dist/front/legacy.d.ts.map +1 -0
- package/dist/front/legacy.js +408 -0
- package/dist/front/legacy.js.map +1 -0
- package/dist/front/locate.d.ts +4 -0
- package/dist/front/locate.d.ts.map +1 -0
- package/dist/front/locate.js +19 -0
- package/dist/front/locate.js.map +1 -0
- package/dist/front/lower.d.ts +39 -0
- package/dist/front/lower.d.ts.map +1 -0
- package/dist/front/lower.js +470 -0
- package/dist/front/lower.js.map +1 -0
- package/dist/front/parse/attribute.d.ts +12 -0
- package/dist/front/parse/attribute.d.ts.map +1 -0
- package/dist/front/parse/attribute.js +288 -0
- package/dist/front/parse/attribute.js.map +1 -0
- package/dist/front/parse/bracket.d.ts +3 -0
- package/dist/front/parse/bracket.d.ts.map +1 -0
- package/dist/front/parse/bracket.js +102 -0
- package/dist/front/parse/bracket.js.map +1 -0
- package/dist/front/parse/characters.d.ts +4 -0
- package/dist/front/parse/characters.d.ts.map +1 -0
- package/dist/front/parse/characters.js +6 -0
- package/dist/front/parse/characters.js.map +1 -0
- package/dist/front/parse/decode.d.ts +2 -0
- package/dist/front/parse/decode.d.ts.map +1 -0
- package/dist/front/parse/decode.js +89 -0
- package/dist/front/parse/decode.js.map +1 -0
- package/dist/front/parse/element.d.ts +3 -0
- package/dist/front/parse/element.d.ts.map +1 -0
- package/dist/front/parse/element.js +311 -0
- package/dist/front/parse/element.js.map +1 -0
- package/dist/front/parse/entities.d.ts +2 -0
- package/dist/front/parse/entities.d.ts.map +1 -0
- package/dist/front/parse/entities.js +2234 -0
- package/dist/front/parse/entities.js.map +1 -0
- package/dist/front/parse/expression.d.ts +5 -0
- package/dist/front/parse/expression.d.ts.map +1 -0
- package/dist/front/parse/expression.js +86 -0
- package/dist/front/parse/expression.js.map +1 -0
- package/dist/front/parse/html.d.ts +8 -0
- package/dist/front/parse/html.d.ts.map +1 -0
- package/dist/front/parse/html.js +146 -0
- package/dist/front/parse/html.js.map +1 -0
- package/dist/front/parse/identifier.d.ts +4 -0
- package/dist/front/parse/identifier.d.ts.map +1 -0
- package/dist/front/parse/identifier.js +24 -0
- package/dist/front/parse/identifier.js.map +1 -0
- package/dist/front/parse/index.d.ts +13 -0
- package/dist/front/parse/index.d.ts.map +1 -0
- package/dist/front/parse/index.js +74 -0
- package/dist/front/parse/index.js.map +1 -0
- package/dist/front/parse/js.d.ts +27 -0
- package/dist/front/parse/js.d.ts.map +1 -0
- package/dist/front/parse/js.js +241 -0
- package/dist/front/parse/js.js.map +1 -0
- package/dist/front/parse/options.d.ts +3 -0
- package/dist/front/parse/options.d.ts.map +1 -0
- package/dist/front/parse/options.js +198 -0
- package/dist/front/parse/options.js.map +1 -0
- package/dist/front/parse/parser.d.ts +50 -0
- package/dist/front/parse/parser.d.ts.map +1 -0
- package/dist/front/parse/parser.js +157 -0
- package/dist/front/parse/parser.js.map +1 -0
- package/dist/front/parse/pattern.d.ts +4 -0
- package/dist/front/parse/pattern.d.ts.map +1 -0
- package/dist/front/parse/pattern.js +53 -0
- package/dist/front/parse/pattern.js.map +1 -0
- package/dist/front/parse/script.d.ts +4 -0
- package/dist/front/parse/script.d.ts.map +1 -0
- package/dist/front/parse/script.js +60 -0
- package/dist/front/parse/script.js.map +1 -0
- package/dist/front/parse/style.d.ts +7 -0
- package/dist/front/parse/style.d.ts.map +1 -0
- package/dist/front/parse/style.js +397 -0
- package/dist/front/parse/style.js.map +1 -0
- package/dist/front/parse/tag.d.ts +3 -0
- package/dist/front/parse/tag.d.ts.map +1 -0
- package/dist/front/parse/tag.js +591 -0
- package/dist/front/parse/tag.js.map +1 -0
- package/dist/front/print/css.d.ts +5 -0
- package/dist/front/print/css.d.ts.map +1 -0
- package/dist/front/print/css.js +234 -0
- package/dist/front/print/css.js.map +1 -0
- package/dist/front/print/index.d.ts +18 -0
- package/dist/front/print/index.d.ts.map +1 -0
- package/dist/front/print/index.js +24 -0
- package/dist/front/print/index.js.map +1 -0
- package/dist/front/print/layout.d.ts +11 -0
- package/dist/front/print/layout.d.ts.map +1 -0
- package/dist/front/print/layout.js +73 -0
- package/dist/front/print/layout.js.map +1 -0
- package/dist/front/print/template.d.ts +5 -0
- package/dist/front/print/template.d.ts.map +1 -0
- package/dist/front/print/template.js +455 -0
- package/dist/front/print/template.js.map +1 -0
- package/dist/front/runes.d.ts +13 -0
- package/dist/front/runes.d.ts.map +1 -0
- package/dist/front/runes.js +253 -0
- package/dist/front/runes.js.map +1 -0
- package/dist/front/stores.d.ts +5 -0
- package/dist/front/stores.d.ts.map +1 -0
- package/dist/front/stores.js +84 -0
- package/dist/front/stores.js.map +1 -0
- package/dist/front/typescript.d.ts +2 -0
- package/dist/front/typescript.d.ts.map +1 -0
- package/dist/front/typescript.js +182 -0
- package/dist/front/typescript.js.map +1 -0
- package/dist/front/validate/anchors.d.ts +15 -0
- package/dist/front/validate/anchors.d.ts.map +1 -0
- package/dist/front/validate/anchors.js +43 -0
- package/dist/front/validate/anchors.js.map +1 -0
- package/dist/front/validate/index.d.ts +16 -0
- package/dist/front/validate/index.d.ts.map +1 -0
- package/dist/front/validate/index.js +139 -0
- package/dist/front/validate/index.js.map +1 -0
- package/dist/front/validate/legacy.d.ts +9 -0
- package/dist/front/validate/legacy.d.ts.map +1 -0
- package/dist/front/validate/legacy.js +102 -0
- package/dist/front/validate/legacy.js.map +1 -0
- package/dist/front/validate/report.d.ts +14 -0
- package/dist/front/validate/report.d.ts.map +1 -0
- package/dist/front/validate/report.js +29 -0
- package/dist/front/validate/report.js.map +1 -0
- package/dist/front/validate/template.d.ts +31 -0
- package/dist/front/validate/template.d.ts.map +1 -0
- package/dist/front/validate/template.js +507 -0
- package/dist/front/validate/template.js.map +1 -0
- package/dist/front/wording.d.ts +4 -0
- package/dist/front/wording.d.ts.map +1 -0
- package/dist/front/wording.js +110 -0
- package/dist/front/wording.js.map +1 -0
- package/dist/shared/format.d.ts +3 -0
- package/dist/shared/format.d.ts.map +1 -0
- package/dist/shared/format.js +7 -0
- package/dist/shared/format.js.map +1 -0
- package/easing.d.ts +2 -0
- package/elements.d.ts +1220 -0
- package/index.d.ts +2 -0
- package/motion.d.ts +2 -0
- package/package.json +128 -5
- package/src/compiler/diagnostics.ts +233 -0
- package/src/compiler/index.ts +292 -0
- package/src/compiler/options.ts +140 -0
- package/src/compiler/preprocess/decode.ts +85 -0
- package/src/compiler/preprocess/index.ts +299 -0
- package/src/compiler/preprocess/mapped.ts +146 -0
- package/src/compiler/proxy.ts +154 -0
- package/src/entries/action.ts +1 -0
- package/src/entries/animate.ts +1 -0
- package/src/entries/attachments.ts +1 -0
- package/src/entries/context.ts +50 -0
- package/src/entries/easing.ts +1 -0
- package/src/entries/events.ts +1 -0
- package/src/entries/index-server.ts +17 -0
- package/src/entries/index.ts +41 -0
- package/src/entries/internal/client.ts +15 -0
- package/src/entries/internal/disclose-version.ts +4 -0
- package/src/entries/internal/index.ts +3 -0
- package/src/entries/internal/server.ts +8 -0
- package/src/entries/internal/tracing.ts +1 -0
- package/src/entries/motion-server.ts +1 -0
- package/src/entries/motion.ts +1 -0
- package/src/entries/proxy.ts +86 -0
- package/src/entries/reactivity-server.ts +9 -0
- package/src/entries/reactivity.ts +9 -0
- package/src/entries/report.ts +81 -0
- package/src/entries/server.ts +76 -0
- package/src/entries/store-client.ts +80 -0
- package/src/entries/store-server.ts +44 -0
- package/src/entries/store.ts +201 -0
- package/src/entries/transition.ts +1 -0
- package/src/entries/window-server.ts +1 -0
- package/src/entries/window.ts +1 -0
- package/src/front/ast.ts +369 -0
- package/src/front/diagnostics.ts +53 -0
- package/src/front/ignores.ts +84 -0
- package/src/front/index.ts +86 -0
- package/src/front/legacy.ts +414 -0
- package/src/front/locate.ts +20 -0
- package/src/front/lower.ts +509 -0
- package/src/front/parse/attribute.ts +319 -0
- package/src/front/parse/bracket.ts +99 -0
- package/src/front/parse/characters.ts +19 -0
- package/src/front/parse/decode.ts +87 -0
- package/src/front/parse/element.ts +354 -0
- package/src/front/parse/entities.ts +2233 -0
- package/src/front/parse/expression.ts +85 -0
- package/src/front/parse/html.ts +158 -0
- package/src/front/parse/identifier.ts +29 -0
- package/src/front/parse/index.ts +88 -0
- package/src/front/parse/js.ts +284 -0
- package/src/front/parse/options.ts +194 -0
- package/src/front/parse/parser.ts +189 -0
- package/src/front/parse/pattern.ts +57 -0
- package/src/front/parse/script.ts +74 -0
- package/src/front/parse/style.ts +399 -0
- package/src/front/parse/tag.ts +601 -0
- package/src/front/print/css.ts +239 -0
- package/src/front/print/index.ts +40 -0
- package/src/front/print/layout.ts +87 -0
- package/src/front/print/template.ts +448 -0
- package/src/front/runes.ts +267 -0
- package/src/front/stores.ts +98 -0
- package/src/front/typescript.ts +178 -0
- package/src/front/validate/anchors.ts +54 -0
- package/src/front/validate/index.ts +174 -0
- package/src/front/validate/legacy.ts +119 -0
- package/src/front/validate/report.ts +38 -0
- package/src/front/validate/template.ts +549 -0
- package/src/front/wording.ts +112 -0
- package/src/shared/format.ts +8 -0
- package/store.d.ts +2 -0
- package/svelte-html.d.ts +53 -0
- package/transition.d.ts +2 -0
- package/types/compiler/interfaces.d.ts +2 -0
- package/types/compiler/preprocess.d.ts +2 -0
- package/types/index.d.ts +1453 -0
- package/README.md +0 -3
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { CompileError } from 'vigla/compiler';
|
|
2
|
+
|
|
3
|
+
export interface Notice {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type Kind = 'component' | 'module';
|
|
9
|
+
|
|
10
|
+
const moduleKeys = ['filename', 'rootDir', 'dev', 'generate', 'warningFilter', 'experimental'];
|
|
11
|
+
|
|
12
|
+
const componentKeys = new Set([
|
|
13
|
+
...moduleKeys,
|
|
14
|
+
'name',
|
|
15
|
+
'runes',
|
|
16
|
+
'css',
|
|
17
|
+
'cssHash',
|
|
18
|
+
'cssOutputFilename',
|
|
19
|
+
'outputFilename',
|
|
20
|
+
'customElement',
|
|
21
|
+
'discloseVersion',
|
|
22
|
+
'namespace',
|
|
23
|
+
'modernAst',
|
|
24
|
+
'preserveComments',
|
|
25
|
+
'preserveWhitespace',
|
|
26
|
+
'fragments',
|
|
27
|
+
'hmr',
|
|
28
|
+
'sourcemap',
|
|
29
|
+
'accessors',
|
|
30
|
+
'immutable',
|
|
31
|
+
'compatibility',
|
|
32
|
+
'legacy',
|
|
33
|
+
'format',
|
|
34
|
+
'tag',
|
|
35
|
+
'sveltePath',
|
|
36
|
+
'errorMode',
|
|
37
|
+
'varsReport',
|
|
38
|
+
'loopGuardTimeout',
|
|
39
|
+
'enableSourcemap',
|
|
40
|
+
'hydratable'
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const removed: Readonly<Record<string, string>> = {
|
|
44
|
+
legacy:
|
|
45
|
+
'The legacy option has been removed. If you are using this because of legacy.componentApi, use compatibility.componentApi instead',
|
|
46
|
+
format:
|
|
47
|
+
'The format option has been removed in Svelte 4, the compiler only outputs ESM now. Remove "format" from your compiler options. If you did not set this yourself, bump the version of your bundler plugin (vite-plugin-svelte/rollup-plugin-svelte/svelte-loader)',
|
|
48
|
+
tag: 'The tag option has been removed in Svelte 5. Use `<svelte:options customElement="tag-name" />` inside the component instead. If that does not solve your use case, please open an issue on GitHub with details.',
|
|
49
|
+
sveltePath:
|
|
50
|
+
'The sveltePath option has been removed in Svelte 5. If this option was crucial for you, please open an issue on GitHub with your use case.',
|
|
51
|
+
errorMode:
|
|
52
|
+
'The errorMode option has been removed. If you are using this through svelte-preprocess with TypeScript, use the https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax setting instead',
|
|
53
|
+
varsReport:
|
|
54
|
+
'The vars option has been removed. If you are using this through svelte-preprocess with TypeScript, use the https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax setting instead'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const retired: Readonly<Record<string, Notice>> = {
|
|
58
|
+
loopGuardTimeout: {
|
|
59
|
+
code: 'options_removed_loop_guard_timeout',
|
|
60
|
+
message: 'The `loopGuardTimeout` option has been removed'
|
|
61
|
+
},
|
|
62
|
+
enableSourcemap: {
|
|
63
|
+
code: 'options_removed_enable_sourcemap',
|
|
64
|
+
message:
|
|
65
|
+
'The `enableSourcemap` option has been removed. Source maps are always generated now, and tooling can choose to ignore them'
|
|
66
|
+
},
|
|
67
|
+
hydratable: {
|
|
68
|
+
code: 'options_removed_hydratable',
|
|
69
|
+
message: 'The `hydratable` option has been removed. Svelte components are always hydratable now'
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const deprecated: Readonly<Record<string, Notice>> = {
|
|
74
|
+
accessors: {
|
|
75
|
+
code: 'options_deprecated_accessors',
|
|
76
|
+
message: 'The `accessors` option has been deprecated. It will have no effect in runes mode'
|
|
77
|
+
},
|
|
78
|
+
immutable: {
|
|
79
|
+
code: 'options_deprecated_immutable',
|
|
80
|
+
message: 'The `immutable` option has been deprecated. It will have no effect in runes mode'
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
function fail(code: string, message: string): never {
|
|
85
|
+
throw new CompileError({ code, message, start: 0, end: 0 });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function invalid(details: string): never {
|
|
89
|
+
fail('options_invalid_value', `Invalid compiler option: ${details}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function nested(value: unknown, path: string, allowed: readonly string[]): Record<string, unknown> {
|
|
93
|
+
if (value === undefined) return {};
|
|
94
|
+
if (typeof value !== 'object' || value === null) invalid(`${path} should be an object`);
|
|
95
|
+
const record = value as Record<string, unknown>;
|
|
96
|
+
for (const key of Object.keys(record)) {
|
|
97
|
+
if (!allowed.includes(key))
|
|
98
|
+
fail('options_unrecognised', `Unrecognised compiler option ${path}.${key}`);
|
|
99
|
+
}
|
|
100
|
+
return record;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function validate(options: object, kind: Kind): Notice[] {
|
|
104
|
+
const given = options as Record<string, unknown>;
|
|
105
|
+
const notices: Notice[] = [];
|
|
106
|
+
for (const key of Object.keys(given)) {
|
|
107
|
+
if (!componentKeys.has(key))
|
|
108
|
+
fail('options_unrecognised', `Unrecognised compiler option ${key}`);
|
|
109
|
+
if (given[key] === undefined) continue;
|
|
110
|
+
if (kind === 'module' && !moduleKeys.includes(key)) continue;
|
|
111
|
+
const message = removed[key];
|
|
112
|
+
if (message !== undefined) fail('options_removed', `Invalid compiler option: ${message}`);
|
|
113
|
+
const notice = deprecated[key];
|
|
114
|
+
if (notice !== undefined) fail(notice.code, notice.message);
|
|
115
|
+
const retirement = retired[key];
|
|
116
|
+
if (retirement !== undefined) notices.push(retirement);
|
|
117
|
+
}
|
|
118
|
+
const experimental = nested(given.experimental, 'experimental', ['async']);
|
|
119
|
+
if (experimental.async === false) invalid('`experimental.async: false` — async is the only mode');
|
|
120
|
+
if (kind === 'module') return notices;
|
|
121
|
+
const compatibility = nested(given.compatibility, 'compatibility', ['componentApi']);
|
|
122
|
+
if (compatibility.componentApi === 4) {
|
|
123
|
+
invalid('`compatibility.componentApi: 4` — the Svelte 4 component API is not supported');
|
|
124
|
+
}
|
|
125
|
+
const runes =
|
|
126
|
+
typeof given.runes === 'function' ? given.runes({ filename: given.filename }) : given.runes;
|
|
127
|
+
if (runes === false) invalid('`runes: false` — legacy mode is not supported');
|
|
128
|
+
if (
|
|
129
|
+
given.namespace !== undefined &&
|
|
130
|
+
given.namespace !== 'html' &&
|
|
131
|
+
given.namespace !== 'svg' &&
|
|
132
|
+
given.namespace !== 'mathml'
|
|
133
|
+
) {
|
|
134
|
+
invalid('namespace should be one of "html", "mathml" or "svg"');
|
|
135
|
+
}
|
|
136
|
+
if (given.fragments !== undefined && given.fragments !== 'html' && given.fragments !== 'tree') {
|
|
137
|
+
invalid('fragments should be either "html" or "tree"');
|
|
138
|
+
}
|
|
139
|
+
return notices;
|
|
140
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { decode } from '@jridgewell/sourcemap-codec';
|
|
2
|
+
import type { Map, Segment } from './mapped.ts';
|
|
3
|
+
|
|
4
|
+
interface GeneratorMapping {
|
|
5
|
+
generatedLine: number;
|
|
6
|
+
generatedColumn: number;
|
|
7
|
+
originalLine: number;
|
|
8
|
+
originalColumn: number;
|
|
9
|
+
source: string | null;
|
|
10
|
+
name: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Generator {
|
|
14
|
+
_version: number;
|
|
15
|
+
_file?: string | null;
|
|
16
|
+
_sources: { toArray(): string[] };
|
|
17
|
+
_names: { toArray(): string[] };
|
|
18
|
+
_mappings: { toArray(): GeneratorMapping[] };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function indexOf(values: readonly string[]): Record<string, number> {
|
|
22
|
+
const index: Record<string, number> = {};
|
|
23
|
+
values.forEach((value, position) => {
|
|
24
|
+
index[value] = position;
|
|
25
|
+
});
|
|
26
|
+
return index;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function same(a: GeneratorMapping, b: GeneratorMapping): boolean {
|
|
30
|
+
return (
|
|
31
|
+
a.generatedColumn === b.generatedColumn &&
|
|
32
|
+
a.originalColumn === b.originalColumn &&
|
|
33
|
+
a.name === b.name &&
|
|
34
|
+
a.generatedLine === b.generatedLine &&
|
|
35
|
+
a.originalLine === b.originalLine &&
|
|
36
|
+
a.source === b.source
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function fromGenerator(generator: Generator): Map {
|
|
41
|
+
const sources = generator._sources.toArray();
|
|
42
|
+
const names = generator._names.toArray();
|
|
43
|
+
const sourceIndex = indexOf(sources);
|
|
44
|
+
const nameIndex = indexOf(names);
|
|
45
|
+
const mappings = generator._mappings.toArray();
|
|
46
|
+
const lines: Segment[][] = [[]];
|
|
47
|
+
let line = 1;
|
|
48
|
+
let current = lines[0] as Segment[];
|
|
49
|
+
mappings.forEach((mapping, index) => {
|
|
50
|
+
if (mapping.generatedLine > line) {
|
|
51
|
+
while (mapping.generatedLine > line) {
|
|
52
|
+
lines.push([]);
|
|
53
|
+
line++;
|
|
54
|
+
}
|
|
55
|
+
current = lines[mapping.generatedLine - 1] as Segment[];
|
|
56
|
+
} else if (index > 0 && same(mapping, mappings[index - 1] as GeneratorMapping)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const segment: Segment = [mapping.generatedColumn];
|
|
60
|
+
if (mapping.source != null) {
|
|
61
|
+
segment.push(
|
|
62
|
+
sourceIndex[mapping.source] as number,
|
|
63
|
+
mapping.originalLine - 1,
|
|
64
|
+
mapping.originalColumn
|
|
65
|
+
);
|
|
66
|
+
if (mapping.name != null) segment.push(nameIndex[mapping.name] as number);
|
|
67
|
+
}
|
|
68
|
+
current.push(segment);
|
|
69
|
+
});
|
|
70
|
+
const map = { version: generator._version, sources, names, mappings: lines } as unknown as Map & {
|
|
71
|
+
file?: string;
|
|
72
|
+
};
|
|
73
|
+
if (generator._file != null) map.file = generator._file;
|
|
74
|
+
return map;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function decodeMap(raw: string | object): Map {
|
|
78
|
+
let map = (typeof raw === 'string' ? JSON.parse(raw) : raw) as Map & { mappings: unknown };
|
|
79
|
+
if (typeof map.mappings === 'string') map.mappings = decode(map.mappings) as never;
|
|
80
|
+
const generator = map as unknown as Generator & { constructor: { name: string } };
|
|
81
|
+
if (generator._mappings && generator.constructor.name === 'SourceMapGenerator') {
|
|
82
|
+
map = fromGenerator(generator);
|
|
83
|
+
}
|
|
84
|
+
return map;
|
|
85
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { basename, combine } from 'vigla/compiler';
|
|
2
|
+
import { locator } from '../../front/index.ts';
|
|
3
|
+
import { decodeMap } from './decode.ts';
|
|
4
|
+
import {
|
|
5
|
+
MappedCode,
|
|
6
|
+
addOffset,
|
|
7
|
+
slice,
|
|
8
|
+
type Map,
|
|
9
|
+
type Point,
|
|
10
|
+
type Segment,
|
|
11
|
+
type Source
|
|
12
|
+
} from './mapped.ts';
|
|
13
|
+
|
|
14
|
+
export interface Processed {
|
|
15
|
+
code: string;
|
|
16
|
+
map?: string | object;
|
|
17
|
+
dependencies?: string[];
|
|
18
|
+
attributes?: Record<string, string | boolean>;
|
|
19
|
+
toString?: () => string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type MarkupPreprocessor = (options: {
|
|
23
|
+
content: string;
|
|
24
|
+
filename?: string;
|
|
25
|
+
}) => Processed | void | Promise<Processed | void>;
|
|
26
|
+
|
|
27
|
+
export type Preprocessor = (options: {
|
|
28
|
+
content: string;
|
|
29
|
+
attributes: Record<string, string | boolean>;
|
|
30
|
+
markup: string;
|
|
31
|
+
filename?: string;
|
|
32
|
+
}) => Processed | void | Promise<Processed | void>;
|
|
33
|
+
|
|
34
|
+
export interface PreprocessorGroup {
|
|
35
|
+
name?: string;
|
|
36
|
+
markup?: MarkupPreprocessor;
|
|
37
|
+
style?: Preprocessor;
|
|
38
|
+
script?: Preprocessor;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface Update {
|
|
42
|
+
string?: string;
|
|
43
|
+
map?: Map;
|
|
44
|
+
dependencies?: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function pointer(text: string): (offset: number) => Point {
|
|
48
|
+
const locate = locator(text);
|
|
49
|
+
return (offset) => {
|
|
50
|
+
const { line, column } = locate(offset);
|
|
51
|
+
return { line: line - 1, column };
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class Result implements Source {
|
|
56
|
+
source: string;
|
|
57
|
+
readonly filename: string | undefined;
|
|
58
|
+
readonly basename: string | null;
|
|
59
|
+
readonly maps: Map[] = [];
|
|
60
|
+
readonly dependencies: string[] = [];
|
|
61
|
+
locate: (offset: number) => Point;
|
|
62
|
+
|
|
63
|
+
constructor(source: string, filename: string | undefined) {
|
|
64
|
+
this.source = source;
|
|
65
|
+
this.filename = filename;
|
|
66
|
+
this.locate = pointer(source);
|
|
67
|
+
this.basename = filename == null ? null : basename(filename);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
update({ string, map, dependencies }: Update): void {
|
|
71
|
+
if (string != null) {
|
|
72
|
+
this.source = string;
|
|
73
|
+
this.locate = pointer(string);
|
|
74
|
+
}
|
|
75
|
+
if (map) this.maps.unshift(map);
|
|
76
|
+
if (dependencies) this.dependencies.push(...dependencies);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
processed(): Processed {
|
|
80
|
+
const code = this.source;
|
|
81
|
+
return {
|
|
82
|
+
code,
|
|
83
|
+
dependencies: [...new Set(this.dependencies)],
|
|
84
|
+
map: combine(this.basename, this.maps) as unknown as object,
|
|
85
|
+
toString: () => code
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const dataUri = /data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(\S*)/;
|
|
91
|
+
const mappingUrl = '[#@]\\s*sourceMappingURL\\s*=\\s*(\\S*)';
|
|
92
|
+
const scriptMapping = new RegExp(`(?://${mappingUrl})|(?:/\\*${mappingUrl}\\s*\\*/)$`);
|
|
93
|
+
const styleMapping = new RegExp(`/\\*${mappingUrl}\\s*\\*/$`);
|
|
94
|
+
|
|
95
|
+
function decodeBase64(data: string): string {
|
|
96
|
+
if (typeof Buffer === 'function') return Buffer.from(data, 'base64').toString();
|
|
97
|
+
const bytes = Uint8Array.from(atob(data), (char) => char.charCodeAt(0));
|
|
98
|
+
return new TextDecoder().decode(bytes);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function attachedMap(processed: Processed, tag: 'script' | 'style'): void {
|
|
102
|
+
const warn = (message: string): void => {
|
|
103
|
+
const start =
|
|
104
|
+
processed.code.length < 100 ? processed.code : `${processed.code.slice(0, 100)} [...]`;
|
|
105
|
+
console.warn(`warning: ${message}. processed.code = ${JSON.stringify(start)}`);
|
|
106
|
+
};
|
|
107
|
+
processed.code = processed.code.replace(
|
|
108
|
+
tag === 'script' ? scriptMapping : styleMapping,
|
|
109
|
+
(_, first: string | undefined, second: string | undefined) => {
|
|
110
|
+
const url = (tag === 'script' ? first || second : first) as string;
|
|
111
|
+
const data = (url.match(dataUri) ?? [])[1];
|
|
112
|
+
if (data) {
|
|
113
|
+
if (processed.map) {
|
|
114
|
+
warn(
|
|
115
|
+
'Not implemented. Found sourcemap in both processed.code and processed.map. Please update your preprocessor to return only one sourcemap.'
|
|
116
|
+
);
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
processed.map = decodeBase64(data);
|
|
120
|
+
return '';
|
|
121
|
+
}
|
|
122
|
+
if (!processed.map) {
|
|
123
|
+
warn(
|
|
124
|
+
`Found sourcemap path ${JSON.stringify(url)} in processed.code, but no sourcemap data. Please update your preprocessor to return sourcemap data directly.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function contentCode(processed: Processed, location: Point, basename: string | null): MappedCode {
|
|
133
|
+
let map: Map | undefined;
|
|
134
|
+
if (processed.map) {
|
|
135
|
+
map = decodeMap(processed.map);
|
|
136
|
+
if (map?.sources) {
|
|
137
|
+
const index = map.sources.indexOf(basename);
|
|
138
|
+
if (index !== -1) addOffset(map, location, index);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return MappedCode.processed(processed.code, map);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function tagCode(
|
|
145
|
+
processed: Processed,
|
|
146
|
+
tag: 'style' | 'script',
|
|
147
|
+
originalAttributes: string,
|
|
148
|
+
attributes: string,
|
|
149
|
+
source: Source
|
|
150
|
+
): MappedCode {
|
|
151
|
+
const originalOpen = `<${tag}${originalAttributes}>`;
|
|
152
|
+
const open = `<${tag}${attributes}>`;
|
|
153
|
+
let openCode: MappedCode;
|
|
154
|
+
if (originalOpen.length !== open.length) {
|
|
155
|
+
const name = `<${tag}`.length;
|
|
156
|
+
const mappings: Segment[][] = [
|
|
157
|
+
[
|
|
158
|
+
[0, 0, 0, 0],
|
|
159
|
+
[name, 0, 0, name]
|
|
160
|
+
]
|
|
161
|
+
];
|
|
162
|
+
const line = open.split('\n').length - 1;
|
|
163
|
+
const column = open.length - (line === 0 ? 0 : open.lastIndexOf('\n')) - 1;
|
|
164
|
+
while (mappings.length <= line) mappings.push([[0, 0, 0, name]]);
|
|
165
|
+
(mappings[line] as Segment[]).push([
|
|
166
|
+
column,
|
|
167
|
+
0,
|
|
168
|
+
originalOpen.split('\n').length - 1,
|
|
169
|
+
originalOpen.length - originalOpen.lastIndexOf('\n') - 1
|
|
170
|
+
]);
|
|
171
|
+
const map = { version: 3, names: [], sources: [source.basename], mappings } as unknown as Map;
|
|
172
|
+
addOffset(map, source.locate(0), 0);
|
|
173
|
+
openCode = MappedCode.processed(open, map);
|
|
174
|
+
} else {
|
|
175
|
+
openCode = MappedCode.source(slice(open, 0, source));
|
|
176
|
+
}
|
|
177
|
+
const closeCode = MappedCode.source(
|
|
178
|
+
slice(`</${tag}>`, originalOpen.length + source.source.length, source)
|
|
179
|
+
);
|
|
180
|
+
attachedMap(processed, tag);
|
|
181
|
+
const content = contentCode(processed, source.locate(originalOpen.length), source.basename);
|
|
182
|
+
return openCode.concat(content).concat(closeCode);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const attributePattern = /([\w-$]+\b)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;
|
|
186
|
+
|
|
187
|
+
function parseAttributes(text: string): Record<string, string | boolean> {
|
|
188
|
+
const attributes: Record<string, string | boolean> = {};
|
|
189
|
+
for (const match of text.matchAll(attributePattern)) {
|
|
190
|
+
const value = match[2] || match[3] || match[4];
|
|
191
|
+
attributes[match[1] as string] = !value || value;
|
|
192
|
+
}
|
|
193
|
+
return attributes;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function stringifyAttributes(
|
|
197
|
+
attributes: Record<string, string | boolean> | undefined
|
|
198
|
+
): string | undefined {
|
|
199
|
+
if (!attributes) return undefined;
|
|
200
|
+
const value = Object.entries(attributes)
|
|
201
|
+
.map(([key, value]) => (value === true ? key : `${key}="${value}"`))
|
|
202
|
+
.join(' ');
|
|
203
|
+
return value ? ` ${value}` : value;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const styleTags =
|
|
207
|
+
/<!--[^]*?-->|<style((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
|
|
208
|
+
const scriptTags =
|
|
209
|
+
/<!--[^]*?-->|<script((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
|
|
210
|
+
|
|
211
|
+
interface Replacement {
|
|
212
|
+
offset: number;
|
|
213
|
+
length: number;
|
|
214
|
+
code: MappedCode;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function processTag(
|
|
218
|
+
tag: 'style' | 'script',
|
|
219
|
+
preprocessor: Preprocessor,
|
|
220
|
+
source: Source
|
|
221
|
+
): Promise<Update> {
|
|
222
|
+
const dependencies: string[] = [];
|
|
223
|
+
const markup = source.source;
|
|
224
|
+
const single = async (
|
|
225
|
+
whole: string,
|
|
226
|
+
attributes = '',
|
|
227
|
+
content = '',
|
|
228
|
+
offset: number
|
|
229
|
+
): Promise<MappedCode> => {
|
|
230
|
+
const unchanged = (): MappedCode => MappedCode.source(slice(whole, offset, source));
|
|
231
|
+
if (!attributes && !content) return unchanged();
|
|
232
|
+
const processed = await preprocessor({
|
|
233
|
+
content: content || '',
|
|
234
|
+
attributes: parseAttributes(attributes || ''),
|
|
235
|
+
markup,
|
|
236
|
+
filename: source.filename
|
|
237
|
+
});
|
|
238
|
+
if (!processed) return unchanged();
|
|
239
|
+
if (processed.dependencies) dependencies.push(...processed.dependencies);
|
|
240
|
+
if (!processed.map && processed.code === content) return unchanged();
|
|
241
|
+
return tagCode(
|
|
242
|
+
processed,
|
|
243
|
+
tag,
|
|
244
|
+
attributes,
|
|
245
|
+
stringifyAttributes(processed.attributes) ?? attributes,
|
|
246
|
+
slice(content, offset, source)
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const pending: Promise<Replacement>[] = [];
|
|
251
|
+
for (const match of markup.matchAll(tag === 'style' ? styleTags : scriptTags)) {
|
|
252
|
+
const offset = match.index;
|
|
253
|
+
pending.push(
|
|
254
|
+
single(match[0], match[1], match[2], offset).then((code) => ({
|
|
255
|
+
offset,
|
|
256
|
+
length: match[0].length,
|
|
257
|
+
code
|
|
258
|
+
}))
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
const replacements = await Promise.all(pending);
|
|
262
|
+
const out = new MappedCode();
|
|
263
|
+
let end = 0;
|
|
264
|
+
for (const { offset, length, code } of replacements) {
|
|
265
|
+
out.concat(MappedCode.source(slice(markup.slice(end, offset), end, source))).concat(code);
|
|
266
|
+
end = offset + length;
|
|
267
|
+
}
|
|
268
|
+
out.concat(MappedCode.source(slice(markup.slice(end), end, source)));
|
|
269
|
+
return { string: out.string, map: out.map, dependencies };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function processMarkup(process: MarkupPreprocessor, source: Source): Promise<Update> {
|
|
273
|
+
const processed = await process({ content: source.source, filename: source.filename });
|
|
274
|
+
if (!processed) return {};
|
|
275
|
+
return {
|
|
276
|
+
string: processed.code,
|
|
277
|
+
map: processed.map
|
|
278
|
+
? ((typeof processed.map === 'string' ? JSON.parse(processed.map) : processed.map) as Map)
|
|
279
|
+
: undefined,
|
|
280
|
+
dependencies: processed.dependencies
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export async function preprocess(
|
|
285
|
+
source: string,
|
|
286
|
+
preprocessor: PreprocessorGroup | PreprocessorGroup[],
|
|
287
|
+
options?: { filename?: string }
|
|
288
|
+
): Promise<Processed> {
|
|
289
|
+
const filename =
|
|
290
|
+
(options && options.filename) || (preprocessor as { filename?: string } | undefined)?.filename;
|
|
291
|
+
const groups = preprocessor ? (Array.isArray(preprocessor) ? preprocessor : [preprocessor]) : [];
|
|
292
|
+
const result = new Result(source, filename);
|
|
293
|
+
for (const group of groups) {
|
|
294
|
+
if (group.markup) result.update(await processMarkup(group.markup, result));
|
|
295
|
+
if (group.script) result.update(await processTag('script', group.script, result));
|
|
296
|
+
if (group.style) result.update(await processTag('style', group.style, result));
|
|
297
|
+
}
|
|
298
|
+
return result.processed();
|
|
299
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { DecodedSourceMap, SourceMapSegment } from '@jridgewell/remapping';
|
|
2
|
+
|
|
3
|
+
export type Map = DecodedSourceMap;
|
|
4
|
+
export type Segment = number[];
|
|
5
|
+
|
|
6
|
+
export interface Point {
|
|
7
|
+
line: number;
|
|
8
|
+
column: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Source {
|
|
12
|
+
source: string;
|
|
13
|
+
locate: (offset: number) => Point;
|
|
14
|
+
basename: string | null;
|
|
15
|
+
filename: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function slice(code: string, offset: number, source: Source): Source {
|
|
19
|
+
return {
|
|
20
|
+
source: code,
|
|
21
|
+
locate: (index) => source.locate(index + offset),
|
|
22
|
+
basename: source.basename,
|
|
23
|
+
filename: source.filename
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function addOffset(map: Map, offset: Point, sourceIndex: number): void {
|
|
28
|
+
for (const line of map.mappings) {
|
|
29
|
+
for (const segment of line as unknown as Segment[]) {
|
|
30
|
+
if (segment[1] !== sourceIndex) continue;
|
|
31
|
+
if (segment[2] === 0) (segment[3] as number) += offset.column;
|
|
32
|
+
(segment[2] as number) += offset.line;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function merge<T>(
|
|
38
|
+
own: readonly T[],
|
|
39
|
+
other: readonly T[] | undefined
|
|
40
|
+
): [T[], number[], boolean, boolean] {
|
|
41
|
+
const table = own.slice();
|
|
42
|
+
const indices: number[] = [];
|
|
43
|
+
let changed = false;
|
|
44
|
+
(other ?? []).forEach((value, index) => {
|
|
45
|
+
const existing = own.indexOf(value);
|
|
46
|
+
if (existing >= 0) {
|
|
47
|
+
indices[index] = existing;
|
|
48
|
+
} else {
|
|
49
|
+
indices[index] = table.length;
|
|
50
|
+
table.push(value);
|
|
51
|
+
changed = true;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const moved = changed && indices.some((value, index) => value !== index);
|
|
55
|
+
return [table, indices, changed, moved];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const lineToken = /([^\w\s]|\s+)/g;
|
|
59
|
+
|
|
60
|
+
function emptyMap(): Map {
|
|
61
|
+
return { version: 3, mappings: [], sources: [], names: [] } as unknown as Map;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class MappedCode {
|
|
65
|
+
string: string;
|
|
66
|
+
map: Map;
|
|
67
|
+
|
|
68
|
+
constructor(string = '', map: Map | null = null) {
|
|
69
|
+
this.string = string;
|
|
70
|
+
this.map = map ?? emptyMap();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
concat(other: MappedCode): MappedCode {
|
|
74
|
+
if (other.string === '') return this;
|
|
75
|
+
if (this.string === '') {
|
|
76
|
+
this.string = other.string;
|
|
77
|
+
this.map = other.map;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
const columnOffset = this.string.length - this.string.lastIndexOf('\n') - 1;
|
|
81
|
+
this.string += other.string;
|
|
82
|
+
const own = this.map;
|
|
83
|
+
const theirs = other.map;
|
|
84
|
+
if (theirs.mappings.length === 0) return this;
|
|
85
|
+
const [sources, sourceIndices, sourcesChanged, sourcesMoved] = merge(
|
|
86
|
+
own.sources,
|
|
87
|
+
theirs.sources
|
|
88
|
+
);
|
|
89
|
+
const [names, nameIndices, namesChanged, namesMoved] = merge(own.names, theirs.names);
|
|
90
|
+
if (sourcesChanged) own.sources = sources;
|
|
91
|
+
if (namesChanged) own.names = names;
|
|
92
|
+
if (sourcesMoved || namesMoved) {
|
|
93
|
+
for (const line of theirs.mappings) {
|
|
94
|
+
for (const segment of line as unknown as Segment[]) {
|
|
95
|
+
if (sourcesMoved && (segment[1] as number) >= 0)
|
|
96
|
+
segment[1] = sourceIndices[segment[1] as number] as number;
|
|
97
|
+
if (namesMoved && (segment[4] as number) >= 0)
|
|
98
|
+
segment[4] = nameIndices[segment[4] as number] as number;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const mappings = theirs.mappings as unknown as Segment[][];
|
|
103
|
+
if (columnOffset > 0) {
|
|
104
|
+
for (const segment of mappings[0] as Segment[]) (segment[0] as number) += columnOffset;
|
|
105
|
+
}
|
|
106
|
+
const ownMappings = own.mappings as unknown as Segment[][];
|
|
107
|
+
const lastLine = ownMappings[ownMappings.length - 1] as Segment[];
|
|
108
|
+
for (const segment of mappings.shift() as Segment[]) lastLine.push(segment);
|
|
109
|
+
for (const line of mappings) ownMappings.push(line);
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static processed(string: string, map?: Map): MappedCode {
|
|
114
|
+
const lines = string.split('\n').length;
|
|
115
|
+
if (map) {
|
|
116
|
+
for (let missing = lines - map.mappings.length; missing > 0; missing--) map.mappings.push([]);
|
|
117
|
+
return new MappedCode(string, map);
|
|
118
|
+
}
|
|
119
|
+
if (string === '') return new MappedCode();
|
|
120
|
+
const fresh = emptyMap();
|
|
121
|
+
for (let index = 0; index < lines; index++) fresh.mappings.push([]);
|
|
122
|
+
return new MappedCode(string, fresh);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static source({ source, basename, locate }: Source): MappedCode {
|
|
126
|
+
const offset = locate(0) ?? { line: 0, column: 0 };
|
|
127
|
+
const map = { version: 3, names: [], sources: [basename], mappings: [] } as unknown as Map;
|
|
128
|
+
if (source === '') return new MappedCode(source, map);
|
|
129
|
+
const lines = source.split('\n');
|
|
130
|
+
const mappings = map.mappings as unknown as Segment[][];
|
|
131
|
+
lines.forEach((text, line) => {
|
|
132
|
+
const segments: Segment[] = [];
|
|
133
|
+
mappings.push(segments);
|
|
134
|
+
let column = 0;
|
|
135
|
+
for (const token of text.split(lineToken)) {
|
|
136
|
+
if (token === '') continue;
|
|
137
|
+
segments.push([column, 0, offset.line + line, column]);
|
|
138
|
+
column += token.length;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
for (const segment of mappings[0] as Segment[]) (segment[3] as number) += offset.column;
|
|
142
|
+
return new MappedCode(source, map);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type { SourceMapSegment };
|