MCPcopy
hub / github.com/cssinjs/jss / mergeExtend

Function mergeExtend

packages/jss-plugin-extend/src/index.js:7–50  ·  view source on GitHub ↗
(style, rule, sheet, newStyle)

Source from the content-addressed store, hash-verified

5const valueNs = `extendCurrValue${Date.now()}`
6
7function mergeExtend(style, rule, sheet, newStyle) {
8 const extendType = typeof style.extend
9 // Extend using a rule name.
10 if (extendType === 'string') {
11 if (!sheet) return
12 const refRule = sheet.getRule(style.extend)
13 if (!refRule) return
14 if (refRule === rule) {
15 warning(false, `[JSS] A rule tries to extend itself \n${rule.toString()}`)
16 return
17 }
18 const {parent} = refRule.options
19 if (parent) {
20 const originalStyle = parent.rules.raw[style.extend]
21 extend(originalStyle, rule, sheet, newStyle)
22 }
23 return
24 }
25
26 // Extend using an array.
27 if (Array.isArray(style.extend)) {
28 for (let index = 0; index < style.extend.length; index++) {
29 const singleExtend = style.extend[index]
30 const singleStyle =
31 typeof singleExtend === 'string' ? {...style, extend: singleExtend} : style.extend[index]
32 extend(singleStyle, rule, sheet, newStyle)
33 }
34 return
35 }
36
37 // Extend is a style object.
38 for (const prop in style.extend) {
39 if (prop === 'extend') {
40 extend(style.extend.extend, rule, sheet, newStyle)
41 continue
42 }
43 if (isObject(style.extend[prop])) {
44 if (!(prop in newStyle)) newStyle[prop] = {}
45 extend(style.extend[prop], rule, sheet, newStyle[prop])
46 continue
47 }
48 newStyle[prop] = style.extend[prop]
49 }
50}
51
52function mergeRest(style, rule, sheet, newStyle) {
53 // Copy base style.

Callers 1

extendFunction · 0.85

Calls 4

extendFunction · 0.85
isObjectFunction · 0.85
getRuleMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…