846 lines
29 KiB
JavaScript
846 lines
29 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.Node$2E$ForEachChild = undefined;
|
|
exports.getPropertyName = getPropertyName;
|
|
exports.getBindingName = getBindingName;
|
|
exports.readEnumCase = readEnumCase;
|
|
exports.readTypeParameters = readTypeParameters;
|
|
exports.readInherits = readInherits;
|
|
exports.readCommentLines = readCommentLines;
|
|
exports.readComments = readComments;
|
|
exports.readCommentTags = readCommentTags;
|
|
exports.readCommentsForSignatureDeclaration = readCommentsForSignatureDeclaration;
|
|
exports.readCommentsAtLocation = readCommentsAtLocation;
|
|
exports.readInterface = readInterface;
|
|
exports.readTypeLiteral = readTypeLiteral;
|
|
exports.getFullTypeName = getFullTypeName;
|
|
exports.getFullNodeName = getFullNodeName;
|
|
exports.readClass = readClass;
|
|
exports.hasModifier = hasModifier;
|
|
exports.isConst = isConst;
|
|
exports.isNamespace = isNamespace;
|
|
exports.readVariable = readVariable;
|
|
exports.readEnum = readEnum;
|
|
exports.readTypeReference = readTypeReference;
|
|
exports.readFunctionType = readFunctionType;
|
|
exports.readTypeNode = readTypeNode;
|
|
exports.readParameterDeclaration = readParameterDeclaration;
|
|
exports.readMethodSignature = readMethodSignature;
|
|
exports.readMethodDeclaration = readMethodDeclaration;
|
|
exports.isReadOnly = isReadOnly;
|
|
exports.readPropertySignature = readPropertySignature;
|
|
exports.readPropertyNameComments = readPropertyNameComments;
|
|
exports.readPropertyDeclaration = readPropertyDeclaration;
|
|
exports.readFunctionDeclaration = readFunctionDeclaration;
|
|
exports.readIndexSignature = readIndexSignature;
|
|
exports.readCallSignature = readCallSignature;
|
|
exports.readConstructSignatureDeclaration = readConstructSignatureDeclaration;
|
|
exports.readConstructorDeclaration = readConstructorDeclaration;
|
|
exports.readNamedDeclaration = readNamedDeclaration;
|
|
exports.readAliasDeclaration = readAliasDeclaration;
|
|
exports.readExpressionText = readExpressionText;
|
|
exports.readExportAssignment = readExportAssignment;
|
|
exports.readImportDeclaration = readImportDeclaration;
|
|
exports.readStatement = readStatement;
|
|
exports.readModuleName = readModuleName;
|
|
exports.readModuleDeclaration = readModuleDeclaration;
|
|
exports.readSourceFile = readSourceFile;
|
|
|
|
var _Util = require("./fable-core/Util");
|
|
|
|
var _naming = require("./naming");
|
|
|
|
var _Option = require("./fable-core/Option");
|
|
|
|
var _syntax = require("./syntax");
|
|
|
|
var _Int = require("./fable-core/Int32");
|
|
|
|
var _String = require("./fable-core/String");
|
|
|
|
var _List = require("./fable-core/List");
|
|
|
|
var _List2 = _interopRequireDefault(_List);
|
|
|
|
var _Seq = require("./fable-core/Seq");
|
|
|
|
var _typescript = require("typescript");
|
|
|
|
var typescript = _interopRequireWildcard(_typescript);
|
|
|
|
var _CurriedLambda = require("./fable-core/CurriedLambda");
|
|
|
|
var _CurriedLambda2 = _interopRequireDefault(_CurriedLambda);
|
|
|
|
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function Node_ForEachChild(cbNode) {
|
|
this.forEachChild(nd => {
|
|
cbNode(nd);
|
|
return null;
|
|
}), void 0;
|
|
}
|
|
|
|
exports.Node$2E$ForEachChild = Node_ForEachChild;
|
|
|
|
function getPropertyName(pn) {
|
|
if ((0, _Util.hasInterface)(pn, "TypeScript.Ts.StringLiteral")) {
|
|
return pn.getText();
|
|
} else if ((0, _Util.hasInterface)(pn, "TypeScript.Ts.NumericLiteral")) {
|
|
return pn.getText();
|
|
} else if ((0, _Util.hasInterface)(pn, "TypeScript.Ts.ComputedPropertyName")) {
|
|
return pn.getText();
|
|
} else {
|
|
return (0, _naming.removeQuotes)(pn.getText());
|
|
}
|
|
}
|
|
|
|
function getBindingName(bn) {
|
|
if (true) {
|
|
if ((0, _Util.hasInterface)(bn, "TypeScript.Ts.ArrayBindingPattern")) {
|
|
return bn.getText();
|
|
} else {
|
|
return bn.getText();
|
|
}
|
|
} else {
|
|
return bn.getText();
|
|
}
|
|
}
|
|
|
|
function readEnumCase(em) {
|
|
const name = getPropertyName(em.name);
|
|
let patternInput_1;
|
|
const matchValue = em.initializer;
|
|
|
|
if (matchValue != null) {
|
|
const matchValue_1 = (0, _Option.getValue)(matchValue).kind | 0;
|
|
|
|
if (matchValue_1 === 8) {
|
|
const nl = (0, _Option.getValue)(matchValue);
|
|
patternInput_1 = [new _syntax.FsEnumCaseType(0), nl.text];
|
|
} else if (matchValue_1 === 9) {
|
|
const sl = (0, _Option.getValue)(matchValue);
|
|
patternInput_1 = [new _syntax.FsEnumCaseType(1), sl.text];
|
|
} else if (matchValue_1 === 192) {
|
|
const pue = (0, _Option.getValue)(matchValue);
|
|
const txt = pue.getText();
|
|
const patternInput = (0, _Int.tryParse)(txt, 10, 0);
|
|
|
|
if (patternInput[0]) {
|
|
patternInput_1 = [new _syntax.FsEnumCaseType(0), txt];
|
|
} else {
|
|
patternInput_1 = [new _syntax.FsEnumCaseType(2), null];
|
|
}
|
|
} else {
|
|
patternInput_1 = (0, _String.toFail)((0, _String.printf)("EnumCase type not supported %A %A"))((0, _Option.getValue)(matchValue).kind, name);
|
|
}
|
|
} else {
|
|
patternInput_1 = [new _syntax.FsEnumCaseType(2), null];
|
|
}
|
|
|
|
return new _syntax.FsEnumCase(name, patternInput_1[0], patternInput_1[1]);
|
|
}
|
|
|
|
function readTypeParameters(checker, tps) {
|
|
if (tps != null) {
|
|
return (0, _List.map)(function (tp) {
|
|
const matchValue = tp.default;
|
|
|
|
if (matchValue == null) {
|
|
return new _syntax.FsType(7, new _syntax.FsMapped(tp.name.getText(), getFullNodeName(checker, tp)));
|
|
} else {
|
|
return new _syntax.FsType(22, new _syntax.FsGenericParameterDefaults(readTypeNode(checker, (0, _Option.getValue)(matchValue)), tp.name.getText(), getFullNodeName(checker, tp)));
|
|
}
|
|
}, (0, _Seq.toList)((0, _Option.getValue)(tps)));
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}
|
|
|
|
function readInherits(checker, hcs) {
|
|
if (hcs != null) {
|
|
return (0, _List.collect)(function (hc) {
|
|
return (0, _List.map)(function (eta) {
|
|
const tp = readTypeNode(checker, eta);
|
|
let prms;
|
|
const matchValue = eta.typeArguments;
|
|
|
|
if (matchValue != null) {
|
|
prms = (0, _List.map)(function (t) {
|
|
return readTypeNode(checker, t);
|
|
}, (0, _Seq.toList)((0, _Option.getValue)(matchValue)));
|
|
} else {
|
|
prms = new _List2.default();
|
|
}
|
|
|
|
if (prms.length === 0) {
|
|
return tp;
|
|
} else {
|
|
return new _syntax.FsType(11, new _syntax.FsGenericType(tp, prms));
|
|
}
|
|
}, (0, _Seq.toList)(hc.types));
|
|
}, (0, _Seq.toList)((0, _Option.getValue)(hcs)));
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}
|
|
|
|
function readCommentLines(text) {
|
|
return (0, _List.ofArray)((0, _String.split)((0, _String.replace)((0, _String.replace)(text, "\r\n", "\n"), "\r", "\n"), "\n"));
|
|
}
|
|
|
|
function readComments(comments) {
|
|
if (comments.length === 0) {
|
|
return new _List2.default();
|
|
} else {
|
|
return (0, _List.collect)(function (dp) {
|
|
const matchValue = dp.kind;
|
|
|
|
if (matchValue === "text") {
|
|
return (0, _List.map)(function (arg0) {
|
|
return new _syntax.FsComment(0, arg0);
|
|
}, readCommentLines(dp.text));
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}, (0, _Seq.toList)(comments));
|
|
}
|
|
}
|
|
|
|
function readCommentTags(nd) {
|
|
const matchValue = typescript.getJSDocTags(nd);
|
|
|
|
if (matchValue != null) {
|
|
return (0, _List.collect)(function (tag) {
|
|
const matchValue_1 = tag.kind | 0;
|
|
|
|
if (matchValue_1 === 279) {
|
|
const matchValue_2 = tag.comment;
|
|
|
|
if (matchValue_2 != null) {
|
|
return (0, _List.ofArray)([new _syntax.FsComment(1, new _syntax.FsParamComment("", readCommentLines((0, _Option.getValue)(matchValue_2))))]);
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
} else {
|
|
return (0, _List.ofArray)([new _syntax.FsComment(2, tag.comment)]);
|
|
}
|
|
}, (0, _Seq.toList)((0, _Option.getValue)(matchValue)));
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}
|
|
|
|
function readCommentsForSignatureDeclaration(checker, declaration) {
|
|
const matchValue = checker.getSignatureFromDeclaration(declaration);
|
|
|
|
if (matchValue != null) {
|
|
return readComments((0, _Option.getValue)(matchValue).getDocumentationComment());
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}
|
|
|
|
function readCommentsAtLocation(checker, nd) {
|
|
const matchValue = checker.getSymbolAtLocation(nd);
|
|
|
|
if (matchValue != null) {
|
|
return readComments((0, _Option.getValue)(matchValue).getDocumentationComment());
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}
|
|
|
|
function readInterface(checker, id) {
|
|
const Comments = readCommentsAtLocation(checker, id.name);
|
|
const Name = id.name.getText();
|
|
const FullName = getFullNodeName(checker, id);
|
|
const Inherits = readInherits(checker, id.heritageClauses);
|
|
const Members = (0, _List.map)(function (te) {
|
|
return readNamedDeclaration(checker, te);
|
|
}, (0, _Seq.toList)(id.members));
|
|
return new _syntax.FsInterface(Comments, false, false, Name, FullName, readTypeParameters(checker, id.typeParameters), Inherits, Members);
|
|
}
|
|
|
|
function readTypeLiteral(checker, tl) {
|
|
return new _syntax.FsTypeLiteral((0, _List.map)(function (te) {
|
|
return readNamedDeclaration(checker, te);
|
|
}, (0, _Seq.toList)(tl.members)));
|
|
}
|
|
|
|
function getFullTypeName(checker, tp) {
|
|
const matchValue = tp.symbol;
|
|
|
|
if (matchValue != null) {
|
|
return checker.getFullyQualifiedName((0, _Option.getValue)(matchValue));
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function getFullNodeName(checker, nd) {
|
|
const matchValue = checker.getSymbolAtLocation(nd);
|
|
|
|
if (matchValue != null) {
|
|
return checker.getFullyQualifiedName((0, _Option.getValue)(matchValue));
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function readClass(checker, cd) {
|
|
const fullName = getFullNodeName(checker, cd);
|
|
const Comments = (0, _Option.defaultArg)((0, _Option.defaultArg)(cd.name, null, function (nd) {
|
|
return readCommentsAtLocation(checker, nd);
|
|
}), new _List2.default());
|
|
let Name;
|
|
const matchValue = cd.name;
|
|
|
|
if (matchValue != null) {
|
|
Name = (0, _Option.getValue)(matchValue).getText();
|
|
} else {
|
|
Name = fullName;
|
|
}
|
|
|
|
const Inherits = readInherits(checker, cd.heritageClauses);
|
|
const Members = (0, _List.map)(function (te) {
|
|
return readNamedDeclaration(checker, te);
|
|
}, (0, _Seq.toList)(cd.members));
|
|
return new _syntax.FsInterface(Comments, false, true, Name, fullName, readTypeParameters(checker, cd.typeParameters), Inherits, Members);
|
|
}
|
|
|
|
function hasModifier(kind, modifiers) {
|
|
if (modifiers != null) {
|
|
return (0, _Seq.exists)(function (md) {
|
|
return md.kind === kind;
|
|
}, (0, _Option.getValue)(modifiers));
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function isConst(nd) {
|
|
return (nd.flags | 2) !== 0;
|
|
}
|
|
|
|
function isNamespace(nd) {
|
|
return (0, _Seq.exists)(function (nd_1) {
|
|
return nd_1.kind === 129;
|
|
}, nd.getChildren());
|
|
}
|
|
|
|
function readVariable(checker, vb) {
|
|
return (0, _List.map)(function (vd) {
|
|
return new _syntax.FsType(16, new _syntax.FsVariable(null, hasModifier(124, vb.modifiers), getBindingName(vd.name), (0, _Option.defaultArg)((0, _Option.defaultArg)(vd.type, null, function (t) {
|
|
return readTypeNode(checker, t);
|
|
}), (0, _syntax.simpleType)("obj")), isConst(vd)));
|
|
}, (0, _Seq.toList)(vb.declarationList.declarations));
|
|
}
|
|
|
|
function readEnum(ed) {
|
|
return new _syntax.FsEnum(ed.name.getText(), (0, _List.map)(readEnumCase, (0, _Seq.toList)(ed.members)));
|
|
}
|
|
|
|
function readTypeReference(checker, tr) {
|
|
var typeName;
|
|
var matchValue_1;
|
|
const matchValue = tr.typeArguments;
|
|
|
|
if (matchValue != null) {
|
|
return new _syntax.FsType(11, new _syntax.FsGenericType((typeName = (matchValue_1 = tr.typeName, (0, _Util.hasInterface)(matchValue_1, "TypeScript.Ts.QualifiedName") ? matchValue_1.getText() : matchValue_1.getText()), typeName == null ? (0, _String.toFail)((0, _String.printf)("readTypeReference type name is null: %s"))(tr.getText()) : null, new _syntax.FsType(7, new _syntax.FsMapped(typeName, getFullNodeName(checker, tr)))), (0, _List.map)(function (t) {
|
|
return readTypeNode(checker, t);
|
|
}, (0, _Seq.toList)((0, _Option.getValue)(matchValue)))));
|
|
} else {
|
|
return new _syntax.FsType(7, new _syntax.FsMapped(tr.getText(), getFullNodeName(checker, tr)));
|
|
}
|
|
}
|
|
|
|
function readFunctionType(checker, ft) {
|
|
var matchValue;
|
|
return new _syntax.FsFunction(new _List2.default(), new _syntax.FsFunctionKind(0), hasModifier(115, ft.modifiers), (0, _Option.defaultArg)(ft.name, null, getPropertyName), readTypeParameters(checker, ft.typeParameters), (0, _List.map)(function (pd) {
|
|
return readParameterDeclaration(checker, pd);
|
|
}, (0, _Seq.toList)(ft.parameters)), (matchValue = ft.type, matchValue == null ? (0, _syntax.simpleType)("unit") : readTypeNode(checker, (0, _Option.getValue)(matchValue))));
|
|
}
|
|
|
|
function readTypeNode(checker, t) {
|
|
var ts;
|
|
|
|
readTypeNode: while (true) {
|
|
const matchValue = t.kind | 0;
|
|
|
|
switch (matchValue) {
|
|
case 136:
|
|
return (0, _syntax.simpleType)("string");
|
|
|
|
case 160:
|
|
return new _syntax.FsType(8, readFunctionType(checker, t));
|
|
|
|
case 159:
|
|
return readTypeReference(checker, t);
|
|
|
|
case 164:
|
|
const at = t;
|
|
return new _syntax.FsType(4, readTypeNode(checker, at.elementType));
|
|
|
|
case 133:
|
|
return (0, _syntax.simpleType)("float");
|
|
|
|
case 122:
|
|
return (0, _syntax.simpleType)("bool");
|
|
|
|
case 166:
|
|
const un = t;
|
|
const typs = (0, _Seq.toList)(un.types);
|
|
|
|
const isOption = function (t_1) {
|
|
if (t_1.kind === 139) {
|
|
return true;
|
|
} else {
|
|
return t_1.kind === 95;
|
|
}
|
|
};
|
|
|
|
return new _syntax.FsType(9, new _syntax.FsUnion((0, _Seq.exists)(isOption, typs), (ts = (0, _List.map)(function (t_2) {
|
|
return readTypeNode(checker, t_2);
|
|
}, (0, _List.filter)($var1 => function (value) {
|
|
return !value;
|
|
}(isOption($var1)), typs)), ts.length === 0 ? (0, _List.ofArray)([(0, _syntax.simpleType)("obj")]) : ts)));
|
|
|
|
case 119:
|
|
return new _syntax.FsType(9, new _syntax.FsUnion(true, (0, _List.ofArray)([(0, _syntax.simpleType)("obj")])));
|
|
|
|
case 105:
|
|
return (0, _syntax.simpleType)("unit");
|
|
|
|
case 165:
|
|
const tp = t;
|
|
return new _syntax.FsType(12, new _syntax.FsTuple((0, _List.map)(function (t_3) {
|
|
return readTypeNode(checker, t_3);
|
|
}, (0, _Seq.toList)(tp.elementTypes)), new _syntax.FsTupleKind(1)));
|
|
|
|
case 137:
|
|
return (0, _syntax.simpleType)("Symbol");
|
|
|
|
case 169:
|
|
return new _syntax.FsType(19);
|
|
|
|
case 158:
|
|
return (0, _syntax.simpleType)("bool");
|
|
|
|
case 163:
|
|
const tl = t;
|
|
return new _syntax.FsType(21, readTypeLiteral(checker, tl));
|
|
|
|
case 167:
|
|
const itp = t;
|
|
return new _syntax.FsType(12, new _syntax.FsTuple((0, _List.map)(function (t_4) {
|
|
return readTypeNode(checker, t_4);
|
|
}, (0, _Seq.toList)(itp.types)), new _syntax.FsTupleKind(0)));
|
|
|
|
case 171:
|
|
const ia = t;
|
|
checker = checker;
|
|
t = ia.objectType;
|
|
continue readTypeNode;
|
|
|
|
case 162:
|
|
return (0, _syntax.simpleType)("obj");
|
|
|
|
case 173:
|
|
const lt = t;
|
|
|
|
const readLiteralKind = function (kind, text) {
|
|
if (kind === 9) {
|
|
return new _syntax.FsType(17, (0, _naming.removeQuotes)(text));
|
|
} else {
|
|
return (0, _syntax.simpleType)("obj");
|
|
}
|
|
};
|
|
|
|
const matchValue_1 = lt.literal;
|
|
|
|
if ((0, _Util.hasInterface)(matchValue_1, "TypeScript.Ts.LiteralExpression")) {
|
|
return readLiteralKind(matchValue_1.kind, matchValue_1.getText());
|
|
} else if ((0, _Util.hasInterface)(matchValue_1, "TypeScript.Ts.PrefixUnaryExpression")) {
|
|
return readLiteralKind(matchValue_1.kind, matchValue_1.getText());
|
|
} else {
|
|
return readLiteralKind(matchValue_1.kind, matchValue_1.getText());
|
|
}
|
|
|
|
case 201:
|
|
const eta = t;
|
|
const tp_1 = checker.getTypeFromTypeNode(eta);
|
|
return new _syntax.FsType(7, new _syntax.FsMapped(readExpressionText(eta.expression), getFullTypeName(checker, tp_1)));
|
|
|
|
case 168:
|
|
const pt = t;
|
|
checker = checker;
|
|
t = pt.type;
|
|
continue readTypeNode;
|
|
|
|
case 172:
|
|
return new _syntax.FsType(12, new _syntax.FsTuple((0, _List.ofArray)([(0, _syntax.simpleType)("obj")]), new _syntax.FsTupleKind(2)));
|
|
|
|
case 130:
|
|
return new _syntax.FsType(5);
|
|
|
|
case 139:
|
|
return (0, _syntax.simpleType)("obj");
|
|
|
|
case 95:
|
|
return new _syntax.FsType(5);
|
|
|
|
case 134:
|
|
return (0, _syntax.simpleType)("obj");
|
|
|
|
case 170:
|
|
(0, _String.toConsole)((0, _String.printf)("unsupported TypeNode TypeOperator: %A"))(t);
|
|
return new _syntax.FsType(5);
|
|
|
|
default:
|
|
(0, _String.toConsole)((0, _String.printf)("unsupported TypeNode kind: %A"))(t.kind);
|
|
return new _syntax.FsType(5);
|
|
}
|
|
}
|
|
}
|
|
|
|
function readParameterDeclaration(checker, pd) {
|
|
const stringLiteral = (0, _Seq.tryPick)(function (ch) {
|
|
return (0, _Seq.tryFind)(function (gch) {
|
|
return gch.kind === 9;
|
|
}, (0, _Seq.toList)(ch.getChildren()));
|
|
}, (0, _Seq.toList)(pd.getChildren()));
|
|
let tp;
|
|
|
|
if (stringLiteral == null) {
|
|
const matchValue = pd.type;
|
|
|
|
if (matchValue == null) {
|
|
tp = (0, _syntax.simpleType)("obj");
|
|
} else {
|
|
tp = readTypeNode(checker, (0, _Option.getValue)(matchValue));
|
|
}
|
|
} else {
|
|
tp = new _syntax.FsType(17, (0, _naming.removeQuotes)((0, _Option.getValue)(stringLiteral).getText()));
|
|
}
|
|
|
|
const name = getBindingName(pd.name);
|
|
return new _syntax.FsParam((0, _Option.defaultArg)(function (list) {
|
|
return (0, _Seq.tryFind)(_syntax.FsCommentModule.isParam.bind(_syntax.FsCommentModule), list);
|
|
}(readCommentTags(pd)), null, function (comment) {
|
|
return comment.tag === 1 ? new _syntax.FsComment(1, new _syntax.FsParamComment(name, comment.data.Description)) : comment;
|
|
}), name, (0, _CurriedLambda2.default)(() => pd.questionToken != null)(), (0, _CurriedLambda2.default)(() => pd.dotDotDotToken != null)(), tp);
|
|
}
|
|
|
|
function readMethodSignature(checker, ms) {
|
|
var matchValue;
|
|
return new _syntax.FsFunction(readCommentsForSignatureDeclaration(checker, ms), new _syntax.FsFunctionKind(0), hasModifier(115, ms.modifiers), getPropertyName(ms.name), readTypeParameters(checker, ms.typeParameters), (0, _List.map)(function (pd) {
|
|
return readParameterDeclaration(checker, pd);
|
|
}, (0, _Seq.toList)(ms.parameters)), (matchValue = ms.type, matchValue == null ? (0, _syntax.simpleType)("unit") : readTypeNode(checker, (0, _Option.getValue)(matchValue))));
|
|
}
|
|
|
|
function readMethodDeclaration(checker, md) {
|
|
var matchValue;
|
|
return new _syntax.FsFunction(readCommentsForSignatureDeclaration(checker, md), new _syntax.FsFunctionKind(0), hasModifier(115, md.modifiers), getPropertyName(md.name), readTypeParameters(checker, md.typeParameters), (0, _List.map)(function (pd) {
|
|
return readParameterDeclaration(checker, pd);
|
|
}, (0, _Seq.toList)(md.parameters)), (matchValue = md.type, matchValue == null ? (0, _syntax.simpleType)("unit") : readTypeNode(checker, (0, _Option.getValue)(matchValue))));
|
|
}
|
|
|
|
function isReadOnly(modifiers) {
|
|
return hasModifier(131, modifiers);
|
|
}
|
|
|
|
function readPropertySignature(checker, ps) {
|
|
var matchValue;
|
|
return new _syntax.FsProperty(readPropertyNameComments(checker, ps.name), new _syntax.FsPropertyKind(0), null, getPropertyName(ps.name), (0, _CurriedLambda2.default)(() => ps.questionToken != null)(), (matchValue = ps.type, matchValue != null ? readTypeNode(checker, (0, _Option.getValue)(matchValue)) : new _syntax.FsType(6)), isReadOnly(ps.modifiers));
|
|
}
|
|
|
|
function readPropertyNameComments(checker, pn) {
|
|
if ((0, _Util.hasInterface)(pn, "TypeScript.Ts.StringLiteral")) {
|
|
return readCommentsAtLocation(checker, pn);
|
|
} else if ((0, _Util.hasInterface)(pn, "TypeScript.Ts.NumericLiteral")) {
|
|
return readCommentsAtLocation(checker, pn);
|
|
} else if ((0, _Util.hasInterface)(pn, "TypeScript.Ts.ComputedPropertyName")) {
|
|
return readCommentsAtLocation(checker, pn);
|
|
} else {
|
|
return readCommentsAtLocation(checker, pn);
|
|
}
|
|
}
|
|
|
|
function readPropertyDeclaration(checker, pd) {
|
|
var matchValue;
|
|
return new _syntax.FsProperty(readPropertyNameComments(checker, pd.name), new _syntax.FsPropertyKind(0), null, getPropertyName(pd.name), (0, _CurriedLambda2.default)(() => pd.questionToken != null)(), (matchValue = pd.type, matchValue != null ? readTypeNode(checker, (0, _Option.getValue)(matchValue)) : new _syntax.FsType(6)), isReadOnly(pd.modifiers));
|
|
}
|
|
|
|
function readFunctionDeclaration(checker, fd) {
|
|
var matchValue;
|
|
return new _syntax.FsFunction(readCommentsForSignatureDeclaration(checker, fd), new _syntax.FsFunctionKind(0), hasModifier(115, fd.modifiers), (0, _Option.defaultArg)(fd.name, null, function (id) {
|
|
return id.getText();
|
|
}), readTypeParameters(checker, fd.typeParameters), (0, _List.map)(function (pd) {
|
|
return readParameterDeclaration(checker, pd);
|
|
}, (0, _Seq.toList)(fd.parameters)), (matchValue = fd.type, matchValue == null ? (0, _syntax.simpleType)("unit") : readTypeNode(checker, (0, _Option.getValue)(matchValue))));
|
|
}
|
|
|
|
function readIndexSignature(checker, ps) {
|
|
var matchValue;
|
|
const pm = readParameterDeclaration(checker, ps.parameters[0]);
|
|
return new _syntax.FsProperty(readCommentsForSignatureDeclaration(checker, ps), new _syntax.FsPropertyKind(1), pm, "Item", (0, _CurriedLambda2.default)(() => ps.questionToken != null)(), (matchValue = ps.type, matchValue != null ? readTypeNode(checker, (0, _Option.getValue)(matchValue)) : new _syntax.FsType(6)), isReadOnly(ps.modifiers));
|
|
}
|
|
|
|
function readCallSignature(checker, cs) {
|
|
var matchValue;
|
|
return new _syntax.FsFunction(readCommentsForSignatureDeclaration(checker, cs), new _syntax.FsFunctionKind(2), false, "Invoke", new _List2.default(), (0, _List.map)(function (pd) {
|
|
return readParameterDeclaration(checker, pd);
|
|
}, (0, _Seq.toList)(cs.parameters)), (matchValue = cs.type, matchValue == null ? (0, _syntax.simpleType)("unit") : readTypeNode(checker, (0, _Option.getValue)(matchValue))));
|
|
}
|
|
|
|
function readConstructSignatureDeclaration(checker, cs) {
|
|
return new _syntax.FsFunction(readCommentsForSignatureDeclaration(checker, cs), new _syntax.FsFunctionKind(1), true, "Create", function (tps) {
|
|
return readTypeParameters(checker, tps);
|
|
}(cs.typeParameters), (0, _List.map)(function (pd) {
|
|
return readParameterDeclaration(checker, pd);
|
|
}, (0, _Seq.toList)(cs.parameters)), new _syntax.FsType(19));
|
|
}
|
|
|
|
function readConstructorDeclaration(checker, cs) {
|
|
return new _syntax.FsFunction(readCommentsForSignatureDeclaration(checker, cs), new _syntax.FsFunctionKind(1), true, "Create", function (tps) {
|
|
return readTypeParameters(checker, tps);
|
|
}(cs.typeParameters), (0, _List.map)(function (pd) {
|
|
return readParameterDeclaration(checker, pd);
|
|
}, (0, _Seq.toList)(cs.parameters)), new _syntax.FsType(19));
|
|
}
|
|
|
|
function readNamedDeclaration(checker, te) {
|
|
const matchValue = te.kind | 0;
|
|
|
|
switch (matchValue) {
|
|
case 157:
|
|
return new _syntax.FsType(2, readIndexSignature(checker, te));
|
|
|
|
case 150:
|
|
return new _syntax.FsType(8, readMethodSignature(checker, te));
|
|
|
|
case 148:
|
|
return new _syntax.FsType(2, readPropertySignature(checker, te));
|
|
|
|
case 155:
|
|
return new _syntax.FsType(8, readCallSignature(checker, te));
|
|
|
|
case 156:
|
|
return new _syntax.FsType(8, readConstructSignatureDeclaration(checker, te));
|
|
|
|
case 152:
|
|
return new _syntax.FsType(8, readConstructorDeclaration(checker, te));
|
|
|
|
case 149:
|
|
return new _syntax.FsType(2, readPropertyDeclaration(checker, te));
|
|
|
|
case 151:
|
|
return new _syntax.FsType(8, readMethodDeclaration(checker, te));
|
|
|
|
default:
|
|
(0, _String.toConsole)((0, _String.printf)("unsupported NamedDeclaration kind: %A"))(te.kind);
|
|
return new _syntax.FsType(5);
|
|
}
|
|
}
|
|
|
|
function readAliasDeclaration(checker, d) {
|
|
const tp = function (t) {
|
|
return readTypeNode(checker, t);
|
|
}(d.type);
|
|
|
|
const name = d.name.getText();
|
|
|
|
const asAlias = function () {
|
|
return new _syntax.FsType(10, new _syntax.FsAlias(name, tp, readTypeParameters(checker, d.typeParameters)));
|
|
};
|
|
|
|
if (tp.tag === 9) {
|
|
const sls = function (list) {
|
|
return (0, _List.choose)(_syntax.FsTypeModule.asStringLiteral.bind(_syntax.FsTypeModule), list);
|
|
}(tp.data.Types);
|
|
|
|
if (tp.data.Types.length === sls.length) {
|
|
return new _syntax.FsType(1, new _syntax.FsEnum(name, (0, _List.map)(function (sl) {
|
|
return new _syntax.FsEnumCase(sl, new _syntax.FsEnumCaseType(1), null);
|
|
}, sls)));
|
|
} else {
|
|
return asAlias();
|
|
}
|
|
} else {
|
|
return asAlias();
|
|
}
|
|
}
|
|
|
|
function readExpressionText(ep) {
|
|
const matchValue = ep.kind | 0;
|
|
|
|
if (matchValue === 71) {
|
|
const id = ep;
|
|
return id.getText();
|
|
} else if (matchValue === 179) {
|
|
const pa = ep;
|
|
return pa.getText();
|
|
} else {
|
|
(0, _String.toConsole)((0, _String.printf)("readExpressionText kind not yet supported: %A"))(ep.kind);
|
|
return ep.getText();
|
|
}
|
|
}
|
|
|
|
function readExportAssignment(ea) {
|
|
const matchValue = ea.expression.kind | 0;
|
|
|
|
if (matchValue === 71) {
|
|
const path = readExpressionText(ea.expression);
|
|
return new _syntax.FsType(18, path);
|
|
} else {
|
|
return new _syntax.FsType(6);
|
|
}
|
|
}
|
|
|
|
function readImportDeclaration(im) {
|
|
const moduleSpecifier = (0, _naming.removeQuotes)(im.moduleSpecifier.getText());
|
|
const matchValue = im.importClause;
|
|
|
|
if (matchValue != null) {
|
|
const matchValue_1 = (0, _Option.getValue)(matchValue).namedBindings;
|
|
|
|
if (matchValue_1 != null) {
|
|
if ((0, _Util.hasInterface)((0, _Option.getValue)(matchValue_1), "TypeScript.Ts.NamedImports")) {
|
|
return new _List2.default();
|
|
} else if ((0, _Option.getValue)(matchValue_1).name == null === false) {
|
|
return (0, _List.ofArray)([new _syntax.FsType(20, new _syntax.FsImport(1, new _syntax.ModuleImport((0, _Option.getValue)(matchValue_1).name.getText(), moduleSpecifier, null)))]);
|
|
} else {
|
|
return (0, _List.collect)(function (ch) {
|
|
const matchValue_2 = ch.kind | 0;
|
|
|
|
if (matchValue_2 === 286) {
|
|
const sl = ch;
|
|
return (0, _List.choose)(function (slch) {
|
|
const matchValue_3 = slch.kind | 0;
|
|
|
|
if (matchValue_3 === 242) {
|
|
const imp = slch;
|
|
return new _syntax.FsType(20, new _syntax.FsImport(0, new _syntax.TypeImport(imp.getText(), moduleSpecifier, null)));
|
|
} else {
|
|
return null;
|
|
}
|
|
}, (0, _Seq.toList)(sl.getChildren()));
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}, (0, _Seq.toList)((0, _Option.getValue)(matchValue_1).getChildren()));
|
|
}
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
}
|
|
|
|
function readStatement(checker, sd) {
|
|
const matchValue = sd.kind | 0;
|
|
|
|
switch (matchValue) {
|
|
case 230:
|
|
return (0, _List.ofArray)([new _syntax.FsType(0, readInterface(checker, sd))]);
|
|
|
|
case 232:
|
|
return (0, _List.ofArray)([new _syntax.FsType(1, readEnum(sd))]);
|
|
|
|
case 231:
|
|
return (0, _List.ofArray)([readAliasDeclaration(checker, sd)]);
|
|
|
|
case 229:
|
|
return (0, _List.ofArray)([new _syntax.FsType(0, readClass(checker, sd))]);
|
|
|
|
case 208:
|
|
return readVariable(checker, sd);
|
|
|
|
case 228:
|
|
return (0, _List.ofArray)([new _syntax.FsType(8, readFunctionDeclaration(checker, sd))]);
|
|
|
|
case 233:
|
|
return (0, _List.ofArray)([new _syntax.FsType(13, readModuleDeclaration(checker, sd))]);
|
|
|
|
case 243:
|
|
return (0, _List.ofArray)([readExportAssignment(sd)]);
|
|
|
|
case 238:
|
|
return readImportDeclaration(sd);
|
|
|
|
case 236:
|
|
return new _List2.default();
|
|
|
|
case 244:
|
|
return new _List2.default();
|
|
|
|
case 237:
|
|
const ime = sd;
|
|
return new _List2.default();
|
|
|
|
default:
|
|
(0, _String.toConsole)((0, _String.printf)("unsupported Statement kind: %A"))(sd.kind);
|
|
return new _List2.default();
|
|
}
|
|
}
|
|
|
|
function readModuleName(mn) {
|
|
if ((0, _Util.hasInterface)(mn, "TypeScript.Ts.StringLiteral")) {
|
|
return mn.getText();
|
|
} else {
|
|
return (0, _String.replace)(mn.getText(), "\"", "");
|
|
}
|
|
}
|
|
|
|
function readModuleDeclaration(checker, md) {
|
|
const types = [];
|
|
Node_ForEachChild.bind(md)(function (nd) {
|
|
const matchValue = nd.kind | 0;
|
|
|
|
switch (matchValue) {
|
|
case 234:
|
|
const mb = nd;
|
|
(0, _Seq.iterate)(types.push.bind(types), (0, _List.collect)(function (sd) {
|
|
return readStatement(checker, sd);
|
|
}, (0, _Seq.toList)(mb.statements)));
|
|
break;
|
|
|
|
case 124:
|
|
break;
|
|
|
|
case 71:
|
|
break;
|
|
|
|
case 233:
|
|
types.push.bind(types)(new _syntax.FsType(13, readModuleDeclaration(checker, nd)));
|
|
break;
|
|
|
|
case 9:
|
|
break;
|
|
|
|
case 84:
|
|
break;
|
|
|
|
default:
|
|
(0, _String.toConsole)((0, _String.printf)("unknown kind in ModuleDeclaration: %A"))(nd.kind);
|
|
}
|
|
});
|
|
return new _syntax.FsModule(hasModifier(124, md.modifiers), isNamespace(md), readModuleName(md.name), (0, _Seq.toList)(types), new _List2.default(), new _List2.default());
|
|
}
|
|
|
|
function readSourceFile(checker, sf, file) {
|
|
const modules = [];
|
|
const gbl = new _syntax.FsModule(false, false, "", (0, _List.collect)(function (sd) {
|
|
return readStatement(checker, sd);
|
|
}, (0, _Seq.toList)(sf.statements)), new _List2.default(), new _List2.default());
|
|
modules.push(gbl);
|
|
const Modules = (0, _Seq.toList)(modules);
|
|
return new _syntax.FsFile(file.FileName, file.ModuleName, Modules);
|
|
} |