| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.ClassAccessorProperty = ClassAccessorProperty;
|
|---|
| 7 | exports.ClassBody = ClassBody;
|
|---|
| 8 | exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration;
|
|---|
| 9 | exports.ClassMethod = ClassMethod;
|
|---|
| 10 | exports.ClassPrivateMethod = ClassPrivateMethod;
|
|---|
| 11 | exports.ClassPrivateProperty = ClassPrivateProperty;
|
|---|
| 12 | exports.ClassProperty = ClassProperty;
|
|---|
| 13 | exports.StaticBlock = StaticBlock;
|
|---|
| 14 | exports._classMethodHead = _classMethodHead;
|
|---|
| 15 | var _t = require("@babel/types");
|
|---|
| 16 | var _expressions = require("./expressions.js");
|
|---|
| 17 | var _typescript = require("./typescript.js");
|
|---|
| 18 | var _flow = require("./flow.js");
|
|---|
| 19 | var _methods = require("./methods.js");
|
|---|
| 20 | const {
|
|---|
| 21 | isExportDefaultDeclaration,
|
|---|
| 22 | isExportNamedDeclaration
|
|---|
| 23 | } = _t;
|
|---|
| 24 | function ClassDeclaration(node, parent) {
|
|---|
| 25 | const inExport = isExportDefaultDeclaration(parent) || isExportNamedDeclaration(parent);
|
|---|
| 26 | if (!inExport || !_expressions._shouldPrintDecoratorsBeforeExport.call(this, parent)) {
|
|---|
| 27 | this.printJoin(node.decorators);
|
|---|
| 28 | }
|
|---|
| 29 | if (node.declare) {
|
|---|
| 30 | this.word("declare");
|
|---|
| 31 | this.space();
|
|---|
| 32 | }
|
|---|
| 33 | if (node.abstract) {
|
|---|
| 34 | this.word("abstract");
|
|---|
| 35 | this.space();
|
|---|
| 36 | }
|
|---|
| 37 | this.word("class");
|
|---|
| 38 | if (node.id) {
|
|---|
| 39 | this.space();
|
|---|
| 40 | this.print(node.id);
|
|---|
| 41 | }
|
|---|
| 42 | this.print(node.typeParameters);
|
|---|
| 43 | if (node.superClass) {
|
|---|
| 44 | this.space();
|
|---|
| 45 | this.word("extends");
|
|---|
| 46 | this.space();
|
|---|
| 47 | this.print(node.superClass);
|
|---|
| 48 | this.print(node.superTypeParameters);
|
|---|
| 49 | }
|
|---|
| 50 | if (node.implements) {
|
|---|
| 51 | this.space();
|
|---|
| 52 | this.word("implements");
|
|---|
| 53 | this.space();
|
|---|
| 54 | this.printList(node.implements);
|
|---|
| 55 | }
|
|---|
| 56 | this.space();
|
|---|
| 57 | this.print(node.body);
|
|---|
| 58 | }
|
|---|
| 59 | function ClassBody(node) {
|
|---|
| 60 | this.tokenChar(123);
|
|---|
| 61 | if (node.body.length === 0) {
|
|---|
| 62 | this.tokenChar(125);
|
|---|
| 63 | } else {
|
|---|
| 64 | const separator = classBodyEmptySemicolonsPrinter(this, node);
|
|---|
| 65 | separator == null || separator(-1);
|
|---|
| 66 | const oldNoLineTerminatorAfterNode = this.enterDelimited();
|
|---|
| 67 | this.printJoin(node.body, true, true, separator, true, true);
|
|---|
| 68 | this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
|
|---|
| 69 | if (!this.endsWith(10)) this.newline();
|
|---|
| 70 | this.rightBrace(node);
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 | function classBodyEmptySemicolonsPrinter(printer, node) {
|
|---|
| 74 | if (!printer.tokenMap || node.start == null || node.end == null) {
|
|---|
| 75 | return null;
|
|---|
| 76 | }
|
|---|
| 77 | const indexes = printer.tokenMap.getIndexes(node);
|
|---|
| 78 | if (!indexes) return null;
|
|---|
| 79 | let k = 1;
|
|---|
| 80 | let occurrenceCount = 0;
|
|---|
| 81 | let nextLocIndex = 0;
|
|---|
| 82 | const advanceNextLocIndex = () => {
|
|---|
| 83 | while (nextLocIndex < node.body.length && node.body[nextLocIndex].start == null) {
|
|---|
| 84 | nextLocIndex++;
|
|---|
| 85 | }
|
|---|
| 86 | };
|
|---|
| 87 | advanceNextLocIndex();
|
|---|
| 88 | return i => {
|
|---|
| 89 | if (nextLocIndex <= i) {
|
|---|
| 90 | nextLocIndex = i + 1;
|
|---|
| 91 | advanceNextLocIndex();
|
|---|
| 92 | }
|
|---|
| 93 | const end = nextLocIndex === node.body.length ? node.end : node.body[nextLocIndex].start;
|
|---|
| 94 | let tok;
|
|---|
| 95 | while (k < indexes.length && printer.tokenMap.matchesOriginal(tok = printer._tokens[indexes[k]], ";") && tok.start < end) {
|
|---|
| 96 | printer.tokenChar(59, occurrenceCount++);
|
|---|
| 97 | k++;
|
|---|
| 98 | }
|
|---|
| 99 | };
|
|---|
| 100 | }
|
|---|
| 101 | function ClassProperty(node) {
|
|---|
| 102 | this.printJoin(node.decorators);
|
|---|
| 103 | if (!node.static && !this.format.preserveFormat) {
|
|---|
| 104 | var _node$key$loc;
|
|---|
| 105 | const endLine = (_node$key$loc = node.key.loc) == null || (_node$key$loc = _node$key$loc.end) == null ? void 0 : _node$key$loc.line;
|
|---|
| 106 | if (endLine) this.catchUp(endLine);
|
|---|
| 107 | }
|
|---|
| 108 | _typescript._tsPrintClassMemberModifiers.call(this, node);
|
|---|
| 109 | if (node.computed) {
|
|---|
| 110 | this.tokenChar(91);
|
|---|
| 111 | this.print(node.key);
|
|---|
| 112 | this.tokenChar(93);
|
|---|
| 113 | } else {
|
|---|
| 114 | _flow._variance.call(this, node);
|
|---|
| 115 | this.print(node.key);
|
|---|
| 116 | }
|
|---|
| 117 | if (node.optional) {
|
|---|
| 118 | this.tokenChar(63);
|
|---|
| 119 | }
|
|---|
| 120 | if (node.definite) {
|
|---|
| 121 | this.tokenChar(33);
|
|---|
| 122 | }
|
|---|
| 123 | this.print(node.typeAnnotation);
|
|---|
| 124 | if (node.value) {
|
|---|
| 125 | this.space();
|
|---|
| 126 | this.tokenChar(61);
|
|---|
| 127 | this.space();
|
|---|
| 128 | this.print(node.value);
|
|---|
| 129 | }
|
|---|
| 130 | this.semicolon();
|
|---|
| 131 | }
|
|---|
| 132 | function ClassAccessorProperty(node) {
|
|---|
| 133 | var _node$key$loc2;
|
|---|
| 134 | this.printJoin(node.decorators);
|
|---|
| 135 | const endLine = (_node$key$loc2 = node.key.loc) == null || (_node$key$loc2 = _node$key$loc2.end) == null ? void 0 : _node$key$loc2.line;
|
|---|
| 136 | if (endLine) this.catchUp(endLine);
|
|---|
| 137 | _typescript._tsPrintClassMemberModifiers.call(this, node);
|
|---|
| 138 | this.word("accessor", true);
|
|---|
| 139 | this.space();
|
|---|
| 140 | if (node.computed) {
|
|---|
| 141 | this.tokenChar(91);
|
|---|
| 142 | this.print(node.key);
|
|---|
| 143 | this.tokenChar(93);
|
|---|
| 144 | } else {
|
|---|
| 145 | _flow._variance.call(this, node);
|
|---|
| 146 | this.print(node.key);
|
|---|
| 147 | }
|
|---|
| 148 | if (node.optional) {
|
|---|
| 149 | this.tokenChar(63);
|
|---|
| 150 | }
|
|---|
| 151 | if (node.definite) {
|
|---|
| 152 | this.tokenChar(33);
|
|---|
| 153 | }
|
|---|
| 154 | this.print(node.typeAnnotation);
|
|---|
| 155 | if (node.value) {
|
|---|
| 156 | this.space();
|
|---|
| 157 | this.tokenChar(61);
|
|---|
| 158 | this.space();
|
|---|
| 159 | this.print(node.value);
|
|---|
| 160 | }
|
|---|
| 161 | this.semicolon();
|
|---|
| 162 | }
|
|---|
| 163 | function ClassPrivateProperty(node) {
|
|---|
| 164 | this.printJoin(node.decorators);
|
|---|
| 165 | _typescript._tsPrintClassMemberModifiers.call(this, node);
|
|---|
| 166 | this.print(node.key);
|
|---|
| 167 | if (node.optional) {
|
|---|
| 168 | this.tokenChar(63);
|
|---|
| 169 | }
|
|---|
| 170 | if (node.definite) {
|
|---|
| 171 | this.tokenChar(33);
|
|---|
| 172 | }
|
|---|
| 173 | this.print(node.typeAnnotation);
|
|---|
| 174 | if (node.value) {
|
|---|
| 175 | this.space();
|
|---|
| 176 | this.tokenChar(61);
|
|---|
| 177 | this.space();
|
|---|
| 178 | this.print(node.value);
|
|---|
| 179 | }
|
|---|
| 180 | this.semicolon();
|
|---|
| 181 | }
|
|---|
| 182 | function ClassMethod(node) {
|
|---|
| 183 | _classMethodHead.call(this, node);
|
|---|
| 184 | this.space();
|
|---|
| 185 | this.print(node.body);
|
|---|
| 186 | }
|
|---|
| 187 | function ClassPrivateMethod(node) {
|
|---|
| 188 | _classMethodHead.call(this, node);
|
|---|
| 189 | this.space();
|
|---|
| 190 | this.print(node.body);
|
|---|
| 191 | }
|
|---|
| 192 | function _classMethodHead(node) {
|
|---|
| 193 | this.printJoin(node.decorators);
|
|---|
| 194 | if (!this.format.preserveFormat) {
|
|---|
| 195 | var _node$key$loc3;
|
|---|
| 196 | const endLine = (_node$key$loc3 = node.key.loc) == null || (_node$key$loc3 = _node$key$loc3.end) == null ? void 0 : _node$key$loc3.line;
|
|---|
| 197 | if (endLine) this.catchUp(endLine);
|
|---|
| 198 | }
|
|---|
| 199 | _typescript._tsPrintClassMemberModifiers.call(this, node);
|
|---|
| 200 | _methods._methodHead.call(this, node);
|
|---|
| 201 | }
|
|---|
| 202 | function StaticBlock(node) {
|
|---|
| 203 | this.word("static");
|
|---|
| 204 | this.space();
|
|---|
| 205 | this.tokenChar(123);
|
|---|
| 206 | if (node.body.length === 0) {
|
|---|
| 207 | this.tokenChar(125);
|
|---|
| 208 | } else {
|
|---|
| 209 | this.newline();
|
|---|
| 210 | this.printSequence(node.body, true);
|
|---|
| 211 | this.rightBrace(node);
|
|---|
| 212 | }
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | //# sourceMappingURL=classes.js.map
|
|---|