123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- "use strict";
- exports.__esModule = true;
- exports.TypeParameterDeclaration = exports.StringLiteralTypeAnnotation = exports.NumericLiteralTypeAnnotation = exports.GenericTypeAnnotation = exports.ClassImplements = undefined;
- exports.AnyTypeAnnotation = AnyTypeAnnotation;
- exports.ArrayTypeAnnotation = ArrayTypeAnnotation;
- exports.BooleanTypeAnnotation = BooleanTypeAnnotation;
- exports.BooleanLiteralTypeAnnotation = BooleanLiteralTypeAnnotation;
- exports.NullLiteralTypeAnnotation = NullLiteralTypeAnnotation;
- exports.DeclareClass = DeclareClass;
- exports.DeclareFunction = DeclareFunction;
- exports.DeclareInterface = DeclareInterface;
- exports.DeclareModule = DeclareModule;
- exports.DeclareModuleExports = DeclareModuleExports;
- exports.DeclareTypeAlias = DeclareTypeAlias;
- exports.DeclareOpaqueType = DeclareOpaqueType;
- exports.DeclareVariable = DeclareVariable;
- exports.DeclareExportDeclaration = DeclareExportDeclaration;
- exports.ExistentialTypeParam = ExistentialTypeParam;
- exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
- exports.FunctionTypeParam = FunctionTypeParam;
- exports.InterfaceExtends = InterfaceExtends;
- exports._interfaceish = _interfaceish;
- exports._variance = _variance;
- exports.InterfaceDeclaration = InterfaceDeclaration;
- exports.IntersectionTypeAnnotation = IntersectionTypeAnnotation;
- exports.MixedTypeAnnotation = MixedTypeAnnotation;
- exports.EmptyTypeAnnotation = EmptyTypeAnnotation;
- exports.NullableTypeAnnotation = NullableTypeAnnotation;
- var _types = require("./types");
- Object.defineProperty(exports, "NumericLiteralTypeAnnotation", {
- enumerable: true,
- get: function get() {
- return _types.NumericLiteral;
- }
- });
- Object.defineProperty(exports, "StringLiteralTypeAnnotation", {
- enumerable: true,
- get: function get() {
- return _types.StringLiteral;
- }
- });
- exports.NumberTypeAnnotation = NumberTypeAnnotation;
- exports.StringTypeAnnotation = StringTypeAnnotation;
- exports.ThisTypeAnnotation = ThisTypeAnnotation;
- exports.TupleTypeAnnotation = TupleTypeAnnotation;
- exports.TypeofTypeAnnotation = TypeofTypeAnnotation;
- exports.TypeAlias = TypeAlias;
- exports.OpaqueType = OpaqueType;
- exports.TypeAnnotation = TypeAnnotation;
- exports.TypeParameter = TypeParameter;
- exports.TypeParameterInstantiation = TypeParameterInstantiation;
- exports.ObjectTypeAnnotation = ObjectTypeAnnotation;
- exports.ObjectTypeCallProperty = ObjectTypeCallProperty;
- exports.ObjectTypeIndexer = ObjectTypeIndexer;
- exports.ObjectTypeProperty = ObjectTypeProperty;
- exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty;
- exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier;
- exports.UnionTypeAnnotation = UnionTypeAnnotation;
- exports.TypeCastExpression = TypeCastExpression;
- exports.VoidTypeAnnotation = VoidTypeAnnotation;
- var _babelTypes = require("babel-types");
- var t = _interopRequireWildcard(_babelTypes);
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
- function AnyTypeAnnotation() {
- this.word("any");
- }
- function ArrayTypeAnnotation(node) {
- this.print(node.elementType, node);
- this.token("[");
- this.token("]");
- }
- function BooleanTypeAnnotation() {
- this.word("boolean");
- }
- function BooleanLiteralTypeAnnotation(node) {
- this.word(node.value ? "true" : "false");
- }
- function NullLiteralTypeAnnotation() {
- this.word("null");
- }
- function DeclareClass(node, parent) {
- if (!t.isDeclareExportDeclaration(parent)) {
- this.word("declare");
- this.space();
- }
- this.word("class");
- this.space();
- this._interfaceish(node);
- }
- function DeclareFunction(node, parent) {
- if (!t.isDeclareExportDeclaration(parent)) {
- this.word("declare");
- this.space();
- }
- this.word("function");
- this.space();
- this.print(node.id, node);
- this.print(node.id.typeAnnotation.typeAnnotation, node);
- this.semicolon();
- }
- function DeclareInterface(node) {
- this.word("declare");
- this.space();
- this.InterfaceDeclaration(node);
- }
- function DeclareModule(node) {
- this.word("declare");
- this.space();
- this.word("module");
- this.space();
- this.print(node.id, node);
- this.space();
- this.print(node.body, node);
- }
- function DeclareModuleExports(node) {
- this.word("declare");
- this.space();
- this.word("module");
- this.token(".");
- this.word("exports");
- this.print(node.typeAnnotation, node);
- }
- function DeclareTypeAlias(node) {
- this.word("declare");
- this.space();
- this.TypeAlias(node);
- }
- function DeclareOpaqueType(node, parent) {
- if (!t.isDeclareExportDeclaration(parent)) {
- this.word("declare");
- this.space();
- }
- this.OpaqueType(node);
- }
- function DeclareVariable(node, parent) {
- if (!t.isDeclareExportDeclaration(parent)) {
- this.word("declare");
- this.space();
- }
- this.word("var");
- this.space();
- this.print(node.id, node);
- this.print(node.id.typeAnnotation, node);
- this.semicolon();
- }
- function DeclareExportDeclaration(node) {
- this.word("declare");
- this.space();
- this.word("export");
- this.space();
- if (node.default) {
- this.word("default");
- this.space();
- }
- FlowExportDeclaration.apply(this, arguments);
- }
- function FlowExportDeclaration(node) {
- if (node.declaration) {
- var declar = node.declaration;
- this.print(declar, node);
- if (!t.isStatement(declar)) this.semicolon();
- } else {
- this.token("{");
- if (node.specifiers.length) {
- this.space();
- this.printList(node.specifiers, node);
- this.space();
- }
- this.token("}");
- if (node.source) {
- this.space();
- this.word("from");
- this.space();
- this.print(node.source, node);
- }
- this.semicolon();
- }
- }
- function ExistentialTypeParam() {
- this.token("*");
- }
- function FunctionTypeAnnotation(node, parent) {
- this.print(node.typeParameters, node);
- this.token("(");
- this.printList(node.params, node);
- if (node.rest) {
- if (node.params.length) {
- this.token(",");
- this.space();
- }
- this.token("...");
- this.print(node.rest, node);
- }
- this.token(")");
- if (parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction") {
- this.token(":");
- } else {
- this.space();
- this.token("=>");
- }
- this.space();
- this.print(node.returnType, node);
- }
- function FunctionTypeParam(node) {
- this.print(node.name, node);
- if (node.optional) this.token("?");
- this.token(":");
- this.space();
- this.print(node.typeAnnotation, node);
- }
- function InterfaceExtends(node) {
- this.print(node.id, node);
- this.print(node.typeParameters, node);
- }
- exports.ClassImplements = InterfaceExtends;
- exports.GenericTypeAnnotation = InterfaceExtends;
- function _interfaceish(node) {
- this.print(node.id, node);
- this.print(node.typeParameters, node);
- if (node.extends.length) {
- this.space();
- this.word("extends");
- this.space();
- this.printList(node.extends, node);
- }
- if (node.mixins && node.mixins.length) {
- this.space();
- this.word("mixins");
- this.space();
- this.printList(node.mixins, node);
- }
- this.space();
- this.print(node.body, node);
- }
- function _variance(node) {
- if (node.variance === "plus") {
- this.token("+");
- } else if (node.variance === "minus") {
- this.token("-");
- }
- }
- function InterfaceDeclaration(node) {
- this.word("interface");
- this.space();
- this._interfaceish(node);
- }
- function andSeparator() {
- this.space();
- this.token("&");
- this.space();
- }
- function IntersectionTypeAnnotation(node) {
- this.printJoin(node.types, node, { separator: andSeparator });
- }
- function MixedTypeAnnotation() {
- this.word("mixed");
- }
- function EmptyTypeAnnotation() {
- this.word("empty");
- }
- function NullableTypeAnnotation(node) {
- this.token("?");
- this.print(node.typeAnnotation, node);
- }
- function NumberTypeAnnotation() {
- this.word("number");
- }
- function StringTypeAnnotation() {
- this.word("string");
- }
- function ThisTypeAnnotation() {
- this.word("this");
- }
- function TupleTypeAnnotation(node) {
- this.token("[");
- this.printList(node.types, node);
- this.token("]");
- }
- function TypeofTypeAnnotation(node) {
- this.word("typeof");
- this.space();
- this.print(node.argument, node);
- }
- function TypeAlias(node) {
- this.word("type");
- this.space();
- this.print(node.id, node);
- this.print(node.typeParameters, node);
- this.space();
- this.token("=");
- this.space();
- this.print(node.right, node);
- this.semicolon();
- }
- function OpaqueType(node) {
- this.word("opaque");
- this.space();
- this.word("type");
- this.space();
- this.print(node.id, node);
- this.print(node.typeParameters, node);
- if (node.supertype) {
- this.token(":");
- this.space();
- this.print(node.supertype, node);
- }
- if (node.impltype) {
- this.space();
- this.token("=");
- this.space();
- this.print(node.impltype, node);
- }
- this.semicolon();
- }
- function TypeAnnotation(node) {
- this.token(":");
- this.space();
- if (node.optional) this.token("?");
- this.print(node.typeAnnotation, node);
- }
- function TypeParameter(node) {
- this._variance(node);
- this.word(node.name);
- if (node.bound) {
- this.print(node.bound, node);
- }
- if (node.default) {
- this.space();
- this.token("=");
- this.space();
- this.print(node.default, node);
- }
- }
- function TypeParameterInstantiation(node) {
- this.token("<");
- this.printList(node.params, node, {});
- this.token(">");
- }
- exports.TypeParameterDeclaration = TypeParameterInstantiation;
- function ObjectTypeAnnotation(node) {
- var _this = this;
- if (node.exact) {
- this.token("{|");
- } else {
- this.token("{");
- }
- var props = node.properties.concat(node.callProperties, node.indexers);
- if (props.length) {
- this.space();
- this.printJoin(props, node, {
- addNewlines: function addNewlines(leading) {
- if (leading && !props[0]) return 1;
- },
- indent: true,
- statement: true,
- iterator: function iterator() {
- if (props.length !== 1) {
- if (_this.format.flowCommaSeparator) {
- _this.token(",");
- } else {
- _this.semicolon();
- }
- _this.space();
- }
- }
- });
- this.space();
- }
- if (node.exact) {
- this.token("|}");
- } else {
- this.token("}");
- }
- }
- function ObjectTypeCallProperty(node) {
- if (node.static) {
- this.word("static");
- this.space();
- }
- this.print(node.value, node);
- }
- function ObjectTypeIndexer(node) {
- if (node.static) {
- this.word("static");
- this.space();
- }
- this._variance(node);
- this.token("[");
- this.print(node.id, node);
- this.token(":");
- this.space();
- this.print(node.key, node);
- this.token("]");
- this.token(":");
- this.space();
- this.print(node.value, node);
- }
- function ObjectTypeProperty(node) {
- if (node.static) {
- this.word("static");
- this.space();
- }
- this._variance(node);
- this.print(node.key, node);
- if (node.optional) this.token("?");
- this.token(":");
- this.space();
- this.print(node.value, node);
- }
- function ObjectTypeSpreadProperty(node) {
- this.token("...");
- this.print(node.argument, node);
- }
- function QualifiedTypeIdentifier(node) {
- this.print(node.qualification, node);
- this.token(".");
- this.print(node.id, node);
- }
- function orSeparator() {
- this.space();
- this.token("|");
- this.space();
- }
- function UnionTypeAnnotation(node) {
- this.printJoin(node.types, node, { separator: orSeparator });
- }
- function TypeCastExpression(node) {
- this.token("(");
- this.print(node.expression, node);
- this.print(node.typeAnnotation, node);
- this.token(")");
- }
- function VoidTypeAnnotation() {
- this.word("void");
- }
|