@astrojs/compiler 2.8.1 → 2.9.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/README.md CHANGED
@@ -20,12 +20,12 @@ The Astro compiler can convert `.astro` syntax to a TypeScript Module whose defa
20
20
  - `.astro` files rely on a server implementation exposed as `astro/runtime/server/index.js` in the Node ecosystem. Other runtimes currently need to bring their own rendering implementation and reference it via `internalURL`. This is a pain point we're looking into fixing.
21
21
 
22
22
  ```js
23
- import { transform } from '@astrojs/compiler';
23
+ import { transform, type TransformResult } from "@astrojs/compiler";
24
24
 
25
25
  const result = await transform(source, {
26
- filename: '/Users/astro/Code/project/src/pages/index.astro',
27
- sourcemap: 'both',
28
- internalURL: 'astro/runtime/server/index.js',
26
+ filename: "/Users/astro/Code/project/src/pages/index.astro",
27
+ sourcemap: "both",
28
+ internalURL: "astro/runtime/server/index.js",
29
29
  });
30
30
  ```
31
31
 
@@ -40,8 +40,8 @@ The Astro compiler can emit an AST using the `parse` method.
40
40
  - The `@astrojs/compiler/utils` entrypoint exposes a `walk` function that can be used to traverse the AST. It also exposes the `is` helper which can be used as guards to derive the proper types for each `node`.
41
41
 
42
42
  ```js
43
- import { parse } from '@astrojs/compiler';
44
- import { walk, is } from '@astrojs/compiler/utils';
43
+ import { parse } from "@astrojs/compiler";
44
+ import { walk, is } from "@astrojs/compiler/utils";
45
45
 
46
46
  const result = await parse(source, {
47
47
  position: false, // defaults to `true`
package/dist/astro.wasm CHANGED
Binary file
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(r,t)=>{for(var n in t)o(r,n,{get:t[n],enumerable:!0})},g=(r,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of p(t))!c.call(r,e)&&e!==n&&o(r,e,{get:()=>t[e],enumerable:!(s=a(t,e))||s.enumerable});return r};var m=r=>g(o({},"__esModule",{value:!0}),r);var d={};l(d,{DiagnosticSeverity:()=>i});module.exports=m(d);var i=(e=>(e[e.Error=1]="Error",e[e.Warning=2]="Warning",e[e.Information=3]="Information",e[e.Hint=4]="Hint",e))(i||{});0&&(module.exports={DiagnosticSeverity});
1
+ "use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(r,t)=>{for(var n in t)o(r,n,{get:t[n],enumerable:!0})},g=(r,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of p(t))!c.call(r,e)&&e!==n&&o(r,e,{get:()=>t[e],enumerable:!(s=a(t,e))||s.enumerable});return r};var d=r=>g(o({},"__esModule",{value:!0}),r);var m={};l(m,{DiagnosticSeverity:()=>i});module.exports=d(m);var i=(e=>(e[e.Error=1]="Error",e[e.Warning=2]="Warning",e[e.Information=3]="Information",e[e.Hint=4]="Hint",e))(i||{});0&&(module.exports={DiagnosticSeverity});
@@ -45,7 +45,7 @@ interface TransformOptions {
45
45
  */
46
46
  as?: 'document' | 'fragment';
47
47
  transitionsAnimationURL?: string;
48
- resolvePath?: (specifier: string) => Promise<string>;
48
+ resolvePath?: (specifier: string) => Promise<string> | string;
49
49
  preprocessStyle?: (content: string, attrs: Record<string, string>) => null | Promise<PreprocessorResult | PreprocessorError>;
50
50
  annotateSourceFile?: boolean;
51
51
  /**
@@ -55,7 +55,16 @@ interface TransformOptions {
55
55
  */
56
56
  renderScript?: boolean;
57
57
  }
58
- type ConvertToTSXOptions = Pick<TransformOptions, 'filename' | 'normalizedFilename'>;
58
+ type ConvertToTSXOptions = Pick<TransformOptions, 'filename' | 'normalizedFilename' | 'sourcemap'> & {
59
+ /** If set to true, script tags content will be included in the generated TSX
60
+ * Scripts will be wrapped in an arrow function to be compatible with JSX's spec
61
+ */
62
+ includeScripts?: boolean;
63
+ /** If set to true, style tags content will be included in the generated TSX
64
+ * Styles will be wrapped in a template literal to be compatible with JSX's spec
65
+ */
66
+ includeStyles?: boolean;
67
+ };
59
68
  type HoistedScript = {
60
69
  type: string;
61
70
  } & ({
@@ -68,6 +77,7 @@ type HoistedScript = {
68
77
  });
69
78
  interface HydratedComponent {
70
79
  exportName: string;
80
+ localName: string;
71
81
  specifier: string;
72
82
  resolvedPath: string;
73
83
  }
@@ -81,6 +91,7 @@ interface TransformResult {
81
91
  scripts: HoistedScript[];
82
92
  hydratedComponents: HydratedComponent[];
83
93
  clientOnlyComponents: HydratedComponent[];
94
+ serverComponents: HydratedComponent[];
84
95
  containsHead: boolean;
85
96
  propagation: boolean;
86
97
  }
@@ -92,19 +103,29 @@ interface SourceMap {
92
103
  sourcesContent: string[];
93
104
  version: number;
94
105
  }
106
+ interface TSXLocation {
107
+ start: number;
108
+ end: number;
109
+ }
110
+ interface TSXExtractedTag {
111
+ position: TSXLocation;
112
+ content: string;
113
+ }
114
+ interface TSXExtractedScript extends TSXExtractedTag {
115
+ type: 'processed-module' | 'module' | 'inline' | 'event-attribute' | 'json' | 'unknown';
116
+ }
117
+ interface TSXExtractedStyle extends TSXExtractedTag {
118
+ type: 'tag' | 'style-attribute';
119
+ }
95
120
  interface TSXResult {
96
121
  code: string;
97
122
  map: SourceMap;
98
123
  diagnostics: DiagnosticMessage[];
99
124
  metaRanges: {
100
- frontmatter: {
101
- start: number;
102
- end: number;
103
- };
104
- body: {
105
- start: number;
106
- end: number;
107
- };
125
+ frontmatter: TSXLocation;
126
+ body: TSXLocation;
127
+ scripts?: TSXExtractedScript[];
128
+ styles?: TSXExtractedStyle[];
108
129
  };
109
130
  }
110
131
  interface ParseResult {
@@ -130,4 +151,4 @@ interface InitializeOptions {
130
151
  wasmURL?: string;
131
152
  }
132
153
 
133
- export { ConvertToTSXOptions, DiagnosticLocation, DiagnosticMessage, DiagnosticSeverity, HoistedScript, HydratedComponent, InitializeOptions, ParseOptions, ParseResult, PreprocessorError, PreprocessorResult, RootNode, SourceMap, TSXResult, TransformOptions, TransformResult, convertToTSX, initialize, parse, teardown, transform };
154
+ export { ConvertToTSXOptions, DiagnosticLocation, DiagnosticMessage, DiagnosticSeverity, HoistedScript, HydratedComponent, InitializeOptions, ParseOptions, ParseResult, PreprocessorError, PreprocessorResult, RootNode, SourceMap, TSXExtractedScript, TSXExtractedStyle, TSXExtractedTag, TSXLocation, TSXResult, TransformOptions, TransformResult, convertToTSX, initialize, parse, teardown, transform };
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": "2.8.1",
8
+ "version": "2.9.0",
9
9
  "main": "./dist/node/index.js",
10
10
  "types": "./dist/shared/types.d.ts",
11
11
  "repository": {