This commit is contained in:
synth-ruiner
2017-12-22 17:22:08 +00:00
commit 495f1d958e
3484 changed files with 393731 additions and 0 deletions

34
node_modules/pug-filters/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,34 @@
# Change log
## 1.2.4 / 2016-08-23
- Update to `pug-walk@1.0.0`
## 1.2.3 / 2016-07-18
- Fix includes using custom filters
## 1.2.2 / 2016-06-06
- Update to `jstransformer@1.0.0`
## 1.2.1 / 2016-04-27
- Apply filters to included files as well
## 1.2.0 / 2016-04-01
- Add support for specifying per-filter options
## 1.1.1 / 2015-12-23
- Update UglifyJS to 2.6.2
- Rename to Pug
## 1.1.0 / 2015-11-14
- Add support for filtered includes
## 1.0.0 / 2015-10-08
- Initial stable release

19
node_modules/pug-filters/LICENSE generated vendored Normal file
View 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.

41
node_modules/pug-filters/README.md generated vendored Normal file
View File

@@ -0,0 +1,41 @@
# pug-filters
Code for processing filters in pug templates
[![Build Status](https://img.shields.io/travis/pugjs/pug-filters/master.svg)](https://travis-ci.org/pugjs/pug-filters)
[![Dependency Status](https://img.shields.io/david/pugjs/pug-filters.svg)](https://david-dm.org/pugjs/pug-filters)
[![NPM version](https://img.shields.io/npm/v/pug-filters.svg)](https://www.npmjs.org/package/pug-filters)
## Installation
npm install pug-filters
## Usage
```
var filters = require('pug-filters');
```
### `filters.handleFilters(ast, filters)`
Renders all `Filter` nodes in a Pug AST (`ast`), using user-specified filters (`filters`) or a JSTransformer.
### `filters.runFilter(name, str[, options[, currentDirectory]])`
Invokes filter through `jstransformer`.
This is internally used in `filters.handleFilters`, and is a lower-level interface exclusively for invoking JSTransformer-based filters.
`name` represents the name of the JSTransformer.
`str` represents the string to render.
`currentDirectory` is used when attempting to `require` the transformer module.
`options` may contain the following properties:
- `minify` (boolean): whether or not to attempt minifying the result from the transformer. If minification fails, the original result is returned.
## License
MIT

4
node_modules/pug-filters/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
'use strict';
exports.runFilter = require('./lib/run-filter');
exports.handleFilters = require('./lib/handle-filters');

112
node_modules/pug-filters/lib/handle-filters.js generated vendored Normal file
View File

@@ -0,0 +1,112 @@
'use strict';
var dirname = require('path').dirname;
var constantinople = require('constantinople');
var walk = require('pug-walk');
var error = require('pug-error');
var runFilter = require('./run-filter');
module.exports = handleFilters;
function handleFilters(ast, filters, options, filterAliases) {
options = options || {};
walk(ast, function (node) {
var dir = node.filename ? dirname(node.filename) : null;
if (node.type === 'Filter') {
handleNestedFilters(node, filters, options, filterAliases);
var text = getBodyAsText(node);
var attrs = getAttributes(node, options);
attrs.filename = node.filename;
node.type = 'Text';
node.val = filterWithFallback(node, text, attrs);
} else if (node.type === 'RawInclude' && node.filters.length) {
var firstFilter = node.filters.shift();
var attrs = getAttributes(firstFilter, options);
var filename = attrs.filename = node.file.fullPath;
var str = node.file.str;
node.type = 'Text';
node.val = filterFileWithFallback(firstFilter, filename, str, attrs);
node.filters.forEach(function (filter) {
var attrs = getAttributes(filter, options);
attrs.filename = filename;
node.val = filterWithFallback(filter, node.val, attrs);
});
node.filters = undefined;
node.file = undefined;
}
function filterWithFallback(filter, text, attrs, funcName) {
try {
var filterName = getFilterName(filter);
if (filters && filters[filterName]) {
return filters[filterName](text, attrs);
} else {
return runFilter(filterName, text, attrs, dir, funcName);
}
} catch (ex) {
if (ex.code === 'UNKNOWN_FILTER') {
throw error(ex.code, ex.message, filter);
}
throw ex;
}
}
function filterFileWithFallback(filter, filename, text, attrs) {
var filterName = getFilterName(filter);
if (filters && filters[filterName]) {
return filters[filterName](text, attrs);
} else {
return filterWithFallback(filter, filename, attrs, 'renderFile');
}
}
}, {includeDependencies: true});
function getFilterName(filter) {
var filterName = filter.name;
if (filterAliases && filterAliases[filterName]) {
filterName = filterAliases[filterName];
if (filterAliases[filterName]) {
throw error(
'FILTER_ALISE_CHAIN',
'The filter "' + filter.name + '" is an alias for "' + filterName +
'", which is an alias for "' + filterAliases[filterName] +
'". Pug does not support chains of filter aliases.',
filter
);
}
}
return filterName;
}
return ast;
};
function handleNestedFilters(node, filters, options, filterAliases) {
if (node.block.nodes[0] && node.block.nodes[0].type === 'Filter') {
node.block.nodes[0] = handleFilters(node.block, filters, options, filterAliases).nodes[0];
}
}
function getBodyAsText(node) {
return node.block.nodes.map(
function(node){ return node.val; }
).join('');
}
function getAttributes(node, options) {
var attrs = {};
node.attrs.forEach(function (attr) {
try {
attrs[attr.name] = constantinople.toConstant(attr.val);
} catch (ex) {
if (/not constant/.test(ex.message)) {
throw error('FILTER_OPTION_NOT_CONSTANT', ex.message + ' All filters are rendered compile-time so filter options must be constants.', node);
}
throw ex;
}
});
var opts = options[node.name] || {};
Object.keys(opts).forEach(function (opt) {
if (!attrs.hasOwnProperty(opt)) {
attrs[opt] = opts[opt];
}
});
return attrs;
}

43
node_modules/pug-filters/lib/run-filter.js generated vendored Normal file
View File

@@ -0,0 +1,43 @@
'use strict';
var jstransformer = require('jstransformer');
var uglify = require('uglify-js');
var CleanCSS = require('clean-css');
var resolve = require('resolve');
module.exports = filter;
function filter(name, str, options, currentDirectory, funcName) {
funcName = funcName || 'render';
var tr;
try {
try {
tr = require(resolve.sync('jstransformer-' + name, {basedir: currentDirectory || process.cwd()}));
} catch (ex) {
tr = require('jstransformer-' + name);
}
tr = jstransformer(tr);
} catch (ex) {}
if (tr) {
// TODO: we may want to add a way for people to separately specify "locals"
var result = tr[funcName](str, options, options).body;
if (options && options.minify) {
try {
switch (tr.outputFormat) {
case 'js':
result = uglify.minify(result, {fromString: true}).code;
break;
case 'css':
result = new CleanCSS().minify(result).styles;
break;
}
} catch (ex) {
// better to fail to minify than output nothing
}
}
return result;
} else {
var err = new Error('unknown filter ":' + name + '"');
err.code = 'UNKNOWN_FILTER';
throw err;
}
}

97
node_modules/pug-filters/package.json generated vendored Normal file
View File

@@ -0,0 +1,97 @@
{
"_args": [
[
"pug-filters@^2.1.5",
"C:\\Users\\Tom\\Documents\\Development\\bitsy-image-to-room\\node_modules\\pug"
]
],
"_from": "pug-filters@>=2.1.5 <3.0.0",
"_id": "pug-filters@2.1.5",
"_inCache": true,
"_installable": true,
"_location": "/pug-filters",
"_nodeVersion": "8.4.0",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/pug-filters-2.1.5.tgz_1504711687795_0.1628949735313654"
},
"_npmUser": {
"email": "forbes@lindesay.co.uk",
"name": "forbeslindesay"
},
"_npmVersion": "5.3.0",
"_phantomChildren": {},
"_requested": {
"name": "pug-filters",
"raw": "pug-filters@^2.1.5",
"rawSpec": "^2.1.5",
"scope": null,
"spec": ">=2.1.5 <3.0.0",
"type": "range"
},
"_requiredBy": [
"/pug"
],
"_resolved": "https://registry.npmjs.org/pug-filters/-/pug-filters-2.1.5.tgz",
"_shasum": "66bf6e80d97fbef829bab0aa35eddff33fc964f3",
"_shrinkwrap": null,
"_spec": "pug-filters@^2.1.5",
"_where": "C:\\Users\\Tom\\Documents\\Development\\bitsy-image-to-room\\node_modules\\pug",
"author": {
"name": "Forbes Lindesay"
},
"bugs": {
"url": "https://github.com/pugjs/pug-filters/issues"
},
"dependencies": {
"clean-css": "^3.3.0",
"constantinople": "^3.0.1",
"jstransformer": "1.0.0",
"pug-error": "^1.3.2",
"pug-walk": "^1.1.5",
"resolve": "^1.1.6",
"uglify-js": "^2.6.1"
},
"description": "Code for processing filters in pug templates",
"devDependencies": {
"get-repo": "^1.0.0",
"jstransformer-cdata": "^1.0.0",
"jstransformer-coffee-script": "^1.0.0",
"jstransformer-less": "^2.1.0",
"jstransformer-markdown-it": "^1.0.0",
"jstransformer-stylus": "^1.0.0",
"jstransformer-uglify-js": "^1.1.1",
"pug-lexer": "^3.1.0",
"pug-load": "^2.0.9",
"pug-parser": "^4.0.0"
},
"directories": {},
"dist": {
"integrity": "sha512-xkw71KtrC4sxleKiq+cUlQzsiLn8pM5+vCgkChW2E6oNOzaqTSIBKIQ5cl4oheuDzvJYCTSYzRaVinMUrV4YLQ==",
"shasum": "66bf6e80d97fbef829bab0aa35eddff33fc964f3",
"tarball": "https://registry.npmjs.org/pug-filters/-/pug-filters-2.1.5.tgz"
},
"homepage": "https://github.com/pugjs/pug-filters#readme",
"keywords": [
"pug"
],
"license": "MIT",
"maintainers": [
{
"name": "forbeslindesay",
"email": "forbes@lindesay.co.uk"
},
{
"name": "timothygu",
"email": "timothygu99@gmail.com"
}
],
"name": "pug-filters",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/pugjs/pug-filters.git"
},
"version": "2.1.5"
}

View File

@@ -0,0 +1,275 @@
exports[`test filters can be aliased 1`] = `
Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 0,
"nodes": Array [
Object {
"attributeBlocks": Array [],
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 2,
"nodes": Array [
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"nodes": Array [
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"nodes": Array [
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 4,
"type": "Text",
"val": "function myFunc(foo) {",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 5,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 5,
"type": "Text",
"val": " return foo;",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 6,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 6,
"type": "Text",
"val": "}",
},
],
"type": "Block",
},
"column": 9,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"name": "minify",
"type": "Text",
"val": "function myFunc(n){return n}",
},
],
"type": "Block",
},
"column": 3,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"name": "cdata",
"type": "Text",
"val": "<![CDATA[function myFunc(n){return n}]]>",
},
],
"type": "Block",
},
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"isInline": false,
"line": 2,
"name": "script",
"selfClosing": false,
"type": "Tag",
},
],
"type": "Block",
}
`;
exports[`test options are applied before aliases 1`] = `
Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 0,
"nodes": Array [
Object {
"attributeBlocks": Array [],
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 2,
"nodes": Array [
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"nodes": Array [
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"nodes": Array [
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 4,
"type": "Text",
"val": "function myFunc(foo) {",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 5,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 5,
"type": "Text",
"val": " return foo;",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 6,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 6,
"type": "Text",
"val": "}",
},
],
"type": "Block",
},
"column": 9,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"name": "minify",
"type": "Text",
"val": "function myFunc(n) {
return n;
}",
},
],
"type": "Block",
},
"column": 3,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 3,
"name": "cdata",
"type": "Text",
"val": "<![CDATA[function myFunc(n) {
return n;
}]]>",
},
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 7,
"nodes": Array [
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 7,
"nodes": Array [
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 8,
"type": "Text",
"val": "function myFunc(foo) {",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 9,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 9,
"type": "Text",
"val": " return foo;",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 10,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 10,
"type": "Text",
"val": "}",
},
],
"type": "Block",
},
"column": 9,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 7,
"name": "uglify-js",
"type": "Text",
"val": "function myFunc(n){return n}",
},
],
"type": "Block",
},
"column": 3,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"line": 7,
"name": "cdata",
"type": "Text",
"val": "<![CDATA[function myFunc(n){return n}]]>",
},
],
"type": "Block",
},
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/filter-aliases.test.js",
"isInline": false,
"line": 2,
"name": "script",
"selfClosing": false,
"type": "Tag",
},
],
"type": "Block",
}
`;
exports[`test we do not support chains of aliases 1`] = `
Object {
"code": "PUG:FILTER_ALISE_CHAIN",
"message": "<basedir>/packages/pug-filters/test/filter-aliases.test.js:3:9
The filter \"minify-js\" is an alias for \"minify\", which is an alias for \"uglify-js\". Pug does not support chains of filter aliases.",
}
`;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,100 @@
exports[`test per filter options are applied, even to nested filters 1`] = `
Object {
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 0,
"nodes": Array [
Object {
"attributeBlocks": Array [],
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 2,
"nodes": Array [
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 3,
"nodes": Array [
Object {
"attrs": Array [],
"block": Object {
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 3,
"nodes": Array [
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 4,
"type": "Text",
"val": "function myFunc(foo) {",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 5,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 5,
"type": "Text",
"val": " return foo;",
},
Object {
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 6,
"type": "Text",
"val": "
",
},
Object {
"column": 5,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 6,
"type": "Text",
"val": "}",
},
],
"type": "Block",
},
"column": 9,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 3,
"name": "uglify-js",
"type": "Text",
"val": "function myFunc(n) {
return n;
}",
},
],
"type": "Block",
},
"column": 3,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"line": 3,
"name": "cdata",
"type": "Text",
"val": "<![CDATA[function myFunc(n) {
return n;
}]]>",
},
],
"type": "Block",
},
"column": 1,
"filename": "<basedir>/packages/pug-filters/test/per-filter-options-applied-to-nested-filters.test.js",
"isInline": false,
"line": 2,
"name": "script",
"selfClosing": false,
"type": "Tag",
},
],
"type": "Block",
}
`;

View File

@@ -0,0 +1,84 @@
{
"type": "Block",
"nodes": [
{
"type": "Code",
"val": "var users = [{ name: 'tobi', age: 2 }]",
"buffer": false,
"mustEscape": false,
"isInline": false,
"line": 1,
"filename": "filters-empty.tokens.json"
},
{
"type": "Tag",
"name": "fb:users",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Each",
"obj": "users",
"val": "user",
"key": null,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "fb:user",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "cdata",
"block": {
"type": "Block",
"nodes": [],
"line": 6,
"filename": "filters-empty.tokens.json"
},
"attrs": [],
"line": 6,
"filename": "filters-empty.tokens.json"
}
],
"line": 5,
"filename": "filters-empty.tokens.json"
},
"attrs": [
{
"name": "age",
"val": "user.age",
"mustEscape": true
}
],
"attributeBlocks": [],
"isInline": false,
"line": 5,
"filename": "filters-empty.tokens.json"
}
],
"line": 5,
"filename": "filters-empty.tokens.json"
},
"line": 4,
"filename": "filters-empty.tokens.json"
}
],
"line": 3,
"filename": "filters-empty.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 3,
"filename": "filters-empty.tokens.json"
}
],
"line": 0,
"filename": "filters-empty.tokens.json"
}

