syntax error on generated code for ts enum
joprice opened this issue · comments
I am trying to use ts2ocaml to generate types for cdk8s.
Passing the file cdk8s/lib/app.d.ts
to ts2ocaml:
import { Construct } from 'constructs';
import { Chart } from './chart';
/** The method to divide YAML output into files */
export declare enum YamlOutputType {
/** All resources are output into a single YAML file */
FILE_PER_APP = 0,
/** Resources are split into seperate files by chart */
FILE_PER_CHART = 1,
/** Each resource is output to its own file */
FILE_PER_RESOURCE = 2,
/** Each chart in its own folder and each resource in its own file */
FOLDER_PER_CHART_FILE_PER_RESOURCE = 3
}
export interface AppProps {
/**
* The directory to output Kubernetes manifests.
*
* @default - CDK8S_OUTDIR if defined, otherwise "dist"
*/
readonly outdir?: string;
/**
* The file extension to use for rendered YAML files
* @default .k8s.yaml
*/
readonly outputFileExtension?: string;
/**
* How to divide the YAML output into files
* @default YamlOutputType.FILE_PER_CHART
*/
readonly yamlOutputType?: YamlOutputType;
}
....
results in
[@@@ocaml.warning "-7-11-32-33-39"]
[@@@js.implem
[@@@ocaml.warning "-7-11-32-33-39"]
]
open Ts2ocaml
open Ts2ocaml.Dom
(* import { Construct } from 'constructs'; *)
[@@@js.stop] module Construct = Constructs.Export.Construct [@@@js.start] [@@@js.implem module Construct = Constructs.Export .Construct]
(* import { Chart } from './chart'; *)
[@@@js.stop] module Chart = Cdk8s__chart.Export.Chart [@@@js.start] [@@@js.implem module Chart = Cdk8s__chart.Export.Chart]
and _YamlOutputType = [`FILE_PER_APP[@js 0] | `FILE_PER_CHART[@js 1] | `FILE_PER_RESOURCE[@js 2] | `FOLDER_PER_CHART_FILE_PE R_RESOURCE[@js 3]] [@js.enum]
and _YamlOutputType_FILE_PER_APP = [`FILE_PER_APP[@js 0]] [@js.enum]
and _YamlOutputType_FILE_PER_CHART = [`FILE_PER_CHART[@js 1]] [@js.enum]
and _YamlOutputType_FILE_PER_RESOURCE = [`FILE_PER_RESOURCE[@js 2]] [@js.enum]
and _YamlOutputType_FOLDER_PER_CHART_FILE_PER_RESOURCE = [`FOLDER_PER_CHART_FILE_PER_RESOURCE[@js 3]] [@js.enum]
and _AppProps = private Ojs.t
and _App = private Ojs.t
...
and fails with the following error:
File "cdk8s__app.mli", line 13, characters 0-3:
13 | and _YamlOutputType = [`FILE_PER_APP[@js 0
^^^
Error: Syntax error
File "cdk8s__app.mli", line 13, characters 0-3:
13 | and _YamlOutputType = [`FILE_PER_APP[@js 0] | `FILE_PER_CHART[@js 1] | `FILE_PER_RESOURCE[@js 2] | `FOLDER_PER_CHART_FILE_PER_RESOURCE[@js 3]] [@js.enum]
Fixed in version 1.4.2 which should be live within an hour.
By the way, ts2ocaml 1.4.2 detected mutually-referencing source files: cdk8s/lib/api-object.d.ts
and cdk8s/lib/chart.d.ts
.
As OCaml doesn't allow mutually-referencing sources, you would need manual tweaks to get it working.