@fluixi/ts-plugin 0.1.0-alpha.11 → 0.1.0-alpha.12
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/dist/index.js +66 -73
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -376,79 +376,6 @@ var N = class {
|
|
|
376
376
|
function b(e, t = {}) {
|
|
377
377
|
return new N(e, t).parse();
|
|
378
378
|
}
|
|
379
|
-
function I(e) {
|
|
380
|
-
let t = [], i2 = 0;
|
|
381
|
-
return e.forEach((n, r) => {
|
|
382
|
-
t.push({ kind: "static", text: n, start: i2 }), i2 += n.length, r < e.length - 1 && t.push({ kind: "hole", index: r, start: i2, end: i2 });
|
|
383
|
-
}), t;
|
|
384
|
-
}
|
|
385
|
-
function Q(e, t = {}) {
|
|
386
|
-
return b(I(e), t);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// src/collect.ts
|
|
390
|
-
var UNUSED_CODES = /* @__PURE__ */ new Set([6133, 6196, 6198, 6199, 6205, 6138, 6192]);
|
|
391
|
-
function isUnusedCode(code) {
|
|
392
|
-
return UNUSED_CODES.has(code);
|
|
393
|
-
}
|
|
394
|
-
function usedComponentTags(ts, sourceFile) {
|
|
395
|
-
const tags = /* @__PURE__ */ new Set();
|
|
396
|
-
const visit = (node) => {
|
|
397
|
-
if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && (node.tag.text === "html" || node.tag.text === "svg")) {
|
|
398
|
-
collectTags(Q(templateStatics(ts, node.template)).root.children, tags);
|
|
399
|
-
}
|
|
400
|
-
ts.forEachChild(node, visit);
|
|
401
|
-
};
|
|
402
|
-
visit(sourceFile);
|
|
403
|
-
return tags;
|
|
404
|
-
}
|
|
405
|
-
function templateStatics(ts, tpl) {
|
|
406
|
-
if (ts.isNoSubstitutionTemplateLiteral(tpl)) return [tpl.text];
|
|
407
|
-
const out = [tpl.head.text];
|
|
408
|
-
for (const span of tpl.templateSpans) out.push(span.literal.text);
|
|
409
|
-
return out;
|
|
410
|
-
}
|
|
411
|
-
function collectTags(nodes, out) {
|
|
412
|
-
for (const node of nodes) {
|
|
413
|
-
if (node.kind === "Component" && node.tag) out.add(node.tag.split(".")[0]);
|
|
414
|
-
if ("children" in node && node.children) collectTags(node.children, out);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
function shouldSuppress(ts, sourceFile, diagnostic, used) {
|
|
418
|
-
if (diagnostic.start === void 0 || !isUnusedCode(diagnostic.code)) return false;
|
|
419
|
-
const spanText = sourceFile.text.substr(diagnostic.start, diagnostic.length ?? 0);
|
|
420
|
-
const decl = importDeclarationAt(ts, sourceFile, diagnostic.start);
|
|
421
|
-
if (decl) {
|
|
422
|
-
const names = importedNames(ts, decl);
|
|
423
|
-
if (names.includes(spanText)) return used.has(spanText);
|
|
424
|
-
return names.some((n) => used.has(n));
|
|
425
|
-
}
|
|
426
|
-
return used.has(spanText);
|
|
427
|
-
}
|
|
428
|
-
function importDeclarationAt(ts, sourceFile, pos) {
|
|
429
|
-
let found;
|
|
430
|
-
const visit = (node) => {
|
|
431
|
-
if (found) return;
|
|
432
|
-
if (ts.isImportDeclaration(node) && node.getStart(sourceFile) <= pos && node.getEnd() >= pos) {
|
|
433
|
-
found = node;
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
ts.forEachChild(node, visit);
|
|
437
|
-
};
|
|
438
|
-
visit(sourceFile);
|
|
439
|
-
return found;
|
|
440
|
-
}
|
|
441
|
-
function importedNames(ts, decl) {
|
|
442
|
-
const bindings = decl.importClause?.namedBindings;
|
|
443
|
-
const names = [];
|
|
444
|
-
if (decl.importClause?.name) names.push(decl.importClause.name.text);
|
|
445
|
-
if (bindings && ts.isNamedImports(bindings)) {
|
|
446
|
-
for (const el of bindings.elements) names.push(el.name.text);
|
|
447
|
-
} else if (bindings && ts.isNamespaceImport(bindings)) {
|
|
448
|
-
names.push(bindings.name.text);
|
|
449
|
-
}
|
|
450
|
-
return names;
|
|
451
|
-
}
|
|
452
379
|
|
|
453
380
|
// src/pieces.ts
|
|
454
381
|
function rawContent(ts, node, sf) {
|
|
@@ -491,9 +418,17 @@ function parseCached(ts, sf, tpl) {
|
|
|
491
418
|
return result;
|
|
492
419
|
}
|
|
493
420
|
var templates = /* @__PURE__ */ new WeakMap();
|
|
421
|
+
function mayHaveTemplate(text) {
|
|
422
|
+
return text.includes("html`") || text.includes("svg`");
|
|
423
|
+
}
|
|
424
|
+
var NONE = [];
|
|
494
425
|
function templatesIn(ts, sf) {
|
|
495
426
|
const hit = templates.get(sf);
|
|
496
427
|
if (hit) return hit;
|
|
428
|
+
if (!mayHaveTemplate(sf.text)) {
|
|
429
|
+
templates.set(sf, NONE);
|
|
430
|
+
return NONE;
|
|
431
|
+
}
|
|
497
432
|
const found = [];
|
|
498
433
|
const visit = (node) => {
|
|
499
434
|
if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && (node.tag.text === "html" || node.tag.text === "svg")) {
|
|
@@ -516,6 +451,64 @@ function templateAtCached(ts, sf, pos) {
|
|
|
516
451
|
return match;
|
|
517
452
|
}
|
|
518
453
|
|
|
454
|
+
// src/collect.ts
|
|
455
|
+
var UNUSED_CODES = /* @__PURE__ */ new Set([6133, 6196, 6198, 6199, 6205, 6138, 6192]);
|
|
456
|
+
function isUnusedCode(code) {
|
|
457
|
+
return UNUSED_CODES.has(code);
|
|
458
|
+
}
|
|
459
|
+
var tagCache = /* @__PURE__ */ new WeakMap();
|
|
460
|
+
function usedComponentTags(ts, sourceFile) {
|
|
461
|
+
const hit = tagCache.get(sourceFile);
|
|
462
|
+
if (hit) return hit;
|
|
463
|
+
const tags = /* @__PURE__ */ new Set();
|
|
464
|
+
for (const template of templatesIn(ts, sourceFile)) {
|
|
465
|
+
collectTags(parseCached(ts, sourceFile, template.template).root.children, tags);
|
|
466
|
+
}
|
|
467
|
+
tagCache.set(sourceFile, tags);
|
|
468
|
+
return tags;
|
|
469
|
+
}
|
|
470
|
+
function collectTags(nodes, out) {
|
|
471
|
+
for (const node of nodes) {
|
|
472
|
+
if (node.kind === "Component" && node.tag) out.add(node.tag.split(".")[0]);
|
|
473
|
+
if ("children" in node && node.children) collectTags(node.children, out);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
function shouldSuppress(ts, sourceFile, diagnostic, used) {
|
|
477
|
+
if (diagnostic.start === void 0 || !isUnusedCode(diagnostic.code)) return false;
|
|
478
|
+
const spanText = sourceFile.text.substr(diagnostic.start, diagnostic.length ?? 0);
|
|
479
|
+
const decl = importDeclarationAt(ts, sourceFile, diagnostic.start);
|
|
480
|
+
if (decl) {
|
|
481
|
+
const names = importedNames(ts, decl);
|
|
482
|
+
if (names.includes(spanText)) return used.has(spanText);
|
|
483
|
+
return names.some((n) => used.has(n));
|
|
484
|
+
}
|
|
485
|
+
return used.has(spanText);
|
|
486
|
+
}
|
|
487
|
+
function importDeclarationAt(ts, sourceFile, pos) {
|
|
488
|
+
let found;
|
|
489
|
+
const visit = (node) => {
|
|
490
|
+
if (found) return;
|
|
491
|
+
if (ts.isImportDeclaration(node) && node.getStart(sourceFile) <= pos && node.getEnd() >= pos) {
|
|
492
|
+
found = node;
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
ts.forEachChild(node, visit);
|
|
496
|
+
};
|
|
497
|
+
visit(sourceFile);
|
|
498
|
+
return found;
|
|
499
|
+
}
|
|
500
|
+
function importedNames(ts, decl) {
|
|
501
|
+
const bindings = decl.importClause?.namedBindings;
|
|
502
|
+
const names = [];
|
|
503
|
+
if (decl.importClause?.name) names.push(decl.importClause.name.text);
|
|
504
|
+
if (bindings && ts.isNamedImports(bindings)) {
|
|
505
|
+
for (const el of bindings.elements) names.push(el.name.text);
|
|
506
|
+
} else if (bindings && ts.isNamespaceImport(bindings)) {
|
|
507
|
+
names.push(bindings.name.text);
|
|
508
|
+
}
|
|
509
|
+
return names;
|
|
510
|
+
}
|
|
511
|
+
|
|
519
512
|
// ../compiler/dist/resolve/builtins.mjs
|
|
520
513
|
var s = ["Show", "For", "Index", "Switch", "Match", "Portal", "Dynamic", "ErrorBoundary"];
|
|
521
514
|
var i = ["Suspense", "SuspenseList", "Await"];
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluixi/ts-plugin",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/",
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
|
-
"description": "
|
|
10
|
+
"description": "gives html`` templates the editor support JSX already gets; a component used only as a tag is no longer reported as unused",
|
|
11
11
|
"type": "commonjs",
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
],
|
|
17
17
|
"main": "./dist/index.js",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@fluixi/template-parser": "0.1.0-alpha.
|
|
20
|
-
"@fluixi/compiler": "1.0.0-alpha.
|
|
19
|
+
"@fluixi/template-parser": "0.1.0-alpha.4",
|
|
20
|
+
"@fluixi/compiler": "1.0.0-alpha.78"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"esbuild": "^0.24.0",
|