| 1 | import { |
| 2 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression()., |
| 3 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement()., |
| 4 | identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier()., |
| 5 | } from "@babel/types"scip-typescript npm @babel/types 7.20.7 src/`index.ts`/; |
| 6 | 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`/; |
| 7 | 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`/; |
| 8 | |
| 9 | export type EmitFunctionscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/EmitFunction# = ( |
| 10 | 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#, |
| 11 | idName: string, |
| 12 | hasInit: boolean, |
| 13 | ) => any; |
| 14 | |
| 15 | type Statescip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State# = { |
| 16 | kindscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State#typeLiteral4:kind.: "var" | "let"; |
| 17 | emitscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State#typeLiteral4:emit.: EmitFunctionscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/EmitFunction#; |
| 18 | }; |
| 19 | |
| 20 | type Unpackedscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/Unpacked#<Tscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/Unpacked#[T]> = Tscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/Unpacked#[T] extends (infer U)[] ? U : Tscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/Unpacked#[T]; |
| 21 | |
| 22 | const visitorscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/visitor.: Visitorscip-typescript npm @babel/traverse 7.20.13 src/`types.ts`/Visitor#<Statescip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State#> = { |
| 23 | Scopescip-typescript npm @babel/traverse 7.20.13 src/path/lib/`virtual-types.ts`/VirtualTypeAliases#Scope.(path, state) { |
| 24 | if (state.kindscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State#typeLiteral4:kind. === "let") path.skipscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/skip().(); |
| 25 | }, |
| 26 | |
| 27 | FunctionParentscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Aliases#FunctionParent.(path) { |
| 28 | path.skipscip-typescript npm @babel/traverse 7.20.13 src/path/`context.ts`/skip().(); |
| 29 | }, |
| 30 | |
| 31 | VariableDeclaration(path, state) { |
| 32 | if (state.kindscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State#typeLiteral4:kind. && path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..kindscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclaration#kind. !== state.kindscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State#typeLiteral4:kind.) return; |
| 33 | |
| 34 | const nodes = []; |
| 35 | |
| 36 | const declarations: ReadonlyArrayscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ReadonlyArray#< |
| 37 | NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<Unpackedscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/Unpacked#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.VariableDeclarationscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclaration#["declarations"scip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclaration#declarations.]>> |
| 38 | > = path.get("declarations"); |
| 39 | let firstId; |
| 40 | |
| 41 | for (const declar of declarations) { |
| 42 | firstId = declar.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`/VariableDeclarator#id.; |
| 43 | |
| 44 | if (declar.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..initscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclarator#init.) { |
| 45 | nodes.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().( |
| 46 | expressionStatementscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/expressionStatement().( |
| 47 | assignmentExpressionscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/assignmentExpression().("=", declar.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`/VariableDeclarator#id., declar.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..initscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclarator#init.), |
| 48 | ), |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | for (const name of 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().(declar.getBindingIdentifiers())) { |
| 53 | state.emitscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/State#typeLiteral4:emit.(identifierscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/identifier().(name), name, declar.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node..initscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/VariableDeclarator#init. !== null); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // for (var i in test) |
| 58 | if (path.parentPathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parentPath..isForscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFor().({ leftscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/left0:: path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node. })) { |
| 59 | path.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(firstId); |
| 60 | } else { |
| 61 | path.replaceWithMultiplescip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWithMultiple().(nodes); |
| 62 | } |
| 63 | }, |
| 64 | }; |
| 65 | |
| 66 | export default function hoistVariablesscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/hoistVariables().( |
| 67 | pathscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/hoistVariables().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#, |
| 68 | emitscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/hoistVariables().(emit): EmitFunctionscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/EmitFunction#, |
| 69 | kindscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/hoistVariables().(kind): "var" | "let" = "var", |
| 70 | ) { |
| 71 | pathscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/hoistVariables().(path).traversescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#traverse().(visitorscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/visitor., { kindscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/kind0:, emitscip-typescript npm @babel/helper-hoist-variables 7.18.6 src/`index.ts`/emit0: }); |
| 72 | } |