@astrojs/compiler 0.0.0-sourcemap-20230103195910 → 0.0.0-sync-20230409173822

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,10 +1,119 @@
1
1
  # @astrojs/compiler
2
2
 
3
- ## 0.0.0-sourcemap-20230103195910
3
+ ## 0.0.0-sync-20230409173822
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - ca1806c: Fixes export hoisting edge case
7
+ - 5803b39: Add a sync entrypoint
8
+
9
+ ## 1.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - e0baa85: Preserve whitespace in slots
14
+
15
+ ## 1.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 95a6610: Expose the `convertToTSX` function in the compiler browser bundle
20
+ - 6d168dd: Add ContainsHead flag for metadata
21
+
22
+ ## 1.2.2
23
+
24
+ ### Patch Changes
25
+
26
+ - a8a845f: Fix regression related to self-closing tags
27
+
28
+ ## 1.2.1
29
+
30
+ ### Patch Changes
31
+
32
+ - 348840b: Fix getStaticPaths export when used with a TypeScript type ([#4929](https://github.com/withastro/astro/issues/4929))
33
+ - 8ed067e: Fix parse error for multiline `export type` using Unions or Intersections
34
+ - 6354e50: Improve handling of self-closing tags returned from expression
35
+ - 5a5f91d: Fix `define:vars` when used with a `style` attribute
36
+ - b637e9a: Fix ignored `form` elements after a `form` element that contains an expression
37
+ - 2658ed4: Correctly apply style when `class` and `class:list` are both used
38
+
39
+ ## 1.2.0
40
+
41
+ ### Minor Changes
42
+
43
+ - b2cfd00: Add teardown API to remove WASM instance after using the compiler
44
+
45
+ ## 1.1.2
46
+
47
+ ### Patch Changes
48
+
49
+ - 2de6128: Preserve namespaced attributes when using expressions
50
+ - af13f2d: Fix incorrect `convertToTSX` types. The function accepts `filename`, not `sourcefile`.
51
+ - 5eb4fff: Compile `set:html` and `set:text` quoted and template literal attributes as strings
52
+
53
+ ## 1.1.1
54
+
55
+ ### Patch Changes
56
+
57
+ - 6765f01: Fix attributes starting with : not being properly transformed in the TSX output
58
+
59
+ ## 1.1.0
60
+
61
+ ### Minor Changes
62
+
63
+ - a75824d: Allow passing through result to slot call
64
+
65
+ ## 1.0.2
66
+
67
+ ### Patch Changes
68
+
69
+ - 0c27f3f: Collapse multiple trailing text nodes if present
70
+
71
+ ## 1.0.1
72
+
73
+ ### Patch Changes
74
+
75
+ - 94b2c02: Prevent insertion of maybeRenderHead on hoisted scripts
76
+
77
+ ## 1.0.0
78
+
79
+ ### Major Changes
80
+
81
+ - 8e86bc6: The Astro compiler is officially stable! This release is entirely ceremonial, the code is the same as [`@astrojs/compiler@0.33.0`](https://github.com/withastro/compiler/releases/tag/%40astrojs%2Fcompiler%400.33.0)
82
+
83
+ ## 0.33.0
84
+
85
+ ### Minor Changes
86
+
87
+ - 1adac72: Improve error recovery when using the `transform` function. The compiler will now properly reject the promise with a useful message and stacktrace rather than print internal errors to stdout.
88
+
89
+ ### Patch Changes
90
+
91
+ - 68d3c0c: Fix edge case where `export type` could hang the compiler
92
+ - ec1ddf0: Handle edge case with TypeScript generics handling and our TSX output
93
+ - 23d1fc0: Ignore trailing whitespace in components
94
+
95
+ ## 0.32.0
96
+
97
+ ### Minor Changes
98
+
99
+ - 2404848: Remove `pathname` option in favour of `sourcefile` option
100
+ - 2ca86f6: Remove `site` and `projectRoot` options in favour of the `astroGlobalArgs` option
101
+ - edd3e0e: Merge `sourcefile` and `moduleId` options as a single `filename` option. Add a new `normalizedFilename` option to generate stable hashes instead.
102
+ - 08843bd: Remove `experimentalStaticExtraction` option. It is now the default.
103
+
104
+ ## 0.31.4
105
+
106
+ ### Patch Changes
107
+
108
+ - 960b853: Rename `SerializeOtions` interface to `SerializeOptions`
109
+ - fcab891: Fixes export hoisting edge case
110
+ - 47de01a: Handle module IDs containing quotes
111
+
112
+ ## 0.31.3
113
+
114
+ ### Patch Changes
115
+
116
+ - fd5cb57: Rollback https://github.com/withastro/compiler/pull/674
8
117
 
9
118
  ## 0.31.2
10
119
 
@@ -66,7 +175,7 @@
66
175
 
67
176
  ### Patch Changes
68
177
 
69
- - ec745f4: Self-closing tags will now retreive "end" positional data
178
+ - ec745f4: Self-closing tags will now retrieve "end" positional data
70
179
  - a6c2822: Fix a few TSX output errors
71
180
 
72
181
  ## 0.29.15
@@ -164,7 +273,7 @@
164
273
 
165
274
  ### Minor Changes
166
275
 
167
- - fd2fc28: Fix some utf8 compatability issues
276
+ - fd2fc28: Fix some utf8 compatibility issues
168
277
 
169
278
  ### Patch Changes
170
279
 
@@ -344,7 +453,7 @@
344
453
 
345
454
  - a28c3d8: Fix handling of unbalanced quotes in expression attributes
346
455
  - 28d1d4d: Fix handling of TS generics inside of expressions
347
- - 356d3b6: Prevent wraping module scripts with scope
456
+ - 356d3b6: Prevent wrapping module scripts with scope
348
457
 
349
458
  ## 0.22.1
350
459
 
package/README.md CHANGED
@@ -23,8 +23,7 @@ The Astro compiler can convert `.astro` syntax to a TypeScript Module whose defa
23
23
  import { transform } from '@astrojs/compiler';
24
24
 
25
25
  const result = await transform(source, {
26
- site: 'https://mysite.dev',
27
- sourcefile: '/Users/astro/Code/project/src/pages/index.astro',
26
+ filename: '/Users/astro/Code/project/src/pages/index.astro',
28
27
  sourcemap: 'both',
29
28
  internalURL: 'astro/runtime/server/index.js',
30
29
  });
package/astro.wasm CHANGED
Binary file
@@ -1,4 +1,6 @@
1
1
  import type * as types from '../shared/types';
2
2
  export declare const transform: typeof types.transform;
3
3
  export declare const parse: typeof types.parse;
4
+ export declare const convertToTSX: typeof types.convertToTSX;
5
+ export declare const teardown: typeof types.teardown;
4
6
  export declare const initialize: typeof types.initialize;
package/browser/index.js CHANGED
@@ -5,8 +5,16 @@ export const transform = (input, options) => {
5
5
  export const parse = (input, options) => {
6
6
  return ensureServiceIsRunning().parse(input, options);
7
7
  };
8
+ export const convertToTSX = (input, options) => {
9
+ return ensureServiceIsRunning().convertToTSX(input, options);
10
+ };
8
11
  let initializePromise;
9
12
  let longLivedService;
13
+ export const teardown = () => {
14
+ initializePromise = undefined;
15
+ longLivedService = undefined;
16
+ globalThis['@astrojs/compiler'] = undefined;
17
+ };
10
18
  export const initialize = async (options) => {
11
19
  let wasmURL = options.wasmURL;
12
20
  if (!wasmURL)
@@ -50,6 +58,10 @@ const startRunningService = async (wasmURL) => {
50
58
  const service = globalThis['@astrojs/compiler'];
51
59
  return {
52
60
  transform: (input, options) => new Promise((resolve) => resolve(service.transform(input, options || {}))),
61
+ convertToTSX: (input, options) => new Promise((resolve) => resolve(service.convertToTSX(input, options || {}))).then((result) => ({
62
+ ...result,
63
+ map: JSON.parse(result.map),
64
+ })),
53
65
  parse: (input, options) => new Promise((resolve) => resolve(service.parse(input, options || {}))).then((result) => ({ ...result, ast: JSON.parse(result.ast) })),
54
66
  };
55
67
  };
@@ -19,7 +19,9 @@ export declare const is: {
19
19
  frontmatter: (node: Node) => node is FrontmatterNode;
20
20
  };
21
21
  export declare function walk(node: ParentNode, callback: Visitor): void;
22
- export interface SerializeOtions {
22
+ export interface SerializeOptions {
23
23
  selfClose: boolean;
24
24
  }
25
- export declare function serialize(root: Node, opts?: SerializeOtions): string;
25
+ /** @deprecated Please use `SerializeOptions` */
26
+ export type SerializeOtions = SerializeOptions;
27
+ export declare function serialize(root: Node, opts?: SerializeOptions): string;
package/node/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export type { PreprocessorResult, ParseOptions, TransformOptions, HoistedScript, TransformResult, ParseResult } from '../shared/types';
1
+ export type { HoistedScript, ParseOptions, ParseResult, PreprocessorResult, TransformOptions, TransformResult } from '../shared/types';
2
2
  import type * as types from '../shared/types';
3
3
  export declare const transform: typeof types.transform;
4
4
  export declare const parse: typeof types.parse;
5
5
  export declare const convertToTSX: typeof types.convertToTSX;
6
6
  export declare const compile: (template: string) => Promise<string>;
7
+ export declare const teardown: typeof types.teardown;
package/node/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { promises as fs } from 'fs';
2
- import Go from './wasm_exec.js';
3
2
  import { fileURLToPath } from 'url';
3
+ import Go from './wasm_exec.js';
4
4
  export const transform = async (input, options) => {
5
5
  return getService().then((service) => service.transform(input, options));
6
6
  };
@@ -15,6 +15,10 @@ export const compile = async (template) => {
15
15
  return mod;
16
16
  };
17
17
  let longLivedService;
18
+ export const teardown = () => {
19
+ longLivedService = undefined;
20
+ globalThis['@astrojs/compiler'] = undefined;
21
+ };
18
22
  let getService = () => {
19
23
  if (!longLivedService) {
20
24
  longLivedService = startRunningService().catch((err) => {
package/node/sync.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type * as types from '../shared/types';
2
+ export declare const transform: (input: string, options: types.TransformOptions | undefined) => types.TransformResult;
3
+ export declare const parse: (input: string, options: types.ParseOptions | undefined) => types.ParseResult;
4
+ export declare const convertToTSX: (input: string, options: types.ConvertToTSXOptions | undefined) => types.TSXResult;
5
+ export declare function startRunningService(wasmPath: string): Promise<string>;
package/node/sync.js ADDED
@@ -0,0 +1,52 @@
1
+ import { promises as fs } from 'fs';
2
+ import Go from './wasm_exec';
3
+ function getService() {
4
+ if (!longLivedService) {
5
+ throw new Error("Service hasn't been started. Start it with startRunningService.");
6
+ }
7
+ return longLivedService;
8
+ }
9
+ let longLivedService;
10
+ export const transform = ((input, options) => getService().transform(input, options));
11
+ export const parse = ((input, options) => {
12
+ return getService().parse(input, options);
13
+ });
14
+ export const convertToTSX = ((input, options) => {
15
+ return getService().convertToTSX(input, options);
16
+ });
17
+ export async function startRunningService(wasmPath) {
18
+ const go = new Go();
19
+ const wasm = await instantiateWASM(wasmPath, go.importObject);
20
+ go.run(wasm.instance);
21
+ const _service = globalThis['@astrojs/compiler'];
22
+ longLivedService = {
23
+ transform: (input, options) => {
24
+ try {
25
+ return _service.transform(input, options || {});
26
+ }
27
+ catch (err) {
28
+ // Recreate the service next time on panic
29
+ longLivedService = void 0;
30
+ throw err;
31
+ }
32
+ },
33
+ parse: (input, options) => {
34
+ const result = _service.parse(input, options || {});
35
+ return { ...result, ast: JSON.parse(result.ast) };
36
+ },
37
+ convertToTSX: (input, options) => {
38
+ const result = _service.convertToTSX(input, options || {});
39
+ return { ...result, map: JSON.parse(result.map) };
40
+ },
41
+ };
42
+ return 'hey';
43
+ }
44
+ async function instantiateWASM(wasmURL, importObject) {
45
+ let response = undefined;
46
+ const fetchAndInstantiateTask = async () => {
47
+ const wasmArrayBuffer = await fs.readFile(wasmURL).then((res) => res.buffer);
48
+ return WebAssembly.instantiate(new Uint8Array(wasmArrayBuffer), importObject);
49
+ };
50
+ response = await fetchAndInstantiateTask();
51
+ return response;
52
+ }
package/node/utils.d.ts CHANGED
@@ -19,7 +19,9 @@ export declare const is: {
19
19
  frontmatter: (node: Node) => node is FrontmatterNode;
20
20
  };
21
21
  export declare function walk(node: ParentNode, callback: Visitor): void;
22
- export interface SerializeOtions {
22
+ export interface SerializeOptions {
23
23
  selfClose: boolean;
24
24
  }
25
- export declare function serialize(root: Node, opts?: SerializeOtions): string;
25
+ /** @deprecated Please use `SerializeOptions` */
26
+ export type SerializeOtions = SerializeOptions;
27
+ export declare function serialize(root: Node, opts?: SerializeOptions): string;
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.0.0-sourcemap-20230103195910",
8
+ "version": "0.0.0-sync-20230409173822",
9
9
  "main": "./node/index.js",
10
10
  "types": "./node",
11
11
  "repository": {
@@ -18,6 +18,10 @@
18
18
  "import": "./node/index.js",
19
19
  "default": "./browser/index.js"
20
20
  },
21
+ "./sync": {
22
+ "import": "./node/sync.js",
23
+ "default": "./node/sync.js"
24
+ },
21
25
  "./utils": {
22
26
  "browser": "./browser/utils.js",
23
27
  "import": "./node/utils.js",
@@ -28,10 +32,10 @@
28
32
  },
29
33
  "devDependencies": {
30
34
  "@jridgewell/trace-mapping": "^0.3.16",
31
- "@types/node": "^16.11.64",
35
+ "@types/node": "^18.15.11",
32
36
  "@types/sass": "^1.43.1",
33
37
  "acorn": "^8.8.1",
34
- "typescript": "~4.8.4"
38
+ "typescript": "~4.9.0"
35
39
  },
36
40
  "scripts": {
37
41
  "build": "tsc -p ."
package/shared/ast.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export declare type ParentNode = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode;
2
- export declare type LiteralNode = TextNode | DoctypeNode | CommentNode | FrontmatterNode;
3
- export declare type Node = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode | TextNode | FrontmatterNode | DoctypeNode | CommentNode;
1
+ export type ParentNode = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode;
2
+ export type LiteralNode = TextNode | DoctypeNode | CommentNode | FrontmatterNode;
3
+ export type Node = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode | TextNode | FrontmatterNode | DoctypeNode | CommentNode;
4
4
  export interface Position {
5
5
  start: Point;
6
6
  end?: Point;
@@ -56,7 +56,7 @@ export interface CustomElementNode extends ParentLikeNode {
56
56
  name: string;
57
57
  attributes: AttributeNode[];
58
58
  }
59
- export declare type TagLikeNode = ElementNode | FragmentNode | ComponentNode | CustomElementNode;
59
+ export type TagLikeNode = ElementNode | FragmentNode | ComponentNode | CustomElementNode;
60
60
  export interface DoctypeNode extends ValueNode {
61
61
  type: 'doctype';
62
62
  }
package/shared/types.d.ts CHANGED
@@ -33,22 +33,21 @@ export interface DiagnosticLocation {
33
33
  }
34
34
  export interface TransformOptions {
35
35
  internalURL?: string;
36
- site?: string;
37
- sourcefile?: string;
38
- pathname?: string;
39
- moduleId?: string;
36
+ filename?: string;
37
+ normalizedFilename?: string;
40
38
  sourcemap?: boolean | 'inline' | 'external' | 'both';
39
+ astroGlobalArgs?: string;
41
40
  compact?: boolean;
41
+ resultScopedSlot?: boolean;
42
42
  /**
43
43
  * @deprecated "as" has been removed and no longer has any effect!
44
44
  */
45
45
  as?: 'document' | 'fragment';
46
- projectRoot?: string;
47
46
  resolvePath?: (specifier: string) => Promise<string>;
48
47
  preprocessStyle?: (content: string, attrs: Record<string, string>) => null | Promise<PreprocessorResult | PreprocessorError>;
49
- experimentalStaticExtraction?: boolean;
50
48
  }
51
- export declare type HoistedScript = {
49
+ export type ConvertToTSXOptions = Pick<TransformOptions, 'filename' | 'normalizedFilename'>;
50
+ export type HoistedScript = {
52
51
  type: string;
53
52
  } & ({
54
53
  type: 'external';
@@ -73,6 +72,7 @@ export interface TransformResult {
73
72
  scripts: HoistedScript[];
74
73
  hydratedComponents: HydratedComponent[];
75
74
  clientOnlyComponents: HydratedComponent[];
75
+ containsHead: boolean;
76
76
  }
77
77
  export interface SourceMap {
78
78
  file: string;
@@ -93,10 +93,19 @@ export interface ParseResult {
93
93
  }
94
94
  export declare function transform(input: string, options?: TransformOptions): Promise<TransformResult>;
95
95
  export declare function parse(input: string, options?: ParseOptions): Promise<ParseResult>;
96
- export declare function convertToTSX(input: string, options?: {
97
- sourcefile?: string;
98
- }): Promise<TSXResult>;
96
+ export declare function convertToTSX(input: string, options?: ConvertToTSXOptions): Promise<TSXResult>;
99
97
  export declare function initialize(options: InitializeOptions): Promise<void>;
98
+ /**
99
+ * When calling the core compiler APIs, e.g. `transform`, `parse`, etc, they
100
+ * would automatically instantiate a WASM instance to process the input. When
101
+ * done, you can call this to manually teardown the WASM instance.
102
+ *
103
+ * If the APIs are called again, they will automatically instantiate a new WASM
104
+ * instance. In browsers, you have to call `initialize()` again before using the APIs.
105
+ *
106
+ * Note: Calling teardown is optional and exists mostly as an optimization only.
107
+ */
108
+ export declare function teardown(): void;
100
109
  export interface InitializeOptions {
101
110
  wasmURL?: string;
102
111
  }
package/sync.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './node/sync';