MCPcopy Create free account
hub / github.com/babel/babel / pushBody

Function pushBody

packages/babel-plugin-transform-classes/src/transformClass.ts:141–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

139 }
140
141 function pushBody() {
142 const classBodyPaths: any[] = path.get("body.body");
143
144 for (const path of classBodyPaths) {
145 const node = path.node;
146
147 if (path.isClassProperty() || path.isClassPrivateProperty()) {
148 throw path.buildCodeFrameError("Missing class properties transform.");
149 }
150
151 if (node.decorators) {
152 throw path.buildCodeFrameError(
153 "Method has decorators, put the decorator plugin before the classes one.",
154 );
155 }
156
157 if (t.isClassMethod(node)) {
158 const isConstructor = node.kind === "constructor";
159
160 const replaceSupers = new ReplaceSupers({
161 methodPath: path,
162 objectRef: classState.classRef,
163 superRef: classState.superName,
164 constantSuper: assumptions.constantSuper,
165 file: file,
166 refToPreserve: classState.classRef,
167 });
168
169 replaceSupers.replace();
170
171 if (isConstructor) {
172 const superReturns: NodePath<t.ReturnStatement>[] = [];
173 path.traverse(
174 visitors.environmentVisitor({
175 ReturnStatement(path) {
176 if (!path.getFunctionParent()!.isArrowFunctionExpression()) {
177 superReturns.push(path);
178 }
179 },
180 }),
181 );
182 classState.superReturns = superReturns;
183 classState.userConstructorPath = path;
184 // Replace the constructor body of our class.
185 t.inheritsComments(classState.construct!, node).params =
186 node.params as t.FunctionParameter[];
187 } else {
188 path.ensureFunctionName(supportUnicodeId);
189 let wrapped;
190 if (node !== path.node) {
191 wrapped = path.node;
192 // The node has been wrapped. Reset it to the original once, but store the wrapper.
193 path.replaceWith(node);
194 }
195
196 pushMethod(node, wrapped);
197 }
198 }

Callers 1

classTransformerFunction · 0.85

Calls 8

replaceMethod · 0.95
pushMethodFunction · 0.85
traverseMethod · 0.80
getMethod · 0.65
isClassPropertyMethod · 0.65
isClassMethodMethod · 0.65
buildCodeFrameErrorMethod · 0.45

Tested by

no test coverage detected