File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
migrations/replace-sass-color Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 77 NamespaceOptions ,
88 namespace ,
99 isSassFunction ,
10+ getFunctionArgs ,
11+ stripQuotes ,
1012 StopWalkingFunctionNodes ,
1113} from '../../utilities/sass' ;
1214import { isKeyOf } from '../../utilities/type-guards' ;
@@ -93,9 +95,9 @@ const plugin = (options: PluginOptions = {}): Plugin => {
9395
9496 // 2. Replace `color()` with variable
9597 if ( node . value === namespacedColor ) {
96- const colorFnArgs = node . nodes . filter ( ( node ) => node . type !== 'div' ) ;
97- const hue = colorFnArgs [ 0 ] ?. value ?? '' ;
98- const value = colorFnArgs [ 1 ] ?. value ?? 'base' ;
98+ const colorFnArgs = getFunctionArgs ( node ) ;
99+ const hue = stripQuotes ( colorFnArgs [ 0 ] ?? '' ) ;
100+ const value = stripQuotes ( colorFnArgs [ 1 ] ?? 'base' ) ;
99101 const forBackground = colorFnArgs [ 2 ] ;
100102
101103 // Skip color() with for-background argument
Original file line number Diff line number Diff line change @@ -179,6 +179,16 @@ export function getFunctionArgs(node: FunctionNode): string[] {
179179 return args ;
180180}
181181
182+ /**
183+ * Removes surrounding quotes from a string
184+ * @example
185+ * const string = '"hello"';
186+ * stripQuotes(string); // hello
187+ */
188+ export function stripQuotes ( string : string ) {
189+ return string . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' ) ;
190+ }
191+
182192/**
183193 * All transformable dimension units. These values are used to determine
184194 * if a decl.value can be converted to pixels and mapped to a Polaris custom property.
You can’t perform that action at this time.
0 commit comments