Summary
Since postcss 8.5.16 (postcss/postcss#2036), Input#origin() expects 1-based columns and internally converts to 0-based before passing to source-map-js.
However, happy-css-modules still applies its own - 1 workaround in src/locator/postcss.ts#L95-L99:
const classSelectorOrigin = rule.source.input.origin(
classSelectorLocation.start.line,
// The column of `Input#origin` is 0-based. This behavior is undocumented and probably a postcss's bug.
// TODO: Open PR to postcss/postcss
classSelectorLocation.start.column - 1,
);
This results in double subtraction (column - 1 here + column - 1 inside postcss), producing -1 when the column is 1, which causes source-map-js to throw:
TypeError: Column must be greater than or equal to 0, got -1
Suggested fix
Remove the - 1 workaround since postcss 8.5.16 now correctly handles the conversion:
const classSelectorOrigin = rule.source.input.origin(
classSelectorLocation.start.line,
- // The column of `Input#origin` is 0-based. This behavior is undocumented and probably a postcss's bug.
- // TODO: Open PR to postcss/postcss
- classSelectorLocation.start.column - 1,
+ classSelectorLocation.start.column,
);
Reproduction
# With postcss 8.5.16 and happy-css-modules 5.0.1
hcm '**/*.module.scss'
# => AggregateError: Failed to process files
# => TypeError: Column must be greater than or equal to 0, got -1
Downgrading to postcss 8.5.15 resolves the issue.
Environment
- happy-css-modules: 5.0.1
- postcss: 8.5.16
- source-map-js: 1.2.1
- sass: 1.101.0
Related
Summary
Since postcss 8.5.16 (postcss/postcss#2036),
Input#origin()expects 1-based columns and internally converts to 0-based before passing tosource-map-js.However,
happy-css-modulesstill applies its own- 1workaround insrc/locator/postcss.ts#L95-L99:This results in double subtraction (
column - 1here +column - 1inside postcss), producing-1when the column is1, which causessource-map-jsto throw:Suggested fix
Remove the
- 1workaround since postcss 8.5.16 now correctly handles the conversion:const classSelectorOrigin = rule.source.input.origin( classSelectorLocation.start.line, - // The column of `Input#origin` is 0-based. This behavior is undocumented and probably a postcss's bug. - // TODO: Open PR to postcss/postcss - classSelectorLocation.start.column - 1, + classSelectorLocation.start.column, );Reproduction
Downgrading to postcss 8.5.15 resolves the issue.
Environment
Related
input.origin().columnanderror.columnhave wrong values postcss/postcss#2035Input#origin()returning incorrect position postcss/postcss#2036