@bascik/language-server 0.1.0-rc.3 → 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 +619 -360
- 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 +36 -129
- package/dist/cli.js.map +1 -1
- package/dist/compatibility-rules.json +11 -2
- package/dist/component-metadata.d.ts +1 -1
- package/dist/component-metadata.d.ts.map +1 -1
- package/dist/component-metadata.js +31 -25
- 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 +52 -30
- package/dist/project.js.map +1 -1
- package/dist/rules.d.ts +29 -3
- 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 +5 -1
package/dist/analyzer.js
CHANGED
|
@@ -1,160 +1,162 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { DiagnosticSeverity, CompletionItemKind, MarkupKind, CodeActionKind, } from "vscode-languageserver";
|
|
5
|
+
import { isInsideComponentRoots, normalizeComponentName, htmlSuppliesComponentProp, } from "./project.js";
|
|
6
|
+
import { findCompatibilityMatches } from "./rules.js";
|
|
7
|
+
import { analyzeApiRouteSource } from "./api-rules.js";
|
|
8
|
+
import { findComponentStructureProblems, isKnownBascikAttribute, isKnownBuildValue, unknownBascikAttributeMessage, unknownDirectiveValueMessage, } from "./directive-rules.js";
|
|
9
|
+
import { findModuleSpecifiers } from "./module-specifiers.js";
|
|
10
|
+
import { analyzeServerScriptSource } from "./server-script-rules.js";
|
|
11
|
+
import { analyzeComponentSource, } from "./component-metadata.js";
|
|
12
|
+
import { parseIgnoreDirectives, isDiagnosticIgnored, } from "./ignore-comments.js";
|
|
13
|
+
import { loadExtensionConfig } from "./config.js";
|
|
12
14
|
export const BUILT_IN_HTML_ELEMENTS = new Set([
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
15
|
+
"a",
|
|
16
|
+
"abbr",
|
|
17
|
+
"address",
|
|
18
|
+
"area",
|
|
19
|
+
"article",
|
|
20
|
+
"aside",
|
|
21
|
+
"audio",
|
|
22
|
+
"b",
|
|
23
|
+
"base",
|
|
24
|
+
"bdi",
|
|
25
|
+
"bdo",
|
|
26
|
+
"blockquote",
|
|
27
|
+
"body",
|
|
28
|
+
"br",
|
|
29
|
+
"button",
|
|
30
|
+
"canvas",
|
|
31
|
+
"caption",
|
|
32
|
+
"cite",
|
|
33
|
+
"code",
|
|
34
|
+
"col",
|
|
35
|
+
"colgroup",
|
|
36
|
+
"data",
|
|
37
|
+
"datalist",
|
|
38
|
+
"dd",
|
|
39
|
+
"del",
|
|
40
|
+
"details",
|
|
41
|
+
"dfn",
|
|
42
|
+
"dialog",
|
|
43
|
+
"div",
|
|
44
|
+
"dl",
|
|
45
|
+
"dt",
|
|
46
|
+
"em",
|
|
47
|
+
"embed",
|
|
48
|
+
"fieldset",
|
|
49
|
+
"figcaption",
|
|
50
|
+
"figure",
|
|
51
|
+
"footer",
|
|
52
|
+
"form",
|
|
53
|
+
"h1",
|
|
54
|
+
"h2",
|
|
55
|
+
"h3",
|
|
56
|
+
"h4",
|
|
57
|
+
"h5",
|
|
58
|
+
"h6",
|
|
59
|
+
"head",
|
|
60
|
+
"header",
|
|
61
|
+
"hgroup",
|
|
62
|
+
"hr",
|
|
63
|
+
"html",
|
|
64
|
+
"i",
|
|
65
|
+
"iframe",
|
|
66
|
+
"img",
|
|
67
|
+
"input",
|
|
68
|
+
"ins",
|
|
69
|
+
"kbd",
|
|
70
|
+
"label",
|
|
71
|
+
"legend",
|
|
72
|
+
"li",
|
|
73
|
+
"link",
|
|
74
|
+
"main",
|
|
75
|
+
"map",
|
|
76
|
+
"mark",
|
|
77
|
+
"meta",
|
|
78
|
+
"meter",
|
|
79
|
+
"nav",
|
|
80
|
+
"noscript",
|
|
81
|
+
"object",
|
|
82
|
+
"ol",
|
|
83
|
+
"optgroup",
|
|
84
|
+
"option",
|
|
85
|
+
"output",
|
|
86
|
+
"p",
|
|
87
|
+
"picture",
|
|
88
|
+
"pre",
|
|
89
|
+
"progress",
|
|
90
|
+
"q",
|
|
91
|
+
"rp",
|
|
92
|
+
"rt",
|
|
93
|
+
"ruby",
|
|
94
|
+
"s",
|
|
95
|
+
"samp",
|
|
96
|
+
"script",
|
|
97
|
+
"search",
|
|
98
|
+
"section",
|
|
99
|
+
"select",
|
|
100
|
+
"slot",
|
|
101
|
+
"small",
|
|
102
|
+
"source",
|
|
103
|
+
"span",
|
|
104
|
+
"strong",
|
|
105
|
+
"style",
|
|
106
|
+
"sub",
|
|
107
|
+
"summary",
|
|
108
|
+
"sup",
|
|
109
|
+
"table",
|
|
110
|
+
"tbody",
|
|
111
|
+
"td",
|
|
112
|
+
"template",
|
|
113
|
+
"textarea",
|
|
114
|
+
"tfoot",
|
|
115
|
+
"th",
|
|
116
|
+
"thead",
|
|
117
|
+
"time",
|
|
118
|
+
"title",
|
|
119
|
+
"tr",
|
|
120
|
+
"track",
|
|
121
|
+
"u",
|
|
122
|
+
"ul",
|
|
123
|
+
"var",
|
|
124
|
+
"video",
|
|
125
|
+
"wbr",
|
|
124
126
|
]);
|
|
125
127
|
export const SCRIPT_DIRECTIVES = [
|
|
126
128
|
{
|
|
127
|
-
name:
|
|
128
|
-
detail:
|
|
129
|
-
documentation:
|
|
129
|
+
name: "data-bascik-build",
|
|
130
|
+
detail: "Bascik build-time script",
|
|
131
|
+
documentation: "Executes in Node.js at build time. The default exported handler function returns HTML markup that replaces this script tag in the generated HTML.",
|
|
130
132
|
},
|
|
131
133
|
{
|
|
132
|
-
name:
|
|
133
|
-
detail:
|
|
134
|
-
documentation:
|
|
134
|
+
name: "data-bascik-routes",
|
|
135
|
+
detail: "Bascik dynamic routes script",
|
|
136
|
+
documentation: "Executes in Node.js at build time. The default exported handler function returns an array of dynamic route parameters to generate multiple pages from a template.",
|
|
135
137
|
},
|
|
136
138
|
{
|
|
137
|
-
name:
|
|
138
|
-
detail:
|
|
139
|
-
documentation:
|
|
139
|
+
name: "data-bascik-server",
|
|
140
|
+
detail: "Bascik server-side request script",
|
|
141
|
+
documentation: "Executes in Node.js per request on production and dev servers. The default exported handler function replaces this script tag.",
|
|
140
142
|
},
|
|
141
143
|
{
|
|
142
|
-
name:
|
|
143
|
-
detail:
|
|
144
|
-
documentation:
|
|
144
|
+
name: "data-bascik-stream",
|
|
145
|
+
detail: "Bascik server-side streaming script",
|
|
146
|
+
documentation: "Executes in Node.js per request on production servers. Streams chunked HTML responses to the client as data becomes available.",
|
|
145
147
|
},
|
|
146
148
|
];
|
|
147
149
|
export const SCRIPT_BLOCK_RE = /(<script(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)<\/script(?:[\t\n\f\r /][^>]*)?>/gi;
|
|
148
150
|
export function maskHtmlRawTextContents(html) {
|
|
149
|
-
return html.replace(/(<(script|style|textarea)(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)(<\/\2(?:[\t\n\f\r /][^>]*)?>)/gi, (_match, openTag, _tagName, content, closeTag) => `${openTag}${
|
|
151
|
+
return html.replace(/(<(script|style|textarea)(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)(<\/\2(?:[\t\n\f\r /][^>]*)?>)/gi, (_match, openTag, _tagName, content, closeTag) => `${openTag}${" ".repeat(content.length)}${closeTag}`);
|
|
150
152
|
}
|
|
151
153
|
export function escapeRegExp(value) {
|
|
152
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g,
|
|
154
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
153
155
|
}
|
|
154
156
|
export function findMatchingClose(html, tagName, contentStart) {
|
|
155
|
-
const tn = tagName.replace(/[.*+?^${}()|[\]\\]/g,
|
|
156
|
-
const openRe = new RegExp(`<${tn}[\\s>]`,
|
|
157
|
-
const closeRe = new RegExp(`<\\/${tn}>`,
|
|
157
|
+
const tn = tagName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
158
|
+
const openRe = new RegExp(`<${tn}[\\s>]`, "gi");
|
|
159
|
+
const closeRe = new RegExp(`<\\/${tn}>`, "gi");
|
|
158
160
|
let depth = 1;
|
|
159
161
|
let pos = contentStart;
|
|
160
162
|
while (pos < html.length) {
|
|
@@ -182,7 +184,7 @@ export function findMatchingClose(html, tagName, contentStart) {
|
|
|
182
184
|
else if (char === "'" && !inDoubleQuote) {
|
|
183
185
|
inSingleQuote = !inSingleQuote;
|
|
184
186
|
}
|
|
185
|
-
else if (char ===
|
|
187
|
+
else if (char === ">" && !inDoubleQuote && !inSingleQuote) {
|
|
186
188
|
tagEnd = i + 1;
|
|
187
189
|
break;
|
|
188
190
|
}
|
|
@@ -205,7 +207,10 @@ export function findMatchingClose(html, tagName, contentStart) {
|
|
|
205
207
|
return -1;
|
|
206
208
|
}
|
|
207
209
|
const isTagNameStart = (code) => (code >= 65 && code <= 90) || (code >= 97 && code <= 122);
|
|
208
|
-
const isTagNameChar = (code) => isTagNameStart(code) ||
|
|
210
|
+
const isTagNameChar = (code) => isTagNameStart(code) ||
|
|
211
|
+
(code >= 48 && code <= 57) ||
|
|
212
|
+
code === 95 ||
|
|
213
|
+
code === 45;
|
|
209
214
|
/**
|
|
210
215
|
* Tag tokens in source order, matching what
|
|
211
216
|
* `/<\/?([A-Za-z][\w-]*)(?:[^>"']|"[^"]*"|'[^']*')*>/g` finds, in linear time.
|
|
@@ -250,7 +255,7 @@ function* scanTags(source) {
|
|
|
250
255
|
};
|
|
251
256
|
let cursor = 0;
|
|
252
257
|
while (cursor < length) {
|
|
253
|
-
const open = source.indexOf(
|
|
258
|
+
const open = source.indexOf("<", cursor);
|
|
254
259
|
if (open < 0)
|
|
255
260
|
return;
|
|
256
261
|
const closing = source.charCodeAt(open + 1) === 47; /* / */
|
|
@@ -267,7 +272,11 @@ function* scanTags(source) {
|
|
|
267
272
|
cursor = open + 1;
|
|
268
273
|
continue;
|
|
269
274
|
}
|
|
270
|
-
yield {
|
|
275
|
+
yield {
|
|
276
|
+
name: source.slice(nameStart, nameEnd),
|
|
277
|
+
closing,
|
|
278
|
+
text: source.slice(open, end),
|
|
279
|
+
};
|
|
271
280
|
cursor = end;
|
|
272
281
|
}
|
|
273
282
|
}
|
|
@@ -288,7 +297,7 @@ export function findNearestParentComponent(source, componentMap) {
|
|
|
288
297
|
}
|
|
289
298
|
export function parseScriptOpenTagAttributes(openTag) {
|
|
290
299
|
const attrs = new Map();
|
|
291
|
-
const insideTag = openTag.replace(/^<script\b/i,
|
|
300
|
+
const insideTag = openTag.replace(/^<script\b/i, "").replace(/>$/, "");
|
|
292
301
|
const attrRe = /([^\s"'=<>`/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gi;
|
|
293
302
|
let match;
|
|
294
303
|
while ((match = attrRe.exec(insideTag)) !== null) {
|
|
@@ -300,14 +309,32 @@ export function parseScriptOpenTagAttributes(openTag) {
|
|
|
300
309
|
}
|
|
301
310
|
return attrs;
|
|
302
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Attribute values of any open tag, keyed by lowercased name. A bare attribute
|
|
314
|
+
* maps to `""`, as the DOM reports it. The first occurrence of a name wins, as
|
|
315
|
+
* in the HTML tokenizer, and text inside a quoted value is never read as an
|
|
316
|
+
* attribute. An unquoted value keeps its slashes; a trailing `/>` ends it.
|
|
317
|
+
*/
|
|
318
|
+
function readOpenTagAttributes(openTag) {
|
|
319
|
+
const attrs = new Map();
|
|
320
|
+
const insideTag = openTag.replace(/^<[^\s/>]+/, "").replace(/\/?>$/, "");
|
|
321
|
+
const attrRe = /([^\s"'=<>`/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gi;
|
|
322
|
+
let match;
|
|
323
|
+
while ((match = attrRe.exec(insideTag)) !== null) {
|
|
324
|
+
const name = match[1].toLowerCase();
|
|
325
|
+
if (!attrs.has(name))
|
|
326
|
+
attrs.set(name, match[2] ?? match[3] ?? match[4] ?? "");
|
|
327
|
+
}
|
|
328
|
+
return attrs;
|
|
329
|
+
}
|
|
303
330
|
export function resolveScriptTarget(value, documentDir, importRootAbs, kind) {
|
|
304
|
-
if (value.startsWith(
|
|
331
|
+
if (value.startsWith("./") || value.startsWith("../"))
|
|
305
332
|
return path.resolve(documentDir, value);
|
|
306
|
-
if (value.startsWith(
|
|
333
|
+
if (value.startsWith("@/"))
|
|
307
334
|
return path.resolve(importRootAbs, value.slice(2));
|
|
308
|
-
if (value.startsWith(
|
|
335
|
+
if (value.startsWith("/"))
|
|
309
336
|
return undefined;
|
|
310
|
-
if (kind ===
|
|
337
|
+
if (kind === "src") {
|
|
311
338
|
if (/^[a-z][a-z\d+.-]*:/i.test(value))
|
|
312
339
|
return undefined;
|
|
313
340
|
return path.resolve(documentDir, value);
|
|
@@ -315,17 +342,17 @@ export function resolveScriptTarget(value, documentDir, importRootAbs, kind) {
|
|
|
315
342
|
return undefined;
|
|
316
343
|
}
|
|
317
344
|
export function leadingSlashSpecifierMessage(specifier) {
|
|
318
|
-
const rest = specifier.replace(/^\/+/,
|
|
345
|
+
const rest = specifier.replace(/^\/+/, "");
|
|
319
346
|
return (`Leading-slash specifier '${specifier}' is not supported in Bascik scripts. ` +
|
|
320
347
|
`A bare '/' is ambiguous (filesystem root vs. site root). ` +
|
|
321
348
|
`Use '@/${rest}' to resolve against scripts.importRoot, ` +
|
|
322
349
|
`or './${rest}' to resolve relative to this file.`);
|
|
323
350
|
}
|
|
324
351
|
export function collectLeadingSlashDiagnostics(document, openTag, scriptBody, blockStart, attrs) {
|
|
325
|
-
if (!attrs.has(
|
|
326
|
-
!attrs.has(
|
|
327
|
-
!attrs.has(
|
|
328
|
-
!attrs.has(
|
|
352
|
+
if (!attrs.has("data-bascik-build") &&
|
|
353
|
+
!attrs.has("data-bascik-server") &&
|
|
354
|
+
!attrs.has("data-bascik-routes") &&
|
|
355
|
+
!attrs.has("data-bascik-stream")) {
|
|
329
356
|
return [];
|
|
330
357
|
}
|
|
331
358
|
const out = [];
|
|
@@ -337,40 +364,53 @@ export function collectLeadingSlashDiagnostics(document, openTag, scriptBody, bl
|
|
|
337
364
|
},
|
|
338
365
|
message: leadingSlashSpecifierMessage(specifier),
|
|
339
366
|
severity: DiagnosticSeverity.Error,
|
|
340
|
-
source:
|
|
341
|
-
code:
|
|
367
|
+
source: "bascik",
|
|
368
|
+
code: "leading-slash-specifier",
|
|
342
369
|
});
|
|
343
370
|
};
|
|
344
371
|
const srcMatch = /\ssrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(openTag);
|
|
345
372
|
if (srcMatch) {
|
|
346
|
-
const srcValue = srcMatch[1] ?? srcMatch[2] ?? srcMatch[3] ??
|
|
347
|
-
if (srcValue.startsWith(
|
|
373
|
+
const srcValue = srcMatch[1] ?? srcMatch[2] ?? srcMatch[3] ?? "";
|
|
374
|
+
if (srcValue.startsWith("/")) {
|
|
348
375
|
const valueStart = blockStart + (srcMatch.index ?? 0) + srcMatch[0].indexOf(srcValue);
|
|
349
376
|
push(valueStart, valueStart + srcValue.length, srcValue);
|
|
350
377
|
}
|
|
351
378
|
}
|
|
352
379
|
const bodyStart = blockStart + openTag.length;
|
|
353
380
|
for (const { start, end, value } of findModuleSpecifiers(scriptBody)) {
|
|
354
|
-
if (value.startsWith(
|
|
381
|
+
if (value.startsWith("/"))
|
|
355
382
|
push(bodyStart + start, bodyStart + end, value);
|
|
356
383
|
}
|
|
357
384
|
return out;
|
|
358
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Escapes plain text so it renders as typed inside markdown: syntax characters are backslash-escaped, runs of
|
|
388
|
+
* spaces become ` `, `>` is escaped, and a newline becomes a hard break. Descriptions come from a
|
|
389
|
+
* component's `<!-- @bascik -->` header and are prose, not markdown, so `<unsafe>` or `*not bold*` stay literal.
|
|
390
|
+
* Matches VS Code's `MarkdownString.appendText`, so the text looks the same in every editor.
|
|
391
|
+
*/
|
|
392
|
+
export function escapeMarkdownText(text) {
|
|
393
|
+
return text
|
|
394
|
+
.replace(/[\\`*_{}[\]()#+\-!~]/g, "\\$&")
|
|
395
|
+
.replace(/([ \t]+)/g, (_match, spaces) => " ".repeat(spaces.length))
|
|
396
|
+
.replace(/>/g, "\\>")
|
|
397
|
+
.replace(/\n/g, "\\\n");
|
|
398
|
+
}
|
|
359
399
|
export function createComponentDocumentationMarkdown(relativePath, metadata) {
|
|
360
400
|
const parts = [];
|
|
361
401
|
if (metadata?.description) {
|
|
362
|
-
parts.push(metadata.description,
|
|
402
|
+
parts.push(escapeMarkdownText(metadata.description), "\n\n");
|
|
363
403
|
}
|
|
364
404
|
parts.push(`Bascik component from \`${relativePath}\`.`);
|
|
365
405
|
if (metadata) {
|
|
366
|
-
parts.push(
|
|
367
|
-
appendMetadataMembersMarkdown(parts,
|
|
368
|
-
appendMetadataMembersMarkdown(parts,
|
|
406
|
+
parts.push("\n\n");
|
|
407
|
+
appendMetadataMembersMarkdown(parts, "Props", metadata.props);
|
|
408
|
+
appendMetadataMembersMarkdown(parts, "Slots", [
|
|
369
409
|
...metadata.slots,
|
|
370
410
|
...(metadata.defaultSlot ? [metadata.defaultSlot] : []),
|
|
371
411
|
]);
|
|
372
412
|
}
|
|
373
|
-
return parts.join(
|
|
413
|
+
return parts.join("");
|
|
374
414
|
}
|
|
375
415
|
function appendMetadataMembersMarkdown(parts, label, members) {
|
|
376
416
|
if (members.length === 0)
|
|
@@ -379,15 +419,15 @@ function appendMetadataMembersMarkdown(parts, label, members) {
|
|
|
379
419
|
for (const member of members) {
|
|
380
420
|
parts.push(`- \`${member.name}\``);
|
|
381
421
|
if (member.description) {
|
|
382
|
-
parts.push(`: ${member.description}`);
|
|
422
|
+
parts.push(`: ${escapeMarkdownText(member.description)}`);
|
|
383
423
|
}
|
|
384
|
-
parts.push(
|
|
424
|
+
parts.push("\n");
|
|
385
425
|
}
|
|
386
|
-
parts.push(
|
|
426
|
+
parts.push("\n");
|
|
387
427
|
}
|
|
388
428
|
export function completionReplacementRange(document, position) {
|
|
389
429
|
const offset = document.offsetAt(position);
|
|
390
|
-
const prefix = /[^\s<>"'=]*$/.exec(document.getText().slice(0, offset))?.[0] ??
|
|
430
|
+
const prefix = /[^\s<>"'=]*$/.exec(document.getText().slice(0, offset))?.[0] ?? "";
|
|
391
431
|
return {
|
|
392
432
|
start: document.positionAt(offset - prefix.length),
|
|
393
433
|
end: position,
|
|
@@ -395,13 +435,13 @@ export function completionReplacementRange(document, position) {
|
|
|
395
435
|
}
|
|
396
436
|
export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts = []) {
|
|
397
437
|
const { languageId } = document;
|
|
398
|
-
if (languageId !==
|
|
399
|
-
languageId !==
|
|
400
|
-
languageId !==
|
|
401
|
-
languageId !==
|
|
438
|
+
if (languageId !== "css" &&
|
|
439
|
+
languageId !== "javascript" &&
|
|
440
|
+
languageId !== "typescript" &&
|
|
441
|
+
languageId !== "html") {
|
|
402
442
|
return [];
|
|
403
443
|
}
|
|
404
|
-
const normalizedDocumentPath = fsPath.replace(/\\/g,
|
|
444
|
+
const normalizedDocumentPath = fsPath.replace(/\\/g, "/");
|
|
405
445
|
if (/\.(test|spec)\.[a-z0-9]+$/i.test(normalizedDocumentPath)) {
|
|
406
446
|
return [];
|
|
407
447
|
}
|
|
@@ -409,27 +449,33 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
409
449
|
const diagnostics = [];
|
|
410
450
|
const isComponentDocument = snapshot !== undefined &&
|
|
411
451
|
isInsideComponentRoots(normalizedDocumentPath, snapshot.componentRoots);
|
|
412
|
-
|
|
413
|
-
|
|
452
|
+
// The API folder is `directory.api`, so it is read from the project when there is one. Without a project
|
|
453
|
+
// (a file opened on its own), the default folder name is the best guess.
|
|
454
|
+
const isInsideApiRoot = snapshot?.apiRoot
|
|
455
|
+
? isInsideComponentRoots(normalizedDocumentPath, [snapshot.apiRoot])
|
|
456
|
+
: normalizedDocumentPath.includes("/src/api/");
|
|
457
|
+
const isApiRouteDocument = isInsideApiRoot &&
|
|
458
|
+
(languageId === "typescript" || languageId === "javascript");
|
|
414
459
|
if (isApiRouteDocument) {
|
|
415
|
-
if (path.basename(normalizedDocumentPath).startsWith(
|
|
460
|
+
if (path.basename(normalizedDocumentPath).startsWith("_middleware.")) {
|
|
416
461
|
diagnostics.push({
|
|
417
462
|
range: {
|
|
418
463
|
start: { line: 0, character: 0 },
|
|
419
464
|
end: { line: 0, character: Math.min(text.length, 10) },
|
|
420
465
|
},
|
|
421
|
-
message:
|
|
466
|
+
message: "Middleware chains (_middleware.ts) are not supported by design in Bascik API routes. Compose plain functions directly in handler files.",
|
|
422
467
|
severity: DiagnosticSeverity.Error,
|
|
423
|
-
source:
|
|
468
|
+
source: "bascik",
|
|
469
|
+
code: "middleware-unsupported",
|
|
424
470
|
});
|
|
425
471
|
}
|
|
426
472
|
const apiDiags = analyzeApiRouteSource(text);
|
|
427
473
|
for (const diag of apiDiags) {
|
|
428
474
|
let severity = DiagnosticSeverity.Warning;
|
|
429
|
-
if (diag.severity ===
|
|
475
|
+
if (diag.severity === "error") {
|
|
430
476
|
severity = DiagnosticSeverity.Error;
|
|
431
477
|
}
|
|
432
|
-
else if (diag.severity ===
|
|
478
|
+
else if (diag.severity === "info") {
|
|
433
479
|
severity = DiagnosticSeverity.Information;
|
|
434
480
|
}
|
|
435
481
|
diagnostics.push({
|
|
@@ -439,69 +485,70 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
439
485
|
},
|
|
440
486
|
message: diag.message,
|
|
441
487
|
severity,
|
|
442
|
-
source:
|
|
488
|
+
source: "bascik",
|
|
489
|
+
code: diag.code,
|
|
443
490
|
});
|
|
444
491
|
}
|
|
445
492
|
}
|
|
446
|
-
if (languageId ===
|
|
447
|
-
if (snapshot &&
|
|
493
|
+
if (languageId === "html" && fsPath.startsWith("/")) {
|
|
494
|
+
if (snapshot &&
|
|
495
|
+
isInsideComponentRoots(normalizedDocumentPath, snapshot.componentRoots)) {
|
|
448
496
|
const fileName = path.basename(normalizedDocumentPath);
|
|
449
|
-
const nameWithoutExt = fileName.replace(/\.html$/i,
|
|
450
|
-
if (!nameWithoutExt.includes(
|
|
497
|
+
const nameWithoutExt = fileName.replace(/\.html$/i, "").toLowerCase();
|
|
498
|
+
if (!nameWithoutExt.includes("-") &&
|
|
451
499
|
!BUILT_IN_HTML_ELEMENTS.has(nameWithoutExt)) {
|
|
452
500
|
diagnostics.push({
|
|
453
501
|
range: {
|
|
454
502
|
start: { line: 0, character: 0 },
|
|
455
503
|
end: { line: 0, character: Math.min(text.length, 10) },
|
|
456
504
|
},
|
|
505
|
+
code: "component-name-not-hyphenated",
|
|
457
506
|
message: `Component "${nameWithoutExt}" is not hyphenated. Under WHATWG HTML §4.13, custom elements should include a hyphen (e.g. "my-${nameWithoutExt}") to avoid collisions with future HTML standards.`,
|
|
458
507
|
severity: DiagnosticSeverity.Warning,
|
|
459
|
-
source:
|
|
508
|
+
source: "bascik",
|
|
460
509
|
});
|
|
461
510
|
}
|
|
462
511
|
}
|
|
463
512
|
}
|
|
513
|
+
// Scoping rules describe what Bascik cannot rewrite, so they apply to component files, the only code it scopes.
|
|
514
|
+
// Pages and API routes are not scoped. Without a project there is no way to tell, so every file is checked.
|
|
515
|
+
const appliesScopingRules = snapshot === undefined || isComponentDocument;
|
|
464
516
|
const addCompatibilityDiagnostics = (sourceText, kind, offset) => {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
const
|
|
471
|
-
if (!match || typeof match.index !== 'number')
|
|
472
|
-
continue;
|
|
473
|
-
const start = document.positionAt(offset + match.index);
|
|
474
|
-
const end = document.positionAt(offset + match.index + Math.max(match[0].length, 1));
|
|
475
|
-
const severity = rule.severity === 'warning'
|
|
517
|
+
if (!appliesScopingRules)
|
|
518
|
+
return;
|
|
519
|
+
for (const { rule, index, length } of findCompatibilityMatches(sourceText, kind)) {
|
|
520
|
+
const start = document.positionAt(offset + index);
|
|
521
|
+
const end = document.positionAt(offset + index + length);
|
|
522
|
+
const severity = rule.severity === "warning"
|
|
476
523
|
? DiagnosticSeverity.Warning
|
|
477
524
|
: DiagnosticSeverity.Error;
|
|
478
525
|
diagnostics.push({
|
|
479
526
|
range: { start, end },
|
|
480
527
|
message: `${rule.message} ${rule.suggestion}`,
|
|
481
528
|
severity,
|
|
482
|
-
source:
|
|
529
|
+
source: "bascik",
|
|
483
530
|
code: rule.id,
|
|
484
531
|
});
|
|
485
532
|
}
|
|
486
533
|
};
|
|
487
534
|
const isJavaScriptScriptTag = (openTag) => {
|
|
488
535
|
const attrs = parseScriptOpenTagAttributes(openTag);
|
|
489
|
-
const typeValue = attrs.get(
|
|
536
|
+
const typeValue = attrs.get("type");
|
|
490
537
|
if (!typeValue || typeValue === true)
|
|
491
538
|
return true;
|
|
492
539
|
const normalized = String(typeValue).trim().toLowerCase();
|
|
493
|
-
return (normalized ===
|
|
494
|
-
normalized ===
|
|
495
|
-
normalized ===
|
|
496
|
-
normalized ===
|
|
497
|
-
normalized ===
|
|
540
|
+
return (normalized === "module" ||
|
|
541
|
+
normalized === "text/javascript" ||
|
|
542
|
+
normalized === "application/javascript" ||
|
|
543
|
+
normalized === "text/ecmascript" ||
|
|
544
|
+
normalized === "application/ecmascript");
|
|
498
545
|
};
|
|
499
546
|
const scriptBlockRe = new RegExp(SCRIPT_BLOCK_RE.source, SCRIPT_BLOCK_RE.flags);
|
|
500
547
|
const styleBlockRe = /(<style(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)<\/style(?:[\t\n\f\r /][^>]*)?>/gi;
|
|
501
|
-
if (languageId ===
|
|
548
|
+
if (languageId === "html") {
|
|
502
549
|
if (isComponentDocument) {
|
|
503
550
|
const metadata = analyzeComponentSource(text, {
|
|
504
|
-
hasCompanionStyles: fs.existsSync(fsPath.replace(/\.html$/i,
|
|
551
|
+
hasCompanionStyles: fs.existsSync(fsPath.replace(/\.html$/i, ".css")),
|
|
505
552
|
});
|
|
506
553
|
for (const metadataDiagnostic of metadata.diagnostics) {
|
|
507
554
|
diagnostics.push({
|
|
@@ -511,19 +558,22 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
511
558
|
},
|
|
512
559
|
message: metadataDiagnostic.message,
|
|
513
560
|
severity: DiagnosticSeverity.Warning,
|
|
514
|
-
source:
|
|
561
|
+
source: "bascik",
|
|
515
562
|
code: metadataDiagnostic.code,
|
|
516
563
|
});
|
|
517
564
|
}
|
|
518
|
-
const referenceScanText = maskHtmlRawTextContents(text).replace(/<!--[\s\S]*?(?:-->|$)/g, (comment) =>
|
|
519
|
-
const declaredIds = new Set(Array.from(referenceScanText.matchAll(/\sid\s*=\s*(?:"([^"]+)"|'([^']+)')/gi))
|
|
520
|
-
.map((match) => match[1] ?? match[2])
|
|
565
|
+
const referenceScanText = maskHtmlRawTextContents(text).replace(/<!--[\s\S]*?(?:-->|$)/g, (comment) => " ".repeat(comment.length));
|
|
566
|
+
const declaredIds = new Set(Array.from(referenceScanText.matchAll(/\sid\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`/>]+))/gi))
|
|
567
|
+
.map((match) => match[1] ?? match[2] ?? match[3])
|
|
521
568
|
.filter((id) => Boolean(id)));
|
|
522
|
-
const idReferenceAttributeRegex = /\s(for|itemref|aria-activedescendant|aria-details|aria-errormessage|aria-labelledby|aria-describedby|aria-controls|aria-owns|aria-flowto)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
|
|
569
|
+
const idReferenceAttributeRegex = /\s(for|itemref|aria-activedescendant|aria-details|aria-errormessage|aria-labelledby|aria-describedby|aria-controls|aria-owns|aria-flowto)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`/>]+))/gi;
|
|
523
570
|
let idReferenceMatch;
|
|
524
571
|
while ((idReferenceMatch =
|
|
525
572
|
idReferenceAttributeRegex.exec(referenceScanText)) !== null) {
|
|
526
|
-
const value = idReferenceMatch[2] ??
|
|
573
|
+
const value = idReferenceMatch[2] ??
|
|
574
|
+
idReferenceMatch[3] ??
|
|
575
|
+
idReferenceMatch[4] ??
|
|
576
|
+
"";
|
|
527
577
|
for (const id of value.trim().split(/\s+/).filter(Boolean)) {
|
|
528
578
|
if (declaredIds.has(id))
|
|
529
579
|
continue;
|
|
@@ -532,17 +582,20 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
532
582
|
const end = document.positionAt(idReferenceMatch.index + Math.max(valueOffset, 0) + id.length);
|
|
533
583
|
diagnostics.push({
|
|
534
584
|
range: { start, end },
|
|
585
|
+
code: "id-reference-undeclared",
|
|
535
586
|
message: `ID reference "${id}" is not declared in this component and will be left unscoped.`,
|
|
536
587
|
severity: DiagnosticSeverity.Information,
|
|
537
|
-
source:
|
|
588
|
+
source: "bascik",
|
|
538
589
|
});
|
|
539
590
|
}
|
|
540
591
|
}
|
|
541
|
-
const fragmentReferenceRegex = /\shref\s*=\s*(?:"#([^"]+)"|'#([^']+)')/gi;
|
|
592
|
+
const fragmentReferenceRegex = /\shref\s*=\s*(?:"#([^"]+)"|'#([^']+)'|#([^\s"'=<>`/>]+))/gi;
|
|
542
593
|
let fragmentReferenceMatch;
|
|
543
594
|
while ((fragmentReferenceMatch =
|
|
544
595
|
fragmentReferenceRegex.exec(referenceScanText)) !== null) {
|
|
545
|
-
const id = fragmentReferenceMatch[1] ??
|
|
596
|
+
const id = fragmentReferenceMatch[1] ??
|
|
597
|
+
fragmentReferenceMatch[2] ??
|
|
598
|
+
fragmentReferenceMatch[3];
|
|
546
599
|
if (!id || declaredIds.has(id))
|
|
547
600
|
continue;
|
|
548
601
|
const idOffset = fragmentReferenceMatch[0].indexOf(id);
|
|
@@ -550,31 +603,33 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
550
603
|
const end = document.positionAt(fragmentReferenceMatch.index + Math.max(idOffset, 0) + id.length);
|
|
551
604
|
diagnostics.push({
|
|
552
605
|
range: { start, end },
|
|
606
|
+
code: "id-reference-undeclared",
|
|
553
607
|
message: `ID reference "${id}" is not declared in this component and will be left unscoped.`,
|
|
554
608
|
severity: DiagnosticSeverity.Information,
|
|
555
|
-
source:
|
|
609
|
+
source: "bascik",
|
|
556
610
|
});
|
|
557
611
|
}
|
|
558
612
|
}
|
|
559
|
-
const preserveDirectiveRegex = /data-bascik-preserve(?:\s*=\s*("([^"]*)"|'([^']*)'))?/gi;
|
|
613
|
+
const preserveDirectiveRegex = /data-bascik-preserve(?:\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'=<>`/>]+)))?/gi;
|
|
560
614
|
let preserveMatch;
|
|
561
615
|
while ((preserveMatch = preserveDirectiveRegex.exec(text)) !== null) {
|
|
562
616
|
if (preserveMatch[1] === undefined)
|
|
563
617
|
continue;
|
|
564
|
-
const value = preserveMatch[2] ?? preserveMatch[3] ??
|
|
618
|
+
const value = preserveMatch[2] ?? preserveMatch[3] ?? preserveMatch[4] ?? "";
|
|
565
619
|
for (const preserveToken of value.trim().split(/\s+/).filter(Boolean)) {
|
|
566
|
-
if (preserveToken ===
|
|
567
|
-
preserveToken ===
|
|
568
|
-
preserveToken ===
|
|
620
|
+
if (preserveToken === "id" ||
|
|
621
|
+
preserveToken === "name" ||
|
|
622
|
+
preserveToken === "class")
|
|
569
623
|
continue;
|
|
570
624
|
const tokenOffset = preserveMatch[0].indexOf(preserveToken);
|
|
571
625
|
const start = document.positionAt(preserveMatch.index + Math.max(tokenOffset, 0));
|
|
572
626
|
const end = document.positionAt(preserveMatch.index + Math.max(tokenOffset, 0) + preserveToken.length);
|
|
573
627
|
diagnostics.push({
|
|
574
628
|
range: { start, end },
|
|
629
|
+
code: "unknown-preserve-token",
|
|
575
630
|
message: `Unknown data-bascik-preserve token "${preserveToken}". Valid tokens are id, name, and class.`,
|
|
576
631
|
severity: DiagnosticSeverity.Warning,
|
|
577
|
-
source:
|
|
632
|
+
source: "bascik",
|
|
578
633
|
});
|
|
579
634
|
}
|
|
580
635
|
}
|
|
@@ -582,35 +637,38 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
582
637
|
let formMatch;
|
|
583
638
|
while (isComponentDocument &&
|
|
584
639
|
(formMatch = formOpenTagRegex.exec(text)) !== null) {
|
|
585
|
-
const
|
|
586
|
-
const action =
|
|
640
|
+
const formAttributes = readOpenTagAttributes(formMatch[0]);
|
|
641
|
+
const action = formAttributes.get("action");
|
|
587
642
|
if (!action || !/^(?:https?:)?\/\//i.test(action))
|
|
588
643
|
continue;
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
644
|
+
const preserveValue = formAttributes.get("data-bascik-preserve");
|
|
645
|
+
// A bare directive, or an empty value (the bare form as serializers
|
|
646
|
+
// write it), preserves every attribute, `name` included.
|
|
647
|
+
const preserveTokens = (preserveValue ?? "")
|
|
648
|
+
.trim()
|
|
649
|
+
.split(/\s+/)
|
|
650
|
+
.filter(Boolean);
|
|
651
|
+
const preservesName = preserveValue !== undefined &&
|
|
652
|
+
(preserveTokens.length === 0 || preserveTokens.includes("name"));
|
|
596
653
|
if (preservesName)
|
|
597
654
|
continue;
|
|
598
655
|
const start = document.positionAt(formMatch.index);
|
|
599
656
|
const end = document.positionAt(formMatch.index + formMatch[0].length);
|
|
600
657
|
diagnostics.push({
|
|
601
658
|
range: { start, end },
|
|
659
|
+
code: "external-form-missing-preserve-name",
|
|
602
660
|
message: 'External form actions require data-bascik-preserve="name" so submitted field names remain literal.',
|
|
603
661
|
severity: DiagnosticSeverity.Warning,
|
|
604
|
-
source:
|
|
662
|
+
source: "bascik",
|
|
605
663
|
});
|
|
606
664
|
}
|
|
607
665
|
if (snapshot && isComponentDocument) {
|
|
608
666
|
const componentName = normalizeComponentName(fsPath);
|
|
609
|
-
const directiveRegex = /data-bascik-attr-([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([\w-]+)"|'([\w-]+)')/gi;
|
|
667
|
+
const directiveRegex = /data-bascik-attr-([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([\w-]+)"|'([\w-]+)'|([\w-]+))/gi;
|
|
610
668
|
let directiveMatch;
|
|
611
669
|
while ((directiveMatch = directiveRegex.exec(text)) !== null) {
|
|
612
670
|
const targetName = directiveMatch[1];
|
|
613
|
-
const propName = directiveMatch[2] ?? directiveMatch[3];
|
|
671
|
+
const propName = directiveMatch[2] ?? directiveMatch[3] ?? directiveMatch[4];
|
|
614
672
|
const suppliedInOpen = openDocumentTexts.some(({ text }) => htmlSuppliesComponentProp(text, componentName, propName));
|
|
615
673
|
const suppliedInDisk = Array.from(snapshot.htmlUsageByFile.values()).some((usageHtml) => htmlSuppliesComponentProp(usageHtml, componentName, propName));
|
|
616
674
|
if (suppliedInOpen || suppliedInDisk)
|
|
@@ -619,23 +677,26 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
619
677
|
const end = document.positionAt(directiveMatch.index + directiveMatch[0].length);
|
|
620
678
|
diagnostics.push({
|
|
621
679
|
range: { start, end },
|
|
680
|
+
// A hint, not a warning. Whether anything supplies the prop is a question about every page, and the
|
|
681
|
+
// snapshot only reads src/**/*.html, so usage from Markdown or a build script is invisible to it.
|
|
682
|
+
code: "attr-prop-unsupplied",
|
|
622
683
|
message: `data-bascik-attr-${targetName} references prop "${propName}", but no <${componentName}> usage supplies data-bascik-prop-${propName}.`,
|
|
623
|
-
severity: DiagnosticSeverity.
|
|
624
|
-
source:
|
|
684
|
+
severity: DiagnosticSeverity.Information,
|
|
685
|
+
source: "bascik",
|
|
625
686
|
});
|
|
626
687
|
}
|
|
627
688
|
}
|
|
628
689
|
let scriptMatch;
|
|
629
690
|
while ((scriptMatch = scriptBlockRe.exec(text)) !== null) {
|
|
630
691
|
const openTag = scriptMatch[1];
|
|
631
|
-
const scriptBody = scriptMatch[2] ??
|
|
692
|
+
const scriptBody = scriptMatch[2] ?? "";
|
|
632
693
|
const scriptBodyOffset = (scriptMatch.index ?? 0) + openTag.length;
|
|
633
694
|
const attrs = parseScriptOpenTagAttributes(openTag);
|
|
634
695
|
const directiveAttrs = [
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
696
|
+
"data-bascik-build",
|
|
697
|
+
"data-bascik-server",
|
|
698
|
+
"data-bascik-routes",
|
|
699
|
+
"data-bascik-stream",
|
|
639
700
|
];
|
|
640
701
|
const presentDirectives = directiveAttrs.filter((d) => attrs.has(d));
|
|
641
702
|
for (let i = 0; i < presentDirectives.length; i++) {
|
|
@@ -643,20 +704,20 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
643
704
|
const d1 = presentDirectives[i];
|
|
644
705
|
const d2 = presentDirectives[j];
|
|
645
706
|
let message;
|
|
646
|
-
if ((d1 ===
|
|
647
|
-
(d1 ===
|
|
707
|
+
if ((d1 === "data-bascik-build" && d2 === "data-bascik-server") ||
|
|
708
|
+
(d1 === "data-bascik-server" && d2 === "data-bascik-build")) {
|
|
648
709
|
message =
|
|
649
|
-
|
|
710
|
+
"data-bascik-build and data-bascik-server cannot both appear on the same <script> tag. Remove one - a script runs at build time or at request time, not both.";
|
|
650
711
|
}
|
|
651
|
-
else if ((d1 ===
|
|
652
|
-
(d1 ===
|
|
712
|
+
else if ((d1 === "data-bascik-routes" && d2 === "data-bascik-server") ||
|
|
713
|
+
(d1 === "data-bascik-server" && d2 === "data-bascik-routes")) {
|
|
653
714
|
message =
|
|
654
|
-
|
|
715
|
+
"data-bascik-routes and data-bascik-server cannot both appear on the same <script> tag. Remove one - a routes script runs at build time, while a server script runs at request time.";
|
|
655
716
|
}
|
|
656
|
-
else if ((d1 ===
|
|
657
|
-
(d1 ===
|
|
717
|
+
else if ((d1 === "data-bascik-routes" && d2 === "data-bascik-build") ||
|
|
718
|
+
(d1 === "data-bascik-build" && d2 === "data-bascik-routes")) {
|
|
658
719
|
message =
|
|
659
|
-
|
|
720
|
+
"data-bascik-routes and data-bascik-build cannot both appear on the same <script> tag. Remove one.";
|
|
660
721
|
}
|
|
661
722
|
else {
|
|
662
723
|
message = `${d1} and ${d2} cannot both appear on the same <script> tag. Remove one.`;
|
|
@@ -667,22 +728,36 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
667
728
|
range: { start, end },
|
|
668
729
|
message,
|
|
669
730
|
severity: DiagnosticSeverity.Error,
|
|
670
|
-
source:
|
|
731
|
+
source: "bascik",
|
|
732
|
+
code: "script-mode-conflict",
|
|
671
733
|
});
|
|
672
734
|
}
|
|
673
735
|
}
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
736
|
+
const buildValue = attrs.get("data-bascik-build");
|
|
737
|
+
if (typeof buildValue === "string" && !isKnownBuildValue(buildValue)) {
|
|
738
|
+
diagnostics.push({
|
|
739
|
+
range: {
|
|
740
|
+
start: document.positionAt(scriptMatch.index ?? 0),
|
|
741
|
+
end: document.positionAt((scriptMatch.index ?? 0) + openTag.length),
|
|
742
|
+
},
|
|
743
|
+
message: unknownDirectiveValueMessage(buildValue.trim()),
|
|
744
|
+
severity: DiagnosticSeverity.Warning,
|
|
745
|
+
source: "bascik",
|
|
746
|
+
code: "unknown-directive-value",
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
const hasServerDirective = attrs.has("data-bascik-server") ||
|
|
750
|
+
attrs.has("data-bascik-stream") ||
|
|
751
|
+
attrs.has("data-bascik-build") ||
|
|
752
|
+
attrs.has("data-bascik-routes");
|
|
678
753
|
if (hasServerDirective) {
|
|
679
|
-
const directive = attrs.has(
|
|
680
|
-
?
|
|
681
|
-
: attrs.has(
|
|
682
|
-
?
|
|
683
|
-
: attrs.has(
|
|
684
|
-
?
|
|
685
|
-
:
|
|
754
|
+
const directive = attrs.has("data-bascik-stream")
|
|
755
|
+
? "stream"
|
|
756
|
+
: attrs.has("data-bascik-server")
|
|
757
|
+
? "server"
|
|
758
|
+
: attrs.has("data-bascik-build")
|
|
759
|
+
? "build"
|
|
760
|
+
: "routes";
|
|
686
761
|
const hasSrcAttribute = /\ssrc\s*=/i.test(openTag);
|
|
687
762
|
const serverDiags = analyzeServerScriptSource(scriptBody, {
|
|
688
763
|
hasSrcAttribute,
|
|
@@ -692,53 +767,101 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
692
767
|
const start = document.positionAt(scriptBodyOffset + sd.start);
|
|
693
768
|
const end = document.positionAt(scriptBodyOffset + sd.end);
|
|
694
769
|
let severity = DiagnosticSeverity.Error;
|
|
695
|
-
if (sd.severity ===
|
|
770
|
+
if (sd.severity === "warning") {
|
|
696
771
|
severity = DiagnosticSeverity.Warning;
|
|
697
772
|
}
|
|
698
|
-
else if (sd.severity ===
|
|
773
|
+
else if (sd.severity === "info") {
|
|
699
774
|
severity = DiagnosticSeverity.Information;
|
|
700
775
|
}
|
|
701
776
|
diagnostics.push({
|
|
702
777
|
range: { start, end },
|
|
703
778
|
message: sd.message,
|
|
704
779
|
severity,
|
|
705
|
-
source:
|
|
780
|
+
source: "bascik",
|
|
706
781
|
code: sd.code,
|
|
707
782
|
});
|
|
708
783
|
}
|
|
709
784
|
}
|
|
710
785
|
diagnostics.push(...collectLeadingSlashDiagnostics(document, openTag, scriptBody, scriptMatch.index ?? 0, attrs));
|
|
711
|
-
|
|
712
|
-
|
|
786
|
+
// A directive script runs in Node, at build time or per request, and never in the browser Bascik scopes.
|
|
787
|
+
if (isJavaScriptScriptTag(openTag) && !hasServerDirective) {
|
|
788
|
+
addCompatibilityDiagnostics(scriptBody, "js", scriptBodyOffset);
|
|
713
789
|
}
|
|
714
790
|
}
|
|
715
791
|
let styleMatch;
|
|
716
|
-
const hasCompanionCss = fsPath.toLowerCase().endsWith(
|
|
717
|
-
fs.existsSync(fsPath.replace(/\.html$/i,
|
|
792
|
+
const hasCompanionCss = fsPath.toLowerCase().endsWith(".html") &&
|
|
793
|
+
fs.existsSync(fsPath.replace(/\.html$/i, ".css"));
|
|
718
794
|
const maskedText = text
|
|
719
|
-
.replace(/(<(style|textarea|script)(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)(<\/\2(?:[\t\n\f\r /][^>]*)?>)/gi, (_m, open, _tag, content, close) => open +
|
|
720
|
-
.replace(/<!--([\s\S]*?)-->/g, (_m, content) =>
|
|
795
|
+
.replace(/(<(style|textarea|script)(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)(<\/\2(?:[\t\n\f\r /][^>]*)?>)/gi, (_m, open, _tag, content, close) => open + " ".repeat(content.length) + close)
|
|
796
|
+
.replace(/<!--([\s\S]*?)-->/g, (_m, content) => "<!--" + " ".repeat(content.length) + "-->");
|
|
721
797
|
const componentMap = snapshot?.componentMap ?? new Map();
|
|
722
798
|
const componentNames = Array.from(componentMap.keys());
|
|
799
|
+
// Typos in Bascik's own attributes. Bascik ignores an attribute it does not know, so nothing else reports
|
|
800
|
+
// them. `<code>` contents are shown as text by default (`scoping.preserve`), so they are not scanned.
|
|
801
|
+
const attributeScanText = maskedText.replace(/(<code(?=[\t\n\f\r />])(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)(<\/code(?:[\t\n\f\r /][^>]*)?>)/gi, (_m, open, content, close) => open + content.replace(/[^\n]/g, " ") + close);
|
|
802
|
+
const anyOpenTagRe = /<([A-Za-z][\w-]*)((?:[^>"']|"[^"]*"|'[^']*')*)>/g;
|
|
803
|
+
let anyOpenTag;
|
|
804
|
+
while ((anyOpenTag = anyOpenTagRe.exec(attributeScanText)) !== null) {
|
|
805
|
+
const attributesOffset = anyOpenTag.index + 1 + anyOpenTag[1].length;
|
|
806
|
+
const attributeNameRe = /(?:^|\s)([^\s"'=<>`/]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?/g;
|
|
807
|
+
let attributeMatch;
|
|
808
|
+
while ((attributeMatch = attributeNameRe.exec(anyOpenTag[2])) !== null) {
|
|
809
|
+
const attributeName = attributeMatch[1].toLowerCase();
|
|
810
|
+
if (!attributeName.startsWith("data-bascik-") ||
|
|
811
|
+
isKnownBascikAttribute(attributeName))
|
|
812
|
+
continue;
|
|
813
|
+
const nameStart = attributesOffset +
|
|
814
|
+
attributeMatch.index +
|
|
815
|
+
attributeMatch[0].indexOf(attributeMatch[1]);
|
|
816
|
+
diagnostics.push({
|
|
817
|
+
range: {
|
|
818
|
+
start: document.positionAt(nameStart),
|
|
819
|
+
end: document.positionAt(nameStart + attributeMatch[1].length),
|
|
820
|
+
},
|
|
821
|
+
message: unknownBascikAttributeMessage(attributeName),
|
|
822
|
+
severity: DiagnosticSeverity.Warning,
|
|
823
|
+
source: "bascik",
|
|
824
|
+
code: "unknown-bascik-attribute",
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
// Component layout convention: styles above the markup, scripts below it.
|
|
829
|
+
if (isComponentDocument) {
|
|
830
|
+
for (const problem of findComponentStructureProblems(maskedText)) {
|
|
831
|
+
const tagLength = problem.kind === "script-before-markup"
|
|
832
|
+
? "<script".length
|
|
833
|
+
: "<style".length;
|
|
834
|
+
diagnostics.push({
|
|
835
|
+
range: {
|
|
836
|
+
start: document.positionAt(problem.index),
|
|
837
|
+
end: document.positionAt(problem.index + tagLength),
|
|
838
|
+
},
|
|
839
|
+
message: problem.message,
|
|
840
|
+
severity: DiagnosticSeverity.Warning,
|
|
841
|
+
source: "bascik",
|
|
842
|
+
code: "component-structure-order",
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
}
|
|
723
846
|
// 1. Diagnose script directives on non-script tags
|
|
724
847
|
const elementOpenTagRe = /<([A-Za-z][\w-]*)(?:\s+(?:[^>"']|"[^"]*"|'[^']*')*?)?\/?>/gi;
|
|
725
848
|
let elementMatch;
|
|
726
849
|
while ((elementMatch = elementOpenTagRe.exec(maskedText)) !== null) {
|
|
727
850
|
const tagName = elementMatch[1].toLowerCase();
|
|
728
|
-
if (tagName ===
|
|
851
|
+
if (tagName === "script")
|
|
729
852
|
continue;
|
|
730
853
|
const openTag = elementMatch[0];
|
|
731
854
|
const matchStart = elementMatch.index;
|
|
732
855
|
const scriptDirectives = new Set([
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
856
|
+
"data-bascik-build",
|
|
857
|
+
"data-bascik-server",
|
|
858
|
+
"data-bascik-routes",
|
|
859
|
+
"data-bascik-stream",
|
|
737
860
|
]);
|
|
738
861
|
const insideTag = openTag
|
|
739
|
-
.replace(/^<[A-Za-z][\w-]*\s*/i,
|
|
740
|
-
.replace(/\/?>$/,
|
|
741
|
-
const baseOffset = openTag.length - insideTag.length - (openTag.endsWith(
|
|
862
|
+
.replace(/^<[A-Za-z][\w-]*\s*/i, "")
|
|
863
|
+
.replace(/\/?>$/, "");
|
|
864
|
+
const baseOffset = openTag.length - insideTag.length - (openTag.endsWith("/>") ? 2 : 1);
|
|
742
865
|
const attrRe = /([^\s"'=<>`/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gi;
|
|
743
866
|
let attrMatch;
|
|
744
867
|
while ((attrMatch = attrRe.exec(insideTag)) !== null) {
|
|
@@ -748,9 +871,10 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
748
871
|
const end = document.positionAt(matchStart + baseOffset + attrMatch.index + attrMatch[1].length);
|
|
749
872
|
diagnostics.push({
|
|
750
873
|
range: { start, end },
|
|
874
|
+
code: "directive-on-non-script",
|
|
751
875
|
message: `\`${attrMatch[1]}\` is only valid on <script> tags. It has no effect on <${tagName}>.`,
|
|
752
876
|
severity: DiagnosticSeverity.Error,
|
|
753
|
-
source:
|
|
877
|
+
source: "bascik",
|
|
754
878
|
});
|
|
755
879
|
}
|
|
756
880
|
}
|
|
@@ -762,14 +886,14 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
762
886
|
const openTag = slotMatch[0];
|
|
763
887
|
const matchStart = slotMatch.index;
|
|
764
888
|
const insideTag = openTag
|
|
765
|
-
.replace(/^<[A-Za-z][\w-]*\s*/i,
|
|
766
|
-
.replace(/\/?>$/,
|
|
767
|
-
const baseOffset = openTag.length - insideTag.length - (openTag.endsWith(
|
|
889
|
+
.replace(/^<[A-Za-z][\w-]*\s*/i, "")
|
|
890
|
+
.replace(/\/?>$/, "");
|
|
891
|
+
const baseOffset = openTag.length - insideTag.length - (openTag.endsWith("/>") ? 2 : 1);
|
|
768
892
|
const attrRe = /([^\s"'=<>`/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gi;
|
|
769
893
|
let attrMatch;
|
|
770
894
|
let slotAttr = null;
|
|
771
895
|
while ((attrMatch = attrRe.exec(insideTag)) !== null) {
|
|
772
|
-
if (attrMatch[1].toLowerCase() ===
|
|
896
|
+
if (attrMatch[1].toLowerCase() === "data-bascik-slot") {
|
|
773
897
|
slotAttr = {
|
|
774
898
|
name: attrMatch[1],
|
|
775
899
|
value: attrMatch[2] ?? attrMatch[3] ?? attrMatch[4],
|
|
@@ -789,9 +913,10 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
789
913
|
const end = document.positionAt(matchStart + baseOffset + slotAttr.index + slotAttr.name.length);
|
|
790
914
|
diagnostics.push({
|
|
791
915
|
range: { start, end },
|
|
792
|
-
|
|
916
|
+
code: "slot-outside-component",
|
|
917
|
+
message: "`data-bascik-slot` is only valid inside a Bascik component body.",
|
|
793
918
|
severity: DiagnosticSeverity.Error,
|
|
794
|
-
source:
|
|
919
|
+
source: "bascik",
|
|
795
920
|
});
|
|
796
921
|
}
|
|
797
922
|
else if (parentName) {
|
|
@@ -803,9 +928,10 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
803
928
|
const end = document.positionAt(matchStart + baseOffset + slotAttr.index + slotAttr.name.length);
|
|
804
929
|
diagnostics.push({
|
|
805
930
|
range: { start, end },
|
|
931
|
+
code: "undeclared-slot",
|
|
806
932
|
message: `Component <${parentName}> does not declare slot "${slotName}".`,
|
|
807
933
|
severity: DiagnosticSeverity.Error,
|
|
808
|
-
source:
|
|
934
|
+
source: "bascik",
|
|
809
935
|
});
|
|
810
936
|
}
|
|
811
937
|
}
|
|
@@ -813,8 +939,8 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
813
939
|
}
|
|
814
940
|
if (componentNames.length > 0) {
|
|
815
941
|
componentNames.sort((a, b) => b.length - a.length);
|
|
816
|
-
const escapedNames = componentNames.map((name) => name.replace(/[.*+?^${}()|[\]\\]/g,
|
|
817
|
-
const componentTagRe = new RegExp(`<(${escapedNames.join(
|
|
942
|
+
const escapedNames = componentNames.map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
943
|
+
const componentTagRe = new RegExp(`<(${escapedNames.join("|")})\\b`, "gi");
|
|
818
944
|
let compMatch;
|
|
819
945
|
while ((compMatch = componentTagRe.exec(maskedText)) !== null) {
|
|
820
946
|
const tagStartIndex = compMatch.index;
|
|
@@ -830,7 +956,7 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
830
956
|
else if (char === "'" && !inDoubleQuote) {
|
|
831
957
|
inSingleQuote = !inSingleQuote;
|
|
832
958
|
}
|
|
833
|
-
else if (char ===
|
|
959
|
+
else if (char === ">" && !inDoubleQuote && !inSingleQuote) {
|
|
834
960
|
openTagEndIndex = i + 1;
|
|
835
961
|
break;
|
|
836
962
|
}
|
|
@@ -852,7 +978,38 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
852
978
|
range: { start, end },
|
|
853
979
|
message: `Component <${tagName}> does not declare prop "${propName}".`,
|
|
854
980
|
severity: DiagnosticSeverity.Warning,
|
|
855
|
-
source:
|
|
981
|
+
source: "bascik",
|
|
982
|
+
code: "undeclared-prop",
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (compMeta.props.length > 0) {
|
|
987
|
+
const insideOpenTag = openTagText
|
|
988
|
+
.replace(new RegExp(`^<${escapeRegExp(tagName)}\\b`, "i"), "")
|
|
989
|
+
.replace(/\/?>$/, "");
|
|
990
|
+
const baseAttrOffset = openTagText.indexOf(insideOpenTag);
|
|
991
|
+
const bareAttrRe = /([^\s"'=<>`/]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?/gi;
|
|
992
|
+
let bareMatch;
|
|
993
|
+
while ((bareMatch = bareAttrRe.exec(insideOpenTag)) !== null) {
|
|
994
|
+
const attrName = bareMatch[1];
|
|
995
|
+
const lowerAttr = attrName.toLowerCase();
|
|
996
|
+
if (lowerAttr.startsWith("data-bascik-"))
|
|
997
|
+
continue;
|
|
998
|
+
const declaredProp = compMeta.props.find((p) => p.name.toLowerCase() === lowerAttr);
|
|
999
|
+
if (!declaredProp)
|
|
1000
|
+
continue;
|
|
1001
|
+
const alreadySupplied = new RegExp(`\\bdata-bascik-prop-${escapeRegExp(declaredProp.name)}\\b`, "i").test(openTagText);
|
|
1002
|
+
if (alreadySupplied)
|
|
1003
|
+
continue;
|
|
1004
|
+
const attrOffset = tagStartIndex + baseAttrOffset + bareMatch.index;
|
|
1005
|
+
const start = document.positionAt(attrOffset);
|
|
1006
|
+
const end = document.positionAt(attrOffset + attrName.length);
|
|
1007
|
+
diagnostics.push({
|
|
1008
|
+
range: { start, end },
|
|
1009
|
+
message: `Component <${tagName}> declares prop "${declaredProp.name}". Pass it with the data-bascik-prop-${declaredProp.name} prefix instead of "${attrName}".`,
|
|
1010
|
+
severity: DiagnosticSeverity.Warning,
|
|
1011
|
+
source: "bascik",
|
|
1012
|
+
code: "missing-prop-prefix",
|
|
856
1013
|
});
|
|
857
1014
|
}
|
|
858
1015
|
}
|
|
@@ -867,8 +1024,8 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
867
1024
|
range: { start, end },
|
|
868
1025
|
message: `Component tag <${tagName}> is unclosed. It will be treated as self-closing (<${tagName}/>), but an explicit closing tag is recommended to avoid layout or scoping issues.`,
|
|
869
1026
|
severity: DiagnosticSeverity.Warning,
|
|
870
|
-
source:
|
|
871
|
-
code:
|
|
1027
|
+
source: "bascik",
|
|
1028
|
+
code: "unclosed-component-tag",
|
|
872
1029
|
});
|
|
873
1030
|
}
|
|
874
1031
|
else if (compMeta) {
|
|
@@ -880,8 +1037,8 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
880
1037
|
range: { start, end },
|
|
881
1038
|
message: `Component <${tagName}> defines no slots and accepts no children. Use self-closing tag <${tagName} /> instead of paired <${tagName}></${tagName}>.`,
|
|
882
1039
|
severity: DiagnosticSeverity.Warning,
|
|
883
|
-
source:
|
|
884
|
-
code:
|
|
1040
|
+
source: "bascik",
|
|
1041
|
+
code: "prefer-self-closing-component",
|
|
885
1042
|
});
|
|
886
1043
|
}
|
|
887
1044
|
}
|
|
@@ -897,25 +1054,26 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
897
1054
|
const openTag = match[1];
|
|
898
1055
|
const styleBodyOffset = (match.index ?? 0) + openTag.length;
|
|
899
1056
|
// maskedText blanks style bodies (same length), so read the real body from text.
|
|
900
|
-
const styleBody = text.slice(styleBodyOffset, styleBodyOffset + (match[2] ??
|
|
1057
|
+
const styleBody = text.slice(styleBodyOffset, styleBodyOffset + (match[2] ?? "").length);
|
|
901
1058
|
if (hasCompanionCss) {
|
|
902
1059
|
const start = document.positionAt(match.index ?? 0);
|
|
903
1060
|
const end = document.positionAt((match.index ?? 0) + openTag.length);
|
|
904
1061
|
diagnostics.push({
|
|
905
1062
|
range: { start, end },
|
|
906
|
-
|
|
1063
|
+
code: "inline-and-companion-styles",
|
|
1064
|
+
message: "Component has both a companion .css file and an inline <style> tag. They will be combined at build time, but mixing both is not recommended for readability and maintainability.",
|
|
907
1065
|
severity: DiagnosticSeverity.Warning,
|
|
908
|
-
source:
|
|
1066
|
+
source: "bascik",
|
|
909
1067
|
});
|
|
910
1068
|
}
|
|
911
|
-
addCompatibilityDiagnostics(styleBody,
|
|
1069
|
+
addCompatibilityDiagnostics(styleBody, "css", styleBodyOffset);
|
|
912
1070
|
}
|
|
913
1071
|
}
|
|
914
|
-
else if (languageId ===
|
|
915
|
-
addCompatibilityDiagnostics(text,
|
|
1072
|
+
else if (languageId === "css") {
|
|
1073
|
+
addCompatibilityDiagnostics(text, "css", 0);
|
|
916
1074
|
}
|
|
917
1075
|
else {
|
|
918
|
-
addCompatibilityDiagnostics(text,
|
|
1076
|
+
addCompatibilityDiagnostics(text, "js", 0);
|
|
919
1077
|
}
|
|
920
1078
|
const ignoreRanges = parseIgnoreDirectives(text, languageId);
|
|
921
1079
|
const extConfig = snapshot ? loadExtensionConfig(snapshot.projectRoot) : {};
|
|
@@ -925,15 +1083,15 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
925
1083
|
}
|
|
926
1084
|
return diagnostics.filter((diag) => {
|
|
927
1085
|
const line = diag.range.start.line;
|
|
928
|
-
const code = typeof diag.code ===
|
|
1086
|
+
const code = typeof diag.code === "string" ? diag.code : undefined;
|
|
929
1087
|
if (code && disabledRules.has(code.toLowerCase())) {
|
|
930
1088
|
return false;
|
|
931
1089
|
}
|
|
932
|
-
if (code ===
|
|
1090
|
+
if (code === "prefer-self-closing-component" &&
|
|
933
1091
|
extConfig.diagnostics?.selfClosingComponents === false) {
|
|
934
1092
|
return false;
|
|
935
1093
|
}
|
|
936
|
-
if (code ===
|
|
1094
|
+
if (code === "unclosed-component-tag" &&
|
|
937
1095
|
extConfig.diagnostics?.unclosedComponents === false) {
|
|
938
1096
|
return false;
|
|
939
1097
|
}
|
|
@@ -941,10 +1099,10 @@ export function createDiagnostics(document, fsPath, snapshot, openDocumentTexts
|
|
|
941
1099
|
});
|
|
942
1100
|
}
|
|
943
1101
|
export function createCompletions(document, position, snapshot) {
|
|
944
|
-
if (document.languageId !==
|
|
1102
|
+
if (document.languageId !== "html")
|
|
945
1103
|
return undefined;
|
|
946
1104
|
const offset = document.offsetAt(position);
|
|
947
|
-
const maskedSource = maskHtmlRawTextContents(document.getText()).replace(/<!--[\s\S]*?(?:-->|$)/g, (comment) =>
|
|
1105
|
+
const maskedSource = maskHtmlRawTextContents(document.getText()).replace(/<!--[\s\S]*?(?:-->|$)/g, (comment) => " ".repeat(comment.length));
|
|
948
1106
|
const sourceBeforeCursor = maskedSource.slice(0, offset);
|
|
949
1107
|
const tagMatch = /<([A-Za-z][\w-]*)?$/.exec(sourceBeforeCursor);
|
|
950
1108
|
if (!tagMatch) {
|
|
@@ -954,8 +1112,8 @@ export function createCompletions(document, position, snapshot) {
|
|
|
954
1112
|
const currentTagName = openTagMatch[1].toLowerCase();
|
|
955
1113
|
const openTagText = openTagMatch[0];
|
|
956
1114
|
const currentTagStart = offset - openTagText.length;
|
|
957
|
-
if (currentTagName ===
|
|
958
|
-
const hasAnyDirective = SCRIPT_DIRECTIVES.some((dir) => new RegExp(`\\b${dir.name}\\b`,
|
|
1115
|
+
if (currentTagName === "script") {
|
|
1116
|
+
const hasAnyDirective = SCRIPT_DIRECTIVES.some((dir) => new RegExp(`\\b${dir.name}\\b`, "i").test(openTagText));
|
|
959
1117
|
if (hasAnyDirective)
|
|
960
1118
|
return [];
|
|
961
1119
|
const range = completionReplacementRange(document, position);
|
|
@@ -978,7 +1136,7 @@ export function createCompletions(document, position, snapshot) {
|
|
|
978
1136
|
if (currentComponentMetadata) {
|
|
979
1137
|
const range = completionReplacementRange(document, position);
|
|
980
1138
|
return currentComponentMetadata.props
|
|
981
|
-
.filter(({ name }) => !new RegExp(`\\bdata-bascik-prop-${escapeRegExp(name)}\\s*=`,
|
|
1139
|
+
.filter(({ name }) => !new RegExp(`\\bdata-bascik-prop-${escapeRegExp(name)}\\s*=`, "i").test(openTagText))
|
|
982
1140
|
.map((prop) => {
|
|
983
1141
|
const attribute = `data-bascik-prop-${prop.name}`;
|
|
984
1142
|
const item = {
|
|
@@ -990,12 +1148,12 @@ export function createCompletions(document, position, snapshot) {
|
|
|
990
1148
|
},
|
|
991
1149
|
insertTextFormat: 2, // Snippet
|
|
992
1150
|
sortText: `0_${attribute}`,
|
|
993
|
-
detail:
|
|
1151
|
+
detail: "Bascik component prop",
|
|
994
1152
|
};
|
|
995
1153
|
if (prop.description) {
|
|
996
1154
|
item.documentation = {
|
|
997
1155
|
kind: MarkupKind.Markdown,
|
|
998
|
-
value: prop.description,
|
|
1156
|
+
value: escapeMarkdownText(prop.description),
|
|
999
1157
|
};
|
|
1000
1158
|
}
|
|
1001
1159
|
return item;
|
|
@@ -1020,12 +1178,12 @@ export function createCompletions(document, position, snapshot) {
|
|
|
1020
1178
|
},
|
|
1021
1179
|
filterText: `data-bascik-slot ${slot.name}`,
|
|
1022
1180
|
sortText: `0_data-bascik-slot_${slot.name}`,
|
|
1023
|
-
detail:
|
|
1181
|
+
detail: "Bascik named slot",
|
|
1024
1182
|
};
|
|
1025
1183
|
if (slot.description) {
|
|
1026
1184
|
item.documentation = {
|
|
1027
1185
|
kind: MarkupKind.Markdown,
|
|
1028
|
-
value: slot.description,
|
|
1186
|
+
value: escapeMarkdownText(slot.description),
|
|
1029
1187
|
};
|
|
1030
1188
|
}
|
|
1031
1189
|
return item;
|
|
@@ -1033,52 +1191,54 @@ export function createCompletions(document, position, snapshot) {
|
|
|
1033
1191
|
}
|
|
1034
1192
|
const tagStart = offset - tagMatch[0].length;
|
|
1035
1193
|
const sourceBeforeTag = sourceBeforeCursor.slice(0, tagStart);
|
|
1036
|
-
const previousTagStart = sourceBeforeTag.lastIndexOf(
|
|
1037
|
-
const previousTagEnd = sourceBeforeTag.lastIndexOf(
|
|
1194
|
+
const previousTagStart = sourceBeforeTag.lastIndexOf("<");
|
|
1195
|
+
const previousTagEnd = sourceBeforeTag.lastIndexOf(">");
|
|
1038
1196
|
if (previousTagStart > previousTagEnd)
|
|
1039
1197
|
return undefined;
|
|
1040
|
-
const prefix = (tagMatch[1] ??
|
|
1198
|
+
const prefix = (tagMatch[1] ?? "").toLowerCase();
|
|
1041
1199
|
const start = document.positionAt(offset - prefix.length);
|
|
1042
1200
|
const replacementRange = { start, end: position };
|
|
1043
1201
|
const scriptShorthands = [
|
|
1044
1202
|
{
|
|
1045
|
-
label:
|
|
1046
|
-
detail:
|
|
1047
|
-
documentation:
|
|
1203
|
+
label: "bascik-build",
|
|
1204
|
+
detail: "Bascik build-time script block",
|
|
1205
|
+
documentation: "Executes in Node.js at build time. The default exported handler function returns HTML markup that replaces this script tag in the generated HTML.",
|
|
1048
1206
|
insertText: `<script data-bascik-build>\n export default async function () {\n return \`$0\`;\n }\n</script>`,
|
|
1049
1207
|
},
|
|
1050
1208
|
{
|
|
1051
|
-
label:
|
|
1052
|
-
detail:
|
|
1053
|
-
documentation:
|
|
1209
|
+
label: "bascik-routes",
|
|
1210
|
+
detail: "Bascik dynamic routes script block",
|
|
1211
|
+
documentation: "Executes in Node.js at build time. The default exported handler function returns an array of dynamic route parameters to generate multiple pages from a template.",
|
|
1054
1212
|
insertText: `<script data-bascik-routes>\n export default async function () {\n return [\n $0\n ];\n }\n</script>`,
|
|
1055
1213
|
},
|
|
1056
1214
|
{
|
|
1057
|
-
label:
|
|
1058
|
-
detail:
|
|
1059
|
-
documentation:
|
|
1215
|
+
label: "bascik-server",
|
|
1216
|
+
detail: "Bascik server-side request script block",
|
|
1217
|
+
documentation: "Executes in Node.js per request on production and dev servers. The default exported handler function replaces this script tag.",
|
|
1060
1218
|
insertText: `<script data-bascik-server>\n export default async function (request, context, { signal }) {\n return \`$0\`;\n }\n</script>`,
|
|
1061
1219
|
},
|
|
1062
1220
|
{
|
|
1063
|
-
label:
|
|
1064
|
-
detail:
|
|
1065
|
-
documentation:
|
|
1221
|
+
label: "bascik-stream",
|
|
1222
|
+
detail: "Bascik server-side streaming script block",
|
|
1223
|
+
documentation: "Executes in Node.js per request on production servers. Streams chunked HTML responses to the client as data becomes available.",
|
|
1066
1224
|
insertText: `<script data-bascik-stream>\n export default async function (request, context, { signal }) {\n return \`$0\`;\n }\n</script>`,
|
|
1067
1225
|
},
|
|
1068
1226
|
];
|
|
1227
|
+
// The replacement starts at the "<" already typed, so the filter text must start there too, or the editor
|
|
1228
|
+
// compares what was typed ("<my-b") against a label without it and hides every item.
|
|
1229
|
+
const tagRange = {
|
|
1230
|
+
start: document.positionAt(tagStart),
|
|
1231
|
+
end: replacementRange.end,
|
|
1232
|
+
};
|
|
1069
1233
|
const shorthandItems = scriptShorthands
|
|
1070
1234
|
.filter((shorthand) => shorthand.label.startsWith(prefix))
|
|
1071
1235
|
.map((shorthand) => ({
|
|
1072
1236
|
label: shorthand.label,
|
|
1073
1237
|
kind: CompletionItemKind.Snippet,
|
|
1074
1238
|
sortText: `0_${shorthand.label}`,
|
|
1075
|
-
range:
|
|
1076
|
-
start: document.positionAt(tagStart),
|
|
1077
|
-
end: replacementRange.end,
|
|
1078
|
-
},
|
|
1079
|
-
insertText: shorthand.insertText,
|
|
1239
|
+
textEdit: { range: tagRange, newText: shorthand.insertText },
|
|
1080
1240
|
insertTextFormat: 2, // Snippet
|
|
1081
|
-
filterText: shorthand.label
|
|
1241
|
+
filterText: `<${shorthand.label}`,
|
|
1082
1242
|
detail: shorthand.detail,
|
|
1083
1243
|
documentation: {
|
|
1084
1244
|
kind: MarkupKind.Markdown,
|
|
@@ -1092,21 +1252,20 @@ export function createCompletions(document, position, snapshot) {
|
|
|
1092
1252
|
const metadata = snapshot.componentMetadata.get(componentName);
|
|
1093
1253
|
const relativePath = path
|
|
1094
1254
|
.relative(snapshot.projectRoot, componentPath)
|
|
1095
|
-
.replace(/\\/g,
|
|
1255
|
+
.replace(/\\/g, "/");
|
|
1096
1256
|
return {
|
|
1097
1257
|
label: componentName,
|
|
1098
1258
|
kind: CompletionItemKind.Class,
|
|
1099
1259
|
sortText: `0_${componentName}`,
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1260
|
+
textEdit: {
|
|
1261
|
+
range: tagRange,
|
|
1262
|
+
newText: metadata?.defaultSlot
|
|
1263
|
+
? `<${componentName}>$0</${componentName}>`
|
|
1264
|
+
: `<${componentName} />$0`,
|
|
1103
1265
|
},
|
|
1104
|
-
insertText: metadata?.defaultSlot
|
|
1105
|
-
? `<${componentName}>$0</${componentName}>`
|
|
1106
|
-
: `<${componentName} />$0`,
|
|
1107
1266
|
insertTextFormat: 2, // Snippet
|
|
1108
|
-
filterText: componentName
|
|
1109
|
-
detail:
|
|
1267
|
+
filterText: `<${componentName}`,
|
|
1268
|
+
detail: "Bascik component",
|
|
1110
1269
|
documentation: {
|
|
1111
1270
|
kind: MarkupKind.Markdown,
|
|
1112
1271
|
value: createComponentDocumentationMarkdown(relativePath, metadata),
|
|
@@ -1149,34 +1308,34 @@ export function createHover(document, position, snapshot) {
|
|
|
1149
1308
|
return undefined;
|
|
1150
1309
|
const relativePath = path
|
|
1151
1310
|
.relative(snapshot.projectRoot, componentPath)
|
|
1152
|
-
.replace(/\\/g,
|
|
1311
|
+
.replace(/\\/g, "/");
|
|
1153
1312
|
const details = [`### \`<${componentName}>\`\n\n`];
|
|
1154
1313
|
if (metadata.description) {
|
|
1155
|
-
details.push(metadata.description,
|
|
1314
|
+
details.push(escapeMarkdownText(metadata.description), "\n\n");
|
|
1156
1315
|
}
|
|
1157
|
-
details.push(`**Source:** [\`${relativePath}\`](
|
|
1158
|
-
appendMetadataMembersMarkdown(details,
|
|
1159
|
-
appendMetadataMembersMarkdown(details,
|
|
1316
|
+
details.push(`**Source:** [\`${relativePath}\`](${pathToFileURL(componentPath).toString()})\n\n`);
|
|
1317
|
+
appendMetadataMembersMarkdown(details, "Props", metadata.props);
|
|
1318
|
+
appendMetadataMembersMarkdown(details, "Slots", [
|
|
1160
1319
|
...metadata.slots,
|
|
1161
1320
|
...(metadata.defaultSlot ? [metadata.defaultSlot] : []),
|
|
1162
1321
|
]);
|
|
1163
1322
|
const features = [
|
|
1164
|
-
metadata.hasStyles ?
|
|
1165
|
-
metadata.hasScripts ?
|
|
1323
|
+
metadata.hasStyles ? "styles" : "",
|
|
1324
|
+
metadata.hasScripts ? "scripts" : "",
|
|
1166
1325
|
].filter(Boolean);
|
|
1167
1326
|
if (features.length > 0) {
|
|
1168
|
-
details.push(`**Includes:** ${features.join(
|
|
1327
|
+
details.push(`**Includes:** ${features.join(", ")}`);
|
|
1169
1328
|
}
|
|
1170
1329
|
return {
|
|
1171
1330
|
contents: {
|
|
1172
1331
|
kind: MarkupKind.Markdown,
|
|
1173
|
-
value: details.join(
|
|
1332
|
+
value: details.join(""),
|
|
1174
1333
|
},
|
|
1175
1334
|
range: wordRange,
|
|
1176
1335
|
};
|
|
1177
1336
|
}
|
|
1178
1337
|
export function createDefinition(document, position, snapshot, fsPath) {
|
|
1179
|
-
if (document.languageId !==
|
|
1338
|
+
if (document.languageId !== "html")
|
|
1180
1339
|
return undefined;
|
|
1181
1340
|
// 1. Check for script import definition
|
|
1182
1341
|
const text = document.getText();
|
|
@@ -1185,16 +1344,16 @@ export function createDefinition(document, position, snapshot, fsPath) {
|
|
|
1185
1344
|
let scriptMatch;
|
|
1186
1345
|
while ((scriptMatch = SCRIPT_BLOCK_RE.exec(text)) !== null) {
|
|
1187
1346
|
const openTag = scriptMatch[1];
|
|
1188
|
-
const scriptBody = scriptMatch[2] ??
|
|
1347
|
+
const scriptBody = scriptMatch[2] ?? "";
|
|
1189
1348
|
const blockStart = scriptMatch.index ?? 0;
|
|
1190
1349
|
const openTagEnd = blockStart + openTag.length;
|
|
1191
1350
|
const blockEnd = blockStart + scriptMatch[0].length;
|
|
1192
1351
|
if (offset < blockStart || offset > blockEnd)
|
|
1193
1352
|
continue;
|
|
1194
1353
|
const attrs = parseScriptOpenTagAttributes(openTag);
|
|
1195
|
-
if (!attrs.has(
|
|
1196
|
-
!attrs.has(
|
|
1197
|
-
!attrs.has(
|
|
1354
|
+
if (!attrs.has("data-bascik-build") &&
|
|
1355
|
+
!attrs.has("data-bascik-server") &&
|
|
1356
|
+
!attrs.has("data-bascik-routes")) {
|
|
1198
1357
|
return undefined;
|
|
1199
1358
|
}
|
|
1200
1359
|
const baseDir = path.dirname(fsPath);
|
|
@@ -1203,14 +1362,14 @@ export function createDefinition(document, position, snapshot, fsPath) {
|
|
|
1203
1362
|
const srcMatch = /\ssrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(openTag);
|
|
1204
1363
|
if (!srcMatch)
|
|
1205
1364
|
return undefined;
|
|
1206
|
-
const srcValue = srcMatch[1] ?? srcMatch[2] ?? srcMatch[3] ??
|
|
1365
|
+
const srcValue = srcMatch[1] ?? srcMatch[2] ?? srcMatch[3] ?? "";
|
|
1207
1366
|
if (!srcValue)
|
|
1208
1367
|
return undefined;
|
|
1209
1368
|
const valueStart = blockStart + (srcMatch.index ?? 0) + srcMatch[0].indexOf(srcValue);
|
|
1210
1369
|
const valueEnd = valueStart + srcValue.length;
|
|
1211
1370
|
if (offset < valueStart || offset > valueEnd)
|
|
1212
1371
|
return undefined;
|
|
1213
|
-
const resolved = resolveScriptTarget(srcValue, baseDir, importRootAbs,
|
|
1372
|
+
const resolved = resolveScriptTarget(srcValue, baseDir, importRootAbs, "src");
|
|
1214
1373
|
if (!resolved || !fs.existsSync(resolved))
|
|
1215
1374
|
return undefined;
|
|
1216
1375
|
return [
|
|
@@ -1235,7 +1394,7 @@ export function createDefinition(document, position, snapshot, fsPath) {
|
|
|
1235
1394
|
for (const { start, end, value: specifier } of findModuleSpecifiers(scriptBody)) {
|
|
1236
1395
|
if (bodyOffset < start || bodyOffset > end)
|
|
1237
1396
|
continue;
|
|
1238
|
-
const resolved = resolveScriptTarget(specifier, baseDir, importRootAbs,
|
|
1397
|
+
const resolved = resolveScriptTarget(specifier, baseDir, importRootAbs, "specifier");
|
|
1239
1398
|
if (!resolved || !fs.existsSync(resolved))
|
|
1240
1399
|
return undefined;
|
|
1241
1400
|
return [
|
|
@@ -1295,4 +1454,104 @@ export function createDefinition(document, position, snapshot, fsPath) {
|
|
|
1295
1454
|
}
|
|
1296
1455
|
return undefined;
|
|
1297
1456
|
}
|
|
1457
|
+
function rangesOverlap(a, b) {
|
|
1458
|
+
if (a.end.line < b.start.line || b.end.line < a.start.line)
|
|
1459
|
+
return false;
|
|
1460
|
+
if (a.end.line === b.start.line && a.end.character < b.start.character)
|
|
1461
|
+
return false;
|
|
1462
|
+
if (b.end.line === a.start.line && b.end.character < a.start.character)
|
|
1463
|
+
return false;
|
|
1464
|
+
return true;
|
|
1465
|
+
}
|
|
1466
|
+
export function buildAutoFixEdit(document, diag) {
|
|
1467
|
+
const code = typeof diag.code === "string" ? diag.code : undefined;
|
|
1468
|
+
if (code === "missing-prop-prefix") {
|
|
1469
|
+
const rawAttr = document.getText(diag.range);
|
|
1470
|
+
if (!rawAttr || rawAttr.toLowerCase().startsWith("data-bascik-prop-")) {
|
|
1471
|
+
return undefined;
|
|
1472
|
+
}
|
|
1473
|
+
const newText = `data-bascik-prop-${rawAttr}`;
|
|
1474
|
+
return {
|
|
1475
|
+
title: `Prefix prop with data-bascik-prop- (${newText})`,
|
|
1476
|
+
edit: {
|
|
1477
|
+
range: diag.range,
|
|
1478
|
+
newText,
|
|
1479
|
+
},
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
if (code === "prefer-self-closing-component") {
|
|
1483
|
+
const fullText = document.getText(diag.range);
|
|
1484
|
+
const match = /^<([A-Za-z][\w-]*)(\s+(?:[^>"']|"[^"]*"|'[^']*')*?)?>\s*<\/\1\s*>$/is.exec(fullText);
|
|
1485
|
+
if (!match)
|
|
1486
|
+
return undefined;
|
|
1487
|
+
const tagName = match[1];
|
|
1488
|
+
const attrs = (match[2] ?? "").trimEnd();
|
|
1489
|
+
const newText = `<${tagName}${attrs} />`;
|
|
1490
|
+
return {
|
|
1491
|
+
title: `Convert <${tagName}> to self-closing tag`,
|
|
1492
|
+
edit: {
|
|
1493
|
+
range: diag.range,
|
|
1494
|
+
newText,
|
|
1495
|
+
},
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
return undefined;
|
|
1499
|
+
}
|
|
1500
|
+
export function createCodeActions(document, range, diagnostics, snapshot, fsPath) {
|
|
1501
|
+
const activeDiagnostics = diagnostics.length > 0
|
|
1502
|
+
? diagnostics
|
|
1503
|
+
: fsPath
|
|
1504
|
+
? createDiagnostics(document, fsPath, snapshot)
|
|
1505
|
+
: [];
|
|
1506
|
+
const actions = [];
|
|
1507
|
+
for (const diag of activeDiagnostics) {
|
|
1508
|
+
if (!rangesOverlap(diag.range, range))
|
|
1509
|
+
continue;
|
|
1510
|
+
const fix = buildAutoFixEdit(document, diag);
|
|
1511
|
+
if (!fix)
|
|
1512
|
+
continue;
|
|
1513
|
+
actions.push({
|
|
1514
|
+
title: fix.title,
|
|
1515
|
+
kind: CodeActionKind.QuickFix,
|
|
1516
|
+
diagnostics: [diag],
|
|
1517
|
+
isPreferred: true,
|
|
1518
|
+
edit: {
|
|
1519
|
+
changes: {
|
|
1520
|
+
[document.uri]: [fix.edit],
|
|
1521
|
+
},
|
|
1522
|
+
},
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
return actions;
|
|
1526
|
+
}
|
|
1527
|
+
export function applyAutoFixes(document, snapshot, fsPath = "/virtual.html") {
|
|
1528
|
+
const diags = createDiagnostics(document, fsPath, snapshot);
|
|
1529
|
+
const edits = [];
|
|
1530
|
+
for (const diag of diags) {
|
|
1531
|
+
const fix = buildAutoFixEdit(document, diag);
|
|
1532
|
+
if (!fix)
|
|
1533
|
+
continue;
|
|
1534
|
+
const startOffset = document.offsetAt(fix.edit.range.start);
|
|
1535
|
+
const endOffset = document.offsetAt(fix.edit.range.end);
|
|
1536
|
+
edits.push({ startOffset, endOffset, newText: fix.edit.newText });
|
|
1537
|
+
}
|
|
1538
|
+
if (edits.length === 0) {
|
|
1539
|
+
return { text: document.getText(), fixedCount: 0 };
|
|
1540
|
+
}
|
|
1541
|
+
edits.sort((a, b) => b.startOffset - a.startOffset);
|
|
1542
|
+
let text = document.getText();
|
|
1543
|
+
let fixedCount = 0;
|
|
1544
|
+
let lastStart = Number.POSITIVE_INFINITY;
|
|
1545
|
+
for (const edit of edits) {
|
|
1546
|
+
if (edit.endOffset > lastStart)
|
|
1547
|
+
continue;
|
|
1548
|
+
text =
|
|
1549
|
+
text.slice(0, edit.startOffset) +
|
|
1550
|
+
edit.newText +
|
|
1551
|
+
text.slice(edit.endOffset);
|
|
1552
|
+
lastStart = edit.startOffset;
|
|
1553
|
+
fixedCount++;
|
|
1554
|
+
}
|
|
1555
|
+
return { text, fixedCount };
|
|
1556
|
+
}
|
|
1298
1557
|
//# sourceMappingURL=analyzer.js.map
|