@tsrx/core 0.1.49 → 0.1.51
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 +10 -1
- package/src/analyze/prune.js +62 -77
- package/src/analyze/validation.js +7 -7
- package/src/parse/index.js +59 -80
- package/src/plugin.js +219 -107
- package/src/runtime/language-helpers.js +34 -25
- package/src/runtime/ref.js +57 -36
- package/src/scope.js +4 -5
- package/src/source-map-utils.js +8 -22
- package/src/transform/imports.js +8 -14
- package/src/transform/jsx/ast-builders.js +4 -1
- package/src/transform/jsx/index.js +1 -13
- package/src/transform/jsx/server-module.js +102 -96
- package/src/transform/jsx-hoist.js +4 -4
- package/src/transform/lazy.js +196 -137
- package/src/transform/scoping.js +108 -100
- package/src/transform/segments.js +24 -49
- package/src/transform/style-ref.js +92 -106
- package/src/transform/stylesheet.js +5 -21
- package/src/utils/ast.js +25 -20
- package/src/utils/builders.js +66 -2
- package/src/vite/dep-scan.js +135 -0
- package/types/index.d.ts +317 -17
- package/types/parse.d.ts +98 -13
- package/types/runtime/language-helpers.d.ts +10 -5
- package/types/runtime/ref.d.ts +63 -14
- package/types/vite/dep-scan.d.ts +26 -0
package/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type * as ESRap from 'esrap';
|
|
|
6
6
|
import type { Position } from 'acorn';
|
|
7
7
|
import type { RequireAllOrNone } from './helpers';
|
|
8
8
|
import type { Context as ZimmerframeContext } from 'zimmerframe';
|
|
9
|
+
import type MagicString from 'magic-string';
|
|
9
10
|
import type {
|
|
10
11
|
JsxPlatform,
|
|
11
12
|
JsxPlatformHooks,
|
|
@@ -41,14 +42,25 @@ export function createStyleClassMap(
|
|
|
41
42
|
css: AST.CSS.StyleSheet,
|
|
42
43
|
): AST.ObjectExpression;
|
|
43
44
|
export function createStyleClassMapFromStylesheet(css: AST.CSS.StyleSheet): AST.ObjectExpression;
|
|
45
|
+
/** How a `style.x` ref attribute is lowered into setup statements. */
|
|
46
|
+
export interface StyleRefOptions {
|
|
47
|
+
allowMutableRefTarget?: boolean;
|
|
48
|
+
createTempIdentifier?: () => AST.Identifier;
|
|
49
|
+
visitExpression?: (expression: AST.Expression) => AST.Expression;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Walk state for the style-expression class-map collection: the nearest
|
|
54
|
+
* prelude-level selector, which carries the class map entries found beneath it.
|
|
55
|
+
*/
|
|
56
|
+
export interface ClassMapCollectionState {
|
|
57
|
+
enclosing_selector: AST.CSS.ComplexSelector | null;
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
export function createStyleRefSetupStatements(
|
|
45
61
|
refAttributes: ESTreeJSX.JSXAttribute[],
|
|
46
62
|
styleMap: AST.Expression,
|
|
47
|
-
options?:
|
|
48
|
-
allowMutableRefTarget?: boolean;
|
|
49
|
-
createTempIdentifier?: () => AST.Identifier;
|
|
50
|
-
visitExpression?: (expression: AST.Expression) => AST.Expression;
|
|
51
|
-
},
|
|
63
|
+
options?: StyleRefOptions,
|
|
52
64
|
): AST.Statement[];
|
|
53
65
|
export function getStyleElementStylesheet(
|
|
54
66
|
styleElement: AST.JSXStyleElement,
|
|
@@ -137,6 +149,8 @@ export interface BaseNodeMetaData {
|
|
|
137
149
|
/** Memoized `<> … </>` wrapper for a value-position directive (see get_directive_value_wrapper). */
|
|
138
150
|
tsrx_value_wrapper?: AST.TSRXJSXFragment;
|
|
139
151
|
ts_name?: string;
|
|
152
|
+
/** Editor hover override served for this node's mapping, if any. */
|
|
153
|
+
hover?: PluginActionOverrides['hover'];
|
|
140
154
|
delegated?: boolean;
|
|
141
155
|
returned_tsrx_return?: AST.ReturnStatement;
|
|
142
156
|
styleScopeHash?: string;
|
|
@@ -157,7 +171,8 @@ export interface BaseNodeMetaData {
|
|
|
157
171
|
generated_loop_skip_if?: boolean;
|
|
158
172
|
lazy_id?: string;
|
|
159
173
|
disable_verification?: boolean;
|
|
160
|
-
|
|
174
|
+
/** Identifiers whose source ranges also map to this generated identifier. */
|
|
175
|
+
extra_source_mappings?: Array<(AST.Identifier | AST.PrivateIdentifier) & AST.NodeWithLocation>;
|
|
161
176
|
generated_setup_declarations?: AST.Statement[];
|
|
162
177
|
/** Helper components lifted out of a component; read back by `expand_component_helpers`. */
|
|
163
178
|
generated_helpers?: AST.Statement[];
|
|
@@ -173,6 +188,17 @@ export interface BaseNodeMetaData {
|
|
|
173
188
|
/** Top-level scoped classes collected while pruning the component's CSS. */
|
|
174
189
|
topScopedClasses?: TopScopedClasses;
|
|
175
190
|
vapor_pending_fallback?: ESTreeJSX.JSXRenderNode;
|
|
191
|
+
/**
|
|
192
|
+
* Solid: control flow that must lower into a reactive `<Show>`/`<For>`/
|
|
193
|
+
* `<Switch>` rather than run once at setup time.
|
|
194
|
+
*/
|
|
195
|
+
solid_render_control?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Solid: a `() => { …; return jsx; }` wrapper built for a branch body that
|
|
198
|
+
* carries setup statements, so the statements run only when the branch
|
|
199
|
+
* renders. Callers place or inline the arrow depending on the slot.
|
|
200
|
+
*/
|
|
201
|
+
is_branch_arrow?: boolean;
|
|
176
202
|
lazy_param_binding_mappings?: Array<{
|
|
177
203
|
source: AST.Identifier;
|
|
178
204
|
generated: AST.Identifier | AST.Literal;
|
|
@@ -201,6 +227,8 @@ type AcornTSNode<T> = Omit<T, 'parent' | 'loc' | 'range' | 'expression'> & {
|
|
|
201
227
|
|
|
202
228
|
leadingComments?: AST.Comment[] | undefined;
|
|
203
229
|
trailingComments?: AST.Comment[] | undefined;
|
|
230
|
+
innerComments?: AST.Comment[] | undefined;
|
|
231
|
+
comments?: AST.Comment[] | undefined;
|
|
204
232
|
append_into?: AST.Identifier;
|
|
205
233
|
};
|
|
206
234
|
|
|
@@ -214,6 +242,12 @@ interface FunctionLikeTS {
|
|
|
214
242
|
declare module 'estree' {
|
|
215
243
|
interface Program {
|
|
216
244
|
innerComments?: Comment[] | undefined;
|
|
245
|
+
/**
|
|
246
|
+
* Lexer-authoritative `async`/`function` keyword spans, recorded when the
|
|
247
|
+
* parse opted in via `keywordTokens`. No AST node carries them, and the
|
|
248
|
+
* mapping collector needs the source positions.
|
|
249
|
+
*/
|
|
250
|
+
tsrx_keyword_tokens?: Parse.KeywordToken[];
|
|
217
251
|
}
|
|
218
252
|
|
|
219
253
|
interface FunctionDeclaration extends FunctionLikeTS {
|
|
@@ -392,6 +426,8 @@ declare module 'estree' {
|
|
|
392
426
|
extends Omit<ESTreeJSX.JSXFragment, 'children'>, AST.NodeWithMaybeComments {
|
|
393
427
|
/** See {@link TSRXJSXElement}'s `children`. */
|
|
394
428
|
children: AST.Node[];
|
|
429
|
+
/** Loose-mode recovery: the fragment was never closed. */
|
|
430
|
+
unclosed?: boolean;
|
|
395
431
|
}
|
|
396
432
|
|
|
397
433
|
interface JSXCodeBlock extends AST.BaseExpression {
|
|
@@ -507,8 +543,15 @@ declare module 'estree' {
|
|
|
507
543
|
| JSXCodeBlock
|
|
508
544
|
| JSXTemplateDirective;
|
|
509
545
|
|
|
546
|
+
/**
|
|
547
|
+
* A native TSRX element, style element, or fragment: what the parser builds
|
|
548
|
+
* from an opening tag and keeps on its open-element path while the body is
|
|
549
|
+
* parsed.
|
|
550
|
+
*/
|
|
551
|
+
type NativeTSRXTemplateNode = TSRXJSXElement | TSRXJSXFragment | JSXStyleElement;
|
|
552
|
+
|
|
510
553
|
/** A parser node whose body uses native TSRX template semantics. */
|
|
511
|
-
type NativeTSRXNode =
|
|
554
|
+
type NativeTSRXNode = NativeTSRXTemplateNode | JSXCodeBlock;
|
|
512
555
|
|
|
513
556
|
interface ParenthesizedExpression extends AST.BaseNode {
|
|
514
557
|
type: 'ParenthesizedExpression';
|
|
@@ -573,15 +616,27 @@ declare module 'estree' {
|
|
|
573
616
|
emptyKeyword?: AST.NodeWithLocation | null;
|
|
574
617
|
}
|
|
575
618
|
|
|
619
|
+
interface VariableDeclaration {
|
|
620
|
+
/** `declare const x` in an ambient context. */
|
|
621
|
+
declare?: boolean;
|
|
622
|
+
}
|
|
623
|
+
|
|
576
624
|
interface ImportDeclaration {
|
|
577
625
|
importKind: TSESTree.ImportDeclaration['importKind'];
|
|
578
626
|
phase?: 'defer' | null;
|
|
627
|
+
/** Pre-`import attributes` spelling of {@link ImportDeclaration.attributes}. */
|
|
628
|
+
assertions?: AST.ImportAttribute[];
|
|
579
629
|
}
|
|
580
630
|
interface TSRXImportDeclaration extends Omit<ImportDeclaration, 'source'> {
|
|
581
631
|
source: AST.Literal | AST.Identifier;
|
|
582
632
|
}
|
|
583
633
|
interface ImportExpression {
|
|
584
634
|
phase?: 'defer' | null;
|
|
635
|
+
/**
|
|
636
|
+
* acorn parks an ordinary `import(source, options)` call's second
|
|
637
|
+
* argument here; only a deferred import fills in `options`.
|
|
638
|
+
*/
|
|
639
|
+
arguments?: AST.Expression[];
|
|
585
640
|
}
|
|
586
641
|
interface ImportSpecifier {
|
|
587
642
|
importKind: TSESTree.ImportSpecifier['importKind'];
|
|
@@ -604,6 +659,8 @@ declare module 'estree' {
|
|
|
604
659
|
|
|
605
660
|
interface BaseNode {
|
|
606
661
|
is_controlled?: boolean;
|
|
662
|
+
/** Comments the parser attached inside the node's own span. */
|
|
663
|
+
innerComments?: Comment[] | undefined;
|
|
607
664
|
// This is for Pattern but it's a type alias
|
|
608
665
|
// So it's just easy to extend BaseNode even though
|
|
609
666
|
// typeAnnotation, typeArguments do not apply to all nodes
|
|
@@ -646,8 +703,23 @@ declare module 'estree' {
|
|
|
646
703
|
|
|
647
704
|
type TSRXStatement = AST.Statement | TSESTree.Statement;
|
|
648
705
|
|
|
706
|
+
/**
|
|
707
|
+
* A TypeScript-only declaration standing in a statement slot. estree's
|
|
708
|
+
* `Statement` union is closed and knows nothing of TS declarations, so nodes
|
|
709
|
+
* the TS parser puts in a body (or the transforms emit into one) are spelled
|
|
710
|
+
* as an intersection with it.
|
|
711
|
+
*/
|
|
712
|
+
type TSStatement<T> = T & AST.Statement;
|
|
713
|
+
|
|
649
714
|
type NodeWithChildren = TSRXJSXElement | TSRXJSXFragment | JSXStyleElement | ESTreeJSX.JSXElement;
|
|
650
715
|
|
|
716
|
+
/**
|
|
717
|
+
* A parsed element node with an opening tag — an ordinary TSRX element or a
|
|
718
|
+
* `<style>` element. Both carry a tag name and attributes, so element-level
|
|
719
|
+
* passes (nesting validation, scoped-CSS pruning) accept either.
|
|
720
|
+
*/
|
|
721
|
+
type TSRXElementNode = TSRXJSXElement | JSXStyleElement;
|
|
722
|
+
|
|
651
723
|
export namespace CSS {
|
|
652
724
|
export interface BaseNode extends AST.NodeWithMaybeComments {
|
|
653
725
|
start: number;
|
|
@@ -704,6 +776,12 @@ declare module 'estree' {
|
|
|
704
776
|
rule: Rule | null;
|
|
705
777
|
used: boolean;
|
|
706
778
|
is_global?: boolean;
|
|
779
|
+
/**
|
|
780
|
+
* The selector carries a class the generated style-expression class
|
|
781
|
+
* map exposes, so render preparation must keep it (see
|
|
782
|
+
* `mark_class_map_selectors`).
|
|
783
|
+
*/
|
|
784
|
+
class_map_selector?: boolean;
|
|
707
785
|
};
|
|
708
786
|
}
|
|
709
787
|
|
|
@@ -909,6 +987,8 @@ declare module 'estree-jsx' {
|
|
|
909
987
|
}
|
|
910
988
|
|
|
911
989
|
interface TSRXJSXClosingElement extends Omit<JSXClosingElement, 'name'> {
|
|
990
|
+
/** The parser marks the closing half of a dynamic `<{expr}>` tag. */
|
|
991
|
+
isDynamic?: boolean;
|
|
912
992
|
// See TSRXJSXOpeningElement's `name`.
|
|
913
993
|
name:
|
|
914
994
|
| JSXMemberExpression
|
|
@@ -1186,14 +1266,16 @@ declare module 'estree' {
|
|
|
1186
1266
|
typeAnnotation: TSTypeAnnotation | undefined;
|
|
1187
1267
|
}
|
|
1188
1268
|
interface TSModuleBlock extends Omit<AcornTSNode<TSESTree.TSModuleBlock>, 'body'> {
|
|
1189
|
-
|
|
1269
|
+
/** A module block is a module scope: imports and exports are allowed. */
|
|
1270
|
+
body: AST.Program['body'];
|
|
1190
1271
|
}
|
|
1191
1272
|
interface TSModuleDeclaration extends Omit<
|
|
1192
1273
|
AcornTSNode<TSESTree.TSModuleDeclaration>,
|
|
1193
1274
|
'body' | 'id'
|
|
1194
1275
|
> {
|
|
1195
1276
|
body: TSModuleBlock;
|
|
1196
|
-
|
|
1277
|
+
/** A string literal for `declare module '<specifier>'`. */
|
|
1278
|
+
id: AST.Identifier | AST.Literal;
|
|
1197
1279
|
metadata: BaseNodeMetaData & {
|
|
1198
1280
|
exports?: Set<string>;
|
|
1199
1281
|
};
|
|
@@ -1434,6 +1516,13 @@ export interface AnalysisResult {
|
|
|
1434
1516
|
ast: AST.Program;
|
|
1435
1517
|
scopes: Map<AST.Node, ScopeInterface>;
|
|
1436
1518
|
scope: ScopeInterface;
|
|
1519
|
+
/** Module-level scope information, kept as the analysis descends. */
|
|
1520
|
+
module: {
|
|
1521
|
+
ast: AST.Program;
|
|
1522
|
+
scope: ScopeInterface;
|
|
1523
|
+
scopes: Map<AST.Node, ScopeInterface>;
|
|
1524
|
+
filename: string;
|
|
1525
|
+
};
|
|
1437
1526
|
component_metadata: Array<{ id: string }>;
|
|
1438
1527
|
metadata: {
|
|
1439
1528
|
serverImportsPresent: boolean;
|
|
@@ -1494,6 +1583,7 @@ export interface Binding {
|
|
|
1494
1583
|
| AST.FunctionDeclaration
|
|
1495
1584
|
| AST.ClassDeclaration
|
|
1496
1585
|
| AST.ImportDeclaration
|
|
1586
|
+
| AST.TSRXImportDeclaration
|
|
1497
1587
|
| AST.TSModuleDeclaration
|
|
1498
1588
|
| ESTreeJSX.JSXFragment;
|
|
1499
1589
|
/** Whether this binding has been reassigned */
|
|
@@ -1593,6 +1683,7 @@ export interface ScopeInterface {
|
|
|
1593
1683
|
| AST.FunctionDeclaration
|
|
1594
1684
|
| AST.ClassDeclaration
|
|
1595
1685
|
| AST.ImportDeclaration
|
|
1686
|
+
| AST.TSRXImportDeclaration
|
|
1596
1687
|
| AST.TSModuleDeclaration
|
|
1597
1688
|
| ESTreeJSX.JSXFragment,
|
|
1598
1689
|
): Binding;
|
|
@@ -1631,14 +1722,7 @@ export interface BaseState {
|
|
|
1631
1722
|
}
|
|
1632
1723
|
|
|
1633
1724
|
export interface AnalysisState extends BaseState {
|
|
1634
|
-
analysis: AnalysisResult
|
|
1635
|
-
module: {
|
|
1636
|
-
ast: AnalysisResult['ast'];
|
|
1637
|
-
scope: AnalysisResult['scope'];
|
|
1638
|
-
scopes: AnalysisResult['scopes'];
|
|
1639
|
-
filename: string;
|
|
1640
|
-
};
|
|
1641
|
-
};
|
|
1725
|
+
analysis: AnalysisResult;
|
|
1642
1726
|
elements?: Array<AST.TSRXJSXElement | AST.JSXStyleElement>;
|
|
1643
1727
|
function_depth?: number;
|
|
1644
1728
|
collect?: boolean;
|
|
@@ -1804,10 +1888,171 @@ export type JsxVisitorContext = ZimmerframeContext<AST.Node, JsxTransformContext
|
|
|
1804
1888
|
/**
|
|
1805
1889
|
* Delegated event result
|
|
1806
1890
|
*/
|
|
1891
|
+
/**
|
|
1892
|
+
* Represents the path of a destructured assignment from either a declaration
|
|
1893
|
+
* or assignment expression. For example, given `const { foo: { bar: baz } } = quux`,
|
|
1894
|
+
* the path of `baz` is `foo.bar`.
|
|
1895
|
+
*/
|
|
1896
|
+
export interface DestructuredAssignment {
|
|
1897
|
+
/**
|
|
1898
|
+
* The node the destructuring path ends in. Can be a member expression only
|
|
1899
|
+
* for assignment expressions.
|
|
1900
|
+
*/
|
|
1901
|
+
node: AST.Identifier | AST.MemberExpression;
|
|
1902
|
+
/** `true` if this is a `...rest` destructuring. */
|
|
1903
|
+
is_rest: boolean;
|
|
1904
|
+
/** `true` if this has a fallback value like `const { foo = 'bar' } = ..`. */
|
|
1905
|
+
has_default_value: boolean;
|
|
1906
|
+
/**
|
|
1907
|
+
* The value of the current path. Will be a call expression if a rest element
|
|
1908
|
+
* or default is involved — e.g. `const { foo: { bar: baz = 42 }, ...rest } =
|
|
1909
|
+
* quux` — since we can't represent `baz` or `rest` purely as a path. Will be
|
|
1910
|
+
* an await expression in case of an async default value
|
|
1911
|
+
* (`const { foo = await bar } = ...`).
|
|
1912
|
+
*/
|
|
1913
|
+
expression: (object: AST.Identifier | AST.CallExpression) => AST.Expression;
|
|
1914
|
+
/** Like `expression` but without default values. */
|
|
1915
|
+
update_expression: (object: AST.Identifier) => AST.Expression;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
/** Render state threaded through the stylesheet printer. */
|
|
1919
|
+
export interface StylesheetRenderState {
|
|
1920
|
+
code: MagicString;
|
|
1921
|
+
hash: string;
|
|
1922
|
+
minify: boolean;
|
|
1923
|
+
selector: string;
|
|
1924
|
+
keyframes: Record<
|
|
1925
|
+
string,
|
|
1926
|
+
{
|
|
1927
|
+
indexes: number[];
|
|
1928
|
+
local: boolean | undefined;
|
|
1929
|
+
}
|
|
1930
|
+
>;
|
|
1931
|
+
specificity: {
|
|
1932
|
+
bumped: boolean;
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
/**
|
|
1937
|
+
* One generated occurrence of a source line's code, as indexed by
|
|
1938
|
+
* `build_src_to_gen_map`.
|
|
1939
|
+
*/
|
|
1940
|
+
export interface CodePosition {
|
|
1941
|
+
line: number;
|
|
1942
|
+
column: number;
|
|
1943
|
+
end_line: number;
|
|
1944
|
+
end_column: number;
|
|
1945
|
+
code: string;
|
|
1946
|
+
metadata: {
|
|
1947
|
+
css?: BaseNodeMetaData['css'];
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
/** A generated position recorded against a source line's column. */
|
|
1952
|
+
export interface SourceLineGeneratedPosition {
|
|
1953
|
+
column: number;
|
|
1954
|
+
position: CodePosition;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
/** Generated positions of each distinct piece of source code, keyed by its text. */
|
|
1958
|
+
export type CodeToGeneratedMap = Map<string, CodePosition[]>;
|
|
1959
|
+
|
|
1960
|
+
/** Source positions of each piece of generated code, keyed by its text. */
|
|
1961
|
+
export type GeneratedToSourceMap = Map<string, Array<{ line: number; column: number }>>;
|
|
1962
|
+
|
|
1963
|
+
/** Generated positions reachable from a source line, keyed by that line. */
|
|
1964
|
+
export type SourceLineGeneratedMap = Map<number, SourceLineGeneratedPosition[]>;
|
|
1965
|
+
|
|
1966
|
+
/** Walk state of `create_scopes`: the scope the current node lives in. */
|
|
1967
|
+
export interface ScopeState {
|
|
1968
|
+
scope: ScopeInterface;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
/** A `<style>` block's source region in the authored file. */
|
|
1972
|
+
export interface CssSourceRegion {
|
|
1973
|
+
start: number;
|
|
1974
|
+
end: number;
|
|
1975
|
+
content: string;
|
|
1976
|
+
id: string;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
/** A `<script>` block's source region in the authored file. */
|
|
1980
|
+
export interface ScriptSourceRegion {
|
|
1981
|
+
start: number;
|
|
1982
|
+
end: number;
|
|
1983
|
+
content: string;
|
|
1984
|
+
id: string;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
/** One source ↔ generated correspondence collected from the printed output. */
|
|
1988
|
+
export interface MappingToken {
|
|
1989
|
+
source: string | null | undefined;
|
|
1990
|
+
generated: string;
|
|
1991
|
+
loc: AST.SourceLocation;
|
|
1992
|
+
metadata: PluginActionOverrides;
|
|
1993
|
+
generatedLoc?: AST.SourceLocation;
|
|
1994
|
+
end_loc?: AST.SourceLocation;
|
|
1995
|
+
sourceLength?: number;
|
|
1996
|
+
mappingData?: Partial<CodeMapping['data']>;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/** A generated identifier's position, resolved against the generated text. */
|
|
2000
|
+
export interface TokenClass {
|
|
2001
|
+
name: string;
|
|
2002
|
+
line: number;
|
|
2003
|
+
column: number;
|
|
2004
|
+
offset: number;
|
|
2005
|
+
length: number;
|
|
2006
|
+
sourceOffset: number;
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
/** Per-element scoped-class info, keyed by the element's generated name. */
|
|
2010
|
+
export type CssElementInfo = Map<string, BaseNodeMetaData['css']>;
|
|
2011
|
+
|
|
1807
2012
|
export interface DelegatedEventResult {
|
|
1808
2013
|
function?: AST.FunctionExpression | AST.FunctionDeclaration | AST.ArrowFunctionExpression;
|
|
1809
2014
|
}
|
|
1810
2015
|
|
|
2016
|
+
/**
|
|
2017
|
+
* Which way the CSS selector matcher walks the element tree: `0` matches the
|
|
2018
|
+
* rest of the selector against descendants/following siblings, `1` against
|
|
2019
|
+
* ancestors/preceding siblings.
|
|
2020
|
+
*/
|
|
2021
|
+
export type CssPruneDirection = 0 | 1;
|
|
2022
|
+
|
|
2023
|
+
/**
|
|
2024
|
+
* Anything a source range can be copied from: a parsed node, or a synthesized
|
|
2025
|
+
* range built for a generated node.
|
|
2026
|
+
*/
|
|
2027
|
+
export interface MaybeLocated {
|
|
2028
|
+
start?: number;
|
|
2029
|
+
end?: number;
|
|
2030
|
+
loc?: AST.SourceLocation | null;
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
/** The lazy destructuring patterns: `&{ … }` and `&[ … ]`. */
|
|
2034
|
+
export type LazyPattern = AST.ObjectPattern | AST.ArrayPattern;
|
|
2035
|
+
|
|
2036
|
+
/** Id allocation state for the lazy destructuring transform. */
|
|
2037
|
+
export interface LazyContext {
|
|
2038
|
+
lazy_next_id: number;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
/** A name introduced by a lazy `&{ … }` / `&[ … ]` destructuring pattern. */
|
|
2042
|
+
export interface LazyBinding {
|
|
2043
|
+
/** The generated identifier the pattern was replaced with (`__lazy0`). */
|
|
2044
|
+
source_name: string;
|
|
2045
|
+
/**
|
|
2046
|
+
* Builds the access that reads this binding off the generated source
|
|
2047
|
+
* identifier (`__lazy0.name`, `__lazy0[1]`). `reference` is the identifier
|
|
2048
|
+
* being rewritten; its source range is carried onto the generated property
|
|
2049
|
+
* so mappings still point at the authored name.
|
|
2050
|
+
*/
|
|
2051
|
+
read: (
|
|
2052
|
+
reference?: AST.Identifier | ESTreeJSX.JSXIdentifier,
|
|
2053
|
+
) => AST.Identifier | AST.MemberExpression;
|
|
2054
|
+
}
|
|
2055
|
+
|
|
1811
2056
|
export type TopScopedClasses = Map<
|
|
1812
2057
|
string,
|
|
1813
2058
|
{
|
|
@@ -1982,6 +2227,61 @@ export type VolarCompileFn<TOptions = ParseOptions> = (
|
|
|
1982
2227
|
options?: TOptions,
|
|
1983
2228
|
) => VolarMappingsResult;
|
|
1984
2229
|
|
|
2230
|
+
/**
|
|
2231
|
+
* The node interface behind a `type` discriminant, preferring the widened TSRX
|
|
2232
|
+
* shapes for the JSX kinds the parser actually produces.
|
|
2233
|
+
*/
|
|
2234
|
+
export type NodeOfType<T extends NodeTypeName> = T extends 'JSXElement'
|
|
2235
|
+
? AST.TSRXJSXElement
|
|
2236
|
+
: T extends 'JSXFragment'
|
|
2237
|
+
? AST.TSRXJSXFragment
|
|
2238
|
+
: Extract<AST.Node, { type: T }>;
|
|
2239
|
+
|
|
2240
|
+
/**
|
|
2241
|
+
* Every node kind's `type` discriminant. TypeScript node types carry an
|
|
2242
|
+
* enum-typed discriminant, so the string form is spelled out alongside it.
|
|
2243
|
+
*/
|
|
2244
|
+
export type NodeTypeName = AST.Node['type'] | `${AST.Node['type']}`;
|
|
2245
|
+
|
|
2246
|
+
/**
|
|
2247
|
+
* The per-target compile entry point the shared compile test-suite runs
|
|
2248
|
+
* against (see `@tsrx/core/test-harness/compile`).
|
|
2249
|
+
*/
|
|
2250
|
+
export interface CompileHarness {
|
|
2251
|
+
compile: CompileFn;
|
|
2252
|
+
/** The target's name, used in test titles. */
|
|
2253
|
+
name: string;
|
|
2254
|
+
/** The authored DOM-element class attribute shape the platform emits. */
|
|
2255
|
+
classAttrName: 'class' | 'className';
|
|
2256
|
+
/**
|
|
2257
|
+
* The class attribute shape the platform uses when injecting scoped CSS
|
|
2258
|
+
* hashes. Defaults to `classAttrName`.
|
|
2259
|
+
*/
|
|
2260
|
+
generatedClassAttrName?: 'class' | 'className';
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
/** The per-target entry points the shared source-mapping tests run against. */
|
|
2264
|
+
export interface SourceMappingHarness {
|
|
2265
|
+
compile: CompileFn;
|
|
2266
|
+
compile_to_volar_mappings: VolarCompileFn;
|
|
2267
|
+
/** The target's name, used in test titles. */
|
|
2268
|
+
name: string;
|
|
2269
|
+
/**
|
|
2270
|
+
* Does the platform refuse top-level `await` in a component body (without
|
|
2271
|
+
* any escape directive)? React and Preact return async functions and accept
|
|
2272
|
+
* it; Solid forbids it outright. When true, the shared `AwaitExpression`
|
|
2273
|
+
* test asserts the compiler throws rather than that it maps successfully.
|
|
2274
|
+
*/
|
|
2275
|
+
rejectsComponentAwait: boolean;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
/** The per-target entry point the shared editor-diagnostics tests run against. */
|
|
2279
|
+
export interface CompileDiagnosticsHarness {
|
|
2280
|
+
compile_to_volar_mappings: VolarCompileFn;
|
|
2281
|
+
/** The target's name, used in test titles. */
|
|
2282
|
+
name: string;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
1985
2285
|
/**
|
|
1986
2286
|
* Source map transformation types
|
|
1987
2287
|
*/
|
package/types/parse.d.ts
CHANGED
|
@@ -35,10 +35,15 @@ declare module 'acorn' {
|
|
|
35
35
|
interface Parser {
|
|
36
36
|
readToken(...args: Parameters<ReadToken>): ReturnType<ReadToken>;
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
interface Token {
|
|
40
|
+
/** The tokenizer records a token's value; acorn's own types omit it. */
|
|
41
|
+
value: string | number | RegExp | bigint | null;
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
declare module 'esrap' {
|
|
41
|
-
export function print<V extends CoreCompiler.Visitors<AST.Node,
|
|
46
|
+
export function print<State, V extends CoreCompiler.Visitors<AST.Node, State>>(
|
|
42
47
|
ast: AST.Node,
|
|
43
48
|
visitors: V,
|
|
44
49
|
options?: ESRap.PrintOptions,
|
|
@@ -46,22 +51,22 @@ declare module 'esrap' {
|
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
declare module 'esrap/languages/tsx' {
|
|
49
|
-
export default function tsx<V extends CoreCompiler.Visitors<AST.Node,
|
|
54
|
+
export default function tsx<State, V extends CoreCompiler.Visitors<AST.Node, State>>(
|
|
50
55
|
options: Parse.ESRapTSOptions,
|
|
51
56
|
): V;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
declare module 'zimmerframe' {
|
|
55
|
-
export function walk(
|
|
60
|
+
export function walk<State>(
|
|
56
61
|
node: AST.Node,
|
|
57
|
-
state:
|
|
58
|
-
visitors: CoreCompiler.Visitors<AST.Node,
|
|
62
|
+
state: NoInfer<State>,
|
|
63
|
+
visitors: CoreCompiler.Visitors<AST.Node, State>,
|
|
59
64
|
): AST.Node;
|
|
60
65
|
|
|
61
|
-
export function walk(
|
|
66
|
+
export function walk<State>(
|
|
62
67
|
node: AST.CSS.Node,
|
|
63
|
-
state:
|
|
64
|
-
visitors: CoreCompiler.Visitors<AST.CSS.Node,
|
|
68
|
+
state: NoInfer<State>,
|
|
69
|
+
visitors: CoreCompiler.Visitors<AST.CSS.Node, State>,
|
|
65
70
|
): AST.CSS.Node;
|
|
66
71
|
}
|
|
67
72
|
|
|
@@ -129,7 +134,7 @@ export namespace Parse {
|
|
|
129
134
|
/** Valid flags for the current ECMAScript version */
|
|
130
135
|
validFlags: string;
|
|
131
136
|
/** Unicode properties data for the current ECMAScript version */
|
|
132
|
-
unicodeProperties:
|
|
137
|
+
unicodeProperties: unknown;
|
|
133
138
|
/** Source pattern string of the regular expression */
|
|
134
139
|
source: string;
|
|
135
140
|
/** Flags string of the regular expression */
|
|
@@ -215,6 +220,35 @@ export namespace Parse {
|
|
|
215
220
|
beforeMeaningfulChild: boolean;
|
|
216
221
|
}
|
|
217
222
|
|
|
223
|
+
/**
|
|
224
|
+
* The slots the parser stamps onto a native template node while it is still
|
|
225
|
+
* being built. The node is started before its opening tag is read, so only
|
|
226
|
+
* then does it learn whether it is an element, a style element, or a fragment;
|
|
227
|
+
* the discriminant and the opening/closing slots are written through this view
|
|
228
|
+
* rather than through the finished node types, which pin the discriminant and
|
|
229
|
+
* require a closing tag.
|
|
230
|
+
*/
|
|
231
|
+
export interface NativeTemplateNodeSlots {
|
|
232
|
+
type: AST.NativeTSRXTemplateNode['type'];
|
|
233
|
+
openingElement?: ESTreeJSX.TSRXJSXOpeningElement;
|
|
234
|
+
closingElement?: ESTreeJSX.TSRXJSXClosingElement | null;
|
|
235
|
+
openingFragment?: ESTreeJSX.JSXOpeningFragment;
|
|
236
|
+
closingFragment?: ESTreeJSX.JSXClosingFragment | null;
|
|
237
|
+
isDynamic?: boolean;
|
|
238
|
+
unclosed?: boolean;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The two fields the parser rewrites when it retypes a parsed control-flow
|
|
243
|
+
* statement as its directive expression form (`IfStatement` ->
|
|
244
|
+
* `JSXIfExpression`, …). Rewriting a discriminant in place has no assignable
|
|
245
|
+
* cast, so the reinterpretation is confined to this shape.
|
|
246
|
+
*/
|
|
247
|
+
export interface JSXControlFlowDirectiveSlots {
|
|
248
|
+
type: AST.JSXTemplateDirective['type'];
|
|
249
|
+
statementType: AST.JSXTemplateDirective['statementType'];
|
|
250
|
+
}
|
|
251
|
+
|
|
218
252
|
/**
|
|
219
253
|
* Token context - controls how tokens are interpreted in different syntactic contexts
|
|
220
254
|
*/
|
|
@@ -1191,6 +1225,19 @@ export namespace Parse {
|
|
|
1191
1225
|
|
|
1192
1226
|
tsParseTypeArguments(): AST.Node;
|
|
1193
1227
|
|
|
1228
|
+
/**
|
|
1229
|
+
* Parse type arguments in an expression position, rescanning the `<` that was
|
|
1230
|
+
* tokenized outside a type context (@sveltejs/acorn-typescript). `undefined`
|
|
1231
|
+
* when the rescan does not yield a `<`.
|
|
1232
|
+
*/
|
|
1233
|
+
tsParseTypeArgumentsInExpression(): AST.TSTypeParameterInstantiation | undefined;
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* Run a parser callback, restoring the tokenizer and returning `undefined`
|
|
1237
|
+
* when it aborts or throws (@sveltejs/acorn-typescript).
|
|
1238
|
+
*/
|
|
1239
|
+
tsTryParseAndCatch<T>(fn: () => T): T | undefined;
|
|
1240
|
+
|
|
1194
1241
|
tsTryParseTypeAnnotation(): AST.TSTypeAnnotation;
|
|
1195
1242
|
|
|
1196
1243
|
/**
|
|
@@ -1719,13 +1766,13 @@ export namespace Parse {
|
|
|
1719
1766
|
* Parse JSX opening element at position
|
|
1720
1767
|
* @param startPos Start position
|
|
1721
1768
|
* @param startLoc Start location
|
|
1722
|
-
* @returns JSXOpeningElement or
|
|
1769
|
+
* @returns JSXOpeningElement (widened to TSRX's dynamic `<{expr}>` name) or,
|
|
1770
|
+
* for `<>`, JSXOpeningFragment
|
|
1723
1771
|
*/
|
|
1724
1772
|
jsx_parseOpeningElementAt(
|
|
1725
1773
|
startPos?: number,
|
|
1726
1774
|
startLoc?: AST.Position,
|
|
1727
|
-
): ESTreeJSX.
|
|
1728
|
-
// it could also be ESTreeJSX.JSXOpeningFragment
|
|
1775
|
+
): ESTreeJSX.TSRXJSXOpeningElement | ESTreeJSX.JSXOpeningFragment;
|
|
1729
1776
|
|
|
1730
1777
|
/**
|
|
1731
1778
|
* Parse JSX closing element at position
|
|
@@ -1771,13 +1818,51 @@ export namespace Parse {
|
|
|
1771
1818
|
error: Error | null;
|
|
1772
1819
|
thrown: boolean;
|
|
1773
1820
|
aborted: boolean;
|
|
1774
|
-
|
|
1821
|
+
/** Opaque tokenizer state snapshot the parser restores on failure. */
|
|
1822
|
+
failState: unknown;
|
|
1775
1823
|
};
|
|
1776
1824
|
parse(input: string, options: Options): AST.Program;
|
|
1777
1825
|
|
|
1778
1826
|
getElementName(node?: AST.Node): string | null;
|
|
1779
1827
|
}
|
|
1780
1828
|
|
|
1829
|
+
/**
|
|
1830
|
+
* An acorn parser plugin: given the parser class built so far, returns a
|
|
1831
|
+
* subclass that overrides the hooks it needs.
|
|
1832
|
+
*/
|
|
1833
|
+
export type AcornPlugin = (BaseParser: ParserConstructor) => ParserConstructor;
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* Options accepted by a parse function built with `createParser`. Everything
|
|
1837
|
+
* beyond `filename` is opt-in behaviour of the compile pipeline.
|
|
1838
|
+
*/
|
|
1839
|
+
export interface ParseFunctionOptions {
|
|
1840
|
+
/** Collect non-fatal errors instead of throwing. */
|
|
1841
|
+
collect?: boolean;
|
|
1842
|
+
/** Loose (error-recovering) parse; implies `collect`. */
|
|
1843
|
+
loose?: boolean;
|
|
1844
|
+
/** Destination for collected errors when `collect`/`loose` is set. */
|
|
1845
|
+
errors?: CoreCompiler.CompileError[];
|
|
1846
|
+
/** Destination for the comments collected during the parse. */
|
|
1847
|
+
comments?: AST.CommentWithLocation[];
|
|
1848
|
+
/** Keep `ParenthesizedExpression` nodes in the output. */
|
|
1849
|
+
preserveParens?: boolean;
|
|
1850
|
+
/**
|
|
1851
|
+
* Record the source spans of `async`/`function` keywords on the program as
|
|
1852
|
+
* `tsrx_keyword_tokens` — the mapping collector needs them and no AST node
|
|
1853
|
+
* carries them.
|
|
1854
|
+
*/
|
|
1855
|
+
keywordTokens?: boolean;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
/** A keyword span recorded by the `keywordTokens` parse option. */
|
|
1859
|
+
export interface KeywordToken {
|
|
1860
|
+
value: string;
|
|
1861
|
+
start: number;
|
|
1862
|
+
end: number;
|
|
1863
|
+
loc: AST.SourceLocation;
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1781
1866
|
/**
|
|
1782
1867
|
* The constructor/class type for the extended TSRX parser.
|
|
1783
1868
|
* This represents the static side of the parser class after extending with plugins.
|
|
@@ -14,12 +14,17 @@ export const array_prototype: typeof Array.prototype;
|
|
|
14
14
|
export const has_own_property: typeof Object.prototype.hasOwnProperty;
|
|
15
15
|
|
|
16
16
|
export function has_prototype_accessor(value: object, key: PropertyKey): boolean;
|
|
17
|
-
export function array_slice(array_like: ArrayLike<
|
|
17
|
+
export function array_slice<T>(array_like: ArrayLike<T>, ...args: number[]): T[];
|
|
18
18
|
export function iterable_array_from<T>(
|
|
19
19
|
iterable: Iterable<T> | Iterator<T> | ArrayLike<T>,
|
|
20
20
|
index?: number,
|
|
21
21
|
): T[];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The props bag minus one prop. Constrained to `object` rather than an index
|
|
24
|
+
* signature so an interface- or class-typed props bag is accepted; returns `{}`
|
|
25
|
+
* when `props` is nullish.
|
|
26
|
+
*/
|
|
27
|
+
export function exclude_prop_from_object<
|
|
28
|
+
T extends object = Record<PropertyKey, unknown>,
|
|
29
|
+
K extends PropertyKey = PropertyKey,
|
|
30
|
+
>(props: T | null | undefined, exclude_prop: K): Omit<T, K>;
|