tempo-sdk 0.0.8 → 0.0.10
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 +96 -0
- package/dist/annotation-strategy-DCJHc--2.d.cts +13 -0
- package/dist/annotation-strategy-DCJHc--2.d.ts +13 -0
- package/dist/chunk-2LP5G6CD.js +748 -0
- package/dist/chunk-2LP5G6CD.js.map +1 -0
- package/dist/chunk-F64WRL4H.js +884 -0
- package/dist/chunk-F64WRL4H.js.map +1 -0
- package/dist/chunk-GHPL4LGE.js +205 -0
- package/dist/chunk-GHPL4LGE.js.map +1 -0
- package/dist/chunk-IG3JZVZI.js +846 -0
- package/dist/chunk-IG3JZVZI.js.map +1 -0
- package/dist/chunk-X3K7Z2BH.js +900 -0
- package/dist/chunk-X3K7Z2BH.js.map +1 -0
- package/dist/chunk-ZHORRCQG.js +756 -0
- package/dist/chunk-ZHORRCQG.js.map +1 -0
- package/dist/expo/plugin.cjs +921 -0
- package/dist/expo/plugin.cjs.map +1 -0
- package/dist/expo/plugin.d.cts +5 -0
- package/dist/expo/plugin.d.ts +5 -0
- package/dist/expo/plugin.js +8 -0
- package/dist/expo/plugin.js.map +1 -0
- package/dist/expo-babel-plugin.cjs +919 -0
- package/dist/expo-babel-plugin.cjs.map +1 -0
- package/dist/expo-babel-plugin.d.cts +71 -0
- package/dist/expo-babel-plugin.d.ts +71 -0
- package/dist/expo-babel-plugin.js +8 -0
- package/dist/expo-babel-plugin.js.map +1 -0
- package/dist/index.cjs +1170 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +99 -0
- package/dist/index.js +100 -53
- package/dist/index.js.map +1 -1
- package/dist/nextjs-loader.cjs +114 -67
- package/dist/nextjs-loader.cjs.map +1 -1
- package/package.json +23 -6
|
@@ -0,0 +1,921 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// expo/plugin.ts
|
|
31
|
+
var plugin_exports = {};
|
|
32
|
+
__export(plugin_exports, {
|
|
33
|
+
default: () => tempoExpoBabelPlugin,
|
|
34
|
+
tempoExpoBabelPlugin: () => tempoExpoBabelPlugin
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
37
|
+
|
|
38
|
+
// expo-babel-plugin.ts
|
|
39
|
+
var import_node_fs4 = require("fs");
|
|
40
|
+
var import_node_path4 = require("path");
|
|
41
|
+
var import_pluginutils = require("@rollup/pluginutils");
|
|
42
|
+
|
|
43
|
+
// annotation-strategy.ts
|
|
44
|
+
var import_node_fs = require("fs");
|
|
45
|
+
var import_node_path = require("path");
|
|
46
|
+
var DEFAULT_EXCLUDE = ["**/node_modules/**"];
|
|
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 import_node_fs.realpathSync.native(root);
|
|
69
|
+
} catch {
|
|
70
|
+
return root;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function isIntrinsicElement(tagName) {
|
|
74
|
+
return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
|
|
75
|
+
}
|
|
76
|
+
function hasJsxAttribute(info, attrName) {
|
|
77
|
+
for (const attr of info.element.openingElement.attributes) {
|
|
78
|
+
const name = attr.name;
|
|
79
|
+
if (name?.name === attrName) return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
|
|
84
|
+
return {
|
|
85
|
+
"data-tempo-filepath": filepath,
|
|
86
|
+
"data-tempo-position": info.element.openingElement.start,
|
|
87
|
+
"data-tempo-modifiedts": modifiedtsMs
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function computeTempoAnnotatedProps(params) {
|
|
91
|
+
const {
|
|
92
|
+
info,
|
|
93
|
+
filepath,
|
|
94
|
+
modifiedtsMs,
|
|
95
|
+
computeAnnotatedProps,
|
|
96
|
+
typeInfo,
|
|
97
|
+
elementSupportOverrides
|
|
98
|
+
} = params;
|
|
99
|
+
const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);
|
|
100
|
+
if (isIntrinsicElement(info.tagName)) {
|
|
101
|
+
return {
|
|
102
|
+
...userProps,
|
|
103
|
+
"data-tempo-supports-children": hasJsxAttribute(
|
|
104
|
+
info,
|
|
105
|
+
"data-tempo-supports-children"
|
|
106
|
+
) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const override = elementSupportOverrides?.get(info.tagName);
|
|
110
|
+
if (override) {
|
|
111
|
+
return {
|
|
112
|
+
...userProps,
|
|
113
|
+
"data-tempo-supports-style": override.supportsStyle,
|
|
114
|
+
"data-tempo-supports-classname": override.supportsClassName,
|
|
115
|
+
"data-tempo-supports-children": hasJsxAttribute(
|
|
116
|
+
info,
|
|
117
|
+
"data-tempo-supports-children"
|
|
118
|
+
) ? void 0 : override.supportsChildren
|
|
119
|
+
};
|
|
120
|
+
}
|
|
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
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function getFileAnnotationContext(params) {
|
|
133
|
+
const rawCleanFilename = cleanModuleId(params.filename);
|
|
134
|
+
let cleanFilename = rawCleanFilename;
|
|
135
|
+
if (params.canonicalizeFilename) {
|
|
136
|
+
try {
|
|
137
|
+
cleanFilename = import_node_fs.realpathSync.native(rawCleanFilename);
|
|
138
|
+
} catch {
|
|
139
|
+
cleanFilename = rawCleanFilename;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
cleanFilename,
|
|
144
|
+
filepath: (0, import_node_path.relative)(params.root, cleanFilename),
|
|
145
|
+
modifiedtsMs: Math.trunc((0, import_node_fs.statSync)(cleanFilename).mtimeMs)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
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
|
+
|
|
696
|
+
// expo-babel-plugin.ts
|
|
697
|
+
var EXPO_DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx", "**/*.js"];
|
|
698
|
+
var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
|
|
699
|
+
var REACT_NATIVE_STYLE_COMPONENTS = /* @__PURE__ */ new Set([
|
|
700
|
+
"ActivityIndicator",
|
|
701
|
+
"Button",
|
|
702
|
+
"FlatList",
|
|
703
|
+
"Image",
|
|
704
|
+
"ImageBackground",
|
|
705
|
+
"KeyboardAvoidingView",
|
|
706
|
+
"Modal",
|
|
707
|
+
"Pressable",
|
|
708
|
+
"RefreshControl",
|
|
709
|
+
"SafeAreaView",
|
|
710
|
+
"ScrollView",
|
|
711
|
+
"SectionList",
|
|
712
|
+
"Switch",
|
|
713
|
+
"Text",
|
|
714
|
+
"TextInput",
|
|
715
|
+
"TouchableHighlight",
|
|
716
|
+
"TouchableNativeFeedback",
|
|
717
|
+
"TouchableOpacity",
|
|
718
|
+
"TouchableWithoutFeedback",
|
|
719
|
+
"View",
|
|
720
|
+
"VirtualizedList"
|
|
721
|
+
]);
|
|
722
|
+
var REACT_NATIVE_NO_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set([
|
|
723
|
+
"ActivityIndicator",
|
|
724
|
+
"Image",
|
|
725
|
+
"RefreshControl",
|
|
726
|
+
"Switch"
|
|
727
|
+
]);
|
|
728
|
+
var REACT_NATIVE_SUPPORT_OVERRIDES = new Map(
|
|
729
|
+
[...REACT_NATIVE_STYLE_COMPONENTS].map((tagName) => [
|
|
730
|
+
tagName,
|
|
731
|
+
{
|
|
732
|
+
supportsStyle: true,
|
|
733
|
+
supportsClassName: false,
|
|
734
|
+
supportsChildren: !REACT_NATIVE_NO_CHILDREN_COMPONENTS.has(tagName)
|
|
735
|
+
}
|
|
736
|
+
])
|
|
737
|
+
);
|
|
738
|
+
function hasParserPlugin(plugins, name) {
|
|
739
|
+
return plugins.some(
|
|
740
|
+
(plugin) => Array.isArray(plugin) ? plugin[0] === name : plugin === name
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
function getBabelTagName(name) {
|
|
744
|
+
switch (name.type) {
|
|
745
|
+
case "JSXIdentifier":
|
|
746
|
+
return name.name;
|
|
747
|
+
case "JSXNamespacedName":
|
|
748
|
+
return `${name.namespace.name}:${name.name.name}`;
|
|
749
|
+
case "JSXMemberExpression":
|
|
750
|
+
return `${getBabelTagName(name.object)}.${name.property.name}`;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function hasAttribute(node, attrName) {
|
|
754
|
+
return node.attributes.some(
|
|
755
|
+
(attr) => attr.type === "JSXAttribute" && attr.name.name === attrName
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
function propValueToExpression(api, value) {
|
|
759
|
+
if (typeof value === "function") {
|
|
760
|
+
return api.template.expression(value.toString())();
|
|
761
|
+
}
|
|
762
|
+
return api.types.valueToNode(value);
|
|
763
|
+
}
|
|
764
|
+
function getSupportOverrides(options) {
|
|
765
|
+
if (!options.reactNativeClassName) {
|
|
766
|
+
return REACT_NATIVE_SUPPORT_OVERRIDES;
|
|
767
|
+
}
|
|
768
|
+
return new Map(
|
|
769
|
+
[...REACT_NATIVE_SUPPORT_OVERRIDES].map(([tagName, support]) => [
|
|
770
|
+
tagName,
|
|
771
|
+
{ ...support, supportsClassName: true }
|
|
772
|
+
])
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
function dataAttrToDataSetKey(attrName) {
|
|
776
|
+
return attrName.replace(/^data-/, "").replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
777
|
+
}
|
|
778
|
+
function findDataSetAttribute(openingElement) {
|
|
779
|
+
return openingElement.attributes.find(
|
|
780
|
+
(attr) => attr.type === "JSXAttribute" && attr.name.name === "dataSet"
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
function addAnnotations(api, tagName, openingElement, props) {
|
|
784
|
+
const t = api.types;
|
|
785
|
+
if (isIntrinsicElement(tagName)) {
|
|
786
|
+
for (const [key, value] of Object.entries(props)) {
|
|
787
|
+
if (value === void 0 || hasAttribute(openingElement, key)) continue;
|
|
788
|
+
openingElement.attributes.push(
|
|
789
|
+
t.jsxAttribute(
|
|
790
|
+
t.jsxIdentifier(key),
|
|
791
|
+
t.jsxExpressionContainer(propValueToExpression(api, value))
|
|
792
|
+
)
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const dataSetProps = [];
|
|
798
|
+
for (const [key, value] of Object.entries(props)) {
|
|
799
|
+
if (value === void 0) continue;
|
|
800
|
+
dataSetProps.push(
|
|
801
|
+
t.objectProperty(
|
|
802
|
+
t.identifier(dataAttrToDataSetKey(key)),
|
|
803
|
+
propValueToExpression(api, value)
|
|
804
|
+
)
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
if (dataSetProps.length === 0) return;
|
|
808
|
+
const existing = findDataSetAttribute(openingElement);
|
|
809
|
+
if (!existing) {
|
|
810
|
+
openingElement.attributes.push(
|
|
811
|
+
t.jsxAttribute(
|
|
812
|
+
t.jsxIdentifier("dataSet"),
|
|
813
|
+
t.jsxExpressionContainer(t.objectExpression(dataSetProps))
|
|
814
|
+
)
|
|
815
|
+
);
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (existing.value?.type === "JSXExpressionContainer" && existing.value.expression.type !== "JSXEmptyExpression") {
|
|
819
|
+
existing.value.expression = t.objectExpression([
|
|
820
|
+
t.spreadElement(existing.value.expression),
|
|
821
|
+
...dataSetProps
|
|
822
|
+
]);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
function resolveBabelRoot(state, options, filename) {
|
|
826
|
+
return resolveCanonicalRoot(
|
|
827
|
+
(0, import_node_path4.resolve)(
|
|
828
|
+
options.root ?? findNearestPackageRoot(filename) ?? state.cwd ?? state.file.opts.cwd ?? state.file.opts.root ?? process.cwd()
|
|
829
|
+
)
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
function findNearestPackageRoot(filename) {
|
|
833
|
+
let current = (0, import_node_path4.dirname)(filename);
|
|
834
|
+
while (true) {
|
|
835
|
+
if ((0, import_node_fs4.existsSync)((0, import_node_path4.resolve)(current, "package.json"))) return current;
|
|
836
|
+
const parent = (0, import_node_path4.dirname)(current);
|
|
837
|
+
if (parent === current) return null;
|
|
838
|
+
current = parent;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
function resolveFilename(state) {
|
|
842
|
+
const filename = state.filename ?? state.file.opts.filename;
|
|
843
|
+
if (!filename) return null;
|
|
844
|
+
return (0, import_node_path4.resolve)(cleanModuleId(filename));
|
|
845
|
+
}
|
|
846
|
+
function tempoExpoBabelPlugin(api, rawOptions = {}) {
|
|
847
|
+
api.assertVersion(7);
|
|
848
|
+
const enabled = rawOptions.enabled ?? !!process.env.TEMPO;
|
|
849
|
+
const include = rawOptions.include === void 0 ? EXPO_DEFAULT_INCLUDE : rawOptions.include;
|
|
850
|
+
const exclude = rawOptions.exclude === void 0 ? DEFAULT_EXCLUDE : rawOptions.exclude;
|
|
851
|
+
const filter = (0, import_pluginutils.createFilter)(include, exclude);
|
|
852
|
+
let typeAnalyzerRoot = null;
|
|
853
|
+
let typeAnalyzer = null;
|
|
854
|
+
return {
|
|
855
|
+
name: "tempo-expo-annotate",
|
|
856
|
+
manipulateOptions(opts, parserOpts) {
|
|
857
|
+
parserOpts.plugins ?? (parserOpts.plugins = []);
|
|
858
|
+
if (!hasParserPlugin(parserOpts.plugins, "jsx")) {
|
|
859
|
+
parserOpts.plugins.push("jsx");
|
|
860
|
+
}
|
|
861
|
+
const filename = opts.filename ?? "";
|
|
862
|
+
if (/\.(ts|tsx)$/.test(filename) && !hasParserPlugin(parserOpts.plugins, "typescript")) {
|
|
863
|
+
parserOpts.plugins.push("typescript");
|
|
864
|
+
}
|
|
865
|
+
},
|
|
866
|
+
visitor: {
|
|
867
|
+
Program: {
|
|
868
|
+
enter(path3, state) {
|
|
869
|
+
if (!enabled) return;
|
|
870
|
+
const options = { ...rawOptions, ...state.opts };
|
|
871
|
+
const filename = resolveFilename(state);
|
|
872
|
+
if (!filename || !filter(filename)) return;
|
|
873
|
+
const source = state.file.code;
|
|
874
|
+
const root = resolveBabelRoot(state, options, filename);
|
|
875
|
+
let context;
|
|
876
|
+
try {
|
|
877
|
+
context = getFileAnnotationContext({
|
|
878
|
+
source,
|
|
879
|
+
filename,
|
|
880
|
+
root,
|
|
881
|
+
canonicalizeFilename: true
|
|
882
|
+
});
|
|
883
|
+
} catch {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
if (options.typeSupport !== false && typeAnalyzerRoot !== root) {
|
|
887
|
+
typeAnalyzerRoot = root;
|
|
888
|
+
typeAnalyzer = createTypeAnalyzer(root);
|
|
889
|
+
}
|
|
890
|
+
const typeInfo = options.typeSupport === false ? null : typeAnalyzer?.analyzeFileTypes(context.cleanFilename, source);
|
|
891
|
+
const supportOverrides = getSupportOverrides(options);
|
|
892
|
+
path3.traverse({
|
|
893
|
+
JSXElement(elementPath) {
|
|
894
|
+
const element = elementPath.node;
|
|
895
|
+
const tagName = getBabelTagName(element.openingElement.name);
|
|
896
|
+
if (FRAGMENT_TAG_NAMES.has(tagName)) return;
|
|
897
|
+
const info = {
|
|
898
|
+
element,
|
|
899
|
+
tagName
|
|
900
|
+
};
|
|
901
|
+
const props = computeTempoAnnotatedProps({
|
|
902
|
+
info,
|
|
903
|
+
filepath: context.filepath,
|
|
904
|
+
modifiedtsMs: context.modifiedtsMs,
|
|
905
|
+
computeAnnotatedProps: options.computeAnnotatedProps,
|
|
906
|
+
typeInfo,
|
|
907
|
+
elementSupportOverrides: supportOverrides
|
|
908
|
+
});
|
|
909
|
+
addAnnotations(api, tagName, element.openingElement, props);
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
918
|
+
0 && (module.exports = {
|
|
919
|
+
tempoExpoBabelPlugin
|
|
920
|
+
});
|
|
921
|
+
//# sourceMappingURL=plugin.cjs.map
|