Comparing version 0.0.9-33 to 0.0.9-34
@@ -740,3 +740,16 @@ "use strict"; | ||
} | ||
function generateFunctionArg(arg) { | ||
const openParens = "("; | ||
const closeParens = ")"; | ||
function typeToArg(type_) { | ||
return (function (y) { | ||
return y.replace(closeParens, ""); | ||
})((function (y) { | ||
return y.replace(openParens, ""); | ||
})((function (y) { | ||
return y.replace(" ", "_"); | ||
})((function (y) { | ||
return y[0].toLowerCase() + y.slice(1); | ||
})(generateTopLevelType(type_))))); | ||
} | ||
function generateFunctionArg(knownNames, arg) { | ||
switch (arg.kind) { | ||
@@ -747,6 +760,46 @@ case "FunctionArg": { | ||
case "AnonFunctionArg": { | ||
return `_${arg.index}`; | ||
const tempName = (function () { | ||
switch (arg.type.kind) { | ||
case "FunctionType": { | ||
return "fn"; | ||
} | ||
default: { | ||
return `${typeToArg(arg.type)}`; | ||
} | ||
} | ||
})(); | ||
if (knownNames.indexOf(tempName) === -1) { | ||
return tempName; | ||
} | ||
else { | ||
return `_${tempName}`; | ||
} | ||
; | ||
} | ||
} | ||
} | ||
function knownArgNames(args) { | ||
switch (args.length) { | ||
case 0: { | ||
return []; | ||
} | ||
case args.length: { | ||
if (args.length >= 1) { | ||
const [arg, ...rest] = args; | ||
switch (arg.kind) { | ||
case "FunctionArg": { | ||
return [arg.name, ...knownArgNames(rest)]; | ||
} | ||
case "AnonFunctionArg": { | ||
return knownArgNames(rest); | ||
} | ||
} | ||
; | ||
} | ||
} | ||
default: { | ||
return []; | ||
} | ||
} | ||
} | ||
function generateFunctionArgType(arg) { | ||
@@ -766,5 +819,8 @@ switch (arg.kind) { | ||
})(List.map(generateFunctionArgType, function_.args)); | ||
const knownNames = knownArgNames(function_.args); | ||
const args = (function (y) { | ||
return y.join(" "); | ||
})(List.map(generateFunctionArg, function_.args)); | ||
})(List.map(function (x) { | ||
return generateFunctionArg(knownNames, x); | ||
}, function_.args)); | ||
const maybeLetBody = generateLetBlock(function_.letBody); | ||
@@ -771,0 +827,0 @@ const maybeDoBody = function_.doBody === null ? "" : `\n${(0, Common_1.prefixLines)(generateDoBlock(function_.doBody), 4)}`; |
{ | ||
"name": "derw", | ||
"version": "0.0.9-33", | ||
"version": "0.0.9-34", | ||
"description": "An Elm-inspired language that transpiles to TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -765,3 +765,19 @@ import * as List from "../stdlib/List"; | ||
function generateFunctionArg(arg: FunctionArgsUnion): string { | ||
const openParens: string = "("; | ||
const closeParens: string = ")"; | ||
function typeToArg(type_: Type): string { | ||
return (function(y: any) { | ||
return y.replace(closeParens, ""); | ||
})((function(y: any) { | ||
return y.replace(openParens, ""); | ||
})((function(y: any) { | ||
return y.replace(" ", "_"); | ||
})((function(y: any) { | ||
return y[0].toLowerCase() + y.slice(1); | ||
})(generateTopLevelType(type_))))); | ||
} | ||
function generateFunctionArg(knownNames: string[], arg: FunctionArgsUnion): string { | ||
switch (arg.kind) { | ||
@@ -772,3 +788,17 @@ case "FunctionArg": { | ||
case "AnonFunctionArg": { | ||
return `_${arg.index}`; | ||
const tempName: string = (function (): any { | ||
switch (arg.type.kind) { | ||
case "FunctionType": { | ||
return "fn"; | ||
} | ||
default: { | ||
return `${typeToArg(arg.type)}`; | ||
} | ||
} | ||
})(); | ||
if (knownNames.indexOf(tempName) === -1) { | ||
return tempName; | ||
} else { | ||
return `_${tempName}`; | ||
}; | ||
} | ||
@@ -778,2 +808,26 @@ } | ||
function knownArgNames(args: FunctionArgsUnion[]): string[] { | ||
switch (args.length) { | ||
case 0: { | ||
return [ ]; | ||
} | ||
case args.length: { | ||
if (args.length >= 1) { | ||
const [ arg, ...rest ] = args; | ||
switch (arg.kind) { | ||
case "FunctionArg": { | ||
return [ arg.name, ...knownArgNames(rest) ]; | ||
} | ||
case "AnonFunctionArg": { | ||
return knownArgNames(rest); | ||
} | ||
}; | ||
} | ||
} | ||
default: { | ||
return [ ]; | ||
} | ||
} | ||
} | ||
function generateFunctionArgType(arg: FunctionArgsUnion): string { | ||
@@ -794,5 +848,8 @@ switch (arg.kind) { | ||
})(List.map(generateFunctionArgType, function_.args)); | ||
const knownNames: string[] = knownArgNames(function_.args); | ||
const args: string = (function(y: any) { | ||
return y.join(" "); | ||
})(List.map(generateFunctionArg, function_.args)); | ||
})(List.map(function(x: any) { | ||
return generateFunctionArg(knownNames, x); | ||
}, function_.args)); | ||
const maybeLetBody: string = generateLetBlock(function_.letBody); | ||
@@ -799,0 +856,0 @@ const maybeDoBody: string = function_.doBody === null ? "" : `\n${prefixLines(generateDoBlock(function_.doBody), 4)}`; |
Sorry, the diff of this file is not supported yet
1442372
32605