-
Notifications
You must be signed in to change notification settings - Fork 570
compiler fails to handle arbitrary string js tags #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where "data-*" and "aria-*" indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator for *js.Object special field access we can support arbitrary string values in js tags. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where "data-*" and "aria-*" indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator for *js.Object special field access we can support arbitrary string values in js tags. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where "data-*" and "aria-*" indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator for *js.Object special field access we can support arbitrary string values in js tags. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where "data-*" and "aria-*" indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator for *js.Object special field access we can support arbitrary string values in js tags. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where "data-*" and "aria-*" indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator for *js.Object special field access we can support arbitrary string values in js tags. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where `"data-*"` and `"aria-*"` indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator (where required) we can support arbitrary string values in js-tagged fields for `*js.Object` special structs. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where `"data-*"` and `"aria-*"` indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator (where required) we can support arbitrary string values in js-tagged fields for `*js.Object` special structs. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where `"data-*"` and `"aria-*"` indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator (where required) we can support arbitrary string values in js-tagged fields for `*js.Object` special structs. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where `"data-*"` and `"aria-*"` indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator (where required) we can support arbitrary string values in js-tagged fields for `*js.Object` special structs. Fixes gopherjs#778
Javascript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where `"data-*"` and `"aria-*"` indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to the index operator (where required) we can support arbitrary string values in js-tagged fields for `*js.Object` special structs. Fixes gopherjs#778
JavaScript allows for arbitrary strings to be used as index values on an Object. A good example of where this comes up is React where `"data-*"` and `"aria-*"` indexes are used on objects (https://reactjs.org/docs/dom-elements.html). By switching from property selectors to index operator (where required), we support arbitrary string values in js-tagged fields for *js.Object special structs. Fixes #778.
I think there may still be an issue here. I have the latest GopherJS 1.10-4 and still have a problem with getting an attribute whose name begins with a period, e.g. ".label-text". If I have a *js.Object named foo, foo.Get(".label-text") always returns undefined. I can look at the actual javascript object (in the browser debugger) and confirm that the entry is, indeed, there. I can also get any entry that does not have the period. FYI, the name was not my idea - it's a name style used in jointjs. |
@pbrown12303 do you have a reproducer? Because this appears to work for me:
|
I think @pbrown12303 is talking about something else, since he mentions using
Output:
A reproduction case is indeed necessary. |
cc @theclapp who has helped on Slack thus far. |
Ah, some more context is warranted. I am not constructing the object - it already exists. The following function creates the data structure that is used to initialize this object, which is a jointjs Element. The function containing the call is bound to the attribute updateRectangles. It is being called by another function also bound to an attribute: initialize. The initialize function is successfully called and it, in turn, successfully calls the updateRectangles function. The problem occurs in the execution of updateRectangles: the calls to .Get(".xxx") all return Undefined as a result.
|
Argh! Pilot error! There was a typo: attribute name was .label-Text, call was to Get(.label-text). Uppercase vs lowercase T. So sorry to waste everyone's time, but I thank you for your quick and thoughtful responses. |
Consider the following test:
This currently fails at runtime (
gopherjs test
) with:This is because the compiler currently translates field access (getting or setting) via the dot notation:
Where a string contains a non-identifier value (e.g. space above) this is destined to fail.
Some external libraries (e.g. React) require properties to be set that are composed of non-identifier strings, e.g. https://reactjs.org/docs/dom-elements.html, where
"data-*"
and"aria-*"
are used for attribute names.An equivalent way to set properties is via the bracket notation:
Hence it probably makes more sense in general to use this for js tag compilation.
For more details see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors
PR that addresses this will follow shortly.
The text was updated successfully, but these errors were encountered: