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

invalid/non stable ast for combinator with comment #189

Open
alexander-akait opened this issue Mar 15, 2019 · 23 comments
Open

invalid/non stable ast for combinator with comment #189

alexander-akait opened this issue Mar 15, 2019 · 23 comments
Labels

Comments

@alexander-akait
Copy link
Collaborator

alexander-akait commented Mar 15, 2019

Input:

h2 /*test*/ h4 { } /* Here we don't have `comment` node in ast (store comment in `raws`) */
h2/*test*/h4 { } /* Comment in ast */

It is do impossible analyzes comments, also adopt new version to stylelint and prettier. For me it is bug, but fixing this change ast.

@alexander-akait
Copy link
Collaborator Author

/cc @ai what do you think about this

@ai
Copy link
Member

ai commented Mar 15, 2019

Why it will change AST?

@alexander-akait
Copy link
Collaborator Author

@ai new comment node appears in ast(before it was in raws), just want to clarify should we release this as patch or major?

@ai
Copy link
Member

ai commented Mar 16, 2019

Technically it should be major

@alexander-akait
Copy link
Collaborator Author

Same problem for [ /*t*/ title /*t*/ = /*t*/ "Something" /*t*/ ], comments should be part of ast not raw

@alexander-akait
Copy link
Collaborator Author

alexander-akait commented Mar 19, 2019

/cc @ai i ahve some questions about spaces too
Example:

[   href   =   "test"   i   ] { }
  ^      ^   ^        ^   ^

What node(s) should store spaces in this case (inside raws?)? Because now logic in parser is very misleading and I can't understand whether we do it right or not. We have attribute, value, insensitive values.

@ai
Copy link
Member

ai commented Mar 19, 2019

To be honest, I am not sure that I know the best answer.

But I think in selector parser we should work with spaces in a different way, compare to PostCSS core. In main CSS syntax, whitespaces don’t mean anything. In selector, whitespace can have a lot of meanings.

So, I think it could be better to have a special token for spaces.

@alexander-akait
Copy link
Collaborator Author

@ai yep, we already have special token for space, my questions about where we should store meta information about space (raws). Let's see on example above:

  • First spaces should be stored in raws.before or raws.attribute.before?
  • Second space should be stored in raws.attribute.before or raws.operatore.before?
  • Third space should be stored in raws.operator.after or raws.value.before
  • Four space should be stored in raws.value.after or raws.insensitive.before (insensitive will be renamed in flag in next major)
  • Five space should be stored in raws.insensitive.after or raws.after (insensitive will be renamed in flag in next major)

@ai
Copy link
Member

ai commented Mar 19, 2019

Why do we need a raws for whitespaces when we have space token?

@alexander-akait
Copy link
Collaborator Author

alexander-akait commented Mar 19, 2019

@ai hm can you provide example/PoC of ast with space token (based on example above)? We need this spaces for linting/printing in stylelint and prettier

@ai
Copy link
Member

ai commented Mar 19, 2019

a b > { type: "word", value: "a" }, { type: "space", value: " " }, { type: "word", value: "b" }

@alexander-akait
Copy link
Collaborator Author

@ai in example above space is descendant selector, we already provide combinator as separate node, but in my example spaces mean nothing so we omit them from ast

@ai
Copy link
Member

ai commented Mar 19, 2019

I am not sure that we should omit them from AST.

@alexander-akait
Copy link
Collaborator Author

@ai I do not see their meaning as they really do not carry here any semantic load, also we do this right now, we can plan this on next major, but will be great solve problems with spaces using raws for next release

@ai
Copy link
Member

ai commented Mar 19, 2019

Yeap. This discussion is on you. Sorry, that I can't help right now.

@alexander-akait
Copy link
Collaborator Author

@ai Maybe not related to issue, but what is blocker integrate selector parser in postcss? Non standard syntax? Or nobody send a PR?

@ai
Copy link
Member

ai commented Mar 20, 2019

@evilebottnawi I am afraid that we will freeze API which will not be the best.

@alexander-akait
Copy link
Collaborator Author

@ai we can afraid this forever 😄 To be honestly ast of postcss is not enough for prettier/stylelint nowadays (prettier breaks code in many cases and i recommended don't use this for css/scss/less/etc). I think we should start integration selector/value/media parsers otherwise we will need do fork postcss and continue development 😞

@alexander-akait
Copy link
Collaborator Author

alexander-akait commented Mar 21, 2019

Also we can release this under flag/option and as experimental (adding information to readme about non stable)

We have big tests code base in stylelint and prettier and webpack so i think we catch all problems very fast

@ai
Copy link
Member

ai commented Mar 21, 2019

RIght now our main focus is visitor API postcss/postcss#1245

@alexander-akait
Copy link
Collaborator Author

alexander-akait commented Mar 21, 2019

Great feature 👍 Already look on this.

@ai Is there any sense send a PR or better fork postcss and starting own development for prettier? Because i don't want to waste my time on something what will be never merged.

@ai
Copy link
Member

ai commented Mar 21, 2019

@evilebottnawi I have a better plan. Let’s release new AST in postcss-selector-parser and if nobody will complain about it, we can move it to PostCSS

@alexander-akait
Copy link
Collaborator Author

@ai okay 👍 i will ping you before release or when i have some questions

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

No branches or pull requests

2 participants