-
Notifications
You must be signed in to change notification settings - Fork 1
Fix PropertyAccessExpression in JSX tags (Context.Provider, React.Fragment) #13
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
69eccc9
Initial plan
Copilot 28af96c
Fix Context.Provider support by handling PropertyAccessExpression in …
Copilot a8aa770
Fix TypeScript compilation errors for JsxTagNameExpression handling
Copilot b9a1218
Refactor: Extract shared utility function to eliminate code duplication
Copilot 170c0ca
Improve utility function and fix edge cases per code review feedback
Copilot f28d351
Improve code safety and remove unnecessary check
Copilot 225e810
Add tests for React.Fragment and Provider with dynamic props
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import React, { createContext, useContext } from "@rbxts/react"; | ||
|
|
||
| const layerContext = createContext(0); | ||
|
|
||
| export default () => { | ||
| const depth = useContext(layerContext); | ||
|
|
||
| return <layerContext.Provider value={depth + 1}></layerContext.Provider>; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import * as ts from "typescript"; | ||
|
|
||
| /** | ||
| * Shared utility functions for JSX transformation | ||
| */ | ||
|
|
||
| /** | ||
| * Converts a JSX tag name expression to a string representation. | ||
| * Handles PropertyAccessExpression recursively (e.g., Ctx.Provider -> "Ctx.Provider") | ||
| * Handles ThisExpression (e.g., <this.Component> -> "this.Component") | ||
| */ | ||
| export function jsxTagExpressionToString(expr: ts.JsxTagNameExpression): string { | ||
| if (ts.isIdentifier(expr)) { | ||
| return expr.text; | ||
| } else if (ts.isPropertyAccessExpression(expr)) { | ||
| // For PropertyAccessExpression, recursively process the base expression | ||
| // In JSX context, expr.expression should be another valid JSX tag name expression | ||
| // (Identifier, PropertyAccessExpression, or ThisExpression) | ||
| const baseExpr = expr.expression; | ||
| let baseString: string; | ||
|
|
||
| if (ts.isIdentifier(baseExpr)) { | ||
| baseString = baseExpr.text; | ||
| } else if (ts.isPropertyAccessExpression(baseExpr)) { | ||
| // Recursively handle nested property access (e.g., a.b.c) | ||
| // Type assertion is safe here because we know it's a PropertyAccessExpression | ||
| baseString = jsxTagExpressionToString(baseExpr as ts.JsxTagNameExpression); | ||
| } else if ((baseExpr as ts.Node).kind === ts.SyntaxKind.ThisKeyword) { | ||
| baseString = "this"; | ||
| } else { | ||
| // Fallback for unexpected expression types | ||
| baseString = "Unknown"; | ||
| } | ||
|
|
||
| return baseString + "." + expr.name.text; | ||
| } else if ((expr as ts.Node).kind === ts.SyntaxKind.ThisKeyword) { | ||
| // Handle ThisExpression | ||
| return "this"; | ||
| } else if (ts.isJsxNamespacedName(expr)) { | ||
| // Handle namespaced names (e.g., <ns:tag>) | ||
| return expr.namespace.text + ":" + expr.name.text; | ||
| } | ||
| return "Unknown"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.