@wix/zero-config-implementation 1.94.0 → 1.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"registry": "https://registry.npmjs.org/",
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.95.0",
|
|
8
8
|
"description": "Core library for extracting component manifests from JS and CSS files",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/index.js",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
]
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
|
-
"falconPackageHash": "
|
|
109
|
+
"falconPackageHash": "831bcccde22937359efc18de9a5b8b4e52d3ca3fa6ebdbdd9bcb4a65"
|
|
110
110
|
}
|
|
@@ -263,6 +263,29 @@ describe('toEditorReactComponent display conversion', () => {
|
|
|
263
263
|
})
|
|
264
264
|
})
|
|
265
265
|
|
|
266
|
+
describe('toEditorReactComponent — cssProperties defaultValue', () => {
|
|
267
|
+
it('ignores the var() fallback when building a regular CSS property defaultValue', () => {
|
|
268
|
+
const extractorData = new Map<string, unknown>()
|
|
269
|
+
extractorData.set('css-matcher', matcherDataFromCss('background: var(wst-primary-background-color, tomato);'))
|
|
270
|
+
extractorData.set('css-properties', { relevant: [CSS_PROPERTIES.CSS_PROPERTY_TYPE.background] })
|
|
271
|
+
|
|
272
|
+
const rootElement: ExtractedElement = {
|
|
273
|
+
traceId: 'trace-root',
|
|
274
|
+
name: 'root',
|
|
275
|
+
tag: 'div',
|
|
276
|
+
attributes: {},
|
|
277
|
+
extractorData,
|
|
278
|
+
children: [],
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const result = toEditorReactComponent(createComponent(rootElement))
|
|
282
|
+
|
|
283
|
+
expect(result.editorElement?.cssProperties?.background).toEqual({
|
|
284
|
+
defaultValue: 'var(--wst-primary-background-color)',
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
})
|
|
288
|
+
|
|
266
289
|
describe('toEditorReactComponent selector conversion', () => {
|
|
267
290
|
it.each([
|
|
268
291
|
['a', 'a___'],
|
|
@@ -16,6 +16,7 @@ import { IoError } from '../errors'
|
|
|
16
16
|
import { buildRefElementManifestKey } from '../extensions/ref-elements/path-utils'
|
|
17
17
|
import type { RefElementMatch } from '../extensions/ref-elements/types'
|
|
18
18
|
import type { ComponentInfoWithCss } from '../index'
|
|
19
|
+
import { stripVarFallback } from '../information-extractors/css/parse'
|
|
19
20
|
import type { MatchedCssData, RegisteredCustomProperty } from '../information-extractors/css/types'
|
|
20
21
|
import type {
|
|
21
22
|
CoupledComponentInfo,
|
|
@@ -580,7 +581,8 @@ function buildCssProperties(element: ExtractedElement | undefined): Record<strin
|
|
|
580
581
|
result[propName] = buildDisplayProperty(element)
|
|
581
582
|
continue
|
|
582
583
|
}
|
|
583
|
-
const
|
|
584
|
+
const resolvedValue = resolveLonghand(propName, cssPropertyValues)
|
|
585
|
+
const defaultValue = resolvedValue !== undefined ? stripVarFallback(resolvedValue) : undefined
|
|
584
586
|
result[propName] = {
|
|
585
587
|
...(defaultValue !== undefined && { defaultValue }),
|
|
586
588
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { parseCss, resolveCssPropertyValue } from './parse'
|
|
2
|
+
import { parseCss, resolveCssPropertyValue, stripVarFallback } from './parse'
|
|
3
3
|
|
|
4
4
|
describe('parseCss — getStateClasses', () => {
|
|
5
5
|
it('extracts a custom-class modifier with no paired pseudo', () => {
|
|
@@ -325,3 +325,21 @@ describe('resolveVarIdentifiers — CSS Modules @value compatibility', () => {
|
|
|
325
325
|
expect(contentProperty.value).toBe('"var(foo)"')
|
|
326
326
|
})
|
|
327
327
|
})
|
|
328
|
+
|
|
329
|
+
describe('stripVarFallback', () => {
|
|
330
|
+
it('removes a var() fallback, keeping only the variable reference', () => {
|
|
331
|
+
expect(stripVarFallback('var(--wst-primary-background-color, tomato)')).toBe('var(--wst-primary-background-color)')
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it('leaves a var() with no fallback unchanged', () => {
|
|
335
|
+
expect(stripVarFallback('var(--x)')).toBe('var(--x)')
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('strips a fallback embedded within a larger value', () => {
|
|
339
|
+
expect(stripVarFallback('1px solid var(--border-color, gray)')).toBe('1px solid var(--border-color)')
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
it('leaves a value with no var() unchanged', () => {
|
|
343
|
+
expect(stripVarFallback('10px')).toBe('10px')
|
|
344
|
+
})
|
|
345
|
+
})
|
|
@@ -373,6 +373,34 @@ function resolveVarIdentifiers(valueNode: CssNode, valueAliases: Map<string, str
|
|
|
373
373
|
return generate(valueNode)
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Removes the fallback argument from every var() call in a CSS value string. A var()
|
|
378
|
+
* fallback is not a meaningful "default value" for the editor to surface — only the
|
|
379
|
+
* variable reference itself is — so `var(--x, tomato)` becomes `var(--x)`.
|
|
380
|
+
*/
|
|
381
|
+
export function stripVarFallback(cssValue: string): string {
|
|
382
|
+
if (!cssValue.includes('var(')) return cssValue
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const valueAst = parse(cssValue, { context: 'value' })
|
|
386
|
+
walk(valueAst, {
|
|
387
|
+
visit: 'Function',
|
|
388
|
+
enter(functionNode: FunctionNode) {
|
|
389
|
+
if (functionNode.name !== 'var') return
|
|
390
|
+
const functionArguments = [...functionNode.children]
|
|
391
|
+
const firstCommaIndex = functionArguments.findIndex(
|
|
392
|
+
(argumentNode) => argumentNode.type === 'Operator' && argumentNode.value === ',',
|
|
393
|
+
)
|
|
394
|
+
if (firstCommaIndex === -1) return
|
|
395
|
+
functionNode.children.fromArray(functionArguments.slice(0, firstCommaIndex))
|
|
396
|
+
},
|
|
397
|
+
})
|
|
398
|
+
return generate(valueAst)
|
|
399
|
+
} catch {
|
|
400
|
+
return cssValue
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
376
404
|
/**
|
|
377
405
|
* Extracts all CSS custom property names referenced via var() by walking
|
|
378
406
|
* the declaration value AST for Function nodes named "var".
|