View File

@@ -0,0 +1,83 @@
{
"type": "Block",
"nodes": [
{
"type": "Code",
"val": "users = [{ name: 'tobi', age: 2 }]",
"buffer": false,
"mustEscape": false,
"isInline": false,
"line": 2,
"filename": "filters.cdata.tokens.json"
},
{
"type": "Tag",
"name": "fb:users",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Each",
"obj": "users",
"val": "user",
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "fb:user",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "cdata",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "#{user.name}",
"line": 8
}
]
},
"attrs": [],
"line": 7,
"filename": "filters.cdata.tokens.json"
}
]
},
"attrs": [
{
"name": "age",
"val": "user.age",
"mustEscape": true
}
],
"attributeBlocks": [],
"isInline": false,
"line": 6,
"filename": "filters.cdata.tokens.json"
}
],
"line": 6,
"filename": "filters.cdata.tokens.json"
},
"line": 5,
"filename": "filters.cdata.tokens.json"
}
]
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 4,
"filename": "filters.cdata.tokens.json"
}
],
"line": 0,
"filename": "filters.cdata.tokens.json"
}

View File

@@ -0,0 +1,84 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "script",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "coffee-script",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "regexp = /\\n/",
"line": 3
}
],
"line": 2,
"filename": "filters.coffeescript.tokens.json"
},
"attrs": [],
"line": 2,
"filename": "filters.coffeescript.tokens.json"
},
{
"type": "Filter",
"name": "coffee-script",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "math =",
"line": 5
},
{
"type": "Text",
"val": "\n",
"line": 6
},
{
"type": "Text",
"val": " square: (value) -> value * value",
"line": 6
}
],
"line": 4,
"filename": "filters.coffeescript.tokens.json"
},
"attrs": [
{
"name": "minify",
"val": "true",
"mustEscape": true
}
],
"line": 4,
"filename": "filters.coffeescript.tokens.json"
}
],
"line": 1,
"filename": "filters.coffeescript.tokens.json"
},
"attrs": [
{
"name": "type",
"val": "'text/javascript'",
"mustEscape": true
}
],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.coffeescript.tokens.json"
}
],
"line": 0,
"filename": "filters.coffeescript.tokens.json"
}

View File

@@ -0,0 +1,101 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "html",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "body",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "custom",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "Line 1",
"line": 4
},
{
"type": "Text",
"val": "\n",
"line": 5
},
{
"type": "Text",
"val": "Line 2",
"line": 5
},
{
"type": "Text",
"val": "\n",
"line": 6
},
{
"type": "Text",
"val": "",
"line": 6
},
{
"type": "Text",
"val": "\n",
"line": 7
},
{
"type": "Text",
"val": "Line 4",
"line": 7
}
],
"line": 3,
"filename": "filters.custom.tokens.json"
},
"attrs": [
{
"name": "opt",
"val": "'val'",
"mustEscape": true
},
{
"name": "num",
"val": "2",
"mustEscape": true
}
],
"line": 3,
"filename": "filters.custom.tokens.json"
}
],
"line": 2,
"filename": "filters.custom.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 2,
"filename": "filters.custom.tokens.json"
}
],
"line": 1,
"filename": "filters.custom.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.custom.tokens.json"
}
],
"line": 0,
"filename": "filters.custom.tokens.json"
}

View File

@@ -0,0 +1,91 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "html",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "body",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "pre",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "RawInclude",
"file": {
"type": "FileReference",
"line": 4,
"filename": "filters.include.custom.tokens.json",
"path": "filters.include.custom.pug",
"fullPath": "test/cases/filters.include.custom.pug",
"str": "html\n body\n pre\n include:custom(opt='val' num=2) filters.include.custom.pug\n"
},
"line": 4,
"filename": "filters.include.custom.tokens.json",
"filters": [
{
"type": "IncludeFilter",
"name": "custom",
"attrs": [
{
"name": "opt",
"val": "'val'",
"mustEscape": true
},
{
"name": "num",
"val": "2",
"mustEscape": true
}
],
"line": 4,
"filename": "filters.include.custom.tokens.json"
}
]
}
],
"line": 3,
"filename": "filters.include.custom.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 3,
"filename": "filters.include.custom.tokens.json"
}
],
"line": 2,
"filename": "filters.include.custom.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 2,
"filename": "filters.include.custom.tokens.json"
}
],
"line": 1,
"filename": "filters.include.custom.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.include.custom.tokens.json"
}
],
"line": 0,
"filename": "filters.include.custom.tokens.json"
}

View File

@@ -0,0 +1,4 @@
html
body
pre
include:custom(opt='val' num=2) filters.include.custom.pug

View File

@@ -0,0 +1,153 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "html",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "body",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "RawInclude",
"file": {
"type": "FileReference",
"line": 3,
"filename": "filters.include.tokens.json",
"path": "some.md",
"fullPath": "test/cases/some.md",
"str": "Just _some_ markdown **tests**.\n\nWith new line.\n"
},
"line": 3,
"filename": "filters.include.tokens.json",
"filters": [
{
"type": "IncludeFilter",
"name": "markdown-it",
"attrs": [],
"line": 3,
"filename": "filters.include.tokens.json"
}
]
},
{
"type": "Tag",
"name": "script",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "RawInclude",
"file": {
"type": "FileReference",
"line": 5,
"filename": "filters.include.tokens.json",
"path": "include-filter-coffee.coffee",
"fullPath": "test/cases/include-filter-coffee.coffee",
"str": "math =\n square: (value) -> value * value\n"
},
"line": 5,
"filename": "filters.include.tokens.json",
"filters": [
{
"type": "IncludeFilter",
"name": "coffee-script",
"attrs": [
{
"name": "minify",
"val": "true",
"mustEscape": true
}
],
"line": 5,
"filename": "filters.include.tokens.json"
}
]
}
],
"line": 4,
"filename": "filters.include.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 4,
"filename": "filters.include.tokens.json"
},
{
"type": "Tag",
"name": "script",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "RawInclude",
"file": {
"type": "FileReference",
"line": 7,
"filename": "filters.include.tokens.json",
"path": "include-filter-coffee.coffee",
"fullPath": "test/cases/include-filter-coffee.coffee",
"str": "math =\n square: (value) -> value * value\n"
},
"line": 7,
"filename": "filters.include.tokens.json",
"filters": [
{
"type": "IncludeFilter",
"name": "coffee-script",
"attrs": [
{
"name": "minify",
"val": "false",
"mustEscape": true
}
],
"line": 7,
"filename": "filters.include.tokens.json"
}
]
}
],
"line": 6,
"filename": "filters.include.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 6,
"filename": "filters.include.tokens.json"
}
],
"line": 2,
"filename": "filters.include.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 2,
"filename": "filters.include.tokens.json"
}
],
"line": 1,
"filename": "filters.include.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.include.tokens.json"
}
],
"line": 0,
"filename": "filters.include.tokens.json"
}

