@astrojs/language-server 2.11.1 → 2.12.0
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/core/astro2tsx.d.ts +6 -3
- package/dist/core/astro2tsx.js +13 -22
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +7 -13
- package/dist/core/parseCSS.d.ts +2 -5
- package/dist/core/parseCSS.js +36 -133
- package/dist/core/parseJS.d.ts +2 -4
- package/dist/core/parseJS.js +53 -231
- package/package.json +2 -2
package/dist/core/astro2tsx.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { ConvertToTSXOptions, TSXResult } from '@astrojs/compiler/types';
|
|
1
|
+
import type { ConvertToTSXOptions, TSXExtractedScript, TSXExtractedStyle, TSXResult } from '@astrojs/compiler/types';
|
|
2
2
|
import type { VirtualCode } from '@volar/language-core';
|
|
3
3
|
import { Range } from '@volar/language-server';
|
|
4
|
-
import { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
4
|
export interface LSPTSXRanges {
|
|
6
5
|
frontmatter: Range;
|
|
7
6
|
body: Range;
|
|
7
|
+
scripts: TSXExtractedScript[];
|
|
8
|
+
styles: TSXExtractedStyle[];
|
|
8
9
|
}
|
|
9
10
|
export declare function safeConvertToTSX(content: string, options: ConvertToTSXOptions): TSXResult | {
|
|
10
11
|
code: string;
|
|
@@ -36,10 +37,12 @@ export declare function safeConvertToTSX(content: string, options: ConvertToTSXO
|
|
|
36
37
|
start: number;
|
|
37
38
|
end: number;
|
|
38
39
|
};
|
|
40
|
+
scripts: never[];
|
|
41
|
+
styles: never[];
|
|
39
42
|
};
|
|
40
43
|
};
|
|
41
44
|
export declare function getTSXRangesAsLSPRanges(tsx: TSXResult): LSPTSXRanges;
|
|
42
|
-
export declare function astro2tsx(input: string, fileName: string
|
|
45
|
+
export declare function astro2tsx(input: string, fileName: string): {
|
|
43
46
|
virtualCode: VirtualCode;
|
|
44
47
|
diagnostics: import("@astrojs/compiler").DiagnosticMessage[] | {
|
|
45
48
|
code: 1000;
|
package/dist/core/astro2tsx.js
CHANGED
|
@@ -40,6 +40,8 @@ function safeConvertToTSX(content, options) {
|
|
|
40
40
|
start: 0,
|
|
41
41
|
end: 0,
|
|
42
42
|
},
|
|
43
|
+
scripts: [],
|
|
44
|
+
styles: [],
|
|
43
45
|
},
|
|
44
46
|
};
|
|
45
47
|
}
|
|
@@ -50,19 +52,21 @@ function getTSXRangesAsLSPRanges(tsx) {
|
|
|
50
52
|
return {
|
|
51
53
|
frontmatter: language_server_1.Range.create(textDocument.positionAt(tsx.metaRanges.frontmatter.start), textDocument.positionAt(tsx.metaRanges.frontmatter.end)),
|
|
52
54
|
body: language_server_1.Range.create(textDocument.positionAt(tsx.metaRanges.body.start), textDocument.positionAt(tsx.metaRanges.body.end)),
|
|
55
|
+
scripts: tsx.metaRanges.scripts ?? [],
|
|
56
|
+
styles: tsx.metaRanges.styles ?? [],
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
59
|
exports.getTSXRangesAsLSPRanges = getTSXRangesAsLSPRanges;
|
|
56
|
-
function astro2tsx(input, fileName
|
|
60
|
+
function astro2tsx(input, fileName) {
|
|
57
61
|
const tsx = safeConvertToTSX(input, { filename: fileName });
|
|
58
62
|
return {
|
|
59
|
-
virtualCode: getVirtualCodeTSX(input, tsx, fileName
|
|
63
|
+
virtualCode: getVirtualCodeTSX(input, tsx, fileName),
|
|
60
64
|
diagnostics: tsx.diagnostics,
|
|
61
65
|
ranges: getTSXRangesAsLSPRanges(tsx),
|
|
62
66
|
};
|
|
63
67
|
}
|
|
64
68
|
exports.astro2tsx = astro2tsx;
|
|
65
|
-
function getVirtualCodeTSX(input, tsx, fileName
|
|
69
|
+
function getVirtualCodeTSX(input, tsx, fileName) {
|
|
66
70
|
tsx.code = (0, utils_js_1.patchTSX)(tsx.code, fileName);
|
|
67
71
|
const v3Mappings = (0, sourcemap_codec_1.decode)(tsx.map.mappings);
|
|
68
72
|
const sourcedDoc = vscode_html_languageservice_1.TextDocument.create('', 'astro', 0, input);
|
|
@@ -96,31 +100,18 @@ function getVirtualCodeTSX(input, tsx, fileName, htmlDocument) {
|
|
|
96
100
|
lastMapping.lengths[0] += length;
|
|
97
101
|
}
|
|
98
102
|
else {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
mappings.push({
|
|
104
|
+
sourceOffsets: [current.sourceOffset],
|
|
105
|
+
generatedOffsets: [current.genOffset],
|
|
106
|
+
lengths: [length],
|
|
107
|
+
data: {
|
|
104
108
|
verification: true,
|
|
105
109
|
completion: true,
|
|
106
110
|
semantic: true,
|
|
107
111
|
navigation: true,
|
|
108
112
|
structure: true,
|
|
109
113
|
format: false,
|
|
110
|
-
}
|
|
111
|
-
: {
|
|
112
|
-
verification: false,
|
|
113
|
-
completion: false,
|
|
114
|
-
semantic: false,
|
|
115
|
-
navigation: false,
|
|
116
|
-
structure: false,
|
|
117
|
-
format: false,
|
|
118
|
-
};
|
|
119
|
-
mappings.push({
|
|
120
|
-
sourceOffsets: [current.sourceOffset],
|
|
121
|
-
generatedOffsets: [current.genOffset],
|
|
122
|
-
lengths: [length],
|
|
123
|
-
data: rangeCapabilities,
|
|
114
|
+
},
|
|
124
115
|
});
|
|
125
116
|
}
|
|
126
117
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export declare class AstroVirtualCode implements VirtualCode {
|
|
|
16
16
|
astroMeta: AstroMetadata;
|
|
17
17
|
compilerDiagnostics: DiagnosticMessage[];
|
|
18
18
|
htmlDocument: HTMLDocument;
|
|
19
|
-
scriptCodeIds: string[];
|
|
20
19
|
codegenStacks: never[];
|
|
21
20
|
constructor(fileName: string, snapshot: ts.IScriptSnapshot);
|
|
22
21
|
get hasCompilationErrors(): boolean;
|
package/dist/core/index.js
CHANGED
|
@@ -145,25 +145,19 @@ class AstroVirtualCode {
|
|
|
145
145
|
},
|
|
146
146
|
},
|
|
147
147
|
];
|
|
148
|
-
this.
|
|
148
|
+
const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName);
|
|
149
149
|
const astroMetadata = (0, parseAstro_1.getAstroMetadata)(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()));
|
|
150
|
-
if (astroMetadata.diagnostics.length > 0) {
|
|
151
|
-
this.compilerDiagnostics.push(...astroMetadata.diagnostics);
|
|
152
|
-
}
|
|
153
150
|
const { htmlDocument, virtualCode: htmlVirtualCode } = (0, parseHTML_1.parseHTML)(this.snapshot, astroMetadata.frontmatter.status === 'closed'
|
|
154
151
|
? astroMetadata.frontmatter.position.end.offset
|
|
155
152
|
: 0);
|
|
156
153
|
this.htmlDocument = htmlDocument;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.embeddedCodes = [];
|
|
162
|
-
this.embeddedCodes.push(htmlVirtualCode);
|
|
163
|
-
const tsx = (0, astro2tsx_1.astro2tsx)(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName, htmlDocument);
|
|
154
|
+
htmlVirtualCode.embeddedCodes = [
|
|
155
|
+
(0, parseCSS_1.extractStylesheets)(tsx.ranges.styles),
|
|
156
|
+
...(0, parseJS_js_1.extractScriptTags)(tsx.ranges.scripts),
|
|
157
|
+
];
|
|
164
158
|
this.astroMeta = { ...astroMetadata, tsxRanges: tsx.ranges };
|
|
165
|
-
this.compilerDiagnostics
|
|
166
|
-
this.embeddedCodes
|
|
159
|
+
this.compilerDiagnostics = [...tsx.diagnostics, ...astroMetadata.diagnostics];
|
|
160
|
+
this.embeddedCodes = [htmlVirtualCode, tsx.virtualCode];
|
|
167
161
|
}
|
|
168
162
|
get hasCompilationErrors() {
|
|
169
163
|
return this.compilerDiagnostics.filter((diag) => diag.severity === 1).length > 0;
|
package/dist/core/parseCSS.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TSXExtractedStyle } from '@astrojs/compiler/types';
|
|
2
2
|
import type { VirtualCode } from '@volar/language-core';
|
|
3
|
-
|
|
4
|
-
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
-
export declare function extractStylesheets(snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualCode[];
|
|
6
|
-
export declare function collectClassesAndIdsFromDocument(ast: ParseResult['ast']): string[];
|
|
3
|
+
export declare function extractStylesheets(styles: TSXExtractedStyle[]): VirtualCode;
|
package/dist/core/parseCSS.js
CHANGED
|
@@ -1,142 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const utils_1 = require("@astrojs/compiler/utils");
|
|
3
|
+
exports.extractStylesheets = void 0;
|
|
5
4
|
const muggle_string_1 = require("muggle-string");
|
|
6
5
|
const buildMappings_js_1 = require("../buildMappings.js");
|
|
7
|
-
function extractStylesheets(
|
|
8
|
-
|
|
9
|
-
const inlineStyles = findInlineStyles(ast);
|
|
10
|
-
if (inlineStyles.length > 0) {
|
|
11
|
-
const codes = [];
|
|
12
|
-
for (const inlineStyle of inlineStyles) {
|
|
13
|
-
codes.push('x { ');
|
|
14
|
-
codes.push([
|
|
15
|
-
inlineStyle.value,
|
|
16
|
-
undefined,
|
|
17
|
-
inlineStyle.position.start.offset + 'style="'.length,
|
|
18
|
-
{
|
|
19
|
-
completion: true,
|
|
20
|
-
verification: false,
|
|
21
|
-
semantic: true,
|
|
22
|
-
navigation: true,
|
|
23
|
-
structure: true,
|
|
24
|
-
format: false,
|
|
25
|
-
},
|
|
26
|
-
]);
|
|
27
|
-
codes.push(' }\n');
|
|
28
|
-
}
|
|
29
|
-
const mappings = (0, buildMappings_js_1.buildMappings)(codes);
|
|
30
|
-
const text = (0, muggle_string_1.toString)(codes);
|
|
31
|
-
embeddedCSSCodes.push({
|
|
32
|
-
id: 'inline.css',
|
|
33
|
-
languageId: 'css',
|
|
34
|
-
snapshot: {
|
|
35
|
-
getText: (start, end) => text.substring(start, end),
|
|
36
|
-
getLength: () => text.length,
|
|
37
|
-
getChangeRange: () => undefined,
|
|
38
|
-
},
|
|
39
|
-
embeddedCodes: [],
|
|
40
|
-
mappings,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return embeddedCSSCodes;
|
|
6
|
+
function extractStylesheets(styles) {
|
|
7
|
+
return mergeCSSContexts(styles);
|
|
44
8
|
}
|
|
45
9
|
exports.extractStylesheets = extractStylesheets;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
getChangeRange: () => undefined,
|
|
67
|
-
},
|
|
68
|
-
mappings: [
|
|
69
|
-
{
|
|
70
|
-
sourceOffsets: [node.startTagEnd],
|
|
71
|
-
generatedOffsets: [0],
|
|
72
|
-
lengths: [styleText.length],
|
|
73
|
-
data: {
|
|
74
|
-
verification: false,
|
|
75
|
-
completion: true,
|
|
76
|
-
semantic: true,
|
|
77
|
-
navigation: true,
|
|
78
|
-
structure: true,
|
|
79
|
-
format: false,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
embeddedCodes: [],
|
|
84
|
-
});
|
|
85
|
-
cssIndex++;
|
|
86
|
-
}
|
|
87
|
-
if (node.children)
|
|
88
|
-
getEmbeddedCSSInNodes(node.children);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return embeddedCSSCodes;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Find all inline styles using the Astro AST
|
|
95
|
-
* Inline styles are styles that are defined in the `style` attribute of an element.
|
|
96
|
-
* TODO: Merge this with `findEmbeddedCSS`? Unlike scripts, there's no scoping being done here, so merging all of it in
|
|
97
|
-
* the same virtual file is possible, though it might make mapping more tricky.
|
|
98
|
-
*/
|
|
99
|
-
function findInlineStyles(ast) {
|
|
100
|
-
const styleAttrs = [];
|
|
101
|
-
// `@astrojs/compiler`'s `walk` method is async, so we can't use it here. Arf
|
|
102
|
-
function walkDown(parent) {
|
|
103
|
-
if (!parent.children)
|
|
104
|
-
return;
|
|
105
|
-
parent.children.forEach((child) => {
|
|
106
|
-
if (utils_1.is.element(child)) {
|
|
107
|
-
const styleAttribute = child.attributes.find((attr) => attr.name === 'style' && attr.kind === 'quoted');
|
|
108
|
-
if (styleAttribute && styleAttribute.position) {
|
|
109
|
-
styleAttrs.push(styleAttribute);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (utils_1.is.parent(child)) {
|
|
113
|
-
walkDown(child);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
walkDown(ast);
|
|
118
|
-
return styleAttrs;
|
|
119
|
-
}
|
|
120
|
-
// TODO: Provide completion for classes and IDs
|
|
121
|
-
function collectClassesAndIdsFromDocument(ast) {
|
|
122
|
-
const classesAndIds = [];
|
|
123
|
-
function walkDown(parent) {
|
|
124
|
-
if (!parent.children)
|
|
125
|
-
return;
|
|
126
|
-
parent.children.forEach((child) => {
|
|
127
|
-
if (utils_1.is.element(child)) {
|
|
128
|
-
const classOrIDAttributes = child.attributes
|
|
129
|
-
.filter((attr) => attr.kind === 'quoted' && (attr.name === 'class' || attr.name === 'id'))
|
|
130
|
-
.flatMap((attr) => attr.value.split(' '));
|
|
131
|
-
classesAndIds.push(...classOrIDAttributes);
|
|
132
|
-
}
|
|
133
|
-
if (utils_1.is.parent(child)) {
|
|
134
|
-
walkDown(child);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
10
|
+
function mergeCSSContexts(inlineStyles) {
|
|
11
|
+
const codes = [];
|
|
12
|
+
for (const javascriptContext of inlineStyles) {
|
|
13
|
+
if (javascriptContext.type === 'style-attribute')
|
|
14
|
+
codes.push('__ { ');
|
|
15
|
+
codes.push([
|
|
16
|
+
javascriptContext.content,
|
|
17
|
+
undefined,
|
|
18
|
+
javascriptContext.position.start,
|
|
19
|
+
{
|
|
20
|
+
verification: true,
|
|
21
|
+
completion: true,
|
|
22
|
+
semantic: true,
|
|
23
|
+
navigation: true,
|
|
24
|
+
structure: true,
|
|
25
|
+
format: false,
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
28
|
+
if (javascriptContext.type === 'style-attribute')
|
|
29
|
+
codes.push(' }\n');
|
|
137
30
|
}
|
|
138
|
-
|
|
139
|
-
|
|
31
|
+
const mappings = (0, buildMappings_js_1.buildMappings)(codes);
|
|
32
|
+
const text = (0, muggle_string_1.toString)(codes);
|
|
33
|
+
return {
|
|
34
|
+
id: 'style.css',
|
|
35
|
+
languageId: 'css',
|
|
36
|
+
snapshot: {
|
|
37
|
+
getText: (start, end) => text.substring(start, end),
|
|
38
|
+
getLength: () => text.length,
|
|
39
|
+
getChangeRange: () => undefined,
|
|
40
|
+
},
|
|
41
|
+
embeddedCodes: [],
|
|
42
|
+
mappings,
|
|
43
|
+
};
|
|
140
44
|
}
|
|
141
|
-
exports.collectClassesAndIdsFromDocument = collectClassesAndIdsFromDocument;
|
|
142
45
|
//# sourceMappingURL=parseCSS.js.map
|
package/dist/core/parseJS.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TSXExtractedScript } from '@astrojs/compiler/types';
|
|
2
2
|
import type { VirtualCode } from '@volar/language-core';
|
|
3
|
-
|
|
4
|
-
import type { HTMLDocument } from 'vscode-html-languageservice';
|
|
5
|
-
export declare function extractScriptTags(snapshot: ts.IScriptSnapshot, htmlDocument: HTMLDocument, ast: ParseResult['ast']): VirtualCode[];
|
|
3
|
+
export declare function extractScriptTags(scripts: TSXExtractedScript[]): VirtualCode[];
|
package/dist/core/parseJS.js
CHANGED
|
@@ -1,164 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractScriptTags = void 0;
|
|
4
|
-
const utils_1 = require("@astrojs/compiler/utils");
|
|
5
4
|
const muggle_string_1 = require("muggle-string");
|
|
6
5
|
const buildMappings_1 = require("../buildMappings");
|
|
7
|
-
function extractScriptTags(
|
|
8
|
-
const embeddedJSCodes =
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
function extractScriptTags(scripts) {
|
|
7
|
+
const embeddedJSCodes = [];
|
|
8
|
+
const moduleScripts = scripts
|
|
9
|
+
.filter((script) => script.type === 'module' || script.type === 'processed-module')
|
|
10
|
+
.map(moduleScriptToVirtualCode);
|
|
11
|
+
const inlineScripts = scripts
|
|
12
|
+
.filter((script) => script.type === 'event-attribute' || script.type === 'inline')
|
|
13
|
+
.sort((a, b) => a.position.start - b.position.start);
|
|
14
|
+
embeddedJSCodes.push(...moduleScripts);
|
|
15
|
+
const mergedJSContext = mergeJSContexts(inlineScripts);
|
|
16
|
+
if (mergedJSContext) {
|
|
17
|
+
embeddedJSCodes.push(mergedJSContext);
|
|
17
18
|
}
|
|
18
19
|
return embeddedJSCodes;
|
|
19
20
|
}
|
|
20
21
|
exports.extractScriptTags = extractScriptTags;
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return 'module';
|
|
28
|
-
// whenever there are attributes, is:inline is implied and in the absence of type=module, the script is classic
|
|
29
|
-
return 'classic';
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Get all the isolated scripts in the HTML document
|
|
33
|
-
* Isolated scripts are scripts that are hoisted by Astro and as such, are isolated from the rest of the code because of the implicit `type="module"`
|
|
34
|
-
* All the isolated scripts are passed to the TypeScript language server as separate `.mts` files.
|
|
35
|
-
*/
|
|
36
|
-
function findModuleScripts(snapshot, roots) {
|
|
37
|
-
const embeddedScripts = [];
|
|
38
|
-
let scriptIndex = 0;
|
|
39
|
-
getEmbeddedScriptsInNodes(roots);
|
|
40
|
-
function getEmbeddedScriptsInNodes(nodes) {
|
|
41
|
-
for (const [_, node] of nodes.entries()) {
|
|
42
|
-
if (node.tag === 'script' &&
|
|
43
|
-
node.startTagEnd !== undefined &&
|
|
44
|
-
node.endTagStart !== undefined &&
|
|
45
|
-
getScriptType(node) !== 'classic') {
|
|
46
|
-
const scriptText = snapshot.getText(node.startTagEnd, node.endTagStart);
|
|
47
|
-
const extension = getScriptType(node) === 'processed module' ? 'mts' : 'mjs';
|
|
48
|
-
const languageId = getScriptType(node) === 'processed module' ? 'typescript' : 'javascript';
|
|
49
|
-
embeddedScripts.push({
|
|
50
|
-
id: `${scriptIndex}.${extension}`,
|
|
51
|
-
languageId: languageId,
|
|
52
|
-
snapshot: {
|
|
53
|
-
getText: (start, end) => scriptText.substring(start, end),
|
|
54
|
-
getLength: () => scriptText.length,
|
|
55
|
-
getChangeRange: () => undefined,
|
|
56
|
-
},
|
|
57
|
-
mappings: [
|
|
58
|
-
{
|
|
59
|
-
sourceOffsets: [node.startTagEnd],
|
|
60
|
-
generatedOffsets: [0],
|
|
61
|
-
lengths: [scriptText.length],
|
|
62
|
-
data: {
|
|
63
|
-
verification: true,
|
|
64
|
-
completion: true,
|
|
65
|
-
semantic: true,
|
|
66
|
-
navigation: true,
|
|
67
|
-
structure: true,
|
|
68
|
-
format: false,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
embeddedCodes: [],
|
|
73
|
-
});
|
|
74
|
-
scriptIndex++;
|
|
75
|
-
}
|
|
76
|
-
if (node.children)
|
|
77
|
-
getEmbeddedScriptsInNodes(node.children);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return embeddedScripts;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get all the inline scripts in the HTML document
|
|
84
|
-
* Inline scripts are scripts that are not hoisted by Astro and as such, are not isolated from the rest of the code.
|
|
85
|
-
* All the inline scripts are concatenated into a single `.mjs` file and passed to the TypeScript language server.
|
|
86
|
-
*/
|
|
87
|
-
function findClassicScripts(htmlDocument, snapshot) {
|
|
88
|
-
const inlineScripts = [];
|
|
89
|
-
getInlineScriptsInNodes(htmlDocument.roots);
|
|
90
|
-
function getInlineScriptsInNodes(nodes) {
|
|
91
|
-
for (const [_, node] of nodes.entries()) {
|
|
92
|
-
if (node.tag === 'script' &&
|
|
93
|
-
node.startTagEnd !== undefined &&
|
|
94
|
-
node.endTagStart !== undefined &&
|
|
95
|
-
!isJSON(node.attributes?.type) &&
|
|
96
|
-
getScriptType(node) === 'classic') {
|
|
97
|
-
const scriptText = snapshot.getText(node.startTagEnd, node.endTagStart);
|
|
98
|
-
inlineScripts.push({
|
|
99
|
-
startOffset: node.startTagEnd,
|
|
100
|
-
content: scriptText,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (node.children)
|
|
104
|
-
getInlineScriptsInNodes(node.children);
|
|
105
|
-
}
|
|
22
|
+
function moduleScriptToVirtualCode(script, index) {
|
|
23
|
+
let extension = 'mts';
|
|
24
|
+
let languageId = 'typescript';
|
|
25
|
+
if (script.type === 'module') {
|
|
26
|
+
extension = 'mjs';
|
|
27
|
+
languageId = 'javascript';
|
|
106
28
|
}
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (utils_1.is.element(child)) {
|
|
133
|
-
const eventAttribute = child.attributes.find((attr) => htmlEventAttributes.includes(attr.name) && attr.kind === 'quoted');
|
|
134
|
-
if (eventAttribute && eventAttribute.position) {
|
|
135
|
-
eventAttrs.push({
|
|
136
|
-
// Add a semicolon to the end of the event attribute to attempt to prevent errors from spreading to the rest of the document
|
|
137
|
-
// This is not perfect, but it's better than nothing
|
|
138
|
-
// See: https://github.com/microsoft/vscode/blob/e8e04769ec817a3374c3eaa26a08d3ae491820d5/extensions/html-language-features/server/src/modes/embeddedSupport.ts#L192
|
|
139
|
-
content: eventAttribute.value + ';',
|
|
140
|
-
startOffset: eventAttribute.position.start.offset + `${eventAttribute.name}="`.length,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (utils_1.is.parent(child)) {
|
|
145
|
-
walkDown(child);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
walkDown(ast);
|
|
150
|
-
return eventAttrs;
|
|
29
|
+
return {
|
|
30
|
+
id: `${index}.${extension}`,
|
|
31
|
+
languageId,
|
|
32
|
+
snapshot: {
|
|
33
|
+
getText: (start, end) => script.content.substring(start, end),
|
|
34
|
+
getLength: () => script.content.length,
|
|
35
|
+
getChangeRange: () => undefined,
|
|
36
|
+
},
|
|
37
|
+
mappings: [
|
|
38
|
+
{
|
|
39
|
+
sourceOffsets: [script.position.start],
|
|
40
|
+
generatedOffsets: [0],
|
|
41
|
+
lengths: [script.content.length],
|
|
42
|
+
data: {
|
|
43
|
+
verification: true,
|
|
44
|
+
completion: true,
|
|
45
|
+
semantic: true,
|
|
46
|
+
navigation: true,
|
|
47
|
+
structure: true,
|
|
48
|
+
format: false,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
embeddedCodes: [],
|
|
53
|
+
};
|
|
151
54
|
}
|
|
152
55
|
/**
|
|
153
56
|
* Merge all the inline and non-hoisted scripts into a single `.mjs` file
|
|
154
57
|
*/
|
|
155
|
-
function mergeJSContexts(
|
|
58
|
+
function mergeJSContexts(inlineScripts) {
|
|
59
|
+
if (inlineScripts.length === 0) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
156
62
|
const codes = [];
|
|
157
|
-
for (const javascriptContext of
|
|
63
|
+
for (const javascriptContext of inlineScripts) {
|
|
158
64
|
codes.push([
|
|
159
|
-
|
|
65
|
+
// Add a semicolon to the end of the event attribute to attempt to prevent errors from spreading to the rest of the document
|
|
66
|
+
// This is not perfect, but it's better than nothing
|
|
67
|
+
// See: https://github.com/microsoft/vscode/blob/e8e04769ec817a3374c3eaa26a08d3ae491820d5/extensions/html-language-features/server/src/modes/embeddedSupport.ts#L192
|
|
68
|
+
javascriptContext.content + ';',
|
|
160
69
|
undefined,
|
|
161
|
-
javascriptContext.
|
|
70
|
+
javascriptContext.position.start,
|
|
162
71
|
{
|
|
163
72
|
verification: true,
|
|
164
73
|
completion: true,
|
|
@@ -183,91 +92,4 @@ function mergeJSContexts(javascriptContexts) {
|
|
|
183
92
|
mappings,
|
|
184
93
|
};
|
|
185
94
|
}
|
|
186
|
-
const htmlEventAttributes = [
|
|
187
|
-
'onabort',
|
|
188
|
-
'onafterprint',
|
|
189
|
-
'onauxclick',
|
|
190
|
-
'onbeforematch',
|
|
191
|
-
'onbeforeprint',
|
|
192
|
-
'onbeforeunload',
|
|
193
|
-
'onblur',
|
|
194
|
-
'oncancel',
|
|
195
|
-
'oncanplay',
|
|
196
|
-
'oncanplaythrough',
|
|
197
|
-
'onchange',
|
|
198
|
-
'onclick',
|
|
199
|
-
'onclose',
|
|
200
|
-
'oncontextlost',
|
|
201
|
-
'oncontextmenu',
|
|
202
|
-
'oncontextrestored',
|
|
203
|
-
'oncopy',
|
|
204
|
-
'oncuechange',
|
|
205
|
-
'oncut',
|
|
206
|
-
'ondblclick',
|
|
207
|
-
'ondrag',
|
|
208
|
-
'ondragend',
|
|
209
|
-
'ondragenter',
|
|
210
|
-
'ondragleave',
|
|
211
|
-
'ondragover',
|
|
212
|
-
'ondragstart',
|
|
213
|
-
'ondrop',
|
|
214
|
-
'ondurationchange',
|
|
215
|
-
'onemptied',
|
|
216
|
-
'onended',
|
|
217
|
-
'onerror',
|
|
218
|
-
'onfocus',
|
|
219
|
-
'onformdata',
|
|
220
|
-
'onhashchange',
|
|
221
|
-
'oninput',
|
|
222
|
-
'oninvalid',
|
|
223
|
-
'onkeydown',
|
|
224
|
-
'onkeypress',
|
|
225
|
-
'onkeyup',
|
|
226
|
-
'onlanguagechange',
|
|
227
|
-
'onload',
|
|
228
|
-
'onloadeddata',
|
|
229
|
-
'onloadedmetadata',
|
|
230
|
-
'onloadstart',
|
|
231
|
-
'onmessage',
|
|
232
|
-
'onmessageerror',
|
|
233
|
-
'onmousedown',
|
|
234
|
-
'onmouseenter',
|
|
235
|
-
'onmouseleave',
|
|
236
|
-
'onmousemove',
|
|
237
|
-
'onmouseout',
|
|
238
|
-
'onmouseover',
|
|
239
|
-
'onmouseup',
|
|
240
|
-
'onoffline',
|
|
241
|
-
'ononline',
|
|
242
|
-
'onpagehide',
|
|
243
|
-
'onpageshow',
|
|
244
|
-
'onpaste',
|
|
245
|
-
'onpause',
|
|
246
|
-
'onplay',
|
|
247
|
-
'onplaying',
|
|
248
|
-
'onpopstate',
|
|
249
|
-
'onprogress',
|
|
250
|
-
'onratechange',
|
|
251
|
-
'onrejectionhandled',
|
|
252
|
-
'onreset',
|
|
253
|
-
'onresize',
|
|
254
|
-
'onscroll',
|
|
255
|
-
'onscrollend',
|
|
256
|
-
'onsecuritypolicyviolation',
|
|
257
|
-
'onseeked',
|
|
258
|
-
'onseeking',
|
|
259
|
-
'onselect',
|
|
260
|
-
'onslotchange',
|
|
261
|
-
'onstalled',
|
|
262
|
-
'onstorage',
|
|
263
|
-
'onsubmit',
|
|
264
|
-
'onsuspend',
|
|
265
|
-
'ontimeupdate',
|
|
266
|
-
'ontoggle',
|
|
267
|
-
'onunhandledrejection',
|
|
268
|
-
'onunload',
|
|
269
|
-
'onvolumechange',
|
|
270
|
-
'onwaiting',
|
|
271
|
-
'onwheel',
|
|
272
|
-
];
|
|
273
95
|
//# sourceMappingURL=parseJS.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"astro-ls": "./bin/nodeServer.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@astrojs/compiler": "^2.
|
|
23
|
+
"@astrojs/compiler": "^2.9.1",
|
|
24
24
|
"@jridgewell/sourcemap-codec": "^1.4.15",
|
|
25
25
|
"@volar/kit": "~2.4.0-alpha.15",
|
|
26
26
|
"@volar/language-core": "~2.4.0-alpha.15",
|