tempo-sdk 0.0.15 → 0.0.18
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/dist/canvas/editor.d.ts +164 -0
- package/dist/canvas/editor.js +898 -0
- package/dist/canvas/editor.js.map +1 -0
- package/dist/canvas/index.d.ts +174 -0
- package/dist/canvas/index.js +2301 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/canvas/parser.d.ts +108 -0
- package/dist/canvas/parser.js +11 -0
- package/dist/canvas/parser.js.map +1 -0
- package/dist/chunk-6Q4I3RFN.js +643 -0
- package/dist/chunk-6Q4I3RFN.js.map +1 -0
- package/dist/{chunk-77BNMPBS.js → chunk-CB5NJJJT.js} +31 -5
- package/dist/chunk-CB5NJJJT.js.map +1 -0
- package/dist/expo/plugin.cjs +30 -4
- package/dist/expo/plugin.cjs.map +1 -1
- package/dist/expo/plugin.js +1 -1
- package/dist/expo-babel-plugin.cjs +30 -4
- package/dist/expo-babel-plugin.cjs.map +1 -1
- package/dist/expo-babel-plugin.d.cts +1 -1
- package/dist/expo-babel-plugin.d.ts +1 -1
- package/dist/expo-babel-plugin.js +1 -1
- package/dist/index.d.ts +3 -34
- package/dist/index.js +26 -6
- package/dist/index.js.map +1 -1
- package/dist/nextjs-loader.cjs +29 -4
- package/dist/nextjs-loader.cjs.map +1 -1
- package/dist/page-xi1aI5a7.d.ts +36 -0
- package/package.json +18 -3
- package/dist/annotation-strategy-DCJHc--2.d.cts +0 -13
- package/dist/annotation-strategy-DCJHc--2.d.ts +0 -13
- package/dist/chunk-2LP5G6CD.js +0 -748
- package/dist/chunk-2LP5G6CD.js.map +0 -1
- package/dist/chunk-77BNMPBS.js.map +0 -1
- package/dist/chunk-F64WRL4H.js +0 -884
- package/dist/chunk-F64WRL4H.js.map +0 -1
- package/dist/chunk-G7M57ARC.js +0 -902
- package/dist/chunk-G7M57ARC.js.map +0 -1
- package/dist/chunk-GHPL4LGE.js +0 -205
- package/dist/chunk-GHPL4LGE.js.map +0 -1
- package/dist/chunk-IG3JZVZI.js +0 -846
- package/dist/chunk-IG3JZVZI.js.map +0 -1
- package/dist/chunk-WGGLHHC5.js +0 -337
- package/dist/chunk-WGGLHHC5.js.map +0 -1
- package/dist/chunk-X3K7Z2BH.js +0 -900
- package/dist/chunk-X3K7Z2BH.js.map +0 -1
- package/dist/chunk-ZHORRCQG.js +0 -756
- package/dist/chunk-ZHORRCQG.js.map +0 -1
- package/dist/index.cjs +0 -1170
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -99
package/dist/chunk-ZHORRCQG.js
DELETED
|
@@ -1,756 +0,0 @@
|
|
|
1
|
-
// annotation-strategy.ts
|
|
2
|
-
import { existsSync, realpathSync, statSync } from "fs";
|
|
3
|
-
import { dirname, relative, resolve } from "path";
|
|
4
|
-
|
|
5
|
-
// ../../modules/annotation/has-expression-children.ts
|
|
6
|
-
function hasJsxExpressionChild(element) {
|
|
7
|
-
for (const child of element.children) {
|
|
8
|
-
if (child.type !== "JSXExpressionContainer") continue;
|
|
9
|
-
const expression = child.expression;
|
|
10
|
-
if (!expression || expression.type === "JSXEmptyExpression") continue;
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ../../modules/tempo-dom-id/index.ts
|
|
17
|
-
var FNV_OFFSET_BASIS = 2166136261;
|
|
18
|
-
var FNV_PRIME = 16777619;
|
|
19
|
-
function fnv1a32(value) {
|
|
20
|
-
let hash = FNV_OFFSET_BASIS;
|
|
21
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
22
|
-
hash ^= value.charCodeAt(index);
|
|
23
|
-
hash = Math.imul(hash, FNV_PRIME) >>> 0;
|
|
24
|
-
}
|
|
25
|
-
return hash.toString(36);
|
|
26
|
-
}
|
|
27
|
-
function mint_dom_id(filepath, source_position) {
|
|
28
|
-
return `t-${fnv1a32(
|
|
29
|
-
`${filepath}:${source_position.line}:${source_position.column}:${source_position.offset}`
|
|
30
|
-
)}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// annotation-strategy.ts
|
|
34
|
-
var DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx"];
|
|
35
|
-
var DEFAULT_EXCLUDE = ["**/node_modules/**"];
|
|
36
|
-
var ROOT_META_NAME = "tempo-project-root";
|
|
37
|
-
var IMPORT_RESOLUTION_EXTENSIONS = [
|
|
38
|
-
"",
|
|
39
|
-
".tsx",
|
|
40
|
-
".ts",
|
|
41
|
-
".jsx",
|
|
42
|
-
".js",
|
|
43
|
-
".mjs",
|
|
44
|
-
".cjs",
|
|
45
|
-
".json"
|
|
46
|
-
];
|
|
47
|
-
var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
48
|
-
"area",
|
|
49
|
-
"base",
|
|
50
|
-
"br",
|
|
51
|
-
"col",
|
|
52
|
-
"embed",
|
|
53
|
-
"hr",
|
|
54
|
-
"img",
|
|
55
|
-
"input",
|
|
56
|
-
"link",
|
|
57
|
-
"meta",
|
|
58
|
-
"param",
|
|
59
|
-
"source",
|
|
60
|
-
"track",
|
|
61
|
-
"wbr"
|
|
62
|
-
]);
|
|
63
|
-
function cleanModuleId(id) {
|
|
64
|
-
return id.replace(/[?#].*$/, "");
|
|
65
|
-
}
|
|
66
|
-
function resolveCanonicalRoot(root) {
|
|
67
|
-
try {
|
|
68
|
-
return realpathSync.native(root);
|
|
69
|
-
} catch {
|
|
70
|
-
return root;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function hasRootMetaTag(html) {
|
|
74
|
-
return /<meta[^>]+name=["']tempo-project-root["'][^>]*>/i.test(html);
|
|
75
|
-
}
|
|
76
|
-
function isIntrinsicElement(tagName) {
|
|
77
|
-
return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
|
|
78
|
-
}
|
|
79
|
-
function hasJsxAttribute(info, attrName) {
|
|
80
|
-
for (const attr of info.element.openingElement.attributes) {
|
|
81
|
-
const name = attr.name;
|
|
82
|
-
if (name?.name === attrName) return true;
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
function pathExistsWithCommonExtensions(basePath) {
|
|
87
|
-
for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
|
|
88
|
-
const candidate = `${basePath}${ext}`;
|
|
89
|
-
if (existsSync(candidate)) return true;
|
|
90
|
-
}
|
|
91
|
-
for (const ext of IMPORT_RESOLUTION_EXTENSIONS) {
|
|
92
|
-
const candidate = resolve(basePath, `index${ext}`);
|
|
93
|
-
if (existsSync(candidate)) return true;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
function findMissingRelativeImport(source, importerPath) {
|
|
98
|
-
const importPattern = /(?:import|export)\s+(?:[\s\S]*?\s+from\s+)?["'](\.{1,2}\/[^"']+)["']/g;
|
|
99
|
-
let match;
|
|
100
|
-
while (match = importPattern.exec(source)) {
|
|
101
|
-
const specifier = match[1];
|
|
102
|
-
if (!specifier) continue;
|
|
103
|
-
const resolved = resolve(dirname(importerPath), specifier);
|
|
104
|
-
if (!pathExistsWithCommonExtensions(resolved)) {
|
|
105
|
-
return specifier;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
function getSourcePositionForOffset(source, offset) {
|
|
111
|
-
let line = 1;
|
|
112
|
-
let lineStart = 0;
|
|
113
|
-
for (let index = 0; index < offset; index += 1) {
|
|
114
|
-
if (source.charCodeAt(index) === 10) {
|
|
115
|
-
line += 1;
|
|
116
|
-
lineStart = index + 1;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return { line, column: offset - lineStart, offset };
|
|
120
|
-
}
|
|
121
|
-
function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, source) {
|
|
122
|
-
const offset = info.element.openingElement.start;
|
|
123
|
-
return {
|
|
124
|
-
"data-tempo-filepath": filepath,
|
|
125
|
-
"data-tempo-position": offset,
|
|
126
|
-
"data-tempo-modifiedts": modifiedtsMs,
|
|
127
|
-
"data-dom-id": mint_dom_id(
|
|
128
|
-
filepath,
|
|
129
|
-
getSourcePositionForOffset(source, offset)
|
|
130
|
-
)
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function computeTempoAnnotatedProps(params) {
|
|
134
|
-
const {
|
|
135
|
-
info,
|
|
136
|
-
filepath,
|
|
137
|
-
modifiedtsMs,
|
|
138
|
-
source,
|
|
139
|
-
computeAnnotatedProps,
|
|
140
|
-
typeInfo,
|
|
141
|
-
elementSupportOverrides
|
|
142
|
-
} = params;
|
|
143
|
-
const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs, source);
|
|
144
|
-
const dynamicChildrenProp = hasJsxExpressionChild(info.element) ? { "data-tempo-dynamic-children": true } : {};
|
|
145
|
-
if (isIntrinsicElement(info.tagName)) {
|
|
146
|
-
return {
|
|
147
|
-
...userProps,
|
|
148
|
-
...dynamicChildrenProp,
|
|
149
|
-
"data-tempo-supports-children": hasJsxAttribute(
|
|
150
|
-
info,
|
|
151
|
-
"data-tempo-supports-children"
|
|
152
|
-
) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
const override = elementSupportOverrides?.get(info.tagName);
|
|
156
|
-
if (override) {
|
|
157
|
-
return {
|
|
158
|
-
...userProps,
|
|
159
|
-
...dynamicChildrenProp,
|
|
160
|
-
"data-tempo-supports-style": override.supportsStyle,
|
|
161
|
-
"data-tempo-supports-classname": override.supportsClassName,
|
|
162
|
-
"data-tempo-supports-children": hasJsxAttribute(
|
|
163
|
-
info,
|
|
164
|
-
"data-tempo-supports-children"
|
|
165
|
-
) ? void 0 : override.supportsChildren
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
const support = typeInfo?.get(info.element.openingElement.start);
|
|
169
|
-
return {
|
|
170
|
-
...userProps,
|
|
171
|
-
...dynamicChildrenProp,
|
|
172
|
-
"data-tempo-supports-style": support?.supportsStyle ?? false,
|
|
173
|
-
"data-tempo-supports-classname": support?.supportsClassName ?? false,
|
|
174
|
-
"data-tempo-supports-children": hasJsxAttribute(
|
|
175
|
-
info,
|
|
176
|
-
"data-tempo-supports-children"
|
|
177
|
-
) ? void 0 : support?.supportsChildren ?? false
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
function getFileAnnotationContext(params) {
|
|
181
|
-
const rawCleanFilename = cleanModuleId(params.filename);
|
|
182
|
-
let cleanFilename = rawCleanFilename;
|
|
183
|
-
if (params.canonicalizeFilename) {
|
|
184
|
-
try {
|
|
185
|
-
cleanFilename = realpathSync.native(rawCleanFilename);
|
|
186
|
-
} catch {
|
|
187
|
-
cleanFilename = rawCleanFilename;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
cleanFilename,
|
|
192
|
-
filepath: relative(params.root, cleanFilename),
|
|
193
|
-
modifiedtsMs: Math.trunc(statSync(cleanFilename).mtimeMs)
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// type-analyzer.ts
|
|
198
|
-
import ts2 from "typescript";
|
|
199
|
-
import path2 from "path";
|
|
200
|
-
import { realpathSync as realpathSync3 } from "fs";
|
|
201
|
-
|
|
202
|
-
// ../../modules/typescript/workspace-service.ts
|
|
203
|
-
import { realpathSync as realpathSync2, statSync as statSync2 } from "fs";
|
|
204
|
-
import path from "path";
|
|
205
|
-
import ts from "typescript";
|
|
206
|
-
function canonicalPath(input) {
|
|
207
|
-
const resolved = path.resolve(input);
|
|
208
|
-
try {
|
|
209
|
-
return realpathSync2.native(resolved);
|
|
210
|
-
} catch {
|
|
211
|
-
return resolved;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function compareProjectPriority(left, right) {
|
|
215
|
-
const depthDelta = right.rootDir.length - left.rootDir.length;
|
|
216
|
-
if (depthDelta !== 0) {
|
|
217
|
-
return depthDelta;
|
|
218
|
-
}
|
|
219
|
-
const priorityDelta = right.priority - left.priority;
|
|
220
|
-
if (priorityDelta !== 0) {
|
|
221
|
-
return priorityDelta;
|
|
222
|
-
}
|
|
223
|
-
return left.id.localeCompare(right.id);
|
|
224
|
-
}
|
|
225
|
-
function isWithinRoot(filePath, rootDir) {
|
|
226
|
-
return filePath === rootDir || filePath.startsWith(`${rootDir}${path.sep}`);
|
|
227
|
-
}
|
|
228
|
-
function loadProject(descriptor) {
|
|
229
|
-
const id = descriptor.id.trim();
|
|
230
|
-
if (!id) {
|
|
231
|
-
throw new Error("Project id must be a non-empty string");
|
|
232
|
-
}
|
|
233
|
-
const tsconfigPath = canonicalPath(descriptor.tsconfigPath);
|
|
234
|
-
const rootDir = canonicalPath(descriptor.rootDir);
|
|
235
|
-
const readResult = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
236
|
-
if (readResult.error) {
|
|
237
|
-
throw new Error(
|
|
238
|
-
`Failed to read tsconfig at ${tsconfigPath}: ${ts.flattenDiagnosticMessageText(
|
|
239
|
-
readResult.error.messageText,
|
|
240
|
-
"\n"
|
|
241
|
-
)}`
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
const parsed = ts.parseJsonConfigFileContent(
|
|
245
|
-
readResult.config,
|
|
246
|
-
ts.sys,
|
|
247
|
-
path.dirname(tsconfigPath)
|
|
248
|
-
);
|
|
249
|
-
if (parsed.errors.length > 0) {
|
|
250
|
-
const message = parsed.errors.map(
|
|
251
|
-
(diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
|
|
252
|
-
).join("; ");
|
|
253
|
-
throw new Error(`Failed to parse tsconfig at ${tsconfigPath}: ${message}`);
|
|
254
|
-
}
|
|
255
|
-
const normalizedFiles = parsed.fileNames.map(
|
|
256
|
-
(fileName) => canonicalPath(fileName)
|
|
257
|
-
);
|
|
258
|
-
return {
|
|
259
|
-
id,
|
|
260
|
-
rootDir,
|
|
261
|
-
tsconfigPath,
|
|
262
|
-
priority: descriptor.priority ?? 0,
|
|
263
|
-
options: parsed.options,
|
|
264
|
-
fileNames: normalizedFiles,
|
|
265
|
-
moduleResolutionCache: ts.createModuleResolutionCache(
|
|
266
|
-
rootDir,
|
|
267
|
-
(value) => value,
|
|
268
|
-
parsed.options
|
|
269
|
-
)
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
function getFileMtimeVersion(filePath) {
|
|
273
|
-
try {
|
|
274
|
-
const stats = statSync2(filePath);
|
|
275
|
-
return String(stats.mtimeMs);
|
|
276
|
-
} catch {
|
|
277
|
-
return "0";
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
function createTsWorkspaceService(descriptor) {
|
|
281
|
-
if (descriptor.projects.length === 0) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
"TsWorkspaceDescriptor.projects must include at least one project"
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
const workspaceRoot = canonicalPath(descriptor.workspaceRoot);
|
|
287
|
-
const loadedProjects = descriptor.projects.map(
|
|
288
|
-
(project) => loadProject(project)
|
|
289
|
-
);
|
|
290
|
-
const projectsById = /* @__PURE__ */ new Map();
|
|
291
|
-
for (const project of loadedProjects) {
|
|
292
|
-
if (projectsById.has(project.id)) {
|
|
293
|
-
throw new Error(`Duplicate project id: ${project.id}`);
|
|
294
|
-
}
|
|
295
|
-
projectsById.set(project.id, project);
|
|
296
|
-
}
|
|
297
|
-
const primaryProject = (descriptor.primaryProjectId ? projectsById.get(descriptor.primaryProjectId) : null) ?? loadedProjects[0];
|
|
298
|
-
if (descriptor.primaryProjectId && !projectsById.has(descriptor.primaryProjectId)) {
|
|
299
|
-
throw new Error(
|
|
300
|
-
`Primary project id not found: ${descriptor.primaryProjectId}`
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
const orderedProjects = [...loadedProjects].sort(compareProjectPriority);
|
|
304
|
-
const rootFileNames = /* @__PURE__ */ new Set();
|
|
305
|
-
for (const project of loadedProjects) {
|
|
306
|
-
for (const fileName of project.fileNames) {
|
|
307
|
-
rootFileNames.add(fileName);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
const inMemoryFiles = /* @__PURE__ */ new Map();
|
|
311
|
-
let projectVersion = 0;
|
|
312
|
-
function getOwningProject(filePath) {
|
|
313
|
-
const canonicalFilePath = canonicalPath(filePath);
|
|
314
|
-
for (const project of orderedProjects) {
|
|
315
|
-
if (isWithinRoot(canonicalFilePath, project.rootDir)) {
|
|
316
|
-
return project;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return primaryProject;
|
|
320
|
-
}
|
|
321
|
-
const moduleResolutionHost = {
|
|
322
|
-
fileExists: ts.sys.fileExists,
|
|
323
|
-
readFile: ts.sys.readFile,
|
|
324
|
-
realpath: ts.sys.realpath,
|
|
325
|
-
directoryExists: ts.sys.directoryExists,
|
|
326
|
-
getCurrentDirectory: () => workspaceRoot,
|
|
327
|
-
getDirectories: ts.sys.getDirectories
|
|
328
|
-
};
|
|
329
|
-
const host = {
|
|
330
|
-
getScriptFileNames: () => Array.from(rootFileNames),
|
|
331
|
-
getScriptVersion: (filePath) => {
|
|
332
|
-
const canonicalFilePath = canonicalPath(filePath);
|
|
333
|
-
const inMemory = inMemoryFiles.get(canonicalFilePath);
|
|
334
|
-
if (inMemory) {
|
|
335
|
-
return String(inMemory.version);
|
|
336
|
-
}
|
|
337
|
-
return getFileMtimeVersion(canonicalFilePath);
|
|
338
|
-
},
|
|
339
|
-
getScriptSnapshot: (filePath) => {
|
|
340
|
-
const canonicalFilePath = canonicalPath(filePath);
|
|
341
|
-
const inMemory = inMemoryFiles.get(canonicalFilePath);
|
|
342
|
-
if (inMemory) {
|
|
343
|
-
return ts.ScriptSnapshot.fromString(inMemory.content);
|
|
344
|
-
}
|
|
345
|
-
const diskContent = ts.sys.readFile(canonicalFilePath);
|
|
346
|
-
if (diskContent === void 0) {
|
|
347
|
-
return void 0;
|
|
348
|
-
}
|
|
349
|
-
return ts.ScriptSnapshot.fromString(diskContent);
|
|
350
|
-
},
|
|
351
|
-
getCurrentDirectory: () => workspaceRoot,
|
|
352
|
-
getCompilationSettings: () => primaryProject.options,
|
|
353
|
-
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
354
|
-
fileExists: ts.sys.fileExists,
|
|
355
|
-
readFile: ts.sys.readFile,
|
|
356
|
-
readDirectory: ts.sys.readDirectory,
|
|
357
|
-
directoryExists: ts.sys.directoryExists,
|
|
358
|
-
getDirectories: ts.sys.getDirectories,
|
|
359
|
-
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
|
360
|
-
getProjectVersion: () => String(projectVersion),
|
|
361
|
-
resolveModuleNames: (moduleNames, containingFile) => {
|
|
362
|
-
const owningProject = getOwningProject(containingFile);
|
|
363
|
-
return moduleNames.map((moduleName) => {
|
|
364
|
-
const ownerResolution = ts.resolveModuleName(
|
|
365
|
-
moduleName,
|
|
366
|
-
containingFile,
|
|
367
|
-
owningProject.options,
|
|
368
|
-
moduleResolutionHost,
|
|
369
|
-
owningProject.moduleResolutionCache
|
|
370
|
-
).resolvedModule;
|
|
371
|
-
if (ownerResolution) {
|
|
372
|
-
return ownerResolution;
|
|
373
|
-
}
|
|
374
|
-
if (owningProject.id === primaryProject.id) {
|
|
375
|
-
return void 0;
|
|
376
|
-
}
|
|
377
|
-
return ts.resolveModuleName(
|
|
378
|
-
moduleName,
|
|
379
|
-
containingFile,
|
|
380
|
-
primaryProject.options,
|
|
381
|
-
moduleResolutionHost,
|
|
382
|
-
primaryProject.moduleResolutionCache
|
|
383
|
-
).resolvedModule;
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
const languageService = ts.createLanguageService(
|
|
388
|
-
host,
|
|
389
|
-
ts.createDocumentRegistry()
|
|
390
|
-
);
|
|
391
|
-
return {
|
|
392
|
-
updateFile(filePath, content) {
|
|
393
|
-
const canonicalFilePath = canonicalPath(filePath);
|
|
394
|
-
const currentVersion = inMemoryFiles.get(canonicalFilePath)?.version ?? 0;
|
|
395
|
-
inMemoryFiles.set(canonicalFilePath, {
|
|
396
|
-
version: currentVersion + 1,
|
|
397
|
-
content
|
|
398
|
-
});
|
|
399
|
-
if (!rootFileNames.has(canonicalFilePath)) {
|
|
400
|
-
rootFileNames.add(canonicalFilePath);
|
|
401
|
-
}
|
|
402
|
-
projectVersion += 1;
|
|
403
|
-
},
|
|
404
|
-
closeFile(filePath) {
|
|
405
|
-
const canonicalFilePath = canonicalPath(filePath);
|
|
406
|
-
inMemoryFiles.delete(canonicalFilePath);
|
|
407
|
-
projectVersion += 1;
|
|
408
|
-
},
|
|
409
|
-
getProgram() {
|
|
410
|
-
return languageService.getProgram() ?? null;
|
|
411
|
-
},
|
|
412
|
-
getSemanticDiagnostics(filePath) {
|
|
413
|
-
const canonicalFilePath = canonicalPath(filePath);
|
|
414
|
-
return languageService.getSemanticDiagnostics(canonicalFilePath);
|
|
415
|
-
},
|
|
416
|
-
getDefinition(filePath, position) {
|
|
417
|
-
const canonicalFilePath = canonicalPath(filePath);
|
|
418
|
-
return languageService.getDefinitionAtPosition(
|
|
419
|
-
canonicalFilePath,
|
|
420
|
-
position
|
|
421
|
-
);
|
|
422
|
-
},
|
|
423
|
-
dispose() {
|
|
424
|
-
languageService.dispose();
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// type-analyzer.ts
|
|
430
|
-
function isCustomComponent(node) {
|
|
431
|
-
const text = node.getText();
|
|
432
|
-
return text.length > 0 && text[0] !== text[0].toLowerCase();
|
|
433
|
-
}
|
|
434
|
-
function canonicalPath2(value) {
|
|
435
|
-
const resolved = path2.resolve(value);
|
|
436
|
-
try {
|
|
437
|
-
return realpathSync3.native(resolved);
|
|
438
|
-
} catch {
|
|
439
|
-
return resolved;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
function parseManagedTsconfigPaths(rawConfig) {
|
|
443
|
-
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
444
|
-
return [];
|
|
445
|
-
}
|
|
446
|
-
const metadata = rawConfig.tempobook;
|
|
447
|
-
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
448
|
-
return [];
|
|
449
|
-
}
|
|
450
|
-
const managedPaths = metadata.managedTsconfigPaths;
|
|
451
|
-
if (!Array.isArray(managedPaths)) {
|
|
452
|
-
return [];
|
|
453
|
-
}
|
|
454
|
-
return managedPaths.filter(
|
|
455
|
-
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
function parseProjectReferenceTsconfigPaths(references, configDir) {
|
|
459
|
-
if (!references || references.length === 0) {
|
|
460
|
-
return [];
|
|
461
|
-
}
|
|
462
|
-
const entries = [];
|
|
463
|
-
for (const reference of references) {
|
|
464
|
-
const referencePath = reference.path;
|
|
465
|
-
if (!referencePath) {
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
const resolvedPath = path2.resolve(configDir, referencePath);
|
|
469
|
-
const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : path2.join(resolvedPath, "tsconfig.json");
|
|
470
|
-
entries.push(tsconfigPath);
|
|
471
|
-
}
|
|
472
|
-
return entries;
|
|
473
|
-
}
|
|
474
|
-
function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
|
|
475
|
-
const configDir = path2.dirname(configPath);
|
|
476
|
-
const projects = [
|
|
477
|
-
{
|
|
478
|
-
id: "root",
|
|
479
|
-
rootDir: root,
|
|
480
|
-
tsconfigPath: configPath,
|
|
481
|
-
priority: 0
|
|
482
|
-
}
|
|
483
|
-
];
|
|
484
|
-
const seenTsconfigPaths = /* @__PURE__ */ new Set([canonicalPath2(configPath)]);
|
|
485
|
-
const referencedTsconfigPaths = parseProjectReferenceTsconfigPaths(
|
|
486
|
-
parsedConfig.projectReferences,
|
|
487
|
-
configDir
|
|
488
|
-
);
|
|
489
|
-
const managedTsconfigPaths = parseManagedTsconfigPaths(rawConfig).map(
|
|
490
|
-
(entry) => path2.resolve(configDir, entry)
|
|
491
|
-
);
|
|
492
|
-
const candidateTsconfigPaths = [
|
|
493
|
-
...managedTsconfigPaths,
|
|
494
|
-
...referencedTsconfigPaths
|
|
495
|
-
];
|
|
496
|
-
for (const candidatePath of candidateTsconfigPaths) {
|
|
497
|
-
const normalizedPath = canonicalPath2(candidatePath);
|
|
498
|
-
if (seenTsconfigPaths.has(normalizedPath)) {
|
|
499
|
-
continue;
|
|
500
|
-
}
|
|
501
|
-
if (!ts2.sys.fileExists(normalizedPath)) {
|
|
502
|
-
continue;
|
|
503
|
-
}
|
|
504
|
-
seenTsconfigPaths.add(normalizedPath);
|
|
505
|
-
projects.push({
|
|
506
|
-
id: `external-${projects.length}`,
|
|
507
|
-
rootDir: path2.dirname(normalizedPath),
|
|
508
|
-
tsconfigPath: normalizedPath,
|
|
509
|
-
priority: 0
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
return projects;
|
|
513
|
-
}
|
|
514
|
-
function createTypeAnalyzer(root) {
|
|
515
|
-
const configPath = ts2.findConfigFile(
|
|
516
|
-
root,
|
|
517
|
-
ts2.sys.fileExists,
|
|
518
|
-
"tsconfig.json"
|
|
519
|
-
);
|
|
520
|
-
if (!configPath) return null;
|
|
521
|
-
const configFile = ts2.readConfigFile(configPath, ts2.sys.readFile);
|
|
522
|
-
if (configFile.error) return null;
|
|
523
|
-
const parsedConfig = ts2.parseJsonConfigFileContent(
|
|
524
|
-
configFile.config,
|
|
525
|
-
ts2.sys,
|
|
526
|
-
root
|
|
527
|
-
);
|
|
528
|
-
const workspaceProjects = buildWorkspaceProjects(
|
|
529
|
-
root,
|
|
530
|
-
configPath,
|
|
531
|
-
parsedConfig,
|
|
532
|
-
configFile.config
|
|
533
|
-
);
|
|
534
|
-
const workspaceProjectRoots = workspaceProjects.map(
|
|
535
|
-
(project) => canonicalPath2(project.rootDir)
|
|
536
|
-
);
|
|
537
|
-
const workspaceService = createTsWorkspaceService({
|
|
538
|
-
workspaceRoot: root,
|
|
539
|
-
primaryProjectId: "root",
|
|
540
|
-
projects: workspaceProjects
|
|
541
|
-
});
|
|
542
|
-
let cssPropertiesType;
|
|
543
|
-
function resolveCSSPropertiesType(checker, sourceFile) {
|
|
544
|
-
if (cssPropertiesType !== void 0) return cssPropertiesType;
|
|
545
|
-
try {
|
|
546
|
-
let jsxNs = checker.resolveName(
|
|
547
|
-
"JSX",
|
|
548
|
-
sourceFile,
|
|
549
|
-
ts2.SymbolFlags.Namespace,
|
|
550
|
-
false
|
|
551
|
-
);
|
|
552
|
-
if (!jsxNs) {
|
|
553
|
-
const program = workspaceService.getProgram();
|
|
554
|
-
const compilerOptions = program?.getCompilerOptions();
|
|
555
|
-
const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
|
|
556
|
-
const resolved = ts2.resolveModuleName(
|
|
557
|
-
`${jsxImportSource}/jsx-runtime`,
|
|
558
|
-
sourceFile.fileName,
|
|
559
|
-
compilerOptions,
|
|
560
|
-
ts2.sys
|
|
561
|
-
);
|
|
562
|
-
if (resolved.resolvedModule) {
|
|
563
|
-
const runtimeFile = program?.getSourceFile(
|
|
564
|
-
resolved.resolvedModule.resolvedFileName
|
|
565
|
-
);
|
|
566
|
-
if (runtimeFile) {
|
|
567
|
-
const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
|
|
568
|
-
if (runtimeSymbol) {
|
|
569
|
-
const exports = checker.getExportsOfModule(runtimeSymbol);
|
|
570
|
-
jsxNs = exports.find((s) => s.name === "JSX");
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
if (!jsxNs) {
|
|
576
|
-
cssPropertiesType = null;
|
|
577
|
-
return null;
|
|
578
|
-
}
|
|
579
|
-
const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
|
|
580
|
-
if (!intrinsicSym) {
|
|
581
|
-
cssPropertiesType = null;
|
|
582
|
-
return null;
|
|
583
|
-
}
|
|
584
|
-
const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
|
|
585
|
-
if (!divSym) {
|
|
586
|
-
cssPropertiesType = null;
|
|
587
|
-
return null;
|
|
588
|
-
}
|
|
589
|
-
const styleSym = checker.getTypeOfSymbol(divSym).getProperty("style");
|
|
590
|
-
if (!styleSym) {
|
|
591
|
-
cssPropertiesType = null;
|
|
592
|
-
return null;
|
|
593
|
-
}
|
|
594
|
-
const styleType = checker.getTypeOfSymbol(styleSym);
|
|
595
|
-
if (styleType.isUnion()) {
|
|
596
|
-
const nonUndefined = styleType.types.find(
|
|
597
|
-
(t) => !(t.flags & ts2.TypeFlags.Undefined)
|
|
598
|
-
);
|
|
599
|
-
cssPropertiesType = nonUndefined ?? null;
|
|
600
|
-
} else {
|
|
601
|
-
cssPropertiesType = styleType;
|
|
602
|
-
}
|
|
603
|
-
} catch {
|
|
604
|
-
cssPropertiesType = null;
|
|
605
|
-
}
|
|
606
|
-
return cssPropertiesType;
|
|
607
|
-
}
|
|
608
|
-
let reactNodeType;
|
|
609
|
-
function resolveReactNodeType(checker, sourceFile) {
|
|
610
|
-
if (reactNodeType !== void 0) return reactNodeType;
|
|
611
|
-
try {
|
|
612
|
-
let jsxNs = checker.resolveName(
|
|
613
|
-
"JSX",
|
|
614
|
-
sourceFile,
|
|
615
|
-
ts2.SymbolFlags.Namespace,
|
|
616
|
-
false
|
|
617
|
-
);
|
|
618
|
-
if (!jsxNs) {
|
|
619
|
-
const program = workspaceService.getProgram();
|
|
620
|
-
const compilerOptions = program?.getCompilerOptions();
|
|
621
|
-
const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
|
|
622
|
-
const resolved = ts2.resolveModuleName(
|
|
623
|
-
`${jsxImportSource}/jsx-runtime`,
|
|
624
|
-
sourceFile.fileName,
|
|
625
|
-
compilerOptions,
|
|
626
|
-
ts2.sys
|
|
627
|
-
);
|
|
628
|
-
if (resolved.resolvedModule) {
|
|
629
|
-
const runtimeFile = program?.getSourceFile(
|
|
630
|
-
resolved.resolvedModule.resolvedFileName
|
|
631
|
-
);
|
|
632
|
-
if (runtimeFile) {
|
|
633
|
-
const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
|
|
634
|
-
if (runtimeSymbol) {
|
|
635
|
-
const exports = checker.getExportsOfModule(runtimeSymbol);
|
|
636
|
-
jsxNs = exports.find((s) => s.name === "JSX");
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
if (!jsxNs) {
|
|
642
|
-
reactNodeType = null;
|
|
643
|
-
return null;
|
|
644
|
-
}
|
|
645
|
-
const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
|
|
646
|
-
if (!intrinsicSym) {
|
|
647
|
-
reactNodeType = null;
|
|
648
|
-
return null;
|
|
649
|
-
}
|
|
650
|
-
const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
|
|
651
|
-
if (!divSym) {
|
|
652
|
-
reactNodeType = null;
|
|
653
|
-
return null;
|
|
654
|
-
}
|
|
655
|
-
const childrenSym = checker.getTypeOfSymbol(divSym).getProperty("children");
|
|
656
|
-
if (!childrenSym) {
|
|
657
|
-
reactNodeType = null;
|
|
658
|
-
return null;
|
|
659
|
-
}
|
|
660
|
-
const childrenType = checker.getTypeOfSymbol(childrenSym);
|
|
661
|
-
if (childrenType.isUnion()) {
|
|
662
|
-
const nonUndefined = childrenType.types.find(
|
|
663
|
-
(t) => !(t.flags & ts2.TypeFlags.Undefined)
|
|
664
|
-
);
|
|
665
|
-
reactNodeType = nonUndefined ?? null;
|
|
666
|
-
} else {
|
|
667
|
-
reactNodeType = childrenType;
|
|
668
|
-
}
|
|
669
|
-
} catch {
|
|
670
|
-
reactNodeType = null;
|
|
671
|
-
}
|
|
672
|
-
return reactNodeType;
|
|
673
|
-
}
|
|
674
|
-
return {
|
|
675
|
-
analyzeFileTypes(filePath, source) {
|
|
676
|
-
const canonicalFilePath = canonicalPath2(filePath);
|
|
677
|
-
const belongsToWorkspace = workspaceProjectRoots.some(
|
|
678
|
-
(projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${path2.sep}`)
|
|
679
|
-
);
|
|
680
|
-
if (!belongsToWorkspace) {
|
|
681
|
-
return null;
|
|
682
|
-
}
|
|
683
|
-
workspaceService.updateFile(filePath, source);
|
|
684
|
-
const program = workspaceService.getProgram();
|
|
685
|
-
if (!program) return null;
|
|
686
|
-
const sourceFile = program.getSourceFile(filePath);
|
|
687
|
-
if (!sourceFile) return null;
|
|
688
|
-
const checker = program.getTypeChecker();
|
|
689
|
-
const cssProps = resolveCSSPropertiesType(checker, sourceFile);
|
|
690
|
-
const result = /* @__PURE__ */ new Map();
|
|
691
|
-
function visit(node) {
|
|
692
|
-
if ((ts2.isJsxOpeningElement(node) || ts2.isJsxSelfClosingElement(node)) && isCustomComponent(node.tagName)) {
|
|
693
|
-
const position = node.getStart(sourceFile);
|
|
694
|
-
const attrsType = checker.getContextualType(node.attributes);
|
|
695
|
-
let supportsStyle = false;
|
|
696
|
-
let supportsClassName = false;
|
|
697
|
-
let supportsChildren = false;
|
|
698
|
-
if (attrsType) {
|
|
699
|
-
const classNameProp = attrsType.getProperty("className");
|
|
700
|
-
if (classNameProp) {
|
|
701
|
-
const propType = checker.getTypeOfSymbol(classNameProp);
|
|
702
|
-
supportsClassName = checker.isTypeAssignableTo(
|
|
703
|
-
checker.getStringType(),
|
|
704
|
-
propType
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
const styleProp = attrsType.getProperty("style");
|
|
708
|
-
if (styleProp && cssProps) {
|
|
709
|
-
let propType = checker.getTypeOfSymbol(styleProp);
|
|
710
|
-
if (propType.isUnion()) {
|
|
711
|
-
const nonUndefined = propType.types.find(
|
|
712
|
-
(t) => !(t.flags & ts2.TypeFlags.Undefined)
|
|
713
|
-
);
|
|
714
|
-
if (nonUndefined) propType = nonUndefined;
|
|
715
|
-
}
|
|
716
|
-
supportsStyle = checker.isTypeAssignableTo(cssProps, propType);
|
|
717
|
-
}
|
|
718
|
-
const reactNode = resolveReactNodeType(checker, sourceFile);
|
|
719
|
-
const childrenProp = attrsType.getProperty("children");
|
|
720
|
-
if (childrenProp && reactNode) {
|
|
721
|
-
let propType = checker.getTypeOfSymbol(childrenProp);
|
|
722
|
-
if (propType.isUnion()) {
|
|
723
|
-
const nonUndefined = propType.types.find(
|
|
724
|
-
(t) => !(t.flags & ts2.TypeFlags.Undefined)
|
|
725
|
-
);
|
|
726
|
-
if (nonUndefined) propType = nonUndefined;
|
|
727
|
-
}
|
|
728
|
-
supportsChildren = checker.isTypeAssignableTo(
|
|
729
|
-
reactNode,
|
|
730
|
-
propType
|
|
731
|
-
);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
result.set(position, { supportsStyle, supportsClassName, supportsChildren });
|
|
735
|
-
}
|
|
736
|
-
ts2.forEachChild(node, visit);
|
|
737
|
-
}
|
|
738
|
-
visit(sourceFile);
|
|
739
|
-
return result;
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
export {
|
|
745
|
-
DEFAULT_INCLUDE,
|
|
746
|
-
DEFAULT_EXCLUDE,
|
|
747
|
-
ROOT_META_NAME,
|
|
748
|
-
cleanModuleId,
|
|
749
|
-
resolveCanonicalRoot,
|
|
750
|
-
hasRootMetaTag,
|
|
751
|
-
findMissingRelativeImport,
|
|
752
|
-
computeTempoAnnotatedProps,
|
|
753
|
-
getFileAnnotationContext,
|
|
754
|
-
createTypeAnalyzer
|
|
755
|
-
};
|
|
756
|
-
//# sourceMappingURL=chunk-ZHORRCQG.js.map
|