Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ func insertCustomApp(jsPath string, flags Flag) {
// React element/route patterns for path matching
elementPatterns := []string{
// JSX pattern (1.2.78+): (0,S.jsx)(se.qh,{path:"/collection/*",element:...})
`(\([\w$\.,]+\))\(([\w\.]+),\{path:"/collection(?:/[\w\*]+)?",?(element|children)?`,
// Settings page should be more consistent with having no conditional renders
`(\([\w$\.,]+\))\(([\w\.]+),\{path:"/settings(?:/[\w\*]+)?",?(element|children)?`,
// createElement pattern: X.createElement(Y,{path:"/collection"...})
`([\w_\$][\w_\$\d]*(?:\(\))?\.createElement|\([\w$\.,]+\))\(([\w\.]+),\{path:"\/collection"(?:,(element|children)?[:.\w,{}()$/*"]+)?\}`,
}
Expand Down Expand Up @@ -332,12 +333,20 @@ func insertCustomApp(jsPath string, flags Flag) {
return fmt.Sprintf("{%s%s", appMap, submatches[1])
})

utils.ReplaceOnce(
&content,
// Seek to the full matched React.lazy pattern
matchedReactPattern = utils.SeekToCloseParen(
content,
matchedReactPattern,
func(submatches ...string) string {
return fmt.Sprintf("%s%s", submatches[0], appReactMap)
})
'(',
')',
)

content = strings.Replace(
content,
matchedReactPattern,
fmt.Sprintf("%s%s", matchedReactPattern, appReactMap),
1,
)

utils.ReplaceOnce(
&content,
Expand Down
10 changes: 7 additions & 3 deletions src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,18 @@ func SeekToCloseParen(content string, regexpTerm string, leftChar, rightChar byt
start := loc[0]
end := start
count := 0
init := false

for {
if content[end] == leftChar {
switch content[end] {
case leftChar:
count += 1
} else if content[end] == rightChar {
init = true
case rightChar:
count -= 1
}
end += 1
if count == 0 {
if count == 0 && init {
break
}
}
Expand Down