Skip to content
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

atruleExpression always null #39

Closed
strarsis opened this issue Mar 14, 2017 · 5 comments
Closed

atruleExpression always null #39

strarsis opened this issue Mar 14, 2017 · 5 comments

Comments

@strarsis
Copy link
Contributor

@strarsis strarsis commented Mar 14, 2017

The this.atruleExpression is always null, even with Atrule expressions, even not inside an Atrule expression.
There isn't any node of type 'atruleExpression' or of similar name either.
It would be very convenient if the atruleExpression is available for all its child nodes.

var csstree  = require('css-tree');

var testCss = '@media screen{.st1{fill:red;}}';
var cssAst = csstree.parse(testCss);
csstree.walk(cssAst, function(node, item, list) {
  // this.atruleExpression is always null, even inside node with type == 'Atrule'.
});
lahmatiy added a commit that referenced this issue Mar 14, 2017
@lahmatiy
Copy link
Member

@lahmatiy lahmatiy commented Mar 14, 2017

Yep, it's because Atrule.expression is MediaQueryList type, not an AtruleExpression. Not sure it's a bug, but agree it's confusing.
I'm planning to change solution to provide access to upper nodes (via the stack or something like that). But still thinking about a better way to do that.
Until new solution I added contextWalker marker for MediaQueryList, it should help right now. Will publish patch version later.

@strarsis
Copy link
Contributor Author

@strarsis strarsis commented Mar 14, 2017

I want to filter selectors by their parent Atrule expression (media query),
this is only possible when the parent Atrule is known for each selector.
Is this possible with the current csstree release already or do I have to wait until the next release?

@lahmatiy
Copy link
Member

@lahmatiy lahmatiy commented Mar 14, 2017

Well, for your task you need a this.atrule reference rather than a this.atruleExpression. We need to add this marker also. That's why I dislike current solution.
Yep, you need wait until next release. Or use csstree/csstree in you package.json instead of version (in this case, csstree will be installed from master branch).

@lahmatiy
Copy link
Member

@lahmatiy lahmatiy commented Mar 14, 2017

I added this.atrule reference in context. Also, I've created an issue #41 to track status on changes in walker implementation.

lahmatiy added a commit that referenced this issue Apr 3, 2017
@lahmatiy
Copy link
Member

@lahmatiy lahmatiy commented Sep 5, 2017

Start with 1.0.0-alpha20 at-rule prelude is always wraps into AtruleExpression. So this.atruleExpression now works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.