Skip to content

Instantly share code, notes, and snippets.

@rrdelaney
Created March 3, 2018 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrdelaney/f93da5d17ccf224c6da0c86999222fe5 to your computer and use it in GitHub Desktop.
Save rrdelaney/f93da5d17ccf224c6da0c86999222fe5 to your computer and use it in GitHub Desktop.
TypeScript Decoder
module Decoder = {
let node = json => {
let syntaxKind = json |> Json.Decode.field("kind", Json.Decode.int);
if (syntaxKind == Internal.SyntaxKind.declareKeyword) {
Unknown;
} else {
Unknown;
};
}
and declareKeyword = json =>
DeclareKeyword(
Json.Decode.{
pos: json |> field("pos", int),
end_: json |> field("end", int)
}
)
and exportKeyword = json =>
ExportKeyword(
Json.Decode.{
pos: json |> field("pos", int),
end_: json |> field("end", int)
}
)
and identifier = json =>
Identifier(
Json.Decode.{
pos: json |> field("pos", int),
end_: json |> field("end", int),
escapedText: json |> field("escapedText", string),
text: json |> field("text", string)
}
)
and functionDeclaration = json =>
FunctionDeclaration(
Json.Decode.{
pos: json |> field("pos", int),
end_: json |> field("end", int),
modifiers: json |> field("modifiers", array(node)),
name: json |> field("name", node),
typeParameters: json |> field("typeParameters", array(node)),
parameters: json |> field("parameters", array(node)),
type_: json |> field("type", node)
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment