Skip to content

Commit 4dc77d7

Browse files
Before new
1 parent 8321415 commit 4dc77d7

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

src/index.js

+5-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const fs = require('fs');
44
const path = require('path');
5-
const {inspect} = require('util');
65
const {sha256} = require('js-sha256');
76
const styleToObject = require('style-to-object');
87
const expressions = require('posthtml-expressions');
@@ -13,15 +12,6 @@ const parseAttrs = require('posthtml-attrs-parser');
1312
const {match} = require('posthtml/lib/api');
1413
const merge = require('deepmerge');
1514
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-
};
2515

2616
const defaultSlotType = 'replace';
2717

@@ -66,6 +56,7 @@ function processNodes(tree, options, messages) {
6656

6757
const defaultSlotName = sha256(filePath);
6858
const slotsLocals = parseSlotsLocals(options.fillTagName, html, node.content, defaultSlotName);
59+
6960
const {attributes, locals} = parseLocals(options, slotsLocals, node, html);
7061

7162
options.expressions.locals = attributes;
@@ -298,14 +289,14 @@ function parseAttributes(node, attributes, locals, options) {
298289
* Merge slots content
299290
* @param {Object} tree
300291
* @param {Object} node
301-
* @param {Boolean} strict
292+
* @param {Boolean} strictNames
302293
* @param {String} slotTagName
303294
* @param {String} fillTagName
304295
* @param {Boolean|String} fallbackSlotTagName
305296
* @param defaultSlotName
306297
* @return {Object} tree
307298
*/
308-
function mergeSlots(tree, node, {strict, slotTagName, fillTagName, fallbackSlotTagName}, defaultSlotName) {
299+
function mergeSlots(tree, node, {strictNames, slotTagName, fillTagName, fallbackSlotTagName}, defaultSlotName) {
309300
const slots = getSlots(slotTagName, tree, defaultSlotName, fallbackSlotTagName); // Slot in component.html
310301
const fillSlots = getSlots(fillTagName, node.content, defaultSlotName); // Slot in page.html
311302
const clean = content => content.replace(/(\n|\t)/g, '').trim();
@@ -365,7 +356,7 @@ function mergeSlots(tree, node, {strict, slotTagName, fillTagName, fallbackSlotT
365356
delete fillSlots[slotName];
366357
}
367358

368-
if (strict) {
359+
if (strictNames) {
369360
const unexpectedSlots = [];
370361

371362
for (const fillSlotName of Object.keys(fillSlots)) {
@@ -458,12 +449,6 @@ function applyPluginsToTree(tree, plugins) {
458449
}, tree);
459450
}
460451

461-
// function processWithPostHtml(html, options = {}, plugins = []) {
462-
// return posthtml(plugins)
463-
// .process(html, options)
464-
// .then(result => result.tree);
465-
// }
466-
467452
module.exports = (options = {}) => {
468453
options = {
469454
...{
@@ -489,6 +474,7 @@ module.exports = (options = {}) => {
489474
scriptLocalAttribute: 'props',
490475
matcher: [],
491476
strict: true,
477+
strictNames: false,
492478
attrsParserRules: {}
493479
},
494480
...options
@@ -552,8 +538,6 @@ module.exports = (options = {}) => {
552538

553539
// options.locals.$isUndefined = value => value === void 0
554540

555-
log(debug, 'Debug enabled?');
556-
557541
return function (tree) {
558542
tree = processNodes(tree, options, tree.messages);
559543

0 commit comments

Comments
 (0)