-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Convert token strings to expressions #12402
Conversation
4c62117
to
a74113e
Compare
Per #11659 (comment), it’s likely that the iOS and macOS map SDKs still support setting properties to constant string expressions containing mapbox-gl-native/platform/darwin/src/MGLStyleValue_Private.h Lines 74 to 78 in 192c611
However, we no longer document the token syntax, and removing support for it could be chalked up to a fix for a roundtripping bug:
|
I stand corrected. Nonetheless, we could implement the reverse of the transformation described in #11659 (comment) at the SDK level to unblock this work: scan the string for curly braces and convert to key path expressions. The downside is that the SDK has no context about the feature’s fields, so #11953 would effectively regress. |
a74113e
to
eb56eee
Compare
I've done so in the latest commit; could you please take a look?
#11953 applied only to URLs; tokens for non-existent feature properties have always been replaced with an empty string. |
eb56eee
to
e2d20f1
Compare
@tobrun How about Android? Does the SDK need to continue to support e.g. |
@@ -121,6 +121,16 @@ namespace mbgl { | |||
- (void)set<%- camelize(property.name) %>:(NSExpression *)<%- objCName(property) %> { | |||
MGLAssertStyleLayerIsValid(); | |||
|
|||
<% if (property.tokens) { -%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the template is only for layout properties. If paint properties like background-pattern
can also accept tokens, then this change needs to be repeated further down in the template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text-field
and icon-image
, both layout properties, are the only ones that accept tokens, and we don't plan to add any token-accepting properties in the future.
Long term, I feel not as afaik that use-case is completely covered with the Our documentation is indeed a little sparse on the token syntax, we only show case usage through examples. I have been trying to up our documentation game with the introduction of expressions. |
Looks like Android will continue to support |
ed38b5d
to
b272605
Compare
e2d20f1
to
8cb077b
Compare
@jfirebaugh did a quick manual test on this PR and still works 👍 |
8cb077b
to
02af6ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one additional test case suggestion
ASSERT_EQ(*convertTokenStringToExpression("{token} token"), *concat(vec(toString(get(literal("token"))), literal(" token")))); | ||
ASSERT_EQ(*convertTokenStringToExpression("{token} {token}"), *concat(vec(toString(get(literal("token"))), literal(" "), toString(get(literal("token")))))); | ||
ASSERT_EQ(*convertTokenStringToExpression("{token} {token"), *concat(vec(toString(get(literal("token"))), literal(" "), literal("{token")))); | ||
ASSERT_EQ(*convertTokenStringToExpression("{token {token}"), *concat(vec(literal("{token "), toString(get(literal("token")))))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add "{token}{token}"
as well
Removes mgl_expressionByReplacingTokensWithKeyPaths and associated code. Converting on output is no longer necessary: from the prior commit, core converts token strings to expressions at parse time; all that's necessary is to ensure that the runtime styling API does so as well.
02af6ed
to
9dbcca7
Compare
Fixes #11659.
This may need some additional coordination with SDK code. Specifically, the constructor
DataDrivenPropertyValue(T)
(whereT
isstd::string
) no longer accepts token strings foricon-image
ortext-field
. Such strings should be converted to expressions, and then theDataDrivenPropertyValue(PropertyExpression<T>)
constructor should be used. It's difficult to tell if the former constructor is in use by SDK code (I can't simply delete it and see what fails to compile, because there are lots of uses that aren't affected).