diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index e980c464d..4ea66124f 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -73,25 +74,19 @@ void NodeExpression::Parse(const Nan::FunctionCallbackInfo& info) { expected = parseType(info[1]->ToObject()); } - auto expr = info[0]; - - try { - ParsingContext ctx = expected ? ParsingContext(*expected) : ParsingContext(); - ParseResult parsed = ctx.parseLayerPropertyExpression(mbgl::style::conversion::Convertible(expr)); - if (parsed) { - assert(ctx.getErrors().size() == 0); - auto nodeExpr = new NodeExpression(std::move(*parsed)); - const int argc = 0; - v8::Local argv[0] = {}; - auto wrapped = Nan::NewInstance(cons, argc, argv).ToLocalChecked(); - nodeExpr->Wrap(wrapped); - info.GetReturnValue().Set(wrapped); - return; - } + auto success = [&cons, &info](std::unique_ptr result) { + auto nodeExpr = new NodeExpression(std::move(result)); + const int argc = 0; + v8::Local argv[0] = {}; + auto wrapped = Nan::NewInstance(cons, argc, argv).ToLocalChecked(); + nodeExpr->Wrap(wrapped); + info.GetReturnValue().Set(wrapped); + }; + auto fail = [&info](const std::vector& errors) { v8::Local result = Nan::New(); - for (std::size_t i = 0; i < ctx.getErrors().size(); i++) { - const auto& error = ctx.getErrors()[i]; + for (std::size_t i = 0; i < errors.size(); ++i) { + const auto& error = errors[i]; v8::Local err = Nan::New(); Nan::Set(err, Nan::New("key").ToLocalChecked(), @@ -102,6 +97,29 @@ void NodeExpression::Parse(const Nan::FunctionCallbackInfo& info) { Nan::Set(result, Nan::New((uint32_t)i), err); } info.GetReturnValue().Set(result); + }; + + auto expr = info[0]; + + try { + mbgl::style::conversion::Convertible convertible(expr); + + if (expr->IsObject() && !expr->IsArray() && expected) { + mbgl::style::conversion::Error error; + auto func = convertFunctionToExpression(*expected, convertible, error, false); + if (func) { + return success(std::move(*func)); + } + return fail({ { error.message, "" } }); + } + + ParsingContext ctx = expected ? ParsingContext(*expected) : ParsingContext(); + ParseResult parsed = ctx.parseLayerPropertyExpression(mbgl::style::conversion::Convertible(expr)); + if (parsed) { + assert(ctx.getErrors().empty()); + return success(std::move(*parsed)); + } + return fail(ctx.getErrors()); } catch(std::exception &ex) { return Nan::ThrowError(ex.what()); } diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index acc8724a2..287211f38 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -15,30 +15,17 @@ "expression-tests/legacy/categorical/string": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/categorical/string-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/categorical/tokens": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/array": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/array-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/base": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/color": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/color-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/color-hcl": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/color-lab": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/composite": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/composite-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/duplicate-stops": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/implicit": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/exponential/number": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/exponential/number-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/array": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/array-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/boolean": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/boolean-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/color": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/color-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/enum": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/enum-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/number": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/number-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", - "expression-tests/legacy/identity/string": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/identity/string-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/interval/array": "https://github.com/mapbox/mapbox-gl-native/issues/12747", "expression-tests/legacy/interval/array-default": "https://github.com/mapbox/mapbox-gl-native/issues/12747",