puglite 1.0.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.
- package/README.md +115 -0
- package/angular-webpack/index.js +27 -0
- package/angular-webpack/loader.js +37 -0
- package/builders/browser/index.js +49 -0
- package/builders/browser/schema.json +138 -0
- package/builders/dev-server/index.js +48 -0
- package/builders/dev-server/schema.json +98 -0
- package/builders/karma/README.md +82 -0
- package/builders/karma/index.js +40 -0
- package/builders/karma/schema.json +260 -0
- package/builders/vitest/README.md +218 -0
- package/builders/vitest/index.js +98 -0
- package/builders/vitest/schema.json +8 -0
- package/builders.json +25 -0
- package/lib/attrs.js +150 -0
- package/lib/build.js +27 -0
- package/lib/code-gen.js +769 -0
- package/lib/error.js +56 -0
- package/lib/index.js +416 -0
- package/lib/lexer.d.ts +366 -0
- package/lib/lexer.js +1713 -0
- package/lib/parser-lib/inline-tags.js +23 -0
- package/lib/parser.js +1299 -0
- package/lib/prepublish.js +70 -0
- package/lib/runtime-build.js +27 -0
- package/lib/runtime-lib/dependencies.js +34 -0
- package/lib/runtime-lib/internals.js +8 -0
- package/lib/runtime-lib/sources.js +13 -0
- package/lib/runtime-wrap.js +10 -0
- package/lib/runtime.js +287 -0
- package/lib/strip-comments.js +77 -0
- package/lib/wrap.js +10 -0
- package/package.json +72 -0
package/lib/attrs.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var assert = require('assert');
|
|
4
|
+
var constantinople = require('constantinople');
|
|
5
|
+
var runtime = require('./runtime');
|
|
6
|
+
var stringify = require('js-stringify');
|
|
7
|
+
|
|
8
|
+
function isConstant(src) {
|
|
9
|
+
return constantinople(src, {pug: runtime, pug_interp: undefined});
|
|
10
|
+
}
|
|
11
|
+
function toConstant(src) {
|
|
12
|
+
return constantinople.toConstant(src, {pug: runtime, pug_interp: undefined});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = compileAttrs;
|
|
16
|
+
/**
|
|
17
|
+
* options:
|
|
18
|
+
* - terse
|
|
19
|
+
* - runtime
|
|
20
|
+
* - format ('html' || 'object')
|
|
21
|
+
*/
|
|
22
|
+
function compileAttrs(attrs, options) {
|
|
23
|
+
assert(Array.isArray(attrs), 'Attrs should be an array');
|
|
24
|
+
assert(
|
|
25
|
+
attrs.every(function(attr) {
|
|
26
|
+
return (
|
|
27
|
+
attr &&
|
|
28
|
+
typeof attr === 'object' &&
|
|
29
|
+
typeof attr.name === 'string' &&
|
|
30
|
+
(typeof attr.val === 'string' || typeof attr.val === 'boolean') &&
|
|
31
|
+
typeof attr.mustEscape === 'boolean'
|
|
32
|
+
);
|
|
33
|
+
}),
|
|
34
|
+
'All attributes should be supplied as an object of the form {name, val, mustEscape}'
|
|
35
|
+
);
|
|
36
|
+
assert(options && typeof options === 'object', 'Options should be an object');
|
|
37
|
+
assert(
|
|
38
|
+
typeof options.terse === 'boolean',
|
|
39
|
+
'Options.terse should be a boolean'
|
|
40
|
+
);
|
|
41
|
+
assert(
|
|
42
|
+
typeof options.runtime === 'function',
|
|
43
|
+
'Options.runtime should be a function that takes a runtime function name and returns the source code that will evaluate to that function at runtime'
|
|
44
|
+
);
|
|
45
|
+
assert(
|
|
46
|
+
options.format === 'html' || options.format === 'object',
|
|
47
|
+
'Options.format should be "html" or "object"'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
var buf = [];
|
|
51
|
+
var classes = [];
|
|
52
|
+
var classEscaping = [];
|
|
53
|
+
|
|
54
|
+
function addAttribute(key, val, mustEscape, buf) {
|
|
55
|
+
if (isConstant(val)) {
|
|
56
|
+
if (options.format === 'html') {
|
|
57
|
+
var str = stringify(
|
|
58
|
+
runtime.attr(key, toConstant(val), mustEscape, options.terse)
|
|
59
|
+
);
|
|
60
|
+
var last = buf[buf.length - 1];
|
|
61
|
+
if (last && last[last.length - 1] === str[0]) {
|
|
62
|
+
buf[buf.length - 1] = last.substr(0, last.length - 1) + str.substr(1);
|
|
63
|
+
} else {
|
|
64
|
+
buf.push(str);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
val = toConstant(val);
|
|
68
|
+
if (mustEscape) {
|
|
69
|
+
val = runtime.escape(val);
|
|
70
|
+
}
|
|
71
|
+
buf.push(stringify(key) + ': ' + stringify(val));
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
if (options.format === 'html') {
|
|
75
|
+
buf.push(
|
|
76
|
+
options.runtime('attr') +
|
|
77
|
+
'("' +
|
|
78
|
+
key +
|
|
79
|
+
'", ' +
|
|
80
|
+
val +
|
|
81
|
+
', ' +
|
|
82
|
+
stringify(mustEscape) +
|
|
83
|
+
', ' +
|
|
84
|
+
stringify(options.terse) +
|
|
85
|
+
')'
|
|
86
|
+
);
|
|
87
|
+
} else {
|
|
88
|
+
if (mustEscape) {
|
|
89
|
+
val = options.runtime('escape') + '(' + val + ')';
|
|
90
|
+
}
|
|
91
|
+
buf.push(stringify(key) + ': ' + val);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
attrs.forEach(function(attr) {
|
|
97
|
+
var key = attr.name;
|
|
98
|
+
var val = attr.val;
|
|
99
|
+
var mustEscape = attr.mustEscape;
|
|
100
|
+
|
|
101
|
+
if (key === 'class') {
|
|
102
|
+
classes.push(val);
|
|
103
|
+
classEscaping.push(mustEscape);
|
|
104
|
+
} else {
|
|
105
|
+
if (key === 'style') {
|
|
106
|
+
if (isConstant(val)) {
|
|
107
|
+
val = stringify(runtime.style(toConstant(val)));
|
|
108
|
+
} else {
|
|
109
|
+
val = options.runtime('style') + '(' + val + ')';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
addAttribute(key, val, mustEscape, buf);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
var classesBuf = [];
|
|
116
|
+
if (classes.length) {
|
|
117
|
+
if (classes.every(isConstant)) {
|
|
118
|
+
addAttribute(
|
|
119
|
+
'class',
|
|
120
|
+
stringify(runtime.classes(classes.map(toConstant), classEscaping)),
|
|
121
|
+
false,
|
|
122
|
+
classesBuf
|
|
123
|
+
);
|
|
124
|
+
} else {
|
|
125
|
+
classes = classes.map(function(cls, i) {
|
|
126
|
+
if (isConstant(cls)) {
|
|
127
|
+
cls = stringify(
|
|
128
|
+
classEscaping[i] ? runtime.escape(toConstant(cls)) : toConstant(cls)
|
|
129
|
+
);
|
|
130
|
+
classEscaping[i] = false;
|
|
131
|
+
}
|
|
132
|
+
return cls;
|
|
133
|
+
});
|
|
134
|
+
addAttribute(
|
|
135
|
+
'class',
|
|
136
|
+
options.runtime('classes') +
|
|
137
|
+
'([' +
|
|
138
|
+
classes.join(',') +
|
|
139
|
+
'], ' +
|
|
140
|
+
stringify(classEscaping) +
|
|
141
|
+
')',
|
|
142
|
+
false,
|
|
143
|
+
classesBuf
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
buf = classesBuf.concat(buf);
|
|
148
|
+
if (options.format === 'html') return buf.length ? buf.join('+') : '""';
|
|
149
|
+
else return '{' + buf.join(',') + '}';
|
|
150
|
+
}
|
package/lib/build.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var dependencies = require('./lib/dependencies.js');
|
|
5
|
+
var internals = require('./lib/internals.js');
|
|
6
|
+
var sources = require('./lib/sources.js');
|
|
7
|
+
|
|
8
|
+
module.exports = build;
|
|
9
|
+
|
|
10
|
+
function build(functions) {
|
|
11
|
+
var fns = [];
|
|
12
|
+
functions = functions.filter(function(fn) {
|
|
13
|
+
return !internals[fn];
|
|
14
|
+
});
|
|
15
|
+
for (var i = 0; i < functions.length; i++) {
|
|
16
|
+
if (fns.indexOf(functions[i]) === -1) {
|
|
17
|
+
fns.push(functions[i]);
|
|
18
|
+
functions.push.apply(functions, dependencies[functions[i]]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return fns
|
|
22
|
+
.sort()
|
|
23
|
+
.map(function(name) {
|
|
24
|
+
return sources[name];
|
|
25
|
+
})
|
|
26
|
+
.join('\n');
|
|
27
|
+
}
|