-
Notifications
You must be signed in to change notification settings - Fork 222
Fix ModelExpression's in section directive blocks. #1615
Conversation
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.
Might be worth adding a comment in DirectiveRemovalOptimizationPass
to explain the + 50
as well.
LGTM. We should later revisit other passes in this phase (maybe as part of https://github.com/aspnet/Razor/issues/1616) and make sure they are less fragile.
@@ -13,6 +13,8 @@ public class ModelExpressionPass : IntermediateNodePassBase, IRazorOptimizationP | |||
{ | |||
private const string ModelExpressionTypeName = "Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression"; | |||
|
|||
public override int Order => DefaultFeatureOrder + 100; |
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.
Add a comment here to explain the + 100
A high level suggestion I have to make this more flexible would be to add an annotation at the document level inside the model pass. That's something I considered when bringing up this feature anyway. |
Like mark nodes that have already been handled by the |
IIRC you said there was some trickiness about the ordering of passes wrt determining the model type. That's what I was referring to |
Ah, ya if we wanted to take that approach we could mark the document with an annotation stating the model type. Honestly wouldn't be that awful 😄 |
8ae279d
to
68346d5
Compare
🆙 📅 to have the section directive pass move non-token section nodes from the directive intermediate node to the section intermediate node. This way there's no double reference of those nodes. |
section.Children.Add(directive.Node.Children[i]); | ||
directive.Node.Children.RemoveAt(i--); |
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.
It would be better to change this to a while loop. This is just.... an abomination.
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.
#TaylorControlFlow
- Changed `SectionDirectivePass` to move non-token body nodes from the original `DirectiveIntermediateNode` to the `SectionIntermediateNode`. By doing this there's no longer dual references of `SectionIntermediateNode` bodies. - Added MVC tests for current and 1_X extensions. #1614
68346d5
to
196f3ba
Compare
DirectiveRemovalPass
runs atDefaultFeatureOrder + 50
in order to allow the design time directive tokens pass to consume directive intermediate nodes; however, this has a side effect of leaving around the original@section
nodes a bit too long. TheModelExpressionPass
would see two references to the sections body (SectionIntermediateNode
andDirectiveIntermediateNode
) and then do its work twice. To combat this behavior I bumped the ModelExpressionPass order to be 50 points higher than the directive removal pass.#1614