{"version":3,"names":["isExportDefaultDeclaration","isExportNamedDeclaration","ClassDeclaration","node","parent","format","decoratorsBeforeExport","printJoin","decorators","declare","word","space","abstract","id","print","typeParameters","superClass","superTypeParameters","implements","printList","body","ClassBody","token","length","newline","indent","printSequence","dedent","endsWith","sourceWithOffset","loc","rightBrace","ClassProperty","endLine","key","end","line","catchUp","tsPrintClassMemberModifiers","computed","_variance","optional","definite","typeAnnotation","value","semicolon","ClassAccessorProperty","ClassPrivateProperty","static","ClassMethod","_classMethodHead","ClassPrivateMethod","_methodHead","StaticBlock"],"sources":["../../src/generators/classes.ts"],"sourcesContent":["import type Printer from \"../printer\";\nimport {\n isExportDefaultDeclaration,\n isExportNamedDeclaration,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport * as charCodes from \"charcodes\";\n\nexport function ClassDeclaration(\n this: Printer,\n node: t.ClassDeclaration,\n parent: t.Node,\n) {\n if (process.env.BABEL_8_BREAKING) {\n this.printJoin(node.decorators, node);\n } else {\n if (\n !this.format.decoratorsBeforeExport ||\n (!isExportDefaultDeclaration(parent) && !isExportNamedDeclaration(parent))\n ) {\n this.printJoin(node.decorators, node);\n }\n }\n\n if (node.declare) {\n // TS\n this.word(\"declare\");\n this.space();\n }\n\n if (node.abstract) {\n // TS\n this.word(\"abstract\");\n this.space();\n }\n\n this.word(\"class\");\n\n if (node.id) {\n this.space();\n this.print(node.id, node);\n }\n\n this.print(node.typeParameters, node);\n\n if (node.superClass) {\n this.space();\n this.word(\"extends\");\n this.space();\n this.print(node.superClass, node);\n this.print(node.superTypeParameters, node);\n }\n\n if (node.implements) {\n this.space();\n this.word(\"implements\");\n this.space();\n this.printList(node.implements, node);\n }\n\n this.space();\n this.print(node.body, node);\n}\n\nexport { ClassDeclaration as ClassExpression };\n\nexport function ClassBody(this: Printer, node: t.ClassBody) {\n this.token(\"{\");\n if (node.body.length === 0) {\n this.token(\"}\");\n } else {\n this.newline();\n\n this.indent();\n this.printSequence(node.body, node);\n this.dedent();\n\n if (!this.endsWith(charCodes.lineFeed)) this.newline();\n\n this.sourceWithOffset(\"end\", node.loc, 0, -1);\n\n this.rightBrace();\n }\n}\n\nexport function ClassProperty(this: Printer, node: t.ClassProperty) {\n this.printJoin(node.decorators, node);\n\n // catch up to property key, avoid line break\n // between member modifiers and the property key.\n const endLine = node.key.loc?.end?.line;\n if (endLine) this.catchUp(endLine);\n\n this.tsPrintClassMemberModifiers(node);\n\n if (node.computed) {\n this.token(\"[\");\n this.print(node.key, node);\n this.token(\"]\");\n } else {\n this._variance(node);\n this.print(node.key, node);\n }\n\n // TS\n if (node.optional) {\n this.token(\"?\");\n }\n if (node.definite) {\n this.token(\"!\");\n }\n\n this.print(node.typeAnnotation, node);\n if (node.value) {\n this.space();\n this.token(\"=\");\n this.space();\n this.print(node.value, node);\n }\n this.semicolon();\n}\n\nexport function ClassAccessorProperty(\n this: Printer,\n node: t.ClassAccessorProperty,\n) {\n this.printJoin(node.decorators, node);\n\n // catch up to property key, avoid line break\n // between member modifiers and the property key.\n const endLine = node.key.loc?.end?.line;\n if (endLine) this.catchUp(endLine);\n\n // TS does not support class accessor property yet\n this.tsPrintClassMemberModifiers(node);\n\n this.word(\"accessor\", true);\n this.space();\n\n if (node.computed) {\n this.token(\"[\");\n this.print(node.key, node);\n this.token(\"]\");\n } else {\n // Todo: Flow does not support class accessor property yet.\n this._variance(node);\n this.print(node.key, node);\n }\n\n // TS\n if (node.optional) {\n this.token(\"?\");\n }\n if (node.definite) {\n this.token(\"!\");\n }\n\n this.print(node.typeAnnotation, node);\n if (node.value) {\n this.space();\n this.token(\"=\");\n this.space();\n this.print(node.value, node);\n }\n this.semicolon();\n}\n\nexport function ClassPrivateProperty(\n this: Printer,\n node: t.ClassPrivateProperty,\n) {\n this.printJoin(node.decorators, node);\n if (node.static) {\n this.word(\"static\");\n this.space();\n }\n this.print(node.key, node);\n this.print(node.typeAnnotation, node);\n if (node.value) {\n this.space();\n this.token(\"=\");\n this.space();\n this.print(node.value, node);\n }\n this.semicolon();\n}\n\nexport function ClassMethod(this: Printer, node: t.ClassMethod) {\n this._classMethodHead(node);\n this.space();\n this.print(node.body, node);\n}\n\nexport function ClassPrivateMethod(this: Printer, node: t.ClassPrivateMethod) {\n this._classMethodHead(node);\n this.space();\n this.print(node.body, node);\n}\n\nexport function _classMethodHead(\n this: Printer,\n node: t.ClassMethod | t.ClassPrivateMethod | t.TSDeclareMethod,\n) {\n this.printJoin(node.decorators, node);\n\n // catch up to method key, avoid line break\n // between member modifiers/method heads and the method key.\n const endLine = node.key.loc?.end?.line;\n if (endLine) this.catchUp(endLine);\n\n this.tsPrintClassMemberModifiers(node);\n this._methodHead(node);\n}\n\nexport function StaticBlock(this: Printer, node: t.StaticBlock) {\n this.word(\"static\");\n this.space();\n this.token(\"{\");\n if (node.body.length === 0) {\n this.token(\"}\");\n } else {\n this.newline();\n this.printSequence(node.body, node, {\n indent: true,\n });\n\n this.sourceWithOffset(\"end\", node.loc, 0, -1);\n\n this.rightBrace();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AACA;AAGsB;EAFpBA,0BAA0B;EAC1BC;AAAwB;AAKnB,SAASC,gBAAgB,CAE9BC,IAAwB,EACxBC,MAAc,EACd;EAGO;IACL,IACE,CAAC,IAAI,CAACC,MAAM,CAACC,sBAAsB,IAClC,CAACN,0BAA0B,CAACI,MAAM,CAAC,IAAI,CAACH,wBAAwB,CAACG,MAAM,CAAE,EAC1E;MACA,IAAI,CAACG,SAAS,CAACJ,IAAI,CAACK,UAAU,EAAEL,IAAI,CAAC;IACvC;EACF;EAEA,IAAIA,IAAI,CAACM,OAAO,EAAE;IAEhB,IAAI,CAACC,IAAI,CAAC,SAAS,CAAC;IACpB,IAAI,CAACC,KAAK,EAAE;EACd;EAEA,IAAIR,IAAI,CAACS,QAAQ,EAAE;IAEjB,IAAI,CAACF,IAAI,CAAC,UAAU,CAAC;IACrB,IAAI,CAACC,KAAK,EAAE;EACd;EAEA,IAAI,CAACD,IAAI,CAAC,OA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