1
- import type { AtRule , ChildNode , Comment , Container , Declaration , Rule } from 'postcss'
1
+ import type { AtRule , ChildNode , Comment , Container , Declaration , Root , Rule } from 'postcss'
2
2
import type { ConvertUnit , PxtoremOptions } from '..'
3
3
import { defaultOptions } from '..'
4
4
import { MAYBE_REGEXP } from './constant'
@@ -202,15 +202,24 @@ export type H = {
202
202
}
203
203
}
204
204
205
- export function setupCurrentOptions ( h : H , node : Comment | ChildNode ) {
205
+ export function setupCurrentOptions (
206
+ h : H ,
207
+ {
208
+ node,
209
+ comment,
210
+ } : {
211
+ node ?: ChildNode | Root
212
+ comment ?: ChildNode | Comment
213
+ } ,
214
+ ) {
206
215
const opts = h [ currentOptions ] . originOpts
207
216
208
217
const filePath = node ?. source ?. input . file
209
218
210
- if ( ( node as Comment ) ?. text ) {
219
+ if ( isOptionComment ( comment ) ) {
211
220
h [ currentOptions ] . originOpts = {
212
221
...opts ,
213
- ...getOptionsFromComment ( node as Comment , opts . parseOptions ) ,
222
+ ...getOptionsFromComment ( comment , opts . parseOptions ) ,
214
223
}
215
224
}
216
225
@@ -223,7 +232,7 @@ export function setupCurrentOptions(h: H, node: Comment | ChildNode) {
223
232
return
224
233
}
225
234
226
- h [ currentOptions ] . rootValue = isFunction ( opts . rootValue ) ? opts . rootValue ( node . source ! . input ) : opts . rootValue
235
+ h [ currentOptions ] . rootValue = isFunction ( opts . rootValue ) ? opts . rootValue ( node ? .source ! . input ) : opts . rootValue
227
236
228
237
h [ currentOptions ] . pxReplace = createPxReplace ( h [ currentOptions ] . rootValue , opts . unitPrecision , opts . minPixelValue )
229
238
}
0 commit comments