-
Notifications
You must be signed in to change notification settings - Fork 9
bugfix dep #56
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
bugfix dep #56
Changes from all commits
d4ee2bc
453855c
9932a7e
c994f58
a4dbed5
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 |
|---|---|---|
|
|
@@ -69,4 +69,42 @@ describe('mapping2ForPlugin', () => { | |
| }" | ||
| `); | ||
| }); | ||
|
|
||
| it('should transform to optional key mapping ', () => { | ||
| const code = ` | ||
| function MyComp({ comment }) { | ||
| return ( | ||
| <div > | ||
| {comment.replies?.map(reply => ( | ||
| <CommentComponent | ||
| key={reply.id} | ||
| /> | ||
| ))} | ||
| </div> | ||
| ) | ||
| } | ||
| `; | ||
| const transformedCode = transform(code); | ||
| expect(transformedCode).toMatchInlineSnapshot(` | ||
| "import { compBuilder as $$compBuilder, createForNode as $$createForNode, createCompNode as $$createCompNode, createHTMLNode as $$createHTMLNode } from "@openinula/next"; | ||
| function MyComp({ | ||
| comment | ||
| }) { | ||
| const $$self = $$compBuilder(); | ||
| $$self.addProp("comment", $$value => comment = $$value, 1); | ||
| return $$self.prepare().init($$createHTMLNode("div", null, $$createForNode(() => comment.replies, () => { | ||
| return comment.replies?.map?.(reply => reply.id); | ||
| }, ($$n, updateItemFuncArr, reply, $$key, $$i) => { | ||
| updateItemFuncArr[$$i] = (newItem, newIdx) => { | ||
| reply = newItem; | ||
| }; | ||
| return [$$createCompNode(CommentComponent, { | ||
| "key": reply.id | ||
| }, $$node => { | ||
| $$node.updateProp("key", () => reply.id, [reply?.id], 1); | ||
| })]; | ||
| }, 1))); | ||
| }" | ||
| `); | ||
| }); | ||
|
Comment on lines
+73
to
+109
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. 💡 Verification agent 🧩 Analysis chainGreat coverage for arr?.map with key mapping; add a couple of edge-case tests This snapshot thoroughly validates the optional map transformation and key handling. To avoid regressions, consider adding:
These ensure both OptionalCallExpression variants and computed properties are covered. You can check if these cases are already covered anywhere with: 🏁 Script executed: #!/bin/bash
# 1) Look for existing tests using `map?.(`, nested optional mapping, or computed '["map"]'
rg -n --no-heading "map\?\.\(|\?\.\s*map\(|\?\.\s*\[\s*['\"]map['\"]\s*\]\s*\?\.\s*\(" -A 2 test
# 2) Confirm no handling of `ChainExpression` in the plugin (helps validate the earlier concern)
rg -n --no-heading "ChainExpression" next-packages/compiler/babel-inula-next-core/src/sugarPlugins/mapping2ForPlugin.tsLength of output: 267 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Search for literal 'map?.(' occurrences =="
rg -n -F 'map?.(' || true
echo
echo "== Search for literal '?.map(' occurrences =="
rg -n -F '?.map(' || true
echo
echo "== Search for literal '\"map\"' and \"'map'\" (to find computed property uses) =="
rg -n -F '"map"' || true
rg -n -F "'map'" || true
echo
echo "== Locate mapping2ForPlugin.ts =="
mapping_files=$(fd -HI --type f mapping2ForPlugin.ts 2>/dev/null || true)
if [ -z "$mapping_files" ]; then
mapping_files=$(find . -type f -name mapping2ForPlugin.ts 2>/dev/null || true)
fi
if [ -z "$mapping_files" ]; then
echo "No mapping2ForPlugin.ts found."
else
echo "Found files:"
printf '%s\n' "$mapping_files"
fi
echo
echo "== Show mapping2ForPlugin.ts (first 400 lines) and search for 'ChainExpression' =="
if [ -n "$mapping_files" ]; then
while IFS= read -r f; do
echo "---- $f ----"
sed -n '1,400p' "$f" || true
echo
echo "Search for 'ChainExpression' in $f:"
rg -n "ChainExpression" "$f" || true
echo
done <<< "$mapping_files"
fi
echo
echo "== Search for 'ChainExpression' anywhere in repo =="
rg -n "ChainExpression" || trueLength of output: 8138 Good coverage for arr?.map?. — computed-property + nested-callback cases need attention Short summary: arr?.map?.(...) is already covered in tests, but the mapping plugin only accepts Identifier properties named "map", so computed-access forms (e.g. obj?.['map']?.(...)) will be ignored. Please add tests for the missing edge cases and decide whether to extend the plugin. Files/locations found
Suggested actions
🤖 Prompt for AI Agents |
||
| }); | ||
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.
Potentially missed cases due to ChainExpression wrappers around optional chains
Optional chaining in Babel can introduce a ChainExpression wrapper around the entire chain. In such cases:
Because the current checks require the immediate parent to be JSXExpressionContainer (outer) or ArrowFunctionExpression (inner), these cases may be skipped and not transformed.
Proposed fix: Loosen the parent checks to tolerate an intermediate ChainExpression, and replace the correct target when doing path.replaceWith(). Here is a robust version of mapCallVisitor illustrating the adjustments (focus: parent checks and replacement target):
This keeps your current logic but ensures wrapped chains aren’t accidentally skipped.
🤖 Prompt for AI Agents