-
Notifications
You must be signed in to change notification settings - Fork 405
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: wire-reform tests #1524
fix: wire-reform tests #1524
Changes from all commits
7f52a11
e77db68
aed2ded
3d1f418
14eafb5
a2d20c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,22 @@ function getGeneratedConfig(t, wiredValue) { | |
const configBlockBody = []; | ||
const configProps = []; | ||
const generateParameterConfigValue = memberExprPaths => { | ||
// Note: When memberExprPaths ($foo.bar) has an invalid identifier (eg: foo..bar, foo.bar[3]) | ||
// it should (ideally) resolve in a compilation error during validation phase. | ||
// This is not possible due that platform components may have a param definition which is invalid | ||
// but passes compilation, and throwing at compile time would break such components. | ||
// In such cases where the param does not have proper notation, the config generated will use the bracket | ||
// notation to match the current behavior (that most likely end up resolving that param as undefined). | ||
const isInvalidMemberExpr = memberExprPaths.some( | ||
maybeIdentifier => !t.isValidES3Identifier(maybeIdentifier) | ||
); | ||
const memberExprPropertyGen = !isInvalidMemberExpr ? t.identifier : t.StringLiteral; | ||
|
||
if (memberExprPaths.length === 1) { | ||
return { | ||
configValueExpression: t.memberExpression( | ||
t.identifier(WIRE_CONFIG_ARG_NAME), | ||
t.identifier(memberExprPaths[0]) | ||
memberExprPropertyGen(memberExprPaths[0]) | ||
), | ||
}; | ||
} | ||
|
@@ -58,7 +69,8 @@ function getGeneratedConfig(t, wiredValue) { | |
t.identifier(varName), | ||
t.memberExpression( | ||
t.identifier(WIRE_CONFIG_ARG_NAME), | ||
t.identifier(memberExprPaths[0]) | ||
memberExprPropertyGen(memberExprPaths[0]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
isInvalidMemberExpr | ||
) | ||
), | ||
]); | ||
|
@@ -70,7 +82,11 @@ function getGeneratedConfig(t, wiredValue) { | |
const nextPropValue = t.assignmentExpression( | ||
'=', | ||
t.identifier(varName), | ||
t.memberExpression(t.identifier(varName), t.identifier(memberExprPaths[i])) | ||
t.memberExpression( | ||
t.identifier(varName), | ||
memberExprPropertyGen(memberExprPaths[i]), | ||
isInvalidMemberExpr | ||
) | ||
); | ||
|
||
conditionTest = t.logicalExpression( | ||
|
@@ -85,7 +101,8 @@ function getGeneratedConfig(t, wiredValue) { | |
conditionTest, | ||
t.memberExpression( | ||
t.identifier(varName), | ||
t.identifier(memberExprPaths[memberExprPaths.length - 1]) | ||
memberExprPropertyGen(memberExprPaths[memberExprPaths.length - 1]), | ||
isInvalidMemberExpr | ||
), | ||
t.identifier('undefined') | ||
); | ||
|
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.
I don't fully understand what this is.
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.
@caridy without this fix, the compiler will transform and input like this one:
@wire(FooAdapter, { bar: '$a.0b' })
into:and
0b
is not a valid identifier, therefore it will result in an invalid syntax.This fix, transforms it into:
in order to preserve backward compatibility.
Ideally, this (and other similar cases) should result in a compilation error, but throwing at compile time for existing components (that weren't throwing) is not an option now.