2
2
3
3
const fs = require ( 'fs' ) ;
4
4
const path = require ( 'path' ) ;
5
- const { inspect} = require ( 'util' ) ;
6
5
const { sha256} = require ( 'js-sha256' ) ;
7
6
const styleToObject = require ( 'style-to-object' ) ;
8
7
const expressions = require ( 'posthtml-expressions' ) ;
@@ -13,15 +12,6 @@ const parseAttrs = require('posthtml-attrs-parser');
13
12
const { match} = require ( 'posthtml/lib/api' ) ;
14
13
const merge = require ( 'deepmerge' ) ;
15
14
const findPathFromTagName = require ( './find-path' ) ;
16
- // const posthtml = require('posthtml');
17
-
18
- const debug = true ;
19
-
20
- const log = ( object , what ) => {
21
- if ( debug ) {
22
- console . log ( what , inspect ( object , false , null , true ) ) ;
23
- }
24
- } ;
25
15
26
16
const defaultSlotType = 'replace' ;
27
17
@@ -66,6 +56,7 @@ function processNodes(tree, options, messages) {
66
56
67
57
const defaultSlotName = sha256 ( filePath ) ;
68
58
const slotsLocals = parseSlotsLocals ( options . fillTagName , html , node . content , defaultSlotName ) ;
59
+
69
60
const { attributes, locals} = parseLocals ( options , slotsLocals , node , html ) ;
70
61
71
62
options . expressions . locals = attributes ;
@@ -298,14 +289,14 @@ function parseAttributes(node, attributes, locals, options) {
298
289
* Merge slots content
299
290
* @param {Object } tree
300
291
* @param {Object } node
301
- * @param {Boolean } strict
292
+ * @param {Boolean } strictNames
302
293
* @param {String } slotTagName
303
294
* @param {String } fillTagName
304
295
* @param {Boolean|String } fallbackSlotTagName
305
296
* @param defaultSlotName
306
297
* @return {Object } tree
307
298
*/
308
- function mergeSlots ( tree , node , { strict , slotTagName, fillTagName, fallbackSlotTagName} , defaultSlotName ) {
299
+ function mergeSlots ( tree , node , { strictNames , slotTagName, fillTagName, fallbackSlotTagName} , defaultSlotName ) {
309
300
const slots = getSlots ( slotTagName , tree , defaultSlotName , fallbackSlotTagName ) ; // Slot in component.html
310
301
const fillSlots = getSlots ( fillTagName , node . content , defaultSlotName ) ; // Slot in page.html
311
302
const clean = content => content . replace ( / ( \n | \t ) / g, '' ) . trim ( ) ;
@@ -365,7 +356,7 @@ function mergeSlots(tree, node, {strict, slotTagName, fillTagName, fallbackSlotT
365
356
delete fillSlots [ slotName ] ;
366
357
}
367
358
368
- if ( strict ) {
359
+ if ( strictNames ) {
369
360
const unexpectedSlots = [ ] ;
370
361
371
362
for ( const fillSlotName of Object . keys ( fillSlots ) ) {
@@ -458,12 +449,6 @@ function applyPluginsToTree(tree, plugins) {
458
449
} , tree ) ;
459
450
}
460
451
461
- // function processWithPostHtml(html, options = {}, plugins = []) {
462
- // return posthtml(plugins)
463
- // .process(html, options)
464
- // .then(result => result.tree);
465
- // }
466
-
467
452
module . exports = ( options = { } ) => {
468
453
options = {
469
454
...{
@@ -489,6 +474,7 @@ module.exports = (options = {}) => {
489
474
scriptLocalAttribute : 'props' ,
490
475
matcher : [ ] ,
491
476
strict : true ,
477
+ strictNames : false ,
492
478
attrsParserRules : { }
493
479
} ,
494
480
...options
@@ -552,8 +538,6 @@ module.exports = (options = {}) => {
552
538
553
539
// options.locals.$isUndefined = value => value === void 0
554
540
555
- log ( debug , 'Debug enabled?' ) ;
556
-
557
541
return function ( tree ) {
558
542
tree = processNodes ( tree , options , tree . messages ) ;
559
543
0 commit comments