Skip to content

Commit

Permalink
fix: type
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Apr 14, 2018
1 parent 86a9035 commit 056b99b
Show file tree
Hide file tree
Showing 28 changed files with 8,391 additions and 198 deletions.
27 changes: 22 additions & 5 deletions packages/@jxa/sdef-to-dts/src/sdef-to-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ interface Record extends RootNode {
name: "record";
}


const convertJSONSchemaType = (type: string): string => {
switch (type) {
case "text":
return "string";
case "number":
case "integer":
return "integer";
case "boolean":
return "boolean";
case "Any":
case "type class":
return "any";
}
return "any";
};
const convertType = (type: string, namespace: string, definedJSONSchemaList: JSONSchema[]): "number" | "string" | "boolean" | string => {
switch (type) {
case "text":
Expand All @@ -65,6 +81,7 @@ const convertType = (type: string, namespace: string, definedJSONSchemaList: JSO
case "boolean":
return "boolean";
case "Any":
case "type class":
return "any";
}
const otherType = pascalCase(type);
Expand All @@ -83,7 +100,7 @@ const createOptionalParameter = (name: string, parameters: Node[]): Promise<stri
return {
name: camelCase(param.attributes.name),
description: param.attributes.description,
type: param.attributes.type
type: convertJSONSchemaType(param.attributes.type)
}
});
const properties: { [index: string]: any } = {};
Expand All @@ -94,7 +111,7 @@ const createOptionalParameter = (name: string, parameters: Node[]): Promise<stri
}
});
const required = parameters.filter(param => {
return param.attributes.optional === "yes"
return param.attributes.optional !== "yes"
}).map(param => {
return camelCase(param.attributes.name);
});
Expand Down Expand Up @@ -130,7 +147,7 @@ const recordToJSONSchema = (command: Record): JSONSchema => {
}
});
const required = propertiesList.filter(param => {
return param.attributes.optional === "yes"
return param.attributes.optional !== "yes"
}).map(param => {
return camelCase(param.attributes.name);
});
Expand Down Expand Up @@ -172,7 +189,7 @@ const commandToDeclare = async (namespace: string, command: Command, recordSchem
});
let optionalParameterTypeName = `${pascalCaseName}OptionalParameter`;
const optionalParameterTypeNameCount = optionalMap.get(optionalParameterTypeName) || 0;
if(optionalParameterTypeNameCount > 0){
if (optionalParameterTypeNameCount > 0) {
optionalParameterTypeName += String(optionalParameterTypeNameCount);
}
optionalMap.set(optionalParameterTypeName, optionalParameterTypeNameCount + 1);
Expand Down Expand Up @@ -232,7 +249,7 @@ export const transform = async (namespace: string, sdefContent: string) => {
}));
const optionalBindingMap = new Map<string, number>();
const functionDefinitions = await Promise.all(commands.map(command => {
return commandToDeclare(namespace, command, recordSchema,optionalBindingMap);
return commandToDeclare(namespace, command, recordSchema, optionalBindingMap);
}));
const functionDefinitionHeaders = functionDefinitions.map(def => def.header);
const functionDefinitionBodies = functionDefinitions.map(def => def.body);
Expand Down
Loading

0 comments on commit 056b99b

Please sign in to comment.