| 1 | import type { Filescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File# } from "@babel/core"scip-typescript npm @babel/core 7.20.12 src/`index.ts`/; |
| 2 | import type { NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor# } from "@babel/traverse"scip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/; |
| 3 | import traversescip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/traverse(). from "@babel/traverse"scip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/; |
| 4 | import { |
| 5 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression()., |
| 6 | cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode()., |
| 7 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement()., |
| 8 | filescip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/file()., |
| 9 | identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier()., |
| 10 | } from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 11 | import type * as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/ from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 12 | import helpersscip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/helpers. from "./helpers"scip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/; |
| 13 | |
| 14 | function makePathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(pathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#) { |
| 15 | const parts = []; |
| 16 | |
| 17 | for (; pathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(path).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.; pathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(path) = pathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(path).parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath.) { |
| 18 | parts.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(pathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(path).keyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#key.); |
| 19 | if (pathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(path).inListscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#`<get>inList`().) parts.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(pathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(path).listKeyscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#listKey.); |
| 20 | } |
| 21 | |
| 22 | return parts.reversescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#reverse().().joinscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#join().("."); |
| 23 | } |
| 24 | |
| 25 | let FileClassscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/FileClass.: typeof Filescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File# | undefined = undefined; |
| 26 | |
| 27 | interface HelperMetadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata# { |
| 28 | globalsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#globals.: string[]; |
| 29 | localBindingNamesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#localBindingNames.: string[]; |
| 30 | dependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#dependencies.: Mapscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#, string>; |
| 31 | exportBindingAssignmentsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportBindingAssignments.: string[]; |
| 32 | exportPathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportPath.: string; |
| 33 | exportNamescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportName.: string; |
| 34 | importBindingsReferencesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#importBindingsReferences.: string[]; |
| 35 | importPathsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#importPaths.: string[]; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Given a file AST for a given helper, get a bunch of metadata about it so that Babel can quickly render |
| 40 | * the helper is whatever context it is needed in. |
| 41 | */ |
| 42 | function getHelperMetadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(filescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(file): Filescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#): HelperMetadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata# { |
| 43 | const globals = new Setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#<string>(); |
| 44 | const localBindingNames = new Setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#<string>(); |
| 45 | // Maps imported identifier -> helper name |
| 46 | const dependencies = new Mapscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#, string>(); |
| 47 | |
| 48 | let exportName: string | undefined; |
| 49 | let exportPath: string | undefined; |
| 50 | const exportBindingAssignments: string[] = []; |
| 51 | const importPaths: string[] = []; |
| 52 | const importBindingsReferences: string[] = []; |
| 53 | |
| 54 | const dependencyVisitor: Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor# = { |
| 55 | ImportDeclaration(child) { |
| 56 | const name = child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..sourcescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ImportDeclaration#source..valuescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/StringLiteral#value.; |
| 57 | if (!helpersscip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/helpers.[name]) { |
| 58 | throw child.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().(`Unknown helper ${name}`); |
| 59 | } |
| 60 | if ( |
| 61 | child.get("specifiers").lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. !== 1 || |
| 62 | // @ts-expect-error isImportDefaultSpecifier does not work with NodePath union |
| 63 | !child.get("specifiers.0").isImportDefaultSpecifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isImportDefaultSpecifier().() |
| 64 | ) { |
| 65 | throw child.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 66 | "Helpers can only import a default value", |
| 67 | ); |
| 68 | } |
| 69 | const bindingIdentifier = child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..specifiersscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ImportDeclaration#specifiers.[0].localscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ImportDefaultSpecifier#local.; |
| 70 | dependencies.setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#set().(bindingIdentifier, name); |
| 71 | importPaths.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(makePathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(child)); |
| 72 | }, |
| 73 | ExportDefaultDeclaration(child) { |
| 74 | const decl = child.get("declaration"); |
| 75 | |
| 76 | if (!decl.isFunctionDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunctionDeclaration().() || !decl.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..idscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/FunctionDeclaration#id.) { |
| 77 | throw decl.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 78 | "Helpers can only export named function declarations", |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | exportName = decl.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..idscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/FunctionDeclaration#id..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.; |
| 83 | exportPath = makePathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(child); |
| 84 | }, |
| 85 | ExportAllDeclaration(child) { |
| 86 | throw child.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().("Helpers can only export default"); |
| 87 | }, |
| 88 | ExportNamedDeclaration(child) { |
| 89 | throw child.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().("Helpers can only export default"); |
| 90 | }, |
| 91 | Statementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Aliases#Statement.(child) { |
| 92 | if (child.isImportDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isImportDeclaration().() || child.isExportDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isExportDeclaration().()) return; |
| 93 | |
| 94 | child.skipscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/skip().(); |
| 95 | }, |
| 96 | }; |
| 97 | |
| 98 | const referenceVisitor: Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor# = { |
| 99 | Program(path) { |
| 100 | const bindings = path.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getAllBindingsscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getAllBindings().(); |
| 101 | |
| 102 | Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.keysscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#keys().(bindings).forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(name => { |
| 103 | if (name === exportName) return; |
| 104 | if (dependencies.hasscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#has().(bindings[name].identifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#identifier.)) return; |
| 105 | |
| 106 | localBindingNames.addscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#add().(name); |
| 107 | }); |
| 108 | }, |
| 109 | ReferencedIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types.ts`/VirtualTypeAliases#ReferencedIdentifier.(child) { |
| 110 | const name = child.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.; |
| 111 | const binding = child.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().(name); |
| 112 | if (!binding) { |
| 113 | globals.addscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#add().(name); |
| 114 | } else if (dependencies.hasscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#has().(binding.identifierscip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#identifier.)) { |
| 115 | importBindingsReferences.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(makePathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(child)); |
| 116 | } |
| 117 | }, |
| 118 | AssignmentExpression(child) { |
| 119 | const left = child.get("left"); |
| 120 | |
| 121 | if (!(exportName in left.getBindingIdentifiers())) return; |
| 122 | |
| 123 | if (!left.isIdentifierscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isIdentifier().()) { |
| 124 | throw left.buildCodeFrameErrorscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#buildCodeFrameError().( |
| 125 | "Only simple assignments to exports are allowed in helpers", |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | const binding = child.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..getBindingscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#getBinding().(exportName); |
| 130 | |
| 131 | if (binding?.scopescip-typescript npm @babel/traverse 7.20.13 src/scope/`binding.ts`/Binding#scope..pathscip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#path..isProgramscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isProgram().()) { |
| 132 | exportBindingAssignments.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(makePathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/makePath().(child)); |
| 133 | } |
| 134 | }, |
| 135 | }; |
| 136 | |
| 137 | traversescip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/traverse().(filescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(file).astscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#ast., dependencyVisitor, filescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(file).scopescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#scope.); |
| 138 | traversescip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/traverse().(filescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(file).astscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#ast., referenceVisitor, filescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(file).scopescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#scope.); |
| 139 | |
| 140 | if (!exportPath) throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#("Helpers must have a default export."); |
| 141 | |
| 142 | // Process these in reverse so that mutating the references does not invalidate any later paths in |
| 143 | // the list. |
| 144 | exportBindingAssignments.reversescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#reverse().(); |
| 145 | |
| 146 | return { |
| 147 | globalsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#globals.: Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#.fromscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/ArrayConstructor#from().(globals), |
| 148 | localBindingNamesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#localBindingNames.: Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#.fromscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/ArrayConstructor#from().(localBindingNames), |
| 149 | dependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#dependencies., |
| 150 | exportBindingAssignmentsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportBindingAssignments., |
| 151 | exportPathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportPath., |
| 152 | exportNamescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportName., |
| 153 | importBindingsReferencesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#importBindingsReferences., |
| 154 | importPathsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#importPaths., |
| 155 | }; |
| 156 | } |
| 157 | |
| 158 | type GetDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/GetDependency# = (name: string) => tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#; |
| 159 | |
| 160 | /** |
| 161 | * Given a helper AST and information about how it will be used, update the AST to match the usage. |
| 162 | */ |
| 163 | function permuteHelperASTscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().( |
| 164 | filescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(file): Filescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#, |
| 165 | metadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(metadata): HelperMetadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#, |
| 166 | idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id)?: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#, |
| 167 | localBindingsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(localBindings)?: string[], |
| 168 | getDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(getDependency)?: GetDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/GetDependency#, |
| 169 | ) { |
| 170 | if (localBindingsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(localBindings) && !idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id)) { |
| 171 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#("Unexpected local bindings for module-based helpers."); |
| 172 | } |
| 173 | |
| 174 | if (!idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id)) return; |
| 175 | |
| 176 | const { |
| 177 | localBindingNamesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#localBindingNames., |
| 178 | dependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#dependencies., |
| 179 | exportBindingAssignmentsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportBindingAssignments., |
| 180 | exportPathscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportPath., |
| 181 | exportNamescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#exportName., |
| 182 | importBindingsReferencesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#importBindingsReferences., |
| 183 | importPathsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#importPaths., |
| 184 | } = metadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(metadata); |
| 185 | |
| 186 | const dependenciesRefs: Recordscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Record#<string, tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#> = {}; |
| 187 | dependencies.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Map#forEach().((name, id) => { |
| 188 | dependenciesRefs[id.namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.] = |
| 189 | (typeof getDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(getDependency) === "function" && getDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(getDependency)(name)) || id; |
| 190 | }); |
| 191 | |
| 192 | const toRename: Recordscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Record#<string, string> = {}; |
| 193 | const bindings = new Setscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#(localBindingsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(localBindings) || []); |
| 194 | localBindingNames.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(name => { |
| 195 | let newName = name; |
| 196 | while (bindings.hasscip-typescript npm typescript 5.9.3 lib/`lib.es2015.collection.d.ts`/Set#has().(newName)) newName = "_" + newName; |
| 197 | |
| 198 | if (newName !== name) toRename[name] = newName; |
| 199 | }); |
| 200 | |
| 201 | if (idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id).typescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#type. === "Identifier" && exportName !== idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id).namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.) { |
| 202 | toRename[exportName] = idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id).namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.; |
| 203 | } |
| 204 | |
| 205 | const { pathscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#path. } = filescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(file); |
| 206 | |
| 207 | // We need to compute these in advance because removing nodes would |
| 208 | // invalidate the paths. |
| 209 | const exp: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ExportDefaultDeclarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ExportDefaultDeclaration#> = path.get(exportPath); |
| 210 | const imps: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.ImportDeclarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/ImportDeclaration#>[] = importPaths.mapscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#map().(p => |
| 211 | path.get(p), |
| 212 | ); |
| 213 | const impsBindingRefs: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#>[] = |
| 214 | importBindingsReferences.mapscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#map().(p => path.get(p)); |
| 215 | |
| 216 | // We assert that this is a FunctionDeclaration in dependencyVisitor. |
| 217 | const decl = exp.get("declaration") as NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.FunctionDeclarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/FunctionDeclaration#>; |
| 218 | |
| 219 | if (idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id).typescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#type. === "Identifier") { |
| 220 | exp.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(decl); |
| 221 | } else if (idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id).typescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#type. === "MemberExpression") { |
| 222 | exportBindingAssignments.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(assignPath => { |
| 223 | const assign: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#> = path.get(assignPath); |
| 224 | assign.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id), assign.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.)); |
| 225 | }); |
| 226 | exp.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(decl); |
| 227 | path.pushContainerscip-typescript npm @babel/traverse 7.20.13 src/path/`modification.ts`/pushContainer().( |
| 228 | "body", |
| 229 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement().( |
| 230 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(id), identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(exportName)), |
| 231 | ), |
| 232 | ); |
| 233 | } else { |
| 234 | throw new Errorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Error#("Unexpected helper format."); |
| 235 | } |
| 236 | |
| 237 | Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.keysscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#keys().(toRename).forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(name => { |
| 238 | path.scopescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#scope..renamescip-typescript npm @babel/traverse 7.20.13 src/scope/`index.ts`/Scope#rename().(name, toRename[name]); |
| 239 | }); |
| 240 | |
| 241 | for (const path of imps) path.removescip-typescript npm @babel/traverse 7.20.13 src/path/`removal.ts`/remove().(); |
| 242 | for (const path of impsBindingRefs) { |
| 243 | const node = cloneNodescip-typescript npm @babel/types 7.20.7 src/clone/`cloneNode.ts`/cloneNode().(dependenciesRefs[path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..namescip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier#name.]); |
| 244 | path.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(node); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | interface HelperDatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData# { |
| 249 | buildscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#build.: ( |
| 250 | getDependency: GetDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/GetDependency#, |
| 251 | id: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#, |
| 252 | localBindings: string[], |
| 253 | ) => { |
| 254 | nodes: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Programscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Program#["body"scip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Program#body.]; |
| 255 | globals: string[]; |
| 256 | }; |
| 257 | minVersionscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#minVersion.: string; |
| 258 | getDependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#getDependencies.: () => string[]; |
| 259 | } |
| 260 | |
| 261 | const helperDatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/helperData.: Recordscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Record#<string, HelperDatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#> = Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.createscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#create().(null); |
| 262 | function loadHelperscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name): string) { |
| 263 | if (!helperDatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/helperData.[namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name)]) { |
| 264 | const helper = helpersscip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/helpers.[namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name)]; |
| 265 | if (!helper) { |
| 266 | throw Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.assignscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/ObjectConstructor#assign().(new ReferenceErrorscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ReferenceError#(`Unknown helper ${namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name)}`), { |
| 267 | codescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/code0:: "BABEL_HELPER_UNKNOWN", |
| 268 | helperscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/helper0:: namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name), |
| 269 | }); |
| 270 | } |
| 271 | |
| 272 | const fn = (): Filescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File# => { |
| 273 | if (!process.env.BABEL_8_BREAKING) { |
| 274 | if (!FileClassscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/FileClass.) { |
| 275 | const fakeFile = { astscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#ast.: filescip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/file().(helper.astscip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/Helper#ast.()), pathscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#path.: null } as Filescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#; |
| 276 | traversescip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/traverse().(fakeFile.astscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#ast., { |
| 277 | Programscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/Program0:: path => (fakeFile.pathscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#path. = path).stopscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/stop().(), |
| 278 | }); |
| 279 | return fakeFile; |
| 280 | } |
| 281 | } |
| 282 | return new FileClassscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/FileClass.( |
| 283 | { filenamescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/filename0:: `babel-helper://${namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name)}` }, |
| 284 | { |
| 285 | astscip-typescript npm @babel/core 7.20.12 src/transformation/`normalize-file.ts`/NormalizedFile#typeLiteral216:ast.: filescip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/file().(helper.astscip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/Helper#ast.()), |
| 286 | codescip-typescript npm @babel/core 7.20.12 src/transformation/`normalize-file.ts`/NormalizedFile#typeLiteral216:code.: "[internal Babel helper code]", |
| 287 | inputMapscip-typescript npm @babel/core 7.20.12 src/transformation/`normalize-file.ts`/NormalizedFile#typeLiteral216:inputMap.: null, |
| 288 | }, |
| 289 | ); |
| 290 | }; |
| 291 | |
| 292 | // We compute the helper metadata lazily, so that we skip that |
| 293 | // work if we only need the `.minVersion` (for example because |
| 294 | // of a call to `.availableHelper` when `@babel/rutime`). |
| 295 | let metadata: HelperMetadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata# | null = null; |
| 296 | |
| 297 | helperDatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/helperData.[namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name)] = { |
| 298 | minVersionscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#minVersion.: helper.minVersionscip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/Helper#minVersion., |
| 299 | buildscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#build.(getDependency, id, localBindings) { |
| 300 | const file = fn(); |
| 301 | metadata ||= getHelperMetadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(file); |
| 302 | permuteHelperASTscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/permuteHelperAST().(file, metadata, id, localBindings, getDependency); |
| 303 | |
| 304 | return { |
| 305 | nodes: file.astscip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#ast..programscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/File#program..bodyscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Program#body., |
| 306 | globals: metadata.globalsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#globals., |
| 307 | }; |
| 308 | }, |
| 309 | getDependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#getDependencies.() { |
| 310 | metadata ||= getHelperMetadatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getHelperMetadata().(fn()); |
| 311 | return Arrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#.fromscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/ArrayConstructor#from().(metadata.dependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperMetadata#dependencies..valuesscip-typescript npm typescript 5.9.3 lib/`lib.es2015.iterable.d.ts`/Map#values().()); |
| 312 | }, |
| 313 | }; |
| 314 | } |
| 315 | |
| 316 | return helperDatascip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/helperData.[namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(name)]; |
| 317 | } |
| 318 | |
| 319 | export function getscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().( |
| 320 | namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(name): string, |
| 321 | getDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(getDependency)?: GetDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/GetDependency#, |
| 322 | idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(id)?: tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Identifierscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Identifier# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.MemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/MemberExpression#, |
| 323 | localBindingsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(localBindings)?: string[], |
| 324 | ) { |
| 325 | return loadHelperscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(name)).buildscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#build.(getDependencyscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(getDependency), idscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(id), localBindingsscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().(localBindings)); |
| 326 | } |
| 327 | |
| 328 | export function minVersionscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/minVersion().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/minVersion().(name): string) { |
| 329 | return loadHelperscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/minVersion().(name)).minVersionscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#minVersion.; |
| 330 | } |
| 331 | |
| 332 | export function getDependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getDependencies().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getDependencies().(name): string): ReadonlyArrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ReadonlyArray#<string> { |
| 333 | return loadHelperscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/getDependencies().(name)).getDependenciesscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/HelperData#getDependencies.(); |
| 334 | } |
| 335 | |
| 336 | export function ensurescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/ensure().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/ensure().(name): string, newFileClassscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/ensure().(newFileClass): typeof Filescip-typescript npm @babel/core 7.20.12 src/transformation/file/`file.ts`/File#) { |
| 337 | // We inject the File class here rather than importing it to avoid |
| 338 | // circular dependencies between @babel/core and @babel/helpers. |
| 339 | FileClassscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/FileClass. ||= newFileClassscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/ensure().(newFileClass); |
| 340 | |
| 341 | loadHelperscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/loadHelper().(namescip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/ensure().(name)); |
| 342 | } |
| 343 | |
| 344 | export const listscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/list. = Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.keysscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#keys().(helpersscip-typescript npm @babel/helpers 7.20.13 src/`helpers.ts`/helpers.).mapscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#map().(name => name.replacescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/String#replace().(/^_/, "")); |
| 345 | |
| 346 | export default getscip-typescript npm @babel/helpers 7.20.13 src/`index.ts`/get().; |