tern icon indicating copy to clipboard operation
tern copied to clipboard

JSON type definitions parser is too weak

Open ilevd opened this issue 7 years ago • 0 comments
trafficstars

Supposing I have the next JSON types definition file:

{
  "!name": "my",
  "my": {
    "myfunc" : {
      "!type" : "fn(data:+my.charts.Pie|+my.charts.Area) -> +my.charts.Pie|+my.charts.Area",
      "!doc" : "Creates and returns a Pie or Area."
    },
    "myfunc2" : {
      "!type" : "fn() -> string|number",
      "!doc" : "Creates and returns a Pie or Area."
    },
    "myfunc3" : {
      "!type" : "fn(data:{field:(+my.charts.Pie|+my.charts.Area)}) -> string|number",
      "!doc" : "Creates and returns a Pie or Area."
    },
    "charts": {
      "Pie": {
        "!doc": "Pie chart class.",
        "prototype": {
          "toHtmlTable": {
            "!type": "fn(opt_title?: string, opt_asString?: bool) -> Element|string",
            "!url": "https://api.anychart.com/8.3.0/anychart.core.Chart#toHtmlTable",
            "!doc": "Creates and returns a chart as HTML table."
          },
          "getPngBase64String": {
            "!type": "fn(onSuccessOrOptions: fn()|+Object, opt_onError?: fn(), opt_width?: number, opt_height?: number, opt_quality?: number)",
            "!url": "https://api.anychart.com/8.3.0/anychart.core.Chart#getPngBase64String",
            "!doc": "Returns PNG as base64 string."
          }
        }
      },
      "Area": {
        "!doc": "Area chart class.",
        "prototype": {
          "toHtmlTable": {
            "!type": "fn(opt_title?: string, opt_asString?: bool) -> Element|string",
            "!doc": "Creates and returns a chart as HTML table."
          },
          "getPngBase64String": {
            "!type": "fn(onSuccessOrOptions: fn()|+Object, opt_onError?: fn(), opt_width?: number, opt_height?: number, opt_quality?: number)",
            "!doc": "Returns PNG as base64 string."
          }
        }
      }
    }
  }
}

Then it throw: Unrecognized type spec: fn(data:+my.charts.Pie|+my.charts.Area) -> +my.charts.Pie|+my.charts.Area (at 8)

So I need to add space between : and +: fn(data: +my.charts.Pie|+my.charts.Area) -> +my.charts.Pie|+my.charts.Area

Even then it parses it as myfunc(my.charts.Pie data) -> my.charts.Pie without my.charts.Area.

Another sample: fn(data:{field:(+my.charts.Pie|+my.charts.Area)}) -> string|number in myfunc3, works only with transformation to: fn(data: {field: +my.charts.Pie|+my.charts.Area}) -> string|number and again, finds only first complex user type - myfunc3({field:my.charts.Pie} data) -> string|number.

ilevd avatar Oct 01 '18 05:10 ilevd