@@ -42,21 +42,17 @@ module.exports = (options = {}) => tree => {
42
42
options . plugins = options . plugins || [ ] ;
43
43
options . strict = typeof options . strict === 'undefined' ? true : options . strict ;
44
44
options . attrsParserRules = options . attrsParserRules || { } ;
45
-
46
45
options . slot = new RegExp ( `^${ options . slot } :` , 'i' ) ;
47
46
options . fill = new RegExp ( `^${ options . fill } :` , 'i' ) ;
48
47
options . tagPrefix = new RegExp ( `^${ options . tagPrefix } ` , 'i' ) ;
49
48
options . matcher = options . matcher || [ { tag : options . tag } , { tag : options . tagPrefix } ] ;
50
-
51
49
options . roots = Array . isArray ( options . roots ) ? options . roots : [ options . roots ] ;
52
50
options . roots . forEach ( ( root , index ) => {
53
51
options . roots [ index ] = path . join ( options . root , root ) ;
54
52
} ) ;
55
-
56
53
options . namespaces = Array . isArray ( options . namespaces ) ? options . namespaces : [ options . namespaces ] ;
57
54
options . namespaces . forEach ( ( namespace , index ) => {
58
55
options . namespaces [ index ] . root = path . resolve ( namespace . root ) ;
59
-
60
56
if ( namespace . fallback ) {
61
57
options . namespaces [ index ] . fallback = path . resolve ( namespace . fallback ) ;
62
58
}
@@ -69,11 +65,7 @@ module.exports = (options = {}) => tree => {
69
65
options . locals = { ...options . expressions . locals } ;
70
66
options . aware = { } ;
71
67
72
- log ( options , 'options' , 'init' ) ;
73
-
74
- // Apply expressions to initial tree
75
68
tree = expressions ( options . expressions ) ( tree ) ;
76
-
77
69
tree = processTree ( options ) ( tree ) ;
78
70
79
71
return tree ;
@@ -111,11 +103,9 @@ function processTree(options) {
111
103
return currentNode ;
112
104
}
113
105
114
- // Process <stack > tag
106
+ // Process <push > tag
115
107
processPushes ( currentNode , pushedContent , options ) ;
116
108
117
- // log(componentNode, 'componentNode');
118
-
119
109
log ( `${ ++ processCounter } ${ componentPath } ` , 'Processing component' , 'processTree' ) ;
120
110
121
111
let nextNode = parser ( readFileSync ( componentPath , 'utf8' ) ) ;
@@ -129,17 +119,11 @@ function processTree(options) {
129
119
const { attributes, locals} = processLocals ( currentNode , nextNode , slotContent , options ) ;
130
120
131
121
options . expressions . locals = attributes ;
132
-
133
122
options . expressions . locals . $slots = slotContent ;
134
-
135
123
// const plugins = [...options.plugins, expressions(options.expressions)];
136
-
137
- log ( { attributes, locals, slotContent} , 'Processed attributes, locals and slots' , 'processTree' ) ;
138
-
139
124
nextNode = expressions ( options . expressions ) ( nextNode ) ;
140
- // process.exit(0);
141
125
142
- // Process <stack > tag
126
+ // Process <push > tag
143
127
processPushes ( nextNode , pushedContent , options ) ;
144
128
145
129
// Process <stack> tag
@@ -192,8 +176,6 @@ function setFilledSlots(currentNode, slots, {slot}) {
192
176
193
177
const name = fillNode . tag . split ( ':' ) [ 1 ] ;
194
178
195
- log ( name , 'found filled slot' , 'setFilledSlots' ) ;
196
-
197
179
/** @var {Object} locals */
198
180
const locals = Object . fromEntries ( Object . entries ( fillNode . attrs ) . filter ( ( [ attributeName ] ) => ! [ name , 'type' ] . includes ( attributeName ) ) ) ;
199
181
@@ -217,8 +199,6 @@ function setFilledSlots(currentNode, slots, {slot}) {
217
199
218
200
return fillNode ;
219
201
} ) ;
220
-
221
- log ( slots , 'all filled slots found' , 'setFilledSlots' ) ;
222
202
}
223
203
224
204
/**
@@ -242,7 +222,7 @@ function processPushes(tree, content, {push}) {
242
222
const pushContent = render ( pushNode . content ) ;
243
223
244
224
if ( typeof pushNode . attrs . once === 'undefined' || ! content [ pushNode . attrs . name ] . includes ( pushContent ) ) {
245
- if ( typeof pushNode . attrs . prepend === 'undefined' ) {
225
+ if ( typeof pushNode . attrs . prepend === 'undefined' ) {
246
226
content [ pushNode . attrs . name ] . push ( pushContent ) ;
247
227
} else {
248
228
content [ pushNode . attrs . name ] . unshift ( pushContent ) ;
@@ -254,8 +234,6 @@ function processPushes(tree, content, {push}) {
254
234
255
235
return pushNode ;
256
236
} ) ;
257
-
258
- log ( Object . keys ( content ) , 'Found pushes' , 'processPushes' ) ;
259
237
}
260
238
261
239
/**
@@ -267,8 +245,6 @@ function processPushes(tree, content, {push}) {
267
245
* @return {void }
268
246
*/
269
247
function processStacks ( tree , content , { stack} ) {
270
- log ( Object . keys ( content ) , 'Process stacks for this push' , 'processStacks' ) ;
271
-
272
248
match . call ( tree , { tag : stack } , stackNode => {
273
249
stackNode . tag = false ;
274
250
stackNode . content = content [ stackNode . attrs . name ] ;
@@ -292,8 +268,6 @@ function processSlotContent(tree, content, {slot}) {
292
268
content [ name ] = { } ;
293
269
}
294
270
295
- log ( name , 'processing slot' , 'processSlotContent' ) ;
296
-
297
271
content [ name ] . tag = slotNode . tag ;
298
272
content [ name ] . attrs = slotNode . attrs ;
299
273
content [ name ] . content = slotNode . content ;
@@ -305,8 +279,6 @@ function processSlotContent(tree, content, {slot}) {
305
279
306
280
return slotNode ;
307
281
} ) ;
308
-
309
- log ( content , 'Slots processed' , 'processSlotContent' ) ;
310
282
}
311
283
312
284
/**
@@ -321,8 +293,6 @@ function processFillContent(tree, content, {fill}) {
321
293
match . call ( tree , { tag : fill } , fillNode => {
322
294
const name = fillNode . tag . split ( ':' ) [ 1 ] ;
323
295
324
- log ( name , 'Processing fill' , 'processFillContent' ) ;
325
-
326
296
fillNode . tag = false ;
327
297
328
298
if ( content [ name ] ?. rendered ) {
@@ -341,8 +311,6 @@ function processFillContent(tree, content, {fill}) {
341
311
342
312
return fillNode ;
343
313
} ) ;
344
-
345
- log ( content , 'Processed fill' , 'processFillContent' ) ;
346
314
}
347
315
348
316
/**
@@ -360,6 +328,7 @@ function processLocals(currentNode, nextNode, slotContent, options) {
360
328
const merged = [ ] ;
361
329
const computed = [ ] ;
362
330
const aware = [ ] ;
331
+
363
332
Object . keys ( attributes ) . forEach ( attributeName => {
364
333
const newAttributeName = attributeName
365
334
. replace ( 'merge:' , '' )
@@ -368,22 +337,18 @@ function processLocals(currentNode, nextNode, slotContent, options) {
368
337
369
338
switch ( true ) {
370
339
case attributeName . startsWith ( 'merge:' ) :
371
- log ( attributeName , 'merge' , 'processLocals' ) ;
372
340
attributes [ newAttributeName ] = attributes [ attributeName ] ;
373
341
delete attributes [ attributeName ] ;
374
342
merged . push ( newAttributeName ) ;
375
-
376
343
break ;
377
344
378
345
case attributeName . startsWith ( 'computed:' ) :
379
- log ( attributeName , 'computed' , 'processLocals' ) ;
380
346
attributes [ newAttributeName ] = attributes [ attributeName ] ;
381
347
delete attributes [ attributeName ] ;
382
348
computed . push ( newAttributeName ) ;
383
349
break ;
384
350
385
351
case attributeName . startsWith ( 'aware:' ) :
386
- log ( attributeName , 'aware' , 'processLocals' ) ;
387
352
attributes [ newAttributeName ] = attributes [ attributeName ] ;
388
353
delete attributes [ attributeName ] ;
389
354
aware . push ( newAttributeName ) ;
@@ -419,8 +384,6 @@ function processLocals(currentNode, nextNode, slotContent, options) {
419
384
// Retrieve default locals from <script props> and merge with attributes
420
385
const { locals} = scriptDataLocals ( nextNode , { localsAttr : options . localsAttr , removeScriptLocals : true , locals : { ...attributes , $slots : slotContent } } ) ;
421
386
422
- log ( locals , 'locals parsed in tag ' + currentNode . tag , 'processLocals' ) ;
423
-
424
387
// Merge default locals and attributes or overrides props with attributes
425
388
if ( locals ) {
426
389
if ( merged . length > 0 ) {
@@ -448,8 +411,6 @@ function processLocals(currentNode, nextNode, slotContent, options) {
448
411
options . aware = Object . fromEntries ( Object . entries ( attributes ) . filter ( ( [ attributeName ] ) => aware . includes ( attributeName ) ) ) ;
449
412
}
450
413
451
- log ( { locals, attributes} , 'locals and attributes processed for tag ' + currentNode . tag , 'processLocals' ) ;
452
-
453
414
return { attributes, locals} ;
454
415
}
455
416
@@ -472,51 +433,34 @@ function processAttributes(currentNode, attributes, locals, options) {
472
433
473
434
const nodeAttrs = parseAttrs ( currentNode . content [ index ] . attrs , options . attrsParserRules ) ;
474
435
475
- log ( nodeAttrs , 'nodeAttrs in processAttributes' , 'processAttributes' ) ;
476
- log ( locals , 'locals in processAttributes' , 'processAttributes' ) ;
477
- log ( options . aware , 'options aware in processAttributes' , 'processAttributes' ) ;
478
-
479
436
Object . keys ( attributes ) . forEach ( attr => {
480
- log ( attr , 'processing attribute' , 'processAttributes' ) ;
481
- log ( typeof locals [ attr ] === 'undefined' , 'not in locals?' , 'processAttributes' ) ;
482
-
483
437
if ( typeof locals [ attr ] === 'undefined' && ! Object . keys ( options . aware ) . includes ( attr ) ) {
484
438
if ( [ 'class' ] . includes ( attr ) ) {
485
- // Merge class
486
439
if ( typeof nodeAttrs . class === 'undefined' ) {
487
440
nodeAttrs . class = [ ] ;
488
441
}
489
442
490
443
nodeAttrs . class . push ( attributes . class ) ;
491
-
492
444
delete attributes . class ;
493
445
} else if ( [ 'override:class' ] . includes ( attr ) ) {
494
- // Override class
495
446
nodeAttrs . class = attributes [ 'override:class' ] ;
496
-
497
447
delete attributes [ 'override:class' ] ;
498
448
} else if ( [ 'style' ] . includes ( attr ) ) {
499
- // Merge style
500
449
if ( typeof nodeAttrs . style === 'undefined' ) {
501
450
nodeAttrs . style = { } ;
502
451
}
503
452
504
453
nodeAttrs . style = Object . assign ( nodeAttrs . style , styleToObject ( attributes . style ) ) ;
505
-
506
454
delete attributes . style ;
507
455
} else if ( [ 'override:style' ] . includes ( attr ) ) {
508
- // Override style
509
456
nodeAttrs . style = attributes [ 'override:style' ] ;
510
457
delete attributes [ 'override:style' ] ;
511
458
} else if ( ! attr . startsWith ( '$' ) && attr !== options . attribute ) {
512
- // Everything that doesn't start with '$' else set as attribute name/value
513
459
nodeAttrs [ attr ] = attributes [ attr ] ;
514
460
delete attributes [ attr ] ;
515
461
}
516
462
}
517
463
} ) ;
518
464
519
465
currentNode . content [ index ] . attrs = nodeAttrs . compose ( ) ;
520
-
521
- log ( currentNode . content [ index ] . attrs , 'after processing attributes' , 'processAttributes' ) ;
522
466
}
0 commit comments