View File

@@ -0,0 +1,56 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "p",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "before ",
"line": 1,
"filename": "filters.inline.tokens.json"
},
{
"type": "Filter",
"name": "cdata",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "inside",
"line": 1,
"filename": "filters.inline.tokens.json"
}
],
"line": 1,
"filename": "filters.inline.tokens.json"
},
"attrs": [],
"line": 1,
"filename": "filters.inline.tokens.json"
},
{
"type": "Text",
"val": " after",
"line": 1,
"filename": "filters.inline.tokens.json"
}
],
"line": 1,
"filename": "filters.inline.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.inline.tokens.json"
}
],
"line": 0,
"filename": "filters.inline.tokens.json"
}

View File

@@ -0,0 +1,113 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "html",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "head",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "style",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "less",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "@pad: 15px;",
"line": 5
},
{
"type": "Text",
"val": "\n",
"line": 6
},
{
"type": "Text",
"val": "body {",
"line": 6
},
{
"type": "Text",
"val": "\n",
"line": 7
},
{
"type": "Text",
"val": " padding: @pad;",
"line": 7
},
{
"type": "Text",
"val": "\n",
"line": 8
},
{
"type": "Text",
"val": "}",
"line": 8
}
],
"line": 4,
"filename": "filters.less.tokens.json"
},
"attrs": [],
"line": 4,
"filename": "filters.less.tokens.json"
}
],
"line": 3,
"filename": "filters.less.tokens.json"
},
"attrs": [
{
"name": "type",
"val": "\"text/css\"",
"mustEscape": true
}
],
"attributeBlocks": [],
"isInline": false,
"line": 3,
"filename": "filters.less.tokens.json"
}
],
"line": 2,
"filename": "filters.less.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 2,
"filename": "filters.less.tokens.json"
}
],
"line": 1,
"filename": "filters.less.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.less.tokens.json"
}
],
"line": 0,
"filename": "filters.less.tokens.json"
}

