fix: add scoped error logging for lexer/parser errors
- Add std.log.scoped(.pugz) to template.zig and view_engine.zig - Log detailed error info (code, line, column, message) when parsing fails - Log template path context in ViewEngine on parse errors - Remove debug print from lexer, use proper scoped logging instead - Move benchmarks, docs, examples, playground, tests out of src/ to project root - Update build.zig and documentation paths accordingly - Bump version to 0.3.1
This commit is contained in:
166
tests/sample_data/pug-load/test/__snapshots__/index.test.js.snap
Normal file
166
tests/sample_data/pug-load/test/__snapshots__/index.test.js.snap
Normal file
@@ -0,0 +1,166 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`pug-load 1`] = `
|
||||
Object {
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"line": 0,
|
||||
"nodes": Array [
|
||||
Object {
|
||||
"column": 1,
|
||||
"file": Object {
|
||||
"ast": Object {
|
||||
"filename": "<dirname>/bar.pug",
|
||||
"line": 0,
|
||||
"nodes": Array [
|
||||
Object {
|
||||
"column": 1,
|
||||
"filename": "<dirname>/bar.pug",
|
||||
"line": 1,
|
||||
"mode": "replace",
|
||||
"name": "bing",
|
||||
"nodes": Array [],
|
||||
"type": "NamedBlock",
|
||||
},
|
||||
],
|
||||
"type": "Block",
|
||||
},
|
||||
"column": 9,
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"fullPath": "<dirname>/bar.pug",
|
||||
"line": 1,
|
||||
"path": "bar.pug",
|
||||
"raw": Object {
|
||||
"hash": "538bf7d4b81ef364b1f2e9d42c11f156",
|
||||
"size": 11,
|
||||
"type": "Buffer",
|
||||
},
|
||||
"str": "block bing
|
||||
",
|
||||
"type": "FileReference",
|
||||
},
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"line": 1,
|
||||
"type": "Extends",
|
||||
},
|
||||
Object {
|
||||
"column": 1,
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"line": 3,
|
||||
"mode": "replace",
|
||||
"name": "bing",
|
||||
"nodes": Array [
|
||||
Object {
|
||||
"block": Object {
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"line": 4,
|
||||
"nodes": Array [],
|
||||
"type": "Block",
|
||||
},
|
||||
"column": 3,
|
||||
"file": Object {
|
||||
"ast": Object {
|
||||
"filename": "<dirname>/bing.pug",
|
||||
"line": 0,
|
||||
"nodes": Array [
|
||||
Object {
|
||||
"attributeBlocks": Array [],
|
||||
"attrs": Array [
|
||||
Object {
|
||||
"column": 1,
|
||||
"filename": "<basedir>/packages/pug-load/test/bing.pug",
|
||||
"line": 1,
|
||||
"mustEscape": false,
|
||||
"name": "class",
|
||||
"val": "'bing'",
|
||||
},
|
||||
],
|
||||
"block": Object {
|
||||
"filename": "<dirname>/bing.pug",
|
||||
"line": 1,
|
||||
"nodes": Array [
|
||||
Object {
|
||||
"column": 7,
|
||||
"filename": "<dirname>/bing.pug",
|
||||
"line": 1,
|
||||
"type": "Text",
|
||||
"val": "bong",
|
||||
},
|
||||
],
|
||||
"type": "Block",
|
||||
},
|
||||
"column": 1,
|
||||
"filename": "<dirname>/bing.pug",
|
||||
"isInline": false,
|
||||
"line": 1,
|
||||
"name": "div",
|
||||
"selfClosing": false,
|
||||
"type": "Tag",
|
||||
},
|
||||
],
|
||||
"type": "Block",
|
||||
},
|
||||
"column": 11,
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"fullPath": "<dirname>/bing.pug",
|
||||
"line": 4,
|
||||
"path": "bing.pug",
|
||||
"raw": Object {
|
||||
"hash": "58ecbe086e7a045084cbddac849a2563",
|
||||
"size": 11,
|
||||
"type": "Buffer",
|
||||
},
|
||||
"str": ".bing bong
|
||||
",
|
||||
"type": "FileReference",
|
||||
},
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"line": 4,
|
||||
"type": "Include",
|
||||
},
|
||||
Object {
|
||||
"attributeBlocks": Array [],
|
||||
"attrs": Array [],
|
||||
"block": Object {
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"line": 5,
|
||||
"nodes": Array [
|
||||
Object {
|
||||
"column": 5,
|
||||
"file": Object {
|
||||
"column": 13,
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"fullPath": "<dirname>/script.js",
|
||||
"line": 6,
|
||||
"path": "script.js",
|
||||
"raw": Object {
|
||||
"hash": "86d4f8e34165faeb09f10255121078f8",
|
||||
"size": 32,
|
||||
"type": "Buffer",
|
||||
},
|
||||
"str": "document.write('hello world!');
|
||||
",
|
||||
"type": "FileReference",
|
||||
},
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"filters": Array [],
|
||||
"line": 6,
|
||||
"type": "RawInclude",
|
||||
},
|
||||
],
|
||||
"type": "Block",
|
||||
},
|
||||
"column": 3,
|
||||
"filename": "<dirname>/foo.pug",
|
||||
"isInline": false,
|
||||
"line": 5,
|
||||
"name": "script",
|
||||
"selfClosing": false,
|
||||
"type": "Tag",
|
||||
},
|
||||
],
|
||||
"type": "NamedBlock",
|
||||
},
|
||||
],
|
||||
"type": "Block",
|
||||
}
|
||||
`;
|
||||
1
tests/sample_data/pug-load/test/bar.pug
Normal file
1
tests/sample_data/pug-load/test/bar.pug
Normal file
@@ -0,0 +1 @@
|
||||
block bing
|
||||
1
tests/sample_data/pug-load/test/bing.pug
Normal file
1
tests/sample_data/pug-load/test/bing.pug
Normal file
@@ -0,0 +1 @@
|
||||
.bing bong
|
||||
6
tests/sample_data/pug-load/test/foo.pug
Normal file
6
tests/sample_data/pug-load/test/foo.pug
Normal file
@@ -0,0 +1,6 @@
|
||||
extends bar.pug
|
||||
|
||||
block bing
|
||||
include bing.pug
|
||||
script
|
||||
include script.js
|
||||
30
tests/sample_data/pug-load/test/index.test.js
Normal file
30
tests/sample_data/pug-load/test/index.test.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var assert = require('assert');
|
||||
var walk = require('pug-walk');
|
||||
var lex = require('pug-lexer');
|
||||
var parse = require('pug-parser');
|
||||
var load = require('../');
|
||||
|
||||
test('pug-load', () => {
|
||||
var filename = __dirname + '/foo.pug';
|
||||
var ast = load.file(filename, {
|
||||
lex: lex,
|
||||
parse: parse,
|
||||
});
|
||||
|
||||
ast = walk(
|
||||
ast,
|
||||
function(node) {
|
||||
if (node.filename)
|
||||
node.filename = '<dirname>/' + path.basename(node.filename);
|
||||
if (node.fullPath)
|
||||
node.fullPath = '<dirname>/' + path.basename(node.fullPath);
|
||||
},
|
||||
{includeDependencies: true}
|
||||
);
|
||||
|
||||
expect(ast).toMatchSnapshot();
|
||||
});
|
||||
1
tests/sample_data/pug-load/test/script.js
Normal file
1
tests/sample_data/pug-load/test/script.js
Normal file
@@ -0,0 +1 @@
|
||||
document.write('hello world!');
|
||||
Reference in New Issue
Block a user