aboutsummaryrefslogtreecommitdiff
path: root/node_modules/babel-generator/lib/generators/flow.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/babel-generator/lib/generators/flow.js')
-rw-r--r--node_modules/babel-generator/lib/generators/flow.js101
1 files changed, 92 insertions, 9 deletions
diff --git a/node_modules/babel-generator/lib/generators/flow.js b/node_modules/babel-generator/lib/generators/flow.js
index 5422acea6..819c26ed2 100644
--- a/node_modules/babel-generator/lib/generators/flow.js
+++ b/node_modules/babel-generator/lib/generators/flow.js
@@ -1,6 +1,7 @@
"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;
@@ -12,7 +13,9 @@ 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;
@@ -45,6 +48,7 @@ exports.ThisTypeAnnotation = ThisTypeAnnotation;
exports.TupleTypeAnnotation = TupleTypeAnnotation;
exports.TypeofTypeAnnotation = TypeofTypeAnnotation;
exports.TypeAlias = TypeAlias;
+exports.OpaqueType = OpaqueType;
exports.TypeAnnotation = TypeAnnotation;
exports.TypeParameter = TypeParameter;
exports.TypeParameterInstantiation = TypeParameterInstantiation;
@@ -57,6 +61,13 @@ 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");
}
@@ -79,17 +90,21 @@ function NullLiteralTypeAnnotation() {
this.word("null");
}
-function DeclareClass(node) {
- this.word("declare");
- this.space();
+function DeclareClass(node, parent) {
+ if (!t.isDeclareExportDeclaration(parent)) {
+ this.word("declare");
+ this.space();
+ }
this.word("class");
this.space();
this._interfaceish(node);
}
-function DeclareFunction(node) {
- this.word("declare");
- this.space();
+function DeclareFunction(node, parent) {
+ if (!t.isDeclareExportDeclaration(parent)) {
+ this.word("declare");
+ this.space();
+ }
this.word("function");
this.space();
this.print(node.id, node);
@@ -128,9 +143,19 @@ function DeclareTypeAlias(node) {
this.TypeAlias(node);
}
-function DeclareVariable(node) {
- this.word("declare");
- this.space();
+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);
@@ -138,6 +163,44 @@ function DeclareVariable(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("*");
}
@@ -275,6 +338,26 @@ function TypeAlias(node) {
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(":");