@tsrx/core 0.0.19 → 0.0.21
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 +10 -185
- package/package.json +1 -1
- package/src/diagnostics.js +7 -0
- package/src/errors.js +3 -1
- package/src/index.js +1 -0
- package/src/parse/index.js +4 -2
- package/src/plugin.js +157 -112
- package/src/scope.js +2 -2
- package/src/transform/jsx/ast-builders.js +29 -0
- package/src/transform/jsx/index.js +819 -201
- package/src/utils/builders.js +68 -0
- package/types/index.d.ts +10 -3
- package/types/jsx-platform.d.ts +7 -3
- package/types/parse.d.ts +4 -2
package/src/utils/builders.js
CHANGED
|
@@ -1100,6 +1100,74 @@ export function jsx_attribute(name, value = null, shorthand = false, loc_info) {
|
|
|
1100
1100
|
return set_location(node, loc_info);
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
1103
|
+
/**
|
|
1104
|
+
* Build a fresh `JSXOpeningElement`. For elements derived from an existing
|
|
1105
|
+
* Element node, prefer `jsx_element` which spreads from the source.
|
|
1106
|
+
*
|
|
1107
|
+
* @param {ESTreeJSX.JSXOpeningElement['name']} name
|
|
1108
|
+
* @param {ESTreeJSX.JSXOpeningElement['attributes']} [attributes]
|
|
1109
|
+
* @param {boolean} [self_closing]
|
|
1110
|
+
* @param {AST.NodeWithLocation} [loc_info]
|
|
1111
|
+
* @returns {ESTreeJSX.JSXOpeningElement}
|
|
1112
|
+
*/
|
|
1113
|
+
export function jsx_opening_element(name, attributes = [], self_closing = false, loc_info) {
|
|
1114
|
+
const node = /** @type {ESTreeJSX.JSXOpeningElement} */ ({
|
|
1115
|
+
type: 'JSXOpeningElement',
|
|
1116
|
+
name,
|
|
1117
|
+
attributes,
|
|
1118
|
+
selfClosing: self_closing,
|
|
1119
|
+
metadata: { path: [] },
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1122
|
+
return set_location(node, loc_info);
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* Build a fresh `JSXClosingElement`.
|
|
1127
|
+
*
|
|
1128
|
+
* @param {ESTreeJSX.JSXClosingElement['name']} name
|
|
1129
|
+
* @param {AST.NodeWithLocation} [loc_info]
|
|
1130
|
+
* @returns {ESTreeJSX.JSXClosingElement}
|
|
1131
|
+
*/
|
|
1132
|
+
export function jsx_closing_element(name, loc_info) {
|
|
1133
|
+
const node = /** @type {ESTreeJSX.JSXClosingElement} */ ({
|
|
1134
|
+
type: 'JSXClosingElement',
|
|
1135
|
+
name,
|
|
1136
|
+
metadata: { path: [] },
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
return set_location(node, loc_info);
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Build a fresh `JSXElement` from explicit opening / closing / children.
|
|
1144
|
+
* Companion to `jsx_opening_element` / `jsx_closing_element`. For elements
|
|
1145
|
+
* derived from an existing source node, use `jsx_element` (which spreads
|
|
1146
|
+
* the source's name and metadata).
|
|
1147
|
+
*
|
|
1148
|
+
* @param {ESTreeJSX.JSXOpeningElement} opening_element
|
|
1149
|
+
* @param {ESTreeJSX.JSXClosingElement | null} [closing_element]
|
|
1150
|
+
* @param {ESTreeJSX.JSXElement['children']} [children]
|
|
1151
|
+
* @param {AST.NodeWithLocation} [loc_info]
|
|
1152
|
+
* @returns {ESTreeJSX.JSXElement}
|
|
1153
|
+
*/
|
|
1154
|
+
export function jsx_element_fresh(
|
|
1155
|
+
opening_element,
|
|
1156
|
+
closing_element = null,
|
|
1157
|
+
children = [],
|
|
1158
|
+
loc_info,
|
|
1159
|
+
) {
|
|
1160
|
+
const node = /** @type {ESTreeJSX.JSXElement} */ ({
|
|
1161
|
+
type: 'JSXElement',
|
|
1162
|
+
openingElement: opening_element,
|
|
1163
|
+
closingElement: closing_element,
|
|
1164
|
+
children,
|
|
1165
|
+
metadata: { path: [] },
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
return set_location(node, loc_info);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1103
1171
|
/**
|
|
1104
1172
|
* @param {AST.Element} node
|
|
1105
1173
|
* @param {ESTreeJSX.JSXOpeningElement['attributes']} attributes
|
package/types/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export { createJsxTransform, componentToFunctionDeclaration };
|
|
|
29
29
|
* Compile error interface
|
|
30
30
|
*/
|
|
31
31
|
export interface CompileError extends Error {
|
|
32
|
+
code: string | undefined;
|
|
32
33
|
pos: number | undefined;
|
|
33
34
|
raisedAt: number | undefined;
|
|
34
35
|
end: number | undefined;
|
|
@@ -50,6 +51,11 @@ export interface CompileOptions {
|
|
|
50
51
|
* When true, non-fatal errors are collected on the result's `errors`
|
|
51
52
|
* array instead of being thrown. Defaults to false (strict mode: throws).
|
|
52
53
|
*/
|
|
54
|
+
collect?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Enables editor-oriented parser recovery such as incomplete markup.
|
|
57
|
+
* Also collects non-fatal errors as `collect`.
|
|
58
|
+
*/
|
|
53
59
|
loose?: boolean;
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -1149,6 +1155,7 @@ export interface ParseError {
|
|
|
1149
1155
|
* Parse options
|
|
1150
1156
|
*/
|
|
1151
1157
|
export interface ParseOptions {
|
|
1158
|
+
collect?: boolean;
|
|
1152
1159
|
loose?: boolean;
|
|
1153
1160
|
errors?: CompileError[];
|
|
1154
1161
|
comments?: AST.CommentWithLocation[];
|
|
@@ -1278,7 +1285,7 @@ export interface ScopeConstructorInterface {
|
|
|
1278
1285
|
parent: ScopeInterface | null;
|
|
1279
1286
|
porous: boolean;
|
|
1280
1287
|
error_options: {
|
|
1281
|
-
|
|
1288
|
+
collect: boolean;
|
|
1282
1289
|
errors: CompileError[];
|
|
1283
1290
|
filename: string;
|
|
1284
1291
|
comments?: AST.CommentWithLocation[];
|
|
@@ -1371,7 +1378,7 @@ export interface AnalysisState extends BaseState {
|
|
|
1371
1378
|
};
|
|
1372
1379
|
elements?: AST.Element[];
|
|
1373
1380
|
function_depth?: number;
|
|
1374
|
-
|
|
1381
|
+
collect?: boolean;
|
|
1375
1382
|
configured_compat_kinds?: Set<string>;
|
|
1376
1383
|
metadata: BaseStateMetaData & {
|
|
1377
1384
|
styleClasses?: StyleClasses;
|
|
@@ -1582,7 +1589,7 @@ export interface CompileResult {
|
|
|
1582
1589
|
css: string;
|
|
1583
1590
|
/**
|
|
1584
1591
|
* Non-fatal errors collected during compilation. Populated only when the
|
|
1585
|
-
* caller passes `loose: true`; empty otherwise.
|
|
1592
|
+
* caller passes `collect: true` or `loose: true`; empty otherwise.
|
|
1586
1593
|
*/
|
|
1587
1594
|
errors: CompileError[];
|
|
1588
1595
|
}
|
package/types/jsx-platform.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ export interface JsxTransformContext {
|
|
|
42
42
|
/** Source filename for diagnostics; null when the caller did not supply one. */
|
|
43
43
|
filename: string | null;
|
|
44
44
|
/** True when recoverable errors should be collected onto `errors` instead of thrown. */
|
|
45
|
-
|
|
46
|
-
/** Collected non-fatal errors. Undefined when `
|
|
45
|
+
collect: boolean;
|
|
46
|
+
/** Collected non-fatal errors. Undefined when `collect` is false. */
|
|
47
47
|
errors: CompileError[] | undefined;
|
|
48
48
|
/** Module-level comments used to honor `@tsrx-ignore` / `@tsrx-expect-error`. */
|
|
49
49
|
comments: AST.CommentWithLocation[] | undefined;
|
|
@@ -64,10 +64,14 @@ export interface JsxTransformOptions {
|
|
|
64
64
|
* of thrown so editor tooling can surface them as diagnostics. Errors that
|
|
65
65
|
* leave the transform in an unrecoverable state are still thrown.
|
|
66
66
|
*/
|
|
67
|
+
collect?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Don't collect allowable errors such as unclosed tags
|
|
70
|
+
*/
|
|
67
71
|
loose?: boolean;
|
|
68
72
|
/**
|
|
69
73
|
* Collected non-fatal errors. The transform appends to this array when
|
|
70
|
-
* `loose` is true; callers read it after the transform returns.
|
|
74
|
+
* `collect` or `loose` is true; callers read it after the transform returns.
|
|
71
75
|
*/
|
|
72
76
|
errors?: CompileError[];
|
|
73
77
|
/**
|
package/types/parse.d.ts
CHANGED
|
@@ -183,13 +183,15 @@ export namespace Parse {
|
|
|
183
183
|
|
|
184
184
|
export interface Options extends Omit<acorn.Options, 'onComment' | 'ecmaVersion'> {
|
|
185
185
|
tsrxOptions?: {
|
|
186
|
+
collect: boolean;
|
|
186
187
|
loose: boolean;
|
|
187
|
-
errors: CoreCompiler.CompileError[];
|
|
188
|
+
errors: CoreCompiler.CompileError[] | undefined;
|
|
188
189
|
filename: string | undefined;
|
|
189
190
|
};
|
|
190
191
|
rippleOptions?: {
|
|
192
|
+
collect: boolean;
|
|
191
193
|
loose: boolean;
|
|
192
|
-
errors: CoreCompiler.CompileError[];
|
|
194
|
+
errors: CoreCompiler.CompileError[] | undefined;
|
|
193
195
|
filename: string | undefined;
|
|
194
196
|
};
|
|
195
197
|
// The type has "latest" but it's converted to 1e8 at runtime
|