Skip to content

Commit

Permalink
Before new
Browse files Browse the repository at this point in the history
  • Loading branch information
thewebartisan7 committed Oct 18, 2022
1 parent 8321415 commit 4dc77d7
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const fs = require('fs');
const path = require('path');
const {inspect} = require('util');
const {sha256} = require('js-sha256');
const styleToObject = require('style-to-object');
const expressions = require('posthtml-expressions');
Expand All @@ -13,15 +12,6 @@ const parseAttrs = require('posthtml-attrs-parser');
const {match} = require('posthtml/lib/api');
const merge = require('deepmerge');
const findPathFromTagName = require('./find-path');
// const posthtml = require('posthtml');

const debug = true;

const log = (object, what) => {
if (debug) {
console.log(what, inspect(object, false, null, true));
}
};

const defaultSlotType = 'replace';

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

const defaultSlotName = sha256(filePath);
const slotsLocals = parseSlotsLocals(options.fillTagName, html, node.content, defaultSlotName);

const {attributes, locals} = parseLocals(options, slotsLocals, node, html);

options.expressions.locals = attributes;
Expand Down Expand Up @@ -298,14 +289,14 @@ function parseAttributes(node, attributes, locals, options) {
* Merge slots content
* @param {Object} tree
* @param {Object} node
* @param {Boolean} strict
* @param {Boolean} strictNames
* @param {String} slotTagName
* @param {String} fillTagName
* @param {Boolean|String} fallbackSlotTagName
* @param defaultSlotName
* @return {Object} tree
*/
function mergeSlots(tree, node, {strict, slotTagName, fillTagName, fallbackSlotTagName}, defaultSlotName) {
function mergeSlots(tree, node, {strictNames, slotTagName, fillTagName, fallbackSlotTagName}, defaultSlotName) {
const slots = getSlots(slotTagName, tree, defaultSlotName, fallbackSlotTagName); // Slot in component.html
const fillSlots = getSlots(fillTagName, node.content, defaultSlotName); // Slot in page.html
const clean = content => content.replace(/(\n|\t)/g, '').trim();
Expand Down Expand Up @@ -365,7 +356,7 @@ function mergeSlots(tree, node, {strict, slotTagName, fillTagName, fallbackSlotT
delete fillSlots[slotName];
}

if (strict) {
if (strictNames) {
const unexpectedSlots = [];

for (const fillSlotName of Object.keys(fillSlots)) {
Expand Down Expand Up @@ -458,12 +449,6 @@ function applyPluginsToTree(tree, plugins) {
}, tree);
}

// function processWithPostHtml(html, options = {}, plugins = []) {
// return posthtml(plugins)
// .process(html, options)
// .then(result => result.tree);
// }

module.exports = (options = {}) => {
options = {
...{
Expand All @@ -489,6 +474,7 @@ module.exports = (options = {}) => {
scriptLocalAttribute: 'props',
matcher: [],
strict: true,
strictNames: false,
attrsParserRules: {}
},
...options
Expand Down Expand Up @@ -552,8 +538,6 @@ module.exports = (options = {}) => {

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

log(debug, 'Debug enabled?');

return function (tree) {
tree = processNodes(tree, options, tree.messages);

Expand Down

0 comments on commit 4dc77d7

Please sign in to comment.