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

Ensure that NoWorkResult and LazyResult have the same outcome. #1909

Conversation

romainmenke
Copy link
Contributor

see : #1869

@romainmenke romainmenke changed the title difference between NoWorkResult and LazyResult Ensure that NoWorkResult and LazyResult have the same outcome. Dec 30, 2023
@@ -16,6 +16,7 @@ class MapGenerator {
this.root = root
this.opts = opts
this.css = cssString
this.originalCSS = cssString
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a chicken vs. egg problem here that doesn't exist when fully parsing.

When the source is parsed there is already an Input instance created early. And this instance will have information about previous sourcemaps.

When the source is not parsed the Input instance is created in previous() but this is done after the annotation comments have already been removed.

Some mechanic is needed to get the previous sourcemaps from the original source and to store the modified css without the annotation comments.

I decided to add a second variable this.originalCSS which holds an unmodified copy.

I don't know if this is the best or even a good solution.
Please give feedback on this.

@@ -74,7 +75,7 @@ class MapGenerator {
}
}
} else if (this.css) {
this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
this.css = this.css.replace(/\n*?\/\*#[\S\s]*?\*\/$/gm, '')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When fully parsed all leading whitespace before an annotation comment will be removed, not only the first \n.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this part is related to the PR's main purpose (ensuring both NoWorkResult and LazyResult have the same outcome)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a LazyResult the annotation is a parsed comment.
Comment nodes in PostCSS also contain all the leading whitespace.

In a NoWorkResult this RegExp is used and it only replaced a single preceding newline.

Comment on lines +40 to 43
} else {
map.clearAnnotation();
this.result.css = map.css;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no sourcemap is requested the already present inline sourcemap must also be removed.

@romainmenke romainmenke marked this pull request as ready for review December 30, 2023 19:03
@ai ai merged commit c751e11 into postcss:main Jan 4, 2024
8 checks passed
@romainmenke romainmenke deleted the no-work-result-vs-lazy-result--inventive-pygmy-marmoset-5bbea7d7dd branch January 4, 2024 15:17
@ai
Copy link
Member

ai commented Jan 4, 2024

Thanks. Released in 8.4.33.

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

Successfully merging this pull request may close these issues.

None yet

3 participants