Error during minify.sh

Peter Flower 7 years ago

Hi Anton, help me with this please:
I have this piece of code, which is correct:

contextmenu.on('open', function (evt) {
var feature = mapa.forEachFeatureAtPixel(evt.pixel, ft => ft);
            if (feature && feature.get('type') === 'removable') {
                contextmenu.clear();
                removeMarkerItem.data = { marker: feature };
                contextmenu.push(removeMarkerItem);
            } else {
                contextmenu.clear();
                contextmenu.extend(contextmenu_items);
                contextmenu.extend(contextmenu.getDefaultItems());
           }
        });

When I execute minify.sh, it throws this error:

[ERR] C2000: Rhino Parse Error (syntax error => var feature = mapa.forEachFeatureAtPixel(evt.pixel, ft => ft);) -- /Users/xxxxxx/IntelliJ IDEA/traccar/traccar-web/web/app/view/map/BaseMap.js:425:70
[ERR] C2000: Rhino Parse Error (Compilation produced 1 syntax errors. => null) -- /Users/xxxxxx/IntelliJ IDEA/traccar/traccar-web/web/app/view/map/BaseMap.js:1
[ERR] Compilation produced 1 syntax errors.

The code runs OK, the problem is that I can't minify the file.
What's that warning and how can I fix it?
The exactly place of the error is this: ft => ft

Thank you very much!!

Anton Tananaev 7 years ago

My guess would be that you are trying to use features from ES6, which is probably not supported.

Peter Flower 7 years ago

Hi, the problem was about "arrow functions".
The fix is:
Before:

var feature = mapa.forEachFeatureAtPixel(evt.pixel, ft => ft);

After:

var feature = mapa.forEachFeatureAtPixel(evt.pixel, function(feature, layer) { return feature; });

Best Regards