-
Notifications
You must be signed in to change notification settings - Fork 464
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
Implement the Trace AST node #2089
Conversation
In order to fix sass#1585 we need to introduce the `Trace` node from Ruby Sass. This node interacts with propsets in an interesting way. Have two node to represent the single Ruby `Prop` node caused a lot of trouble with correct implementing check nesting logic for `Trace`. The trouble with implementing `Trace` were exaggerated by us incorrectly eval propsets into declarations in the expand step. This PR moves the de-nesting of prop nodes the cssize step to [better match Ruby Sass][1]. Later we should rename this node `Prop` but it's out of scope of this PR. This should allow my work on porting the `Trace` node over from Ruby Sass to fix sass#1585. [1]: https://github.com/sass/sass/blob/63586f1e51c0aec47a7afcc8cd17aa03f32f0a29/lib/sass/tree/visitors/cssize.rb#L149-L166
Overall: LGTM. From what I see in the code, the I will add some additional minor nitpicking directly to the code in this PR ... |
// } | ||
|
||
bool CheckNesting::is_invalid_mixin_definition_parent(Statement* parent) | ||
{ |
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.
has bool
signature but only returns false?
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.
There either return false or thrown error. The Ruby Sass implement is return the error string or false which is gross in C++.
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.
ACK. But wouldn't it be more sane to just make them void
then? Not really a big deal, but signature just indicates something it is not actually doing this way.
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 think void might actually make the usage nicer.
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.
Agree. It probably would make sense to just name it "check_mixin_definition_parent" etc. That would also make it more clear that they actually do throw an error (I don't really expect that from something prefixed "is_").
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.
Made them void
and removed the is_
prefix. This makes the method names the same as Ruby Sass.
I decided to keep it Trace because that's the Ruby name. I would also like to come back to renaming
The implement doesn't care about the mixin itself, just it's name and pstate. I presume the name for displaying error messages somewhere I haven't seen yet. |
@xzyfer so the name is actually not used so far? Leaving the |
@@ -98,6 +100,8 @@ namespace Sass { | |||
return k; | |||
} | |||
|
|||
this->at_root_without_rule = false; |
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.
On a third look I don't see why it shouldn't work here if you add the LOCAL_FLAG
call here ... Since you seem to reset it just right before you exit the function (and therefore this variable scope).
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.
Sorry, you're correct.
@mgreter I explain in more detail in #2086
|
@xzyfer I fail to see what the "metadata" is ... maybe you can elaborate a bit more on that. |
I'm not 100% sure myself. As far as I can tell the Trace is a block The primary usecase appears to be in maintaining a backtrace in This is the explanation I got from @nex3
|
The Trace node is a simple wrapper around the result of a mixin call and `@content`. It exists as a way to group the resulting properties as a block but maintain some metadata about the initiating mixin call or `@content` block. It also plays an important rule is bubble those blocks with `@at-root` and nested property sets. This required implementing the final missing `cssize` methods. As a result we should a complete `@at-root` implementation. `Trace` "wrapping" other nodes didn't play nice with the naive check nesting implementation I lazily wrote so I also implemented 99% of the check nesting visitor like-for-like with Ruby Sass. The missing piece is handling `@imports` which is the only part I didn't need to touch in this work. Spec sass/sass-spec#868 Fixes sass#1585
OK, so it is pretty much the same thing I need for exposing import stack on C-API. After imports are resolved (in eval) we have the full AST Tree with |
That's my understanding. The node was originally called MixinTraceNode in Ruby Sass but was renamed to TraceNode but is still so far only used for mixins. |
OK, that clears some things up. I will see if I can re-use the |
I would avoid this. Ruby Sass is explicit about it's usecase.
There are various assumption made in places like check nesting and cssize visitors around this. |
The Trace node is a simple wrapper around the result of a mixin call and `@content`. It exists as a way to group the resulting properties as a block but maintain some metadata about the initiating mixin call or `@content` block. It also plays an important rule is bubble those blocks with `@at-root` and nested property sets. This required implementing the final missing `cssize` methods. As a result we should a complete `@at-root` implementation. `Trace` "wrapping" other nodes didn't play nice with the naive check nesting implementation I lazily wrote so I also implemented 99% of the check nesting visitor like-for-like with Ruby Sass. The missing piece is handling `@imports` which is the only part I didn't need to touch in this work. Spec sass/sass-spec#868 Fixes sass#1585
The Trace node is a simple wrapper around the result of a mixin call and `@content`. It exists as a way to group the resulting properties as a block but maintain some metadata about the initiating mixin call or `@content` block. It also plays an important rule is bubble those blocks with `@at-root` and nested property sets. This required implementing the final missing `cssize` methods. As a result we should a complete `@at-root` implementation. `Trace` "wrapping" other nodes didn't play nice with the naive check nesting implementation I lazily wrote so I also implemented 99% of the check nesting visitor like-for-like with Ruby Sass. The missing piece is handling `@imports` which is the only part I didn't need to touch in this work. Spec sass/sass-spec#868 Fixes sass#1585
I addressed the feedback, and did some additional clean up. |
I've also made sure the respective PRs this references are up to date with the changes made here so they serve as an accurate reference to the intentions of this merge. |
Nice work! Thx for that PR! |
This PR is the combination of #2085 and #2086.
They have their own detailed descriptions I wont repeat here.
Unfortunately those two PRs each have a single failing spec
which is due to a missing implementation provided by the
alternative PR. Those PRs have been marked as DNM and
will closed by this PR. I'm doing this so that master stays green
in case a revert is required.
Spec sass/sass-spec#868
Closes #2085
Closes #2086
Fixes #1585