756 Commits
Author SHA1 Message Date
Andrey Sitnik f121ccda0f Fix 8.5.17 visitor regression 2026-07-29 12:56:11 +00:00
Haïm DimerandGitHub 05a93532d1 Preserve the BOM when stringifying (#2119)
PostCSS aims for byte-to-byte equal output, but the stringifier dropped a
leading byte order mark: `parse('a{}').toString()` returned `a{}`. The
BOM is already detected (`Input#hasBOM`) but was never re-emitted, so the
`bom.css` round-trip test had to be skipped.

Emit the BOM in `Stringifier#root` when the source had one, and re-enable the
previously skipped test.
2026-07-28 11:38:17 +02:00
Andrey Sitnik 2a1afe6782 Does no load source map file without opts.from 2026-07-24 16:59:19 +00:00
Sarath FrancisandGitHub 2b6d01d957 Fix custom property losing its semicolon before a comment (#2117)
A custom property declaration that is the last non-comment child but is
followed by comment siblings was stringified without its terminating
semicolon. Unlike a normal declaration, a custom property keeps everything
up to the next `;` or `}` as its value, so on re-parse the trailing
comments were folded into the value and the comment nodes disappeared.

Building such a tree with append()/insertAfter()/after() therefore
silently dropped the comments. Emit the semicolon when a custom property
still has following siblings so the output round-trips, mirroring the
existing handling for childless at-rules.
2026-07-22 09:41:08 +02:00
Sarath FrancisandGitHub cdc8897519 Fix childless at-rule losing its semicolon before a comment (#2115)
A childless (statement) at-rule that is the last non-comment child but is
followed by comment siblings was stringified without its terminating
semicolon. On re-parse the trailing comments were folded into the
at-rule prelude and dropped, so building such a tree with append() or
insertBefore() silently lost the comment nodes.

Emit the semicolon when a childless at-rule still has following siblings
so the output round-trips.
2026-07-21 10:53:42 +02:00
Sarath FrancisandGitHub 680ebe0244 Fix missing space when AtRule#params is set after parsing (#2113) 2026-07-19 10:23:15 +02:00
Mahin AnowarandGitHub 96354b9667 Rebuild nodes from another PostCSS copy in Warning (#2112) 2026-07-15 19:24:51 +02:00
Mahin AnowarandGitHub 8faa4f8eee Keep explicitly set raws.before when inserting nodes into root (#2111) 2026-07-13 12:37:33 +02:00
Andrey Sitnik c5fff770ca Limit where source map can be loaded for security reasons 2026-07-12 20:31:03 +00:00
Andrey Sitnik 69d5b399fd Fix Maximum call stack size exceeded error 2026-07-11 19:06:38 +00:00
Andrey Sitnik c05932eede Fix linter 2026-07-11 17:47:41 +00:00
Andrey Sitnik 3c60e5b691 Fix CI 2026-07-11 16:46:55 +00:00
Andrey Sitnik 62ad57f190 Prevent prototype hijacking in fromJSON 2026-07-11 16:44:46 +00:00
Alexander KireyevandGitHub 64117f22bc Fix Input#origin() mixing null and undefined for unmapped end position (#2106)
When the requested end position has no mapping in the source map,
originalPositionFor() returns an object with line/column set to null
rather than omitting them. endLine picked that null up correctly, but
endColumn was computed as `to && to.column + 1`, which due to operator
precedence is `to && (to.column + 1)`, turning null into 1. So callers
could get back { endColumn: 1, endLine: null }, which doesn't match
how every other unmapped case in this function behaves (undefined for
both). Looks like the +1 fix in #2036 covered the mapped case but not
this one.

Guard `to` the same way `from` already is, so an unmapped end position
just stays undefined.
2026-06-30 23:14:26 +02:00
Andrey Sitnik fb2bc3f358 Update formatting 2026-06-28 14:54:32 +00:00
mizdraandGitHub aef1148997 Fix Input#origin() returning incorrect position (#2036)
* Add missing `test.run()`

* Fix `Input#origin()` returning incorrect position

* Refactor test with source-map-js
2026-06-28 16:53:40 +02:00
Andrey Sitnik 88a1b66752 Fix tests 2026-06-28 14:50:44 +00:00
Mahin AnowarandGitHub 9e1092edf0 Don't clone root-less child nodes in container constructor (#2097)
The container constructor cloned every real Node passed in `nodes`, so a
freshly created (parent-less) node was adopted as a copy and the caller's
original reference never had its `parent` set — later operating on it threw
`Cannot read properties of undefined`. The clone was added only to keep the
source tree intact when moving nodes between roots, so it's skipped when the
node has no parent. Nodes that already belong to another tree are still
cloned, preserving the existing behavior. Closes #1987.
2026-06-28 16:50:07 +02:00
Sarath FrancisandGitHub be16af8528 Preserve node raws when rehydrating a JSON AST (#2100)
fromJSON() attached child nodes through the container constructor, which
runs them back through append()/normalize(). For root-level children that
re-applies insertion spacing normalization and overwrites each node's own
raws.before with the previous sibling's, so toJSON() -> fromJSON() was not
lossless: stylesheets with non-uniform blank lines between top-level rules
came back with their spacing flattened.

Rehydrate children separately and attach them directly, keeping the raws
exactly as serialized.
2026-06-28 12:56:11 +02:00
Sarath FrancisandGitHub aeeb3006c0 Fix Node#rangeBy() ignoring index 0 (#2091)
When calling Node#rangeBy() (and therefore Node#error() and
Node#warn()) with index 0, the resulting range covered the whole node
instead of a single character at offset 0.

The end-of-range branch used a truthy check on opts.index, so an index
of 0 fell through and left the end position at the node's end. This is
the same off-by-zero issue that was previously fixed for endIndex; the
index branches were missed. Switch both index checks to a numeric type
check, matching the existing endIndex handling.

index 0 now produces a single-character range, consistent with every
other index value.
2026-06-27 15:48:04 +02:00
74d18036e9 fix(node): always include offset in positionBy() like rangeBy() (#2099)
positionBy()'s default branch returned this.source.start verbatim, so for
custom syntaxes whose source.start lacks an offset (e.g. postcss-html) it
returned a position without offset, violating the Position type which
declares offset as required. rangeBy()/positionInside() were normalized to
always compute offset via sourceOffset() (#2033, issue #2029) but
positionBy() was left behind. Mirror the rangeBy() pattern.

Co-authored-by: oss69U-prep <prep@local>

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-27 15:31:28 +02:00
Andrey Sitnik 8aa951d5a5 Fix linter warnings 2026-05-11 17:27:55 +00:00
rootvector2 45d99215bb Address review: source-map dict tokens and oxfmt formatting 2026-05-11 21:41:17 +05:30
rootvector2 430e360b65 Add OSS-Fuzz fuzzing harness under test/fuzzing/ 2026-05-11 20:18:26 +05:30
James Garbutt e712faf51f fix: always call raw to retrieve raw values
Without this, it becomes impossible to override the stringifier with
your own raw computation, etc.
2026-05-04 12:37:08 +01:00
Andrey Sitnik 94190f83cb Speed up parsing many nested brackets 2026-04-26 12:53:38 +00:00
Andrey Sitnik d972b7cfd9 Update dependencies 2026-04-26 11:03:52 +00:00
Andrey SitnikandGitHub 675d4292f7 Escape </style> in CSS output (#2074) 2026-04-15 16:38:35 +02:00
Andrey Sitnik c08d9fa53f Another way to fix CI with TS on old Node.js 2026-04-07 16:27:01 +00:00
Andrey Sitnik 4654f72d56 Try to fix Node.js 10 on CI 2026-04-07 16:16:39 +00:00
Andrey Sitnik 85bf516d71 Move to oxfmt 2026-04-07 16:07:54 +00:00
Andrey Sitnik 9f08141f59 Update dependencies 2026-04-07 16:04:25 +00:00
Andrey Sitnik f45d36cfdb Update dependencies 2025-10-18 14:12:14 +00:00
Carlos (Goodwine)andGitHub 0b9dd87dfb Fix ContainerWithChildren to allow discriminating the node type by comparing its type property (#2049)
* Fix ContainerWithChildren to allow discriminating the node type by comparing its type property

* add more description to the test

* Revert version changes

* move tests to test/types.ts
2025-06-16 15:55:49 +02:00
Andrey Sitnik b8a22156cb Update dependencies 2025-05-29 13:54:36 +09:00
mizdraandGitHub ad3b622e89 Clarify documentation for node.source.end.offset (#2032)
* Clarify documentation for `node.source.end.offset`

* Add test cases for `node.source`

* Show example code for `end.offset`
2025-04-12 14:22:12 +02:00
mizdraandGitHub 676f35fe97 Add Input#fromLineAndColumn, CssSyntaxError.input.offset and CssSyntaxError.input.endOffset (#2034)
* Test the current behavior of error location

* Fix missing jsdoc for `Input#error(message, start, end, opts)`

* Refactor `fromOffset`

* Add `Input#fromLineAndColumn`

* Add `Input#offset` and `Input#endOffset`

* Convert `_getLineToIndex` to function
2025-03-22 18:08:32 +01:00
b38a1162f1 Fix missing offset in Node#positionInside, Node#positionBy and Node#rangeBy (#2033)
* Fix `opts` argument cannot be omitted

* Assign default values to `opts` just in case

- The `opts` argument to `Node#error` is currently omissible, but we'll assign a default value just in case.

* Add test cases

* Add test cases for `Node#rangeBy({start, end})`

* Add test cases for offset

* Fix missing offset in `Node#positionInside`, `Node#positionBy` and `Node#rangeBy`

* Fix conflict resolution mistakes

---------

Co-authored-by: Andrey Sitnik <[email protected]>
2025-03-22 18:07:03 +01:00
mizdraandGitHub a9a4e8849a Fix opts argument of Node#rangeBy() and Node#positionBy() cannot be omitted (#2031)
* Fix `opts` argument cannot be omitted

* Assign default values to `opts` just in case

- The `opts` argument to `Node#error` is currently omissible, but we'll assign a default value just in case.

* Add test cases
2025-03-22 17:13:46 +01:00
Andrey Sitnik d3d4d735df Update ESLint config 2025-02-19 13:43:47 +00:00
Andrey Sitnik a66145915f Fix tests 2025-02-19 11:59:45 +00:00
Andrey Sitnik 9571f4f00d Fix 80 columns limit 2025-01-13 15:13:59 +00:00
2f3c759a4b Add Input#document (#1996)
* Add `Input#document`

* Update lib/postcss.d.ts

Co-authored-by: Andrey Sitnik <[email protected]>

* apply suggestion from code review

---------

Co-authored-by: Andrey Sitnik <[email protected]>
2025-01-13 16:12:42 +01:00
Romain MenkeandGitHub 97e48f613e Fix position calculations when offset is missing (#1983) 2024-11-11 20:55:58 +01:00
Romain MenkeandGitHub b3f6e2737f fix inconsistent position calculations (#1980) 2024-11-10 22:13:31 +01:00
Andrey Sitnik 19afb318d6 Sort source code and fix ESLint 2024-08-31 23:26:27 +02:00
Andrey Sitnik 75b939cbe8 Try to fix old Node.js tests 2024-08-31 23:21:31 +02:00
Andrey Sitnik c67fd78c15 Clean up code 2024-08-31 20:59:37 +00:00
Steven P.andGitHub 40d6b9f5b7 Pretty CssSyntaxError from onelined (minified) css (#1965)
* Pretty CssSyntaxError from oneline (minified) css

* - cut minified css in place
- extend minified css length to 160

* - cut minified css considering block
2024-08-31 22:55:32 +02:00
Romain Menke 89975f2a70 failing test: for endIndex 0 in rangeBy 2024-03-20 18:24:44 +01:00