CodeVetter · Repo Unpack · Data flow
postcss/postcss
CSS enters as text or a string-convertible value and gains an Input object that owns original text, source identity, and previous-map information. The parser turns token offsets into AST source positions and retains formatting separately in raws. Plugins mutate the shared tree and append messages to Result, after which a builder emits CSS and optionally source mappings. JSON serialization provides a separate transport boundary; neither that API nor normal output generation writes the resulting artifact to disk.
- Input rejects null, undefined, and objects without toString, converts accepted input to text, strips an initial BOM, and keeps opts.document separately from the parsed CSS.
- Input resolves relative from paths, preserves absolute paths and URL-like identifiers, loads PreviousMap when supported, and assigns a non-secure nanoid-based diagnostic ID when no file identity exists.
- Tokenizer emits token arrays containing text and offsets; Parser.init attaches a shared Input and start position, while declaration parsing records an exclusive end offset.
- Parser.raw separates cleaned selector/value/parameter text from its original token spelling; Stringifier.rawValue reuses that spelling only while the semantic value still matches.
- LazyResult accepts existing Root/Document trees or previous Result/LazyResult objects without reparsing; it clears cleanliness markers and carries a previous result's map into opts.map.prev.
- Visitor callbacks receive helpers containing the public API and current Result; proxies mark selected property changes dirty, and markDirty propagates invalidation through ancestors.
- Serialization either concatenates builder chunks directly or lets MapGenerator track generated positions, attach source mappings, compose previous maps, and return CSS with an optional external map; the documented caller writes files.
- Node.toJSON omits parent/proxy links and deduplicates Inputs using inputId; fromJSON restores Input/PreviousMap prototypes, resolves input references, constructs nodes bottom-up, and reconnects child.parent without spacing normalization.