MCPcopy Create free account
hub / github.com/adobe/react-spectrum / parse

Function parse

packages/@react-spectrum/style-macro-s1/src/runtime.ts:69–113  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

67}
68
69function parse(s: string) {
70 let properties = new Map<string, string>();
71 let i = 0;
72 while (i < s.length) {
73 while (i < s.length && s[i] === ' ') {
74 i++;
75 }
76
77 let start = i;
78 readValue(); // property index
79
80 // read conditions (up to the last segment)
81 let condition = i;
82 while (i < s.length && s[i] !== ' ') {
83 readValue();
84 }
85
86 let property = s.slice(start, condition);
87 properties.set(property, (properties.get(property) || '') + ' ' + s.slice(start, i));
88 }
89
90 function readValue() {
91 if (s[i] === '-') {
92 // the beginning and end of arbitrary values are marked with -
93 while (i < s.length && s[i] !== ' ') {
94 i++;
95 if (s[i] === '-') {
96 i++;
97 break;
98 }
99 }
100 } else {
101 while (i < s.length) {
102 if (s[i] === '_') {
103 i++;
104 } else {
105 i++;
106 break;
107 }
108 }
109 }
110 }
111
112 return properties;
113}

Callers 1

mergeStylesFunction · 0.70

Calls 3

sliceMethod · 0.80
readValueFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected