microtags 0.0.14 → 0.1.1
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 +554 -20
- package/dist/build.cjs +412 -0
- package/dist/build.cjs.map +7 -0
- package/dist/build.d.ts +17 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +395 -0
- package/dist/build.js.map +7 -0
- package/dist/builders.d.ts +70 -4
- package/dist/builders.d.ts.map +1 -1
- package/dist/{chunk-CCYWRJW6.js → chunk-46UEUDVX.js} +4 -26
- package/dist/chunk-46UEUDVX.js.map +7 -0
- package/dist/chunk-LS4L5QRD.js +26 -0
- package/dist/chunk-LS4L5QRD.js.map +7 -0
- package/dist/chunk-RKWPTT6P.js +69 -0
- package/dist/chunk-RKWPTT6P.js.map +7 -0
- package/dist/chunk-ZZ4ZLOQY.js +33 -0
- package/dist/chunk-ZZ4ZLOQY.js.map +7 -0
- package/dist/cli.cjs +536 -0
- package/dist/cli.cjs.map +7 -0
- package/dist/context.js +2 -1
- package/dist/esbuild.cjs +451 -0
- package/dist/esbuild.cjs.map +7 -0
- package/dist/esbuild.d.ts +7 -0
- package/dist/esbuild.d.ts.map +1 -0
- package/dist/esbuild.js +434 -0
- package/dist/esbuild.js.map +7 -0
- package/dist/factory.d.ts +7 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/htm.browser.cjs +591 -0
- package/dist/htm.browser.cjs.map +7 -0
- package/dist/htm.browser.d.ts +30 -0
- package/dist/htm.browser.d.ts.map +1 -0
- package/dist/htm.browser.js +498 -0
- package/dist/htm.browser.js.map +7 -0
- package/dist/htm.browser.min.js +3 -0
- package/dist/htm.browser.min.js.map +7 -0
- package/dist/htm.cjs +284 -0
- package/dist/htm.cjs.map +7 -0
- package/dist/htm.d.ts +14 -0
- package/dist/htm.d.ts.map +1 -0
- package/dist/htm.js +196 -0
- package/dist/htm.js.map +7 -0
- package/dist/htm.min.js +3 -0
- package/dist/htm.min.js.map +7 -0
- package/dist/index.cjs +125 -11
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +133 -17
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/meta.json +411 -26
- package/dist/preact-shared.d.ts +61 -0
- package/dist/preact-shared.d.ts.map +1 -0
- package/dist/preact.browser.d.ts +8 -0
- package/dist/preact.browser.d.ts.map +1 -0
- package/dist/preact.browser.js +45 -0
- package/dist/preact.browser.js.map +7 -0
- package/dist/preact.browser.min.js +2 -0
- package/dist/preact.browser.min.js.map +7 -0
- package/dist/preact.cjs +128 -0
- package/dist/preact.cjs.map +7 -0
- package/dist/preact.d.ts +9 -0
- package/dist/preact.d.ts.map +1 -0
- package/dist/preact.js +35 -0
- package/dist/preact.js.map +7 -0
- package/dist/render-support.cjs +86 -0
- package/dist/render-support.cjs.map +7 -0
- package/dist/render-support.d.ts +23 -0
- package/dist/render-support.d.ts.map +1 -0
- package/dist/render-support.js +12 -0
- package/dist/render-support.js.map +7 -0
- package/dist/render-support.min.js +2 -0
- package/dist/render-support.min.js.map +7 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/vite.cjs +448 -0
- package/dist/vite.cjs.map +7 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +429 -0
- package/dist/vite.js.map +7 -0
- package/package.json +92 -13
- package/dist/chunk-CCYWRJW6.js.map +0 -7
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/esbuild.ts
|
|
11
|
+
import { readFileSync } from "fs";
|
|
12
|
+
|
|
13
|
+
// src/build.ts
|
|
14
|
+
var ts;
|
|
15
|
+
try {
|
|
16
|
+
ts = __require("typescript");
|
|
17
|
+
} catch (err) {
|
|
18
|
+
const { code, message } = err;
|
|
19
|
+
if (code === "MODULE_NOT_FOUND" && message?.includes("'typescript'")) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'microtags/build requires "typescript" as a peer dependency. Install it with: npm install --save-dev typescript'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
throw new Error(
|
|
25
|
+
'microtags/build could not load "typescript" because `require` is unavailable or unusable here. Load the entry from its built form (microtags/build, or dist/ in this repo) instead of from source.',
|
|
26
|
+
{ cause: err }
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function transform(code, options) {
|
|
30
|
+
const keep = options?.keep ?? [];
|
|
31
|
+
const filename = options?.filename;
|
|
32
|
+
const sf = ts.createSourceFile(
|
|
33
|
+
filename ?? "input.ts",
|
|
34
|
+
code,
|
|
35
|
+
ts.ScriptTarget.Latest,
|
|
36
|
+
true
|
|
37
|
+
);
|
|
38
|
+
const defineAliases = findDefineAliases(sf);
|
|
39
|
+
const spans = [];
|
|
40
|
+
const strippedBindings = /* @__PURE__ */ new Set();
|
|
41
|
+
const warnings = [];
|
|
42
|
+
let keptLink = false;
|
|
43
|
+
function visit(node) {
|
|
44
|
+
if (!ts.isCallExpression(node)) {
|
|
45
|
+
ts.forEachChild(node, visit);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "render") {
|
|
49
|
+
const receiver = node.expression.expression;
|
|
50
|
+
const chainRoot = findChainRoot(receiver);
|
|
51
|
+
if (chainRoot && isDefineCall(chainRoot, defineAliases)) {
|
|
52
|
+
const tagName = getDefineLiteralTag(chainRoot);
|
|
53
|
+
if (tagName === null && keep.length > 0) {
|
|
54
|
+
const line2 = sf.getLineAndCharacterOfPosition(
|
|
55
|
+
chainRoot.getStart()
|
|
56
|
+
).line + 1;
|
|
57
|
+
warnings.push({
|
|
58
|
+
kind: "non-literal-tag",
|
|
59
|
+
file: filename,
|
|
60
|
+
line: line2,
|
|
61
|
+
message: "define() call with non-literal tag name cannot be matched by --keep"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (shouldKeep(node, tagName, keep)) {
|
|
65
|
+
keptLink = true;
|
|
66
|
+
ts.forEachChild(node, visit);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const binding = findBindingName(node);
|
|
70
|
+
if (binding) strippedBindings.add(binding);
|
|
71
|
+
spans.push({
|
|
72
|
+
start: dotPosition(node),
|
|
73
|
+
end: node.getEnd()
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const line = sf.getLineAndCharacterOfPosition(
|
|
78
|
+
node.getStart()
|
|
79
|
+
).line + 1;
|
|
80
|
+
warnings.push({
|
|
81
|
+
kind: "outside-chain",
|
|
82
|
+
file: filename,
|
|
83
|
+
line,
|
|
84
|
+
message: ".render() call outside a define chain"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
ts.forEachChild(node, visit);
|
|
88
|
+
}
|
|
89
|
+
__name(visit, "visit");
|
|
90
|
+
ts.forEachChild(sf, visit);
|
|
91
|
+
spans.sort((a, b) => b.start - a.start);
|
|
92
|
+
let result = code;
|
|
93
|
+
for (const span of spans) {
|
|
94
|
+
const removed = result.slice(span.start, span.end);
|
|
95
|
+
const newlines = removed.split("\n").length - 1;
|
|
96
|
+
result = result.slice(0, span.start) + "\n".repeat(newlines) + result.slice(span.end);
|
|
97
|
+
}
|
|
98
|
+
if (options?.cascade) {
|
|
99
|
+
result = cascadeRemove(result, filename);
|
|
100
|
+
}
|
|
101
|
+
if (strippedBindings.size > 0) {
|
|
102
|
+
const resultSf = ts.createSourceFile(
|
|
103
|
+
filename ?? "input.ts",
|
|
104
|
+
result,
|
|
105
|
+
ts.ScriptTarget.Latest,
|
|
106
|
+
true
|
|
107
|
+
);
|
|
108
|
+
findStrippedStaticCalls(
|
|
109
|
+
resultSf,
|
|
110
|
+
strippedBindings,
|
|
111
|
+
warnings,
|
|
112
|
+
filename
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (keptLink && !importsSupport(sf)) {
|
|
116
|
+
result += `
|
|
117
|
+
import '${SUPPORT}'
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
return { code: result, warnings };
|
|
121
|
+
}
|
|
122
|
+
__name(transform, "transform");
|
|
123
|
+
var SUPPORT = "microtags/render-support";
|
|
124
|
+
function importsSupport(sf) {
|
|
125
|
+
return sf.statements.some(
|
|
126
|
+
(node) => ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text === SUPPORT
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
__name(importsSupport, "importsSupport");
|
|
130
|
+
function findDefineAliases(sf) {
|
|
131
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
132
|
+
ts.forEachChild(sf, (node) => {
|
|
133
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text === "microtags" && node.importClause?.namedBindings && ts.isNamedImports(
|
|
134
|
+
node.importClause.namedBindings
|
|
135
|
+
)) {
|
|
136
|
+
for (const spec of node.importClause.namedBindings.elements) {
|
|
137
|
+
const origName = spec.propertyName?.text ?? spec.name.text;
|
|
138
|
+
if (origName === "define") {
|
|
139
|
+
aliases.add(spec.name.text);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return aliases;
|
|
145
|
+
}
|
|
146
|
+
__name(findDefineAliases, "findDefineAliases");
|
|
147
|
+
function findChainRoot(node) {
|
|
148
|
+
if (ts.isCallExpression(node)) {
|
|
149
|
+
if (ts.isIdentifier(node.expression)) {
|
|
150
|
+
return node;
|
|
151
|
+
}
|
|
152
|
+
if (ts.isPropertyAccessExpression(node.expression)) {
|
|
153
|
+
return findChainRoot(
|
|
154
|
+
node.expression.expression
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
__name(findChainRoot, "findChainRoot");
|
|
161
|
+
function isDefineCall(node, aliases) {
|
|
162
|
+
return ts.isIdentifier(node.expression) && aliases.has(node.expression.text);
|
|
163
|
+
}
|
|
164
|
+
__name(isDefineCall, "isDefineCall");
|
|
165
|
+
function getDefineLiteralTag(node) {
|
|
166
|
+
if (node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) {
|
|
167
|
+
return node.arguments[0].text;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
__name(getDefineLiteralTag, "getDefineLiteralTag");
|
|
172
|
+
function shouldKeep(renderCall, tagName, keep) {
|
|
173
|
+
if (renderCall.arguments.length >= 2) {
|
|
174
|
+
const opts = renderCall.arguments[1];
|
|
175
|
+
if (ts.isObjectLiteralExpression(opts)) {
|
|
176
|
+
for (const prop of opts.properties) {
|
|
177
|
+
if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === "client" && prop.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (tagName !== null && keep.includes(tagName)) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
__name(shouldKeep, "shouldKeep");
|
|
189
|
+
function dotPosition(renderCall) {
|
|
190
|
+
const pa = renderCall.expression;
|
|
191
|
+
return pa.expression.getEnd();
|
|
192
|
+
}
|
|
193
|
+
__name(dotPosition, "dotPosition");
|
|
194
|
+
function findBindingName(node) {
|
|
195
|
+
let current = node;
|
|
196
|
+
while (current.parent) {
|
|
197
|
+
current = current.parent;
|
|
198
|
+
if (ts.isVariableDeclaration(current) && ts.isIdentifier(current.name)) {
|
|
199
|
+
return current.name.text;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
__name(findBindingName, "findBindingName");
|
|
205
|
+
function cascadeRemove(code, filename) {
|
|
206
|
+
let changed = true;
|
|
207
|
+
let result = code;
|
|
208
|
+
while (changed) {
|
|
209
|
+
changed = false;
|
|
210
|
+
const sf = ts.createSourceFile(
|
|
211
|
+
filename ?? "input.ts",
|
|
212
|
+
result,
|
|
213
|
+
ts.ScriptTarget.Latest,
|
|
214
|
+
true
|
|
215
|
+
);
|
|
216
|
+
const refs = collectReferences(sf);
|
|
217
|
+
const removeSpans = [];
|
|
218
|
+
ts.forEachChild(sf, (node) => {
|
|
219
|
+
if (ts.isImportDeclaration(node) && node.importClause) {
|
|
220
|
+
if (isExportedNode(node)) return;
|
|
221
|
+
const nb = node.importClause.namedBindings;
|
|
222
|
+
if (!nb) return;
|
|
223
|
+
if (!ts.isNamedImports(nb)) {
|
|
224
|
+
const name = node.importClause.name;
|
|
225
|
+
if (name && !refs.has(name.text)) {
|
|
226
|
+
removeSpans.push({
|
|
227
|
+
start: node.getStart(),
|
|
228
|
+
end: node.getEnd()
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const dead = [];
|
|
234
|
+
const live = [];
|
|
235
|
+
for (const el of nb.elements) {
|
|
236
|
+
if (refs.has(el.name.text)) {
|
|
237
|
+
live.push(el);
|
|
238
|
+
} else {
|
|
239
|
+
dead.push(el);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (dead.length === 0) return;
|
|
243
|
+
if (live.length === 0) {
|
|
244
|
+
removeSpans.push({
|
|
245
|
+
start: node.getStart(),
|
|
246
|
+
end: node.getEnd()
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
for (const d of dead) {
|
|
250
|
+
let start = d.getStart();
|
|
251
|
+
let end = d.getEnd();
|
|
252
|
+
const text = result;
|
|
253
|
+
const after = text.slice(end);
|
|
254
|
+
const before = text.slice(0, start);
|
|
255
|
+
if (/^\s*,/.test(after)) {
|
|
256
|
+
end += after.match(
|
|
257
|
+
/^\s*,/
|
|
258
|
+
)[0].length;
|
|
259
|
+
} else if (/,\s*$/.test(before)) {
|
|
260
|
+
start = before.lastIndexOf(",");
|
|
261
|
+
}
|
|
262
|
+
removeSpans.push({ start, end });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (ts.isVariableStatement(node)) {
|
|
268
|
+
if (isExportedNode(node)) return;
|
|
269
|
+
const allDead = node.declarationList.declarations.every(
|
|
270
|
+
(d) => ts.isIdentifier(d.name) && !refs.has(d.name.text)
|
|
271
|
+
);
|
|
272
|
+
if (allDead) {
|
|
273
|
+
removeSpans.push({
|
|
274
|
+
start: node.getStart(),
|
|
275
|
+
end: node.getEnd()
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
281
|
+
if (isExportedNode(node)) return;
|
|
282
|
+
if (node.name && !refs.has(node.name.text)) {
|
|
283
|
+
removeSpans.push({
|
|
284
|
+
start: node.getStart(),
|
|
285
|
+
end: node.getEnd()
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (ts.isClassDeclaration(node)) {
|
|
291
|
+
if (isExportedNode(node)) return;
|
|
292
|
+
if (node.name && !refs.has(node.name.text)) {
|
|
293
|
+
removeSpans.push({
|
|
294
|
+
start: node.getStart(),
|
|
295
|
+
end: node.getEnd()
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
if (removeSpans.length === 0) break;
|
|
301
|
+
changed = true;
|
|
302
|
+
removeSpans.sort((a, b) => b.start - a.start);
|
|
303
|
+
for (const span of removeSpans) {
|
|
304
|
+
const removed = result.slice(
|
|
305
|
+
span.start,
|
|
306
|
+
span.end
|
|
307
|
+
);
|
|
308
|
+
const newlines = removed.split("\n").length - 1;
|
|
309
|
+
result = result.slice(0, span.start) + "\n".repeat(newlines) + result.slice(span.end);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
__name(cascadeRemove, "cascadeRemove");
|
|
315
|
+
function collectReferences(sf) {
|
|
316
|
+
const refs = /* @__PURE__ */ new Set();
|
|
317
|
+
const declared = /* @__PURE__ */ new Set();
|
|
318
|
+
ts.forEachChild(sf, (node) => {
|
|
319
|
+
if (ts.isImportDeclaration(node)) {
|
|
320
|
+
if (node.importClause?.namedBindings && ts.isNamedImports(
|
|
321
|
+
node.importClause.namedBindings
|
|
322
|
+
)) {
|
|
323
|
+
for (const el of node.importClause.namedBindings.elements) {
|
|
324
|
+
declared.add(el.name.text);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (ts.isVariableStatement(node)) {
|
|
330
|
+
for (const d of node.declarationList.declarations) {
|
|
331
|
+
if (ts.isIdentifier(d.name)) {
|
|
332
|
+
declared.add(d.name.text);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
337
|
+
declared.add(node.name.text);
|
|
338
|
+
}
|
|
339
|
+
if (ts.isClassDeclaration(node) && node.name) {
|
|
340
|
+
declared.add(node.name.text);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
function visitRefs(node) {
|
|
344
|
+
if (ts.isIdentifier(node) && declared.has(node.text)) {
|
|
345
|
+
const parent = node.parent;
|
|
346
|
+
if (ts.isImportSpecifier(parent) || ts.isVariableDeclaration(parent) && parent.name === node || ts.isFunctionDeclaration(parent) && parent.name === node || ts.isClassDeclaration(parent) && parent.name === node) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
refs.add(node.text);
|
|
350
|
+
}
|
|
351
|
+
ts.forEachChild(node, visitRefs);
|
|
352
|
+
}
|
|
353
|
+
__name(visitRefs, "visitRefs");
|
|
354
|
+
ts.forEachChild(sf, (node) => {
|
|
355
|
+
if (ts.isImportDeclaration(node)) return;
|
|
356
|
+
visitRefs(node);
|
|
357
|
+
});
|
|
358
|
+
return refs;
|
|
359
|
+
}
|
|
360
|
+
__name(collectReferences, "collectReferences");
|
|
361
|
+
function isExportedNode(node) {
|
|
362
|
+
if (!ts.canHaveModifiers(node)) return false;
|
|
363
|
+
const mods = ts.getModifiers(node);
|
|
364
|
+
if (!mods) return false;
|
|
365
|
+
return mods.some(
|
|
366
|
+
(m) => m.kind === ts.SyntaxKind.ExportKeyword
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
__name(isExportedNode, "isExportedNode");
|
|
370
|
+
function findStrippedStaticCalls(sf, bindings, warnings, filename) {
|
|
371
|
+
function visit(node) {
|
|
372
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(
|
|
373
|
+
node.expression
|
|
374
|
+
) && node.expression.name.text === "render" && ts.isIdentifier(
|
|
375
|
+
node.expression.expression
|
|
376
|
+
) && bindings.has(
|
|
377
|
+
node.expression.expression.text
|
|
378
|
+
)) {
|
|
379
|
+
const line = sf.getLineAndCharacterOfPosition(
|
|
380
|
+
node.getStart()
|
|
381
|
+
).line + 1;
|
|
382
|
+
warnings.push({
|
|
383
|
+
kind: "stripped-static",
|
|
384
|
+
file: filename,
|
|
385
|
+
line,
|
|
386
|
+
message: `${node.expression.expression.text}.render() called but render was stripped`
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
ts.forEachChild(node, visit);
|
|
390
|
+
}
|
|
391
|
+
__name(visit, "visit");
|
|
392
|
+
ts.forEachChild(sf, visit);
|
|
393
|
+
}
|
|
394
|
+
__name(findStrippedStaticCalls, "findStrippedStaticCalls");
|
|
395
|
+
|
|
396
|
+
// src/esbuild.ts
|
|
397
|
+
function microtags(options) {
|
|
398
|
+
const filter = options?.filter ?? /\.(ts|js|mjs)$/;
|
|
399
|
+
const cascade = options?.cascade;
|
|
400
|
+
const keep = options?.keep;
|
|
401
|
+
return {
|
|
402
|
+
name: "microtags",
|
|
403
|
+
setup(build) {
|
|
404
|
+
build.onLoad({ filter }, (args) => {
|
|
405
|
+
const code = readFileSync(
|
|
406
|
+
args.path,
|
|
407
|
+
"utf8"
|
|
408
|
+
);
|
|
409
|
+
const result = transform(code, {
|
|
410
|
+
cascade,
|
|
411
|
+
keep,
|
|
412
|
+
filename: args.path
|
|
413
|
+
});
|
|
414
|
+
const warnings = result.warnings.map((w) => ({
|
|
415
|
+
text: w.message,
|
|
416
|
+
location: {
|
|
417
|
+
file: args.path,
|
|
418
|
+
line: w.line
|
|
419
|
+
}
|
|
420
|
+
}));
|
|
421
|
+
return {
|
|
422
|
+
contents: result.code,
|
|
423
|
+
loader: args.path.endsWith(".ts") ? "ts" : "js",
|
|
424
|
+
warnings
|
|
425
|
+
};
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
__name(microtags, "microtags");
|
|
431
|
+
export {
|
|
432
|
+
microtags
|
|
433
|
+
};
|
|
434
|
+
//# sourceMappingURL=esbuild.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/esbuild.ts", "../src/build.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Plugin, OnLoadArgs, OnLoadResult } from 'esbuild'\nimport { readFileSync } from 'fs'\nimport { transform } from './build.js'\nimport type { TransformOptions } from './build.js'\n\nexport interface MicrotagsEsbuildOptions\n extends TransformOptions {\n filter?:RegExp\n}\n\nexport function microtags (\n options?:MicrotagsEsbuildOptions\n):Plugin {\n const filter = options?.filter ?? /\\.(ts|js|mjs)$/\n const cascade = options?.cascade\n const keep = options?.keep as string[] | undefined\n\n return {\n name: 'microtags',\n setup (build) {\n build.onLoad({ filter }, (args:OnLoadArgs) => {\n const code = readFileSync(\n args.path, 'utf8'\n )\n const result = transform(code, {\n cascade,\n keep,\n filename: args.path,\n })\n\n const warnings = result.warnings.map(w => ({\n text: w.message,\n location: {\n file: args.path,\n line: w.line,\n },\n }))\n\n return {\n contents: result.code,\n loader: args.path.endsWith('.ts') ?\n 'ts' :\n 'js',\n warnings,\n } as OnLoadResult\n })\n },\n }\n}\n", "import type TypeScript from 'typescript'\n\ndeclare const require:(id:string) => unknown\n\nlet ts:typeof TypeScript\ntry {\n ts = require('typescript') as typeof TypeScript\n} catch (err) {\n // Only a failure to resolve the bare name means typescript is\n // missing. Anything else is a context that cannot `require` it:\n // an ESM bundle without `require`, or a Vite config bundle, which\n // hands `require` a file URL.\n const { code, message } = err as { code?:string, message?:string }\n if (\n code === 'MODULE_NOT_FOUND' &&\n message?.includes(\"'typescript'\")\n ) {\n throw new Error(\n 'microtags/build requires \"typescript\" as a peer dependency. ' +\n 'Install it with: npm install --save-dev typescript'\n )\n }\n throw new Error(\n 'microtags/build could not load \"typescript\" because `require` ' +\n 'is unavailable or unusable here. Load the entry from its ' +\n 'built form (microtags/build, or dist/ in this repo) instead ' +\n 'of from source.',\n { cause: err }\n )\n}\n\nexport interface TransformWarning {\n kind:'outside-chain'|'stripped-static'|'non-literal-tag'\n file?:string\n line:number\n message:string\n}\n\nexport interface TransformOptions {\n cascade?:boolean\n keep?:string[]\n filename?:string\n}\n\nexport interface TransformResult {\n code:string\n warnings:TransformWarning[]\n}\n\nexport function transform (\n code:string,\n options?:TransformOptions\n):TransformResult {\n const keep = options?.keep ?? []\n const filename = options?.filename\n\n const sf = ts.createSourceFile(\n filename ?? 'input.ts',\n code,\n ts.ScriptTarget.Latest,\n true\n )\n\n const defineAliases = findDefineAliases(sf)\n const spans:{ start:number, end:number }[] = []\n const strippedBindings:Set<string> = new Set()\n const warnings:TransformWarning[] = []\n let keptLink = false\n\n function visit (node:TypeScript.Node) {\n if (!ts.isCallExpression(node)) {\n ts.forEachChild(node, visit)\n return\n }\n\n if (\n ts.isPropertyAccessExpression(node.expression) &&\n node.expression.name.text === 'render'\n ) {\n const receiver = node.expression.expression\n const chainRoot = findChainRoot(receiver)\n\n if (\n chainRoot &&\n isDefineCall(chainRoot, defineAliases)\n ) {\n const tagName = getDefineLiteralTag(chainRoot)\n\n if (tagName === null && keep.length > 0) {\n const line = sf.getLineAndCharacterOfPosition(\n chainRoot.getStart()\n ).line + 1\n warnings.push({\n kind: 'non-literal-tag',\n file: filename,\n line,\n message:\n 'define() call with non-literal ' +\n 'tag name cannot be matched ' +\n 'by --keep',\n })\n }\n\n if (shouldKeep(node, tagName, keep)) {\n keptLink = true\n ts.forEachChild(node, visit)\n return\n }\n\n const binding = findBindingName(node)\n if (binding) strippedBindings.add(binding)\n\n spans.push({\n start: dotPosition(node),\n end: node.getEnd(),\n })\n return\n }\n\n const line = sf.getLineAndCharacterOfPosition(\n node.getStart()\n ).line + 1\n warnings.push({\n kind: 'outside-chain',\n file: filename,\n line,\n message:\n '.render() call outside a define chain',\n })\n }\n\n ts.forEachChild(node, visit)\n }\n\n ts.forEachChild(sf, visit)\n\n spans.sort((a, b) => b.start - a.start)\n\n let result = code\n for (const span of spans) {\n const removed = result.slice(span.start, span.end)\n const newlines = removed.split('\\n').length - 1\n result = result.slice(0, span.start) +\n '\\n'.repeat(newlines) +\n result.slice(span.end)\n }\n\n if (options?.cascade) {\n result = cascadeRemove(result, filename)\n }\n\n if (strippedBindings.size > 0) {\n const resultSf = ts.createSourceFile(\n filename ?? 'input.ts',\n result,\n ts.ScriptTarget.Latest,\n true\n )\n findStrippedStaticCalls(\n resultSf, strippedBindings, warnings, filename\n )\n }\n\n // A kept render link needs the server render support module at\n // runtime (ADR-009). Appended so no existing line moves; imports\n // are hoisted, so its position does not matter.\n if (keptLink && !importsSupport(sf)) {\n result += `\\nimport '${SUPPORT}'\\n`\n }\n\n return { code: result, warnings }\n}\n\nconst SUPPORT = 'microtags/render-support'\n\nfunction importsSupport (sf:TypeScript.SourceFile):boolean {\n return sf.statements.some(node =>\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier) &&\n node.moduleSpecifier.text === SUPPORT\n )\n}\n\nfunction findDefineAliases (\n sf:TypeScript.SourceFile\n):Set<string> {\n const aliases = new Set<string>()\n ts.forEachChild(sf, node => {\n if (\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier) &&\n node.moduleSpecifier.text === 'microtags' &&\n node.importClause?.namedBindings &&\n ts.isNamedImports(\n node.importClause.namedBindings\n )\n ) {\n for (const spec of\n node.importClause.namedBindings.elements\n ) {\n const origName =\n spec.propertyName?.text ??\n spec.name.text\n if (origName === 'define') {\n aliases.add(spec.name.text)\n }\n }\n }\n })\n return aliases\n}\n\nfunction findChainRoot (\n node:TypeScript.Node\n):TypeScript.CallExpression | null {\n if (ts.isCallExpression(node)) {\n if (ts.isIdentifier(node.expression)) {\n return node\n }\n if (\n ts.isPropertyAccessExpression(node.expression)\n ) {\n return findChainRoot(\n node.expression.expression\n )\n }\n }\n return null\n}\n\nfunction isDefineCall (\n node:TypeScript.CallExpression,\n aliases:Set<string>\n):boolean {\n return ts.isIdentifier(node.expression) &&\n aliases.has(node.expression.text)\n}\n\nfunction getDefineLiteralTag (\n node:TypeScript.CallExpression\n):string | null {\n if (\n node.arguments.length > 0 &&\n ts.isStringLiteral(node.arguments[0])\n ) {\n return node.arguments[0].text\n }\n return null\n}\n\nfunction shouldKeep (\n renderCall:TypeScript.CallExpression,\n tagName:string | null,\n keep:string[]\n):boolean {\n if (renderCall.arguments.length >= 2) {\n const opts = renderCall.arguments[1]\n if (ts.isObjectLiteralExpression(opts)) {\n for (const prop of opts.properties) {\n if (\n ts.isPropertyAssignment(prop) &&\n ts.isIdentifier(prop.name) &&\n prop.name.text === 'client' &&\n prop.initializer.kind ===\n ts.SyntaxKind.TrueKeyword\n ) {\n return true\n }\n }\n }\n }\n\n if (tagName !== null && keep.includes(tagName)) {\n return true\n }\n\n return false\n}\n\nfunction dotPosition (\n renderCall:TypeScript.CallExpression\n):number {\n const pa = renderCall\n .expression as TypeScript.PropertyAccessExpression\n return pa.expression.getEnd()\n}\n\nfunction findBindingName (\n node:TypeScript.Node\n):string | null {\n let current:TypeScript.Node = node\n while (current.parent) {\n current = current.parent\n if (\n ts.isVariableDeclaration(current) &&\n ts.isIdentifier(current.name)\n ) {\n return current.name.text\n }\n }\n return null\n}\n\nfunction cascadeRemove (\n code:string,\n filename?:string\n):string {\n let changed = true\n let result = code\n while (changed) {\n changed = false\n const sf = ts.createSourceFile(\n filename ?? 'input.ts',\n result,\n ts.ScriptTarget.Latest,\n true\n )\n\n const refs = collectReferences(sf)\n const removeSpans:{\n start:number, end:number\n }[] = []\n\n ts.forEachChild(sf, node => {\n if (\n ts.isImportDeclaration(node) &&\n node.importClause\n ) {\n if (isExportedNode(node)) return\n const nb = node.importClause.namedBindings\n if (!nb) return\n if (!ts.isNamedImports(nb)) {\n const name = node.importClause.name\n if (\n name &&\n !refs.has(name.text)\n ) {\n removeSpans.push({\n start: node.getStart(),\n end: node.getEnd(),\n })\n }\n return\n }\n const dead:TypeScript.ImportSpecifier[] = []\n const live:TypeScript.ImportSpecifier[] = []\n for (const el of nb.elements) {\n if (refs.has(el.name.text)) {\n live.push(el)\n } else {\n dead.push(el)\n }\n }\n if (dead.length === 0) return\n if (live.length === 0) {\n removeSpans.push({\n start: node.getStart(),\n end: node.getEnd(),\n })\n } else {\n for (const d of dead) {\n let start = d.getStart()\n let end = d.getEnd()\n const text = result\n const after = text.slice(end)\n const before = text.slice(0, start)\n if (/^\\s*,/.test(after)) {\n end += after.match(\n /^\\s*,/\n )![0].length\n } else if (/,\\s*$/.test(before)) {\n start = before.lastIndexOf(',')\n }\n removeSpans.push({ start, end })\n }\n }\n return\n }\n\n if (ts.isVariableStatement(node)) {\n if (isExportedNode(node)) return\n const allDead = node\n .declarationList\n .declarations\n .every(d =>\n ts.isIdentifier(d.name) &&\n !refs.has(d.name.text)\n )\n if (allDead) {\n removeSpans.push({\n start: node.getStart(),\n end: node.getEnd(),\n })\n }\n return\n }\n\n if (ts.isFunctionDeclaration(node)) {\n if (isExportedNode(node)) return\n if (\n node.name &&\n !refs.has(node.name.text)\n ) {\n removeSpans.push({\n start: node.getStart(),\n end: node.getEnd(),\n })\n }\n return\n }\n\n if (ts.isClassDeclaration(node)) {\n if (isExportedNode(node)) return\n if (\n node.name &&\n !refs.has(node.name.text)\n ) {\n removeSpans.push({\n start: node.getStart(),\n end: node.getEnd(),\n })\n }\n }\n })\n\n if (removeSpans.length === 0) break\n\n changed = true\n removeSpans.sort((a, b) => b.start - a.start)\n for (const span of removeSpans) {\n const removed = result.slice(\n span.start, span.end\n )\n const newlines =\n removed.split('\\n').length - 1\n result = result.slice(0, span.start) +\n '\\n'.repeat(newlines) +\n result.slice(span.end)\n }\n }\n\n return result\n}\n\nfunction collectReferences (\n sf:TypeScript.SourceFile\n):Set<string> {\n const refs = new Set<string>()\n const declared = new Set<string>()\n\n ts.forEachChild(sf, node => {\n if (ts.isImportDeclaration(node)) {\n if (\n node.importClause?.namedBindings &&\n ts.isNamedImports(\n node.importClause.namedBindings\n )\n ) {\n for (const el of\n node.importClause\n .namedBindings.elements\n ) {\n declared.add(el.name.text)\n }\n }\n return\n }\n if (ts.isVariableStatement(node)) {\n for (const d of\n node.declarationList.declarations\n ) {\n if (ts.isIdentifier(d.name)) {\n declared.add(d.name.text)\n }\n }\n }\n if (\n ts.isFunctionDeclaration(node) && node.name\n ) {\n declared.add(node.name.text)\n }\n if (\n ts.isClassDeclaration(node) && node.name\n ) {\n declared.add(node.name.text)\n }\n })\n\n function visitRefs (node:TypeScript.Node) {\n if (\n ts.isIdentifier(node) &&\n declared.has(node.text)\n ) {\n const parent = node.parent\n if (\n ts.isImportSpecifier(parent) ||\n (\n ts.isVariableDeclaration(parent) &&\n parent.name === node\n ) ||\n (\n ts.isFunctionDeclaration(parent) &&\n parent.name === node\n ) ||\n (\n ts.isClassDeclaration(parent) &&\n parent.name === node\n )\n ) {\n return\n }\n refs.add(node.text)\n }\n ts.forEachChild(node, visitRefs)\n }\n\n ts.forEachChild(sf, node => {\n if (ts.isImportDeclaration(node)) return\n visitRefs(node)\n })\n\n return refs\n}\n\nfunction isExportedNode (\n node:TypeScript.Node\n):boolean {\n if (!ts.canHaveModifiers(node)) return false\n const mods = ts.getModifiers(node)\n if (!mods) return false\n return mods.some(\n m => m.kind === ts.SyntaxKind.ExportKeyword\n )\n}\n\nfunction findStrippedStaticCalls (\n sf:TypeScript.SourceFile,\n bindings:Set<string>,\n warnings:TransformWarning[],\n filename?:string\n) {\n function visit (node:TypeScript.Node) {\n if (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(\n node.expression\n ) &&\n node.expression.name.text === 'render' &&\n ts.isIdentifier(\n node.expression.expression\n ) &&\n bindings.has(\n node.expression.expression.text\n )\n ) {\n const line = sf.getLineAndCharacterOfPosition(\n node.getStart()\n ).line + 1\n warnings.push({\n kind: 'stripped-static',\n file: filename,\n line,\n message:\n `${node.expression.expression.text}` +\n '.render() called but render ' +\n 'was stripped',\n })\n }\n ts.forEachChild(node, visit)\n }\n ts.forEachChild(sf, visit)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AACA,SAAS,oBAAoB;;;ACG7B,IAAI;AACJ,IAAI;AACA,OAAK,UAAQ,YAAY;AAC7B,SAAS,KAAK;AAKV,QAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,MACI,SAAS,sBACT,SAAS,SAAS,cAAc,GAClC;AACE,UAAM,IAAI;AAAA,MACN;AAAA,IAEJ;AAAA,EACJ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@@ -21,7 +21,13 @@ export interface FactoryConfig<Props extends FactoryProps = FactoryProps> {
|
|
|
21
21
|
/**
|
|
22
22
|
* Create an HTMLElement subclass with the microtags lifecycle.
|
|
23
23
|
* The returned class has no Shadow DOM, tracks its own prop signals,
|
|
24
|
-
* and runs setup() on connect / cleanups
|
|
24
|
+
* and runs setup() on connect / cleanups a microtask after disconnect.
|
|
25
25
|
*/
|
|
26
26
|
export declare function factory<Props extends FactoryProps = FactoryProps>(config: FactoryConfig<Props>): typeof HTMLElement;
|
|
27
|
+
/**
|
|
28
|
+
* Bind a signal (or computed) to a declared prop of a host, so the prop
|
|
29
|
+
* reads through to it. Same as assigning the signal to the accessor,
|
|
30
|
+
* but typed: the signal's value must match the prop's type.
|
|
31
|
+
*/
|
|
32
|
+
export declare const bindProp: <H extends HTMLElement, K extends Exclude<keyof H, keyof HTMLElement>>(host: H, name: K, source: () => H[K]) => void;
|
|
27
33
|
//# sourceMappingURL=factory.d.ts.map
|
package/dist/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGR,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,MAAM,EACT,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AAY3D,yCAAyC;AACzC,MAAM,WAAW,aAAa,CAAC,KAAK,SAAS,YAAY,GAAG,YAAY;IACpE,kDAAkD;IAClD,KAAK,EAAC,KAAK,CAAA;IACX,qDAAqD;IACrD,iBAAiB,EAAC,MAAM,EAAE,CAAA;IAC1B,qCAAqC;IACrC,IAAI,CAAC,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,oCAAoC;IACpC,QAAQ,CAAC,EAAC,MAAM,CAAC,MAAM,E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