View File

@@ -0,0 +1,70 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "html",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "body",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "markdown-it",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "This is _some_ awesome **markdown**",
"line": 4
},
{
"type": "Text",
"val": "\n",
"line": 5
},
{
"type": "Text",
"val": "whoop.",
"line": 5
}
],
"line": 3,
"filename": "filters.markdown.tokens.json"
},
"attrs": [],
"line": 3,
"filename": "filters.markdown.tokens.json"
}
],
"line": 2,
"filename": "filters.markdown.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 2,
"filename": "filters.markdown.tokens.json"
}
],
"line": 1,
"filename": "filters.markdown.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.markdown.tokens.json"
}
],
"line": 0,
"filename": "filters.markdown.tokens.json"
}

View File

@@ -0,0 +1,161 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "script",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "cdata",
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "uglify-js",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "(function() {",
"line": 3
},
{
"type": "Text",
"val": "\n",
"line": 4
},
{
"type": "Text",
"val": " console.log('test')",
"line": 4
},
{
"type": "Text",
"val": "\n",
"line": 5
},
{
"type": "Text",
"val": "})()",
"line": 5
}
],
"line": 2,
"filename": "filters.nested.tokens.json"
},
"attrs": [],
"line": 2,
"filename": "filters.nested.tokens.json"
}
],
"line": 2,
"filename": "filters.nested.tokens.json"
},
"attrs": [],
"line": 2,
"filename": "filters.nested.tokens.json"
}
],
"line": 1,
"filename": "filters.nested.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.nested.tokens.json"
},
{
"type": "Tag",
"name": "script",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "cdata",
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "uglify-js",
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "coffee-script",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "(->",
"line": 8
},
{
"type": "Text",
"val": "\n",
"line": 9
},
{
"type": "Text",
"val": " console.log 'test'",
"line": 9
},
{
"type": "Text",
"val": "\n",
"line": 10
},
{
"type": "Text",
"val": ")()",
"line": 10
}
],
"line": 7,
"filename": "filters.nested.tokens.json"
},
"attrs": [],
"line": 7,
"filename": "filters.nested.tokens.json"
}
],
"line": 7,
"filename": "filters.nested.tokens.json"
},
"attrs": [],
"line": 7,
"filename": "filters.nested.tokens.json"
}
],
"line": 7,
"filename": "filters.nested.tokens.json"
},
"attrs": [],
"line": 7,
"filename": "filters.nested.tokens.json"
}
],
"line": 6,
"filename": "filters.nested.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 6,
"filename": "filters.nested.tokens.json"
}
],
"line": 0,
"filename": "filters.nested.tokens.json"
}

View File

@@ -0,0 +1,109 @@
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "html",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "head",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "style",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [
{
"type": "Filter",
"name": "stylus",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "body",
"line": 5
},
{
"type": "Text",
"val": "\n",
"line": 6
},
{
"type": "Text",
"val": " padding: 50px",
"line": 6
}
],
"line": 4,
"filename": "filters.stylus.tokens.json"
},
"attrs": [],
"line": 4,
"filename": "filters.stylus.tokens.json"
}
],
"line": 3,
"filename": "filters.stylus.tokens.json"
},
"attrs": [
{
"name": "type",
"val": "\"text/css\"",
"mustEscape": true
}
],
"attributeBlocks": [],
"isInline": false,
"line": 3,
"filename": "filters.stylus.tokens.json"
}
],
"line": 2,
"filename": "filters.stylus.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 2,
"filename": "filters.stylus.tokens.json"
},
{
"type": "Tag",
"name": "body",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [],
"line": 7,
"filename": "filters.stylus.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 7,
"filename": "filters.stylus.tokens.json"
}
],
"line": 1,
"filename": "filters.stylus.tokens.json"
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"filename": "filters.stylus.tokens.json"
}
],
"line": 0,
"filename": "filters.stylus.tokens.json"
}

View File

@@ -0,0 +1,2 @@
math =
square: (value) -> value * value

3
node_modules/pug-filters/test/cases/some.md generated vendored Normal file
View File

@@ -0,0 +1,3 @@
Just _some_ markdown **tests**.
With new line.

