@tsrx/preact 0.0.8 → 0.0.9
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/package.json +2 -2
- package/src/index.js +10 -7
- package/types/index.d.ts +3 -2
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Preact compiler built on @tsrx/core",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.9",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"esrap": "^2.1.0",
|
|
27
27
|
"zimmerframe": "^1.1.2",
|
|
28
|
-
"@tsrx/core": "0.0.
|
|
28
|
+
"@tsrx/core": "0.0.14"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"preact": ">=10"
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @import * as AST from 'estree' */
|
|
2
|
-
/** @import { ParseOptions } from '@tsrx/core/types' */
|
|
2
|
+
/** @import { CompileError, ParseOptions } from '@tsrx/core/types' */
|
|
3
3
|
/** @import { CompileOptions } from './transform.js' */
|
|
4
4
|
|
|
5
5
|
import { createVolarMappingsResult, dedupeMappings, parseModule } from '@tsrx/core';
|
|
@@ -24,13 +24,15 @@ export function parse(source, filename, options) {
|
|
|
24
24
|
*
|
|
25
25
|
* @param {string} source
|
|
26
26
|
* @param {string} [filename]
|
|
27
|
-
* @param {CompileOptions} [compile_options]
|
|
28
|
-
* @returns {{ code: string, map: any, css: { code: string, hash: string } | null }}
|
|
27
|
+
* @param {CompileOptions & { loose?: boolean }} [compile_options]
|
|
28
|
+
* @returns {{ code: string, map: any, css: { code: string, hash: string } | null, errors: CompileError[] }}
|
|
29
29
|
*/
|
|
30
30
|
export function compile(source, filename, compile_options) {
|
|
31
|
-
const
|
|
31
|
+
const errors = /** @type {CompileError[]} */ ([]);
|
|
32
|
+
const collect = !!compile_options?.loose;
|
|
33
|
+
const ast = parseModule(source, filename, collect ? { loose: true, errors } : undefined);
|
|
32
34
|
const { ast: _ast, ...result } = transform(ast, source, filename, compile_options);
|
|
33
|
-
return result;
|
|
35
|
+
return { ...result, errors };
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|
|
@@ -42,7 +44,8 @@ export function compile(source, filename, compile_options) {
|
|
|
42
44
|
* @returns {import('@tsrx/core/types').VolarMappingsResult}
|
|
43
45
|
*/
|
|
44
46
|
export function compile_to_volar_mappings(source, filename, options) {
|
|
45
|
-
const
|
|
47
|
+
const errors = /** @type {import('@tsrx/core/types').CompileError[]} */ ([]);
|
|
48
|
+
const ast = parseModule(source, filename, { ...options, errors });
|
|
46
49
|
const transformed = transform(ast, source, filename, options);
|
|
47
50
|
const result = createVolarMappingsResult({
|
|
48
51
|
ast: transformed.ast,
|
|
@@ -50,7 +53,7 @@ export function compile_to_volar_mappings(source, filename, options) {
|
|
|
50
53
|
source,
|
|
51
54
|
generated_code: transformed.code,
|
|
52
55
|
source_map: transformed.map,
|
|
53
|
-
errors
|
|
56
|
+
errors,
|
|
54
57
|
});
|
|
55
58
|
|
|
56
59
|
return {
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Program } from 'estree';
|
|
2
|
-
import type { ParseOptions, VolarMappingsResult } from '@tsrx/core/types';
|
|
2
|
+
import type { CompileError, ParseOptions, VolarMappingsResult } from '@tsrx/core/types';
|
|
3
3
|
|
|
4
4
|
export interface CompileOptions {
|
|
5
5
|
suspenseSource?: string;
|
|
@@ -12,11 +12,12 @@ export function parse(source: string, filename?: string, options?: ParseOptions)
|
|
|
12
12
|
export function compile(
|
|
13
13
|
source: string,
|
|
14
14
|
filename?: string,
|
|
15
|
-
compile_options?: CompileOptions,
|
|
15
|
+
compile_options?: CompileOptions & { loose?: boolean },
|
|
16
16
|
): {
|
|
17
17
|
code: string;
|
|
18
18
|
map: unknown;
|
|
19
19
|
css: { code: string; hash: string } | null;
|
|
20
|
+
errors: CompileError[];
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export function compile_to_volar_mappings(
|