@bascik/language-server 0.1.0-rc.4 → 0.1.0-rc.6

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.
Files changed (119) hide show
  1. package/README.md +72 -30
  2. package/dist/analyzer.d.ts +70 -1
  3. package/dist/analyzer.d.ts.map +1 -1
  4. package/dist/analyzer.js +657 -77
  5. package/dist/analyzer.js.map +1 -1
  6. package/dist/api-rules.d.ts +7 -0
  7. package/dist/api-rules.d.ts.map +1 -1
  8. package/dist/api-rules.js +235 -16
  9. package/dist/api-rules.js.map +1 -1
  10. package/dist/bin.js +4 -1
  11. package/dist/bin.js.map +1 -1
  12. package/dist/check.d.ts +14 -1
  13. package/dist/check.d.ts.map +1 -1
  14. package/dist/check.js +116 -10
  15. package/dist/check.js.map +1 -1
  16. package/dist/cli.d.ts.map +1 -1
  17. package/dist/cli.js +27 -8
  18. package/dist/cli.js.map +1 -1
  19. package/dist/compatibility-rules.json +21 -3
  20. package/dist/component-metadata.d.ts.map +1 -1
  21. package/dist/component-metadata.js +3 -1
  22. package/dist/component-metadata.js.map +1 -1
  23. package/dist/component-usages.d.ts +47 -0
  24. package/dist/component-usages.d.ts.map +1 -0
  25. package/dist/component-usages.js +495 -0
  26. package/dist/component-usages.js.map +1 -0
  27. package/dist/config-reader.d.ts +41 -0
  28. package/dist/config-reader.d.ts.map +1 -0
  29. package/dist/config-reader.js +461 -0
  30. package/dist/config-reader.js.map +1 -0
  31. package/dist/config.d.ts +10 -0
  32. package/dist/config.d.ts.map +1 -1
  33. package/dist/config.js +25 -30
  34. package/dist/config.js.map +1 -1
  35. package/dist/directive-rules.d.ts +3 -3
  36. package/dist/directive-rules.d.ts.map +1 -1
  37. package/dist/directive-rules.js +6 -6
  38. package/dist/directive-rules.js.map +1 -1
  39. package/dist/hand-written-escaper.d.ts +35 -0
  40. package/dist/hand-written-escaper.d.ts.map +1 -0
  41. package/dist/hand-written-escaper.js +739 -0
  42. package/dist/hand-written-escaper.js.map +1 -0
  43. package/dist/module-specifiers.d.ts +25 -0
  44. package/dist/module-specifiers.d.ts.map +1 -1
  45. package/dist/module-specifiers.js +234 -165
  46. package/dist/module-specifiers.js.map +1 -1
  47. package/dist/name-groups.d.ts +36 -0
  48. package/dist/name-groups.d.ts.map +1 -0
  49. package/dist/name-groups.js +198 -0
  50. package/dist/name-groups.js.map +1 -0
  51. package/dist/plain-holes.d.ts +116 -0
  52. package/dist/plain-holes.d.ts.map +1 -0
  53. package/dist/plain-holes.js +1970 -0
  54. package/dist/plain-holes.js.map +1 -0
  55. package/dist/project.d.ts +58 -1
  56. package/dist/project.d.ts.map +1 -1
  57. package/dist/project.js +146 -8
  58. package/dist/project.js.map +1 -1
  59. package/dist/references.d.ts +47 -0
  60. package/dist/references.d.ts.map +1 -0
  61. package/dist/references.js +241 -0
  62. package/dist/references.js.map +1 -0
  63. package/dist/script-modules.d.ts +60 -0
  64. package/dist/script-modules.d.ts.map +1 -0
  65. package/dist/script-modules.js +382 -0
  66. package/dist/script-modules.js.map +1 -0
  67. package/dist/server-script-rules.d.ts +94 -1
  68. package/dist/server-script-rules.d.ts.map +1 -1
  69. package/dist/server-script-rules.js +2572 -230
  70. package/dist/server-script-rules.js.map +1 -1
  71. package/dist/server-script-templates.d.ts +250 -0
  72. package/dist/server-script-templates.d.ts.map +1 -0
  73. package/dist/server-script-templates.js +1685 -0
  74. package/dist/server-script-templates.js.map +1 -0
  75. package/dist/server.d.ts +191 -3
  76. package/dist/server.d.ts.map +1 -1
  77. package/dist/server.js +822 -50
  78. package/dist/server.js.map +1 -1
  79. package/dist/start.d.ts +10 -1
  80. package/dist/start.d.ts.map +1 -1
  81. package/dist/start.js +14 -2
  82. package/dist/start.js.map +1 -1
  83. package/dist/string-typed-flow.d.ts +26 -0
  84. package/dist/string-typed-flow.d.ts.map +1 -0
  85. package/dist/string-typed-flow.js +496 -0
  86. package/dist/string-typed-flow.js.map +1 -0
  87. package/dist/typescript-blocks.d.ts +205 -0
  88. package/dist/typescript-blocks.d.ts.map +1 -0
  89. package/dist/typescript-blocks.js +464 -0
  90. package/dist/typescript-blocks.js.map +1 -0
  91. package/dist/typescript-editor-mode.d.ts +28 -0
  92. package/dist/typescript-editor-mode.d.ts.map +1 -0
  93. package/dist/typescript-editor-mode.js +161 -0
  94. package/dist/typescript-editor-mode.js.map +1 -0
  95. package/dist/typescript-engine.d.ts +115 -0
  96. package/dist/typescript-engine.d.ts.map +1 -0
  97. package/dist/typescript-engine.js +286 -0
  98. package/dist/typescript-engine.js.map +1 -0
  99. package/dist/typescript-features.d.ts +136 -0
  100. package/dist/typescript-features.d.ts.map +1 -0
  101. package/dist/typescript-features.js +374 -0
  102. package/dist/typescript-features.js.map +1 -0
  103. package/dist/typescript-loader.d.ts +55 -0
  104. package/dist/typescript-loader.d.ts.map +1 -0
  105. package/dist/typescript-loader.js +202 -0
  106. package/dist/typescript-loader.js.map +1 -0
  107. package/dist/typescript-lsp.d.ts +8 -0
  108. package/dist/typescript-lsp.d.ts.map +1 -0
  109. package/dist/typescript-lsp.js +115 -0
  110. package/dist/typescript-lsp.js.map +1 -0
  111. package/dist/typescript-service.d.ts +350 -0
  112. package/dist/typescript-service.d.ts.map +1 -0
  113. package/dist/typescript-service.js +1465 -0
  114. package/dist/typescript-service.js.map +1 -0
  115. package/dist/typescript-worker.d.ts +11 -0
  116. package/dist/typescript-worker.d.ts.map +1 -0
  117. package/dist/typescript-worker.js +107 -0
  118. package/dist/typescript-worker.js.map +1 -0
  119. package/package.json +20 -7
