@astrojs/compiler 0.26.0 → 0.27.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/CHANGELOG.md +56 -0
- package/astro.wasm +0 -0
- package/package.json +1 -1
- package/shared/diagnostics.d.ts +16 -0
- package/shared/diagnostics.js +1 -0
- package/shared/types.d.ts +28 -4
- package/shared/types.js +9 -0
- package/types.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @astrojs/compiler
|
|
2
2
|
|
|
3
|
+
## 0.27.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c770e7b: The compiler will now return `diagnostics` and unique error codes to be handled by the consumer. For example:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import type { DiagnosticSeverity, DiagnosticCode } from '@astrojs/compiler/types';
|
|
11
|
+
import { transform } from '@astrojs/compiler';
|
|
12
|
+
|
|
13
|
+
async function run() {
|
|
14
|
+
const { diagnostics } = await transform(file, opts);
|
|
15
|
+
|
|
16
|
+
function log(severity: DiagnosticSeverity, message: string) {
|
|
17
|
+
switch (severity) {
|
|
18
|
+
case DiagnosticSeverity.Error:
|
|
19
|
+
return console.error(message);
|
|
20
|
+
case DiagnosticSeverity.Warning:
|
|
21
|
+
return console.warn(message);
|
|
22
|
+
case DiagnosticSeverity.Information:
|
|
23
|
+
return console.info(message);
|
|
24
|
+
case DiagnosticSeverity.Hint:
|
|
25
|
+
return console.info(message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for (const diagnostic of diagnostics) {
|
|
30
|
+
let message = diagnostic.text;
|
|
31
|
+
if (diagnostic.hint) {
|
|
32
|
+
message += `\n\n[hint] ${diagnostic.hint}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Or customize messages for a known DiagnosticCode
|
|
36
|
+
if (diagnostic.code === DiagnosticCode.ERROR_UNMATCHED_IMPORT) {
|
|
37
|
+
message = `My custom message about an unmatched import!`;
|
|
38
|
+
}
|
|
39
|
+
log(diagnostic.severity, message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- 0b24c24: Implement automatic typing for Astro.props in the TSX output
|
|
47
|
+
|
|
48
|
+
## 0.26.1
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- 920898c: Handle edge case with `noscript` tags
|
|
53
|
+
- 8ee78a6: handle slots that contains the head element
|
|
54
|
+
- 244e43e: Do not hoist import inside object
|
|
55
|
+
- b8cd954: Fix edge case with line comments and export hoisting
|
|
56
|
+
- 52ebfb7: Fix parse/tsx output to gracefully handle invalid HTML (style outside of body, etc)
|
|
57
|
+
- 884efc6: Fix edge case with multi-line export hoisting
|
|
58
|
+
|
|
3
59
|
## 0.26.0
|
|
4
60
|
|
|
5
61
|
### Minor Changes
|
package/astro.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const enum DiagnosticCode {
|
|
2
|
+
ERROR = 1000,
|
|
3
|
+
ERROR_UNTERMINATED_JS_COMMENT = 1001,
|
|
4
|
+
ERROR_FRAGMENT_SHORTHAND_ATTRS = 1002,
|
|
5
|
+
ERROR_UNMATCHED_IMPORT = 1003,
|
|
6
|
+
ERROR_UNSUPPORTED_SLOT_ATTRIBUTE = 1004,
|
|
7
|
+
WARNING = 2000,
|
|
8
|
+
WARNING_UNTERMINATED_HTML_COMMENT = 2001,
|
|
9
|
+
WARNING_UNCLOSED_HTML_TAG = 2002,
|
|
10
|
+
WARNING_DEPRECATED_DIRECTIVE = 2003,
|
|
11
|
+
WARNING_IGNORED_DIRECTIVE = 2004,
|
|
12
|
+
WARNING_UNSUPPORTED_EXPRESSION = 2005,
|
|
13
|
+
WARNING_SET_WITH_CHILDREN = 2006,
|
|
14
|
+
INFO = 3000,
|
|
15
|
+
HINT = 4000
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/shared/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { RootNode } from './ast';
|
|
2
|
+
import { DiagnosticCode } from './diagnostics';
|
|
2
3
|
export * from './ast';
|
|
4
|
+
export * from './diagnostics';
|
|
3
5
|
export interface PreprocessorResult {
|
|
4
6
|
code: string;
|
|
5
7
|
map?: string;
|
|
@@ -10,6 +12,25 @@ export interface PreprocessorError {
|
|
|
10
12
|
export interface ParseOptions {
|
|
11
13
|
position?: boolean;
|
|
12
14
|
}
|
|
15
|
+
export declare enum DiagnosticSeverity {
|
|
16
|
+
Error = 1,
|
|
17
|
+
Warning = 2,
|
|
18
|
+
Information = 3,
|
|
19
|
+
Hint = 4
|
|
20
|
+
}
|
|
21
|
+
export interface DiagnosticMessage {
|
|
22
|
+
severity: DiagnosticSeverity;
|
|
23
|
+
code: DiagnosticCode;
|
|
24
|
+
location: DiagnosticLocation;
|
|
25
|
+
hint?: string;
|
|
26
|
+
text: string;
|
|
27
|
+
}
|
|
28
|
+
export interface DiagnosticLocation {
|
|
29
|
+
file: string;
|
|
30
|
+
line: number;
|
|
31
|
+
column: number;
|
|
32
|
+
length: number;
|
|
33
|
+
}
|
|
13
34
|
export interface TransformOptions {
|
|
14
35
|
internalURL?: string;
|
|
15
36
|
site?: string;
|
|
@@ -42,14 +63,15 @@ export interface HydratedComponent {
|
|
|
42
63
|
resolvedPath: string;
|
|
43
64
|
}
|
|
44
65
|
export interface TransformResult {
|
|
45
|
-
css: string[];
|
|
46
|
-
scripts: HoistedScript[];
|
|
47
|
-
hydratedComponents: HydratedComponent[];
|
|
48
|
-
clientOnlyComponents: HydratedComponent[];
|
|
49
66
|
code: string;
|
|
50
67
|
map: string;
|
|
51
68
|
scope: string;
|
|
52
69
|
styleError: string[];
|
|
70
|
+
diagnostics: DiagnosticMessage[];
|
|
71
|
+
css: string[];
|
|
72
|
+
scripts: HoistedScript[];
|
|
73
|
+
hydratedComponents: HydratedComponent[];
|
|
74
|
+
clientOnlyComponents: HydratedComponent[];
|
|
53
75
|
}
|
|
54
76
|
export interface SourceMap {
|
|
55
77
|
file: string;
|
|
@@ -62,9 +84,11 @@ export interface SourceMap {
|
|
|
62
84
|
export interface TSXResult {
|
|
63
85
|
code: string;
|
|
64
86
|
map: SourceMap;
|
|
87
|
+
diagnostics: DiagnosticMessage[];
|
|
65
88
|
}
|
|
66
89
|
export interface ParseResult {
|
|
67
90
|
ast: RootNode;
|
|
91
|
+
diagnostics: DiagnosticMessage[];
|
|
68
92
|
}
|
|
69
93
|
export declare function transform(input: string, options?: TransformOptions): Promise<TransformResult>;
|
|
70
94
|
export declare function parse(input: string, options?: ParseOptions): Promise<ParseResult>;
|
package/shared/types.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
1
|
export * from './ast';
|
|
2
|
+
export * from './diagnostics';
|
|
3
|
+
// eslint-disable-next-line no-shadow
|
|
4
|
+
export var DiagnosticSeverity;
|
|
5
|
+
(function (DiagnosticSeverity) {
|
|
6
|
+
DiagnosticSeverity[DiagnosticSeverity["Error"] = 1] = "Error";
|
|
7
|
+
DiagnosticSeverity[DiagnosticSeverity["Warning"] = 2] = "Warning";
|
|
8
|
+
DiagnosticSeverity[DiagnosticSeverity["Information"] = 3] = "Information";
|
|
9
|
+
DiagnosticSeverity[DiagnosticSeverity["Hint"] = 4] = "Hint";
|
|
10
|
+
})(DiagnosticSeverity || (DiagnosticSeverity = {}));
|
package/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './shared/
|
|
1
|
+
export * from './shared/types';
|