Skip to content

Commit

Permalink
TASK Simplify regex and relax pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubitz committed Jun 13, 2024
1 parent 6a013de commit 29b3386
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/ContentRepository90/Rules/FusionNodeContextPathRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public function refactorFileContent(string $fileContent): string
'// TODO 9.0 migration: Line %LINE: !! You very likely need to rewrite "VARIABLE.contextPath" to "Neos.Node.serializedNodeAddress(VARIABLE)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
)
->process(fn(string $eelExpression) => preg_replace(
'/q\((node|documentNode|site)\)\.property\\((\'|")_contextPath(\'|")\\)/',
'/q\(([^)]+)\)\.property\([\'"]_contextPath[\'"]\)/',
'Neos.Node.serializedNodeAddress($1)',
$eelExpression
))
->addCommentsIfRegexMatches(
'/\.property\\((\'|")_contextPath(\'|")\\)/',
'/\.property\([\'"]_contextPath[\'"]\)/',
'// TODO 9.0 migration: Line %LINE: !! You very likely need to rewrite "q(VARIABLE).property(\'_contextPath\')" to "Neos.Node.serializedNodeAddress(VARIABLE)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
)
->getProcessedContent();
Expand Down
8 changes: 4 additions & 4 deletions src/ContentRepository90/Rules/FusionNodeDepthRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ public function refactorFileContent(string $fileContent): string
{
return EelExpressionTransformer::parse($fileContent)
->process(fn(string $eelExpression) => preg_replace(
'/([a-zA-Z.]+)?(node|documentNode)\.depth/',
'/([a-zA-Z.]+)?(site|node|documentNode)\.depth/',
'Neos.Node.depth($1$2)',
$eelExpression
))
->addCommentsIfRegexMatches(
'/\.depth$/',
'/\.depth([^(]|$)/',
'// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.depth" to Neos.Node.depth(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
)
->process(fn(string $eelExpression) => preg_replace(
'/q\((node|documentNode)\)\.property\\((\'|")_depth(\'|")\\)/',
'/q\(([^)]+)\)\.property\([\'"]_depth[\'"]\)/',
'Neos.Node.depth($1)',
$eelExpression
))
->addCommentsIfRegexMatches(
'/\.property\\((\'|")_depth(\'|")\\)/',
'/\.property\([\'"]_depth[\'"]\)/',
'// TODO 9.0 migration: Line %LINE: You may need to rewrite "q(VARIABLE).property(\'_depth\')" to Neos.Node.depth(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
)->getProcessedContent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function refactorFileContent(string $fileContent): string
$eelExpression
))
->addCommentsIfRegexMatches(
'/\.hiddenInIndex/',
'/\.hiddenInIndex$/',
'// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.hiddenInIndex" to VARIABLE.property(\'hiddenInIndex\'). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
)
->process(fn(string $eelExpression) => preg_replace(
'/\.property\\((\'|")_hiddenInIndex(\'|")\\)/',
'/\.property\([^)]+_hiddenInIndex[^)]+\)/',
'.property(\'hiddenInIndex\')',
$eelExpression
)
Expand Down
4 changes: 2 additions & 2 deletions src/ContentRepository90/Rules/FusionNodePathRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function refactorFileContent(string $fileContent): string
$eelExpression
))
->addCommentsIfRegexMatches(
'/\.path$/',
'/\.path([^(]|$)/',
'// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.path" to Neos.Node.path(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'
)
->process(fn(string $eelExpression) => preg_replace(
'/q\((node|documentNode|site)\)\.property\\((\'|")_path(\'|")\\)/',
'/q\(([^)]+)\)\.property\([^)]+_path[^)]+\)/',
'Neos.Node.path($1)',
$eelExpression
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
#
attributes = ${node.contextPath || documentNode.contextPath || q(node).property('_contextPath') || q(documentNode).property("_contextPath")}
foo = ${q(bar).property('_contextPath') || q(bar).property("_contextPath")}
boo = ${q(nodes).first().property('_contextPath') || q(nodes).first().property("_contextPath")}

#
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes`
Expand All @@ -31,8 +32,8 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
}
}
-----
// TODO 9.0 migration: Line 11: !! You very likely need to rewrite "q(VARIABLE).property('_contextPath')" to "Neos.Node.serializedNodeAddress(VARIABLE)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 27: !! You very likely need to rewrite "VARIABLE.contextPath" to "Neos.Node.serializedNodeAddress(VARIABLE)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 12: !! You very likely need to rewrite "q(VARIABLE).property('_contextPath')" to "Neos.Node.serializedNodeAddress(VARIABLE)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 28: !! You very likely need to rewrite "VARIABLE.contextPath" to "Neos.Node.serializedNodeAddress(VARIABLE)". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) {

renderer = Neos.Fusion:Component {
Expand All @@ -41,7 +42,8 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
# pass down props
#
attributes = ${Neos.Node.serializedNodeAddress(node) || Neos.Node.serializedNodeAddress(documentNode) || Neos.Node.serializedNodeAddress(node) || Neos.Node.serializedNodeAddress(documentNode)}
foo = ${q(bar).property('_contextPath') || q(bar).property("_contextPath")}
foo = ${Neos.Node.serializedNodeAddress(bar) || Neos.Node.serializedNodeAddress(bar)}
boo = ${q(nodes).first().property('_contextPath') || q(nodes).first().property("_contextPath")}

#
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
#
attributes = ${node.depth || documentNode.depth || q(node).property('_depth') || q(documentNode).property("_depth")}
foo = ${q(bar).property('_depth') || q(bar).property("_depth")}
boo = ${q(nodes).first().property('_depth') || q(nodes).first().property("_depth")}

#
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes`
Expand All @@ -23,16 +24,18 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
<input
type="checkbox"
name={node.depth}
value={someOtherVariable.depth}
value={someOtherVariable.depth || something}
path={someOtherVariable.depth}
checked={props.checked}
{...node.depth}
/>
`
}
}
-----
// TODO 9.0 migration: Line 11: You may need to rewrite "q(VARIABLE).property('_depth')" to Neos.Node.depth(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 27: You may need to rewrite "VARIABLE.depth" to Neos.Node.depth(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 13: You may need to rewrite "q(VARIABLE).property('_depth')" to Neos.Node.depth(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 29: You may need to rewrite "VARIABLE.depth" to Neos.Node.depth(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 30: You may need to rewrite "VARIABLE.depth" to Neos.Node.depth(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) {

renderer = Neos.Fusion:Component {
Expand All @@ -41,7 +44,8 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
# pass down props
#
attributes = ${Neos.Node.depth(node) || Neos.Node.depth(documentNode) || Neos.Node.depth(node) || Neos.Node.depth(documentNode)}
foo = ${q(bar).property('_depth') || q(bar).property("_depth")}
foo = ${Neos.Node.depth(bar) || Neos.Node.depth(bar)}
boo = ${q(nodes).first().property('_depth') || q(nodes).first().property("_depth")}

#
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes`
Expand All @@ -58,7 +62,8 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
<input
type="checkbox"
name={Neos.Node.depth(node)}
value={someOtherVariable.depth}
value={someOtherVariable.depth || something}
path={someOtherVariable.depth}
checked={props.checked}
{...Neos.Node.depth(node)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
# pass down props
#
attributes = ${node.path || documentNode.path || q(node).property('_path') || q(documentNode).property("_path")}
foo = ${q(bar).property('_path') || q(bar).property("_path")}
boo = ${q(nodes).first().property('_path') || q(nodes).first().property("_path")}

#
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes`
Expand All @@ -22,15 +24,17 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
<input
type="checkbox"
name={node.path}
value={someOtherVariable.path}
value={someOtherVariable.path || something}
path={someOtherVariable.path}
checked={props.checked}
{...node.path}
/>
`
}
}
-----
// TODO 9.0 migration: Line 26: You may need to rewrite "VARIABLE.path" to Neos.Node.path(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 29: You may need to rewrite "VARIABLE.path" to Neos.Node.path(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
// TODO 9.0 migration: Line 30: You may need to rewrite "VARIABLE.path" to Neos.Node.path(VARIABLE). We did not auto-apply this migration because we cannot be sure whether the variable is a Node.
prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) {

renderer = Neos.Fusion:Component {
Expand All @@ -39,6 +43,8 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
# pass down props
#
attributes = ${Neos.Node.path(node) || Neos.Node.path(documentNode) || Neos.Node.path(node) || Neos.Node.path(documentNode)}
foo = ${Neos.Node.path(bar) || Neos.Node.path(bar)}
boo = ${q(nodes).first().property('_path') || q(nodes).first().property("_path")}

#
# the `checked` state is calculated outside the renderer to allow` overriding via `attributes`
Expand All @@ -55,7 +61,8 @@ prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Fie
<input
type="checkbox"
name={Neos.Node.path(node)}
value={someOtherVariable.path}
value={someOtherVariable.path || something}
path={someOtherVariable.path}
checked={props.checked}
{...Neos.Node.path(node)}
/>
Expand Down

0 comments on commit 29b3386

Please sign in to comment.