mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-10 21:01:41 +00:00
update
This commit is contained in:
4
node_modules/pug-walk/HISTORY.md
generated
vendored
Normal file
4
node_modules/pug-walk/HISTORY.md
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
1.0.0 / 2016-08-22
|
||||
==================
|
||||
|
||||
* Initial stable release
|
19
node_modules/pug-walk/LICENSE
generated
vendored
Normal file
19
node_modules/pug-walk/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2015 Forbes Lindesay
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
138
node_modules/pug-walk/README.md
generated
vendored
Normal file
138
node_modules/pug-walk/README.md
generated
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
# pug-walk
|
||||
|
||||
Walk and transform a Pug AST
|
||||
|
||||
[](https://travis-ci.org/pugjs/pug-walk)
|
||||
[](https://david-dm.org/pugjs/pug?path=packages/pug-walk)
|
||||
[](https://david-dm.org/pugjs/pug?path=packages/pug-walk&type=dev)
|
||||
[](https://www.npmjs.org/package/pug-walk)
|
||||
[](https://codecov.io/gh/pugjs/pug-walk/branch/master)
|
||||
|
||||
## Installation
|
||||
|
||||
npm install pug-walk
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var walk = require('pug-walk');
|
||||
```
|
||||
|
||||
### `walk(ast, before, after, options)`
|
||||
|
||||
Traverse and optionally transform a [Pug AST](https://github.com/pugjs/pug-ast-spec).
|
||||
|
||||
`ast` is not cloned, so any changes done to it will be done directly on the AST provided.
|
||||
|
||||
`before` and `after` are functions with the signature `(node, replace)`. `before` is called when a node is first seen, while `after` is called after the children of the node (if any) have already been traversed.
|
||||
|
||||
The `replace` parameter is a function that can be used to replace the node in the AST. It takes either an object or an array as its only parameter. If an object is specified, the current node is replaced by the parameter in the AST. If an array is specified and the ancestor of the current node allows such an operation, the node is replaced by all of the nodes in the specified array. This way, you can remove and add new nodes adjacent to the current node. Whether the parent node allows array operation is indicated by the property `replace.arrayAllowed`, which is set to true when the parent is a Block and when the parent is a Include and the node is an IncludeFilter.
|
||||
|
||||
If `before` returns `false`, the children of this node will not be traversed and left unchanged (unless `replace` has been called). Otherwise, the returned value of `before` is ignored. The returned value of `after` is always ignored. If `replace()` is called in `before()` with an array, and `before()` does not return `false`, the nodes in the array are still descended.
|
||||
|
||||
`options` can contain the following properties:
|
||||
|
||||
* `includeDependencies` (boolean): Walk the AST of a loaded dependent file (i.e., includes and extends). Defaults to `false`.
|
||||
* `parents` (array<Node>): Nodes that are ancestors to the current `ast`. This option is used mainly internally, and users usually do not have to specify it. Defaults to `[]`.
|
||||
|
||||
```js
|
||||
var lex = require('pug-lexer');
|
||||
var parse = require('pug-parser');
|
||||
|
||||
// Changing content of all Text nodes
|
||||
// ==================================
|
||||
|
||||
var source = '.my-class foo';
|
||||
var dest = '.my-class bar';
|
||||
|
||||
var ast = parse(lex(source));
|
||||
|
||||
ast = walk(ast, function before(node, replace) {
|
||||
if (node.type === 'Text') {
|
||||
node.val = 'bar';
|
||||
|
||||
// Alternatively, you can replace the entire node
|
||||
// rather than just the text.
|
||||
// replace({ type: 'Text', val: 'bar', line: node.line });
|
||||
}
|
||||
}, {
|
||||
includeDependencies: true
|
||||
});
|
||||
|
||||
assert.deepEqual(parse(lex(dest)), ast);
|
||||
|
||||
// Convert all simple <strong> elements to text
|
||||
// ============================================
|
||||
|
||||
var source = 'p abc #[strong NO]\nstrong on its own line';
|
||||
var dest = 'p abc #[| NO]\n| on its own line';
|
||||
|
||||
var ast = parse(lex(source));
|
||||
|
||||
ast = walk(ast, function before(node, replace) {
|
||||
// Find all <strong> tags
|
||||
if (node.type === 'Tag' && node.name === 'strong') {
|
||||
var children = node.block.nodes;
|
||||
|
||||
// Make sure that the Tag only has one child -- the text
|
||||
if (children.length === 1 && children[0].type === 'Text') {
|
||||
// Replace the Tag with the Text
|
||||
replace({ type: 'Text', val: children[0].val, line: node.line });
|
||||
}
|
||||
}
|
||||
}, {
|
||||
includeDependencies: true
|
||||
});
|
||||
|
||||
assert.deepEqual(parse(lex(dest)), ast);
|
||||
|
||||
// Flatten blocks
|
||||
// ==============
|
||||
|
||||
var ast = {
|
||||
type: 'Block',
|
||||
nodes: [
|
||||
{ type: 'Text', val: 'a' },
|
||||
{
|
||||
type: 'Block',
|
||||
nodes: [
|
||||
{ type: 'Text', val: 'b' },
|
||||
{
|
||||
type: 'Block',
|
||||
nodes: [ { type: 'Text', val: 'c' } ]
|
||||
},
|
||||
{ type: 'Text', val: 'd' }
|
||||
]
|
||||
},
|
||||
{ type: 'Text', val: 'e' }
|
||||
]
|
||||
};
|
||||
|
||||
var dest = {
|
||||
type: 'Block',
|
||||
nodes: [
|
||||
{ type: 'Text', val: 'a' },
|
||||
{ type: 'Text', val: 'b' },
|
||||
{ type: 'Text', val: 'c' },
|
||||
{ type: 'Text', val: 'd' },
|
||||
{ type: 'Text', val: 'e' }
|
||||
]
|
||||
};
|
||||
|
||||
// We need to use `after` handler instead of `before`
|
||||
// handler because we want to flatten the innermost
|
||||
// blocks first before proceeding onto outer blocks.
|
||||
|
||||
ast = walk(ast, null, function after(node, replace) {
|
||||
if (node.type === 'Block' && replace.arrayAllowed) {
|
||||
// Replace the block with its contents
|
||||
replace(node.nodes);
|
||||
}
|
||||
});
|
||||
|
||||
assert.deepEqual(dest, ast);
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
112
node_modules/pug-walk/index.js
generated
vendored
Normal file
112
node_modules/pug-walk/index.js
generated
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = walkAST;
|
||||
function walkAST(ast, before, after, options) {
|
||||
if (after && typeof after === 'object' && typeof options === 'undefined') {
|
||||
options = after;
|
||||
after = null;
|
||||
}
|
||||
options = options || {includeDependencies: false};
|
||||
var parents = options.parents = options.parents || [];
|
||||
|
||||
var replace = function replace(replacement) {
|
||||
if (Array.isArray(replacement) && !replace.arrayAllowed) {
|
||||
throw new Error('replace() can only be called with an array if the last parent is a Block or NamedBlock');
|
||||
}
|
||||
ast = replacement;
|
||||
};
|
||||
replace.arrayAllowed = parents[0] && (
|
||||
/^(Named)?Block$/.test(parents[0].type) ||
|
||||
parents[0].type === 'RawInclude' && ast.type === 'IncludeFilter');
|
||||
|
||||
if (before) {
|
||||
var result = before(ast, replace);
|
||||
if (result === false) {
|
||||
return ast;
|
||||
} else if (Array.isArray(ast)) {
|
||||
// return right here to skip after() call on array
|
||||
return walkAndMergeNodes(ast);
|
||||
}
|
||||
}
|
||||
|
||||
parents.unshift(ast);
|
||||
|
||||
switch (ast.type) {
|
||||
case 'NamedBlock':
|
||||
case 'Block':
|
||||
ast.nodes = walkAndMergeNodes(ast.nodes);
|
||||
break;
|
||||
case 'Case':
|
||||
case 'Filter':
|
||||
case 'Mixin':
|
||||
case 'Tag':
|
||||
case 'InterpolatedTag':
|
||||
case 'When':
|
||||
case 'Code':
|
||||
case 'While':
|
||||
if (ast.block) {
|
||||
ast.block = walkAST(ast.block, before, after, options);
|
||||
}
|
||||
break;
|
||||
case 'Each':
|
||||
if (ast.block) {
|
||||
ast.block = walkAST(ast.block, before, after, options);
|
||||
}
|
||||
if (ast.alternate) {
|
||||
ast.alternate = walkAST(ast.alternate, before, after, options);
|
||||
}
|
||||
break;
|
||||
case 'Conditional':
|
||||
if (ast.consequent) {
|
||||
ast.consequent = walkAST(ast.consequent, before, after, options);
|
||||
}
|
||||
if (ast.alternate) {
|
||||
ast.alternate = walkAST(ast.alternate, before, after, options);
|
||||
}
|
||||
break;
|
||||
case 'Include':
|
||||
walkAST(ast.block, before, after, options);
|
||||
walkAST(ast.file, before, after, options);
|
||||
break;
|
||||
case 'Extends':
|
||||
walkAST(ast.file, before, after, options);
|
||||
break;
|
||||
case 'RawInclude':
|
||||
ast.filters = walkAndMergeNodes(ast.filters);
|
||||
walkAST(ast.file, before, after, options);
|
||||
break;
|
||||
case 'Attrs':
|
||||
case 'BlockComment':
|
||||
case 'Comment':
|
||||
case 'Doctype':
|
||||
case 'IncludeFilter':
|
||||
case 'MixinBlock':
|
||||
case 'YieldBlock':
|
||||
case 'Text':
|
||||
break;
|
||||
case 'FileReference':
|
||||
if (options.includeDependencies && ast.ast) {
|
||||
walkAST(ast.ast, before, after, options);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unexpected node type ' + ast.type);
|
||||
break;
|
||||
}
|
||||
|
||||
parents.shift();
|
||||
|
||||
after && after(ast, replace);
|
||||
return ast;
|
||||
|
||||
function walkAndMergeNodes(nodes) {
|
||||
return nodes.reduce(function (nodes, node) {
|
||||
var result = walkAST(node, before, after, options);
|
||||
if (Array.isArray(result)) {
|
||||
return nodes.concat(result);
|
||||
} else {
|
||||
return nodes.concat([result]);
|
||||
}
|
||||
}, []);
|
||||
}
|
||||
}
|
54
node_modules/pug-walk/package.json
generated
vendored
Normal file
54
node_modules/pug-walk/package.json
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"pug-walk@1.1.8",
|
||||
"/Users/tatiana/selfdefined"
|
||||
]
|
||||
],
|
||||
"_from": "pug-walk@1.1.8",
|
||||
"_id": "pug-walk@1.1.8",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-GMu3M5nUL3fju4/egXwZO0XLi6fW/K3T3VTgFQ14GxNi8btlxgT5qZL//JwZFm/2Fa64J/PNS8AZeys3wiMkVA==",
|
||||
"_location": "/pug-walk",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "pug-walk@1.1.8",
|
||||
"name": "pug-walk",
|
||||
"escapedName": "pug-walk",
|
||||
"rawSpec": "1.1.8",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.1.8"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pug-filters",
|
||||
"/pug-linker",
|
||||
"/pug-load"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pug-walk/-/pug-walk-1.1.8.tgz",
|
||||
"_spec": "1.1.8",
|
||||
"_where": "/Users/tatiana/selfdefined",
|
||||
"author": {
|
||||
"name": "ForbesLindesay"
|
||||
},
|
||||
"description": "Walk and transform a pug AST",
|
||||
"devDependencies": {
|
||||
"pug-lexer": "^4.1.0",
|
||||
"pug-parser": "^5.0.1"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"gitHead": "1bdf628a70fda7a0d840c52f3abce54b1c6b0130",
|
||||
"keywords": [
|
||||
"pug"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "pug-walk",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pugjs/pug/tree/master/packages/pug-walk"
|
||||
},
|
||||
"version": "1.1.8"
|
||||
}
|
Reference in New Issue
Block a user