tempo-sdk 0.0.12 → 0.0.13
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/chunk-G7M57ARC.js +902 -0
- package/dist/chunk-G7M57ARC.js.map +1 -0
- package/dist/expo/plugin.cjs +586 -11
- package/dist/expo/plugin.cjs.map +1 -1
- package/dist/expo/plugin.js +1 -1
- package/dist/expo-babel-plugin.cjs +586 -11
- package/dist/expo-babel-plugin.cjs.map +1 -1
- package/dist/expo-babel-plugin.d.cts +6 -0
- package/dist/expo-babel-plugin.d.ts +6 -0
- package/dist/expo-babel-plugin.js +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +569 -5
- package/dist/index.js.map +1 -1
- package/dist/nextjs-loader.cjs +586 -15
- package/dist/nextjs-loader.cjs.map +1 -1
- package/package.json +3 -1
package/dist/expo/plugin.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// expo/plugin.ts
|
|
@@ -26,8 +36,8 @@ __export(plugin_exports, {
|
|
|
26
36
|
module.exports = __toCommonJS(plugin_exports);
|
|
27
37
|
|
|
28
38
|
// expo-babel-plugin.ts
|
|
29
|
-
var
|
|
30
|
-
var
|
|
39
|
+
var import_node_fs4 = require("fs");
|
|
40
|
+
var import_node_path4 = require("path");
|
|
31
41
|
var import_pluginutils = require("@rollup/pluginutils");
|
|
32
42
|
|
|
33
43
|
// annotation-strategy.ts
|
|
@@ -83,6 +93,7 @@ function computeTempoAnnotatedProps(params) {
|
|
|
83
93
|
filepath,
|
|
84
94
|
modifiedtsMs,
|
|
85
95
|
computeAnnotatedProps,
|
|
96
|
+
typeInfo,
|
|
86
97
|
elementSupportOverrides
|
|
87
98
|
} = params;
|
|
88
99
|
const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);
|
|
@@ -107,7 +118,16 @@ function computeTempoAnnotatedProps(params) {
|
|
|
107
118
|
) ? void 0 : override.supportsChildren
|
|
108
119
|
};
|
|
109
120
|
}
|
|
110
|
-
|
|
121
|
+
const support = typeInfo?.get(info.element.openingElement.start);
|
|
122
|
+
return {
|
|
123
|
+
...userProps,
|
|
124
|
+
"data-tempo-supports-style": support?.supportsStyle ?? false,
|
|
125
|
+
"data-tempo-supports-classname": support?.supportsClassName ?? false,
|
|
126
|
+
"data-tempo-supports-children": hasJsxAttribute(
|
|
127
|
+
info,
|
|
128
|
+
"data-tempo-supports-children"
|
|
129
|
+
) ? void 0 : support?.supportsChildren ?? false
|
|
130
|
+
};
|
|
111
131
|
}
|
|
112
132
|
function getFileAnnotationContext(params) {
|
|
113
133
|
const rawCleanFilename = cleanModuleId(params.filename);
|
|
@@ -126,6 +146,553 @@ function getFileAnnotationContext(params) {
|
|
|
126
146
|
};
|
|
127
147
|
}
|
|
128
148
|
|
|
149
|
+
// type-analyzer.ts
|
|
150
|
+
var import_typescript2 = __toESM(require("typescript"), 1);
|
|
151
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
152
|
+
var import_node_fs3 = require("fs");
|
|
153
|
+
|
|
154
|
+
// ../../modules/typescript/workspace-service.ts
|
|
155
|
+
var import_node_fs2 = require("fs");
|
|
156
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
157
|
+
var import_typescript = __toESM(require("typescript"), 1);
|
|
158
|
+
function canonicalPath(input) {
|
|
159
|
+
const resolved = import_node_path2.default.resolve(input);
|
|
160
|
+
try {
|
|
161
|
+
return import_node_fs2.realpathSync.native(resolved);
|
|
162
|
+
} catch {
|
|
163
|
+
return resolved;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function compareProjectPriority(left, right) {
|
|
167
|
+
const depthDelta = right.rootDir.length - left.rootDir.length;
|
|
168
|
+
if (depthDelta !== 0) {
|
|
169
|
+
return depthDelta;
|
|
170
|
+
}
|
|
171
|
+
const priorityDelta = right.priority - left.priority;
|
|
172
|
+
if (priorityDelta !== 0) {
|
|
173
|
+
return priorityDelta;
|
|
174
|
+
}
|
|
175
|
+
return left.id.localeCompare(right.id);
|
|
176
|
+
}
|
|
177
|
+
function isWithinRoot(filePath, rootDir) {
|
|
178
|
+
return filePath === rootDir || filePath.startsWith(`${rootDir}${import_node_path2.default.sep}`);
|
|
179
|
+
}
|
|
180
|
+
function loadProject(descriptor) {
|
|
181
|
+
const id = descriptor.id.trim();
|
|
182
|
+
if (!id) {
|
|
183
|
+
throw new Error("Project id must be a non-empty string");
|
|
184
|
+
}
|
|
185
|
+
const tsconfigPath = canonicalPath(descriptor.tsconfigPath);
|
|
186
|
+
const rootDir = canonicalPath(descriptor.rootDir);
|
|
187
|
+
const readResult = import_typescript.default.readConfigFile(tsconfigPath, import_typescript.default.sys.readFile);
|
|
188
|
+
if (readResult.error) {
|
|
189
|
+
throw new Error(
|
|
190
|
+
`Failed to read tsconfig at ${tsconfigPath}: ${import_typescript.default.flattenDiagnosticMessageText(
|
|
191
|
+
readResult.error.messageText,
|
|
192
|
+
"\n"
|
|
193
|
+
)}`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
const parsed = import_typescript.default.parseJsonConfigFileContent(
|
|
197
|
+
readResult.config,
|
|
198
|
+
import_typescript.default.sys,
|
|
199
|
+
import_node_path2.default.dirname(tsconfigPath)
|
|
200
|
+
);
|
|
201
|
+
if (parsed.errors.length > 0) {
|
|
202
|
+
const message = parsed.errors.map(
|
|
203
|
+
(diagnostic) => import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
|
|
204
|
+
).join("; ");
|
|
205
|
+
throw new Error(`Failed to parse tsconfig at ${tsconfigPath}: ${message}`);
|
|
206
|
+
}
|
|
207
|
+
const normalizedFiles = parsed.fileNames.map(
|
|
208
|
+
(fileName) => canonicalPath(fileName)
|
|
209
|
+
);
|
|
210
|
+
return {
|
|
211
|
+
id,
|
|
212
|
+
rootDir,
|
|
213
|
+
tsconfigPath,
|
|
214
|
+
priority: descriptor.priority ?? 0,
|
|
215
|
+
options: parsed.options,
|
|
216
|
+
fileNames: normalizedFiles,
|
|
217
|
+
moduleResolutionCache: import_typescript.default.createModuleResolutionCache(
|
|
218
|
+
rootDir,
|
|
219
|
+
(value) => value,
|
|
220
|
+
parsed.options
|
|
221
|
+
)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function getFileMtimeVersion(filePath) {
|
|
225
|
+
try {
|
|
226
|
+
const stats = (0, import_node_fs2.statSync)(filePath);
|
|
227
|
+
return String(stats.mtimeMs);
|
|
228
|
+
} catch {
|
|
229
|
+
return "0";
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function createTsWorkspaceService(descriptor) {
|
|
233
|
+
if (descriptor.projects.length === 0) {
|
|
234
|
+
throw new Error(
|
|
235
|
+
"TsWorkspaceDescriptor.projects must include at least one project"
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
const workspaceRoot = canonicalPath(descriptor.workspaceRoot);
|
|
239
|
+
const loadedProjects = descriptor.projects.map(
|
|
240
|
+
(project) => loadProject(project)
|
|
241
|
+
);
|
|
242
|
+
const projectsById = /* @__PURE__ */ new Map();
|
|
243
|
+
for (const project of loadedProjects) {
|
|
244
|
+
if (projectsById.has(project.id)) {
|
|
245
|
+
throw new Error(`Duplicate project id: ${project.id}`);
|
|
246
|
+
}
|
|
247
|
+
projectsById.set(project.id, project);
|
|
248
|
+
}
|
|
249
|
+
const primaryProject = (descriptor.primaryProjectId ? projectsById.get(descriptor.primaryProjectId) : null) ?? loadedProjects[0];
|
|
250
|
+
if (descriptor.primaryProjectId && !projectsById.has(descriptor.primaryProjectId)) {
|
|
251
|
+
throw new Error(
|
|
252
|
+
`Primary project id not found: ${descriptor.primaryProjectId}`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
const orderedProjects = [...loadedProjects].sort(compareProjectPriority);
|
|
256
|
+
const rootFileNames = /* @__PURE__ */ new Set();
|
|
257
|
+
for (const project of loadedProjects) {
|
|
258
|
+
for (const fileName of project.fileNames) {
|
|
259
|
+
rootFileNames.add(fileName);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const inMemoryFiles = /* @__PURE__ */ new Map();
|
|
263
|
+
let projectVersion = 0;
|
|
264
|
+
function getOwningProject(filePath) {
|
|
265
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
266
|
+
for (const project of orderedProjects) {
|
|
267
|
+
if (isWithinRoot(canonicalFilePath, project.rootDir)) {
|
|
268
|
+
return project;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return primaryProject;
|
|
272
|
+
}
|
|
273
|
+
const moduleResolutionHost = {
|
|
274
|
+
fileExists: import_typescript.default.sys.fileExists,
|
|
275
|
+
readFile: import_typescript.default.sys.readFile,
|
|
276
|
+
realpath: import_typescript.default.sys.realpath,
|
|
277
|
+
directoryExists: import_typescript.default.sys.directoryExists,
|
|
278
|
+
getCurrentDirectory: () => workspaceRoot,
|
|
279
|
+
getDirectories: import_typescript.default.sys.getDirectories
|
|
280
|
+
};
|
|
281
|
+
const host = {
|
|
282
|
+
getScriptFileNames: () => Array.from(rootFileNames),
|
|
283
|
+
getScriptVersion: (filePath) => {
|
|
284
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
285
|
+
const inMemory = inMemoryFiles.get(canonicalFilePath);
|
|
286
|
+
if (inMemory) {
|
|
287
|
+
return String(inMemory.version);
|
|
288
|
+
}
|
|
289
|
+
return getFileMtimeVersion(canonicalFilePath);
|
|
290
|
+
},
|
|
291
|
+
getScriptSnapshot: (filePath) => {
|
|
292
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
293
|
+
const inMemory = inMemoryFiles.get(canonicalFilePath);
|
|
294
|
+
if (inMemory) {
|
|
295
|
+
return import_typescript.default.ScriptSnapshot.fromString(inMemory.content);
|
|
296
|
+
}
|
|
297
|
+
const diskContent = import_typescript.default.sys.readFile(canonicalFilePath);
|
|
298
|
+
if (diskContent === void 0) {
|
|
299
|
+
return void 0;
|
|
300
|
+
}
|
|
301
|
+
return import_typescript.default.ScriptSnapshot.fromString(diskContent);
|
|
302
|
+
},
|
|
303
|
+
getCurrentDirectory: () => workspaceRoot,
|
|
304
|
+
getCompilationSettings: () => primaryProject.options,
|
|
305
|
+
getDefaultLibFileName: (options) => import_typescript.default.getDefaultLibFilePath(options),
|
|
306
|
+
fileExists: import_typescript.default.sys.fileExists,
|
|
307
|
+
readFile: import_typescript.default.sys.readFile,
|
|
308
|
+
readDirectory: import_typescript.default.sys.readDirectory,
|
|
309
|
+
directoryExists: import_typescript.default.sys.directoryExists,
|
|
310
|
+
getDirectories: import_typescript.default.sys.getDirectories,
|
|
311
|
+
useCaseSensitiveFileNames: () => import_typescript.default.sys.useCaseSensitiveFileNames,
|
|
312
|
+
getProjectVersion: () => String(projectVersion),
|
|
313
|
+
resolveModuleNames: (moduleNames, containingFile) => {
|
|
314
|
+
const owningProject = getOwningProject(containingFile);
|
|
315
|
+
return moduleNames.map((moduleName) => {
|
|
316
|
+
const ownerResolution = import_typescript.default.resolveModuleName(
|
|
317
|
+
moduleName,
|
|
318
|
+
containingFile,
|
|
319
|
+
owningProject.options,
|
|
320
|
+
moduleResolutionHost,
|
|
321
|
+
owningProject.moduleResolutionCache
|
|
322
|
+
).resolvedModule;
|
|
323
|
+
if (ownerResolution) {
|
|
324
|
+
return ownerResolution;
|
|
325
|
+
}
|
|
326
|
+
if (owningProject.id === primaryProject.id) {
|
|
327
|
+
return void 0;
|
|
328
|
+
}
|
|
329
|
+
return import_typescript.default.resolveModuleName(
|
|
330
|
+
moduleName,
|
|
331
|
+
containingFile,
|
|
332
|
+
primaryProject.options,
|
|
333
|
+
moduleResolutionHost,
|
|
334
|
+
primaryProject.moduleResolutionCache
|
|
335
|
+
).resolvedModule;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const languageService = import_typescript.default.createLanguageService(
|
|
340
|
+
host,
|
|
341
|
+
import_typescript.default.createDocumentRegistry()
|
|
342
|
+
);
|
|
343
|
+
return {
|
|
344
|
+
updateFile(filePath, content) {
|
|
345
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
346
|
+
const currentVersion = inMemoryFiles.get(canonicalFilePath)?.version ?? 0;
|
|
347
|
+
inMemoryFiles.set(canonicalFilePath, {
|
|
348
|
+
version: currentVersion + 1,
|
|
349
|
+
content
|
|
350
|
+
});
|
|
351
|
+
if (!rootFileNames.has(canonicalFilePath)) {
|
|
352
|
+
rootFileNames.add(canonicalFilePath);
|
|
353
|
+
}
|
|
354
|
+
projectVersion += 1;
|
|
355
|
+
},
|
|
356
|
+
closeFile(filePath) {
|
|
357
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
358
|
+
inMemoryFiles.delete(canonicalFilePath);
|
|
359
|
+
projectVersion += 1;
|
|
360
|
+
},
|
|
361
|
+
getProgram() {
|
|
362
|
+
return languageService.getProgram() ?? null;
|
|
363
|
+
},
|
|
364
|
+
getSemanticDiagnostics(filePath) {
|
|
365
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
366
|
+
return languageService.getSemanticDiagnostics(canonicalFilePath);
|
|
367
|
+
},
|
|
368
|
+
getDefinition(filePath, position) {
|
|
369
|
+
const canonicalFilePath = canonicalPath(filePath);
|
|
370
|
+
return languageService.getDefinitionAtPosition(
|
|
371
|
+
canonicalFilePath,
|
|
372
|
+
position
|
|
373
|
+
);
|
|
374
|
+
},
|
|
375
|
+
dispose() {
|
|
376
|
+
languageService.dispose();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// type-analyzer.ts
|
|
382
|
+
function isCustomComponent(node) {
|
|
383
|
+
const text = node.getText();
|
|
384
|
+
return text.length > 0 && text[0] !== text[0].toLowerCase();
|
|
385
|
+
}
|
|
386
|
+
function canonicalPath2(value) {
|
|
387
|
+
const resolved = import_node_path3.default.resolve(value);
|
|
388
|
+
try {
|
|
389
|
+
return import_node_fs3.realpathSync.native(resolved);
|
|
390
|
+
} catch {
|
|
391
|
+
return resolved;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function parseManagedTsconfigPaths(rawConfig) {
|
|
395
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
const metadata = rawConfig.tempobook;
|
|
399
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
400
|
+
return [];
|
|
401
|
+
}
|
|
402
|
+
const managedPaths = metadata.managedTsconfigPaths;
|
|
403
|
+
if (!Array.isArray(managedPaths)) {
|
|
404
|
+
return [];
|
|
405
|
+
}
|
|
406
|
+
return managedPaths.filter(
|
|
407
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
function parseProjectReferenceTsconfigPaths(references, configDir) {
|
|
411
|
+
if (!references || references.length === 0) {
|
|
412
|
+
return [];
|
|
413
|
+
}
|
|
414
|
+
const entries = [];
|
|
415
|
+
for (const reference of references) {
|
|
416
|
+
const referencePath = reference.path;
|
|
417
|
+
if (!referencePath) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const resolvedPath = import_node_path3.default.resolve(configDir, referencePath);
|
|
421
|
+
const tsconfigPath = resolvedPath.endsWith(".json") ? resolvedPath : import_node_path3.default.join(resolvedPath, "tsconfig.json");
|
|
422
|
+
entries.push(tsconfigPath);
|
|
423
|
+
}
|
|
424
|
+
return entries;
|
|
425
|
+
}
|
|
426
|
+
function buildWorkspaceProjects(root, configPath, parsedConfig, rawConfig) {
|
|
427
|
+
const configDir = import_node_path3.default.dirname(configPath);
|
|
428
|
+
const projects = [
|
|
429
|
+
{
|
|
430
|
+
id: "root",
|
|
431
|
+
rootDir: root,
|
|
432
|
+
tsconfigPath: configPath,
|
|
433
|
+
priority: 0
|
|
434
|
+
}
|
|
435
|
+
];
|
|
436
|
+
const seenTsconfigPaths = /* @__PURE__ */ new Set([canonicalPath2(configPath)]);
|
|
437
|
+
const referencedTsconfigPaths = parseProjectReferenceTsconfigPaths(
|
|
438
|
+
parsedConfig.projectReferences,
|
|
439
|
+
configDir
|
|
440
|
+
);
|
|
441
|
+
const managedTsconfigPaths = parseManagedTsconfigPaths(rawConfig).map(
|
|
442
|
+
(entry) => import_node_path3.default.resolve(configDir, entry)
|
|
443
|
+
);
|
|
444
|
+
const candidateTsconfigPaths = [
|
|
445
|
+
...managedTsconfigPaths,
|
|
446
|
+
...referencedTsconfigPaths
|
|
447
|
+
];
|
|
448
|
+
for (const candidatePath of candidateTsconfigPaths) {
|
|
449
|
+
const normalizedPath = canonicalPath2(candidatePath);
|
|
450
|
+
if (seenTsconfigPaths.has(normalizedPath)) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (!import_typescript2.default.sys.fileExists(normalizedPath)) {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
seenTsconfigPaths.add(normalizedPath);
|
|
457
|
+
projects.push({
|
|
458
|
+
id: `external-${projects.length}`,
|
|
459
|
+
rootDir: import_node_path3.default.dirname(normalizedPath),
|
|
460
|
+
tsconfigPath: normalizedPath,
|
|
461
|
+
priority: 0
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
return projects;
|
|
465
|
+
}
|
|
466
|
+
function createTypeAnalyzer(root) {
|
|
467
|
+
const configPath = import_typescript2.default.findConfigFile(
|
|
468
|
+
root,
|
|
469
|
+
import_typescript2.default.sys.fileExists,
|
|
470
|
+
"tsconfig.json"
|
|
471
|
+
);
|
|
472
|
+
if (!configPath) return null;
|
|
473
|
+
const configFile = import_typescript2.default.readConfigFile(configPath, import_typescript2.default.sys.readFile);
|
|
474
|
+
if (configFile.error) return null;
|
|
475
|
+
const parsedConfig = import_typescript2.default.parseJsonConfigFileContent(
|
|
476
|
+
configFile.config,
|
|
477
|
+
import_typescript2.default.sys,
|
|
478
|
+
root
|
|
479
|
+
);
|
|
480
|
+
const workspaceProjects = buildWorkspaceProjects(
|
|
481
|
+
root,
|
|
482
|
+
configPath,
|
|
483
|
+
parsedConfig,
|
|
484
|
+
configFile.config
|
|
485
|
+
);
|
|
486
|
+
const workspaceProjectRoots = workspaceProjects.map(
|
|
487
|
+
(project) => canonicalPath2(project.rootDir)
|
|
488
|
+
);
|
|
489
|
+
const workspaceService = createTsWorkspaceService({
|
|
490
|
+
workspaceRoot: root,
|
|
491
|
+
primaryProjectId: "root",
|
|
492
|
+
projects: workspaceProjects
|
|
493
|
+
});
|
|
494
|
+
let cssPropertiesType;
|
|
495
|
+
function resolveCSSPropertiesType(checker, sourceFile) {
|
|
496
|
+
if (cssPropertiesType !== void 0) return cssPropertiesType;
|
|
497
|
+
try {
|
|
498
|
+
let jsxNs = checker.resolveName(
|
|
499
|
+
"JSX",
|
|
500
|
+
sourceFile,
|
|
501
|
+
import_typescript2.default.SymbolFlags.Namespace,
|
|
502
|
+
false
|
|
503
|
+
);
|
|
504
|
+
if (!jsxNs) {
|
|
505
|
+
const program = workspaceService.getProgram();
|
|
506
|
+
const compilerOptions = program?.getCompilerOptions();
|
|
507
|
+
const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
|
|
508
|
+
const resolved = import_typescript2.default.resolveModuleName(
|
|
509
|
+
`${jsxImportSource}/jsx-runtime`,
|
|
510
|
+
sourceFile.fileName,
|
|
511
|
+
compilerOptions,
|
|
512
|
+
import_typescript2.default.sys
|
|
513
|
+
);
|
|
514
|
+
if (resolved.resolvedModule) {
|
|
515
|
+
const runtimeFile = program?.getSourceFile(
|
|
516
|
+
resolved.resolvedModule.resolvedFileName
|
|
517
|
+
);
|
|
518
|
+
if (runtimeFile) {
|
|
519
|
+
const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
|
|
520
|
+
if (runtimeSymbol) {
|
|
521
|
+
const exports2 = checker.getExportsOfModule(runtimeSymbol);
|
|
522
|
+
jsxNs = exports2.find((s) => s.name === "JSX");
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (!jsxNs) {
|
|
528
|
+
cssPropertiesType = null;
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
|
|
532
|
+
if (!intrinsicSym) {
|
|
533
|
+
cssPropertiesType = null;
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
|
|
537
|
+
if (!divSym) {
|
|
538
|
+
cssPropertiesType = null;
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
const styleSym = checker.getTypeOfSymbol(divSym).getProperty("style");
|
|
542
|
+
if (!styleSym) {
|
|
543
|
+
cssPropertiesType = null;
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
const styleType = checker.getTypeOfSymbol(styleSym);
|
|
547
|
+
if (styleType.isUnion()) {
|
|
548
|
+
const nonUndefined = styleType.types.find(
|
|
549
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
550
|
+
);
|
|
551
|
+
cssPropertiesType = nonUndefined ?? null;
|
|
552
|
+
} else {
|
|
553
|
+
cssPropertiesType = styleType;
|
|
554
|
+
}
|
|
555
|
+
} catch {
|
|
556
|
+
cssPropertiesType = null;
|
|
557
|
+
}
|
|
558
|
+
return cssPropertiesType;
|
|
559
|
+
}
|
|
560
|
+
let reactNodeType;
|
|
561
|
+
function resolveReactNodeType(checker, sourceFile) {
|
|
562
|
+
if (reactNodeType !== void 0) return reactNodeType;
|
|
563
|
+
try {
|
|
564
|
+
let jsxNs = checker.resolveName(
|
|
565
|
+
"JSX",
|
|
566
|
+
sourceFile,
|
|
567
|
+
import_typescript2.default.SymbolFlags.Namespace,
|
|
568
|
+
false
|
|
569
|
+
);
|
|
570
|
+
if (!jsxNs) {
|
|
571
|
+
const program = workspaceService.getProgram();
|
|
572
|
+
const compilerOptions = program?.getCompilerOptions();
|
|
573
|
+
const jsxImportSource = compilerOptions?.jsxImportSource ?? "react";
|
|
574
|
+
const resolved = import_typescript2.default.resolveModuleName(
|
|
575
|
+
`${jsxImportSource}/jsx-runtime`,
|
|
576
|
+
sourceFile.fileName,
|
|
577
|
+
compilerOptions,
|
|
578
|
+
import_typescript2.default.sys
|
|
579
|
+
);
|
|
580
|
+
if (resolved.resolvedModule) {
|
|
581
|
+
const runtimeFile = program?.getSourceFile(
|
|
582
|
+
resolved.resolvedModule.resolvedFileName
|
|
583
|
+
);
|
|
584
|
+
if (runtimeFile) {
|
|
585
|
+
const runtimeSymbol = checker.getSymbolAtLocation(runtimeFile);
|
|
586
|
+
if (runtimeSymbol) {
|
|
587
|
+
const exports2 = checker.getExportsOfModule(runtimeSymbol);
|
|
588
|
+
jsxNs = exports2.find((s) => s.name === "JSX");
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (!jsxNs) {
|
|
594
|
+
reactNodeType = null;
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
const intrinsicSym = checker.getExportsOfModule(jsxNs).find((s) => s.name === "IntrinsicElements") ?? checker.getDeclaredTypeOfSymbol(jsxNs).getProperty("IntrinsicElements");
|
|
598
|
+
if (!intrinsicSym) {
|
|
599
|
+
reactNodeType = null;
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
const divSym = checker.getDeclaredTypeOfSymbol(intrinsicSym).getProperty("div");
|
|
603
|
+
if (!divSym) {
|
|
604
|
+
reactNodeType = null;
|
|
605
|
+
return null;
|
|
606
|
+
}
|
|
607
|
+
const childrenSym = checker.getTypeOfSymbol(divSym).getProperty("children");
|
|
608
|
+
if (!childrenSym) {
|
|
609
|
+
reactNodeType = null;
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
const childrenType = checker.getTypeOfSymbol(childrenSym);
|
|
613
|
+
if (childrenType.isUnion()) {
|
|
614
|
+
const nonUndefined = childrenType.types.find(
|
|
615
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
616
|
+
);
|
|
617
|
+
reactNodeType = nonUndefined ?? null;
|
|
618
|
+
} else {
|
|
619
|
+
reactNodeType = childrenType;
|
|
620
|
+
}
|
|
621
|
+
} catch {
|
|
622
|
+
reactNodeType = null;
|
|
623
|
+
}
|
|
624
|
+
return reactNodeType;
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
analyzeFileTypes(filePath, source) {
|
|
628
|
+
const canonicalFilePath = canonicalPath2(filePath);
|
|
629
|
+
const belongsToWorkspace = workspaceProjectRoots.some(
|
|
630
|
+
(projectRoot) => canonicalFilePath === projectRoot || canonicalFilePath.startsWith(`${projectRoot}${import_node_path3.default.sep}`)
|
|
631
|
+
);
|
|
632
|
+
if (!belongsToWorkspace) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
workspaceService.updateFile(filePath, source);
|
|
636
|
+
const program = workspaceService.getProgram();
|
|
637
|
+
if (!program) return null;
|
|
638
|
+
const sourceFile = program.getSourceFile(filePath);
|
|
639
|
+
if (!sourceFile) return null;
|
|
640
|
+
const checker = program.getTypeChecker();
|
|
641
|
+
const cssProps = resolveCSSPropertiesType(checker, sourceFile);
|
|
642
|
+
const result = /* @__PURE__ */ new Map();
|
|
643
|
+
function visit(node) {
|
|
644
|
+
if ((import_typescript2.default.isJsxOpeningElement(node) || import_typescript2.default.isJsxSelfClosingElement(node)) && isCustomComponent(node.tagName)) {
|
|
645
|
+
const position = node.getStart(sourceFile);
|
|
646
|
+
const attrsType = checker.getContextualType(node.attributes);
|
|
647
|
+
let supportsStyle = false;
|
|
648
|
+
let supportsClassName = false;
|
|
649
|
+
let supportsChildren = false;
|
|
650
|
+
if (attrsType) {
|
|
651
|
+
const classNameProp = attrsType.getProperty("className");
|
|
652
|
+
if (classNameProp) {
|
|
653
|
+
const propType = checker.getTypeOfSymbol(classNameProp);
|
|
654
|
+
supportsClassName = checker.isTypeAssignableTo(
|
|
655
|
+
checker.getStringType(),
|
|
656
|
+
propType
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
const styleProp = attrsType.getProperty("style");
|
|
660
|
+
if (styleProp && cssProps) {
|
|
661
|
+
let propType = checker.getTypeOfSymbol(styleProp);
|
|
662
|
+
if (propType.isUnion()) {
|
|
663
|
+
const nonUndefined = propType.types.find(
|
|
664
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
665
|
+
);
|
|
666
|
+
if (nonUndefined) propType = nonUndefined;
|
|
667
|
+
}
|
|
668
|
+
supportsStyle = checker.isTypeAssignableTo(cssProps, propType);
|
|
669
|
+
}
|
|
670
|
+
const reactNode = resolveReactNodeType(checker, sourceFile);
|
|
671
|
+
const childrenProp = attrsType.getProperty("children");
|
|
672
|
+
if (childrenProp && reactNode) {
|
|
673
|
+
let propType = checker.getTypeOfSymbol(childrenProp);
|
|
674
|
+
if (propType.isUnion()) {
|
|
675
|
+
const nonUndefined = propType.types.find(
|
|
676
|
+
(t) => !(t.flags & import_typescript2.default.TypeFlags.Undefined)
|
|
677
|
+
);
|
|
678
|
+
if (nonUndefined) propType = nonUndefined;
|
|
679
|
+
}
|
|
680
|
+
supportsChildren = checker.isTypeAssignableTo(
|
|
681
|
+
reactNode,
|
|
682
|
+
propType
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
result.set(position, { supportsStyle, supportsClassName, supportsChildren });
|
|
687
|
+
}
|
|
688
|
+
import_typescript2.default.forEachChild(node, visit);
|
|
689
|
+
}
|
|
690
|
+
visit(sourceFile);
|
|
691
|
+
return result;
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
129
696
|
// expo-babel-plugin.ts
|
|
130
697
|
var EXPO_DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx", "**/*.js"];
|
|
131
698
|
var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
|
|
@@ -272,16 +839,16 @@ function injectProjectRootMeta(api, programPath, root) {
|
|
|
272
839
|
}
|
|
273
840
|
function resolveBabelRoot(state, options, filename) {
|
|
274
841
|
return resolveCanonicalRoot(
|
|
275
|
-
(0,
|
|
842
|
+
(0, import_node_path4.resolve)(
|
|
276
843
|
options.root ?? findNearestPackageRoot(filename) ?? state.cwd ?? state.file.opts.cwd ?? state.file.opts.root ?? process.cwd()
|
|
277
844
|
)
|
|
278
845
|
);
|
|
279
846
|
}
|
|
280
847
|
function findNearestPackageRoot(filename) {
|
|
281
|
-
let current = (0,
|
|
848
|
+
let current = (0, import_node_path4.dirname)(filename);
|
|
282
849
|
while (true) {
|
|
283
|
-
if ((0,
|
|
284
|
-
const parent = (0,
|
|
850
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path4.resolve)(current, "package.json"))) return current;
|
|
851
|
+
const parent = (0, import_node_path4.dirname)(current);
|
|
285
852
|
if (parent === current) return null;
|
|
286
853
|
current = parent;
|
|
287
854
|
}
|
|
@@ -289,7 +856,7 @@ function findNearestPackageRoot(filename) {
|
|
|
289
856
|
function resolveFilename(state) {
|
|
290
857
|
const filename = state.filename ?? state.file.opts.filename;
|
|
291
858
|
if (!filename) return null;
|
|
292
|
-
return (0,
|
|
859
|
+
return (0, import_node_path4.resolve)(cleanModuleId(filename));
|
|
293
860
|
}
|
|
294
861
|
function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
295
862
|
api.assertVersion(7);
|
|
@@ -297,6 +864,8 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
|
297
864
|
const include = rawOptions.include === void 0 ? EXPO_DEFAULT_INCLUDE : rawOptions.include;
|
|
298
865
|
const exclude = rawOptions.exclude === void 0 ? DEFAULT_EXCLUDE : rawOptions.exclude;
|
|
299
866
|
const filter = (0, import_pluginutils.createFilter)(include, exclude);
|
|
867
|
+
let typeAnalyzerRoot = null;
|
|
868
|
+
let typeAnalyzer = null;
|
|
300
869
|
return {
|
|
301
870
|
name: "tempo-expo-annotate",
|
|
302
871
|
manipulateOptions(opts, parserOpts) {
|
|
@@ -311,7 +880,7 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
|
311
880
|
},
|
|
312
881
|
visitor: {
|
|
313
882
|
Program: {
|
|
314
|
-
enter(
|
|
883
|
+
enter(path3, state) {
|
|
315
884
|
if (!enabled) return;
|
|
316
885
|
const options = { ...rawOptions, ...state.opts };
|
|
317
886
|
const filename = resolveFilename(state);
|
|
@@ -330,10 +899,15 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
|
330
899
|
return;
|
|
331
900
|
}
|
|
332
901
|
if (context.filepath === "index.js") {
|
|
333
|
-
injectProjectRootMeta(api,
|
|
902
|
+
injectProjectRootMeta(api, path3, root);
|
|
903
|
+
}
|
|
904
|
+
if (options.typeSupport !== false && typeAnalyzerRoot !== root) {
|
|
905
|
+
typeAnalyzerRoot = root;
|
|
906
|
+
typeAnalyzer = createTypeAnalyzer(root);
|
|
334
907
|
}
|
|
908
|
+
const typeInfo = options.typeSupport === false ? null : typeAnalyzer?.analyzeFileTypes(context.cleanFilename, source);
|
|
335
909
|
const supportOverrides = getSupportOverrides(options);
|
|
336
|
-
|
|
910
|
+
path3.traverse({
|
|
337
911
|
JSXElement(elementPath) {
|
|
338
912
|
const element = elementPath.node;
|
|
339
913
|
const tagName = getBabelTagName(element.openingElement.name);
|
|
@@ -347,6 +921,7 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
|
347
921
|
filepath: context.filepath,
|
|
348
922
|
modifiedtsMs: context.modifiedtsMs,
|
|
349
923
|
computeAnnotatedProps: options.computeAnnotatedProps,
|
|
924
|
+
typeInfo,
|
|
350
925
|
elementSupportOverrides: supportOverrides
|
|
351
926
|
});
|
|
352
927
|
addAnnotations(api, tagName, element.openingElement, props);
|