9
node_modules/pug-filters/test/custom-filters.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
var assert = require('assert');
module.exports = {
custom: function (str, options) {
expect(options.opt).toBe('val');
expect(options.num).toBe(2);
return 'BEGIN' + str + 'END';
}
};

View File

@@ -0,0 +1,3 @@
- var opt = 'a'
:cdata(option=opt)
hey

View File

@@ -0,0 +1,37 @@
{
"type": "Block",
"nodes": [
{
"type": "Code",
"val": "var opt = 'a'",
"buffer": false,
"escape": false,
"isInline": false,
"line": 1
},
{
"type": "Filter",
"name": "cdata",
"block": {
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "hey",
"line": 3
}
],
"line": 2
},
"attrs": [
{
"name": "option",
"val": "opt",
"escaped": true
}
],
"line": 2
}
],
"line": 0
}

89
node_modules/pug-filters/test/filter-aliases.test.js generated vendored Normal file
View File

@@ -0,0 +1,89 @@
const lex = require('pug-lexer');
const parse = require('pug-parser');
const handleFilters = require('../').handleFilters;
const customFilters = {};
test('filters can be aliased', () => {
const source = `
script
:cdata:minify
function myFunc(foo) {
return foo;
}
`;
const ast = parse(
lex(source, {filename: __filename}),
{filename: __filename, src: source}
);
const options = {};
const aliases = {
'minify': 'uglify-js',
};
const output = handleFilters(ast, customFilters, options, aliases);
expect(output).toMatchSnapshot();
});
test('we do not support chains of aliases', () => {
const source = `
script
:cdata:minify-js
function myFunc(foo) {
return foo;
}
`;
const ast = parse(
lex(source, {filename: __filename}),
{filename: __filename, src: source}
);
const options = {};
const aliases = {
'minify-js': 'minify',
'minify': 'uglify-js',
};
try {
const output = handleFilters(ast, customFilters, options, aliases);
} catch (ex) {
expect({
code: ex.code,
message: ex.message,
}).toMatchSnapshot();
return;
}
throw new Error('Expected an exception');
});
test('options are applied before aliases', () => {
const source = `
script
:cdata:minify
function myFunc(foo) {
return foo;
}
:cdata:uglify-js
function myFunc(foo) {
return foo;
}
`;
const ast = parse(
lex(source, {filename: __filename}),
{filename: __filename, src: source}
);
const options = {
'minify': {output: {beautify: true}},
};
const aliases = {
'minify': 'uglify-js',
};
const output = handleFilters(ast, customFilters, options, aliases);
expect(output).toMatchSnapshot();
});

51
node_modules/pug-filters/test/index.test.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
'use strict';
var fs = require('fs');
var assert = require('assert');
var handleFilters = require('../').handleFilters;
var customFilters = require('./custom-filters.js');
process.chdir(__dirname + '/../');
var testCases;
testCases = fs.readdirSync(__dirname + '/cases').filter(function (name) {
return /\.input\.json$/.test(name);
});
//
testCases.forEach(function (filename) {
function read (path) {
return fs.readFileSync(__dirname + '/cases/' + path, 'utf8');
}
test('cases/' + filename, function () {
var actualAst = JSON.stringify(handleFilters(JSON.parse(read(filename)), customFilters), null, ' ');
expect(actualAst).toMatchSnapshot();
})
});
testCases = fs.readdirSync(__dirname + '/errors').filter(function (name) {
return /\.input\.json$/.test(name);
});
testCases.forEach(function (filename) {
function read (path) {
return fs.readFileSync(__dirname + '/errors/' + path, 'utf8');
}
test('errors/' + filename, function () {
var actual;
try {
handleFilters(JSON.parse(read(filename)), customFilters);
throw new Error('Expected ' + filename + ' to throw an exception.');
} catch (ex) {
if (!ex || !ex.code || !ex.code.indexOf('PUG:') === 0) throw ex;
actual = {
msg: ex.msg,
code: ex.code,
line: ex.line
};
}
expect(actual).toMatchSnapshot();
})
});

View File

@@ -0,0 +1,28 @@
const lex = require('pug-lexer');
const parse = require('pug-parser');
const handleFilters = require('../').handleFilters;
const customFilters = {};
test('per filter options are applied, even to nested filters', () => {
const source = `
script
:cdata:uglify-js
function myFunc(foo) {
return foo;
}
`;
const ast = parse(
lex(source, {filename: __filename}),
{filename: __filename, src: source}
);
const options = {
'uglify-js': {output: {beautify: true}},
};
const output = handleFilters(ast, customFilters, options);
expect(output).toMatchSnapshot();
// TODO: render with `options.filterOptions['uglify-js']`
});

131
node_modules/pug-filters/test/update-test-cases.js generated vendored Normal file
View File

