zig-pug 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +346 -0
  3. package/binding.c +375 -0
  4. package/binding.gyp +28 -0
  5. package/common.gypi +5 -0
  6. package/include/zigpug.h +135 -0
  7. package/index.js +205 -0
  8. package/package.json +87 -0
  9. package/vendor/mujs/COPYING +16 -0
  10. package/vendor/mujs/README +50 -0
  11. package/vendor/mujs/astnames.h +92 -0
  12. package/vendor/mujs/jsarray.c +832 -0
  13. package/vendor/mujs/jsboolean.c +38 -0
  14. package/vendor/mujs/jsbuiltin.c +249 -0
  15. package/vendor/mujs/jscompile.c +1428 -0
  16. package/vendor/mujs/jsdate.c +861 -0
  17. package/vendor/mujs/jsdtoa.c +749 -0
  18. package/vendor/mujs/jserror.c +139 -0
  19. package/vendor/mujs/jsfunction.c +231 -0
  20. package/vendor/mujs/jsgc.c +284 -0
  21. package/vendor/mujs/jsi.h +870 -0
  22. package/vendor/mujs/jsintern.c +137 -0
  23. package/vendor/mujs/jslex.c +878 -0
  24. package/vendor/mujs/jsmath.c +194 -0
  25. package/vendor/mujs/jsnumber.c +198 -0
  26. package/vendor/mujs/jsobject.c +560 -0
  27. package/vendor/mujs/json.c +422 -0
  28. package/vendor/mujs/jsparse.c +1065 -0
  29. package/vendor/mujs/jsproperty.c +341 -0
  30. package/vendor/mujs/jsregexp.c +232 -0
  31. package/vendor/mujs/jsrepr.c +285 -0
  32. package/vendor/mujs/jsrun.c +2096 -0
  33. package/vendor/mujs/jsstate.c +334 -0
  34. package/vendor/mujs/jsstring.c +852 -0
  35. package/vendor/mujs/jsvalue.c +708 -0
  36. package/vendor/mujs/libmujs.a +0 -0
  37. package/vendor/mujs/main.c +396 -0
  38. package/vendor/mujs/mujs.h +253 -0
  39. package/vendor/mujs/one.c +25 -0
  40. package/vendor/mujs/opnames.h +85 -0
  41. package/vendor/mujs/pp.c +980 -0
  42. package/vendor/mujs/regexp.c +1277 -0
  43. package/vendor/mujs/regexp.h +46 -0
  44. package/vendor/mujs/utf.c +305 -0
  45. package/vendor/mujs/utf.h +52 -0
  46. package/vendor/mujs/utfdata.h +2209 -0
