| 1 | import { declarescip-typescript npm @babel/helper-plugin-utils 7.20.2 src/`index.ts`/declare(). } from "@babel/helper-plugin-utils"scip-typescript npm @babel/helper-plugin-utils 7.20.2 src/`index.ts`/; |
| 2 | import { types as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/ } from "@babel/core"scip-typescript npm @babel/core 7.20.12 src/`index.ts`/; |
| 3 | import type { NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath# } from "@babel/traverse"scip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/; |
| 4 | |
| 5 | export default declarescip-typescript npm @babel/helper-plugin-utils 7.20.2 src/`index.ts`/declare().(api => { |
| 6 | api.assertVersionscip-typescript npm @babel/core 7.20.12 src/config/helpers/`config-api.ts`/ConfigAPI#typeLiteral7:assertVersion.(7); |
| 7 | |
| 8 | function transformStatementList(paths: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Statementscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Statement#>[]) { |
| 9 | for (const path of paths) { |
| 10 | if (!path.isFunctionDeclarationscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isFunctionDeclaration().()) continue; |
| 11 | const func = path.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.; |
| 12 | const declar = tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.variableDeclarationscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/variableDeclaration().("let", [ |
| 13 | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.variableDeclaratorscip-typescript npm @babel/types 7.20.7 src/builders/generated/`index.ts`/variableDeclarator().(func.idscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/FunctionDeclaration#id., tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.toExpression(func)), |
| 14 | ]); |
| 15 | |
| 16 | // hoist it up above everything else |
| 17 | // @ts-expect-error todo(flow->ts): avoid mutations |
| 18 | declar._blockHoist = 2; |
| 19 | |
| 20 | // todo: name this |
| 21 | func.idscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/FunctionDeclaration#id. = null; |
| 22 | |
| 23 | path.replaceWithscip-typescript npm @babel/traverse 7.20.13 src/path/`replacement.ts`/replaceWith().(declar); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | return { |
| 28 | namescip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#typeLiteral0:name.: "transform-block-scoped-functions", |
| 29 | |
| 30 | visitorscip-typescript npm @babel/core 7.20.12 src/config/validation/`plugins.ts`/PluginObject#typeLiteral0:visitor.: { |
| 31 | BlockStatement(path) { |
| 32 | const { nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node., parentscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#parent. } = path; |
| 33 | if ( |
| 34 | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.isFunctionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isFunction().(parent, { bodyscip-typescript npm @babel/plugin-transform-block-scoped-functions 7.18.6 src/`index.ts`/body0:: node }) || |
| 35 | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.isExportDeclarationscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isExportDeclaration().(parent) |
| 36 | ) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | transformStatementList(path.get("body")); |
| 41 | }, |
| 42 | |
| 43 | SwitchCase(path) { |
| 44 | transformStatementList(path.get("consequent")); |
| 45 | }, |
| 46 | }, |
| 47 | }; |
| 48 | }); |