Refactor printer functions into factory pattern#189
Open
bartveneman wants to merge 3 commits intomainfrom
Open
Refactor printer functions into factory pattern#189bartveneman wants to merge 3 commits intomainfrom
bartveneman wants to merge 3 commits intomainfrom
Conversation
Extract unquote/print_string as pure top-level exports. Refactor all other print_* functions into a create_printers() factory that captures optional_space, newline, last_semicolon, minify, make_indent, and lookup_comment as closure values. Export pre-configured pretty-print instances (OPTIONAL_SPACE=' ', NEWLINE='\n') so callers can use them with just CSSNode or CSSNode[]. The format() function continues to call create_printers() internally with minify-aware values and a lookup_comment callback backed by the parsed comment positions. https://claude.ai/code/session_018n5LPJrTpLBwUW6mcdJtkS
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #189 +/- ##
==========================================
- Coverage 96.78% 96.26% -0.52%
==========================================
Files 2 2
Lines 342 348 +6
Branches 119 119
==========================================
+ Hits 331 335 +4
- Misses 10 12 +2
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 2.13kB (13.57%) ⬆️
Affected Assets, Files, and Routes:view changes for bundle: formatCss-esmAssets Changed:
Files in
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the CSS formatter to extract printer functions into a factory function (
create_printers) that accepts configuration parameters. This enables code reuse and allows both minified and pretty-printed output without duplicating logic.Key Changes
create_printersfactory function: Moved all printer functions (print_operator, print_list, print_value, etc.) into a factory that accepts formatting configuration (optional_space, newline, last_semicolon, minify flag, indent maker, and comment lookup function)unquote()andprint_string()are now exported at the module level since they don't depend on formatting configurationcreate_printerswith non-minified defaults (spaces, newlines, tab indentation) and exported all printer functions for direct useformat()function: Now creates a printer instance with the appropriate configuration based on minify and tab_size options, then delegates toprint_stylesheetOPTIONAL_SPACE,NEWLINE, andLAST_SEMICOLONconstants with function parameters throughout the printer functionsImplementation Details
format()function can provide comment extractionmake_indentfunction is parameterized to support both tab-based and space-based indentation based on configurationhttps://claude.ai/code/session_018n5LPJrTpLBwUW6mcdJtkS