-
Notifications
You must be signed in to change notification settings - Fork 469
Jsx ast #7286
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
Jsx ast #7286
Changes from 29 commits
Commits
Show all changes
107 commits
Select commit
Hold shift + click to select a range
db7eee6
Intial exploration of JSX ast
nojaf 28aa287
Initial mapping from0
nojaf b57f2df
Format code
nojaf 32161a3
Merge branch 'master' into jsx-ast
nojaf d714829
Fix jsx fragment mapping
nojaf e27b339
Remove fragment
nojaf 92657ee
Update test output
nojaf 441de6e
Introducing Pexp_jsx_unary_element & Pexp_jsx_container_element
nojaf bf1b411
Refactor fragment transformation.
nojaf 5fe5f12
Initial transform of Pexp_jsx_unary_element in automatic mode
nojaf 9251609
Make props for unary element in automatic mode.
nojaf 1aaa686
Initial custom component unary tag
nojaf b374212
lowercase container element with children.
nojaf c91aeda
Uppercase container elements
nojaf 85ccab4
Streamline automatic element calls
nojaf 86c9f5f
lowercase container element in classic mode
nojaf 0dfd5b6
Deal with uppercase tags in classic mode.
nojaf 203ff25
Remove old code
nojaf a273f2e
Improve recovery of incomplete jsx tags.
nojaf 998edbe
Correct range of incomplete jsx elements
nojaf fcf2d90
Update semantic tokens
nojaf 162b7a2
Make the closing tag optional for jsx_container_element.
nojaf 9b815a0
Add tighter pattern match for edge case in jsx props completion.
nojaf 9408d06
Update analysis tests for jsx elements ast.
nojaf cc5beb4
print_jsx_unary_tag
nojaf 02e9fc9
Merge branch 'master' into jsx-ast
nojaf 5e060ea
Rough print_jsx_container_tag
nojaf e57ab30
Add ml printing
nojaf b6407d0
Wing the sexp thing
nojaf e565ca7
First step towards ast mapping
nojaf 84e9cbe
prop punning conversion
nojaf bbfe816
Map prop value
nojaf 63fc87b
Map prop spreading
nojaf d6c9fa8
Initial container element mapping.
nojaf e446ae1
Try support children spreading
nojaf 5fef337
Only print space when there are props
nojaf 251244b
Add space after children.
nojaf aec0d8e
Restore braces in props and children
nojaf 6a3f4c9
Inline is_jsx_expression and remove old code
nojaf 506dda3
Better indentation of children
nojaf 96839f4
Handle unary tag
shulhi ff1bb65
Refactor
shulhi 91c283e
WIP: Fix unary tag comments handling
shulhi 2b9b5ce
Fix comments inside prop expression
shulhi 0133f91
Formats
shulhi aaef8ac
Fix closing tag indentation
shulhi b863888
Fix closing tag indentation for cases with break vs inline
shulhi 7f8bf01
Handle some edge cases
shulhi 4e0951c
Refactor
shulhi 7843795
Merge pull request #3 from shulhi/shulhi-jsx-ast
nojaf 9e68c1a
WIP: Handle punning
shulhi 53616a7
Fix optional printing with braces
shulhi 25e20b8
WIP: Handle comments attachment in a different way
shulhi ad72bf2
Handle empty props
shulhi 7ba4996
Handle props spread
shulhi f09cd70
Fix optional with punning
shulhi aa1d978
Merge pull request #4 from shulhi/shulhi-jsx-ast-2
nojaf 0ee7601
Indent props if they don't fit on one line.
nojaf bd45146
Fix indentation of children when props are multiline.
nojaf 2d50ff8
Refactor to Pexp_jsx_element
nojaf fcabcff
Merge branch 'master' into jsx-ast
nojaf ddcdaa2
Don't always append make when uppercase component
nojaf 52ecf03
Use Doc.line for child spreading
nojaf cd9059f
Exotic prop name
nojaf 2e9fb66
Don't create record if only spreading prop, use that expression instead.
nojaf 37755ae
Key prop can be optional
nojaf 3a434c9
Keep comment after opening greater than
nojaf 6cf1e71
Print prop value with comments
nojaf ae9b428
Update generic jsx completion tests
nojaf f3b96df
Revert isJsxComponent
nojaf b1f8dfe
Assign comment to the opening element tag name.
nojaf 64001e2
Attach comments to closing > and closing tag
nojaf 8148cf5
Extract helpers to parsetree_viewer
nojaf cfc4669
setup to walk jsx props
nojaf 2946ea0
Correct range for prop spreading
nojaf 4fcc3ce
Complete walk_jsx_prop
nojaf 161b12c
Finish comment assignment for container elements
nojaf cd98c9f
Revisit comment attachment for unary tags
nojaf 67da647
Improve behaviour for comments in unary tag
nojaf 86fea57
Keep location as is for prop spreading
nojaf f10bc55
print leading comments of closing unary token
nojaf b40c019
Attach comments between empty container tag
nojaf 28497d2
comments between opening and closing tag
nojaf e7bf344
Correct opening_greater_than_doc
nojaf b8d609e
Deal with container element comment edge cases.
nojaf 6d15369
Ensure comments inside braced property values are correct.
nojaf 88534ba
More accurate locations
nojaf 210fa87
Update syntax roundtrip test files
nojaf 8373814
Update mapping test results
nojaf d92d7c5
comment after prop name
nojaf d9b59dd
For them older camls
nojaf 4e160f3
More older caml stuff
nojaf 93eb5af
Remove unreached code in typecore
nojaf 6152b83
Remove leftover comments
nojaf 2126fc9
Preserve lines between jsx elements
nojaf 645b244
Preserve newline between jsx children, streamline jsx fragment childr…
nojaf a0c0d0d
Update analysis expected
nojaf f1da36f
Another location change in expected
nojaf 80c307a
One more update?
nojaf 5e5dabd
Merge branch 'master' into jsx-ast
nojaf 091f1a3
Merge branch 'master' into jsx-ast
nojaf 11ced99
Remove leftover comments
nojaf 0c825d5
Remove obsolete comment
nojaf 8ff481d
Ensure fragment starts after arrow
nojaf 8723426
Add changelog entry
nojaf a1e4ca9
Merge branch 'master' into jsx-ast
nojaf e1ad251
Add missing Pexp_await
nojaf 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 |
---|---|---|
|
@@ -1232,8 +1232,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor | |
then ValueOrField | ||
else Value); | ||
})) | ||
| Pexp_construct ({txt = Lident ("::" | "()")}, _) -> | ||
(* Ignore list expressions, used in JSX, unit, and more *) () | ||
| Pexp_construct (lid, eOpt) -> ( | ||
let lidPath = flattenLidCheckDot lid in | ||
if debug then | ||
|
@@ -1324,10 +1322,27 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor | |
inJsx = !inJsxContext; | ||
})) | ||
| None -> ()) | ||
| Pexp_apply {funct = {pexp_desc = Pexp_ident compName}; args} | ||
when Res_parsetree_viewer.is_jsx_expression expr -> | ||
| Pexp_jsx_unary_element | ||
{ | ||
jsx_unary_element_tag_name = compName; | ||
jsx_unary_element_props = props; | ||
} | ||
| Pexp_jsx_container_element | ||
{ | ||
jsx_container_element_tag_name_start = compName; | ||
jsx_container_element_props = props; | ||
} -> | ||
inJsxContext := true; | ||
let jsxProps = CompletionJsx.extractJsxProps ~compName ~args in | ||
let children = | ||
match expr.pexp_desc with | ||
| Pexp_jsx_container_element | ||
{jsx_container_element_children = children} -> | ||
children | ||
| _ -> JSXChildrenItems [] | ||
in | ||
let jsxProps = | ||
CompletionJsx.extractJsxProps ~compName ~props ~children | ||
in | ||
let compNamePath = flattenLidCheckDot ~jsx:true compName in | ||
if debug then | ||
Printf.printf "JSX <%s:%s %s> _children:%s\n" | ||
|
@@ -1344,10 +1359,20 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor | |
| None -> "None" | ||
| Some childrenPosStart -> Pos.toString childrenPosStart); | ||
let jsxCompletable = | ||
CompletionJsx.findJsxPropsCompletable ~jsxProps | ||
~endPos:(Loc.end_ expr.pexp_loc) ~posBeforeCursor | ||
~posAfterCompName:(Loc.end_ compName.loc) | ||
~firstCharBeforeCursorNoWhite ~charAtCursor | ||
match expr.pexp_desc with | ||
| Pexp_jsx_container_element | ||
{ | ||
jsx_container_element_closing_tag = None; | ||
jsx_container_element_children = | ||
JSXChildrenSpreading _ | JSXChildrenItems (_ :: _); | ||
} -> | ||
(* This is a weird edge case where there is no closing tag but there are children *) | ||
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.
Is that an example of such a case? 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. Yup! |
||
None | ||
| _ -> | ||
CompletionJsx.findJsxPropsCompletable ~jsxProps | ||
~endPos:(Loc.end_ expr.pexp_loc) ~posBeforeCursor | ||
~posAfterCompName:(Loc.end_ compName.loc) | ||
~firstCharBeforeCursorNoWhite ~charAtCursor | ||
in | ||
if jsxCompletable <> None then setResultOpt jsxCompletable | ||
else if compName.loc |> Loc.hasPos ~pos:posBeforeCursor then | ||
|
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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'm curious why do we need
inJsxContext
flag since we are already in JSX branch? Maybe we can document this decision somewhere in the code.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.
This is used in CompletionBackEnd to autocomplete
->React.string
when dotting into a string.CPField
andCPPipe
do have a comment for it.