-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Split Less and SCSS parsing into different parsers #2844
Conversation
Now, .less files are always parsed with postcss-less, and .scss files areare always parsed with postcss-scss. This: - Is less hacky. - Is meant to avoid issues like prettier#2829. - Is probably more performant. `parser: "postcss"` and `--parser postcss` continue to work like before: First trying postcss-less, and if that fails, postcss-scss, unless a regex says that we should try in the opposite order. The new values for the parser option are "postcss-less" and "postcss-scss".
I feel like the
Unfortunately changing this would obviously be an API breaking change. |
I agree that the parser option is strange and could be better. But I don't think it should affect this PR in any way. Btw, the postcss parts of your table should look more like this:
|
Agreed, parser was designed before we intended to support more than just pure JavaScript. I think that it makes sense to introduce a language option and we figure out a way to make it backwards compatible. |
website/pages/playground/index.html
Outdated
@@ -359,7 +359,7 @@ | |||
</div> | |||
<div class="options last"> | |||
<label>--trailing-comma <select id="trailingComma"><option value="none">none</option><option value="es5">es5</option><option value="all">all</option></select></label> | |||
<label>--parser <select id="parser"><option value="babylon">babylon</option><option value="flow">flow</option><option value="typescript">typescript</option><option value="postcss">postcss</option><option value="json">json</option><option value="graphql">graphql</option></select></label> | |||
<label>--parser <select id="parser"><option value="babylon">babylon</option><option value="flow">flow</option><option value="typescript">typescript</option><option value="postcss">postcss</option><!-- TODO: Enable these when prettier@>1.7.0 has been released. <option value="postcss-less">postcss-less</option><option value="postcss-scss">postcss-scss</option>--><option value="json">json</option><option value="graphql">graphql</option></select></label> |
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.
1.8.0 now
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.
Exclusive >1.7.0
is technically correct 😉
@@ -84,7 +84,7 @@ Format options: | |||
|
|||
--no-bracket-spacing Do not print spaces between brackets. | |||
--jsx-bracket-same-line Put > on the last line instead of at a new line. | |||
--parser <flow|babylon|typescript|postcss|json|graphql> | |||
--parser <flow|babylon|typescript|postcss|postcss-less|postcss-scss|json|graphql> |
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.
Suggestion: let's just name it less
and scss
. And allow both postcss
and css
to work and only mention css
in the docs.
We're unlikely going to ever support anything else than postcss to parse our CSS and at the end of the day the users don't care, they just want to parse their css/less/sass.
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.
Do you mean that it is unlikely that we'll support two different parsers for the same language, like we do for JS with both Babylon and Flow? Or that it is unlikely that we'll every switch from postcss to something else?
I have been researching switching away from postcss:
- css-tree for CSS
- less or gonzales-pe for Less
- dart-sass or gonzales-pe for SCSS (see also JS API: Create a method to get SASS AST sass/dart-sass#88)
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.
If we did switch away, we probably wouldn't want to keep supporting postcss (another advantage of using --language)
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.
Yeah, what I mean is that we just name it with the language, so we don't get stuck to a specific parser if we want to switch.
Indeed. Opened #2846 for discussion. |
Conflicts: src/cli-constant.js tests_integration/__tests__/__snapshots__/early-exit.js.snap
Updates:
|
6332d17
to
00fc5b0
Compare
@@ -238,6 +238,8 @@ function replaceHash(hash) { | |||
|
|||
function getCodemirrorMode(options) { | |||
switch (options.parser) { | |||
// TODO: Remove the "postcss" case when prettier@>1.7.0 is released. |
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.
Is this a prerelease task, or a postrelease task? (Or doesn't matter)
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.
post
* Split Less and SCSS parsing into different parsers Now, .less files are always parsed with postcss-less, and .scss files areare always parsed with postcss-scss. This: - Is less hacky. - Is meant to avoid issues like prettier#2829. - Is probably more performant. `parser: "postcss"` and `--parser postcss` continue to work like before: First trying postcss-less, and if that fails, postcss-scss, unless a regex says that we should try in the opposite order. The new values for the parser option are "postcss-less" and "postcss-scss". * Remove postcss from package.json since it is not used * Rename parser-less to less and parser-scss to scss * Deprecate parser:postcss in favor of parser:css * Fix CSS tests
@ismail-syed They do, well spotted! |
Now, .less files are always parsed with postcss-less, and .scss files
areare always parsed with postcss-scss. This:
parser: "postcss"
and--parser postcss
continue to work like before:First trying postcss-less, and if that fails, postcss-scss, unless a
regex says that we should try in the opposite order. The new values for
the parser option are "postcss-less" and "postcss-scss".