tempo-sdk 0.0.99 → 0.0.101
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/README.md +3 -403
- package/dist/assets/editor.d.ts +43 -65
- package/dist/assets/editor.js +1 -573
- package/dist/assets/index.d.ts +11 -61
- package/dist/assets/index.js +1 -338
- package/dist/assets/parser.d.ts +68 -78
- package/dist/assets/parser.js +1 -33
- package/dist/astro/asset-preview-client.d.ts +3 -2
- package/dist/astro/asset-preview-client.js +1 -93
- package/dist/astro/controls.d.ts +1 -3
- package/dist/astro/controls.js +1 -7
- package/dist/astro/document-client.d.ts +5 -6
- package/dist/astro/document-client.js +1 -78
- package/dist/astro/runtime.d.ts +23 -11
- package/dist/astro/runtime.js +1 -86
- package/dist/astro.d.ts +19 -13
- package/dist/astro.js +1 -818
- package/dist/canvas/astro-contract.d.ts +0 -3
- package/dist/canvas/astro-contract.js +1 -9
- package/dist/canvas/astro.d.ts +3 -4
- package/dist/canvas/astro.js +1 -42
- package/dist/canvas/editor.d.ts +187 -183
- package/dist/canvas/editor.js +1 -1094
- package/dist/canvas/flutter-preview.d.ts +0 -1
- package/dist/canvas/flutter-preview.js +1 -9
- package/dist/canvas/index.d.ts +46 -100
- package/dist/canvas/index.js +1 -3926
- package/dist/canvas/interact-projection.d.ts +7 -5
- package/dist/canvas/interact-projection.js +1 -12
- package/dist/canvas/parser.d.ts +10 -303
- package/dist/canvas/parser.js +1 -30
- package/dist/canvas/svelte.d.ts +6 -7
- package/dist/canvas/svelte.js +1 -91
- package/dist/canvas/vue.d.ts +9 -49
- package/dist/canvas/vue.js +1 -264
- package/dist/chunk-FH6TMWFA.js +1 -0
- package/dist/chunk-GQIOB5SV.js +1 -0
- package/dist/chunk-HBQ7FFH7.js +1 -0
- package/dist/chunk-JRJOWLCN.js +1 -0
- package/dist/chunk-M3GN2KUH.js +1 -0
- package/dist/chunk-MPIHFFML.js +1 -0
- package/dist/chunk-N2V6XXRK.js +1 -0
- package/dist/chunk-QNVQ7U2W.js +1 -0
- package/dist/chunk-T5TY3U2H.js +1 -0
- package/dist/chunk-TK37FQAR.js +1 -0
- package/dist/chunk-XO2BSHWM.js +1 -0
- package/dist/chunk-XUSV3KOD.js +1 -0
- package/dist/chunk-YRBEBVG4.js +1 -0
- package/dist/{controls-uCaQ3CNX.d.ts → controls-DKslABtM.d.ts} +0 -3
- package/dist/expo/plugin.cjs +1 -1928
- package/dist/expo/plugin.js +1 -8
- package/dist/expo-babel-plugin.cjs +1 -1928
- package/dist/expo-babel-plugin.d.cts +46 -40
- package/dist/expo-babel-plugin.d.ts +46 -40
- package/dist/expo-babel-plugin.js +1 -8
- package/dist/flutter-preview-path.d.ts +23 -7
- package/dist/flutter-preview-path.js +1 -16
- package/dist/index.d.ts +33 -45
- package/dist/index.js +1 -20
- package/dist/nextjs/plugin.cjs +1 -413
- package/dist/nextjs/plugin.js +1 -7
- package/dist/nextjs-loader.cjs +1 -2277
- package/dist/nextjs.cjs +1 -484
- package/dist/nextjs.d.cts +2 -58
- package/dist/nextjs.d.ts +2 -58
- package/dist/nextjs.js +1 -17
- package/dist/nuxt/runtime/identity.d.ts +2 -4
- package/dist/nuxt/runtime/identity.js +1 -18
- package/dist/nuxt.d.ts +31 -92
- package/dist/nuxt.js +1 -5854
- package/dist/{page-DwLnOM5d.d.ts → page-Bc8PekIX.d.ts} +1 -5
- package/dist/parser.d-MO5ciJ5n.d.ts +236 -0
- package/dist/{storyboard-CMJVBSXn.d.ts → storyboard.contract.d-UQ4MUYN5.d.ts} +3 -25
- package/dist/svelte.d.ts +8 -18
- package/dist/svelte.js +1 -917
- package/dist/types-CfUgM2w4.d.ts +57 -0
- package/dist/v1-client-compat-n0E0XxuX.d.ts +5 -0
- package/dist/vue.d.ts +17 -58
- package/dist/vue.js +1 -1501
- package/package.json +12 -62
- package/dist/assets/editor.js.map +0 -1
- package/dist/assets/index.js.map +0 -1
- package/dist/assets/parser.js.map +0 -1
- package/dist/astro/asset-preview-client.js.map +0 -1
- package/dist/astro/controls.js.map +0 -1
- package/dist/astro/document-client.js.map +0 -1
- package/dist/astro/runtime.js.map +0 -1
- package/dist/astro.js.map +0 -1
- package/dist/canvas/astro-contract.js.map +0 -1
- package/dist/canvas/astro.js.map +0 -1
- package/dist/canvas/editor.js.map +0 -1
- package/dist/canvas/flutter-preview.js.map +0 -1
- package/dist/canvas/index.js.map +0 -1
- package/dist/canvas/interact-projection.js.map +0 -1
- package/dist/canvas/parser.js.map +0 -1
- package/dist/canvas/svelte.js.map +0 -1
- package/dist/canvas/vue.js.map +0 -1
- package/dist/chunk-27WT3XUG.js +0 -455
- package/dist/chunk-27WT3XUG.js.map +0 -1
- package/dist/chunk-5HIIF354.js +0 -67
- package/dist/chunk-5HIIF354.js.map +0 -1
- package/dist/chunk-65B52AR7.js +0 -11
- package/dist/chunk-65B52AR7.js.map +0 -1
- package/dist/chunk-6HYKKP5N.js +0 -2658
- package/dist/chunk-6HYKKP5N.js.map +0 -1
- package/dist/chunk-6SOP4XU6.js +0 -1891
- package/dist/chunk-6SOP4XU6.js.map +0 -1
- package/dist/chunk-AFXE462X.js +0 -1253
- package/dist/chunk-AFXE462X.js.map +0 -1
- package/dist/chunk-BQPKOVI5.js +0 -115
- package/dist/chunk-BQPKOVI5.js.map +0 -1
- package/dist/chunk-CYDF4LYJ.js +0 -342
- package/dist/chunk-CYDF4LYJ.js.map +0 -1
- package/dist/chunk-CYQE3TLC.js +0 -37
- package/dist/chunk-CYQE3TLC.js.map +0 -1
- package/dist/chunk-DI2ZFAWL.js +0 -14
- package/dist/chunk-DI2ZFAWL.js.map +0 -1
- package/dist/chunk-EGRHWZRV.js +0 -1
- package/dist/chunk-EGRHWZRV.js.map +0 -1
- package/dist/chunk-FGWGY3G3.js +0 -157
- package/dist/chunk-FGWGY3G3.js.map +0 -1
- package/dist/chunk-HOBTDB6G.js +0 -112
- package/dist/chunk-HOBTDB6G.js.map +0 -1
- package/dist/chunk-I7VF4ZOV.js +0 -630
- package/dist/chunk-I7VF4ZOV.js.map +0 -1
- package/dist/chunk-JVVHU3A7.js +0 -1077
- package/dist/chunk-JVVHU3A7.js.map +0 -1
- package/dist/chunk-MIXQVPDH.js +0 -8606
- package/dist/chunk-MIXQVPDH.js.map +0 -1
- package/dist/chunk-MU7S7NU7.js +0 -183
- package/dist/chunk-MU7S7NU7.js.map +0 -1
- package/dist/chunk-OX2YKYSL.js +0 -13
- package/dist/chunk-OX2YKYSL.js.map +0 -1
- package/dist/chunk-PYAJHLXO.js +0 -903
- package/dist/chunk-PYAJHLXO.js.map +0 -1
- package/dist/chunk-SGN7BDRE.js +0 -16
- package/dist/chunk-SGN7BDRE.js.map +0 -1
- package/dist/chunk-SGTGDLOX.js +0 -285
- package/dist/chunk-SGTGDLOX.js.map +0 -1
- package/dist/chunk-T364NBR3.js +0 -1440
- package/dist/chunk-T364NBR3.js.map +0 -1
- package/dist/chunk-U66QI3EN.js +0 -1524
- package/dist/chunk-U66QI3EN.js.map +0 -1
- package/dist/chunk-WTXOWQ7N.js +0 -47
- package/dist/chunk-WTXOWQ7N.js.map +0 -1
- package/dist/chunk-X5DJKVBT.js +0 -1308
- package/dist/chunk-X5DJKVBT.js.map +0 -1
- package/dist/chunk-ZT7HJ6YU.js +0 -38
- package/dist/chunk-ZT7HJ6YU.js.map +0 -1
- package/dist/chunk-ZW26VZHX.js +0 -3169
- package/dist/chunk-ZW26VZHX.js.map +0 -1
- package/dist/controls-reader-5MFHYBZZ.js +0 -192
- package/dist/controls-reader-5MFHYBZZ.js.map +0 -1
- package/dist/expo/plugin.cjs.map +0 -1
- package/dist/expo/plugin.js.map +0 -1
- package/dist/expo-babel-plugin.cjs.map +0 -1
- package/dist/expo-babel-plugin.js.map +0 -1
- package/dist/flutter-preview-path.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/nextjs/plugin.cjs.map +0 -1
- package/dist/nextjs/plugin.js.map +0 -1
- package/dist/nextjs-loader.cjs.map +0 -1
- package/dist/nextjs.cjs.map +0 -1
- package/dist/nextjs.js.map +0 -1
- package/dist/nuxt/runtime/identity.js.map +0 -1
- package/dist/nuxt.js.map +0 -1
- package/dist/svelte.js.map +0 -1
- package/dist/types-C8OIU-kc.d.ts +0 -106
- package/dist/v1-client-compat-qxaXEDm_.d.ts +0 -23
- package/dist/vue.js.map +0 -1
package/dist/svelte.js
CHANGED
|
@@ -1,917 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
applyStringEdits,
|
|
3
|
-
defaultSourceRoot,
|
|
4
|
-
mapOffsetThroughStringEdits,
|
|
5
|
-
readModifiedTs,
|
|
6
|
-
resolveAnnotationIdentity
|
|
7
|
-
} from "./chunk-HOBTDB6G.js";
|
|
8
|
-
import {
|
|
9
|
-
MagicString
|
|
10
|
-
} from "./chunk-JVVHU3A7.js";
|
|
11
|
-
import {
|
|
12
|
-
appendModuleVersionRecord
|
|
13
|
-
} from "./chunk-BQPKOVI5.js";
|
|
14
|
-
import {
|
|
15
|
-
readLiteralExpression,
|
|
16
|
-
sourceVersionHash
|
|
17
|
-
} from "./chunk-MU7S7NU7.js";
|
|
18
|
-
|
|
19
|
-
// svelte.ts
|
|
20
|
-
import { readFileSync } from "fs";
|
|
21
|
-
import { resolve } from "path";
|
|
22
|
-
|
|
23
|
-
// ../../modules/svelte-editor/compiler.ts
|
|
24
|
-
import * as SvelteCompiler from "svelte/compiler";
|
|
25
|
-
|
|
26
|
-
// ../../modules/svelte-editor/byte-order-mark.ts
|
|
27
|
-
function withoutByteOrderMark(source) {
|
|
28
|
-
return source.charCodeAt(0) === 65279 ? ` ${source.slice(1)}` : source;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ../../modules/svelte-editor/compiler.ts
|
|
32
|
-
var compile2 = (source, options) => SvelteCompiler.compile(withoutByteOrderMark(source), options);
|
|
33
|
-
var parse2 = ((source, options) => SvelteCompiler.parse(
|
|
34
|
-
withoutByteOrderMark(source),
|
|
35
|
-
options
|
|
36
|
-
));
|
|
37
|
-
|
|
38
|
-
// ../../modules/svelte-editor/escape.ts
|
|
39
|
-
function escapeSvelteAttributeValue(value, quote) {
|
|
40
|
-
let escaped = value.split("&").join("&").split("<").join("<").split(">").join(">").split("{").join("{").split("}").join("}");
|
|
41
|
-
escaped = quote === '"' ? escaped.split('"').join(""") : escaped.split("'").join("'");
|
|
42
|
-
return escaped;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
46
|
-
var WalkerBase = class {
|
|
47
|
-
constructor() {
|
|
48
|
-
this.should_skip = false;
|
|
49
|
-
this.should_remove = false;
|
|
50
|
-
this.replacement = null;
|
|
51
|
-
this.context = {
|
|
52
|
-
skip: () => this.should_skip = true,
|
|
53
|
-
remove: () => this.should_remove = true,
|
|
54
|
-
replace: (node) => this.replacement = node
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @template {Node} Parent
|
|
59
|
-
* @param {Parent | null | undefined} parent
|
|
60
|
-
* @param {keyof Parent | null | undefined} prop
|
|
61
|
-
* @param {number | null | undefined} index
|
|
62
|
-
* @param {Node} node
|
|
63
|
-
*/
|
|
64
|
-
replace(parent, prop, index, node) {
|
|
65
|
-
if (parent && prop) {
|
|
66
|
-
if (index != null) {
|
|
67
|
-
parent[prop][index] = node;
|
|
68
|
-
} else {
|
|
69
|
-
parent[prop] = node;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @template {Node} Parent
|
|
75
|
-
* @param {Parent | null | undefined} parent
|
|
76
|
-
* @param {keyof Parent | null | undefined} prop
|
|
77
|
-
* @param {number | null | undefined} index
|
|
78
|
-
*/
|
|
79
|
-
remove(parent, prop, index) {
|
|
80
|
-
if (parent && prop) {
|
|
81
|
-
if (index !== null && index !== void 0) {
|
|
82
|
-
parent[prop].splice(index, 1);
|
|
83
|
-
} else {
|
|
84
|
-
delete parent[prop];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
|
91
|
-
var SyncWalker = class extends WalkerBase {
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
* @param {SyncHandler} [enter]
|
|
95
|
-
* @param {SyncHandler} [leave]
|
|
96
|
-
*/
|
|
97
|
-
constructor(enter, leave) {
|
|
98
|
-
super();
|
|
99
|
-
this.should_skip = false;
|
|
100
|
-
this.should_remove = false;
|
|
101
|
-
this.replacement = null;
|
|
102
|
-
this.context = {
|
|
103
|
-
skip: () => this.should_skip = true,
|
|
104
|
-
remove: () => this.should_remove = true,
|
|
105
|
-
replace: (node) => this.replacement = node
|
|
106
|
-
};
|
|
107
|
-
this.enter = enter;
|
|
108
|
-
this.leave = leave;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* @template {Node} Parent
|
|
112
|
-
* @param {Node} node
|
|
113
|
-
* @param {Parent | null} parent
|
|
114
|
-
* @param {keyof Parent} [prop]
|
|
115
|
-
* @param {number | null} [index]
|
|
116
|
-
* @returns {Node | null}
|
|
117
|
-
*/
|
|
118
|
-
visit(node, parent, prop, index) {
|
|
119
|
-
if (node) {
|
|
120
|
-
if (this.enter) {
|
|
121
|
-
const _should_skip = this.should_skip;
|
|
122
|
-
const _should_remove = this.should_remove;
|
|
123
|
-
const _replacement = this.replacement;
|
|
124
|
-
this.should_skip = false;
|
|
125
|
-
this.should_remove = false;
|
|
126
|
-
this.replacement = null;
|
|
127
|
-
this.enter.call(this.context, node, parent, prop, index);
|
|
128
|
-
if (this.replacement) {
|
|
129
|
-
node = this.replacement;
|
|
130
|
-
this.replace(parent, prop, index, node);
|
|
131
|
-
}
|
|
132
|
-
if (this.should_remove) {
|
|
133
|
-
this.remove(parent, prop, index);
|
|
134
|
-
}
|
|
135
|
-
const skipped = this.should_skip;
|
|
136
|
-
const removed = this.should_remove;
|
|
137
|
-
this.should_skip = _should_skip;
|
|
138
|
-
this.should_remove = _should_remove;
|
|
139
|
-
this.replacement = _replacement;
|
|
140
|
-
if (skipped) return node;
|
|
141
|
-
if (removed) return null;
|
|
142
|
-
}
|
|
143
|
-
let key;
|
|
144
|
-
for (key in node) {
|
|
145
|
-
const value = node[key];
|
|
146
|
-
if (value && typeof value === "object") {
|
|
147
|
-
if (Array.isArray(value)) {
|
|
148
|
-
const nodes = (
|
|
149
|
-
/** @type {Array<unknown>} */
|
|
150
|
-
value
|
|
151
|
-
);
|
|
152
|
-
for (let i = 0; i < nodes.length; i += 1) {
|
|
153
|
-
const item = nodes[i];
|
|
154
|
-
if (isNode(item)) {
|
|
155
|
-
if (!this.visit(item, node, key, i)) {
|
|
156
|
-
i--;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
} else if (isNode(value)) {
|
|
161
|
-
this.visit(value, node, key, null);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (this.leave) {
|
|
166
|
-
const _replacement = this.replacement;
|
|
167
|
-
const _should_remove = this.should_remove;
|
|
168
|
-
this.replacement = null;
|
|
169
|
-
this.should_remove = false;
|
|
170
|
-
this.leave.call(this.context, node, parent, prop, index);
|
|
171
|
-
if (this.replacement) {
|
|
172
|
-
node = this.replacement;
|
|
173
|
-
this.replace(parent, prop, index, node);
|
|
174
|
-
}
|
|
175
|
-
if (this.should_remove) {
|
|
176
|
-
this.remove(parent, prop, index);
|
|
177
|
-
}
|
|
178
|
-
const removed = this.should_remove;
|
|
179
|
-
this.replacement = _replacement;
|
|
180
|
-
this.should_remove = _should_remove;
|
|
181
|
-
if (removed) return null;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return node;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
function isNode(value) {
|
|
188
|
-
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
|
192
|
-
function walk(ast, { enter, leave }) {
|
|
193
|
-
const instance = new SyncWalker(enter, leave);
|
|
194
|
-
return instance.visit(ast, null);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// ../../modules/svelte-editor/literal-attributes.ts
|
|
198
|
-
function literalMustacheAttribute(attribute) {
|
|
199
|
-
const name = attribute.name.toLowerCase();
|
|
200
|
-
if (name === "class" || name === "style" || name.startsWith("on"))
|
|
201
|
-
return null;
|
|
202
|
-
const tag = Array.isArray(attribute.value) ? attribute.value.length === 1 ? attribute.value[0] : void 0 : attribute.value === true ? void 0 : attribute.value;
|
|
203
|
-
if (tag?.type !== "ExpressionTag") return null;
|
|
204
|
-
const expression = tag.expression;
|
|
205
|
-
const value = readLiteralExpression(expression);
|
|
206
|
-
if (typeof value !== "string" && typeof value !== "number") return null;
|
|
207
|
-
return {
|
|
208
|
-
value,
|
|
209
|
-
rendered: String(value),
|
|
210
|
-
expression: { start: expression.start, end: expression.end },
|
|
211
|
-
quoted: Array.isArray(attribute.value)
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// ../../modules/svelte-editor/style-directives.ts
|
|
216
|
-
function normalizeProperty(property) {
|
|
217
|
-
const trimmed = property.trim();
|
|
218
|
-
return trimmed.startsWith("--") ? trimmed : trimmed.toLowerCase();
|
|
219
|
-
}
|
|
220
|
-
function styleDirectives(attributes) {
|
|
221
|
-
return attributes.filter(
|
|
222
|
-
(attribute) => attribute.type === "StyleDirective"
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
function literalStyleDirective(source, directive, siblings) {
|
|
226
|
-
if (directive.modifiers.length > 0) return null;
|
|
227
|
-
if (siblings.some(
|
|
228
|
-
(other) => other !== directive && normalizeProperty(other.name) === normalizeProperty(directive.name)
|
|
229
|
-
))
|
|
230
|
-
return null;
|
|
231
|
-
const value = directive.value;
|
|
232
|
-
if (!Array.isArray(value) || value.length !== 1) return null;
|
|
233
|
-
const text = value[0];
|
|
234
|
-
if (text.type !== "Text") return null;
|
|
235
|
-
const quote = source[text.start - 1];
|
|
236
|
-
if (quote !== '"' && quote !== "'" || source[text.end] !== quote || text.end + 1 !== directive.end)
|
|
237
|
-
return null;
|
|
238
|
-
return { value: text.data, start: text.start, end: text.end, quote };
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// ../../modules/svelte-editor/parse.ts
|
|
242
|
-
function parseSvelteSourceInternal(source, filename, validation = "compiler") {
|
|
243
|
-
const cacheKey = `${validation}\0${filename}\0${source}`;
|
|
244
|
-
const cached = parseCache.get(cacheKey);
|
|
245
|
-
if (cached) {
|
|
246
|
-
parseCache.delete(cacheKey);
|
|
247
|
-
parseCache.set(cacheKey, cached);
|
|
248
|
-
return cached;
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
if (validation === "compiler") {
|
|
252
|
-
compile2(source, { filename, generate: false });
|
|
253
|
-
}
|
|
254
|
-
const ast = parse2(source, { filename, modern: true });
|
|
255
|
-
const elements = /* @__PURE__ */ new Map();
|
|
256
|
-
const invocations = /* @__PURE__ */ new Map();
|
|
257
|
-
const targets = /* @__PURE__ */ new Map();
|
|
258
|
-
const targetNodes = /* @__PURE__ */ new Map();
|
|
259
|
-
const elementStack = [];
|
|
260
|
-
const fragmentOwnerTypes = /* @__PURE__ */ new WeakMap();
|
|
261
|
-
const templateScopes = /* @__PURE__ */ new WeakMap();
|
|
262
|
-
const scopeStack = [];
|
|
263
|
-
walk(ast, {
|
|
264
|
-
enter(node, parent) {
|
|
265
|
-
const svelteNode = node;
|
|
266
|
-
if (svelteNode.type === "Fragment") {
|
|
267
|
-
const fragment = node;
|
|
268
|
-
const owner = parent;
|
|
269
|
-
const inherits = (owner?.type === "RegularElement" || owner?.type === "Component" || owner?.type === "SvelteComponent") && !owner.attributes.some(
|
|
270
|
-
(attribute) => attribute.type === "LetDirective"
|
|
271
|
-
) && !fragment.nodes.some(
|
|
272
|
-
(child) => child.type === "ConstTag" || child.type === "SnippetBlock"
|
|
273
|
-
);
|
|
274
|
-
const scope = inherits ? scopeStack[scopeStack.length - 1] ?? fragment : fragment;
|
|
275
|
-
templateScopes.set(fragment, scope);
|
|
276
|
-
scopeStack.push(scope);
|
|
277
|
-
fragmentOwnerTypes.set(
|
|
278
|
-
node,
|
|
279
|
-
parent?.type ?? null
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
const target = toTargetInfo(
|
|
283
|
-
source,
|
|
284
|
-
node
|
|
285
|
-
);
|
|
286
|
-
if (target) {
|
|
287
|
-
const fragment = parent;
|
|
288
|
-
target.parentFragmentOwnerType = fragment?.type === "Fragment" ? fragmentOwnerTypes.get(fragment) ?? null : null;
|
|
289
|
-
targets.set(target.start, target);
|
|
290
|
-
targetNodes.set(
|
|
291
|
-
target.start,
|
|
292
|
-
node
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
if (svelteNode.type !== "RegularElement" && svelteNode.type !== "Component")
|
|
296
|
-
return;
|
|
297
|
-
const element = node;
|
|
298
|
-
const parentFragment = parent;
|
|
299
|
-
if (parentFragment.type !== "Fragment") {
|
|
300
|
-
throw new Error(
|
|
301
|
-
`native element at offset ${element.start} has no exact template fragment parent`
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
const opening = locateOpeningTagEnd(source, element);
|
|
305
|
-
if (opening.kind === "invalid") {
|
|
306
|
-
throw new Error(opening.message);
|
|
307
|
-
}
|
|
308
|
-
const into = svelteNode.type === "Component" ? invocations : elements;
|
|
309
|
-
if (into.has(element.start)) {
|
|
310
|
-
throw new Error(
|
|
311
|
-
`multiple native elements start at UTF-16 offset ${element.start}`
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
into.set(element.start, {
|
|
315
|
-
node: element,
|
|
316
|
-
tagName: element.name,
|
|
317
|
-
start: element.start,
|
|
318
|
-
end: element.end,
|
|
319
|
-
openingEnd: opening.openingEnd,
|
|
320
|
-
selfClosing: opening.selfClosing,
|
|
321
|
-
childrenStart: opening.selfClosing ? null : opening.openingEnd,
|
|
322
|
-
childrenEnd: opening.selfClosing ? null : locateClosingTagStart(source, element, opening.openingEnd),
|
|
323
|
-
parentElementStart: elementStack[elementStack.length - 1]?.start ?? null,
|
|
324
|
-
parentFragment,
|
|
325
|
-
parentFragmentOwnerType: fragmentOwnerTypes.get(parentFragment) ?? null,
|
|
326
|
-
// An invocation runs another component's code with its props.
|
|
327
|
-
containsDynamicTemplateSyntax: svelteNode.type === "Component" || containsDynamicSyntax(element),
|
|
328
|
-
attributeNames: element.attributes.filter(
|
|
329
|
-
(attribute) => attribute.type === "Attribute"
|
|
330
|
-
).map((attribute) => attribute.name),
|
|
331
|
-
hasSpreadAttributes: element.attributes.some(
|
|
332
|
-
(attribute) => attribute.type === "SpreadAttribute"
|
|
333
|
-
),
|
|
334
|
-
directiveTypes: element.attributes.filter(
|
|
335
|
-
(attribute) => attribute.type !== "Attribute" && attribute.type !== "SpreadAttribute"
|
|
336
|
-
).map((attribute) => attribute.type)
|
|
337
|
-
});
|
|
338
|
-
if (svelteNode.type === "RegularElement") elementStack.push(element);
|
|
339
|
-
},
|
|
340
|
-
leave(node) {
|
|
341
|
-
const svelteNode = node;
|
|
342
|
-
if (svelteNode.type === "RegularElement") elementStack.pop();
|
|
343
|
-
if (svelteNode.type === "Fragment") scopeStack.pop();
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
const result = {
|
|
347
|
-
kind: "ok",
|
|
348
|
-
elements,
|
|
349
|
-
invocations,
|
|
350
|
-
templateScopes,
|
|
351
|
-
targets,
|
|
352
|
-
targetNodes
|
|
353
|
-
};
|
|
354
|
-
rememberParse(cacheKey, result);
|
|
355
|
-
return result;
|
|
356
|
-
} catch (error) {
|
|
357
|
-
const result = compilerError(error);
|
|
358
|
-
rememberParse(cacheKey, result);
|
|
359
|
-
return result;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
function toTargetInfo(source, node) {
|
|
363
|
-
if (node.type === "RegularElement") {
|
|
364
|
-
return {
|
|
365
|
-
kind: "native-element",
|
|
366
|
-
tagName: node.name ?? "",
|
|
367
|
-
start: node.start,
|
|
368
|
-
end: node.end,
|
|
369
|
-
...targetAttributeFacts(source, node.attributes ?? [], true)
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
if (node.type === "Component") {
|
|
373
|
-
return {
|
|
374
|
-
kind: "component",
|
|
375
|
-
tagName: node.name ?? "",
|
|
376
|
-
start: node.start,
|
|
377
|
-
end: node.end,
|
|
378
|
-
...targetAttributeFacts(source, node.attributes ?? [])
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
if (node.type === "SvelteComponent") {
|
|
382
|
-
return {
|
|
383
|
-
kind: "component",
|
|
384
|
-
tagName: node.name ?? node.type,
|
|
385
|
-
start: node.start,
|
|
386
|
-
end: node.end,
|
|
387
|
-
...targetAttributeFacts(source, node.attributes ?? [])
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
if (node.type === "SvelteElement") {
|
|
391
|
-
return {
|
|
392
|
-
kind: "dynamic-element",
|
|
393
|
-
tagName: node.name ?? node.type,
|
|
394
|
-
start: node.start,
|
|
395
|
-
end: node.end,
|
|
396
|
-
...targetAttributeFacts(source, node.attributes ?? [])
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
if (node.type === "SlotElement" || node.type === "TitleElement" || node.type === "SvelteBody" || node.type === "SvelteBoundary" || node.type === "SvelteDocument" || node.type === "SvelteFragment" || node.type === "SvelteHead" || node.type === "SvelteSelf" || node.type === "SvelteWindow") {
|
|
400
|
-
return {
|
|
401
|
-
kind: "special-element",
|
|
402
|
-
tagName: node.name ?? node.type,
|
|
403
|
-
start: node.start,
|
|
404
|
-
end: node.end
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
return null;
|
|
408
|
-
}
|
|
409
|
-
function targetAttributeFacts(source, attributes, native = false) {
|
|
410
|
-
const directives = styleDirectives(attributes);
|
|
411
|
-
const literalMustaches = native && !attributes.some((attribute) => attribute.type === "SpreadAttribute");
|
|
412
|
-
const staticAttributes = {};
|
|
413
|
-
for (const attribute of attributes) {
|
|
414
|
-
if (attribute.type !== "Attribute") continue;
|
|
415
|
-
const literal = literalMustaches ? literalMustacheAttribute(attribute) : null;
|
|
416
|
-
if (literal) {
|
|
417
|
-
staticAttributes[attribute.name] = literal.rendered;
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
if (attribute.value === true) {
|
|
421
|
-
staticAttributes[attribute.name] = true;
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
if (Array.isArray(attribute.value) && attribute.value.every((part) => part.type === "Text")) {
|
|
425
|
-
staticAttributes[attribute.name] = attribute.value.map((part) => part.data).join("");
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
return {
|
|
429
|
-
attributeNames: attributes.filter(
|
|
430
|
-
(attribute) => attribute.type === "Attribute"
|
|
431
|
-
).map((attribute) => attribute.name),
|
|
432
|
-
hasSpreadAttributes: attributes.some(
|
|
433
|
-
(attribute) => attribute.type === "SpreadAttribute"
|
|
434
|
-
),
|
|
435
|
-
directiveTypes: attributes.filter(
|
|
436
|
-
(attribute) => attribute.type !== "Attribute" && attribute.type !== "SpreadAttribute"
|
|
437
|
-
).map((attribute) => attribute.type),
|
|
438
|
-
staticAttributes,
|
|
439
|
-
styleDirectives: directives.map((directive) => {
|
|
440
|
-
const literal = literalStyleDirective(source, directive, directives);
|
|
441
|
-
return {
|
|
442
|
-
name: directive.name,
|
|
443
|
-
...literal ? { literal: literal.value } : {}
|
|
444
|
-
};
|
|
445
|
-
})
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
var PARSE_CACHE_LIMIT = 16;
|
|
449
|
-
var parseCache = /* @__PURE__ */ new Map();
|
|
450
|
-
function rememberParse(key, result) {
|
|
451
|
-
parseCache.set(key, result);
|
|
452
|
-
while (parseCache.size > PARSE_CACHE_LIMIT) {
|
|
453
|
-
const oldest = parseCache.keys().next().value;
|
|
454
|
-
if (oldest === void 0) break;
|
|
455
|
-
parseCache.delete(oldest);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
function locateOpeningTagEnd(source, element) {
|
|
459
|
-
const lastAttribute = element.attributes[element.attributes.length - 1];
|
|
460
|
-
const afterName = element.start + 1 + element.name.length;
|
|
461
|
-
const cursor = lastAttribute?.end ?? afterName;
|
|
462
|
-
const tail = source.slice(cursor, element.end);
|
|
463
|
-
const closing = /^(\s*)(\/?)>/.exec(tail);
|
|
464
|
-
if (!closing) {
|
|
465
|
-
return {
|
|
466
|
-
kind: "invalid",
|
|
467
|
-
message: `could not locate the opening-tag terminator for <${element.name}> at UTF-16 offset ${element.start}`
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
return {
|
|
471
|
-
kind: "ok",
|
|
472
|
-
openingEnd: cursor + closing[0].length,
|
|
473
|
-
selfClosing: closing[2] === "/"
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
function locateClosingTagStart(source, element, openingEnd) {
|
|
477
|
-
const escapedName = element.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
478
|
-
const match = new RegExp(`</${escapedName}\\s*>$`).exec(
|
|
479
|
-
source.slice(openingEnd, element.end)
|
|
480
|
-
);
|
|
481
|
-
return match ? openingEnd + match.index : null;
|
|
482
|
-
}
|
|
483
|
-
function containsDynamicSyntax(element) {
|
|
484
|
-
let dynamic = false;
|
|
485
|
-
walk(element, {
|
|
486
|
-
enter(node) {
|
|
487
|
-
const type = node.type;
|
|
488
|
-
if (type === "ExpressionTag" || type === "HtmlTag" || type === "RenderTag" || type === "AttachTag" || type === "ConstTag" || type === "DeclarationTag" || type === "DebugTag" || type === "SpreadAttribute" || typeof type === "string" && type.endsWith("Directive") || type === "Component" || type === "SvelteComponent" || type === "SvelteElement" || type === "EachBlock" || type === "IfBlock" || type === "AwaitBlock" || type === "KeyBlock" || type === "SnippetBlock") {
|
|
489
|
-
dynamic = true;
|
|
490
|
-
this.skip();
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
return dynamic;
|
|
495
|
-
}
|
|
496
|
-
function compilerError(error) {
|
|
497
|
-
if (error && typeof error === "object") {
|
|
498
|
-
const value = error;
|
|
499
|
-
return {
|
|
500
|
-
kind: "invalid",
|
|
501
|
-
code: typeof value.code === "string" ? value.code : "invalid_svelte",
|
|
502
|
-
message: typeof value.message === "string" ? value.message : (
|
|
503
|
-
/* v8 ignore next -- Svelte compiler diagnostics always carry messages */
|
|
504
|
-
"Svelte source could not be parsed"
|
|
505
|
-
)
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
return {
|
|
509
|
-
kind: "invalid",
|
|
510
|
-
code: "invalid_svelte",
|
|
511
|
-
message: String(error)
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// ../../modules/svelte-editor/annotate.ts
|
|
516
|
-
var TEMPO_ATTRIBUTE_NAMES = [
|
|
517
|
-
"data-tempo-filepath",
|
|
518
|
-
"data-tempo-position",
|
|
519
|
-
"data-tempo-modifiedts",
|
|
520
|
-
"data-tempo-source-version"
|
|
521
|
-
];
|
|
522
|
-
var TEMPO_ATTRIBUTE_NAME_SET = new Set(TEMPO_ATTRIBUTE_NAMES);
|
|
523
|
-
var TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE = "data-tempo-svelte-source-registry";
|
|
524
|
-
function annotateSvelteSource(options) {
|
|
525
|
-
if (!options.filepath || !options.filename || !Number.isFinite(options.modifiedTs) || !Number.isInteger(options.modifiedTs) || options.modifiedTs < 0 || options.sourceVersion === "") {
|
|
526
|
-
return {
|
|
527
|
-
kind: "refused",
|
|
528
|
-
code: "invalid_metadata",
|
|
529
|
-
message: "filename, filepath, a non-negative integer modifiedTs, and a non-empty sourceVersion are required"
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
const inputSource = removeGeneratedSourceRegistries(options.source);
|
|
533
|
-
const validation = options.validation ?? "compiler";
|
|
534
|
-
const parsed = parseSvelteSourceInternal(
|
|
535
|
-
inputSource,
|
|
536
|
-
options.filename,
|
|
537
|
-
validation
|
|
538
|
-
);
|
|
539
|
-
if (parsed.kind === "invalid") {
|
|
540
|
-
return { kind: "refused", code: "invalid_source", message: parsed.message };
|
|
541
|
-
}
|
|
542
|
-
const removalEdits = [];
|
|
543
|
-
const existing = /* @__PURE__ */ new Map();
|
|
544
|
-
for (const element of parsed.elements.values()) {
|
|
545
|
-
const tempoAttributes = element.node.attributes.filter(
|
|
546
|
-
(attribute) => attribute.type === "Attribute" && TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name)
|
|
547
|
-
);
|
|
548
|
-
if (tempoAttributes.length === 0) continue;
|
|
549
|
-
const conflict = readExistingAnnotation(inputSource, element.node);
|
|
550
|
-
if (conflict.kind === "refused") return conflict;
|
|
551
|
-
existing.set(element.start, conflict.metadata);
|
|
552
|
-
removalEdits.push(conflict.removalEdit);
|
|
553
|
-
}
|
|
554
|
-
const baseSource = applyStringEdits(inputSource, removalEdits);
|
|
555
|
-
const baseParsed = parseSvelteSourceInternal(
|
|
556
|
-
baseSource,
|
|
557
|
-
options.filename,
|
|
558
|
-
validation
|
|
559
|
-
);
|
|
560
|
-
if (baseParsed.kind === "invalid") {
|
|
561
|
-
return {
|
|
562
|
-
kind: "refused",
|
|
563
|
-
code: "annotation_conflict",
|
|
564
|
-
message: "removing existing Tempo annotations did not recover valid source"
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
const version = options.sourceVersion ?? sourceVersionHash(baseSource);
|
|
568
|
-
for (const [currentOffset, metadata] of existing) {
|
|
569
|
-
const baseOffset = mapOffsetThroughStringEdits(currentOffset, removalEdits);
|
|
570
|
-
if (baseOffset === null || !baseParsed.elements.has(baseOffset) || metadata.filepath !== options.filepath || metadata.position !== baseOffset || metadata.modifiedTs !== options.modifiedTs || metadata.sourceVersion !== version) {
|
|
571
|
-
return {
|
|
572
|
-
kind: "refused",
|
|
573
|
-
code: "annotation_conflict",
|
|
574
|
-
message: `existing Tempo annotations at UTF-16 offset ${currentOffset} do not exactly match the recovered source identity`
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
const edits = [];
|
|
579
|
-
const skippedExistingAnnotations = [];
|
|
580
|
-
for (const element of parsed.elements.values()) {
|
|
581
|
-
const baseOffset = mapOffsetThroughStringEdits(element.start, removalEdits);
|
|
582
|
-
if (baseOffset === null || !baseParsed.elements.has(baseOffset)) {
|
|
583
|
-
return {
|
|
584
|
-
kind: "refused",
|
|
585
|
-
code: "annotation_conflict",
|
|
586
|
-
message: `could not map element at UTF-16 offset ${element.start} to recovered source`
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
if (existing.has(element.start)) {
|
|
590
|
-
skippedExistingAnnotations.push(baseOffset);
|
|
591
|
-
continue;
|
|
592
|
-
}
|
|
593
|
-
const insertionOffset = element.node.attributes[element.node.attributes.length - 1]?.end ?? element.start + 1 + element.tagName.length;
|
|
594
|
-
edits.push({
|
|
595
|
-
start: insertionOffset,
|
|
596
|
-
end: insertionOffset,
|
|
597
|
-
replacement: serializeAnnotations({
|
|
598
|
-
filepath: options.filepath,
|
|
599
|
-
position: baseOffset,
|
|
600
|
-
modifiedTs: options.modifiedTs,
|
|
601
|
-
sourceVersion: version
|
|
602
|
-
})
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
const markupStart = inputSource.charCodeAt(0) === 65279 ? 1 : 0;
|
|
606
|
-
const startEdit = {
|
|
607
|
-
start: markupStart,
|
|
608
|
-
end: markupStart,
|
|
609
|
-
replacement: `{@html '<!--${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}-->'}`
|
|
610
|
-
};
|
|
611
|
-
const annotationEdits = [startEdit, ...edits];
|
|
612
|
-
const annotatedCode = applyStringEdits(inputSource, annotationEdits);
|
|
613
|
-
const sourceRecords = buildSourceRecords({
|
|
614
|
-
source: inputSource,
|
|
615
|
-
parsed,
|
|
616
|
-
removalEdits,
|
|
617
|
-
annotationEdits,
|
|
618
|
-
annotatedCode
|
|
619
|
-
});
|
|
620
|
-
const registry = {
|
|
621
|
-
filename: options.filename,
|
|
622
|
-
filepath: options.filepath,
|
|
623
|
-
modifiedTs: options.modifiedTs,
|
|
624
|
-
sourceVersion: version,
|
|
625
|
-
components: sourceRecords.components,
|
|
626
|
-
hosts: sourceRecords.hosts
|
|
627
|
-
};
|
|
628
|
-
const registryEdit = {
|
|
629
|
-
start: inputSource.length,
|
|
630
|
-
end: inputSource.length,
|
|
631
|
-
replacement: `
|
|
632
|
-
<template ${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}="${escapeSvelteAttributeValue(JSON.stringify(registry), '"')}"></template>
|
|
633
|
-
`
|
|
634
|
-
};
|
|
635
|
-
const transformEdits = [...annotationEdits, registryEdit];
|
|
636
|
-
const code = applyStringEdits(inputSource, transformEdits);
|
|
637
|
-
try {
|
|
638
|
-
if (validation === "compiler") {
|
|
639
|
-
compile2(code, { filename: options.filename, generate: false });
|
|
640
|
-
} else {
|
|
641
|
-
const parsedOutput = parseSvelteSourceInternal(
|
|
642
|
-
code,
|
|
643
|
-
options.filename,
|
|
644
|
-
"syntax"
|
|
645
|
-
);
|
|
646
|
-
if (parsedOutput.kind === "invalid")
|
|
647
|
-
throw new Error(parsedOutput.message);
|
|
648
|
-
}
|
|
649
|
-
} catch (error) {
|
|
650
|
-
return {
|
|
651
|
-
kind: "refused",
|
|
652
|
-
code: "invalid_output",
|
|
653
|
-
message: error instanceof Error ? error.message : String(error)
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
const magic = new MagicString(inputSource);
|
|
657
|
-
for (const edit of transformEdits) {
|
|
658
|
-
magic.appendLeft(edit.start, edit.replacement);
|
|
659
|
-
}
|
|
660
|
-
if (magic.toString() !== code) {
|
|
661
|
-
return {
|
|
662
|
-
kind: "refused",
|
|
663
|
-
code: "invalid_output",
|
|
664
|
-
message: "annotation code and source-map transform outputs diverged"
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
return {
|
|
668
|
-
kind: "ok",
|
|
669
|
-
code,
|
|
670
|
-
map: magic.generateMap({
|
|
671
|
-
source: options.filename,
|
|
672
|
-
includeContent: true,
|
|
673
|
-
hires: true
|
|
674
|
-
}),
|
|
675
|
-
edits,
|
|
676
|
-
elementsAnnotated: edits.length,
|
|
677
|
-
skippedExistingAnnotations,
|
|
678
|
-
sourceVersion: version
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
function removeGeneratedSourceRegistries(source) {
|
|
682
|
-
const escaped = TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE.replace(
|
|
683
|
-
/[.*+?^${}()|[\]\\]/g,
|
|
684
|
-
"\\$&"
|
|
685
|
-
);
|
|
686
|
-
return source.replace(`{@html '<!--${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}-->'}`, "").replace(
|
|
687
|
-
new RegExp(
|
|
688
|
-
`\\n?<template\\s+${escaped}=(?:"[^"]*"|'[^']*')\\s*><\\/template>\\n?`,
|
|
689
|
-
"g"
|
|
690
|
-
),
|
|
691
|
-
""
|
|
692
|
-
);
|
|
693
|
-
}
|
|
694
|
-
function buildSourceRecords(options) {
|
|
695
|
-
const components = [];
|
|
696
|
-
const hosts = [];
|
|
697
|
-
for (const target of options.parsed.targets.values()) {
|
|
698
|
-
if (target.kind !== "component" && target.kind !== "native-element" && target.kind !== "dynamic-element") {
|
|
699
|
-
continue;
|
|
700
|
-
}
|
|
701
|
-
const position = mapOffsetThroughStringEdits(
|
|
702
|
-
target.start,
|
|
703
|
-
options.removalEdits
|
|
704
|
-
);
|
|
705
|
-
if (position === null) continue;
|
|
706
|
-
const compiledOffset = mapOffsetForward(
|
|
707
|
-
target.start,
|
|
708
|
-
options.annotationEdits
|
|
709
|
-
);
|
|
710
|
-
const location = sourceLocationAt(options.annotatedCode, compiledOffset);
|
|
711
|
-
const classValue = target.staticAttributes?.class;
|
|
712
|
-
const styleValue = target.staticAttributes?.style;
|
|
713
|
-
const lockValue = target.staticAttributes?.["data-tempo-locked"];
|
|
714
|
-
const hasSpread = target.hasSpreadAttributes === true;
|
|
715
|
-
const directives = new Set(target.directiveTypes ?? []);
|
|
716
|
-
const attributes = new Set(target.attributeNames ?? []);
|
|
717
|
-
const blockChild = /Block$/.test(target.parentFragmentOwnerType ?? "");
|
|
718
|
-
const node = options.parsed.targetNodes.get(target.start);
|
|
719
|
-
const directiveFacts = (node?.attributes ?? []).flatMap((attribute) => {
|
|
720
|
-
if (attribute.type === "Attribute" || attribute.type === "SpreadAttribute")
|
|
721
|
-
return [];
|
|
722
|
-
if (attribute.type === "AttachTag") return ["@attach"];
|
|
723
|
-
const written = options.source.slice(attribute.start, attribute.end);
|
|
724
|
-
return [written.split("=")[0].trim()];
|
|
725
|
-
});
|
|
726
|
-
const expressions = [
|
|
727
|
-
...blockChild ? ["#slot"] : [],
|
|
728
|
-
...[...attributes].filter((name) => target.staticAttributes?.[name] === void 0).map((name) => name === "class" ? "className" : name),
|
|
729
|
-
...directiveFacts
|
|
730
|
-
].join(" ");
|
|
731
|
-
const common = {
|
|
732
|
-
name: target.tagName,
|
|
733
|
-
line: location.line,
|
|
734
|
-
column: location.column,
|
|
735
|
-
position,
|
|
736
|
-
...typeof classValue === "string" ? { className: classValue } : {},
|
|
737
|
-
...typeof styleValue === "string" ? { style: styleValue } : {},
|
|
738
|
-
...lockValue === true || lockValue === "true" || lockValue === "" ? { locked: true } : lockValue === "false" ? { locked: false } : {},
|
|
739
|
-
// A spread gets a stamp even with no fact, as JSX's does.
|
|
740
|
-
...expressions || hasSpread ? { expressions } : {},
|
|
741
|
-
supportsClassName: !hasSpread && !directives.has("ClassDirective") && (!attributes.has("class") || typeof classValue === "string"),
|
|
742
|
-
supportsStyle: !hasSpread && !directives.has("StyleDirective") && (!attributes.has("style") || typeof styleValue === "string")
|
|
743
|
-
};
|
|
744
|
-
if (target.kind === "component") {
|
|
745
|
-
components.push({ kind: "component", ...common });
|
|
746
|
-
} else {
|
|
747
|
-
hosts.push({ kind: "host", ...common });
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return { components, hosts };
|
|
751
|
-
}
|
|
752
|
-
function mapOffsetForward(offset, edits) {
|
|
753
|
-
let mapped = offset;
|
|
754
|
-
for (const edit of edits) {
|
|
755
|
-
if (edit.start > offset) continue;
|
|
756
|
-
mapped += edit.replacement.length - (edit.end - edit.start);
|
|
757
|
-
}
|
|
758
|
-
return mapped;
|
|
759
|
-
}
|
|
760
|
-
function sourceLocationAt(source, offset) {
|
|
761
|
-
const before = source.slice(0, offset);
|
|
762
|
-
const lines = before.split("\n");
|
|
763
|
-
return {
|
|
764
|
-
line: lines.length,
|
|
765
|
-
column: lines[lines.length - 1]?.length ?? 0
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
function createSvelteAnnotationPreprocessor(options) {
|
|
769
|
-
return {
|
|
770
|
-
name: "svelte-source-annotation",
|
|
771
|
-
markup: ({ content, filename }) => {
|
|
772
|
-
const metadata = options.metadata({ filename, source: content });
|
|
773
|
-
if (metadata === null) return void 0;
|
|
774
|
-
const result = annotateSvelteSource({
|
|
775
|
-
source: content,
|
|
776
|
-
filename: filename ?? metadata.filepath,
|
|
777
|
-
...metadata,
|
|
778
|
-
validation: "syntax"
|
|
779
|
-
});
|
|
780
|
-
if (result.kind === "refused") {
|
|
781
|
-
throw new Error(`${result.code}: ${result.message}`);
|
|
782
|
-
}
|
|
783
|
-
return { code: result.code, map: result.map };
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
}
|
|
787
|
-
function readExistingAnnotation(source, element) {
|
|
788
|
-
const attributes = element.attributes.filter(
|
|
789
|
-
(attribute) => attribute.type === "Attribute"
|
|
790
|
-
);
|
|
791
|
-
const tempo = attributes.filter(
|
|
792
|
-
(attribute) => TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name)
|
|
793
|
-
);
|
|
794
|
-
const names = tempo.map((attribute) => attribute.name);
|
|
795
|
-
if (tempo.length !== TEMPO_ATTRIBUTE_NAMES.length || TEMPO_ATTRIBUTE_NAMES.some((name, index) => names[index] !== name) || attributes.slice(-TEMPO_ATTRIBUTE_NAMES.length).some((attribute, index) => attribute !== tempo[index]) || tempo.some((attribute) => !isStaticLiteralAttribute(attribute))) {
|
|
796
|
-
return annotationConflict(element.start);
|
|
797
|
-
}
|
|
798
|
-
const [
|
|
799
|
-
filepathAttribute,
|
|
800
|
-
positionAttribute,
|
|
801
|
-
modifiedAttribute,
|
|
802
|
-
versionAttribute
|
|
803
|
-
] = tempo;
|
|
804
|
-
if (!filepathAttribute || !positionAttribute || !modifiedAttribute || !versionAttribute) {
|
|
805
|
-
return annotationConflict(element.start);
|
|
806
|
-
}
|
|
807
|
-
const filepath = staticLiteralAttributeValue(filepathAttribute);
|
|
808
|
-
const positionText = staticLiteralAttributeValue(positionAttribute);
|
|
809
|
-
const modifiedText = staticLiteralAttributeValue(modifiedAttribute);
|
|
810
|
-
const sourceVersion = staticLiteralAttributeValue(versionAttribute);
|
|
811
|
-
const position = Number(positionText);
|
|
812
|
-
const modifiedTs = Number(modifiedText);
|
|
813
|
-
const first = tempo[0];
|
|
814
|
-
const last = tempo[tempo.length - 1];
|
|
815
|
-
if (!first || !last || source[first.start - 1] !== " " || !Number.isSafeInteger(position) || position < 0 || !Number.isSafeInteger(modifiedTs) || modifiedTs < 0 || !filepath || !sourceVersion) {
|
|
816
|
-
return annotationConflict(element.start);
|
|
817
|
-
}
|
|
818
|
-
const expected = serializeAnnotations({
|
|
819
|
-
filepath,
|
|
820
|
-
position,
|
|
821
|
-
modifiedTs,
|
|
822
|
-
sourceVersion
|
|
823
|
-
}).slice(1);
|
|
824
|
-
if (source.slice(first.start, last.end) !== expected) {
|
|
825
|
-
return annotationConflict(element.start);
|
|
826
|
-
}
|
|
827
|
-
return {
|
|
828
|
-
kind: "ok",
|
|
829
|
-
metadata: { filepath, position, modifiedTs, sourceVersion },
|
|
830
|
-
removalEdit: {
|
|
831
|
-
start: first.start - 1,
|
|
832
|
-
end: last.end,
|
|
833
|
-
replacement: ""
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
function annotationConflict(offset) {
|
|
838
|
-
return {
|
|
839
|
-
kind: "refused",
|
|
840
|
-
code: "annotation_conflict",
|
|
841
|
-
message: `element at UTF-16 offset ${offset} has partial, dynamic, reordered, or conflicting Tempo annotations`
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
function isStaticLiteralAttribute(attribute) {
|
|
845
|
-
return Array.isArray(attribute.value) && attribute.value.every((part) => part.type === "Text");
|
|
846
|
-
}
|
|
847
|
-
function staticLiteralAttributeValue(attribute) {
|
|
848
|
-
return Array.isArray(attribute.value) ? attribute.value.map((part) => part.type === "Text" ? part.data : "").join("") : "";
|
|
849
|
-
}
|
|
850
|
-
function serializeAnnotations(metadata) {
|
|
851
|
-
const values = {
|
|
852
|
-
"data-tempo-filepath": metadata.filepath,
|
|
853
|
-
"data-tempo-position": String(metadata.position),
|
|
854
|
-
"data-tempo-modifiedts": String(metadata.modifiedTs),
|
|
855
|
-
"data-tempo-source-version": metadata.sourceVersion
|
|
856
|
-
};
|
|
857
|
-
return Object.entries(values).map(
|
|
858
|
-
([name, value]) => ` ${name}="${escapeSvelteAttributeValue(value, '"')}"`
|
|
859
|
-
).join("");
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
// svelte.ts
|
|
863
|
-
var MODULE_SCRIPT = /<script\b[^>]*\b(?:module\b|context\s*=\s*["']module["'])[^>]*>/;
|
|
864
|
-
function tempoSveltePreprocess(options = {}) {
|
|
865
|
-
const root = resolve(options.root ?? process.cwd());
|
|
866
|
-
const sourceRoot = resolve(options.sourceRoot ?? defaultSourceRoot(root));
|
|
867
|
-
const enabled = options.enabled ?? Boolean(process.env.TEMPO);
|
|
868
|
-
const metadata = ({ filename }) => {
|
|
869
|
-
if (!enabled || !filename) return null;
|
|
870
|
-
const identity = resolveAnnotationIdentity(filename, { root, sourceRoot });
|
|
871
|
-
if (!identity?.absoluteFilename.endsWith(".svelte")) return null;
|
|
872
|
-
return {
|
|
873
|
-
filepath: identity.filepath,
|
|
874
|
-
modifiedTs: readModifiedTs(identity.absoluteFilename)
|
|
875
|
-
};
|
|
876
|
-
};
|
|
877
|
-
const annotation = createSvelteAnnotationPreprocessor({ metadata });
|
|
878
|
-
return {
|
|
879
|
-
name: "svelte-source-annotation",
|
|
880
|
-
// The annotation, plus an empty module script when the file has none:
|
|
881
|
-
// the module version record must run once per module evaluation, which
|
|
882
|
-
// is what a module script's top level does (V2-498).
|
|
883
|
-
markup(input) {
|
|
884
|
-
const result = annotation.markup?.(input);
|
|
885
|
-
if (!result || !("code" in result)) return result;
|
|
886
|
-
if (MODULE_SCRIPT.test(result.code)) return result;
|
|
887
|
-
return {
|
|
888
|
-
...result,
|
|
889
|
-
code: `${result.code}
|
|
890
|
-
<script module></script>
|
|
891
|
-
`
|
|
892
|
-
};
|
|
893
|
-
},
|
|
894
|
-
// The module version record ends the module script, as it ends every
|
|
895
|
-
// annotated JSX module. The file's own bytes name its version, the same
|
|
896
|
-
// raw-source hash the element stamps carry.
|
|
897
|
-
script({ content, attributes, filename }) {
|
|
898
|
-
const moduleScript = attributes.module === true || attributes.context === "module";
|
|
899
|
-
if (!moduleScript) return void 0;
|
|
900
|
-
const identity = metadata({ filename });
|
|
901
|
-
if (!identity || !filename) return void 0;
|
|
902
|
-
const sourceVersion = sourceVersionHash(readFileSync(filename, "utf8"));
|
|
903
|
-
return {
|
|
904
|
-
code: appendModuleVersionRecord(
|
|
905
|
-
content,
|
|
906
|
-
identity.filepath,
|
|
907
|
-
identity.modifiedTs,
|
|
908
|
-
sourceVersion
|
|
909
|
-
)
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
export {
|
|
915
|
-
tempoSveltePreprocess
|
|
916
|
-
};
|
|
917
|
-
//# sourceMappingURL=svelte.js.map
|
|
1
|
+
import{a as o}from"./chunk-QNVQ7U2W.js";import{a as e}from"./chunk-XUSV3KOD.js";var n=e(function(t={}){return t.enabled??!!process.env.TEMPO?o("svelte",t.root).tempoSveltePreprocess(t):{name:"svelte-source-annotation",markup:e(()=>{},"markup"),script:e(()=>{},"script")}},"tempoSveltePreprocess");export{n as tempoSveltePreprocess};
|