@@ -13,18 +13,22 @@ import '../syntax/color/utils/constants.js';
1313 */
1414function expand ( ast ) {
1515 //
16- if ( ! [ EnumToken . RuleNodeType , EnumToken . StyleSheetNodeType , EnumToken . AtRuleNodeType ] . includes ( ast . typ ) ) {
17- return ast ;
18- }
19- if ( EnumToken . RuleNodeType == ast . typ ) {
20- return {
21- typ : EnumToken . StyleSheetNodeType ,
22- chi : expandRule ( ast )
23- } ;
24- }
25- if ( ! ( 'chi' in ast ) ) {
26- return ast ;
27- }
16+ // if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
17+ //
18+ // return ast;
19+ // }
20+ // if (EnumToken.RuleNodeType == ast.typ) {
21+ //
22+ // return <AstRuleStyleSheet>{
23+ // typ: EnumToken.StyleSheetNodeType,
24+ // chi: expandRule(<AstRule>ast)
25+ // }
26+ // }
27+ //
28+ // if (!('chi' in ast)) {
29+ //
30+ // return ast;
31+ // }
2832 const result = { ...ast , chi : [ ] } ;
2933 // @ts -ignore
3034 for ( let i = 0 ; i < ast . chi . length ; i ++ ) {
@@ -48,10 +52,11 @@ function expand(ast) {
4852 // @ts -ignore
4953 result . chi . push ( { ...( hasRule ? expand ( node ) : node ) } ) ;
5054 }
51- else {
52- // @ts -ignore
53- result . chi . push ( node ) ;
54- }
55+ // else {
56+ //
57+ // // @ts -ignore
58+ // result.chi.push(node);
59+ // }
5560 }
5661 return result ;
5762}
@@ -65,24 +70,26 @@ function expandRule(node) {
6570 const rule = ast . chi [ i ] ;
6671 if ( ! rule . sel . includes ( '&' ) ) {
6772 const selRule = splitRule ( rule . sel ) ;
68- if ( selRule . length > 1 ) {
69- const r = ':is(' + selRule . map ( a => a . join ( '' ) ) . join ( ',' ) + ')' ;
70- rule . sel = splitRule ( ast . sel ) . reduce ( ( a , b ) => a . concat ( [ b . join ( '' ) + r ] ) , [ ] ) . join ( ',' ) ;
71- }
72- else {
73- // selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
74- const arSelf = splitRule ( ast . sel ) . filter ( ( r ) => r . every ( ( t ) => t != ':before' && t != ':after' && ! t . startsWith ( '::' ) ) ) . reduce ( ( acc , curr ) => acc . concat ( [ curr . join ( '' ) ] ) , [ ] ) . join ( ',' ) ;
75- if ( arSelf . length == 0 ) {
76- ast . chi . splice ( i -- , 1 ) ;
77- continue ;
78- }
79- //
80- selRule . forEach ( arr => combinators . includes ( arr [ 0 ] . charAt ( 0 ) ) ? arr . unshift ( arSelf ) : arr . unshift ( arSelf , ' ' ) ) ;
81- rule . sel = selRule . reduce ( ( acc , curr ) => {
82- acc . push ( curr . join ( '' ) ) ;
83- return acc ;
84- } , [ ] ) . join ( ',' ) ;
73+ // if (selRule.length > 1) {
74+ //
75+ // const r: string = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
76+ // rule.sel = splitRule(ast.sel).reduce((a: string[], b: string[]): string[] => a.concat([b.join('') + r]), <string[]>[]).join(',');
77+ //
78+ // }
79+ // else {
80+ // selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
81+ const arSelf = splitRule ( ast . sel ) . filter ( ( r ) => r . every ( ( t ) => t != ':before' && t != ':after' && ! t . startsWith ( '::' ) ) ) . reduce ( ( acc , curr ) => acc . concat ( [ curr . join ( '' ) ] ) , [ ] ) . join ( ',' ) ;
82+ if ( arSelf . length == 0 ) {
83+ ast . chi . splice ( i -- , 1 ) ;
84+ continue ;
8585 }
86+ //
87+ selRule . forEach ( arr => combinators . includes ( arr [ 0 ] . charAt ( 0 ) ) ? arr . unshift ( arSelf ) : arr . unshift ( arSelf , ' ' ) ) ;
88+ rule . sel = selRule . reduce ( ( acc , curr ) => {
89+ acc . push ( curr . join ( '' ) ) ;
90+ return acc ;
91+ } , [ ] ) . join ( ',' ) ;
92+ // }
8693 }
8794 else {
8895 let childSelectorCompound = [ ] ;
@@ -108,9 +115,10 @@ function expandRule(node) {
108115 if ( s == '&' || parentSelector ) {
109116 withCompound . push ( s ) ;
110117 }
111- else {
112- withoutCompound . push ( s . slice ( 1 ) ) ;
113- }
118+ // else {
119+ //
120+ // withoutCompound.push(s.slice(1));
121+ // }
114122 }
115123 }
116124 else {
@@ -121,9 +129,10 @@ function expandRule(node) {
121129 withCompound . push ( s ) ;
122130 }
123131 }
124- else {
125- withoutCompound . push ( s ) ;
126- }
132+ // else {
133+ //
134+ // withoutCompound.push(s);
135+ // }
127136 }
128137 const selectors = [ ] ;
129138 const selector = rules . length > 1 ? ':is(' + rules . map ( a => a . join ( '' ) ) . join ( ',' ) + ')' : rules [ 0 ] . join ( '' ) ;
@@ -155,11 +164,13 @@ function expandRule(node) {
155164 if ( withCompound . length == 1 ) {
156165 selectors . push ( replaceCompound ( withCompound [ 0 ] , selector ) ) ;
157166 }
158- else {
159- for ( const w of withCompound ) {
160- selectors . push ( replaceCompound ( w , selector ) ) ;
161- }
162- }
167+ // else {
168+ //
169+ // for (const w of withCompound) {
170+ //
171+ // selectors.push(replaceCompound(w, selector));
172+ // }
173+ // }
163174 }
164175 rule . sel = selectors . reduce ( ( acc , curr ) => curr . length == 0 ? acc : acc + ( acc . length > 0 ? ',' : '' ) + curr , '' ) ;
165176 }
@@ -200,10 +211,11 @@ function expandRule(node) {
200211 // @ts -ignore
201212 astAtRule . chi . push ( ...expandRule ( r ) ) ;
202213 }
203- else {
204- // @ts -ignore
205- astAtRule . chi . push ( r ) ;
206- }
214+ // else {
215+ //
216+ // // @ts -ignore
217+ // astAtRule.chi.push(r);
218+ // }
207219 }
208220 }
209221 // @ts -ignore
@@ -230,21 +242,23 @@ function replaceCompound(input, replace) {
230242 if ( replacement == null ) {
231243 replacement = parseString ( replace ) ;
232244 }
233- if ( tokens [ 1 ] . typ == EnumToken . IdenTokenType ) {
234- t . value . val = replacement . length == 1 || ( ! replace . includes ( ' ' ) && replace . charAt ( 0 ) . match ( / [: .] / ) ) ? tokens [ 1 ] . val + replace : replaceCompoundLiteral ( tokens [ 1 ] . val + '&' , replace ) ;
235- tokens . splice ( 1 , 1 ) ;
236- }
237- else {
238- t . value . val = replaceCompoundLiteral ( t . value . val , replace ) ;
239- }
245+ // if (tokens[1].typ == EnumToken.IdenTokenType) {
246+ //
247+ //
248+ // (t.value as LiteralToken).val = (replacement as Token[]).length == 1 || (!replace.includes(' ') && replace.charAt(0).match(/[:.]/)) ? (tokens[1] as IdentToken).val + replace : replaceCompoundLiteral((tokens[1] as IdentToken).val + '&', replace);
249+ // tokens.splice(1, 1);
250+ // } else {
251+ t . value . val = replaceCompoundLiteral ( t . value . val , replace ) ;
252+ // }
240253 continue ;
241254 }
242255 const rule = splitRule ( replace ) ;
243256 t . value . val = rule . length > 1 ? ':is(' + replace + ')' : replace ;
244257 }
245- else if ( t . value . val . length > 1 && t . value . val . charAt ( 0 ) == '&' ) {
246- t . value . val = replaceCompoundLiteral ( t . value . val , replace ) ;
247- }
258+ // else if ((t.value as LiteralToken).val.length > 1 && (t.value as LiteralToken).val.charAt(0) == '&') {
259+ //
260+ // (t.value as LiteralToken).val = replaceCompoundLiteral((t.value as LiteralToken).val, replace);
261+ // }
248262 }
249263 }
250264 return tokens . reduce ( ( acc , curr ) => acc + renderToken ( curr ) , '' ) ;
@@ -257,19 +271,21 @@ function replaceCompoundLiteral(selector, replace) {
257271 tokens . push ( '&' ) ;
258272 tokens . push ( '' ) ;
259273 }
260- else {
261- tokens [ tokens . length - 1 ] += selector . charAt ( i ) ;
262- }
274+ // else {
275+ //
276+ // tokens[tokens.length - 1] += selector.charAt(i);
277+ // }
263278 }
264279 return tokens . sort ( ( a , b ) => {
265280 if ( a == '&' ) {
266281 return 1 ;
267282 }
268283 return b == '&' ? - 1 : 0 ;
269284 } ) . reduce ( ( acc , curr ) => {
270- if ( acc . length > 0 && curr == '&' && ( replace . charAt ( 0 ) != '.' || replace . includes ( ' ' ) ) ) {
271- return acc + ':is(' + replace + ')' ;
272- }
285+ // if (acc.length > 0 && curr == '&' && (replace.charAt(0) != '.' || replace.includes(' '))) {
286+ //
287+ // return acc + ':is(' + replace + ')';
288+ // }
273289 return acc + ( curr == '&' ? replace : curr ) ;
274290 } , '' ) ;
275291}
0 commit comments