@@ -72,6 +72,10 @@ export const transform: Transform = (fileInfo, api) => {
7272 // Implement the transform.
7373 // See below for more details on the API.
7474};
75+
76+ // Optionally defined a named `parser` export to configure the PostCSS parser.
77+ // Docs: https://postcss.org/api/#parser
78+ // export const parser = ...;
7579```
7680
7781## API
@@ -107,6 +111,7 @@ It's an object with helpers provided by `css-codemod` to perform transformations
107111// transform.ts
108112
109113import { Transform } from ' css-codemod' ;
114+ import { parse , stringify } from ' postcss-scss' ;
110115
111116export const transform: Transform = (fileInfo , api ) => {
112117 // Convert the file source into an AST using the provided helper.
@@ -129,8 +134,16 @@ export const transform: Transform = (fileInfo, api) => {
129134
130135 // Convert the mutated AST back into a string.
131136 // Since a string is returned this will be written back to the file.
132- return root .toString ();
137+ // Note: in this example the `postcss-scss` package is used to add
138+ // SCSS syntax support. The stringifier is passed when we call `toString` to
139+ // re-output valid SCSS syntax.
140+ return root .toString (stringify );
133141};
142+
143+ // Note: in this example the `postcss-scss` package is used to add SCSS syntax support.
144+ // This configures PostCSS to correctly parse SCSS syntax.
145+ // Docs: https://postcss.org/api/#parser
146+ export const parser = parse ;
134147```
135148
136149### PostCSS
0 commit comments