@@ -0,0 +1,205 @@
1
+ import { type ComponentSource, type ProjectSnapshot } from "./project.js";
2
+ /** Which program checks a block: the browser one (DOM, no Node types) or the server one (Node, no DOM). */
3
+ export type TypeScriptProgramKind = "client" | "server";
4
+ /** The language VS Code's HTML support embeds a script as, or `undefined` for one it leaves alone. */
5
+ export type EditorScriptLanguage = "typescript" | "javascript" | undefined;
6
+ /** The Bascik directive on a block's script tag, or `undefined` for a client script. */
7
+ export type TypeScriptBlockDirective = "build" | "build-once" | "routes" | "server" | "stream";
8
+ export interface TypeScriptBlock {
9
+ /** Position among the file's TypeScript blocks, from 0. */
10
+ index: number;
11
+ directive: TypeScriptBlockDirective | undefined;
12
+ program: TypeScriptProgramKind;
13
+ /** Offset of the block's first character in the HTML. */
14
+ contentStart: number;
15
+ content: string;
16
+ /**
17
+ * The language VS Code's HTML support embeds the block as, so its own in-file mode answers about it, or
18
+ * `undefined` when it embeds nothing (see `editorScriptLanguage`). An uppercase `TYPE="text/typescript"` leaves
19
+ * the block JavaScript there: its JavaScript mode reads it with the page's plain scripts.
20
+ */
21
+ editorLanguage: EditorScriptLanguage;
22
+ }
23
+ /** Whether a TypeScript block needs scanning at all: a cheap test before any work. */
24
+ export declare function mayHaveTypeScriptBlocks(html: string): boolean;
25
+ /**
26
+ * The language VS Code's HTML support embeds a script as. Its scanner starts every script as JavaScript, and an
27
+ * attribute whose name is `type` as written (so not `TYPE`) with a value changes that: the value as written, quotes
28
+ * included, matching `/["'](module|(text|application)\/(java|ecma)script|text\/babel)["']/` makes it JavaScript,
29
+ * `/["']text\/typescript["']/` TypeScript, and anything else nothing. The last such attribute wins. So
30
+ * `type="text/TypeScript"`, `type=text/typescript` and `type=" text/typescript"`, which Bascik compiles as
31
+ * TypeScript, are embedded as nothing, and `TYPE="text/typescript"` as JavaScript.
32
+ */
33
+ export declare function editorScriptLanguage(openTag: string): EditorScriptLanguage;
34
+ /**
35
+ * The text of every script VS Code's HTML support embeds as `language`, in source order: the scripts its mode for
36
+ * that language reads together as one file.
37
+ */
38
+ export declare function editorEmbeddedScripts(html: string, language: "typescript" | "javascript"): {
39
+ contentStart: number;
40
+ content: string;
41
+ }[];
42
+ /**
43
+ * The `type="text/typescript"` script blocks of an HTML file, in source order. A block inside an HTML comment, a
44
+ * script with `src`, a script whose tag or element never closes, and a script with any other type are not blocks.
45
+ */
46
+ export declare function extractTypeScriptBlocks(html: string): TypeScriptBlock[];
47
+ /**
48
+ * Whether an HTML file has a TypeScript block, so checking it needs TypeScript. A page that only names the type (in
49
+ * prose, a `<pre>`, a comment or a data block) has none, and must never load TypeScript or keep it loaded.
50
+ */
51
+ export declare function hasTypeScriptBlocks(html: string): boolean;
52
+ /**
53
+ * What checking a page's blocks needs from the components it uses, directly or through others: `pageScopeHtml`,
54
+ * the HTML of those whose client scripts run in the page's scope (all of them with `scoping.scriptBlocks` off,
55
+ * none otherwise), whose names are the page's globals; and `usedComponents`, those with a TypeScript block, whose
56
+ * additions to the browser's globals (`interface Window { ... }`, `declare global`) hold on the page too, as their
57
+ * scripts run there. `readOpen` gives an open editor buffer's newer text.
58
+ */
59
+ export declare function pageComponentsForTypeScript(fsPath: string, text: string, snapshot: Pick<ProjectSnapshot, "scopesScriptBlocks" | "componentMap"> & Partial<Pick<ProjectSnapshot, "componentSourceByFile">>, readOpen?: (fsPath: string) => string | undefined): {
60
+ pageScopeHtml: string[];
61
+ usedComponents: ComponentSource[];
62
+ };
63
+ /**
64
+ * The TypeScript block whose content holds `offset` (its end included, where the cursor sits after the last
65
+ * character), or `undefined` when the offset is outside every block.
66
+ */
67
+ export declare function typeScriptBlockAt(html: string, offset: number): TypeScriptBlock | undefined;
68
+ /** A script that runs in the browser in a page's shared scope. */
69
+ export interface PageScopeScript {
70
+ /** `type="text/typescript"` (Bascik strips the types) or plain JavaScript. */
71
+ typed: boolean;
72
+ content: string;
73
+ }
74
+ /**
75
+ * The inline scripts of an HTML file that the browser runs as classic scripts, so their top-level names are
76
+ * globals every other classic script on the page sees: plain JavaScript ones (no `type`, or a JavaScript type)
77
+ * and `type="text/typescript"` ones. A module, a data block, a script with `src` and a server-side script (a
78
+ * Bascik directive) are not among them.
79
+ */
80
+ export declare function extractPageScopeScripts(html: string): PageScopeScript[];
81
+ /** A run of virtual text copied unchanged from the HTML. */
82
+ export interface Segment {
83
+ /** Offset in the virtual text. */
84
+ generated: number;
85
+ /** Offset in the HTML. */
86
+ source: number;
87
+ length: number;
88
+ }
89
+ export interface VirtualBlockText {
90
+ text: string;
91
+ segments: Segment[];
92
+ /** Offset in the virtual text where Bascik's footer starts. A diagnostic from there on is Bascik's, not the author's. */
93
+ footerStart: number;
94
+ /**
95
+ * The footer's check of a named default export function (see `FooterCheck`): the argument's range in the virtual
96
+ * text, and the function name's range in the HTML, where an error in that argument is the author's to fix.
97
+ */
98
+ footerCheck?: {
99
+ generatedStart: number;
100
+ generatedEnd: number;
101
+ sourceStart: number;
102
+ sourceEnd: number;
103
+ };
104
+ /**
105
+ * Names a block declares that another classic script on the page declares too, and so may have assigned: a
106
+ * `var shared: number;` that types a plain script's `var shared = 1` is not "used before being assigned".
107
+ */
108
+ assignedElsewhere?: string[];
109
+ }
110
+ /**
111
+ * A named default export function checked from the footer (`__bascikScript(build);`) instead of being wrapped
112
+ * in the call. Wrapping turns the declaration into an expression, which takes its name out of the module's scope,
113
+ * so it is used whenever the block refers to that name outside the function. `start` and `end` are the name's
114
+ * offsets in the block's content.
115
+ */
116
+ export interface FooterCheck {
117
+ name: string;
118
+ start: number;
119
+ end: number;
120
+ }
121
+ /** A place in the block where Bascik inserts text, found by the caller's parser. */
122
+ export interface Insertion {
123
+ /** Offset in the block's content. */
124
+ at: number;
125
+ text: string;
126
+ }
127
+ /** The `@bascik/bascik` type each directive's default export must satisfy. */
128
+ export declare const DIRECTIVE_SCRIPT_TYPES: Record<TypeScriptBlockDirective, string>;
129
+ /** The function a directive script's default export is passed to, so its parameters and result get their types. */
130
+ export declare const SCRIPT_TYPE_CHECK = "__bascikScript";
131
+ /**
132
+ * Bascik's footer for a block. A directive script's footer declares the typed function its default export is
133
+ * passed to; the type comes from `@bascik/bascik`. Without those types (the project's `@bascik/bascik` is missing
134
+ * or predates them) the footer is `untyped`: the parameters are `any`, which reports nothing rather than something
135
+ * wrong. The empty export makes every block a module.
136
+ */
137
+ export declare function blockFooter(directive: TypeScriptBlockDirective | undefined, typed?: boolean): string;
138
+ /** The virtual text for a block: its content with the insertions made, then the footer. */
139
+ export declare function virtualBlockText(block: TypeScriptBlock, insertions: Insertion[], typed?: boolean, check?: FooterCheck): VirtualBlockText;
140
+ /**
141
+ * The global type alias, declared once per client program, for the real `typeof globalThis`: a page that redeclares
142
+ * `globalThis` (see `GlobalObjects`) can no longer name it itself.
143
+ */
144
+ export declare const GLOBAL_THIS_TYPE = "__BascikGlobalThis";
145
+ /** The page-local type alias that lists a page's classic globals as properties of its global objects. */
146
+ export declare const PAGE_GLOBALS_TYPE = "__bascikPageGlobals";
147
+ /**
148
+ * Text TypeScript shows the author (a message, a hover) without the names the shared text's footer gives the page's
149
+ * global objects: `Window & typeof globalThis & __bascikPageGlobals` reads `Window & typeof globalThis`, the type a
150
+ * classic script sees.
151
+ */
152
+ export declare function withoutGlobalObjectAliases(text: string): string;
153
+ /** The global objects whose properties a classic script's top-level `var` and `function` names become. */
154
+ export type GlobalObjectName = "window" | "self" | "globalThis";
155
+ /**
156
+ * A classic script's top-level `var` and `function` names are properties of `window` (and `self`, `globalThis`),
157
+ * which the shared text, checked as a module, does not see: its footer redeclares those objects, for that page only,
158
+ * with the names added. A name a typed block declares gets its declared type; any other page-scope script's, `any`.
159
+ */
160
+ export interface GlobalObjects {
161
+ members: {
162
+ name: string;
163
+ typed: boolean;
164
+ }[];
165
+ /** The objects to redeclare: not one the page declares itself. */
166
+ objects: GlobalObjectName[];
167
+ }
168
+ /** What `sharedScriptText` adds to the blocks it joins. */
169
+ export interface SharedScriptOptions {
170
+ /** Insertions per block, keyed by the block's `index`. */
171
+ insertions?: Map<number, Insertion[]>;
172
+ /**
173
+ * Globals the page's other classic scripts declare (plain JavaScript ones, components' scripts in the page
174
+ * scope, blocks left out for a syntax error), declared `any` in the footer so a block can use them.
175
+ */
176
+ ambientNames?: string[];
177
+ /** The page's classic globals as properties of its global objects. */
178
+ globalObjects?: GlobalObjects;
179
+ /** See `VirtualBlockText.assignedElsewhere`. */
180
+ assignedElsewhere?: string[];
181
+ }
182
+ /**
183
+ * The virtual text for client blocks that share one scope (a page's): their contents in order, then the footer
184
+ * that declares the page's other globals and makes the text a module of its own, so two pages never share a name.
185
+ */
186
+ export declare function sharedScriptText(blocks: TypeScriptBlock[], options?: SharedScriptOptions): VirtualBlockText;
187
+ /**
188
+ * The HTML offset for a virtual offset. A position inside inserted text stands for the source character right
189
+ * after it, and the end of the block stands for the end of its content.
190
+ */
191
+ export declare function toSourceOffset(virtual: Pick<VirtualBlockText, "segments">, generated: number): number;
192
+ /** The virtual offset for an HTML offset, or `undefined` when the offset is outside the block. */
193
+ export declare function toGeneratedOffset(virtual: Pick<VirtualBlockText, "segments">, source: number): number | undefined;
194
+ /**
195
+ * Ranges inside a file's blocks, computed for `oldText`, moved to where the same block text sits in `newText`. A
196
+ * range in a block whose text changed (or that is gone), or outside every block, is dropped: its position in the
197
+ * new text is unknown until it is checked again. A block is found at its old position among the blocks first,
198
+ * then as the first unclaimed block with the same text, so a block inserted above another does not lose its
199
+ * ranges.
200
+ */
201
+ export declare function relocateBlockRanges<T extends {
202
+ start: number;
203
+ end: number;
204
+ }>(oldText: string, newText: string, ranges: T[]): T[];
205
+ //# sourceMappingURL=typescript-blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-blocks.d.ts","sourceRoot":"","sources":["../src/typescript-blocks.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,eAAe,EAErB,MAAM,cAAc,CAAC;AAEtB,2GAA2G;AAC3G,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAExD,sGAAsG;AACtG,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;AAE3E,wFAAwF;AACxF,MAAM,MAAM,wBAAwB,GAClC,OAAO,GAAG,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,wBAAwB,G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,gBAAgB,EAAE,UAAU,CAAC,EAC3C,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,SAAS,CAUpB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC1E,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,CAAC,EAAE,GACV,CAAC,EAAE,CAyDL"}
@@ -0,0 +1,464 @@
1
+ /**
2
+ * The `<script type="text/typescript">` blocks of an HTML file, and the virtual TypeScript file each one becomes.
3
+ *
4
+ * Blocks are checked in the scope Bascik runs them in. A block with a Bascik directive (`data-bascik-build`,
5
+ * `-build-once`, `-routes`, `-server`, `-stream`) runs in Node as its own module. A client block (no directive)
6
+ * runs in the browser as a classic script: in a component with `scoping.scriptBlocks` on, each block is wrapped
7
+ * in its own function, so it is checked on its own; otherwise (a page) the blocks share the page's scope, so they
8
+ * are checked together, as one text (`sharedScriptText`). Client and server blocks are checked in different
9
+ * programs, with different libraries.
10
+ *
11
+ * Offsets map back to the HTML through segments: the virtual text is the block's own text, with a few inserted
12
+ * characters (the call that gives a directive script's default export its type) and a footer after it.
13
+ *
14
+ * The scan is linear in the length of the HTML, so a keystroke in a long page costs the same as in a short one.
15
+ */
16
+ import { readOpenTagAttributes } from "./analyzer.js";
17
+ import { usedComponentSources, } from "./project.js";
18
+ /** In the order Bascik's compiler resolves a tag that (wrongly) carries more than one. */
19
+ const DIRECTIVES = [
20
+ "server",
21
+ "stream",
22
+ "build",
23
+ "build-once",
24
+ "routes",
25
+ ];
26
+ /** Elements whose content is text, so a `<script` inside them is not a tag. */
27
+ const RAW_TEXT_ELEMENTS = ["script", "style", "textarea", "title"];
28
+ const isTagNameEnd = (char) => char === undefined || /[\t\n\f\r />]/.test(char);
29
+ /**
30
+ * The index of the `>` that ends the open tag whose name ends at `from`, or -1 when the tag never ends. A quote
31
+ * runs to its partner, as in `SCRIPT_BLOCK_RE`, so a `>` inside a quoted value does not end the tag.
32
+ */
33
+ function findOpenTagEnd(html, from) {
34
+ for (let i = from; i < html.length; i++) {
35
+ const char = html[i];
36
+ if (char === ">")
37
+ return i;
38
+ if (char === '"' || char === "'") {
39
+ const close = html.indexOf(char, i + 1);
40
+ if (close < 0)
41
+ return -1;
42
+ i = close;
43
+ }
44
+ }
45
+ return -1;
46
+ }
47
+ /** The index of `</name` (followed by a tag-name end) at or after `from`, or -1. */
48
+ function findCloseTag(lower, from, name) {
49
+ const needle = `</${name}`;
50
+ for (let at = lower.indexOf(needle, from); at >= 0;) {
51
+ if (isTagNameEnd(lower[at + needle.length]))
52
+ return at;
53
+ at = lower.indexOf(needle, at + 1);
54
+ }
55
+ return -1;
56
+ }
57
+ /** Whether a TypeScript block needs scanning at all: a cheap test before any work. */
58
+ export function mayHaveTypeScriptBlocks(html) {
59
+ return /text\/typescript/i.test(html);
60
+ }
61
+ /**
62
+ * Every `<script>` element of an HTML file, in source order. A script inside an HTML comment or another raw-text
63
+ * element, and one whose tag or element never closes, is not one.
64
+ */
65
+ function scanScripts(html) {
66
+ const scripts = [];
67
+ const lower = html.toLowerCase();
68
+ let i = 0;
69
+ while (i < html.length) {
70
+ const lt = lower.indexOf("<", i);
71
+ if (lt < 0)
72
+ break;
73
+ if (lower.startsWith("<!--", lt)) {
74
+ const end = lower.indexOf("-->", lt + 4);
75
+ // An unclosed comment runs to the end of the file, as in a browser.
76
+ if (end < 0)
77
+ break;
78
+ i = end + 3;
79
+ continue;
80
+ }
81
+ const name = RAW_TEXT_ELEMENTS.find((candidate) => lower.startsWith(candidate, lt + 1) &&
82
+ isTagNameEnd(lower[lt + 1 + candidate.length]));
83
+ if (!name) {
84
+ i = lt + 1;
85
+ continue;
86
+ }
87
+ const tagEnd = findOpenTagEnd(html, lt + 1 + name.length);
88
+ if (tagEnd < 0)
89
+ break;
90
+ const contentStart = tagEnd + 1;
91
+ const close = findCloseTag(lower, contentStart, name);
92
+ // An element that never closes swallows the rest of the file; nothing after it is a tag.
93
+ if (close < 0)
94
+ break;
95
+ if (name === "script") {
96
+ const openTag = html.slice(lt, contentStart);
97
+ scripts.push({
98
+ attributes: readOpenTagAttributes(openTag),
99
+ openTag,
100
+ contentStart,
101
+ content: html.slice(contentStart, close),
102
+ });
103
+ }
104
+ i = close + 2 + name.length;
105
+ }
106
+ return scripts;
107
+ }
108
+ const directiveOf = (attributes) => DIRECTIVES.find((candidate) => attributes.has(`data-bascik-${candidate}`));
109
+ /**
110
+ * The language VS Code's HTML support embeds a script as. Its scanner starts every script as JavaScript, and an
111
+ * attribute whose name is `type` as written (so not `TYPE`) with a value changes that: the value as written, quotes
112
+ * included, matching `/["'](module|(text|application)\/(java|ecma)script|text\/babel)["']/` makes it JavaScript,
113
+ * `/["']text\/typescript["']/` TypeScript, and anything else nothing. The last such attribute wins. So
114
+ * `type="text/TypeScript"`, `type=text/typescript` and `type=" text/typescript"`, which Bascik compiles as
115
+ * TypeScript, are embedded as nothing, and `TYPE="text/typescript"` as JavaScript.
116
+ */
117
+ export function editorScriptLanguage(openTag) {
118
+ const insideTag = openTag.replace(/^<[^\s/>]+/, "").replace(/\/?>$/, "");
119
+ const attributeRe = /([^\s"'=<>`/]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s"'][^\s]*))?/g;
120
+ let language = "javascript";
121
+ for (const [, name, value] of insideTag.matchAll(attributeRe)) {
122
+ if (name !== "type" || value === undefined)
123
+ continue;
124
+ if (/["'](module|(text|application)\/(java|ecma)script|text\/babel)["']/.test(value))
125
+ language = "javascript";
126
+ else if (/["']text\/typescript["']/.test(value))
127
+ language = "typescript";
128
+ else
129
+ language = undefined;
130
+ }
131
+ return language;
132
+ }
133
+ /**
134
+ * The text of every script VS Code's HTML support embeds as `language`, in source order: the scripts its mode for
135
+ * that language reads together as one file.
136
+ */
137
+ export function editorEmbeddedScripts(html, language) {
138
+ return scanScripts(html).filter((script) => editorScriptLanguage(script.openTag) === language);
139
+ }
140
+ /**
141
+ * The `type="text/typescript"` script blocks of an HTML file, in source order. A block inside an HTML comment, a
142
+ * script with `src`, a script whose tag or element never closes, and a script with any other type are not blocks.
143
+ */
144
+ export function extractTypeScriptBlocks(html) {
145
+ const blocks = [];
146
+ if (!mayHaveTypeScriptBlocks(html))
147
+ return blocks;
148
+ for (const { attributes, openTag, contentStart, content } of scanScripts(html)) {
149
+ const type = attributes.get("type")?.trim().toLowerCase();
150
+ if (type !== "text/typescript" || attributes.has("src"))
151
+ continue;
152
+ const directive = directiveOf(attributes);
153
+ blocks.push({
154
+ index: blocks.length,
155
+ directive,
156
+ program: directive === undefined ? "client" : "server",
157
+ contentStart,
158
+ content,
159
+ editorLanguage: editorScriptLanguage(openTag),
160
+ });
161
+ }
162
+ return blocks;
163
+ }
164
+ /**
165
+ * Whether an HTML file has a TypeScript block, so checking it needs TypeScript. A page that only names the type (in
166
+ * prose, a `<pre>`, a comment or a data block) has none, and must never load TypeScript or keep it loaded.
167
+ */
168
+ export function hasTypeScriptBlocks(html) {
169
+ return extractTypeScriptBlocks(html).length > 0;
170
+ }
171
+ /**
172
+ * What checking a page's blocks needs from the components it uses, directly or through others: `pageScopeHtml`,
173
+ * the HTML of those whose client scripts run in the page's scope (all of them with `scoping.scriptBlocks` off,
174
+ * none otherwise), whose names are the page's globals; and `usedComponents`, those with a TypeScript block, whose
175
+ * additions to the browser's globals (`interface Window { ... }`, `declare global`) hold on the page too, as their
176
+ * scripts run there. `readOpen` gives an open editor buffer's newer text.
177
+ */
178
+ export function pageComponentsForTypeScript(fsPath, text, snapshot, readOpen) {
179
+ const used = usedComponentSources(fsPath, text, snapshot, readOpen);
180
+ return {
181
+ pageScopeHtml: snapshot.scopesScriptBlocks === false
182
+ ? used.map((component) => component.text)
183
+ : [],
184
+ usedComponents: used.filter((component) => hasTypeScriptBlocks(component.text)),
185
+ };
186
+ }
187
+ /**
188
+ * The TypeScript block whose content holds `offset` (its end included, where the cursor sits after the last
189
+ * character), or `undefined` when the offset is outside every block.
190
+ */
191
+ export function typeScriptBlockAt(html, offset) {
192
+ return extractTypeScriptBlocks(html).find((block) => block.contentStart <= offset &&
193
+ offset <= block.contentStart + block.content.length);
194
+ }
195
+ /** The `type` values a browser runs as a classic script (the HTML standard's JavaScript MIME type essences). */
196
+ const CLASSIC_SCRIPT_TYPES = new Set([
197
+ "",
198
+ "application/ecmascript",
199
+ "application/javascript",
200
+ "application/x-ecmascript",
201
+ "application/x-javascript",
202
+ "text/ecmascript",
203
+ "text/javascript",
204
+ "text/javascript1.0",
205
+ "text/javascript1.1",
206
+ "text/javascript1.2",
207
+ "text/javascript1.3",
208
+ "text/javascript1.4",
209
+ "text/javascript1.5",
210
+ "text/jscript",
211
+ "text/livescript",
212
+ "text/x-ecmascript",
213
+ "text/x-javascript",
214
+ ]);
215
+ /**
216
+ * The inline scripts of an HTML file that the browser runs as classic scripts, so their top-level names are
217
+ * globals every other classic script on the page sees: plain JavaScript ones (no `type`, or a JavaScript type)
218
+ * and `type="text/typescript"` ones. A module, a data block, a script with `src` and a server-side script (a
219
+ * Bascik directive) are not among them.
220
+ */
221
+ export function extractPageScopeScripts(html) {
222
+ const scripts = [];
223
+ for (const { attributes, content } of scanScripts(html)) {
224
+ if (attributes.has("src") || directiveOf(attributes) !== undefined)
225
+ continue;
226
+ const type = (attributes.get("type") ?? "").trim().toLowerCase();
227
+ if (type === "text/typescript")
228
+ scripts.push({ typed: true, content });
229
+ else if (CLASSIC_SCRIPT_TYPES.has(type))
230
+ scripts.push({ typed: false, content });
231
+ }
232
+ return scripts;
233
+ }
234
+ /** The `@bascik/bascik` type each directive's default export must satisfy. */
235
+ export const DIRECTIVE_SCRIPT_TYPES = {
236
+ build: "BuildScript",
237
+ "build-once": "BuildScript",
238
+ routes: "RoutesScript",
239
+ server: "ServerScript",
240
+ stream: "ServerScript",
241
+ };
242
+ /** The function a directive script's default export is passed to, so its parameters and result get their types. */
243
+ export const SCRIPT_TYPE_CHECK = "__bascikScript";
244
+ /**
245
+ * Bascik's footer for a block. A directive script's footer declares the typed function its default export is
246
+ * passed to; the type comes from `@bascik/bascik`. Without those types (the project's `@bascik/bascik` is missing
247
+ * or predates them) the footer is `untyped`: the parameters are `any`, which reports nothing rather than something
248
+ * wrong. The empty export makes every block a module.
249
+ */
250
+ export function blockFooter(directive, typed = true) {
251
+ if (directive === undefined)
252
+ return "\nexport {};\n";
253
+ if (!typed)
254
+ return `\ndeclare function ${SCRIPT_TYPE_CHECK}(script: (...args: any[]) => unknown): unknown;\nexport {};\n`;
255
+ return (`\nimport type * as __bascik from "@bascik/bascik";\n` +
256
+ `declare function ${SCRIPT_TYPE_CHECK}(script: __bascik.${DIRECTIVE_SCRIPT_TYPES[directive]}): unknown;\n` +
257
+ "export {};\n");
258
+ }
259
+ /** The footer line that checks a named default export function, and where its argument starts in that line. */
260
+ function footerCheckLine(name) {
261
+ const opening = `${SCRIPT_TYPE_CHECK}(`;
262
+ return { line: `${opening}${name});\n`, argumentAt: opening.length };
263
+ }
264
+ /** Appends a block's content, with the insertions made, to `text`, recording its segments. */
265
+ function appendBlock(text, segments, block, insertions) {
266
+ const sorted = [...insertions].sort((a, b) => a.at - b.at);
267
+ let cursor = 0;
268
+ for (const insertion of sorted) {
269
+ segments.push({
270
+ generated: text.length,
271
+ source: block.contentStart + cursor,
272
+ length: insertion.at - cursor,
273
+ });
274
+ text += block.content.slice(cursor, insertion.at) + insertion.text;
275
+ cursor = insertion.at;
276
+ }
277
+ segments.push({
278
+ generated: text.length,
279
+ source: block.contentStart + cursor,
280
+ length: block.content.length - cursor,
281
+ });
282
+ return text + block.content.slice(cursor);
283
+ }
284
+ /** The virtual text for a block: its content with the insertions made, then the footer. */
285
+ export function virtualBlockText(block, insertions, typed = true, check) {
286
+ const segments = [];
287
+ let text = appendBlock("", segments, block, insertions);
288
+ const footerStart = text.length;
289
+ text += blockFooter(block.directive, typed);
290
+ if (check === undefined)
291
+ return { text, segments, footerStart };
292
+ const { line, argumentAt } = footerCheckLine(check.name);
293
+ const generatedStart = text.length + argumentAt;
294
+ text += line;
295
+ return {
296
+ text,
297
+ segments,
298
+ footerStart,
299
+ footerCheck: {
300
+ generatedStart,
301
+ generatedEnd: generatedStart + check.name.length,
302
+ sourceStart: block.contentStart + check.start,
303
+ sourceEnd: block.contentStart + check.end,
304
+ },
305
+ };
306
+ }
307
+ /** What goes between two blocks of a shared scope: a new statement, as a new `<script>` element starts one. */
308
+ const SHARED_SCOPE_SEPARATOR = "\n;\n";
309
+ /**
310
+ * The global type alias, declared once per client program, for the real `typeof globalThis`: a page that redeclares
311
+ * `globalThis` (see `GlobalObjects`) can no longer name it itself.
312
+ */
313
+ export const GLOBAL_THIS_TYPE = "__BascikGlobalThis";
314
+ /** The page-local type alias that lists a page's classic globals as properties of its global objects. */
315
+ export const PAGE_GLOBALS_TYPE = "__bascikPageGlobals";
316
+ /**
317
+ * Text TypeScript shows the author (a message, a hover) without the names the shared text's footer gives the page's
318
+ * global objects: `Window & typeof globalThis & __bascikPageGlobals` reads `Window & typeof globalThis`, the type a
319
+ * classic script sees.
320
+ */
321
+ export function withoutGlobalObjectAliases(text) {
322
+ if (!text.includes("__"))
323
+ return text;
324
+ return text
325
+ .replace(PAGE_GLOBALS_MENTION, "")
326
+ .replace(GLOBAL_THIS_MENTION, "typeof globalThis");
327
+ }
328
+ const PAGE_GLOBALS_MENTION = new RegExp(`\\s*&\\s*${PAGE_GLOBALS_TYPE}\\b|\\b${PAGE_GLOBALS_TYPE}\\s*&\\s*`, "g");
329
+ const GLOBAL_THIS_MENTION = new RegExp(`\\b${GLOBAL_THIS_TYPE}\\b`, "g");
330
+ /** The library type of each global object, before a page's classic globals are added to it. */
331
+ const GLOBAL_OBJECT_TYPES = {
332
+ window: `Window & ${GLOBAL_THIS_TYPE}`,
333
+ self: `Window & ${GLOBAL_THIS_TYPE}`,
334
+ globalThis: GLOBAL_THIS_TYPE,
335
+ };
336
+ /**
337
+ * The virtual text for client blocks that share one scope (a page's): their contents in order, then the footer
338
+ * that declares the page's other globals and makes the text a module of its own, so two pages never share a name.
339
+ */
340
+ export function sharedScriptText(blocks, options = {}) {
341
+ const segments = [];
342
+ let text = "";
343
+ blocks.forEach((block, index) => {
344
+ if (index > 0)
345
+ text += SHARED_SCOPE_SEPARATOR;
346
+ text = appendBlock(text, segments, block, options.insertions?.get(block.index) ?? []);
347
+ });
348
+ const footerStart = text.length;
349
+ const ambient = options.ambientNames ?? [];
350
+ if (ambient.length > 0)
351
+ text += `\ndeclare var ${ambient.map((name) => `${name}: any`).join(", ")};`;
352
+ const globals = options.globalObjects;
353
+ if (globals && globals.members.length > 0 && globals.objects.length > 0) {
354
+ const members = globals.members
355
+ .map(({ name, typed }) => `${name}: ${typed ? `typeof ${name}` : "any"}`)
356
+ .join("; ");
357
+ text += `\ntype ${PAGE_GLOBALS_TYPE} = { ${members} };`;
358
+ for (const object of globals.objects)
359
+ text += `\ndeclare var ${object}: ${GLOBAL_OBJECT_TYPES[object]} & ${PAGE_GLOBALS_TYPE};`;
360
+ }
361
+ text += blockFooter(undefined);
362
+ const assignedElsewhere = options.assignedElsewhere ?? [];
363
+ return assignedElsewhere.length > 0
364
+ ? { text, segments, footerStart, assignedElsewhere }
365
+ : { text, segments, footerStart };
366
+ }
367
+ /**
368
+ * The HTML offset for a virtual offset. A position inside inserted text stands for the source character right
369
+ * after it, and the end of the block stands for the end of its content.
370
+ */
371
+ export function toSourceOffset(virtual, generated) {
372
+ const { segments } = virtual;
373
+ for (const segment of segments) {
374
+ if (generated < segment.generated)
375
+ return segment.source;
376
+ if (generated <= segment.generated + segment.length)
377
+ return segment.source + (generated - segment.generated);
378
+ }
379
+ const last = segments[segments.length - 1];
380
+ return last.source + last.length;
381
+ }
382
+ /** The virtual offset for an HTML offset, or `undefined` when the offset is outside the block. */
383
+ export function toGeneratedOffset(virtual, source) {
384
+ // A character at a segment boundary is the first of the next segment, after the inserted text.
385
+ for (const segment of virtual.segments) {
386
+ if (source >= segment.source && source < segment.source + segment.length)
387
+ return segment.generated + (source - segment.source);
388
+ }
389
+ const last = virtual.segments[virtual.segments.length - 1];
390
+ return source === last.source + last.length
391
+ ? last.generated + last.length
392
+ : undefined;
393
+ }
394
+ /**
395
+ * Ranges inside a file's blocks, computed for `oldText`, moved to where the same block text sits in `newText`. A
396
+ * range in a block whose text changed (or that is gone), or outside every block, is dropped: its position in the
397
+ * new text is unknown until it is checked again. A block is found at its old position among the blocks first,
398
+ * then as the first unclaimed block with the same text, so a block inserted above another does not lose its
399
+ * ranges.
400
+ */
401
+ export function relocateBlockRanges(oldText, newText, ranges) {
402
+ if (ranges.length === 0)
403
+ return [];
404
+ const oldBlocks = extractTypeScriptBlocks(oldText);
405
+ const newBlocks = extractTypeScriptBlocks(newText);
406
+ // The unclaimed new blocks with each text, in order, so finding a moved block costs no rescan.
407
+ const byContent = new Map();
408
+ newBlocks.forEach((block, index) => {
409
+ const entry = byContent.get(block.content);
410
+ if (entry)
411
+ entry.indexes.push(index);
412
+ else
413
+ byContent.set(block.content, { indexes: [index], next: 0 });
414
+ });
415
+ const claimed = new Set();
416
+ const take = (content) => {
417
+ const entry = byContent.get(content);
418
+ if (!entry)
419
+ return undefined;
420
+ while (entry.next < entry.indexes.length &&
421
+ claimed.has(entry.indexes[entry.next]))
422
+ entry.next++;
423
+ return entry.indexes[entry.next++];
424
+ };
425
+ const shifts = oldBlocks.map((block, index) => {
426
+ let match = newBlocks[index]?.content === block.content && !claimed.has(index)
427
+ ? index
428
+ : undefined;
429
+ match ??= take(block.content);
430
+ if (match === undefined)
431
+ return undefined;
432
+ claimed.add(match);
433
+ return newBlocks[match].contentStart - block.contentStart;
434
+ });
435
+ const moved = [];
436
+ for (const range of ranges) {
437
+ // The last block starting at or before the range (blocks are in source order).
438
+ let low = 0;
439
+ let high = oldBlocks.length - 1;
440
+ let index = -1;
441
+ while (low <= high) {
442
+ const middle = (low + high) >> 1;
443
+ if (oldBlocks[middle].contentStart <= range.start) {
444
+ index = middle;
445
+ low = middle + 1;
446
+ }
447
+ else
448
+ high = middle - 1;
449
+ }
450
+ const block = oldBlocks[index];
451
+ if (!block || range.end > block.contentStart + block.content.length)
452
+ continue;
453
+ const shift = shifts[index];
454
+ if (shift === undefined)
455
+ continue;
456
+ moved.push({
457
+ ...range,
458
+ start: range.start + shift,
459
+ end: range.end + shift,
460
+ });
461
+ }
462
+ return moved;
463
+ }
464
+ //# sourceMappingURL=typescript-blocks.js.map