@bascik/language-server 0.1.0-rc.2 → 0.1.0-rc.4
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/analyzer.d.ts +21 -5
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +702 -361
- package/dist/analyzer.js.map +1 -1
- package/dist/api-rules.d.ts +2 -0
- package/dist/api-rules.d.ts.map +1 -1
- package/dist/api-rules.js +17 -2
- package/dist/api-rules.js.map +1 -1
- package/dist/bin.js +5 -8
- package/dist/bin.js.map +1 -1
- package/dist/check.d.ts +50 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +173 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +43 -100
- package/dist/cli.js.map +1 -1
- package/dist/compatibility-rules.json +41 -8
- package/dist/component-metadata.d.ts +1 -1
- package/dist/component-metadata.d.ts.map +1 -1
- package/dist/component-metadata.js +32 -26
- package/dist/component-metadata.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -5
- package/dist/config.js.map +1 -1
- package/dist/directive-rules.d.ts +31 -0
- package/dist/directive-rules.d.ts.map +1 -0
- package/dist/directive-rules.js +74 -0
- package/dist/directive-rules.js.map +1 -0
- package/dist/ignore-comments.d.ts.map +1 -1
- package/dist/ignore-comments.js +13 -9
- package/dist/ignore-comments.js.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/dist/module-specifiers.d.ts.map +1 -1
- package/dist/module-specifiers.js +77 -40
- package/dist/module-specifiers.js.map +1 -1
- package/dist/project.d.ts +13 -1
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +59 -30
- package/dist/project.js.map +1 -1
- package/dist/rules.d.ts +29 -2
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +139 -1
- package/dist/rules.js.map +1 -1
- package/dist/server-script-rules.d.ts +2 -2
- package/dist/server-script-rules.d.ts.map +1 -1
- package/dist/server-script-rules.js +96 -80
- package/dist/server-script-rules.js.map +1 -1
- package/dist/server.d.ts +39 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +245 -26
- package/dist/server.js.map +1 -1
- package/dist/start.d.ts +7 -0
- package/dist/start.d.ts.map +1 -0
- package/dist/start.js +12 -0
- package/dist/start.js.map +1 -0
- package/package.json +12 -8
package/dist/cli.js
CHANGED
|
@@ -1,121 +1,64 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import * as path from 'node:path';
|
|
4
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
-
import { DiagnosticSeverity } from 'vscode-languageserver';
|
|
6
|
-
import { buildSnapshot } from './project.js';
|
|
7
|
-
import { createDiagnostics } from './analyzer.js';
|
|
2
|
+
import { CheckUsageError, checkFiles, formatDiagnostic } from "./check.js";
|
|
8
3
|
function parseArgs(args) {
|
|
9
4
|
let targetPath;
|
|
5
|
+
let projectPath;
|
|
6
|
+
let fix = false;
|
|
10
7
|
for (let i = 0; i < args.length; i++) {
|
|
11
8
|
const arg = args[i];
|
|
12
|
-
if (arg ===
|
|
9
|
+
if (arg === "--stdio" || arg === "--check") {
|
|
13
10
|
// Handled by main bin launcher
|
|
14
11
|
continue;
|
|
15
12
|
}
|
|
16
|
-
if (
|
|
13
|
+
if (arg === "--fix") {
|
|
14
|
+
fix = true;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (arg === "--project") {
|
|
18
|
+
projectPath = args[++i];
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (arg.startsWith("--project=")) {
|
|
22
|
+
projectPath = arg.slice("--project=".length);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (!arg.startsWith("-")) {
|
|
17
26
|
targetPath = arg;
|
|
18
27
|
}
|
|
19
28
|
}
|
|
20
|
-
return {
|
|
21
|
-
cwd: process.cwd(),
|
|
22
|
-
targetPath,
|
|
23
|
-
};
|
|
29
|
+
return { targetPath, projectPath, fix };
|
|
24
30
|
}
|
|
31
|
+
/** `bascik-language-server --check`: per-file diagnostics over a folder or file, printed one per line. */
|
|
25
32
|
export async function runCliCheck(args = process.argv.slice(2)) {
|
|
26
|
-
const {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
curr = path.dirname(curr);
|
|
39
|
-
}
|
|
40
|
-
const stat = fs.existsSync(targetRoot) ? fs.statSync(targetRoot) : undefined;
|
|
41
|
-
if (!stat) {
|
|
42
|
-
console.error(`Error: Path does not exist: ${targetRoot}`);
|
|
43
|
-
return 1;
|
|
33
|
+
const { targetPath, projectPath, fix } = parseArgs(args);
|
|
34
|
+
const cwd = process.cwd();
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
result = await checkFiles({
|
|
38
|
+
cwd,
|
|
39
|
+
targets: targetPath ? [targetPath] : undefined,
|
|
40
|
+
projectPath,
|
|
41
|
+
fix,
|
|
42
|
+
});
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
else {
|
|
50
|
-
// Recursively collect .html, .css, .js, .ts
|
|
51
|
-
const stack = [targetRoot];
|
|
52
|
-
while (stack.length > 0) {
|
|
53
|
-
const dir = stack.pop();
|
|
54
|
-
let entries = [];
|
|
55
|
-
try {
|
|
56
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
for (const entry of entries) {
|
|
62
|
-
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist') {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const full = path.join(dir, entry.name);
|
|
66
|
-
if (entry.isDirectory()) {
|
|
67
|
-
stack.push(full);
|
|
68
|
-
}
|
|
69
|
-
else if (entry.isFile() &&
|
|
70
|
-
/\.(html|css|js|ts)$/i.test(entry.name) &&
|
|
71
|
-
!/\.(test|spec)\.[a-z0-9]+$/i.test(entry.name)) {
|
|
72
|
-
filesToCheck.push(full);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const snapshot = await buildSnapshot(projectRoot);
|
|
78
|
-
let errorCount = 0;
|
|
79
|
-
let warningCount = 0;
|
|
80
|
-
for (const filePath of filesToCheck) {
|
|
81
|
-
let content;
|
|
82
|
-
try {
|
|
83
|
-
content = fs.readFileSync(filePath, 'utf8');
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const ext = path.extname(filePath).slice(1).toLowerCase();
|
|
89
|
-
const languageId = ext === 'html'
|
|
90
|
-
? 'html'
|
|
91
|
-
: ext === 'css'
|
|
92
|
-
? 'css'
|
|
93
|
-
: ext === 'ts'
|
|
94
|
-
? 'typescript'
|
|
95
|
-
: 'javascript';
|
|
96
|
-
const doc = TextDocument.create(`file://${filePath}`, languageId, 1, content);
|
|
97
|
-
const diags = createDiagnostics(doc, filePath, snapshot);
|
|
98
|
-
if (diags.length > 0) {
|
|
99
|
-
const rel = path.relative(cwd, filePath);
|
|
100
|
-
for (const d of diags) {
|
|
101
|
-
const line = d.range.start.line + 1;
|
|
102
|
-
const col = d.range.start.character + 1;
|
|
103
|
-
const isError = d.severity === DiagnosticSeverity.Error;
|
|
104
|
-
const prefix = isError ? '\x1b[31merror\x1b[0m' : '\x1b[33mwarning\x1b[0m';
|
|
105
|
-
if (isError)
|
|
106
|
-
errorCount++;
|
|
107
|
-
else
|
|
108
|
-
warningCount++;
|
|
109
|
-
const codeStr = d.code ? ` \x1b[90m(${d.code})\x1b[0m` : '';
|
|
110
|
-
console.log(`${rel}:${line}:${col} - ${prefix}:${codeStr} ${d.message}`);
|
|
111
|
-
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof CheckUsageError) {
|
|
46
|
+
console.error(`Error: ${error.message}`);
|
|
47
|
+
return 1;
|
|
112
48
|
}
|
|
49
|
+
throw error;
|
|
113
50
|
}
|
|
114
|
-
|
|
115
|
-
console.log(
|
|
51
|
+
for (const diagnostic of result.diagnostics)
|
|
52
|
+
console.log(formatDiagnostic(diagnostic));
|
|
53
|
+
const errorCount = result.diagnostics.filter((d) => d.severity === "error").length;
|
|
54
|
+
const warningCount = result.diagnostics.filter((d) => d.severity === "warning").length;
|
|
55
|
+
const hintCount = result.diagnostics.length - errorCount - warningCount;
|
|
56
|
+
if (errorCount > 0 || warningCount > 0 || hintCount > 0) {
|
|
57
|
+
const hints = hintCount > 0 ? `, ${hintCount} hint${hintCount === 1 ? "" : "s"}` : "";
|
|
58
|
+
console.log(`\nFound ${errorCount} error${errorCount === 1 ? "" : "s"}, ${warningCount} warning${warningCount === 1 ? "" : "s"}${hints}.`);
|
|
116
59
|
}
|
|
117
60
|
else {
|
|
118
|
-
console.log(`\x1b[32m✔ No Bascik diagnostics found in ${
|
|
61
|
+
console.log(`\x1b[32m✔ No Bascik diagnostics found in ${result.filesChecked} file${result.filesChecked === 1 ? "" : "s"}.\x1b[0m`);
|
|
119
62
|
}
|
|
120
63
|
return errorCount > 0 ? 1 : 0;
|
|
121
64
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAQ3E,SAAS,S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,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,YAAY,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,GAAG,CAC9H,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CACT,4CAA4C,MAAM,CAAC,YAAY,QAAQ,MAAM,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,UAAU,CACtH,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"id": "css-id-attribute-selector",
|
|
4
|
+
"kind": "css",
|
|
5
|
+
"pattern": "(^|[,{}\\s])\\[id(?:\\s*[~|^$*]?=[^\\]]+)?\\]",
|
|
6
|
+
"flags": "gm",
|
|
7
|
+
"message": "[id] attribute selectors cannot be scoped without DOM wrapping and are stripped at compile time.",
|
|
8
|
+
"suggestion": "Use a CSS #id selector or class selector instead.",
|
|
9
|
+
"severity": "error"
|
|
10
|
+
},
|
|
2
11
|
{
|
|
3
12
|
"id": "css-attribute-selector",
|
|
4
13
|
"kind": "css",
|
|
5
|
-
"pattern": "(^|,)\\s*\\[[A-Za-z0-9_-]+(?:\\s*(?:[~|^$*]?=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\]\"'\\s]+))?)?\\]",
|
|
14
|
+
"pattern": "(^|,)\\s*\\[(?!id\\b)[A-Za-z0-9_-]+(?:\\s*(?:[~|^$*]?=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\]\"'\\s]+))?)?\\](?!(?:[^(),{]|\\([^)]*\\))*\\.[A-Za-z_][\\w-]*)",
|
|
6
15
|
"flags": "gm",
|
|
7
16
|
"message": "Standalone attribute selectors are not scoped by Bascik and may leak globally.",
|
|
8
|
-
"suggestion": "Anchor the selector with a scoped class (for example .card[data-state]) or switch to a class-only selector."
|
|
17
|
+
"suggestion": "Anchor the selector with a scoped class (for example .card[data-state]) or switch to a class-only selector.",
|
|
18
|
+
"severity": "error"
|
|
9
19
|
},
|
|
10
20
|
{
|
|
11
21
|
"id": "css-is-element-names",
|
|
12
22
|
"kind": "css",
|
|
13
|
-
"pattern": ":(?:is|where|has)\\s*\\((?:[^)]
|
|
23
|
+
"pattern": "(?<!\\.[A-Za-z_][\\w-]*(?:\\s+[>+~]?\\s*|\\s+)):(?:is|where|has)\\s*\\((?:[^)]*(?<![.#\\w-])(?:p|div|span|section|article|main|header|footer|aside|nav|ul|ol|li|a|button|input|textarea|select|form|img|svg|path|h[1-6])(?![\\w-])[^)]*)\\)",
|
|
14
24
|
"flags": "gi",
|
|
15
25
|
"message": "Element names inside :is(), :where(), or :has() are not converted by Bascik.",
|
|
16
|
-
"suggestion": "Use a class selector inside the pseudo-class instead of bare element names."
|
|
26
|
+
"suggestion": "Use a class selector inside the pseudo-class instead of bare element names.",
|
|
27
|
+
"severity": "error"
|
|
17
28
|
},
|
|
18
29
|
{
|
|
19
30
|
"id": "js-id-setter",
|
|
@@ -21,7 +32,8 @@
|
|
|
21
32
|
"pattern": "\\.id\\s*=\\s*(?:[\"'`]|\\w)",
|
|
22
33
|
"flags": "g",
|
|
23
34
|
"message": "Runtime .id assignment is not rewritten by Bascik. That will not match the scoped attribute.",
|
|
24
|
-
"suggestion": "Capture the element once with getElementById() and operate on that reference."
|
|
35
|
+
"suggestion": "Capture the element once with getElementById() and operate on that reference.",
|
|
36
|
+
"severity": "error"
|
|
25
37
|
},
|
|
26
38
|
{
|
|
27
39
|
"id": "js-attribute-selector",
|
|
@@ -29,7 +41,8 @@
|
|
|
29
41
|
"pattern": "querySelector\\s*\\(\\s*[\"'][^\"']*\\[[^\\]]+\\][^\"']*[\"']\\s*\\)|querySelectorAll\\s*\\(\\s*[\"'][^\"']*\\[[^\\]]+\\][^\"']*[\"']\\s*\\)",
|
|
30
42
|
"flags": "g",
|
|
31
43
|
"message": "Attribute selectors are not rewritten by Bascik. Use an id or class selector instead.",
|
|
32
|
-
"suggestion": "Use getElementById() or a static class selector that Bascik can rewrite."
|
|
44
|
+
"suggestion": "Use getElementById() or a static class selector that Bascik can rewrite.",
|
|
45
|
+
"severity": "error"
|
|
33
46
|
},
|
|
34
47
|
{
|
|
35
48
|
"id": "js-template-classname",
|
|
@@ -37,7 +50,8 @@
|
|
|
37
50
|
"pattern": "className\\s*=\\s*`[^`]*\\$\\{[^}]+\\}[^`]*`|classList\\.replace\\s*\\(\\s*[^,]+,\\s*`[^`]*\\$\\{[^}]+\\}[^`]*`\\s*\\)",
|
|
38
51
|
"flags": "g",
|
|
39
52
|
"message": "Template-literal class names are not rewritten safely at build time.",
|
|
40
|
-
"suggestion": "Use classList.add(), classList.remove(), or a static string instead."
|
|
53
|
+
"suggestion": "Use classList.add(), classList.remove(), or a static string instead.",
|
|
54
|
+
"severity": "error"
|
|
41
55
|
},
|
|
42
56
|
{
|
|
43
57
|
"id": "js-style-setproperty",
|
|
@@ -45,6 +59,25 @@
|
|
|
45
59
|
"pattern": "style\\.setProperty\\s*\\(\\s*[\"']--",
|
|
46
60
|
"flags": "g",
|
|
47
61
|
"message": "Runtime CSS custom property names are not rewritten by Bascik.",
|
|
48
|
-
"suggestion": "Use the scoped property name explicitly or keep the runtime logic on the resulting element reference."
|
|
62
|
+
"suggestion": "Use the scoped property name explicitly or keep the runtime logic on the resulting element reference.",
|
|
63
|
+
"severity": "error"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "js-unsupported-dom-methods",
|
|
67
|
+
"kind": "js",
|
|
68
|
+
"severity": "error",
|
|
69
|
+
"pattern": "\\.(?:removeAttribute|hasAttribute|toggleAttribute)\\s*\\(\\s*[\"'`](?:class|id|name)[\"'`]",
|
|
70
|
+
"flags": "g",
|
|
71
|
+
"message": "DOM methods taking attribute names (removeAttribute, hasAttribute, toggleAttribute) are not value-scoped by Bascik.",
|
|
72
|
+
"suggestion": "Operate directly on element classList or property references."
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "js-document-class-query",
|
|
76
|
+
"kind": "js",
|
|
77
|
+
"severity": "warning",
|
|
78
|
+
"pattern": "\\bdocument\\.(?:querySelector\\s*\\(\\s*([\"'`])(?![^\"'`]*[#$])[^\"'`]*?\\.[a-zA-Z_][\\w-]*[^\"'`]*\\1\\s*\\)|getElementsByClassName\\s*\\(\\s*([\"'`])[^\"'`$]+\\2\\s*\\)\\s*(?:\\[\\s*0\\s*\\]|\\.item\\s*\\(\\s*0\\s*\\)))",
|
|
79
|
+
"flags": "g",
|
|
80
|
+
"message": "A document-level lookup of one element by class (document.querySelector('.class'), document.getElementsByClassName('class')[0]) is document-wide under deduplicateCss and returns the first instance's element when a component is used multiple times.",
|
|
81
|
+
"suggestion": "Use document.getElementById() or rootEl.querySelector() for per-instance lookup."
|
|
49
82
|
}
|
|
50
83
|
]
|
|
@@ -3,7 +3,7 @@ export interface ComponentMetadataMember {
|
|
|
3
3
|
description?: string;
|
|
4
4
|
}
|
|
5
5
|
export interface ComponentMetadataDiagnostic {
|
|
6
|
-
code:
|
|
6
|
+
code: "component-metadata-duplicate-annotation" | "component-metadata-undeclared-annotation";
|
|
7
7
|
message: string;
|
|
8
8
|
start: number;
|
|
9
9
|
end: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-metadata.d.ts","sourceRoot":"","sources":["../src/component-metadata.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EACA,yCAAyC,GACzC,0CAA0C,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,2BAA2B,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,6BAA6B;IAC5C,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;
|
|
1
|
+
{"version":3,"file":"component-metadata.d.ts","sourceRoot":"","sources":["../src/component-metadata.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EACA,yCAAyC,GACzC,0CAA0C,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,2BAA2B,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,6BAA6B;IAC5C,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAuKD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,6BAAkC,GAC1C,iBAAiB,CA8DnB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function maskNonMarkup(source) {
|
|
2
2
|
return source
|
|
3
|
-
.replace(/<!--[\s\S]*?(?:-->|$)/g, (match) =>
|
|
4
|
-
.replace(/(<(script|style|textarea)\
|
|
3
|
+
.replace(/<!--[\s\S]*?(?:-->|$)/g, (match) => " ".repeat(match.length))
|
|
4
|
+
.replace(/(<(script|style|textarea)(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)(<\/\2(?:[\t\n\f\r /][^>]*)?>)/gi, (_match, openTag, _name, body, closeTag) => `${openTag}${" ".repeat(body.length)}${closeTag}`);
|
|
5
5
|
}
|
|
6
6
|
function inferMembers(source) {
|
|
7
7
|
const masked = maskNonMarkup(source);
|
|
@@ -26,8 +26,8 @@ function inferMembers(source) {
|
|
|
26
26
|
propOffsets.set(normalized, { name, offset });
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
for (const match of masked.matchAll(/data-bascik-(?:attr-[\w:.-]+|text|html)\s*=\s*(?:"([\w-]+)"|'([\w-]+)')/gi)) {
|
|
30
|
-
const name = match[1] ?? match[2];
|
|
29
|
+
for (const match of masked.matchAll(/data-bascik-(?:attr-[\w:.-]+|text|html)\s*=\s*(?:"([\w-]+)"|'([\w-]+)'|([\w-]+))/gi)) {
|
|
30
|
+
const name = match[1] ?? match[2] ?? match[3];
|
|
31
31
|
if (name) {
|
|
32
32
|
const normalized = name.toLowerCase();
|
|
33
33
|
const offset = (match.index ?? 0) + match[0].lastIndexOf(name);
|
|
@@ -36,10 +36,10 @@ function inferMembers(source) {
|
|
|
36
36
|
propOffsets.set(normalized, { name, offset });
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
const slotRegex = /data-bascik-slot(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s
|
|
39
|
+
const slotRegex = /data-bascik-slot(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`/>]+)))?/gi;
|
|
40
40
|
for (const match of masked.matchAll(slotRegex)) {
|
|
41
41
|
const name = match[1] ?? match[2] ?? match[3];
|
|
42
|
-
if (name === undefined || name.trim() ===
|
|
42
|
+
if (name === undefined || name.trim() === "") {
|
|
43
43
|
hasDefaultSlot = true;
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
@@ -53,11 +53,11 @@ function inferMembers(source) {
|
|
|
53
53
|
function findMetadataComment(source) {
|
|
54
54
|
let offset = source.charCodeAt(0) === 0xfeff ? 1 : 0;
|
|
55
55
|
while (offset < source.length) {
|
|
56
|
-
const whitespace = /^\s*/.exec(source.slice(offset))?.[0] ??
|
|
56
|
+
const whitespace = /^\s*/.exec(source.slice(offset))?.[0] ?? "";
|
|
57
57
|
offset += whitespace.length;
|
|
58
|
-
if (!source.startsWith(
|
|
58
|
+
if (!source.startsWith("<!--", offset))
|
|
59
59
|
return undefined;
|
|
60
|
-
const close = source.indexOf(
|
|
60
|
+
const close = source.indexOf("-->", offset + 4);
|
|
61
61
|
if (close < 0)
|
|
62
62
|
return undefined;
|
|
63
63
|
const bodyStart = offset + 4;
|
|
@@ -81,15 +81,18 @@ function parseMetadataComment(source) {
|
|
|
81
81
|
const descriptionLines = [];
|
|
82
82
|
const lineRegex = /.*(?:\r?\n|$)/g;
|
|
83
83
|
for (const lineMatch of content.matchAll(lineRegex)) {
|
|
84
|
-
const rawLine = lineMatch[0].replace(/\r?\n$/,
|
|
84
|
+
const rawLine = lineMatch[0].replace(/\r?\n$/, "");
|
|
85
85
|
if (!rawLine && (lineMatch.index ?? 0) === content.length)
|
|
86
86
|
continue;
|
|
87
|
-
const cleaned = rawLine.replace(/^\s*\*?\s?/,
|
|
87
|
+
const cleaned = rawLine.replace(/^\s*\*?\s?/, "").trimEnd();
|
|
88
88
|
const annotationMatch = /^@(prop|slot)\s+([\w-]+)(?:\s+-\s*(.*))?\s*$/.exec(cleaned);
|
|
89
89
|
if (annotationMatch) {
|
|
90
90
|
const name = annotationMatch[2];
|
|
91
91
|
const rawNameOffset = rawLine.indexOf(name);
|
|
92
|
-
const start = comment.bodyStart +
|
|
92
|
+
const start = comment.bodyStart +
|
|
93
|
+
contentStart +
|
|
94
|
+
(lineMatch.index ?? 0) +
|
|
95
|
+
Math.max(rawNameOffset, 0);
|
|
93
96
|
annotations.push({
|
|
94
97
|
kind: annotationMatch[1],
|
|
95
98
|
name,
|
|
@@ -98,30 +101,32 @@ function parseMetadataComment(source) {
|
|
|
98
101
|
end: start + name.length,
|
|
99
102
|
});
|
|
100
103
|
}
|
|
101
|
-
else if (cleaned && !cleaned.startsWith(
|
|
104
|
+
else if (cleaned && !cleaned.startsWith("@")) {
|
|
102
105
|
descriptionLines.push(cleaned);
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
return {
|
|
106
|
-
description: descriptionLines.join(
|
|
109
|
+
description: descriptionLines.join(" ").trim() || undefined,
|
|
107
110
|
annotations,
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
113
|
export function analyzeComponentSource(source, options = {}) {
|
|
111
114
|
const inferred = inferMembers(source);
|
|
112
115
|
const documented = parseMetadataComment(source);
|
|
113
|
-
const props = inferred.props.map(({ name }) => ({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const props = inferred.props.map(({ name }) => ({
|
|
117
|
+
name,
|
|
118
|
+
}));
|
|
119
|
+
const slots = inferred.slots.map(({ name }) => ({
|
|
120
|
+
name,
|
|
121
|
+
}));
|
|
122
|
+
const defaultSlot = inferred.hasDefaultSlot ? { name: "default" } : undefined;
|
|
118
123
|
const diagnostics = [];
|
|
119
124
|
const seenAnnotations = new Set();
|
|
120
125
|
for (const annotation of documented.annotations) {
|
|
121
126
|
const key = `${annotation.kind}:${annotation.name.toLowerCase()}`;
|
|
122
127
|
if (seenAnnotations.has(key)) {
|
|
123
128
|
diagnostics.push({
|
|
124
|
-
code:
|
|
129
|
+
code: "component-metadata-duplicate-annotation",
|
|
125
130
|
message: `Duplicate @${annotation.kind} annotation for "${annotation.name}". The first annotation is used.`,
|
|
126
131
|
start: annotation.start,
|
|
127
132
|
end: annotation.end,
|
|
@@ -129,15 +134,15 @@ export function analyzeComponentSource(source, options = {}) {
|
|
|
129
134
|
continue;
|
|
130
135
|
}
|
|
131
136
|
seenAnnotations.add(key);
|
|
132
|
-
const member = annotation.kind ===
|
|
137
|
+
const member = annotation.kind === "prop"
|
|
133
138
|
? props.find((candidate) => candidate.name.toLowerCase() === annotation.name.toLowerCase())
|
|
134
|
-
: annotation.name.toLowerCase() ===
|
|
139
|
+
: annotation.name.toLowerCase() === "default"
|
|
135
140
|
? defaultSlot
|
|
136
141
|
: slots.find((candidate) => candidate.name.toLowerCase() === annotation.name.toLowerCase());
|
|
137
142
|
if (!member) {
|
|
138
143
|
diagnostics.push({
|
|
139
|
-
code:
|
|
140
|
-
message: `@${annotation.kind} annotation "${annotation.name}" does not match a ${annotation.kind ===
|
|
144
|
+
code: "component-metadata-undeclared-annotation",
|
|
145
|
+
message: `@${annotation.kind} annotation "${annotation.name}" does not match a ${annotation.kind === "prop" ? "prop" : "slot"} declared in this component's markup.`,
|
|
141
146
|
start: annotation.start,
|
|
142
147
|
end: annotation.end,
|
|
143
148
|
});
|
|
@@ -150,8 +155,9 @@ export function analyzeComponentSource(source, options = {}) {
|
|
|
150
155
|
props,
|
|
151
156
|
slots,
|
|
152
157
|
defaultSlot,
|
|
153
|
-
hasStyles: options.hasCompanionStyles === true ||
|
|
154
|
-
|
|
158
|
+
hasStyles: options.hasCompanionStyles === true ||
|
|
159
|
+
/<style(?=[\t\n\f\r />])/i.test(source),
|
|
160
|
+
hasScripts: /<script(?=[\t\n\f\r />])/i.test(source),
|
|
155
161
|
diagnostics,
|
|
156
162
|
};
|
|
157
163
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../src/component-metadata.ts"],"names":[],"mappings":"AAyCA,SAAS,aAAa,CAAC,MAAc;IACnC,OAAO,MAAM;SACV,OAAO,CAAC,wBAAwB,EAAE,CAAC,KAAK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ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE;QACZ,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;CACH;AAED,wBAAgB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,WAAW,CAAC,EAAE;QACZ,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;CACH;AAED,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,GAClB,qBAAqB,CA8BvB"}
|
package/dist/config.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
3
|
export function loadExtensionConfig(projectRoot) {
|
|
4
|
-
const configFiles = [
|
|
4
|
+
const configFiles = [
|
|
5
|
+
"bascik.ext.json",
|
|
6
|
+
".bascikrc.json",
|
|
7
|
+
"bascik.ext.ts",
|
|
8
|
+
"bascik.ext.js",
|
|
9
|
+
];
|
|
5
10
|
for (const filename of configFiles) {
|
|
6
11
|
const fullPath = path.join(projectRoot, filename);
|
|
7
12
|
if (fs.existsSync(fullPath)) {
|
|
8
13
|
try {
|
|
9
|
-
const raw = fs.readFileSync(fullPath,
|
|
10
|
-
if (filename.endsWith(
|
|
14
|
+
const raw = fs.readFileSync(fullPath, "utf8");
|
|
15
|
+
if (filename.endsWith(".json")) {
|
|
11
16
|
return JSON.parse(raw);
|
|
12
17
|
}
|
|
13
18
|
else {
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAclC,MAAM,UAAU,mBAAmB,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAclC,MAAM,UAAU,mBAAmB,CACjC,WAAmB;IAEnB,MAAM,WAAW,GAAG;QAClB,iBAAiB;QACjB,gBAAgB;QAChB,eAAe;QACf,eAAe;KAChB,CAAC;IACF,KAAK,MAAM,QAAQ,IAAI,WAAW,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAClD,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;gBAC9C,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAA0B,CAAC;gBAClD,CAAC;qBAAM,CAAC;oBACN,+DAA+D;oBAC/D,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAC3D,IAAI,KAAK,EAAE,CAAC;wBACV,qDAAqD;wBACrD,OAAO,QAAQ,CACb,yBAAyB,KAAK,CAAC,CAAC,CAAC,GAAG,CACrC,EAA2B,CAAC;oBAC/B,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-file checks on Bascik's own attributes and component layout.
|
|
3
|
+
*
|
|
4
|
+
* These need only the text of one file, so they live here and run in the editor as well as in
|
|
5
|
+
* `bascik --check`. Checks that need the whole project (the set of pages, the route table, the config) live in
|
|
6
|
+
* `@bascik/bascik` instead; see docs/content/internals/diagnostics.md for the split.
|
|
7
|
+
*/
|
|
8
|
+
/** `data-bascik-*` attributes that are a single fixed name. */
|
|
9
|
+
export declare const KNOWN_BASCIK_DATA_EXACT: readonly ["data-bascik-slot", "data-bascik-build", "data-bascik-server", "data-bascik-routes", "data-bascik-stream", "data-bascik-preserve", "data-bascik-server-id"];
|
|
10
|
+
/** `data-bascik-*` attributes whose name carries a suffix chosen by the author. */
|
|
11
|
+
export declare const KNOWN_BASCIK_DATA_PREFIXES: readonly ["data-bascik-prop-", "data-bascik-attr-"];
|
|
12
|
+
/** Whether a lower-cased attribute name starting with `data-bascik-` is one Bascik reads. */
|
|
13
|
+
export declare function isKnownBascikAttribute(name: string): boolean;
|
|
14
|
+
export declare function unknownBascikAttributeMessage(name: string): string;
|
|
15
|
+
export declare function unknownDirectiveValueMessage(value: string): string;
|
|
16
|
+
/** Whether a `data-bascik-build` value is one Bascik understands. An empty value is a bare directive. */
|
|
17
|
+
export declare function isKnownBuildValue(value: string): boolean;
|
|
18
|
+
export interface StructureProblem {
|
|
19
|
+
kind: "script-before-markup" | "style-after-markup";
|
|
20
|
+
/** Offset of the offending `<script` or `<style` in the text that was scanned. */
|
|
21
|
+
index: number;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks the component template convention: `<style>` above the markup, `<script>` below it.
|
|
26
|
+
*
|
|
27
|
+
* `masked` is the file with comments and the bodies of `<script>`, `<style>` and `<textarea>` blanked out, so
|
|
28
|
+
* the only `<` left are real tags and offsets still match the original file.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findComponentStructureProblems(masked: string): StructureProblem[];
|
|
31
|
+
//# sourceMappingURL=directive-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directive-rules.d.ts","sourceRoot":"","sources":["../src/directive-rules.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,YAClC,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,CACf,CAAC;AAEX,mFAAmF;AACnF,eAAO,MAAM,0BAA0B,YACrC,mBAAmB,EACnB,mBAAmB,CACX,CAAC;AAIX,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK5D;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQlE;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,yGAAyG;AACzG,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,sBAAsB,GAAG,oBAAoB,CAAC;IACpD,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,MAAM,GACb,gBAAgB,EAAE,CAwBpB"}
|