pug-linker
Advanced tools
Comparing version 1.0.2 to 2.0.0
52
index.js
@@ -63,7 +63,8 @@ 'use strict'; | ||
function findDeclaredBlocks(ast) { | ||
function findDeclaredBlocks(ast) /*: {[name: string]: Array<BlockNode>}*/ { | ||
var definitions = {}; | ||
walk(ast, function before(node) { | ||
if (node.type === 'NamedBlock' && node.mode === 'replace') { | ||
definitions[node.name] = node; | ||
definitions[node.name] = definitions[node.name] || []; | ||
definitions[node.name].push(node); | ||
} | ||
@@ -73,2 +74,15 @@ }); | ||
} | ||
function flattenParentBlocks(parentBlocks, accumulator) { | ||
accumulator = accumulator || []; | ||
parentBlocks.forEach(function (parentBlock) { | ||
if (parentBlock.parents) { | ||
flattenParentBlocks(parentBlock.parents, accumulator); | ||
} else { | ||
accumulator.push(parentBlock); | ||
} | ||
}); | ||
return accumulator; | ||
} | ||
function extend(parentBlocks, ast) { | ||
@@ -82,17 +96,18 @@ var stack = {}; | ||
stack[node.name] = node.name; | ||
var parentBlock = parentBlocks[node.name]; | ||
if (parentBlock) { | ||
if (parentBlock.parent) parentBlock = parentBlock.parent; | ||
node.parent = parentBlock; | ||
switch (node.mode) { | ||
case 'append': | ||
parentBlock.nodes = parentBlock.nodes.concat(node.nodes); | ||
break; | ||
case 'prepend': | ||
parentBlock.nodes = node.nodes.concat(parentBlock.nodes); | ||
break; | ||
case 'replace': | ||
parentBlock.nodes = node.nodes; | ||
break; | ||
} | ||
var parentBlockList = parentBlocks[node.name] ? flattenParentBlocks(parentBlocks[node.name]) : []; | ||
if (parentBlockList.length) { | ||
node.parents = parentBlockList; | ||
parentBlockList.forEach(parentBlock => { | ||
switch (node.mode) { | ||
case 'append': | ||
parentBlock.nodes = parentBlock.nodes.concat(node.nodes); | ||
break; | ||
case 'prepend': | ||
parentBlock.nodes = node.nodes.concat(parentBlock.nodes); | ||
break; | ||
case 'replace': | ||
parentBlock.nodes = node.nodes; | ||
break; | ||
} | ||
}); | ||
} | ||
@@ -106,2 +121,3 @@ } | ||
} | ||
function applyIncludes(ast, child) { | ||
@@ -118,2 +134,3 @@ return walk(ast, function before(node, replace) { | ||
} | ||
function applyYield(ast, block) { | ||
@@ -147,2 +164,3 @@ if (!block || !block.nodes.length) return ast; | ||
} | ||
function checkExtendPosition(ast, hasExtends) { | ||
@@ -149,0 +167,0 @@ var legitExtendsReached = false; |
{ | ||
"name": "pug-linker", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Link multiple pug ASTs together using include/extends", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var link = require('../'); | ||
var prettyStringify = require('./common').prettyStringify; | ||
var assertObjEqual = require('./common').assertObjEqual; | ||
@@ -7,0 +5,0 @@ function testDir (dir) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
270576
105
3969