@@ -0,0 +1,131 @@
'use strict';
var fs = require('fs');
var assert = require('assert');
var getRepo = require('get-repo');
var lex = require('pug-lexer');
var load = require('pug-load');
var parse = require('pug-parser');
var handleFilters = require('../').handleFilters;
var customFilters = require('./custom-filters.js');
var existing = fs.readdirSync(__dirname + '/cases').filter(function (name) {
return /\.input\.json$/.test(name);
});
function getError (input, filename) {
try {
handleFilters(input, customFilters);
throw new Error('Expected ' + filename + ' to throw an exception.');
} catch (ex) {
if (!ex || !ex.code || !ex.code.indexOf('PUG:') === 0) throw ex;
return {
msg: ex.msg,
code: ex.code,
line: ex.line
};
}
}
getRepo('pugjs', 'pug-parser').on('data', function (entry) {
var match;
if (entry.type === 'File' && (match = /^\/test\/cases\/(filters.*)\.expected\.json$/.exec(entry.path))) {
var name = match[1];
var filename = name + '.input.json';
var alreadyExists = false;
existing = existing.filter(function (existingName) {
if (existingName === filename) {
alreadyExists = true;
return false;
}
return true;
});
if (alreadyExists) {
var actualInputAst = getLoadedAst(entry.body.toString('utf8'));
try {
var expectedInputAst = JSON.parse(fs.readFileSync(__dirname + '/cases/' + filename, 'utf8'));
assert.deepEqual(expectedInputAst, actualInputAst);
} catch (ex) {
console.log('update: ' + filename);
fs.writeFileSync(__dirname + '/cases/' + filename, JSON.stringify(actualInputAst, null, ' '));
}
var actualAstStr = JSON.stringify(handleFilters(actualInputAst, customFilters), null, ' ');
try {
var expectedAstStr = fs.readFileSync(__dirname + '/cases/' + name + '.expected.json', 'utf8');
assert.equal(actualAstStr, expectedAstStr);
} catch (ex) {
console.log('update: ' + name + '.expected.json');
fs.writeFileSync(__dirname + '/cases/' + name + '.expected.json', actualAstStr);
}
} else {
console.log('create: ' + filename);
var inputAst = getLoadedAst(entry.body.toString('utf8'));
fs.writeFileSync(__dirname + '/cases/' + filename, JSON.stringify(inputAst, null, ' '));
console.log('create: ' + name + '.expected.json');
var ast = handleFilters(inputAst, customFilters);
fs.writeFileSync(__dirname + '/cases/' + name + '.expected.json', JSON.stringify(ast, null, ' '));
}
}
}).on('end', function () {
existing.forEach(function (file) {
fs.unlinkSync(__dirname + '/cases/' + file);
});
var existingErrors = fs.readdirSync(__dirname + '/errors').filter(function (name) {
return /\.input\.json$/.test(name);
});
var pugRe = /\.pug$/;
fs.readdirSync(__dirname + '/errors-src').forEach(function (name) {
if (!pugRe.test(name)) return;
name = name.replace(pugRe, '');
var filename = name + '.input.json';
var alreadyExists = false;
existingErrors = existingErrors.filter(function (existingName) {
if (existingName === filename) {
alreadyExists = true;
return false;
}
return true;
});
if (alreadyExists) {
var actualTokens = parse(lex(fs.readFileSync(__dirname + '/errors-src/' + name + '.pug', 'utf8')));
try {
var expectedTokens = JSON.parse(fs.readFileSync(__dirname + '/errors/' + filename, 'utf8'));
assert.deepEqual(actualTokens, expectedTokens);
} catch (ex) {
console.log('update: ' + filename);
fs.writeFileSync(__dirname + '/errors/' + filename, JSON.stringify(actualTokens, null, ' '));
}
var actual = getError(actualTokens, filename);
try {
var expected = JSON.parse(fs.readFileSync(__dirname + '/errors/' + name + '.expected.json', 'utf8'));
assert.deepEqual(actual, expected);
} catch (ex) {
console.log('update: ' + name + '.expected.json');
fs.writeFileSync(__dirname + '/errors/' + name + '.expected.json', JSON.stringify(actual, null, ' '));
}
} else {
console.log('create: ' + filename);
var ast = parse(lex(fs.readFileSync(__dirname + '/errors-src/' + name + '.pug', 'utf8')));
fs.writeFileSync(__dirname + '/errors/' + filename, JSON.stringify(ast, null, 2));
console.log('create: ' + name + '.expected.json');
var actual = getError(ast, filename);
fs.writeFileSync(__dirname + '/errors/' + name + '.expected.json', JSON.stringify(actual, null, ' '));
}
});
console.log('test cases updated');
});
function getLoadedAst(str) {
return load(JSON.parse(str), {
lex: function () {
throw new Error('The lexer should not be used');
},
parse: function () {
throw new Error('The parser should not be used');
},
resolve: function (filename, source, options) {
return 'test/cases/' + filename.trim();
}
});
}