Skip to content

Commit ff88ffc

Browse files
committed
chore: minor parsing improvements
1 parent 574dd53 commit ff88ffc

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

packages/uniwind/src/metro/processor/css.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ export class CSS {
278278
}
279279

280280
if (Array.isArray(declarationValue)) {
281+
if (declarationValue.length === 1) {
282+
return this.processValue(declarationValue[0]!)
283+
}
284+
281285
return this.addComaBetweenTokens(declarationValue).reduce<string | number>((acc, value, index, array) => {
282286
if (typeof value === 'object') {
283287
const nextValue = array.at(index + 1)

packages/uniwind/src/metro/stylesheet/addMetaToStylesTemplate.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ import { ProcessorBuilder } from '../processor'
33
import { Platform, StyleSheetTemplate } from '../types'
44
import { isDefined, toCamelCase } from '../utils'
55

6+
const simpleSerialize = (value: any): string => {
7+
if (Array.isArray(value)) {
8+
return [
9+
'[',
10+
value.map(simpleSerialize).join(', '),
11+
']',
12+
].join('')
13+
}
14+
15+
return JSON.stringify(value)
16+
}
17+
618
export const addMetaToStylesTemplate = (Processor: ProcessorBuilder, currentPlatform: Platform) => {
719
const stylesheetsEntries = Object.entries(Processor.stylesheets as StyleSheetTemplate)
820
.map(([className, stylesPerMediaQuery]) => {
@@ -26,7 +38,7 @@ export const addMetaToStylesTemplate = (Processor: ProcessorBuilder, currentPlat
2638

2739
const entries = Object.entries(rest)
2840
.flatMap(([property, value]) => Processor.RN.cssToRN(property, value))
29-
.map(([property, value]) => [property, `function() { return ${value} }`])
41+
.map(([property, value]) => [property, `function() { return ${simpleSerialize(value)} }`])
3042

3143
if (platform && platform !== Platform.Native && platform !== currentPlatform) {
3244
return null

0 commit comments

Comments
 (0)