@astrojs/compiler 0.26.1 → 0.27.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # @astrojs/compiler
2
2
 
3
+ ## 0.27.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cc9f174: fixed regression caused by #546
8
+
9
+ ## 0.27.0
10
+
11
+ ### Minor Changes
12
+
13
+ - c770e7b: The compiler will now return `diagnostics` and unique error codes to be handled by the consumer. For example:
14
+
15
+ ```js
16
+ import type { DiagnosticSeverity, DiagnosticCode } from '@astrojs/compiler/types';
17
+ import { transform } from '@astrojs/compiler';
18
+
19
+ async function run() {
20
+ const { diagnostics } = await transform(file, opts);
21
+
22
+ function log(severity: DiagnosticSeverity, message: string) {
23
+ switch (severity) {
24
+ case DiagnosticSeverity.Error:
25
+ return console.error(message);
26
+ case DiagnosticSeverity.Warning:
27
+ return console.warn(message);
28
+ case DiagnosticSeverity.Information:
29
+ return console.info(message);
30
+ case DiagnosticSeverity.Hint:
31
+ return console.info(message);
32
+ }
33
+ }
34
+
35
+ for (const diagnostic of diagnostics) {
36
+ let message = diagnostic.text;
37
+ if (diagnostic.hint) {
38
+ message += `\n\n[hint] ${diagnostic.hint}`;
39
+ }
40
+
41
+ // Or customize messages for a known DiagnosticCode
42
+ if (diagnostic.code === DiagnosticCode.ERROR_UNMATCHED_IMPORT) {
43
+ message = `My custom message about an unmatched import!`;
44
+ }
45
+ log(diagnostic.severity, message);
46
+ }
47
+ }
48
+ ```
49
+
50
+ ### Patch Changes
51
+
52
+ - 0b24c24: Implement automatic typing for Astro.props in the TSX output
53
+
3
54
  ## 0.26.1
4
55
 
5
56
  ### Patch Changes
package/astro.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "module",
6
6
  "bugs": "https://github.com/withastro/compiler/issues",
7
7
  "homepage": "https://astro.build",
8
- "version": "0.26.1",
8
+ "version": "0.27.1",
9
9
  "main": "./node/index.js",
10
10
  "types": "./node",
11
11
  "repository": {
@@ -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/ast';
1
+ export * from './shared/types';