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

Function transformer

packages/dev/codemods/src/use-subpaths/src/codemod.ts:92–260  ·  view source on GitHub ↗
(file: FileInfo, api: API)

Source from the content-addressed store, hash-verified

90}
91
92export default function transformer(file: FileInfo, api: API): string {
93 let specifiersByPackage = getSpecifiersByPackage(file.path);
94 let j = api.jscodeshift.withParser({
95 parse(source: string) {
96 return recastParse(source, {
97 parser: {
98 parse(innerSource: string) {
99 return parse(innerSource, {
100 sourceType: 'module',
101 plugins: [
102 'jsx',
103 'typescript',
104 'importAssertions',
105 'dynamicImport',
106 'decorators-legacy',
107 'classProperties',
108 'classPrivateProperties',
109 'classPrivateMethods',
110 'exportDefaultFrom',
111 'exportNamespaceFrom',
112 'objectRestSpread',
113 'optionalChaining',
114 'nullishCoalescingOperator',
115 'topLevelAwait'
116 ],
117 tokens: true,
118 errorRecovery: true
119 });
120 }
121 }
122 });
123 }
124 });
125
126 let root = j(file.source);
127 let program = root.get().node.program as t.Program;
128 let uniqueSources = new Set<string>();
129 let existingImports = new Map<string, t.ImportDeclaration>();
130 let didChange = false;
131
132 for (let node of program.body) {
133 if (node.type === 'ImportDeclaration') {
134 let source = node.source.value;
135 if (typeof source !== 'string') {
136 continue;
137 }
138
139 existingImports.set(getImportDeclarationKey(node), node);
140
141 if (source in specifiersByPackage) {
142 let sourceMap = specifiersByPackage[source];
143 for (let specifier of node.specifiers ?? []) {
144 if (specifier.type !== 'ImportSpecifier') {
145 continue;
146 }
147
148 let importedName = getImportedName(specifier);
149 let candidates = sourceMap[importedName];

Callers

nothing calls this directly

Calls 14

getSpecifiersByPackageFunction · 0.90
getImportDeclarationKeyFunction · 0.85
getImportedNameFunction · 0.85
resolveTargetSourceFunction · 0.85
createImportDeclarationFunction · 0.85
getNamedSpecifierKeysFunction · 0.85
getImportKeyFunction · 0.85
pushMethod · 0.80
sliceMethod · 0.80
addMethod · 0.65
filterMethod · 0.65

Tested by

no test coverage detected