package/index.js ADDED
@@ -0,0 +1,205 @@
1
+ /**
2
+ * zig-pug - Pug template engine for Node.js
3
+ * Powered by Zig and mujs
4
+ */
5
+
6
+ const binary = require('@mapbox/node-pre-gyp');
7
+ const path = require('path');
8
+ const fs = require('fs');
9
+
10
+ // Try to find precompiled binary first, fallback to development build
11
+ let binding;
12
+ try {
13
+ const binding_path = binary.find(path.resolve(path.join(__dirname, './package.json')));
14
+ binding = require(binding_path);
15
+ } catch (err) {
16
+ // Fallback to development build location
17
+ const dev_path = path.join(__dirname, 'build', 'Release', 'zigpug.node');
18
+ if (fs.existsSync(dev_path)) {
19
+ binding = require(dev_path);
20
+ } else {
21
+ throw new Error(
22
+ 'zig-pug native addon not found. ' +
23
+ 'Please build it with: cd .. && zig build node'
24
+ );
25
+ }
26
+ }
27
+
28
+ /**
29
+ * ZigPugCompiler class - High-level API for compiling Pug templates
30
+ */
31
+ class ZigPugCompiler {
32
+ constructor() {
33
+ this.context = binding.createContext();
34
+ if (!this.context) {
35
+ throw new Error('Failed to create zig-pug context');
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Set a string variable in the template context
41
+ * @param {string} key - Variable name
42
+ * @param {string} value - String value
43
+ * @returns {ZigPugCompiler} - Returns this for chaining
44
+ */
45
+ setString(key, value) {
46
+ if (typeof key !== 'string') {
47
+ throw new TypeError('Key must be a string');
48
+ }
49
+ if (typeof value !== 'string') {
50
+ throw new TypeError('Value must be a string');
51
+ }
52
+
53
+ const success = binding.setString(this.context, key, value);
54
+ if (!success) {
55
+ throw new Error(`Failed to set string variable: ${key}`);
56
+ }
57
+ return this;
58
+ }
59
+
60
+ /**
61
+ * Set a number variable in the template context
62
+ * @param {string} key - Variable name
63
+ * @param {number} value - Number value
64
+ * @returns {ZigPugCompiler} - Returns this for chaining
65
+ */
66
+ setNumber(key, value) {
67
+ if (typeof key !== 'string') {
68
+ throw new TypeError('Key must be a string');
69
+ }
70
+ if (typeof value !== 'number') {
71
+ throw new TypeError('Value must be a number');
72
+ }
73
+
74
+ const success = binding.setNumber(this.context, key, Math.floor(value));
75
+ if (!success) {
76
+ throw new Error(`Failed to set number variable: ${key}`);
77
+ }
78
+ return this;
79
+ }
80
+
81
+ /**
82
+ * Set a boolean variable in the template context
83
+ * @param {string} key - Variable name
84
+ * @param {boolean} value - Boolean value
85
+ * @returns {ZigPugCompiler} - Returns this for chaining
86
+ */
87
+ setBool(key, value) {
88
+ if (typeof key !== 'string') {
89
+ throw new TypeError('Key must be a string');
90
+ }
91
+ if (typeof value !== 'boolean') {
92
+ throw new TypeError('Value must be a boolean');
93
+ }
94
+
95
+ const success = binding.setBool(this.context, key, value);
96
+ if (!success) {
97
+ throw new Error(`Failed to set boolean variable: ${key}`);
98
+ }
99
+ return this;
100
+ }
101
+
102
+ /**
103
+ * Set a variable (automatically detects type)
104
+ * @param {string} key - Variable name
105
+ * @param {string|number|boolean} value - Value of any supported type
106
+ * @returns {ZigPugCompiler} - Returns this for chaining
107
+ */
108
+ set(key, value) {
109
+ if (typeof value === 'string') {
110
+ return this.setString(key, value);
111
+ } else if (typeof value === 'number') {
112
+ return this.setNumber(key, value);
113
+ } else if (typeof value === 'boolean') {
114
+ return this.setBool(key, value);
115
+ } else {
116
+ throw new TypeError(`Unsupported value type for key "${key}": ${typeof value}`);
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Set multiple variables from an object
122
+ * @param {Object} variables - Object with key-value pairs
123
+ * @returns {ZigPugCompiler} - Returns this for chaining
124
+ */
125
+ setVariables(variables) {
126
+ if (typeof variables !== 'object' || variables === null) {
127
+ throw new TypeError('Variables must be an object');
128
+ }
129
+
130
+ for (const [key, value] of Object.entries(variables)) {
131
+ this.set(key, value);
132
+ }
133
+
134
+ return this;
135
+ }
136
+
137
+ /**
138
+ * Compile a Pug template to HTML
139
+ * @param {string} template - Pug template string
140
+ * @returns {string} - Compiled HTML
141
+ */
142
+ compile(template) {
143
+ if (typeof template !== 'string') {
144
+ throw new TypeError('Template must be a string');
145
+ }
146
+
147
+ const html = binding.compile(this.context, template);
148
+ if (!html) {
149
+ throw new Error('Failed to compile template');
150
+ }
151
+
152
+ return html;
153
+ }
154
+
155
+ /**
156
+ * Compile a template with variables in one call
157
+ * @param {string} template - Pug template string
158
+ * @param {Object} variables - Variables to set before compiling
159
+ * @returns {string} - Compiled HTML
160
+ */
161
+ render(template, variables = {}) {
162
+ this.setVariables(variables);
163
+ return this.compile(template);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Convenience function to compile a template with variables
169
+ * @param {string} template - Pug template string
170
+ * @param {Object} variables - Variables for the template
171
+ * @returns {string} - Compiled HTML
172
+ */
173
+ function compile(template, variables = {}) {
174
+ const compiler = new ZigPugCompiler();
175
+ return compiler.render(template, variables);
176
+ }
177
+
178
+ /**
179
+ * Convenience function to compile a template from a file
180
+ * @param {string} filename - Path to the Pug template file
181
+ * @param {Object} variables - Variables for the template
182
+ * @returns {string} - Compiled HTML
183
+ */
184
+ function compileFile(filename, variables = {}) {
185
+ const fs = require('fs');
186
+ const template = fs.readFileSync(filename, 'utf8');
187
+ return compile(template, variables);
188
+ }
189
+
190
+ /**
191
+ * Get the zig-pug version
192
+ * @returns {string} - Version string
193
+ */
194
+ function version() {
195
+ return binding.version();
196
+ }
197
+
198
+ module.exports = {
199
+ ZigPugCompiler,
200
+ compile,
201
+ compileFile,
202
+ version,
203
+ // Backward compatibility alias
204
+ PugCompiler: ZigPugCompiler
205
+ };
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "zig-pug",
3
+ "version": "0.2.0",
4
+ "description": "High-performance Pug template engine powered by Zig and mujs - Native N-API addon with ES5.1 JavaScript support",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "install": "node-pre-gyp install --fallback-to-build || (cd .. && zig build node)",
8
+ "build": "cd .. && zig build node",
9
+ "build:from-source": "cd .. && zig build node",
10
+ "rebuild": "node-gyp rebuild && npm run postbuild",
11
+ "postbuild": "cp ../zig-out/nodejs/libzigpug.* build/Release/ 2>/dev/null || true",
12
+ "clean": "node-gyp clean && rm -rf ../zig-out/nodejs lib/binding",
13
+ "test": "LD_LIBRARY_PATH=../zig-out/nodejs:$LD_LIBRARY_PATH node test/test.js",
14
+ "example": "LD_LIBRARY_PATH=../zig-out/nodejs:$LD_LIBRARY_PATH node example.js",
15
+ "package": "node-pre-gyp package",
16
+ "upload": "node-pre-gyp publish",
17
+ "upload:github": "node scripts/upload-binary.js",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "keywords": [
21
+ "pug",
22
+ "template",
23
+ "template-engine",
24
+ "html",
25
+ "zig",
26
+ "mujs",
27
+ "javascript",
28
+ "es5",
29
+ "native",
30
+ "addon",
31
+ "napi",
32
+ "n-api",
33
+ "node-addon",
34
+ "fast",
35
+ "performance",
36
+ "high-performance",
37
+ "bun",
38
+ "bunjs",
39
+ "compiler",
40
+ "view-engine",
41
+ "express",
42
+ "jade",
43
+ "haml"
44
+ ],
45
+ "author": {
46
+ "name": "carlos-sweb",
47
+ "url": "https://github.com/carlos-sweb"
48
+ },
49
+ "license": "MIT",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/carlos-sweb/zig-pug.git",
53
+ "directory": "nodejs"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/carlos-sweb/zig-pug/issues"
57
+ },
58
+ "homepage": "https://github.com/carlos-sweb/zig-pug#readme",
59
+ "engines": {
60
+ "node": ">=14.0.0"
61
+ },
62
+ "dependencies": {
63
+ "@mapbox/node-pre-gyp": "^1.0.11"
64
+ },
65
+ "devDependencies": {
66
+ "node-gyp": "^10.0.0",
67
+ "aws-sdk": "^2.1691.0"
68
+ },
69
+ "gypfile": true,
70
+ "binary": {
71
+ "module_name": "zigpug",
72
+ "module_path": "./lib/binding/{configuration}/{node_abi}-{platform}-{arch}",
73
+ "remote_path": "./{version}",
74
+ "package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz",
75
+ "host": "https://github.com/carlos-sweb/zig-pug/releases/download/"
76
+ },
77
+ "files": [
78
+ "index.js",
79
+ "binding.c",
80
+ "binding.gyp",
81
+ "common.gypi",
82
+ "README.md",
83
+ "LICENSE",
84
+ "include/",
85
+ "vendor/"
86
+ ]
87
+ }
@@ -0,0 +1,16 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2013-2020 Artifex Software, Inc.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+
@@ -0,0 +1,50 @@
1
+ MuJS: an embeddable Javascript interpreter in C.
2
+
3
+ ABOUT
4
+
5
+ MuJS is a lightweight Javascript interpreter designed for embedding in
6
+ other software to extend them with scripting capabilities.
7
+
8
+ LICENSE
9
+
10
+ MuJS is Copyright 2013-2017 Artifex Software, Inc.
11
+
12
+ Permission to use, copy, modify, and/or distribute this software for any
13
+ purpose with or without fee is hereby granted, provided that the above
14
+ copyright notice and this permission notice appear in all copies.
15
+
16
+ The software is provided "as is" and the author disclaims all warranties with
17
+ regard to this software including all implied warranties of merchantability
18
+ and fitness. In no event shall the author be liable for any special, direct,
19
+ indirect, or consequential damages or any damages whatsoever resulting from
20
+ loss of use, data or profits, whether in an action of contract, negligence
21
+ or other tortious action, arising out of or in connection with the use or
22
+ performance of this software.
23
+
24
+ COMPILING
25
+
26
+ If you are building from source you can either use the provided Unix Makefile:
27
+
28
+ make release
29
+
30
+ Or compile the source with your preferred compiler:
31
+
32
+ cc -O2 -c one.c -o libmujs.o
33
+
34
+ INSTALLING
35
+
36
+ To install the MuJS command line interpreter, static library and header file:
37
+
38
+ make prefix=/usr/local install
39
+
40
+ DOWNLOAD
41
+
42
+ The latest development source is available directly from the git repository:
43
+
44
+ git clone http://git.ghostscript.com/mujs.git
45
+
46
+ REPORTING BUGS AND PROBLEMS
47
+
48
+ Report bugs on the ghostscript bugzilla, with MuJS as the selected component.
49
+
50
+ http://bugs.ghostscript.com/
@@ -0,0 +1,92 @@
1
+ "list",
2
+ "fundec",
3
+ "identifier",
4
+ "exp_identifier",
5
+ "exp_number",
6
+ "exp_string",
7
+ "exp_regexp",
8
+ "exp_elision",
9
+ "exp_null",
10
+ "exp_true",
11
+ "exp_false",
12
+ "exp_this",
13
+ "exp_array",
14
+ "exp_object",
15
+ "exp_prop_val",
16
+ "exp_prop_get",
17
+ "exp_prop_set",
18
+ "exp_fun",
19
+ "exp_index",
20
+ "exp_member",
21
+ "exp_call",
22
+ "exp_new",
23
+ "exp_postinc",
24
+ "exp_postdec",
25
+ "exp_delete",
26
+ "exp_void",
27
+ "exp_typeof",
28
+ "exp_preinc",
29
+ "exp_predec",
30
+ "exp_pos",
31
+ "exp_neg",
32
+ "exp_bitnot",
33
+ "exp_lognot",
34
+ "exp_mod",
35
+ "exp_div",
36
+ "exp_mul",
37
+ "exp_sub",
38
+ "exp_add",
39
+ "exp_ushr",
40
+ "exp_shr",
41
+ "exp_shl",
42
+ "exp_in",
43
+ "exp_instanceof",
44
+ "exp_ge",
45
+ "exp_le",
46
+ "exp_gt",
47
+ "exp_lt",
48
+ "exp_strictne",
49
+ "exp_stricteq",
50
+ "exp_ne",
51
+ "exp_eq",
52
+ "exp_bitand",
53
+ "exp_bitxor",
54
+ "exp_bitor",
55
+ "exp_logand",
56
+ "exp_logor",
57
+ "exp_cond",
58
+ "exp_ass",
59
+ "exp_ass_mul",
60
+ "exp_ass_div",
61
+ "exp_ass_mod",
62
+ "exp_ass_add",
63
+ "exp_ass_sub",
64
+ "exp_ass_shl",
65
+ "exp_ass_shr",
66
+ "exp_ass_ushr",
67
+ "exp_ass_bitand",
68
+ "exp_ass_bitxor",
69
+ "exp_ass_bitor",
70
+ "exp_comma",
71
+ "exp_var",
72
+ "stm_block",
73
+ "stm_empty",
74
+ "stm_var",
75
+ "stm_if",
76
+ "stm_do",
77
+ "stm_while",
78
+ "stm_for",
79
+ "stm_for_var",
80
+ "stm_for_in",
81
+ "stm_for_in_var",
82
+ "stm_continue",
83
+ "stm_break",
84
+ "stm_return",
85
+ "stm_with",
86
+ "stm_switch",
87
+ "stm_throw",
88
+ "stm_try",
89
+ "stm_debugger",
90
+ "stm_label",
91
+ "stm_case",
92
+ "stm_default",