MCPcopy Create free account
hub / github.com/adobe/react-spectrum / transform

Function transform

packages/dev/parcel-transformer-docs/DocsTransformer.js:21–989  ·  view source on GitHub ↗
({asset, options})

Source from the content-addressed store, hash-verified

19
20module.exports = new Transformer({
21 async transform({asset, options}) {
22 let nodeCache = new Map();
23 if (asset.type === 'json') {
24 return [asset];
25 }
26
27 let code = await asset.getCode();
28 let ast = parse(code, {
29 filename: this.name,
30 allowReturnOutsideFunction: true,
31 strictMode: false,
32 sourceType: 'module',
33 plugins: [
34 'classProperties',
35 'exportDefaultFrom',
36 'exportNamespaceFrom',
37 'dynamicImport',
38 'typescript',
39 'jsx',
40 'classPrivateProperties',
41 'classPrivateMethods',
42 'importAttributes'
43 ]
44 });
45
46 let exports = {};
47
48 asset.symbols.ensure();
49 asset.symbols.set('*', `$${asset.id}$exports`);
50 asset.isBundleSplittable = false;
51
52 traverse(ast, {
53 ExportNamedDeclaration(path) {
54 if (path.node.source) {
55 let symbols = new Map();
56 for (let specifier of path.node.specifiers) {
57 symbols.set(specifier.local.name, {local: specifier.exported.name});
58 asset.symbols.set(specifier.exported.name, specifier.exported.name);
59 }
60
61 asset.addDependency({
62 specifier: path.node.source.value,
63 specifierType: 'esm',
64 symbols,
65 pipeline: 'docs-json'
66 });
67 } else if (path.node.declaration) {
68 if (t.isIdentifier(path.node.declaration.id)) {
69 let name = path.node.declaration.id.name;
70 asset.symbols.set(name, name);
71 let prev = exports[name];
72 let val = processExport(path.get('declaration'));
73 if (val) {
74 exports[name] = val;
75 if (!exports[name].description && prev?.description) {
76 exports[name].description = prev.description;
77 }
78 }

Callers

nothing calls this directly

Calls 3

traverseFunction · 0.85
parseFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected