The implementation of the compound assignment operator (+=) in AppSync_JS resolvers is not consistent with JS
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v20.9.0
Amplify CLI Version
1.4.9
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made
Describe the bug
When the compound assignment operator (+=) is used as the return expression the behavior differs from plain JS. Specifically, JS will evaluate the expression and the new value will be returned. AppSync_JS will return "".
This occurs whether the operands are string or numeric.
Expected behavior
The behavior should be consistent with JS or disallowed via a lint rule and the syntax checker in the AWS Console.
Reproduction steps
- Define the following resolver in the Amplify console.
- Create the default test context and run the test.
- Observe that the request and response resolvers return different results.
- (Optional) Uncomment
return data.foo ?? "some other value"and observe that it works as expected
// APPSYNC_JS
import { util } from "@aws-appsync/utils";
export function request1(ctx) {
let someText = "initialValue";
return someText += ":modifiedValue"; // << returns ""
}
export function response2(ctx) {
let someText = "initialValue";
return someText = someText + ":modifiedValue"; // << returns "initialValue:modifiedValue"
}
- (Optional) Observe that the the following code returns "initialValue:modifiedValue" from both functions as expected if run in the browser.
function request(ctx) {
let someText = "initialValue";
return someText += ":modifiedValue";
}
function response(ctx) {
let someText = "initialValue";
return someText = someText + ":modifiedValue";
}
[request(), response()]
Project Identifier
No response
Log output
No response
Additional information
This will probably need to be looked at with https://github.com/aws-amplify/amplify-category-api/issues/3170
Before submitting, please confirm:
- [x] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [x] I have removed any sensitive information from my code snippets and submission.
Hey @naedx, Thanks for raising this. This is similar #3170. Please include this issue when you raise the support ticket for AppSync team.