@astrojs/language-server 2.11.1 → 2.12.1

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.
@@ -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, htmlDocument: HTMLDocument): {
45
+ export declare function astro2tsx(input: string, fileName: string): {
43
46
  virtualCode: VirtualCode;
44
47
  diagnostics: import("@astrojs/compiler").DiagnosticMessage[] | {
45
48
  code: 1000;
@@ -8,7 +8,11 @@ const vscode_html_languageservice_1 = require("vscode-html-languageservice");
8
8
  const utils_js_1 = require("./utils.js");
9
9
  function safeConvertToTSX(content, options) {
10
10
  try {
11
- const tsx = (0, sync_1.convertToTSX)(content, { filename: options.filename });
11
+ const tsx = (0, sync_1.convertToTSX)(content, {
12
+ filename: options.filename,
13
+ includeScripts: false,
14
+ includeStyles: false,
15
+ });
12
16
  return tsx;
13
17
  }
14
18
  catch (e) {
@@ -40,6 +44,8 @@ function safeConvertToTSX(content, options) {
40
44
  start: 0,
41
45
  end: 0,
42
46
  },
47
+ scripts: [],
48
+ styles: [],
43
49
  },
44
50
  };
45
51
  }
@@ -50,19 +56,21 @@ function getTSXRangesAsLSPRanges(tsx) {
50
56
  return {
51
57
  frontmatter: language_server_1.Range.create(textDocument.positionAt(tsx.metaRanges.frontmatter.start), textDocument.positionAt(tsx.metaRanges.frontmatter.end)),
52
58
  body: language_server_1.Range.create(textDocument.positionAt(tsx.metaRanges.body.start), textDocument.positionAt(tsx.metaRanges.body.end)),
59
+ scripts: tsx.metaRanges.scripts ?? [],
60
+ styles: tsx.metaRanges.styles ?? [],
53
61
  };
54
62
  }
55
63
  exports.getTSXRangesAsLSPRanges = getTSXRangesAsLSPRanges;
56
- function astro2tsx(input, fileName, htmlDocument) {
64
+ function astro2tsx(input, fileName) {
57
65
  const tsx = safeConvertToTSX(input, { filename: fileName });
58
66
  return {
59
- virtualCode: getVirtualCodeTSX(input, tsx, fileName, htmlDocument),
67
+ virtualCode: getVirtualCodeTSX(input, tsx, fileName),
60
68
  diagnostics: tsx.diagnostics,
61
69
  ranges: getTSXRangesAsLSPRanges(tsx),
62
70
  };
63
71
  }
64
72
  exports.astro2tsx = astro2tsx;
65
- function getVirtualCodeTSX(input, tsx, fileName, htmlDocument) {
73
+ function getVirtualCodeTSX(input, tsx, fileName) {
66
74
  tsx.code = (0, utils_js_1.patchTSX)(tsx.code, fileName);
67
75
  const v3Mappings = (0, sourcemap_codec_1.decode)(tsx.map.mappings);
68
76
  const sourcedDoc = vscode_html_languageservice_1.TextDocument.create('', 'astro', 0, input);
@@ -96,31 +104,18 @@ function getVirtualCodeTSX(input, tsx, fileName, htmlDocument) {
96
104
  lastMapping.lengths[0] += length;
97
105
  }
98
106
  else {
99
- // Disable features inside script tags. This is a bit annoying to do, I wonder if maybe leaving script tags
100
- // unmapped would be better.
101
- const node = htmlDocument.findNodeAt(current.sourceOffset);
102
- const rangeCapabilities = node.tag !== 'script'
103
- ? {
107
+ mappings.push({
108
+ sourceOffsets: [current.sourceOffset],
109
+ generatedOffsets: [current.genOffset],
110
+ lengths: [length],
111
+ data: {
104
112
  verification: true,
105
113
  completion: true,
106
114
  semantic: true,
107
115
  navigation: true,
108
116
  structure: true,
109
117
  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,
118
+ },
124
119
  });
125
120
  }
126
121
  }
@@ -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;
@@ -145,25 +145,19 @@ class AstroVirtualCode {
145
145
  },
146
146
  },
147
147
  ];
148
- this.compilerDiagnostics = [];
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
- const scriptTags = (0, parseJS_js_1.extractScriptTags)(this.snapshot, htmlDocument, astroMetadata.ast);
158
- this.scriptCodeIds = scriptTags.map((scriptTag) => scriptTag.id);
159
- htmlVirtualCode.embeddedCodes = [];
160
- htmlVirtualCode.embeddedCodes.push(...(0, parseCSS_1.extractStylesheets)(this.snapshot, htmlDocument, astroMetadata.ast), ...scriptTags);
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.push(...tsx.diagnostics);
166
- this.embeddedCodes.push(tsx.virtualCode);
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;
@@ -1,6 +1,3 @@
1
- import type { ParseResult } from '@astrojs/compiler/types';
1
+ import type { TSXExtractedStyle } from '@astrojs/compiler/types';
2
2
  import type { VirtualCode } from '@volar/language-core';
3
- import type ts from 'typescript';
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;
@@ -1,142 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectClassesAndIdsFromDocument = exports.extractStylesheets = void 0;
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(snapshot, htmlDocument, ast) {
8
- const embeddedCSSCodes = findEmbeddedStyles(snapshot, htmlDocument.roots);
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
- * Find all embedded styles in a document.
48
- * Embedded styles are styles that are defined in `<style>` tags.
49
- */
50
- function findEmbeddedStyles(snapshot, roots) {
51
- const embeddedCSSCodes = [];
52
- let cssIndex = 0;
53
- getEmbeddedCSSInNodes(roots);
54
- function getEmbeddedCSSInNodes(nodes) {
55
- for (const [_, node] of nodes.entries()) {
56
- if (node.tag === 'style' &&
57
- node.startTagEnd !== undefined &&
58
- node.endTagStart !== undefined) {
59
- const styleText = snapshot.getText(node.startTagEnd, node.endTagStart);
60
- embeddedCSSCodes.push({
61
- id: `${cssIndex}.css`,
62
- languageId: 'css',
63
- snapshot: {
64
- getText: (start, end) => styleText.substring(start, end),
65
- getLength: () => styleText.length,
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
- walkDown(ast);
139
- return classesAndIds;
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
@@ -1,5 +1,3 @@
1
- import type { ParseResult } from '@astrojs/compiler/types';
1
+ import type { TSXExtractedScript } from '@astrojs/compiler/types';
2
2
  import type { VirtualCode } from '@volar/language-core';
3
- import type ts from 'typescript';
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[];
@@ -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(snapshot, htmlDocument, ast) {
8
- const embeddedJSCodes = findModuleScripts(snapshot, htmlDocument.roots);
9
- const javascriptContexts = [
10
- ...findClassicScripts(htmlDocument, snapshot),
11
- ...findEventAttributes(ast),
12
- ].sort((a, b) => a.startOffset - b.startOffset);
13
- if (javascriptContexts.length > 0) {
14
- // classic scripts share the same scope
15
- // merging them brings about redeclaration errors
16
- embeddedJSCodes.push(mergeJSContexts(javascriptContexts));
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 getScriptType(scriptTag) {
22
- // script tags without attributes are processed and converted into module scripts
23
- if (!scriptTag.attributes || Object.entries(scriptTag.attributes).length === 0)
24
- return 'processed module';
25
- // even when it is not processed by vite, scripts with type=module remain modules
26
- if (scriptTag.attributes['type']?.includes('module') === true)
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 inlineScripts;
108
- }
109
- /**
110
- * Include both MIME JSON types and `importmap` and `speculationrules` script types
111
- * See MIME Types -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
112
- * See Script Types -> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type
113
- */
114
- const JSON_TYPES = ['application/json', 'application/ld+json', 'importmap', 'speculationrules'];
115
- /**
116
- * Check if the script has a type, and if it's included in JSON_TYPES above.
117
- * @param type Found in the `type` attribute of the script tag
118
- */
119
- function isJSON(type) {
120
- if (!type)
121
- return false;
122
- // HTML attributes are quoted, slice " and ' at the start and end of the string
123
- return JSON_TYPES.includes(type.slice(1, -1));
124
- }
125
- function findEventAttributes(ast) {
126
- const eventAttrs = [];
127
- // `@astrojs/compiler`'s `walk` method is async, so we can't use it here. Arf
128
- function walkDown(parent) {
129
- if (!parent.children)
130
- return;
131
- parent.children.forEach((child) => {
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(javascriptContexts) {
58
+ function mergeJSContexts(inlineScripts) {
59
+ if (inlineScripts.length === 0) {
60
+ return undefined;
61
+ }
156
62
  const codes = [];
157
- for (const javascriptContext of javascriptContexts) {
63
+ for (const javascriptContext of inlineScripts) {
158
64
  codes.push([
159
- javascriptContext.content,
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.startOffset,
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.11.1",
3
+ "version": "2.12.1",
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.7.0",
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",