Skip to content

refactor: check all falsy conditions of plugins and opts before returning NoWorkResult in process()#1908

Merged
ai merged 1 commit intopostcss:mainfrom
ahmdammarr:refactor/safe-check-for-NoWorkResult
Jan 4, 2024
Merged

refactor: check all falsy conditions of plugins and opts before returning NoWorkResult in process()#1908
ai merged 1 commit intopostcss:mainfrom
ahmdammarr:refactor/safe-check-for-NoWorkResult

Conversation

@ahmdammarr
Copy link
Copy Markdown
Contributor

resolves #1869

Fixes:

  • refactor check of all falsy condition of plugins and opts before returing NoWorkResult in Processor.process().

postcss/lib/processor.js

Lines 44 to 55 in a0a82d3

process(css, opts = {}) {
if (
this.plugins.length === 0 &&
typeof opts.parser === 'undefined' &&
typeof opts.stringifier === 'undefined' &&
typeof opts.syntax === 'undefined'
) {
return new NoWorkResult(this, css, opts)
} else {
return new LazyResult(this, css, opts)
}
}

For a full repro see : https://github.com/romainmenke/postcss-no-work-result-sourcemaps

By setting parser: null as a processing option you can force a LazyResult.

Setting null instead of undefined is a common mistake, especially when not using TypeScript.

Is it intentional that NoWorkResult and LazyResult have different CSS outputs?

@ai
Copy link
Copy Markdown
Member

ai commented Dec 29, 2023

It looks good to me. It is too late for release for me, I will try to release it tomorrow.

@ahmdammarr ahmdammarr changed the title refactor: check all falsy conditions of plugins and opts before returning NoWorkResult instance in process() refactor: check all falsy conditions of plugins and opts before returning NoWorkResult in process() Dec 29, 2023
@ai ai merged commit f2e7a9f into postcss:main Jan 4, 2024
@ai
Copy link
Copy Markdown
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.

NoWorkResult and LazyResult have very subtle differences and these can be accidentally encountered

2 participants