| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.AnyTypeAnnotation = AnyTypeAnnotation;
|
|---|
| 7 | exports.ArrayTypeAnnotation = ArrayTypeAnnotation;
|
|---|
| 8 | exports.BooleanLiteralTypeAnnotation = BooleanLiteralTypeAnnotation;
|
|---|
| 9 | exports.BooleanTypeAnnotation = BooleanTypeAnnotation;
|
|---|
| 10 | exports.DeclareClass = DeclareClass;
|
|---|
| 11 | exports.DeclareExportAllDeclaration = DeclareExportAllDeclaration;
|
|---|
| 12 | exports.DeclareExportDeclaration = DeclareExportDeclaration;
|
|---|
| 13 | exports.DeclareFunction = DeclareFunction;
|
|---|
| 14 | exports.DeclareInterface = DeclareInterface;
|
|---|
| 15 | exports.DeclareModule = DeclareModule;
|
|---|
| 16 | exports.DeclareModuleExports = DeclareModuleExports;
|
|---|
| 17 | exports.DeclareOpaqueType = DeclareOpaqueType;
|
|---|
| 18 | exports.DeclareTypeAlias = DeclareTypeAlias;
|
|---|
| 19 | exports.DeclareVariable = DeclareVariable;
|
|---|
| 20 | exports.DeclaredPredicate = DeclaredPredicate;
|
|---|
| 21 | exports.EmptyTypeAnnotation = EmptyTypeAnnotation;
|
|---|
| 22 | exports.EnumBooleanBody = EnumBooleanBody;
|
|---|
| 23 | exports.EnumBooleanMember = EnumBooleanMember;
|
|---|
| 24 | exports.EnumDeclaration = EnumDeclaration;
|
|---|
| 25 | exports.EnumDefaultedMember = EnumDefaultedMember;
|
|---|
| 26 | exports.EnumNumberBody = EnumNumberBody;
|
|---|
| 27 | exports.EnumNumberMember = EnumNumberMember;
|
|---|
| 28 | exports.EnumStringBody = EnumStringBody;
|
|---|
| 29 | exports.EnumStringMember = EnumStringMember;
|
|---|
| 30 | exports.EnumSymbolBody = EnumSymbolBody;
|
|---|
| 31 | exports.ExistsTypeAnnotation = ExistsTypeAnnotation;
|
|---|
| 32 | exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
|
|---|
| 33 | exports.FunctionTypeParam = FunctionTypeParam;
|
|---|
| 34 | exports.IndexedAccessType = IndexedAccessType;
|
|---|
| 35 | exports.InferredPredicate = InferredPredicate;
|
|---|
| 36 | exports.InterfaceDeclaration = InterfaceDeclaration;
|
|---|
| 37 | exports.GenericTypeAnnotation = exports.ClassImplements = exports.InterfaceExtends = InterfaceExtends;
|
|---|
| 38 | exports.InterfaceTypeAnnotation = InterfaceTypeAnnotation;
|
|---|
| 39 | exports.IntersectionTypeAnnotation = IntersectionTypeAnnotation;
|
|---|
| 40 | exports.MixedTypeAnnotation = MixedTypeAnnotation;
|
|---|
| 41 | exports.NullLiteralTypeAnnotation = NullLiteralTypeAnnotation;
|
|---|
| 42 | exports.NullableTypeAnnotation = NullableTypeAnnotation;
|
|---|
| 43 | Object.defineProperty(exports, "NumberLiteralTypeAnnotation", {
|
|---|
| 44 | enumerable: true,
|
|---|
| 45 | get: function () {
|
|---|
| 46 | return _types2.NumericLiteral;
|
|---|
| 47 | }
|
|---|
| 48 | });
|
|---|
| 49 | exports.NumberTypeAnnotation = NumberTypeAnnotation;
|
|---|
| 50 | exports.ObjectTypeAnnotation = ObjectTypeAnnotation;
|
|---|
| 51 | exports.ObjectTypeCallProperty = ObjectTypeCallProperty;
|
|---|
| 52 | exports.ObjectTypeIndexer = ObjectTypeIndexer;
|
|---|
| 53 | exports.ObjectTypeInternalSlot = ObjectTypeInternalSlot;
|
|---|
| 54 | exports.ObjectTypeProperty = ObjectTypeProperty;
|
|---|
| 55 | exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty;
|
|---|
| 56 | exports.OpaqueType = OpaqueType;
|
|---|
| 57 | exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
|
|---|
| 58 | exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier;
|
|---|
| 59 | Object.defineProperty(exports, "StringLiteralTypeAnnotation", {
|
|---|
| 60 | enumerable: true,
|
|---|
| 61 | get: function () {
|
|---|
| 62 | return _types2.StringLiteral;
|
|---|
| 63 | }
|
|---|
| 64 | });
|
|---|
| 65 | exports.StringTypeAnnotation = StringTypeAnnotation;
|
|---|
| 66 | exports.SymbolTypeAnnotation = SymbolTypeAnnotation;
|
|---|
| 67 | exports.ThisTypeAnnotation = ThisTypeAnnotation;
|
|---|
| 68 | exports.TupleTypeAnnotation = TupleTypeAnnotation;
|
|---|
| 69 | exports.TypeAlias = TypeAlias;
|
|---|
| 70 | exports.TypeAnnotation = TypeAnnotation;
|
|---|
| 71 | exports.TypeCastExpression = TypeCastExpression;
|
|---|
| 72 | exports.TypeParameter = TypeParameter;
|
|---|
| 73 | exports.TypeParameterDeclaration = exports.TypeParameterInstantiation = TypeParameterInstantiation;
|
|---|
| 74 | exports.TypeofTypeAnnotation = TypeofTypeAnnotation;
|
|---|
| 75 | exports.UnionTypeAnnotation = UnionTypeAnnotation;
|
|---|
| 76 | exports.Variance = Variance;
|
|---|
| 77 | exports.VoidTypeAnnotation = VoidTypeAnnotation;
|
|---|
| 78 | exports._interfaceish = _interfaceish;
|
|---|
| 79 | exports._variance = _variance;
|
|---|
| 80 | var _t = require("@babel/types");
|
|---|
| 81 | var _modules = require("./modules.js");
|
|---|
| 82 | var _index = require("../node/index.js");
|
|---|
| 83 | var _types2 = require("./types.js");
|
|---|
| 84 | const {
|
|---|
| 85 | isDeclareExportDeclaration,
|
|---|
| 86 | isStatement
|
|---|
| 87 | } = _t;
|
|---|
| 88 | function AnyTypeAnnotation() {
|
|---|
| 89 | this.word("any");
|
|---|
| 90 | }
|
|---|
| 91 | function ArrayTypeAnnotation(node) {
|
|---|
| 92 | this.print(node.elementType, true);
|
|---|
| 93 | this.tokenChar(91);
|
|---|
| 94 | this.tokenChar(93);
|
|---|
| 95 | }
|
|---|
| 96 | function BooleanTypeAnnotation() {
|
|---|
| 97 | this.word("boolean");
|
|---|
| 98 | }
|
|---|
| 99 | function BooleanLiteralTypeAnnotation(node) {
|
|---|
| 100 | this.word(node.value ? "true" : "false");
|
|---|
| 101 | }
|
|---|
| 102 | function NullLiteralTypeAnnotation() {
|
|---|
| 103 | this.word("null");
|
|---|
| 104 | }
|
|---|
| 105 | function DeclareClass(node, parent) {
|
|---|
| 106 | if (!isDeclareExportDeclaration(parent)) {
|
|---|
| 107 | this.word("declare");
|
|---|
| 108 | this.space();
|
|---|
| 109 | }
|
|---|
| 110 | this.word("class");
|
|---|
| 111 | this.space();
|
|---|
| 112 | _interfaceish.call(this, node);
|
|---|
| 113 | }
|
|---|
| 114 | function DeclareFunction(node, parent) {
|
|---|
| 115 | if (!isDeclareExportDeclaration(parent)) {
|
|---|
| 116 | this.word("declare");
|
|---|
| 117 | this.space();
|
|---|
| 118 | }
|
|---|
| 119 | this.word("function");
|
|---|
| 120 | this.space();
|
|---|
| 121 | this.print(node.id);
|
|---|
| 122 | this.print(node.id.typeAnnotation.typeAnnotation);
|
|---|
| 123 | if (node.predicate) {
|
|---|
| 124 | this.space();
|
|---|
| 125 | this.print(node.predicate);
|
|---|
| 126 | }
|
|---|
| 127 | this.semicolon();
|
|---|
| 128 | }
|
|---|
| 129 | function InferredPredicate() {
|
|---|
| 130 | this.tokenChar(37);
|
|---|
| 131 | this.word("checks");
|
|---|
| 132 | }
|
|---|
| 133 | function DeclaredPredicate(node) {
|
|---|
| 134 | this.tokenChar(37);
|
|---|
| 135 | this.word("checks");
|
|---|
| 136 | this.tokenChar(40);
|
|---|
| 137 | this.print(node.value);
|
|---|
| 138 | this.tokenChar(41);
|
|---|
| 139 | }
|
|---|
| 140 | function DeclareInterface(node) {
|
|---|
| 141 | this.word("declare");
|
|---|
| 142 | this.space();
|
|---|
| 143 | InterfaceDeclaration.call(this, node);
|
|---|
| 144 | }
|
|---|
| 145 | function DeclareModule(node) {
|
|---|
| 146 | this.word("declare");
|
|---|
| 147 | this.space();
|
|---|
| 148 | this.word("module");
|
|---|
| 149 | this.space();
|
|---|
| 150 | this.print(node.id);
|
|---|
| 151 | this.space();
|
|---|
| 152 | this.print(node.body);
|
|---|
| 153 | }
|
|---|
| 154 | function DeclareModuleExports(node) {
|
|---|
| 155 | this.word("declare");
|
|---|
| 156 | this.space();
|
|---|
| 157 | this.word("module");
|
|---|
| 158 | this.tokenChar(46);
|
|---|
| 159 | this.word("exports");
|
|---|
| 160 | this.print(node.typeAnnotation);
|
|---|
| 161 | }
|
|---|
| 162 | function DeclareTypeAlias(node) {
|
|---|
| 163 | this.word("declare");
|
|---|
| 164 | this.space();
|
|---|
| 165 | TypeAlias.call(this, node);
|
|---|
| 166 | }
|
|---|
| 167 | function DeclareOpaqueType(node, parent) {
|
|---|
| 168 | if (!isDeclareExportDeclaration(parent)) {
|
|---|
| 169 | this.word("declare");
|
|---|
| 170 | this.space();
|
|---|
| 171 | }
|
|---|
| 172 | OpaqueType.call(this, node);
|
|---|
| 173 | }
|
|---|
| 174 | function DeclareVariable(node, parent) {
|
|---|
| 175 | if (!isDeclareExportDeclaration(parent)) {
|
|---|
| 176 | this.word("declare");
|
|---|
| 177 | this.space();
|
|---|
| 178 | }
|
|---|
| 179 | this.word("var");
|
|---|
| 180 | this.space();
|
|---|
| 181 | this.print(node.id);
|
|---|
| 182 | this.print(node.id.typeAnnotation);
|
|---|
| 183 | this.semicolon();
|
|---|
| 184 | }
|
|---|
| 185 | function DeclareExportDeclaration(node) {
|
|---|
| 186 | this.word("declare");
|
|---|
| 187 | this.space();
|
|---|
| 188 | this.word("export");
|
|---|
| 189 | this.space();
|
|---|
| 190 | if (node.default) {
|
|---|
| 191 | this.word("default");
|
|---|
| 192 | this.space();
|
|---|
| 193 | }
|
|---|
| 194 | FlowExportDeclaration.call(this, node);
|
|---|
| 195 | }
|
|---|
| 196 | function DeclareExportAllDeclaration(node) {
|
|---|
| 197 | this.word("declare");
|
|---|
| 198 | this.space();
|
|---|
| 199 | _modules.ExportAllDeclaration.call(this, node);
|
|---|
| 200 | }
|
|---|
| 201 | function EnumDeclaration(node) {
|
|---|
| 202 | const {
|
|---|
| 203 | id,
|
|---|
| 204 | body
|
|---|
| 205 | } = node;
|
|---|
| 206 | this.word("enum");
|
|---|
| 207 | this.space();
|
|---|
| 208 | this.print(id);
|
|---|
| 209 | this.print(body);
|
|---|
| 210 | }
|
|---|
| 211 | function enumExplicitType(context, name, hasExplicitType) {
|
|---|
| 212 | if (hasExplicitType) {
|
|---|
| 213 | context.space();
|
|---|
| 214 | context.word("of");
|
|---|
| 215 | context.space();
|
|---|
| 216 | context.word(name);
|
|---|
| 217 | }
|
|---|
| 218 | context.space();
|
|---|
| 219 | }
|
|---|
| 220 | function enumBody(context, node) {
|
|---|
| 221 | const {
|
|---|
| 222 | members
|
|---|
| 223 | } = node;
|
|---|
| 224 | context.token("{");
|
|---|
| 225 | context.indent();
|
|---|
| 226 | context.newline();
|
|---|
| 227 | for (const member of members) {
|
|---|
| 228 | context.print(member);
|
|---|
| 229 | context.newline();
|
|---|
| 230 | }
|
|---|
| 231 | if (node.hasUnknownMembers) {
|
|---|
| 232 | context.token("...");
|
|---|
| 233 | context.newline();
|
|---|
| 234 | }
|
|---|
| 235 | context.dedent();
|
|---|
| 236 | context.token("}");
|
|---|
| 237 | }
|
|---|
| 238 | function EnumBooleanBody(node) {
|
|---|
| 239 | const {
|
|---|
| 240 | explicitType
|
|---|
| 241 | } = node;
|
|---|
| 242 | enumExplicitType(this, "boolean", explicitType);
|
|---|
| 243 | enumBody(this, node);
|
|---|
| 244 | }
|
|---|
| 245 | function EnumNumberBody(node) {
|
|---|
| 246 | const {
|
|---|
| 247 | explicitType
|
|---|
| 248 | } = node;
|
|---|
| 249 | enumExplicitType(this, "number", explicitType);
|
|---|
| 250 | enumBody(this, node);
|
|---|
| 251 | }
|
|---|
| 252 | function EnumStringBody(node) {
|
|---|
| 253 | const {
|
|---|
| 254 | explicitType
|
|---|
| 255 | } = node;
|
|---|
| 256 | enumExplicitType(this, "string", explicitType);
|
|---|
| 257 | enumBody(this, node);
|
|---|
| 258 | }
|
|---|
| 259 | function EnumSymbolBody(node) {
|
|---|
| 260 | enumExplicitType(this, "symbol", true);
|
|---|
| 261 | enumBody(this, node);
|
|---|
| 262 | }
|
|---|
| 263 | function EnumDefaultedMember(node) {
|
|---|
| 264 | const {
|
|---|
| 265 | id
|
|---|
| 266 | } = node;
|
|---|
| 267 | this.print(id);
|
|---|
| 268 | this.tokenChar(44);
|
|---|
| 269 | }
|
|---|
| 270 | function enumInitializedMember(context, node) {
|
|---|
| 271 | context.print(node.id);
|
|---|
| 272 | context.space();
|
|---|
| 273 | context.token("=");
|
|---|
| 274 | context.space();
|
|---|
| 275 | context.print(node.init);
|
|---|
| 276 | context.token(",");
|
|---|
| 277 | }
|
|---|
| 278 | function EnumBooleanMember(node) {
|
|---|
| 279 | enumInitializedMember(this, node);
|
|---|
| 280 | }
|
|---|
| 281 | function EnumNumberMember(node) {
|
|---|
| 282 | enumInitializedMember(this, node);
|
|---|
| 283 | }
|
|---|
| 284 | function EnumStringMember(node) {
|
|---|
| 285 | enumInitializedMember(this, node);
|
|---|
| 286 | }
|
|---|
| 287 | function FlowExportDeclaration(node) {
|
|---|
| 288 | if (node.declaration) {
|
|---|
| 289 | const declar = node.declaration;
|
|---|
| 290 | this.print(declar);
|
|---|
| 291 | if (!isStatement(declar)) this.semicolon();
|
|---|
| 292 | } else {
|
|---|
| 293 | this.tokenChar(123);
|
|---|
| 294 | if (node.specifiers.length) {
|
|---|
| 295 | this.space();
|
|---|
| 296 | this.printList(node.specifiers);
|
|---|
| 297 | this.space();
|
|---|
| 298 | }
|
|---|
| 299 | this.tokenChar(125);
|
|---|
| 300 | if (node.source) {
|
|---|
| 301 | this.space();
|
|---|
| 302 | this.word("from");
|
|---|
| 303 | this.space();
|
|---|
| 304 | this.print(node.source);
|
|---|
| 305 | }
|
|---|
| 306 | this.semicolon();
|
|---|
| 307 | }
|
|---|
| 308 | }
|
|---|
| 309 | function ExistsTypeAnnotation() {
|
|---|
| 310 | this.tokenChar(42);
|
|---|
| 311 | }
|
|---|
| 312 | function FunctionTypeAnnotation(node, parent) {
|
|---|
| 313 | this.print(node.typeParameters);
|
|---|
| 314 | this.tokenChar(40);
|
|---|
| 315 | if (node.this) {
|
|---|
| 316 | this.word("this");
|
|---|
| 317 | this.tokenChar(58);
|
|---|
| 318 | this.space();
|
|---|
| 319 | this.print(node.this.typeAnnotation);
|
|---|
| 320 | if (node.params.length || node.rest) {
|
|---|
| 321 | this.tokenChar(44);
|
|---|
| 322 | this.space();
|
|---|
| 323 | }
|
|---|
| 324 | }
|
|---|
| 325 | this.printList(node.params);
|
|---|
| 326 | if (node.rest) {
|
|---|
| 327 | if (node.params.length) {
|
|---|
| 328 | this.tokenChar(44);
|
|---|
| 329 | this.space();
|
|---|
| 330 | }
|
|---|
| 331 | this.token("...");
|
|---|
| 332 | this.print(node.rest);
|
|---|
| 333 | }
|
|---|
| 334 | this.tokenChar(41);
|
|---|
| 335 | const type = parent == null ? void 0 : parent.type;
|
|---|
| 336 | if (type != null && (type === "ObjectTypeCallProperty" || type === "ObjectTypeInternalSlot" || type === "DeclareFunction" || type === "ObjectTypeProperty" && parent.method)) {
|
|---|
| 337 | this.tokenChar(58);
|
|---|
| 338 | } else {
|
|---|
| 339 | this.space();
|
|---|
| 340 | this.token("=>");
|
|---|
| 341 | }
|
|---|
| 342 | this.space();
|
|---|
| 343 | this.print(node.returnType);
|
|---|
| 344 | }
|
|---|
| 345 | function FunctionTypeParam(node) {
|
|---|
| 346 | this.print(node.name);
|
|---|
| 347 | if (node.optional) this.tokenChar(63);
|
|---|
| 348 | if (node.name) {
|
|---|
| 349 | this.tokenChar(58);
|
|---|
| 350 | this.space();
|
|---|
| 351 | }
|
|---|
| 352 | this.print(node.typeAnnotation);
|
|---|
| 353 | }
|
|---|
| 354 | function InterfaceExtends(node) {
|
|---|
| 355 | this.print(node.id);
|
|---|
| 356 | this.print(node.typeParameters, true);
|
|---|
| 357 | }
|
|---|
| 358 | function _interfaceish(node) {
|
|---|
| 359 | var _node$extends;
|
|---|
| 360 | this.print(node.id);
|
|---|
| 361 | this.print(node.typeParameters);
|
|---|
| 362 | if ((_node$extends = node.extends) != null && _node$extends.length) {
|
|---|
| 363 | this.space();
|
|---|
| 364 | this.word("extends");
|
|---|
| 365 | this.space();
|
|---|
| 366 | this.printList(node.extends);
|
|---|
| 367 | }
|
|---|
| 368 | if (node.type === "DeclareClass") {
|
|---|
| 369 | var _node$mixins, _node$implements;
|
|---|
| 370 | if ((_node$mixins = node.mixins) != null && _node$mixins.length) {
|
|---|
| 371 | this.space();
|
|---|
| 372 | this.word("mixins");
|
|---|
| 373 | this.space();
|
|---|
| 374 | this.printList(node.mixins);
|
|---|
| 375 | }
|
|---|
| 376 | if ((_node$implements = node.implements) != null && _node$implements.length) {
|
|---|
| 377 | this.space();
|
|---|
| 378 | this.word("implements");
|
|---|
| 379 | this.space();
|
|---|
| 380 | this.printList(node.implements);
|
|---|
| 381 | }
|
|---|
| 382 | }
|
|---|
| 383 | this.space();
|
|---|
| 384 | this.print(node.body);
|
|---|
| 385 | }
|
|---|
| 386 | function _variance(node) {
|
|---|
| 387 | var _node$variance;
|
|---|
| 388 | const kind = (_node$variance = node.variance) == null ? void 0 : _node$variance.kind;
|
|---|
| 389 | if (kind != null) {
|
|---|
| 390 | if (kind === "plus") {
|
|---|
| 391 | this.tokenChar(43);
|
|---|
| 392 | } else if (kind === "minus") {
|
|---|
| 393 | this.tokenChar(45);
|
|---|
| 394 | }
|
|---|
| 395 | }
|
|---|
| 396 | }
|
|---|
| 397 | function InterfaceDeclaration(node) {
|
|---|
| 398 | this.word("interface");
|
|---|
| 399 | this.space();
|
|---|
| 400 | _interfaceish.call(this, node);
|
|---|
| 401 | }
|
|---|
| 402 | function andSeparator(occurrenceCount) {
|
|---|
| 403 | this.space();
|
|---|
| 404 | this.token("&", false, occurrenceCount);
|
|---|
| 405 | this.space();
|
|---|
| 406 | }
|
|---|
| 407 | function InterfaceTypeAnnotation(node) {
|
|---|
| 408 | var _node$extends2;
|
|---|
| 409 | this.word("interface");
|
|---|
| 410 | if ((_node$extends2 = node.extends) != null && _node$extends2.length) {
|
|---|
| 411 | this.space();
|
|---|
| 412 | this.word("extends");
|
|---|
| 413 | this.space();
|
|---|
| 414 | this.printList(node.extends);
|
|---|
| 415 | }
|
|---|
| 416 | this.space();
|
|---|
| 417 | this.print(node.body);
|
|---|
| 418 | }
|
|---|
| 419 | function IntersectionTypeAnnotation(node) {
|
|---|
| 420 | this.printJoin(node.types, undefined, undefined, andSeparator);
|
|---|
| 421 | }
|
|---|
| 422 | function MixedTypeAnnotation() {
|
|---|
| 423 | this.word("mixed");
|
|---|
| 424 | }
|
|---|
| 425 | function EmptyTypeAnnotation() {
|
|---|
| 426 | this.word("empty");
|
|---|
| 427 | }
|
|---|
| 428 | function NullableTypeAnnotation(node) {
|
|---|
| 429 | this.tokenChar(63);
|
|---|
| 430 | this.print(node.typeAnnotation);
|
|---|
| 431 | }
|
|---|
| 432 | function NumberTypeAnnotation() {
|
|---|
| 433 | this.word("number");
|
|---|
| 434 | }
|
|---|
| 435 | function StringTypeAnnotation() {
|
|---|
| 436 | this.word("string");
|
|---|
| 437 | }
|
|---|
| 438 | function ThisTypeAnnotation() {
|
|---|
| 439 | this.word("this");
|
|---|
| 440 | }
|
|---|
| 441 | function TupleTypeAnnotation(node) {
|
|---|
| 442 | this.tokenChar(91);
|
|---|
| 443 | this.printList(node.types);
|
|---|
| 444 | this.tokenChar(93);
|
|---|
| 445 | }
|
|---|
| 446 | function TypeofTypeAnnotation(node) {
|
|---|
| 447 | this.word("typeof");
|
|---|
| 448 | this.space();
|
|---|
| 449 | this.print(node.argument);
|
|---|
| 450 | }
|
|---|
| 451 | function TypeAlias(node) {
|
|---|
| 452 | this.word("type");
|
|---|
| 453 | this.space();
|
|---|
| 454 | this.print(node.id);
|
|---|
| 455 | this.print(node.typeParameters);
|
|---|
| 456 | this.space();
|
|---|
| 457 | this.tokenChar(61);
|
|---|
| 458 | this.space();
|
|---|
| 459 | this.print(node.right);
|
|---|
| 460 | this.semicolon();
|
|---|
| 461 | }
|
|---|
| 462 | function TypeAnnotation(node, parent) {
|
|---|
| 463 | this.tokenChar(58);
|
|---|
| 464 | this.space();
|
|---|
| 465 | if (parent.type === "ArrowFunctionExpression") {
|
|---|
| 466 | this.tokenContext |= _index.TokenContext.arrowFlowReturnType;
|
|---|
| 467 | } else if (node.optional) {
|
|---|
| 468 | this.tokenChar(63);
|
|---|
| 469 | }
|
|---|
| 470 | this.print(node.typeAnnotation);
|
|---|
| 471 | }
|
|---|
| 472 | function TypeParameterInstantiation(node) {
|
|---|
| 473 | this.tokenChar(60);
|
|---|
| 474 | this.printList(node.params);
|
|---|
| 475 | this.tokenChar(62);
|
|---|
| 476 | }
|
|---|
| 477 | function TypeParameter(node) {
|
|---|
| 478 | _variance.call(this, node);
|
|---|
| 479 | this.word(node.name);
|
|---|
| 480 | if (node.bound) {
|
|---|
| 481 | this.print(node.bound);
|
|---|
| 482 | }
|
|---|
| 483 | if (node.default) {
|
|---|
| 484 | this.space();
|
|---|
| 485 | this.tokenChar(61);
|
|---|
| 486 | this.space();
|
|---|
| 487 | this.print(node.default);
|
|---|
| 488 | }
|
|---|
| 489 | }
|
|---|
| 490 | function OpaqueType(node) {
|
|---|
| 491 | this.word("opaque");
|
|---|
| 492 | this.space();
|
|---|
| 493 | this.word("type");
|
|---|
| 494 | this.space();
|
|---|
| 495 | this.print(node.id);
|
|---|
| 496 | this.print(node.typeParameters);
|
|---|
| 497 | if (node.supertype) {
|
|---|
| 498 | this.tokenChar(58);
|
|---|
| 499 | this.space();
|
|---|
| 500 | this.print(node.supertype);
|
|---|
| 501 | }
|
|---|
| 502 | if (node.impltype) {
|
|---|
| 503 | this.space();
|
|---|
| 504 | this.tokenChar(61);
|
|---|
| 505 | this.space();
|
|---|
| 506 | this.print(node.impltype);
|
|---|
| 507 | }
|
|---|
| 508 | this.semicolon();
|
|---|
| 509 | }
|
|---|
| 510 | function ObjectTypeAnnotation(node) {
|
|---|
| 511 | if (node.exact) {
|
|---|
| 512 | this.token("{|");
|
|---|
| 513 | } else {
|
|---|
| 514 | this.tokenChar(123);
|
|---|
| 515 | }
|
|---|
| 516 | const props = [...node.properties, ...(node.callProperties || []), ...(node.indexers || []), ...(node.internalSlots || [])];
|
|---|
| 517 | if (props.length) {
|
|---|
| 518 | this.newline();
|
|---|
| 519 | this.space();
|
|---|
| 520 | this.printJoin(props, true, true, () => {
|
|---|
| 521 | if (props.length !== 1 || node.inexact) {
|
|---|
| 522 | this.tokenChar(44);
|
|---|
| 523 | this.space();
|
|---|
| 524 | }
|
|---|
| 525 | }, true);
|
|---|
| 526 | this.space();
|
|---|
| 527 | }
|
|---|
| 528 | if (node.inexact) {
|
|---|
| 529 | this.indent();
|
|---|
| 530 | this.token("...");
|
|---|
| 531 | if (props.length) {
|
|---|
| 532 | this.newline();
|
|---|
| 533 | }
|
|---|
| 534 | this.dedent();
|
|---|
| 535 | }
|
|---|
| 536 | if (node.exact) {
|
|---|
| 537 | this.token("|}");
|
|---|
| 538 | } else {
|
|---|
| 539 | this.tokenChar(125);
|
|---|
| 540 | }
|
|---|
| 541 | }
|
|---|
| 542 | function ObjectTypeInternalSlot(node) {
|
|---|
| 543 | if (node.static) {
|
|---|
| 544 | this.word("static");
|
|---|
| 545 | this.space();
|
|---|
| 546 | }
|
|---|
| 547 | this.tokenChar(91);
|
|---|
| 548 | this.tokenChar(91);
|
|---|
| 549 | this.print(node.id);
|
|---|
| 550 | this.tokenChar(93);
|
|---|
| 551 | this.tokenChar(93);
|
|---|
| 552 | if (node.optional) this.tokenChar(63);
|
|---|
| 553 | if (!node.method) {
|
|---|
| 554 | this.tokenChar(58);
|
|---|
| 555 | this.space();
|
|---|
| 556 | }
|
|---|
| 557 | this.print(node.value);
|
|---|
| 558 | }
|
|---|
| 559 | function ObjectTypeCallProperty(node) {
|
|---|
| 560 | if (node.static) {
|
|---|
| 561 | this.word("static");
|
|---|
| 562 | this.space();
|
|---|
| 563 | }
|
|---|
| 564 | this.print(node.value);
|
|---|
| 565 | }
|
|---|
| 566 | function ObjectTypeIndexer(node) {
|
|---|
| 567 | if (node.static) {
|
|---|
| 568 | this.word("static");
|
|---|
| 569 | this.space();
|
|---|
| 570 | }
|
|---|
| 571 | _variance.call(this, node);
|
|---|
| 572 | this.tokenChar(91);
|
|---|
| 573 | if (node.id) {
|
|---|
| 574 | this.print(node.id);
|
|---|
| 575 | this.tokenChar(58);
|
|---|
| 576 | this.space();
|
|---|
| 577 | }
|
|---|
| 578 | this.print(node.key);
|
|---|
| 579 | this.tokenChar(93);
|
|---|
| 580 | this.tokenChar(58);
|
|---|
| 581 | this.space();
|
|---|
| 582 | this.print(node.value);
|
|---|
| 583 | }
|
|---|
| 584 | function ObjectTypeProperty(node) {
|
|---|
| 585 | if (node.proto) {
|
|---|
| 586 | this.word("proto");
|
|---|
| 587 | this.space();
|
|---|
| 588 | }
|
|---|
| 589 | if (node.static) {
|
|---|
| 590 | this.word("static");
|
|---|
| 591 | this.space();
|
|---|
| 592 | }
|
|---|
| 593 | if (node.kind === "get" || node.kind === "set") {
|
|---|
| 594 | this.word(node.kind);
|
|---|
| 595 | this.space();
|
|---|
| 596 | }
|
|---|
| 597 | _variance.call(this, node);
|
|---|
| 598 | this.print(node.key);
|
|---|
| 599 | if (node.optional) this.tokenChar(63);
|
|---|
| 600 | if (!node.method) {
|
|---|
| 601 | this.tokenChar(58);
|
|---|
| 602 | this.space();
|
|---|
| 603 | }
|
|---|
| 604 | this.print(node.value);
|
|---|
| 605 | }
|
|---|
| 606 | function ObjectTypeSpreadProperty(node) {
|
|---|
| 607 | this.token("...");
|
|---|
| 608 | this.print(node.argument);
|
|---|
| 609 | }
|
|---|
| 610 | function QualifiedTypeIdentifier(node) {
|
|---|
| 611 | this.print(node.qualification);
|
|---|
| 612 | this.tokenChar(46);
|
|---|
| 613 | this.print(node.id);
|
|---|
| 614 | }
|
|---|
| 615 | function SymbolTypeAnnotation() {
|
|---|
| 616 | this.word("symbol");
|
|---|
| 617 | }
|
|---|
| 618 | function orSeparator(occurrenceCount) {
|
|---|
| 619 | this.space();
|
|---|
| 620 | this.token("|", false, occurrenceCount);
|
|---|
| 621 | this.space();
|
|---|
| 622 | }
|
|---|
| 623 | function UnionTypeAnnotation(node) {
|
|---|
| 624 | this.printJoin(node.types, undefined, undefined, orSeparator);
|
|---|
| 625 | }
|
|---|
| 626 | function TypeCastExpression(node) {
|
|---|
| 627 | this.tokenChar(40);
|
|---|
| 628 | this.print(node.expression);
|
|---|
| 629 | this.print(node.typeAnnotation);
|
|---|
| 630 | this.tokenChar(41);
|
|---|
| 631 | }
|
|---|
| 632 | function Variance(node) {
|
|---|
| 633 | if (node.kind === "plus") {
|
|---|
| 634 | this.tokenChar(43);
|
|---|
| 635 | } else {
|
|---|
| 636 | this.tokenChar(45);
|
|---|
| 637 | }
|
|---|
| 638 | }
|
|---|
| 639 | function VoidTypeAnnotation() {
|
|---|
| 640 | this.word("void");
|
|---|
| 641 | }
|
|---|
| 642 | function IndexedAccessType(node) {
|
|---|
| 643 | this.print(node.objectType, true);
|
|---|
| 644 | this.tokenChar(91);
|
|---|
| 645 | this.print(node.indexType);
|
|---|
| 646 | this.tokenChar(93);
|
|---|
| 647 | }
|
|---|
| 648 | function OptionalIndexedAccessType(node) {
|
|---|
| 649 | this.print(node.objectType);
|
|---|
| 650 | if (node.optional) {
|
|---|
| 651 | this.token("?.");
|
|---|
| 652 | }
|
|---|
| 653 | this.tokenChar(91);
|
|---|
| 654 | this.print(node.indexType);
|
|---|
| 655 | this.tokenChar(93);
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | //# sourceMappingURL=flow.js.map
|
|---|