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
fix(ivy): wrap "inputs" and "outputs" keys if they contain unsafe chars #28919
fix(ivy): wrap "inputs" and "outputs" keys if they contain unsafe chars #28919
Conversation
Why not just quote all of them and let the minifier do its job? |
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.
Help me understand the impact of this more.
The unquoted keys are unquoted so the optimizer will rename them (just as it renames the actual input field on the class). What impact does quoting here have on this renaming? Is the assertion that any property which has special characters will not be renamed by the optimizer?
Should we consider forbidding input names that are not valid JS identifiers?
3c2ce38
to
46edb29
Compare
* quotes. Note: we do not wrap all keys into quotes, as it may have impact on minification and may | ||
* bot work in some cases when object keys are mangled by minifier. | ||
*/ | ||
const UNSAFE_OBJECT_KEY_NAME_REGEXP = /-/g; |
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.
Why -
only? I can have whatever text value as property name like inputs: ['...foo:foo', ',,,bar:bar']
.
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.
Currently we're having problems with -
in input names.
This is a temporary solution while we discuss what to do about this particular issue. Options include:
-
adding some heuristic to decide whether a property will likely be accessed via minified (
this.bar
) or unminified (this.other-bar
) references, and quoting the property mapping for Ivy accordingly. -
prohibiting the use of input names that aren't valid JS identifiers in the first place (which would be a breaking change).
@alxhub A class property can indeed be whatever* string or symbol: class Foo {
'a$b*c' = 42
['d@e!f'] = 84
[mySymbol] = 21
} *: Here only means any character, not special names like As a top-goal of Ivy is to reduce compiler restriction and support any JavaScript usage when possible, I don't think this is a viable approach. |
@alxhub Please also note that a property named in valid identifier may also be quoted: class Foo {
prop0 = 42;
'prop1' = 42;
['prop2'] = 42;
} In above case the quotes will be preserved in compilation result and thus not being minified by closure compiler. The true fix should be dropping |
…racters Prior to this change, keys in "inputs" and "outputs" objects generated by compiler were not checked against unsafe characters. As a result, in some cases the generated code was throwing JS error. Now we check whether a given key contains any unsafe chars and wrap it in quotes if needed.
46edb29
to
654ba38
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Prior to this change, keys in "inputs" and "outputs" objects generated by compiler were not checked against unsafe characters. As a result, in some cases the generated code was throwing JS error. Now we check whether a given key contains any unsafe chars and wrap it in quotes if needed.
This PR resolves ticket FW-1096.
PR Type
What kind of change does this PR introduce?
Does this PR introduce a breaking change?