( path: NodePath<t.Class>, file: File, builtinClasses: ReadonlySet<string>, assumptions: ClassAssumptions, supportUnicodeId: boolean, )
| 62 | }; |
| 63 | |
| 64 | export default function transformClass( |
| 65 | path: NodePath<t.Class>, |
| 66 | file: File, |
| 67 | builtinClasses: ReadonlySet<string>, |
| 68 | assumptions: ClassAssumptions, |
| 69 | supportUnicodeId: boolean, |
| 70 | ) { |
| 71 | const classState: State = { |
| 72 | classRef: undefined, |
| 73 | superName: null, |
| 74 | superReturns: [], |
| 75 | |
| 76 | construct: undefined, |
| 77 | userConstructorPath: undefined, |
| 78 | |
| 79 | body: [], |
| 80 | superThises: [], |
| 81 | pushedCreateClass: false, |
| 82 | protoAlias: null, |
| 83 | |
| 84 | dynamicKeys: new Map(), |
| 85 | |
| 86 | methods: { |
| 87 | instance: { |
| 88 | hasComputed: false, |
| 89 | list: [], |
| 90 | map: new Map(), |
| 91 | }, |
| 92 | static: { |
| 93 | hasComputed: false, |
| 94 | list: [], |
| 95 | map: new Map(), |
| 96 | }, |
| 97 | }, |
| 98 | }; |
| 99 | const scope = path.scope; |
| 100 | |
| 101 | const findThisesVisitor = visitors.environmentVisitor({ |
| 102 | ThisExpression(path) { |
| 103 | classState.superThises.push(path); |
| 104 | }, |
| 105 | }); |
| 106 | |
| 107 | function createClassHelper(args: t.Expression[]) { |
| 108 | return t.callExpression(file.addHelper("createClass"), args); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Creates a class constructor or bail out if there is one |
| 113 | */ |
| 114 | function maybeCreateConstructor() { |
| 115 | const classBodyPath = path.get("body"); |
| 116 | if ( |
| 117 | classBodyPath.node.body.some( |
| 118 | path => t.isClassMethod(path) && path.kind === "constructor", |
| 119 | ) |
| 120 | ) { |
| 121 | return; |
no test coverage detected