Skip to content

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

Merged
ai merged 2 commits intopostcss:mainfrom
romainmenke:no-work-result-vs-lazy-result--inventive-pygmy-marmoset-5bbea7d7dd
Jan 4, 2024
Merged

Ensure that NoWorkResult and LazyResult have the same outcome.#1909
ai merged 2 commits intopostcss:mainfrom
romainmenke:no-work-result-vs-lazy-result--inventive-pygmy-marmoset-5bbea7d7dd

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
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.

}
} 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

@romainmenke romainmenke Jan 2, 2024

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
@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.

3 participants