1122 lines
44 KiB
JavaScript
1122 lines
44 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.engines = undefined;
|
|
exports.getAllTypesFromFile = getAllTypesFromFile;
|
|
exports.getAllTypes = getAllTypes;
|
|
exports.fixType = fixType;
|
|
exports.fixFile = fixFile;
|
|
exports.mergeTypes = mergeTypes;
|
|
exports.mergeModules = mergeModules;
|
|
exports.mergeModulesInFile = mergeModulesInFile;
|
|
exports.createIExportsModule = createIExportsModule;
|
|
exports.createIExports = createIExports;
|
|
exports.fixTic = fixTic;
|
|
exports.addTicForGenericFunctions = addTicForGenericFunctions;
|
|
exports.fixOverloadingOnStringParameters = fixOverloadingOnStringParameters;
|
|
exports.fixNodeArray = fixNodeArray;
|
|
exports.fixReadonlyArray = fixReadonlyArray;
|
|
exports.fixEscapeWords = fixEscapeWords;
|
|
exports.fixDateTime = fixDateTime;
|
|
exports.fixEnumReferences = fixEnumReferences;
|
|
exports.fixDuplicatesInUnion = fixDuplicatesInUnion;
|
|
exports.addTicForGenericTypes = addTicForGenericTypes;
|
|
exports.fixThis = fixThis;
|
|
exports.fixStatic = fixStatic;
|
|
exports.hasTodo = hasTodo;
|
|
exports.removeTodoMembers = removeTodoMembers;
|
|
exports.removeTypeParamsFromStatic = removeTypeParamsFromStatic;
|
|
exports.addConstructors = addConstructors;
|
|
exports.removeInternalModules = removeInternalModules;
|
|
exports.removeDuplicateFunctions = removeDuplicateFunctions;
|
|
exports.removeDuplicateOptions = removeDuplicateOptions;
|
|
exports.extractTypeLiterals = extractTypeLiterals;
|
|
exports.addAliasUnionHelpers = addAliasUnionHelpers;
|
|
exports.fixNamespace = fixNamespace;
|
|
exports.aliasToInterfacePartly = aliasToInterfacePartly;
|
|
exports.fixFsFileOut = fixFsFileOut;
|
|
exports.extractGenericParameterDefaults = extractGenericParameterDefaults;
|
|
exports.fixTypesHasESKeywords = fixTypesHasESKeywords;
|
|
exports.extractTypesInGlobalModules = extractTypesInGlobalModules;
|
|
|
|
var _List = require("./fable-core/List");
|
|
|
|
var _List2 = _interopRequireDefault(_List);
|
|
|
|
var _Seq = require("./fable-core/Seq");
|
|
|
|
var _syntax = require("./syntax");
|
|
|
|
var _String = require("./fable-core/String");
|
|
|
|
var _Option = require("./fable-core/Option");
|
|
|
|
var _Set = require("./fable-core/Set");
|
|
|
|
var _Comparer = require("./fable-core/Comparer");
|
|
|
|
var _Comparer2 = _interopRequireDefault(_Comparer);
|
|
|
|
var _Util = require("./fable-core/Util");
|
|
|
|
var _CurriedLambda = require("./fable-core/CurriedLambda");
|
|
|
|
var _CurriedLambda2 = _interopRequireDefault(_CurriedLambda);
|
|
|
|
var _naming = require("./naming");
|
|
|
|
var _Array = require("./fable-core/Array");
|
|
|
|
var _print = require("./print");
|
|
|
|
var _keywords = require("./keywords");
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function getAllTypesFromFile(fsFile) {
|
|
const tps = Array.from(new _List2.default());
|
|
fixFile(function (tp) {
|
|
tps.push.bind(tps)(tp);
|
|
return tp;
|
|
}, fsFile), void 0;
|
|
return (0, _Seq.toList)(tps);
|
|
}
|
|
|
|
function getAllTypes(fsFiles) {
|
|
return (0, _List.collect)(getAllTypesFromFile, fsFiles);
|
|
}
|
|
|
|
function fixType(fix, tp) {
|
|
const fixModule = function (a) {
|
|
const Types = (0, _List.map)(function (tp_1) {
|
|
return fixType(fix, tp_1);
|
|
}, a.Types);
|
|
return new _syntax.FsModule(a.HasDeclare, a.IsNamespace, a.Name, Types, a.HelperLines, a.Attributes);
|
|
};
|
|
|
|
const fixFile = function (f) {
|
|
const Modules = function (list) {
|
|
return (0, _List.map)(fixModule, list);
|
|
}(f.Modules);
|
|
|
|
return new _syntax.FsFile(f.FileName, f.ModuleName, Modules);
|
|
};
|
|
|
|
const fixParam = function (a_1) {
|
|
var Type;
|
|
const b = fix(new _syntax.FsType(3, (Type = fixType(fix, a_1.Type), new _syntax.FsParam(a_1.Comment, a_1.Name, a_1.Optional, a_1.ParamArray, Type))));
|
|
|
|
if (b.tag === 3) {
|
|
return b.data;
|
|
} else {
|
|
return (0, _String.toFail)((0, _String.printf)("param must be mapped to param"));
|
|
}
|
|
};
|
|
|
|
return fix((() => {
|
|
var Index;
|
|
var Type_1;
|
|
var Type_2;
|
|
var TypeParameters;
|
|
var Params;
|
|
var ReturnType;
|
|
var Types_1;
|
|
var Type_3;
|
|
var TypeParameters_1;
|
|
var Files;
|
|
var Type_4;
|
|
var TypeParameters_2;
|
|
var Inherits;
|
|
var Members;
|
|
|
|
switch (tp.tag) {
|
|
case 21:
|
|
return new _syntax.FsType(21, new _syntax.FsTypeLiteral((0, _List.map)(function (tp_2) {
|
|
return fixType(fix, tp_2);
|
|
}, tp.data.Members)));
|
|
|
|
case 2:
|
|
return new _syntax.FsType(2, (Index = (0, _Option.defaultArg)(tp.data.Index, null, fixParam), Type_1 = fixType(fix, tp.data.Type), new _syntax.FsProperty(tp.data.Comments, tp.data.Kind, Index, tp.data.Name, tp.data.Option, Type_1, tp.data.IsReadonly)));
|
|
|
|
case 3:
|
|
return new _syntax.FsType(3, (Type_2 = fixType(fix, tp.data.Type), new _syntax.FsParam(tp.data.Comment, tp.data.Name, tp.data.Optional, tp.data.ParamArray, Type_2)));
|
|
|
|
case 4:
|
|
return new _syntax.FsType(4, fixType(fix, tp.data));
|
|
|
|
case 8:
|
|
return new _syntax.FsType(8, (TypeParameters = (0, _List.map)(function (tp_3) {
|
|
return fixType(fix, tp_3);
|
|
}, tp.data.TypeParameters), Params = function (list_1) {
|
|
return (0, _List.map)(fixParam, list_1);
|
|
}(tp.data.Params), ReturnType = fixType(fix, tp.data.ReturnType), new _syntax.FsFunction(tp.data.Comments, tp.data.Kind, tp.data.IsStatic, tp.data.Name, TypeParameters, Params, ReturnType)));
|
|
|
|
case 9:
|
|
return new _syntax.FsType(9, (Types_1 = (0, _List.map)(function (tp_4) {
|
|
return fixType(fix, tp_4);
|
|
}, tp.data.Types), new _syntax.FsUnion(tp.data.Option, Types_1)));
|
|
|
|
case 10:
|
|
return new _syntax.FsType(10, (Type_3 = fixType(fix, tp.data.Type), TypeParameters_1 = (0, _List.map)(function (tp_5) {
|
|
return fixType(fix, tp_5);
|
|
}, tp.data.TypeParameters), new _syntax.FsAlias(tp.data.Name, Type_3, TypeParameters_1)));
|
|
|
|
case 11:
|
|
return new _syntax.FsType(11, new _syntax.FsGenericType(fixType(fix, tp.data.Type), (0, _List.map)(function (tp_6) {
|
|
return fixType(fix, tp_6);
|
|
}, tp.data.TypeParameters)));
|
|
|
|
case 12:
|
|
return new _syntax.FsType(12, new _syntax.FsTuple((0, _List.map)(function (tp_7) {
|
|
return fixType(fix, tp_7);
|
|
}, tp.data.Types), tp.data.Kind));
|
|
|
|
case 13:
|
|
return new _syntax.FsType(13, fixModule(tp.data));
|
|
|
|
case 14:
|
|
return new _syntax.FsType(14, fixFile(tp.data));
|
|
|
|
case 15:
|
|
return new _syntax.FsType(15, (Files = function (list_2) {
|
|
return (0, _List.map)(fixFile, list_2);
|
|
}(tp.data.Files), new _syntax.FsFileOut(tp.data.Namespace, tp.data.Opens, Files)));
|
|
|
|
case 16:
|
|
return new _syntax.FsType(16, (Type_4 = fixType(fix, tp.data.Type), new _syntax.FsVariable(tp.data.Export, tp.data.HasDeclare, tp.data.Name, Type_4, tp.data.IsConst)));
|
|
|
|
case 18:
|
|
return tp;
|
|
|
|
case 1:
|
|
return tp;
|
|
|
|
case 7:
|
|
return tp;
|
|
|
|
case 6:
|
|
return tp;
|
|
|
|
case 5:
|
|
return tp;
|
|
|
|
case 17:
|
|
return tp;
|
|
|
|
case 19:
|
|
return tp;
|
|
|
|
case 20:
|
|
return tp;
|
|
|
|
case 22:
|
|
return new _syntax.FsType(22, new _syntax.FsGenericParameterDefaults(fixType(fix, tp.data.Default), tp.data.Name, tp.data.FullName));
|
|
|
|
default:
|
|
return new _syntax.FsType(0, (TypeParameters_2 = (0, _List.map)(function (tp_8) {
|
|
return fixType(fix, tp_8);
|
|
}, tp.data.TypeParameters), Inherits = (0, _List.map)(function (tp_9) {
|
|
return fixType(fix, tp_9);
|
|
}, tp.data.Inherits), Members = (0, _List.map)(function (tp_10) {
|
|
return fixType(fix, tp_10);
|
|
}, tp.data.Members), new _syntax.FsInterface(tp.data.Comments, tp.data.IsStatic, tp.data.IsClass, tp.data.Name, tp.data.FullName, TypeParameters_2, Inherits, Members)));
|
|
}
|
|
})());
|
|
}
|
|
|
|
function fixFile(fix, f) {
|
|
const Modules = function (list) {
|
|
return (0, _List.choose)(_syntax.FsTypeModule.asModule.bind(_syntax.FsTypeModule), list);
|
|
}((0, _List.map)(function (tp_1) {
|
|
return fixType(fix, tp_1);
|
|
}, (0, _List.map)(function (arg0) {
|
|
return new _syntax.FsType(13, arg0);
|
|
}, f.Modules)));
|
|
|
|
return new _syntax.FsFile(f.FileName, f.ModuleName, Modules);
|
|
}
|
|
|
|
function mergeTypes(tps) {
|
|
var Inherits;
|
|
var Members;
|
|
const index = new Map();
|
|
const list = [];
|
|
|
|
for (let b of tps) {
|
|
if (b.tag === 0) {
|
|
if (index.has(b.data.Name)) {
|
|
const i = index.get(b.data.Name) | 0;
|
|
const a = list[i];
|
|
|
|
if (a.tag === 0) {
|
|
list[i] = new _syntax.FsType(0, (Inherits = (0, _Seq.toList)((0, _Set.distinct)((0, _List.append)(a.data.Inherits, b.data.Inherits))), Members = (0, _List.append)(a.data.Members, b.data.Members), new _syntax.FsInterface(a.data.Comments, a.data.IsStatic, a.data.IsClass, a.data.Name, a.data.FullName, a.data.TypeParameters, Inherits, Members)));
|
|
}
|
|
} else {
|
|
list.push(b);
|
|
index.set(b.data.Name, list.length - 1);
|
|
}
|
|
} else {
|
|
list.push(b);
|
|
}
|
|
}
|
|
|
|
return (0, _Seq.toList)(list);
|
|
}
|
|
|
|
function mergeModules(tps) {
|
|
var Types_1;
|
|
const index = new Map();
|
|
const list = [];
|
|
|
|
for (let tp of tps) {
|
|
if (tp.tag === 13) {
|
|
let md2;
|
|
const Types = mergeModules(mergeTypes(tp.data.Types));
|
|
md2 = new _syntax.FsModule(tp.data.HasDeclare, tp.data.IsNamespace, tp.data.Name, Types, tp.data.HelperLines, tp.data.Attributes);
|
|
|
|
if (index.has(tp.data.Name)) {
|
|
const i = index.get(tp.data.Name) | 0;
|
|
const a = (0, _Option.getValue)(_syntax.FsTypeModule.asModule(list[i]));
|
|
list[i] = new _syntax.FsType(13, (Types_1 = mergeTypes((0, _List.append)(a.Types, md2.Types)), new _syntax.FsModule(a.HasDeclare, a.IsNamespace, a.Name, Types_1, a.HelperLines, a.Attributes)));
|
|
} else {
|
|
list.push.bind(list)(new _syntax.FsType(13, md2)), void 0;
|
|
index.set(md2.Name, list.length - 1);
|
|
}
|
|
} else {
|
|
list.push(tp), void 0;
|
|
}
|
|
}
|
|
|
|
return (0, _Seq.toList)(list);
|
|
}
|
|
|
|
function mergeModulesInFile(f) {
|
|
const Modules = function (list) {
|
|
return (0, _List.choose)(_syntax.FsTypeModule.asModule.bind(_syntax.FsTypeModule), list);
|
|
}(mergeModules((0, _List.map)(function (arg0) {
|
|
return new _syntax.FsType(13, arg0);
|
|
}, (0, _Seq.toList)(f.Modules))));
|
|
|
|
return new _syntax.FsFile(f.FileName, f.ModuleName, Modules);
|
|
}
|
|
|
|
const engines = exports.engines = (0, _Set.create)((0, _List.ofArray)(["node", "vscode"]), new _Comparer2.default(_Util.comparePrimitives));
|
|
|
|
function createIExportsModule(ns, md) {
|
|
var Comments;
|
|
var Inherits;
|
|
const typesInIExports = [];
|
|
const typesGlobal = [];
|
|
const typesChild = [];
|
|
const typesChildExport = [];
|
|
const typesOther = [];
|
|
const variablesForParent = [];
|
|
const variables = (0, _Set.create)();
|
|
const exportAssignments = new Set();
|
|
(0, _Seq.iterate)(function (tp) {
|
|
if (tp.tag === 18) {
|
|
(0, _Set.addInPlace)(tp.data, exportAssignments), void 0;
|
|
}
|
|
}, md.Types);
|
|
(0, _Seq.iterate)(function (tp_1) {
|
|
switch (tp_1.tag) {
|
|
case 13:
|
|
const ns_1 = md.Name === "" ? ns : (0, _List.append)(ns, (0, _List.ofArray)([(0, _String.replace)(md.Name, "'", "")]));
|
|
const patternInput = createIExportsModule(ns_1, tp_1.data);
|
|
|
|
for (let v of patternInput[1]) {
|
|
if ((0, _CurriedLambda2.default)(() => v.Export != null)()) {
|
|
(function (arg00) {
|
|
return (0, _Set.addInPlace)(arg00, variables);
|
|
})(v), void 0;
|
|
} else {
|
|
typesChild.push.bind(typesChild)(new _syntax.FsType(16, v));
|
|
}
|
|
}
|
|
|
|
typesOther.push.bind(typesOther)(new _syntax.FsType(13, patternInput[0]));
|
|
break;
|
|
|
|
case 16:
|
|
if (tp_1.data.HasDeclare) {
|
|
if (md.Name === "") {
|
|
typesGlobal.push.bind(typesGlobal)(new _syntax.FsType(16, new _syntax.FsVariable(new _syntax.FsExport(engines.has((0, _Seq.item)(0, ns)), "*", (0, _Seq.item)(0, ns)), tp_1.data.HasDeclare, tp_1.data.Name, tp_1.data.Type, tp_1.data.IsConst)));
|
|
} else if (tp_1.data.IsGlobal) {
|
|
typesGlobal.push(tp_1);
|
|
} else {
|
|
typesOther.push(tp_1);
|
|
}
|
|
} else {
|
|
typesInIExports.push(tp_1);
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
typesInIExports.push(tp_1);
|
|
break;
|
|
|
|
case 0:
|
|
if (tp_1.data.IsStatic) {
|
|
typesInIExports.push.bind(typesInIExports)(new _syntax.FsType(2, new _syntax.FsProperty(new _List2.default(), new _syntax.FsPropertyKind(0), null, (0, _String.replace)(tp_1.data.Name, "Static", ""), false, (0, _syntax.simpleType)(tp_1.data.Name), true)));
|
|
}
|
|
|
|
typesOther.push(tp_1);
|
|
break;
|
|
|
|
default:
|
|
typesOther.push(tp_1);
|
|
}
|
|
}, md.Types);
|
|
const ns_2 = engines.has((0, _Seq.item)(0, ns)) ? (0, _List.slice)(1, null, ns) : ns;
|
|
const selector = ns_2.length === 0 ? "*" : (0, _String.replace)(md.Name, "'", "");
|
|
const path = ns_2.length === 0 ? (0, _String.replace)(md.Name, "'", "") : (0, _String.join)("/", ns_2);
|
|
|
|
if (typesInIExports.length > 0) {
|
|
if (md.HasDeclare) {
|
|
if (!md.IsNamespace) {
|
|
variablesForParent.push.bind(variablesForParent)(new _syntax.FsVariable(new _syntax.FsExport(false, "*", path), true, (0, _naming.lowerFirst)(md.Name), (0, _syntax.simpleType)((0, _String.toText)((0, _String.printf)("%s.IExports"))((0, _naming.fixModuleName)(md.Name))), true));
|
|
}
|
|
} else {
|
|
variablesForParent.push.bind(variablesForParent)(new _syntax.FsVariable(new _syntax.FsExport(false, selector, path), true, (0, _naming.lowerFirst)(md.Name), (0, _syntax.simpleType)((0, _String.toText)((0, _String.printf)("%s.IExports"))((0, _naming.fixModuleName)(md.Name))), true));
|
|
}
|
|
}
|
|
|
|
const iexports = typesInIExports.length === 0 ? new _List2.default() : (0, _List.ofArray)([new _syntax.FsType(0, (Comments = new _List2.default(), Inherits = new _List2.default(), new _syntax.FsInterface(Comments, false, false, "IExports", "IExports", new _List2.default(), Inherits, (0, _Seq.toList)(typesInIExports))))]);
|
|
const globalNames = (0, _Set.create)(function (source) {
|
|
return (0, _Seq.map)(_syntax.getName, source);
|
|
}(typesGlobal), new _Comparer2.default(_Util.comparePrimitives));
|
|
(0, _Seq.iterate)(function (tp_3) {
|
|
if (tp_3.tag === 13) {
|
|
if (!globalNames.has(tp_3.data.Name) ? exportAssignments.has(tp_3.data.Name) : false) {
|
|
(function (arg00_7) {
|
|
return (0, _Set.addInPlace)(arg00_7, variables);
|
|
})(new _syntax.FsVariable(new _syntax.FsExport(false, "*", path), true, (0, _naming.lowerFirst)(tp_3.data.Name), (0, _syntax.simpleType)((0, _String.toText)((0, _String.printf)("%s.IExports"))((0, _naming.fixModuleName)(tp_3.data.Name))), true)), void 0;
|
|
}
|
|
}
|
|
}, md.Types);
|
|
let newMd;
|
|
const Types = (0, _List.append)((0, _List.map)(function (arg0) {
|
|
return new _syntax.FsType(16, arg0);
|
|
}, (0, _Seq.toList)(variables)), (0, _List.append)((0, _Seq.toList)(typesGlobal), (0, _List.append)((0, _Seq.toList)(typesChildExport), (0, _List.append)((0, _Seq.toList)(typesChild), (0, _List.append)(iexports, (0, _Seq.toList)(typesOther))))));
|
|
newMd = new _syntax.FsModule(md.HasDeclare, md.IsNamespace, md.Name, Types, md.HelperLines, md.Attributes);
|
|
return [newMd, (0, _Seq.toList)(variablesForParent)];
|
|
}
|
|
|
|
function createIExports(f) {
|
|
const Modules = (0, _List.map)(function (md) {
|
|
const patternInput = createIExportsModule((0, _List.ofArray)([f.ModuleName]), md);
|
|
return patternInput[0];
|
|
}, (0, _Seq.toList)(f.Modules));
|
|
return new _syntax.FsFile(f.FileName, f.ModuleName, Modules);
|
|
}
|
|
|
|
function fixTic(typeParameters, tp) {
|
|
if (typeParameters.length === 0) {
|
|
return tp;
|
|
} else {
|
|
const set = (0, _Set.create)(typeParameters, new _Comparer2.default((x, y) => x.CompareTo(y)));
|
|
|
|
const fix = function (t) {
|
|
if (t.tag === 7) {
|
|
if (set.has(t)) {
|
|
return new _syntax.FsType(7, new _syntax.FsMapped((0, _String.toText)((0, _String.printf)("'%s"))(t.data.Name), t.data.FullName));
|
|
} else {
|
|
return t;
|
|
}
|
|
} else {
|
|
return t;
|
|
}
|
|
};
|
|
|
|
return fixType(fix, tp);
|
|
}
|
|
}
|
|
|
|
function addTicForGenericFunctions(f) {
|
|
return fixFile(function (tp) {
|
|
return tp.tag === 8 ? fixTic(tp.data.TypeParameters, tp) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function fixOverloadingOnStringParameters(f) {
|
|
return fixFile(function (tp) {
|
|
var Kind;
|
|
var Name;
|
|
var Params;
|
|
|
|
if (tp.tag === 8) {
|
|
if (tp.data.HasStringLiteralParams) {
|
|
const kind = [];
|
|
const name = [];
|
|
const prms = [];
|
|
kind.push.bind(kind)((0, _String.toText)((0, _String.printf)("$0.%s("))((0, _Option.getValue)(tp.data.Name)));
|
|
name.push.bind(name)((0, _String.toText)((0, _String.printf)("%s"))((0, _Option.getValue)(tp.data.Name)));
|
|
const slCount = {
|
|
contents: 0
|
|
};
|
|
(0, _Seq.iterateIndexed)(function (i, prm) {
|
|
const matchValue = _syntax.FsTypeModule.asStringLiteral(prm.Type);
|
|
|
|
if (matchValue != null) {
|
|
void slCount.contents++;
|
|
kind.push.bind(kind)((0, _String.toText)((0, _String.printf)("'%s'"))((0, _Option.getValue)(matchValue)));
|
|
name.push.bind(name)((0, _String.toText)((0, _String.printf)("_%s"))((0, _Option.getValue)(matchValue)));
|
|
} else {
|
|
kind.push.bind(kind)((0, _String.toText)((0, _String.printf)("$%d"))(i + 1 - slCount.contents));
|
|
prms.push(prm);
|
|
}
|
|
|
|
if (i < tp.data.Params.length - 1) {
|
|
kind.push.bind(kind)(",");
|
|
}
|
|
}, tp.data.Params);
|
|
kind.push.bind(kind)(")");
|
|
return new _syntax.FsType(8, (Kind = new _syntax.FsFunctionKind(3, (0, _String.join)("", kind)), Name = (0, _String.join)("", name), Params = (0, _Seq.toList)(prms), new _syntax.FsFunction(tp.data.Comments, Kind, tp.data.IsStatic, Name, tp.data.TypeParameters, Params, tp.data.ReturnType)));
|
|
} else {
|
|
return tp;
|
|
}
|
|
} else {
|
|
return tp;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function fixNodeArray(f) {
|
|
return fixFile(function (tp) {
|
|
return tp.tag === 11 ? tp.data.Type.tag === 7 ? (tp.data.Type.data.Name === "NodeArray" ? tp.data.TypeParameters.length === 1 : false) ? new _syntax.FsType(4, (0, _Seq.item)(0, tp.data.TypeParameters)) : tp : tp : tp;
|
|
}, f);
|
|
}
|
|
|
|
function fixReadonlyArray(f) {
|
|
const fix = function (tp) {
|
|
if (tp.tag === 11) {
|
|
if (tp.data.Type.tag === 7) {
|
|
if (tp.data.Type.data.Name === "ReadonlyArray" ? tp.data.TypeParameters.length === 1 : false) {
|
|
return new _syntax.FsType(4, (0, _Seq.item)(0, tp.data.TypeParameters));
|
|
} else {
|
|
return tp;
|
|
}
|
|
} else {
|
|
return tp;
|
|
}
|
|
} else {
|
|
return tp;
|
|
}
|
|
};
|
|
|
|
return fixFile(function (tp_1) {
|
|
return tp_1.tag === 8 ? fixType(fix, tp_1) : tp_1;
|
|
}, f);
|
|
}
|
|
|
|
function fixEscapeWords(f) {
|
|
return fixFile(function (tp) {
|
|
var Name;
|
|
var Name_1;
|
|
var Name_2;
|
|
var Name_3;
|
|
var Name_4;
|
|
var Name_5;
|
|
|
|
switch (tp.tag) {
|
|
case 7:
|
|
return new _syntax.FsType(7, new _syntax.FsMapped((0, _naming.escapeWord)(tp.data.Name), tp.data.FullName));
|
|
|
|
case 3:
|
|
return new _syntax.FsType(3, (Name = (0, _naming.escapeWord)(tp.data.Name), new _syntax.FsParam(tp.data.Comment, Name, tp.data.Optional, tp.data.ParamArray, tp.data.Type)));
|
|
|
|
case 8:
|
|
return new _syntax.FsType(8, (Name_1 = function (option) {
|
|
return (0, _Option.defaultArg)(option, null, _naming.escapeWord);
|
|
}(tp.data.Name), new _syntax.FsFunction(tp.data.Comments, tp.data.Kind, tp.data.IsStatic, Name_1, tp.data.TypeParameters, tp.data.Params, tp.data.ReturnType)));
|
|
|
|
case 2:
|
|
return new _syntax.FsType(2, (Name_2 = (0, _naming.escapeWord)(tp.data.Name), new _syntax.FsProperty(tp.data.Comments, tp.data.Kind, tp.data.Index, Name_2, tp.data.Option, tp.data.Type, tp.data.IsReadonly)));
|
|
|
|
case 0:
|
|
return new _syntax.FsType(0, (Name_3 = (0, _naming.escapeWord)(tp.data.Name), new _syntax.FsInterface(tp.data.Comments, tp.data.IsStatic, tp.data.IsClass, Name_3, tp.data.FullName, tp.data.TypeParameters, tp.data.Inherits, tp.data.Members)));
|
|
|
|
case 13:
|
|
return new _syntax.FsType(13, (Name_4 = (0, _naming.fixModuleName)(tp.data.Name), new _syntax.FsModule(tp.data.HasDeclare, tp.data.IsNamespace, Name_4, tp.data.Types, tp.data.HelperLines, tp.data.Attributes)));
|
|
|
|
case 16:
|
|
return new _syntax.FsType(16, (Name_5 = (0, _naming.escapeWord)(tp.data.Name), new _syntax.FsVariable(tp.data.Export, tp.data.HasDeclare, Name_5, tp.data.Type, tp.data.IsConst)));
|
|
|
|
case 10:
|
|
return new _syntax.FsType(10, new _syntax.FsAlias((0, _naming.escapeWord)(tp.data.Name), tp.data.Type, tp.data.TypeParameters));
|
|
|
|
default:
|
|
return tp;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function fixDateTime(f) {
|
|
const replaceName = function (name) {
|
|
if ("Date" === name) {
|
|
return "DateTime";
|
|
} else {
|
|
return name;
|
|
}
|
|
};
|
|
|
|
return fixFile(function (tp) {
|
|
return tp.tag === 7 ? new _syntax.FsType(7, new _syntax.FsMapped(replaceName(tp.data.Name), tp.data.FullName)) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function fixEnumReferences(f) {
|
|
const list = [];
|
|
fixFile(function (tp) {
|
|
if (tp.tag === 1) {
|
|
list.push(tp.data.Name), void 0;
|
|
return tp;
|
|
} else {
|
|
return tp;
|
|
}
|
|
}, f), void 0;
|
|
const set = (0, _Set.create)(list, new _Comparer2.default(_Util.comparePrimitives));
|
|
return fixFile(function (tp_1) {
|
|
if (tp_1.tag === 7) {
|
|
if (tp_1.data.Name.indexOf(".") >= 0) {
|
|
const nm = tp_1.data.Name.substr(0, tp_1.data.Name.indexOf("."));
|
|
|
|
if (set.has(nm)) {
|
|
return (0, _syntax.simpleType)(nm);
|
|
} else {
|
|
return tp_1;
|
|
}
|
|
} else {
|
|
return tp_1;
|
|
}
|
|
} else {
|
|
return tp_1;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function fixDuplicatesInUnion(f) {
|
|
return fixFile(function (tp) {
|
|
if (tp.tag === 9) {
|
|
const set = (0, _Set.create)();
|
|
const tps = (0, _List.choose)(function (tp_1) {
|
|
if (set.has(tp_1)) {
|
|
return null;
|
|
} else {
|
|
(0, _Set.addInPlace)(tp_1, set), void 0;
|
|
return tp_1;
|
|
}
|
|
}, tp.data.Types);
|
|
|
|
if (tps.length > 8) {
|
|
return (0, _syntax.simpleType)("obj");
|
|
} else {
|
|
return new _syntax.FsType(9, new _syntax.FsUnion(tp.data.Option, tps));
|
|
}
|
|
} else {
|
|
return tp;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function addTicForGenericTypes(f) {
|
|
return fixFile(function (tp) {
|
|
return tp.tag === 0 ? fixTic(tp.data.TypeParameters, tp) : tp.tag === 10 ? fixTic(tp.data.TypeParameters, tp) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function fixThis(f) {
|
|
return fixFile(function (tp) {
|
|
var Members;
|
|
|
|
if (tp.tag === 0) {
|
|
const replaceThis = function (tp_1) {
|
|
if (tp_1.tag === 19) {
|
|
return new _syntax.FsType(11, new _syntax.FsGenericType((0, _syntax.simpleType)(tp.data.Name), tp.data.TypeParameters));
|
|
} else {
|
|
return tp_1;
|
|
}
|
|
};
|
|
|
|
return new _syntax.FsType(0, (Members = (0, _List.map)(function (tp_2) {
|
|
return fixType(replaceThis, tp_2);
|
|
}, tp.data.Members), new _syntax.FsInterface(tp.data.Comments, tp.data.IsStatic, tp.data.IsClass, tp.data.Name, tp.data.FullName, tp.data.TypeParameters, tp.data.Inherits, Members)));
|
|
} else {
|
|
return tp;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function fixStatic(f) {
|
|
return fixFile(function (tp) {
|
|
var Types;
|
|
return tp.tag === 13 ? new _syntax.FsType(13, (Types = (0, _List.collect)(function (tp2) {
|
|
var Members;
|
|
var Name;
|
|
var Inherits;
|
|
var Members_1;
|
|
return tp2.tag === 0 ? tp2.data.HasStaticMembers ? (0, _List.ofArray)([new _syntax.FsType(0, (Members = tp2.data.NonStaticMembers, new _syntax.FsInterface(tp2.data.Comments, tp2.data.IsStatic, tp2.data.IsClass, tp2.data.Name, tp2.data.FullName, tp2.data.TypeParameters, tp2.data.Inherits, Members))), new _syntax.FsType(0, (Name = (0, _String.toText)((0, _String.printf)("%sStatic"))(tp2.data.Name), Inherits = new _List2.default(), Members_1 = tp2.data.StaticMembers, new _syntax.FsInterface(tp2.data.Comments, true, tp2.data.IsClass, Name, tp2.data.FullName, tp2.data.TypeParameters, Inherits, Members_1)))]) : (0, _List.ofArray)([tp2]) : (0, _List.ofArray)([tp2]);
|
|
}, tp.data.Types), new _syntax.FsModule(tp.data.HasDeclare, tp.data.IsNamespace, tp.data.Name, Types, tp.data.HelperLines, tp.data.Attributes))) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function hasTodo(tp) {
|
|
let has = false;
|
|
fixType(function (t) {
|
|
if (t.tag === 5) {
|
|
has = true;
|
|
return t;
|
|
} else {
|
|
return t;
|
|
}
|
|
}, tp), void 0;
|
|
return has;
|
|
}
|
|
|
|
function removeTodoMembers(f) {
|
|
return fixFile(function (tp) {
|
|
var Members;
|
|
return tp.tag === 0 ? new _syntax.FsType(0, (Members = (0, _List.filter)(function (mb) {
|
|
if (hasTodo(mb)) {
|
|
(0, _String.toConsole)((0, _String.printf)("removing member with TODO: %s.%s"))((0, _syntax.getName)(tp), (0, _syntax.getName)(mb));
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}, tp.data.Members), new _syntax.FsInterface(tp.data.Comments, tp.data.IsStatic, tp.data.IsClass, tp.data.Name, tp.data.FullName, tp.data.TypeParameters, tp.data.Inherits, Members))) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function removeTypeParamsFromStatic(f) {
|
|
return fixFile(function (tp) {
|
|
var TypeParameters;
|
|
return tp.tag === 0 ? new _syntax.FsType(0, (TypeParameters = tp.data.IsStatic ? new _List2.default() : tp.data.TypeParameters, new _syntax.FsInterface(tp.data.Comments, tp.data.IsStatic, tp.data.IsClass, tp.data.Name, tp.data.FullName, TypeParameters, tp.data.Inherits, tp.data.Members))) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function addConstructors(f) {
|
|
const list = [];
|
|
fixFile(function (tp) {
|
|
if (tp.tag === 0) {
|
|
if (tp.data.IsClass ? tp.data.HasConstructor : false) {
|
|
list.push(tp.data), void 0;
|
|
return tp;
|
|
} else {
|
|
return tp;
|
|
}
|
|
} else {
|
|
return tp;
|
|
}
|
|
}, f), void 0;
|
|
const map = new Map((0, _Seq.map)(function (it) {
|
|
return [it.FullName, it];
|
|
}, list));
|
|
return fixFile(function (tp_1) {
|
|
var Members;
|
|
var Members_1;
|
|
|
|
if (tp_1.tag === 0) {
|
|
if (tp_1.data.IsClass) {
|
|
if (tp_1.data.HasConstructor) {
|
|
return tp_1;
|
|
} else {
|
|
const parent = (0, _Seq.tryPick)(function (inh) {
|
|
const fn = (0, _syntax.getFullName)(inh);
|
|
|
|
if (map.has(fn)) {
|
|
return map.get(fn);
|
|
} else {
|
|
return null;
|
|
}
|
|
}, tp_1.data.Inherits);
|
|
|
|
if (parent == null) {
|
|
const defaultCtr = new _syntax.FsType(8, new _syntax.FsFunction(new _List2.default(), new _syntax.FsFunctionKind(1), true, "Create", tp_1.data.TypeParameters, new _List2.default(), new _syntax.FsType(19)));
|
|
return new _syntax.FsType(0, (Members = (0, _List.append)((0, _List.ofArray)([defaultCtr]), tp_1.data.Members), new _syntax.FsInterface(tp_1.data.Comments, tp_1.data.IsStatic, tp_1.data.IsClass, tp_1.data.Name, tp_1.data.FullName, tp_1.data.TypeParameters, tp_1.data.Inherits, Members)));
|
|
} else {
|
|
return new _syntax.FsType(0, (Members_1 = (0, _List.append)((0, _Option.getValue)(parent).Constructors, tp_1.data.Members), new _syntax.FsInterface(tp_1.data.Comments, tp_1.data.IsStatic, tp_1.data.IsClass, tp_1.data.Name, tp_1.data.FullName, tp_1.data.TypeParameters, tp_1.data.Inherits, Members_1)));
|
|
}
|
|
}
|
|
} else {
|
|
return tp_1;
|
|
}
|
|
} else {
|
|
return tp_1;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function removeInternalModules(f) {
|
|
return fixFile(function (tp) {
|
|
var Types;
|
|
return tp.tag === 13 ? new _syntax.FsType(13, (Types = (0, _List.collect)(function (tp_1) {
|
|
const $var1 = tp_1.tag === 13 ? tp_1.data.Name === "internal" ? [0, tp_1.data] : [1] : [1];
|
|
|
|
switch ($var1[0]) {
|
|
case 0:
|
|
return $var1[1].Types;
|
|
|
|
case 1:
|
|
return (0, _List.ofArray)([tp_1]);
|
|
}
|
|
}, tp.data.Types), new _syntax.FsModule(tp.data.HasDeclare, tp.data.IsNamespace, tp.data.Name, Types, tp.data.HelperLines, tp.data.Attributes))) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function removeDuplicateFunctions(f) {
|
|
return fixFile(function (tp) {
|
|
var Members;
|
|
|
|
if (tp.tag === 0) {
|
|
const set = (0, _Set.create)();
|
|
return new _syntax.FsType(0, (Members = (0, _List.collect)(function (mb) {
|
|
if (mb.tag === 8) {
|
|
let fn2;
|
|
const Comments = new _List2.default();
|
|
const ReturnType = new _syntax.FsType(6);
|
|
fn2 = new _syntax.FsFunction(Comments, mb.data.Kind, mb.data.IsStatic, mb.data.Name, mb.data.TypeParameters, mb.data.Params, ReturnType);
|
|
|
|
if ((0, _Set.addInPlace)(fn2, set)) {
|
|
return (0, _List.ofArray)([mb]);
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
} else {
|
|
return (0, _List.ofArray)([mb]);
|
|
}
|
|
}, tp.data.Members), new _syntax.FsInterface(tp.data.Comments, tp.data.IsStatic, tp.data.IsClass, tp.data.Name, tp.data.FullName, tp.data.TypeParameters, tp.data.Inherits, Members)));
|
|
} else {
|
|
return tp;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function removeDuplicateOptions(f) {
|
|
return fixFile(function (tp) {
|
|
var Type;
|
|
const $var2 = tp.tag === 2 ? tp.data.Option ? [0, tp.data] : [1] : [1];
|
|
|
|
switch ($var2[0]) {
|
|
case 0:
|
|
const $var3 = $var2[1].Type.tag === 9 ? $var2[1].Type.data.Option ? [0, $var2[1].Type.data] : [1] : [1];
|
|
|
|
switch ($var3[0]) {
|
|
case 0:
|
|
return new _syntax.FsType(2, (Type = new _syntax.FsType(9, new _syntax.FsUnion(false, $var3[1].Types)), new _syntax.FsProperty($var2[1].Comments, $var2[1].Kind, $var2[1].Index, $var2[1].Name, $var2[1].Option, Type, $var2[1].IsReadonly)));
|
|
|
|
case 1:
|
|
return tp;
|
|
}
|
|
|
|
case 1:
|
|
return tp;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function extractTypeLiterals(f) {
|
|
return fixFile(function (tp) {
|
|
var Types_1;
|
|
|
|
if (tp.tag === 13) {
|
|
const typeNames = new Set(function (list) {
|
|
return (0, _List.map)(_syntax.getName, list);
|
|
}(tp.data.Types));
|
|
|
|
const newTypeName = function (name) {
|
|
newTypeName: while (true) {
|
|
const name_1 = (0, _naming.capitalize)(name);
|
|
|
|
if (typeNames.has(name_1)) {
|
|
const name_2 = (0, _String.toText)((0, _String.printf)("%s_"))(name_1);
|
|
|
|
if (typeNames.has(name_2)) {
|
|
name = name_2;
|
|
continue newTypeName;
|
|
} else {
|
|
(0, _Set.addInPlace)(name_2, typeNames), void 0;
|
|
return name_2;
|
|
}
|
|
} else {
|
|
(0, _Set.addInPlace)(name_1, typeNames), void 0;
|
|
return name_1;
|
|
}
|
|
}
|
|
};
|
|
|
|
return new _syntax.FsType(13, (Types_1 = (0, _List.collect)(function (tp_2) {
|
|
var Members;
|
|
var Type_1;
|
|
var Comments_1;
|
|
var Inherits_1;
|
|
|
|
if (tp_2.tag === 0) {
|
|
const newTypes = [];
|
|
const it2 = new _syntax.FsType(0, (Members = (0, _List.map)(function (mb) {
|
|
var Params;
|
|
return mb.tag === 8 ? new _syntax.FsType(8, (Params = (0, _List.map)(function (prm) {
|
|
var Comments;
|
|
var Inherits;
|
|
|
|
if (prm.Type.tag === 21) {
|
|
let name_3;
|
|
const itName = tp_2.data.Name === "IExports" ? "" : (0, _String.replace)(tp_2.data.Name, "`", "");
|
|
const fnName = (0, _String.replace)((0, _Option.getValue)(mb.data.Name), "`", "");
|
|
const pmName = (0, _String.replace)(prm.Name, "`", "");
|
|
|
|
if (fnName === "Create") {
|
|
name_3 = newTypeName((0, _String.toText)((0, _String.printf)("%s%s"))(itName, (0, _naming.capitalize)(pmName)));
|
|
} else if (fnName === pmName) {
|
|
name_3 = newTypeName((0, _String.toText)((0, _String.printf)("%s%s"))(itName, (0, _naming.capitalize)(pmName)));
|
|
} else {
|
|
name_3 = newTypeName((0, _String.toText)((0, _String.printf)("%s%s%s"))(itName, (0, _naming.capitalize)(fnName), (0, _naming.capitalize)(pmName)));
|
|
}
|
|
|
|
newTypes.push.bind(newTypes)(new _syntax.FsType(0, (Comments = new _List2.default(), Inherits = new _List2.default(), new _syntax.FsInterface(Comments, false, false, name_3, name_3, new _List2.default(), Inherits, prm.Type.data.Members)))), void 0;
|
|
const Type = (0, _syntax.simpleType)(name_3);
|
|
return new _syntax.FsParam(prm.Comment, prm.Name, prm.Optional, prm.ParamArray, Type);
|
|
} else {
|
|
return prm;
|
|
}
|
|
}, mb.data.Params), new _syntax.FsFunction(mb.data.Comments, mb.data.Kind, mb.data.IsStatic, mb.data.Name, mb.data.TypeParameters, Params, mb.data.ReturnType))) : mb;
|
|
}, tp_2.data.Members), new _syntax.FsInterface(tp_2.data.Comments, tp_2.data.IsStatic, tp_2.data.IsClass, tp_2.data.Name, tp_2.data.FullName, tp_2.data.TypeParameters, tp_2.data.Inherits, Members)));
|
|
return (0, _List.append)((0, _List.ofArray)([it2]), (0, _Seq.toList)(newTypes));
|
|
} else if (tp_2.tag === 10) {
|
|
if (tp_2.data.Type.tag === 9) {
|
|
let un2;
|
|
let Types;
|
|
const tps = [];
|
|
(0, _Seq.iterate)(function (tp_3) {
|
|
if (tp_3.tag === 21) {
|
|
(function (arg00_1) {
|
|
(0, _Array.addRangeInPlace)(arg00_1, tps);
|
|
})(tp_3.data.Members);
|
|
} else {
|
|
tps.push.bind(tps)(tp_3);
|
|
}
|
|
}, tp_2.data.Type.data.Types);
|
|
Types = (0, _Seq.toList)(tps);
|
|
un2 = new _syntax.FsUnion(tp_2.data.Type.data.Option, Types);
|
|
return (0, _List.singleton)(new _syntax.FsType(10, (Type_1 = new _syntax.FsType(9, un2), new _syntax.FsAlias(tp_2.data.Name, Type_1, tp_2.data.TypeParameters))));
|
|
} else if (tp_2.data.Type.tag === 21) {
|
|
return (0, _List.singleton)(new _syntax.FsType(0, (Comments_1 = new _List2.default(), Inherits_1 = new _List2.default(), new _syntax.FsInterface(Comments_1, false, false, tp_2.data.Name, tp_2.data.Name, tp_2.data.TypeParameters, Inherits_1, tp_2.data.Type.data.Members))));
|
|
} else {
|
|
return (0, _List.ofArray)([tp_2]);
|
|
}
|
|
} else {
|
|
return (0, _List.ofArray)([tp_2]);
|
|
}
|
|
}, tp.data.Types), new _syntax.FsModule(tp.data.HasDeclare, tp.data.IsNamespace, tp.data.Name, Types_1, tp.data.HelperLines, tp.data.Attributes)));
|
|
} else {
|
|
return tp;
|
|
}
|
|
}, f);
|
|
}
|
|
|
|
function addAliasUnionHelpers(f) {
|
|
return fixFile(function (tp) {
|
|
var Types;
|
|
return tp.tag === 13 ? new _syntax.FsType(13, (Types = (0, _List.collect)(function (tp2) {
|
|
var Attributes;
|
|
var i;
|
|
return tp2.tag === 10 ? tp2.data.Type.tag === 9 ? tp2.data.Type.data.Types.length > 1 ? (0, _List.append)((0, _List.ofArray)([tp2]), (0, _List.ofArray)([new _syntax.FsType(13, (Attributes = (0, _List.ofArray)(["RequireQualifiedAccess", "CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix"]), new _syntax.FsModule(false, false, tp2.data.Name, new _List2.default(), (i = 0, (0, _List.collect)(function (tp3) {
|
|
const n = tp2.data.Type.data.Types.length | 0;
|
|
i = i + 1 | 0;
|
|
const name = (0, _syntax.getName)(tp3);
|
|
const name_1 = name === "" ? (0, _String.toText)((0, _String.printf)("Case%d"))(i) : name;
|
|
const name_2 = (0, _String.replace)(name_1, "'", "");
|
|
const name_3 = (0, _naming.capitalize)(name_2);
|
|
const aliasNameWithTypes = (0, _String.toText)((0, _String.printf)("%s%s"))(tp2.data.Name, (0, _print.printTypeParameters)(tp2.data.TypeParameters));
|
|
|
|
if (tp2.data.Type.data.Option) {
|
|
return (0, _List.ofArray)([(0, _String.toText)((0, _String.printf)("let of%sOption v: %s = v |> Option.map U%d.Case%d"))(name_3, aliasNameWithTypes, n, i), (0, _String.toText)((0, _String.printf)("let of%s v: %s = v |> U%d.Case%d |> Some"))(name_3, aliasNameWithTypes, n, i), (0, _String.toText)((0, _String.printf)("let is%s (v: %s) = match v with None -> false | Some o -> match o with U%d.Case%d _ -> true | _ -> false"))(name_3, aliasNameWithTypes, n, i), (0, _String.toText)((0, _String.printf)("let as%s (v: %s) = match v with None -> None | Some o -> match o with U%d.Case%d o -> Some o | _ -> None"))(name_3, aliasNameWithTypes, n, i)]);
|
|
} else {
|
|
return (0, _List.ofArray)([(0, _String.toText)((0, _String.printf)("let of%s v: %s = v |> U%d.Case%d"))(name_3, aliasNameWithTypes, n, i), (0, _String.toText)((0, _String.printf)("let is%s (v: %s) = match v with U%d.Case%d _ -> true | _ -> false"))(name_3, aliasNameWithTypes, n, i), (0, _String.toText)((0, _String.printf)("let as%s (v: %s) = match v with U%d.Case%d o -> Some o | _ -> None"))(name_3, aliasNameWithTypes, n, i)]);
|
|
}
|
|
}, tp2.data.Type.data.Types)), Attributes)))])) : (0, _List.ofArray)([tp2]) : (0, _List.ofArray)([tp2]) : (0, _List.ofArray)([tp2]);
|
|
}, tp.data.Types), new _syntax.FsModule(tp.data.HasDeclare, tp.data.IsNamespace, tp.data.Name, Types, tp.data.HelperLines, tp.data.Attributes))) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function fixNamespace(f) {
|
|
return fixFile(function (tp) {
|
|
var SpecifiedModule;
|
|
return tp.tag === 7 ? new _syntax.FsType(7, new _syntax.FsMapped((0, _naming.fixNamespaceString)(tp.data.Name), tp.data.FullName)) : tp.tag === 20 ? new _syntax.FsType(20, tp.data.tag === 0 ? new _syntax.FsImport(0, (SpecifiedModule = (0, _naming.fixModuleName)(tp.data.data.SpecifiedModule), new _syntax.TypeImport(tp.data.data.Type, SpecifiedModule, tp.data.data.ResolvedModule))) : new _syntax.FsImport(1, new _syntax.ModuleImport((0, _naming.fixModuleName)(tp.data.data.Module), (0, _naming.fixModuleName)(tp.data.data.SpecifiedModule), tp.data.data.ResolvedModule))) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function aliasToInterfacePartly(f) {
|
|
const compileAliasHasOnlyFunctionToInterface = function (f_1) {
|
|
return fixFile(function (tp) {
|
|
var Inherits;
|
|
var Members;
|
|
var Name;
|
|
var Kind;
|
|
return tp.tag === 10 ? tp.data.Type.tag === 8 ? new _syntax.FsType(0, (Inherits = new _List2.default(), Members = (0, _List.singleton)(new _syntax.FsType(8, (Name = "Invoke", Kind = new _syntax.FsFunctionKind(2), new _syntax.FsFunction(tp.data.Type.data.Comments, Kind, tp.data.Type.data.IsStatic, Name, tp.data.Type.data.TypeParameters, tp.data.Type.data.Params, tp.data.Type.data.ReturnType)))), new _syntax.FsInterface(tp.data.Type.data.Comments, false, false, tp.data.Name, tp.data.Name, tp.data.TypeParameters, Inherits, Members))) : tp : tp;
|
|
}, f_1);
|
|
};
|
|
|
|
const compileAliasHasIntersectionToInterface = function (f_2) {
|
|
return fixFile(function (tp_1) {
|
|
var Comments;
|
|
var Inherits_1;
|
|
var Members_1;
|
|
return tp_1.tag === 10 ? tp_1.data.Type.tag === 12 ? tp_1.data.Type.data.Kind.tag === 0 ? new _syntax.FsType(0, (Comments = new _List2.default(), Inherits_1 = new _List2.default(), Members_1 = new _List2.default(), new _syntax.FsInterface(Comments, false, false, tp_1.data.Name, tp_1.data.Name, tp_1.data.TypeParameters, Inherits_1, Members_1))) : tp_1 : tp_1 : tp_1;
|
|
}, f_2);
|
|
};
|
|
|
|
const compileAliasHasMappedToInterface = function (f_3) {
|
|
return fixFile(function (tp_2) {
|
|
var Comments_1;
|
|
var Inherits_2;
|
|
var Members_2;
|
|
|
|
if (tp_2.tag === 10) {
|
|
const $var4 = tp_2.data.Type.tag === 12 ? tp_2.data.Type.data.Kind.Equals(new _syntax.FsTupleKind(2)) ? [0, tp_2.data.Type.data] : [1] : [1];
|
|
|
|
switch ($var4[0]) {
|
|
case 0:
|
|
return new _syntax.FsType(0, (Comments_1 = new _List2.default(), Inherits_2 = new _List2.default(), Members_2 = new _List2.default(), new _syntax.FsInterface(Comments_1, false, false, tp_2.data.Name, tp_2.data.Name, tp_2.data.TypeParameters, Inherits_2, Members_2)));
|
|
|
|
case 1:
|
|
return tp_2;
|
|
}
|
|
} else {
|
|
return tp_2;
|
|
}
|
|
}, f_3);
|
|
};
|
|
|
|
const flatten = function (f_4) {
|
|
return fixFile(function (tp_3) {
|
|
if (tp_3.tag === 12) {
|
|
const $var5 = tp_3.data.Kind.tag === 0 ? [0] : tp_3.data.Kind.tag === 2 ? [0] : [1];
|
|
|
|
switch ($var5[0]) {
|
|
case 0:
|
|
return (0, _syntax.simpleType)("obj");
|
|
|
|
case 1:
|
|
return tp_3;
|
|
}
|
|
} else {
|
|
return tp_3;
|
|
}
|
|
}, f_4);
|
|
};
|
|
|
|
return flatten(compileAliasHasMappedToInterface(compileAliasHasIntersectionToInterface(compileAliasHasOnlyFunctionToInterface(f))));
|
|
}
|
|
|
|
function fixFsFileOut(fo) {
|
|
const isBrowser = (0, _Seq.exists)(function (mp) {
|
|
return mp.Name.indexOf("HTML") === 0;
|
|
}, function (list) {
|
|
return (0, _List.choose)(_syntax.FsTypeModule.asMapped.bind(_syntax.FsTypeModule), list);
|
|
}(getAllTypes(fo.Files)));
|
|
|
|
const fixHelperLines = function (f) {
|
|
return fixFile(function (tp_1) {
|
|
var HelperLines;
|
|
return tp_1.tag === 13 ? new _syntax.FsType(13, (HelperLines = (0, _List.map)(function (l) {
|
|
return (0, _String.replace)(l, "Option.map", "Microsoft.FSharp.Core.Option.map");
|
|
}, tp_1.data.HelperLines), new _syntax.FsModule(tp_1.data.HasDeclare, tp_1.data.IsNamespace, tp_1.data.Name, tp_1.data.Types, HelperLines, tp_1.data.Attributes))) : tp_1;
|
|
}, f);
|
|
};
|
|
|
|
if (isBrowser) {
|
|
const Opens = (0, _List.append)(fo.Opens, (0, _List.ofArray)(["Fable.Import.Browser"]));
|
|
|
|
const Files = function (list_1) {
|
|
return (0, _List.map)(fixHelperLines, list_1);
|
|
}(fo.Files);
|
|
|
|
return new _syntax.FsFileOut(fo.Namespace, Opens, Files);
|
|
} else {
|
|
return fo;
|
|
}
|
|
}
|
|
|
|
function extractGenericParameterDefaults(f) {
|
|
const fix = function (f_1) {
|
|
const extractAliasesFromGenericParameterDefaults = function (name, tps) {
|
|
const aliases = [];
|
|
(0, _Seq.iterateIndexed)(function (i, _arg2) {
|
|
aliases.push.bind(aliases)(new _syntax.FsAlias(name, new _syntax.FsType(11, new _syntax.FsGenericType((0, _syntax.simpleType)(name), (0, _List.append)((0, _List.map)(function (_arg1) {
|
|
return (0, _syntax.simpleType)("obj");
|
|
}, (0, _List.slice)(0, i, tps)), (0, _List.slice)(i + 1, null, tps)))), (0, _List.slice)(i + 1, null, tps)));
|
|
}, function (list) {
|
|
return (0, _List.choose)(_syntax.FsTypeModule.asGenericParameterDefaults.bind(_syntax.FsTypeModule), list);
|
|
}(tps));
|
|
return (0, _List.map)(function (arg0) {
|
|
return new _syntax.FsType(10, arg0);
|
|
}, (0, _Seq.toList)(aliases));
|
|
};
|
|
|
|
return fixFile(function (tp_1) {
|
|
var Types;
|
|
var tps_1;
|
|
return tp_1.tag === 13 ? new _syntax.FsType(13, (Types = (tps_1 = [], (0, _Seq.iterate)(function (tp_2) {
|
|
if (tp_2.tag === 0) {
|
|
(function (arg00_1) {
|
|
(0, _Array.addRangeInPlace)(arg00_1, tps_1);
|
|
})((0, _CurriedLambda2.default)(extractAliasesFromGenericParameterDefaults)(tp_2.data.Name)(tp_2.data.TypeParameters));
|
|
|
|
tps_1.push.bind(tps_1)(tp_2);
|
|
} else if (tp_2.tag === 10) {
|
|
(function (arg00_3) {
|
|
(0, _Array.addRangeInPlace)(arg00_3, tps_1);
|
|
})((0, _CurriedLambda2.default)(extractAliasesFromGenericParameterDefaults)(tp_2.data.Name)(tp_2.data.TypeParameters));
|
|
|
|
tps_1.push.bind(tps_1)(tp_2);
|
|
} else {
|
|
tps_1.push.bind(tps_1)(tp_2);
|
|
}
|
|
}, tp_1.data.Types), (0, _Seq.toList)(tps_1)), new _syntax.FsModule(tp_1.data.HasDeclare, tp_1.data.IsNamespace, tp_1.data.Name, Types, tp_1.data.HelperLines, tp_1.data.Attributes))) : tp_1;
|
|
}, f_1);
|
|
};
|
|
|
|
const flatten = function (f_2) {
|
|
return fixFile(function (tp_3) {
|
|
return tp_3.tag === 22 ? new _syntax.FsType(7, new _syntax.FsMapped(tp_3.data.Name, tp_3.data.FullName)) : tp_3;
|
|
}, f_2);
|
|
};
|
|
|
|
return flatten(fix(f));
|
|
}
|
|
|
|
function fixTypesHasESKeywords(f) {
|
|
return fixFile(function (tp) {
|
|
return tp.tag === 11 ? function (_arg1) {
|
|
var TypeParameters;
|
|
return _arg1 ? new _syntax.FsType(11, new _syntax.FsGenericType((0, _syntax.simpleType)("obj"), new _List2.default())) : new _syntax.FsType(11, (TypeParameters = (0, _List.map)(function (tp2) {
|
|
return tp2.tag === 7 ? _keywords.esKeywords.has(tp2.data.Name) ? (0, _syntax.simpleType)("obj") : tp2 : tp2;
|
|
}, tp.data.TypeParameters), new _syntax.FsGenericType(tp.data.Type, TypeParameters)));
|
|
}(_keywords.esKeywords.has((0, _syntax.getName)(tp))) : tp;
|
|
}, f);
|
|
}
|
|
|
|
function extractTypesInGlobalModules(f) {
|
|
const Modules = (0, _List.map)(function (md) {
|
|
const tps = Array.from(new _List2.default());
|
|
(0, _Seq.iterate)(function (tp) {
|
|
if (tp.tag === 13) {
|
|
if (tp.data.Name === "global") {
|
|
(function (arg00) {
|
|
(0, _Array.addRangeInPlace)(arg00, tps);
|
|
})(tp.data.Types);
|
|
} else {
|
|
tps.push.bind(tps)(tp);
|
|
}
|
|
} else {
|
|
tps.push.bind(tps)(tp);
|
|
}
|
|
}, md.Types);
|
|
const Types = (0, _Seq.toList)(tps);
|
|
return new _syntax.FsModule(md.HasDeclare, md.IsNamespace, md.Name, Types, md.HelperLines, md.Attributes);
|
|
}, f.Modules);
|
|
return new _syntax.FsFile(f.FileName, f.ModuleName, Modules);
|
|
} |