maplibre / maplibre-style-spec

MapLibre Style Specification & Utilities
https://maplibre.org/maplibre-style-spec/
Other
68 stars 57 forks source link

Transitionable properties aren't handled in `gl-style-migrate` #35

Open erik opened 1 year ago

erik commented 1 year ago

gl-style-migrate throws an exception when encountering properties with transitions. Noticed this on a real style which otherwise seems to render fine, so I suspect it's an issue with the migration code.

Possibly related to https://github.com/maplibre/maplibre-gl-js/issues/1708?

Here's a minimal reproduction:

$ npx --package=@maplibre/maplibre-gl-style-spec -- gl-style-validate style.json
$ npx --package=@maplibre/maplibre-gl-style-spec -- gl-style-format style.json
{
  "version": 8,
  "name": "test style",
  "metadata": {},
  "sources": {
    "vector-source": {"type": "vector", "url": "https://example.com/tiles.json"}
  },
  "layers": [
    {
      "id": "layer-with-transition",
      "type": "symbol",
      "source": "vector-source",
      "source-layer": "source-layer",
      "layout": {},
      "paint": {"icon-opacity-transition": {"duration": 0}}
    }
  ]
}

$ npx --package=@maplibre/maplibre-gl-style-spec -- gl-style-migrate style.json
file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:6500
        return propertySpec.type === 'string' ? ['string', get] : get;
                            ^

TypeError: Cannot read properties of null (reading 'type')
    at convertIdentityFunction (file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:6500:29)
    at convertFunction (file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:6474:16)
    at file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:6968:17
    at file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:3106:13
    at Array.forEach (<anonymous>)
    at inner (file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:3105:33)
    at file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:3119:13
    at eachLayer (file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:3097:9)
    at eachProperty (file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:3117:5)
    at expressions (file:///Users/erik/.npm/_npx/50ece69ec35009f8/node_modules/@maplibre/maplibre-gl-style-spec/dist/gl-style-migrate.mjs:6964:5)

https://github.com/maplibre/maplibre-gl-style-spec/blob/main/src/function/convert.ts#L43

HarelM commented 1 year ago

Thanks for taking the time to open this issue! Transition properties are not present in the spec and this is probably what causes this issue. Feel free to submit a PR to resolve this.