ripple 0.2.184 → 0.2.185
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/compiler/phases/2-analyze/index.js +5 -0
- package/src/compiler/phases/3-transform/client/index.js +181 -131
- package/src/compiler/phases/3-transform/server/index.js +135 -45
- package/src/compiler/types/index.d.ts +89 -63
- package/src/compiler/types/parse.d.ts +30 -0
- package/src/runtime/index-server.js +10 -27
- package/src/runtime/internal/client/operations.js +1 -1
- package/src/runtime/internal/client/runtime.js +8 -8
- package/src/runtime/internal/client/types.d.ts +5 -5
- package/src/runtime/internal/server/index.js +268 -17
- package/src/runtime/internal/server/types.d.ts +19 -11
- package/tests/client/switch.test.ripple +73 -23
- package/tests/server/basic.test.ripple +119 -0
- package/tests/server/composite.test.ripple +1 -1
- package/tests/server/context.test.ripple +31 -0
- package/tests/server/switch.test.ripple +21 -0
|
@@ -16,6 +16,7 @@ import { walk } from 'zimmerframe';
|
|
|
16
16
|
import ts from 'esrap/languages/ts';
|
|
17
17
|
import path from 'node:path';
|
|
18
18
|
import { print } from 'esrap';
|
|
19
|
+
import is_reference from 'is-reference';
|
|
19
20
|
import {
|
|
20
21
|
determine_namespace_for_children,
|
|
21
22
|
escape_html,
|
|
@@ -30,17 +31,6 @@ import { is_event_attribute } from '../../../../utils/events.js';
|
|
|
30
31
|
import { render_stylesheets } from '../stylesheet.js';
|
|
31
32
|
import { createHash } from 'node:crypto';
|
|
32
33
|
|
|
33
|
-
/**
|
|
34
|
-
* @param {TransformServerContext} context
|
|
35
|
-
*/
|
|
36
|
-
function add_ripple_internal_import(context) {
|
|
37
|
-
if (!context.state.to_ts) {
|
|
38
|
-
if (!context.state.imports.has(`import * as _$_ from 'ripple/internal/server'`)) {
|
|
39
|
-
context.state.imports.add(`import * as _$_ from 'ripple/internal/server'`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
34
|
/**
|
|
45
35
|
* @param {AST.Node[]} children
|
|
46
36
|
* @param {TransformServerContext} context
|
|
@@ -110,8 +100,31 @@ const visitors = {
|
|
|
110
100
|
}
|
|
111
101
|
},
|
|
112
102
|
|
|
103
|
+
Identifier(node, context) {
|
|
104
|
+
const parent = /** @type {AST.Node} */ (context.path.at(-1));
|
|
105
|
+
|
|
106
|
+
if (is_reference(node, parent) && node.tracked) {
|
|
107
|
+
const is_right_side_of_assignment =
|
|
108
|
+
parent.type === 'AssignmentExpression' && parent.right === node;
|
|
109
|
+
if (
|
|
110
|
+
(parent.type !== 'AssignmentExpression' && parent.type !== 'UpdateExpression') ||
|
|
111
|
+
is_right_side_of_assignment
|
|
112
|
+
) {
|
|
113
|
+
return b.call('_$_.get', node);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
113
118
|
Component(node, context) {
|
|
114
|
-
|
|
119
|
+
if (node.params.length > 0) {
|
|
120
|
+
let props_param = node.params[0];
|
|
121
|
+
|
|
122
|
+
if (props_param.type === 'Identifier') {
|
|
123
|
+
delete props_param.typeAnnotation;
|
|
124
|
+
} else if (props_param.type === 'ObjectPattern') {
|
|
125
|
+
delete props_param.typeAnnotation;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
115
128
|
|
|
116
129
|
const metadata = { await: false };
|
|
117
130
|
const body_statements = [
|
|
@@ -608,23 +621,32 @@ const visitors = {
|
|
|
608
621
|
if (!is_inside_component(context)) {
|
|
609
622
|
return context.next();
|
|
610
623
|
}
|
|
624
|
+
|
|
611
625
|
const cases = [];
|
|
626
|
+
|
|
612
627
|
for (const switch_case of node.cases) {
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
628
|
+
const case_body = [];
|
|
629
|
+
|
|
630
|
+
if (switch_case.consequent.length !== 0) {
|
|
631
|
+
const consequent_scope =
|
|
632
|
+
context.state.scopes.get(switch_case.consequent) || context.state.scope;
|
|
633
|
+
const consequent = b.block(
|
|
634
|
+
transform_body(switch_case.consequent, {
|
|
635
|
+
...context,
|
|
636
|
+
state: { ...context.state, scope: consequent_scope },
|
|
637
|
+
}),
|
|
638
|
+
);
|
|
639
|
+
case_body.push(...consequent.body);
|
|
640
|
+
}
|
|
641
|
+
|
|
621
642
|
cases.push(
|
|
622
643
|
b.switch_case(
|
|
623
644
|
switch_case.test ? /** @type {AST.Expression} */ (context.visit(switch_case.test)) : null,
|
|
624
|
-
|
|
645
|
+
case_body,
|
|
625
646
|
),
|
|
626
647
|
);
|
|
627
648
|
}
|
|
649
|
+
|
|
628
650
|
context.state.init?.push(
|
|
629
651
|
b.switch(/** @type {AST.Expression} */ (context.visit(node.discriminant)), cases),
|
|
630
652
|
);
|
|
@@ -698,17 +720,91 @@ const visitors = {
|
|
|
698
720
|
AssignmentExpression(node, context) {
|
|
699
721
|
const left = node.left;
|
|
700
722
|
|
|
723
|
+
if (
|
|
724
|
+
left.type === 'MemberExpression' &&
|
|
725
|
+
(left.tracked || (left.property.type === 'Identifier' && left.property.tracked))
|
|
726
|
+
) {
|
|
727
|
+
const operator = node.operator;
|
|
728
|
+
const right = node.right;
|
|
729
|
+
|
|
730
|
+
return b.call(
|
|
731
|
+
'_$_.set_property',
|
|
732
|
+
/** @type {AST.Expression} */ (context.visit(left.object)),
|
|
733
|
+
left.computed
|
|
734
|
+
? /** @type {AST.Expression} */ (context.visit(left.property))
|
|
735
|
+
: b.literal(/** @type {AST.Identifier} */ (left.property).name),
|
|
736
|
+
operator === '='
|
|
737
|
+
? /** @type {AST.Expression} */ (context.visit(right))
|
|
738
|
+
: b.binary(
|
|
739
|
+
operator === '+=' ? '+' : operator === '-=' ? '-' : operator === '*=' ? '*' : '/',
|
|
740
|
+
b.call(
|
|
741
|
+
'_$_.get_property',
|
|
742
|
+
/** @type {AST.Expression} */ (context.visit(left.object)),
|
|
743
|
+
left.computed
|
|
744
|
+
? /** @type {AST.Expression} */ (context.visit(left.property))
|
|
745
|
+
: b.literal(/** @type {AST.Identifier} */ (left.property).name),
|
|
746
|
+
undefined,
|
|
747
|
+
),
|
|
748
|
+
/** @type {AST.Expression} */ (context.visit(right)),
|
|
749
|
+
),
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
|
|
701
753
|
if (left.type === 'Identifier' && left.tracked) {
|
|
754
|
+
const operator = node.operator;
|
|
755
|
+
const right = node.right;
|
|
756
|
+
|
|
757
|
+
return b.call(
|
|
758
|
+
'_$_.set',
|
|
759
|
+
/** @type {AST.Expression} */ (context.visit(left)),
|
|
760
|
+
operator === '='
|
|
761
|
+
? /** @type {AST.Expression} */ (context.visit(right))
|
|
762
|
+
: b.binary(
|
|
763
|
+
operator === '+=' ? '+' : operator === '-=' ? '-' : operator === '*=' ? '*' : '/',
|
|
764
|
+
b.call('_$_.get', left),
|
|
765
|
+
/** @type {AST.Expression} */ (context.visit(right)),
|
|
766
|
+
),
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return context.next();
|
|
771
|
+
},
|
|
772
|
+
|
|
773
|
+
UpdateExpression(node, context) {
|
|
774
|
+
const argument = node.argument;
|
|
775
|
+
|
|
776
|
+
if (
|
|
777
|
+
argument.type === 'MemberExpression' &&
|
|
778
|
+
(argument.tracked || (argument.property.type === 'Identifier' && argument.property.tracked))
|
|
779
|
+
) {
|
|
702
780
|
return b.call(
|
|
703
|
-
'
|
|
781
|
+
node.prefix ? '_$_.update_pre_property' : '_$_.update_property',
|
|
704
782
|
/** @type {AST.Expression} */
|
|
705
|
-
(context.visit(
|
|
783
|
+
(context.visit(argument.object, { ...context.state, metadata: { tracking: false } })),
|
|
784
|
+
argument.computed
|
|
785
|
+
? /** @type {AST.Expression} */ (context.visit(argument.property))
|
|
786
|
+
: b.literal(/** @type {AST.Identifier} */ (argument.property).name),
|
|
787
|
+
node.operator === '--' ? b.literal(-1) : undefined,
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
if (argument.type === 'Identifier' && argument.tracked) {
|
|
792
|
+
return b.call(
|
|
793
|
+
node.prefix ? '_$_.update_pre' : '_$_.update',
|
|
706
794
|
/** @type {AST.Expression} */
|
|
707
|
-
(context.visit(
|
|
795
|
+
(context.visit(argument)),
|
|
796
|
+
node.operator === '--' ? b.literal(-1) : undefined,
|
|
708
797
|
);
|
|
709
798
|
}
|
|
710
799
|
|
|
711
|
-
|
|
800
|
+
if (argument.type === 'TrackedExpression') {
|
|
801
|
+
return b.call(
|
|
802
|
+
node.prefix ? '_$_.update_pre' : '_$_.update',
|
|
803
|
+
/** @type {AST.Expression} */
|
|
804
|
+
(context.visit(argument.argument)),
|
|
805
|
+
node.operator === '--' ? b.literal(-1) : undefined,
|
|
806
|
+
);
|
|
807
|
+
}
|
|
712
808
|
},
|
|
713
809
|
|
|
714
810
|
ServerIdentifier(node, context) {
|
|
@@ -832,6 +928,10 @@ const visitors = {
|
|
|
832
928
|
return b.await(/** @type {AST.AwaitExpression} */ (context.visit(node.argument)));
|
|
833
929
|
},
|
|
834
930
|
|
|
931
|
+
TrackedExpression(node, context) {
|
|
932
|
+
return b.call('_$_.get', /** @type {AST.Expression} */ (context.visit(node.argument)));
|
|
933
|
+
},
|
|
934
|
+
|
|
835
935
|
TrackedObjectExpression(node, context) {
|
|
836
936
|
// For SSR, we just evaluate the object as-is since there's no reactivity
|
|
837
937
|
return b.object(
|
|
@@ -852,20 +952,14 @@ const visitors = {
|
|
|
852
952
|
},
|
|
853
953
|
|
|
854
954
|
MemberExpression(node, context) {
|
|
855
|
-
const parent = context.path.at(-1);
|
|
856
|
-
|
|
857
955
|
if (node.tracked || (node.property.type === 'Identifier' && node.property.tracked)) {
|
|
858
956
|
return b.call(
|
|
859
|
-
'
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
(context.visit(node.
|
|
863
|
-
node.
|
|
864
|
-
|
|
865
|
-
: node.property,
|
|
866
|
-
node.computed,
|
|
867
|
-
node.optional,
|
|
868
|
-
),
|
|
957
|
+
'_$_.get_property',
|
|
958
|
+
/** @type {AST.Expression} */ (context.visit(node.object)),
|
|
959
|
+
node.computed
|
|
960
|
+
? /** @type {AST.Expression} */ (context.visit(node.property))
|
|
961
|
+
: b.literal(/** @type {AST.Identifier} */ (node.property).name),
|
|
962
|
+
node.optional ? b.true : undefined,
|
|
869
963
|
);
|
|
870
964
|
}
|
|
871
965
|
|
|
@@ -877,7 +971,7 @@ const visitors = {
|
|
|
877
971
|
let expression = /** @type {AST.Expression} */ (visit(node.expression, { ...state, metadata }));
|
|
878
972
|
|
|
879
973
|
if (expression.type === 'Identifier' && expression.tracked) {
|
|
880
|
-
expression = b.call('get', expression);
|
|
974
|
+
expression = b.call('_$_.get', expression);
|
|
881
975
|
}
|
|
882
976
|
|
|
883
977
|
if (expression.type === 'Literal') {
|
|
@@ -975,6 +1069,8 @@ export function transform_server(filename, source, analysis, minify_css) {
|
|
|
975
1069
|
metadata: {},
|
|
976
1070
|
};
|
|
977
1071
|
|
|
1072
|
+
state.imports.add(`import * as _$_ from 'ripple/internal/server'`);
|
|
1073
|
+
|
|
978
1074
|
const program = walk(analysis.ast, { ...state }, visitors);
|
|
979
1075
|
|
|
980
1076
|
const css = render_stylesheets(state.stylesheets, minify_css);
|
|
@@ -993,17 +1089,11 @@ export function transform_server(filename, source, analysis, minify_css) {
|
|
|
993
1089
|
}
|
|
994
1090
|
|
|
995
1091
|
// Add async property to component functions
|
|
996
|
-
|
|
997
1092
|
for (const import_node of state.imports) {
|
|
998
1093
|
/** @type {AST.Program} */ (program).body.unshift(b.stmt(b.id(import_node)));
|
|
999
1094
|
}
|
|
1000
1095
|
|
|
1001
|
-
|
|
1002
|
-
// Our types from 'estree' are incompatible
|
|
1003
|
-
// So we'll just give it what it wants with an unknown cast.
|
|
1004
|
-
// Functionally, none of the properties that are different between the two types
|
|
1005
|
-
// are used by the printer, so this is safe.
|
|
1006
|
-
const js = print(/** @type {TSESTree.Node} */ (/** @type {unknown} */ (program)), ts(), {
|
|
1096
|
+
const js = print(program, /** @type {Visitors<AST.Node, TransformServerState>} */ (ts()), {
|
|
1007
1097
|
sourceMapContent: source,
|
|
1008
1098
|
sourceMapSource: path.basename(filename),
|
|
1009
1099
|
});
|
|
@@ -3,6 +3,7 @@ import type * as ESTreeJSX from 'estree-jsx';
|
|
|
3
3
|
import type { TSESTree } from '@typescript-eslint/types';
|
|
4
4
|
import type { NAMESPACE_URI } from '../../runtime/internal/client/constants.js';
|
|
5
5
|
import type { Parse } from '#parser';
|
|
6
|
+
import type * as ESRap from 'esrap';
|
|
6
7
|
|
|
7
8
|
export type RpcModules = Map<string, [string, string]>;
|
|
8
9
|
|
|
@@ -61,13 +62,29 @@ declare module 'estree' {
|
|
|
61
62
|
metadata: FunctionMetaData;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
interface MethodDefinition {
|
|
66
|
+
typeParameters?: TSTypeParameterDeclaration;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface ClassDeclaration {
|
|
70
|
+
typeParameters?: AST.TSTypeParameterDeclaration;
|
|
71
|
+
superTypeArguments?: AST.TSTypeParameterInstantiation;
|
|
72
|
+
implements?: AST.TSClassImplements[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface ClassExpression {
|
|
76
|
+
typeParameters?: AST.TSTypeParameterDeclaration;
|
|
77
|
+
superTypeArguments?: AST.TSTypeParameterInstantiation;
|
|
78
|
+
implements?: AST.TSClassImplements[];
|
|
79
|
+
}
|
|
80
|
+
|
|
64
81
|
interface Identifier extends TrackedNode {
|
|
65
82
|
metadata: BaseNode['metadata'] & {
|
|
66
83
|
tracked_shorthand?: '#Map' | '#Set';
|
|
67
84
|
};
|
|
68
85
|
}
|
|
69
86
|
|
|
70
|
-
interface MemberExpression extends TrackedNode {}
|
|
87
|
+
interface MemberExpression extends AST.TrackedNode {}
|
|
71
88
|
|
|
72
89
|
interface TrackedNode {
|
|
73
90
|
tracked?: boolean;
|
|
@@ -99,9 +116,9 @@ declare module 'estree' {
|
|
|
99
116
|
}
|
|
100
117
|
|
|
101
118
|
// Missing estree type
|
|
102
|
-
interface ParenthesizedExpression extends BaseNode {
|
|
119
|
+
interface ParenthesizedExpression extends AST.BaseNode {
|
|
103
120
|
type: 'ParenthesizedExpression';
|
|
104
|
-
expression: Expression;
|
|
121
|
+
expression: AST.Expression;
|
|
105
122
|
}
|
|
106
123
|
|
|
107
124
|
interface Comment {
|
|
@@ -111,18 +128,18 @@ declare module 'estree' {
|
|
|
111
128
|
/**
|
|
112
129
|
* Custom Comment interface with location information
|
|
113
130
|
*/
|
|
114
|
-
type CommentWithLocation = Comment & NodeWithLocation;
|
|
131
|
+
type CommentWithLocation = AST.Comment & NodeWithLocation;
|
|
115
132
|
|
|
116
133
|
interface TryStatement {
|
|
117
|
-
pending?: BlockStatement | null;
|
|
134
|
+
pending?: AST.BlockStatement | null;
|
|
118
135
|
}
|
|
119
136
|
|
|
120
137
|
interface ForOfStatement {
|
|
121
|
-
index?: Identifier | null;
|
|
122
|
-
key?: Expression | null;
|
|
138
|
+
index?: AST.Identifier | null;
|
|
139
|
+
key?: AST.Expression | null;
|
|
123
140
|
}
|
|
124
141
|
|
|
125
|
-
interface ServerIdentifier extends BaseNode {
|
|
142
|
+
interface ServerIdentifier extends AST.BaseNode {
|
|
126
143
|
type: 'ServerIdentifier';
|
|
127
144
|
}
|
|
128
145
|
|
|
@@ -160,24 +177,24 @@ declare module 'estree' {
|
|
|
160
177
|
// to avoid lots of typecasting or checking for undefined
|
|
161
178
|
metadata: BaseNodeMetaData;
|
|
162
179
|
|
|
163
|
-
comments?:
|
|
180
|
+
comments?: Comment[];
|
|
164
181
|
}
|
|
165
182
|
|
|
166
183
|
interface NodeWithLocation {
|
|
167
184
|
start: number;
|
|
168
185
|
end: number;
|
|
169
|
-
loc: SourceLocation;
|
|
186
|
+
loc: AST.SourceLocation;
|
|
170
187
|
}
|
|
171
188
|
|
|
172
189
|
/**
|
|
173
190
|
* Ripple custom interfaces and types section
|
|
174
191
|
*/
|
|
175
|
-
interface Component extends BaseNode {
|
|
192
|
+
interface Component extends AST.BaseNode {
|
|
176
193
|
type: 'Component';
|
|
177
194
|
// null is for anonymous components {component: () => {}}
|
|
178
|
-
id: Identifier | null;
|
|
179
|
-
params: Pattern[];
|
|
180
|
-
body: Node[];
|
|
195
|
+
id: AST.Identifier | null;
|
|
196
|
+
params: AST.Pattern[];
|
|
197
|
+
body: AST.Node[];
|
|
181
198
|
css: CSS.StyleSheet | null;
|
|
182
199
|
metadata: BaseNodeMetaData & {
|
|
183
200
|
inherited_css?: boolean;
|
|
@@ -185,7 +202,7 @@ declare module 'estree' {
|
|
|
185
202
|
default: boolean;
|
|
186
203
|
}
|
|
187
204
|
|
|
188
|
-
interface TsxCompat extends BaseNode {
|
|
205
|
+
interface TsxCompat extends AST.BaseNode {
|
|
189
206
|
type: 'TsxCompat';
|
|
190
207
|
kind: string;
|
|
191
208
|
attributes: Array<any>;
|
|
@@ -194,19 +211,19 @@ declare module 'estree' {
|
|
|
194
211
|
unclosed?: boolean;
|
|
195
212
|
}
|
|
196
213
|
|
|
197
|
-
interface Html extends BaseNode {
|
|
214
|
+
interface Html extends AST.BaseNode {
|
|
198
215
|
type: 'Html';
|
|
199
216
|
expression: Expression;
|
|
200
217
|
}
|
|
201
218
|
|
|
202
|
-
interface Element extends BaseNode {
|
|
219
|
+
interface Element extends AST.BaseNode {
|
|
203
220
|
type: 'Element';
|
|
204
|
-
id: Identifier;
|
|
221
|
+
id: AST.Identifier;
|
|
205
222
|
attributes: RippleAttribute[];
|
|
206
|
-
children: Node[];
|
|
223
|
+
children: AST.Node[];
|
|
207
224
|
selfClosing?: boolean;
|
|
208
225
|
unclosed?: boolean;
|
|
209
|
-
loc:
|
|
226
|
+
loc: SourceLocation;
|
|
210
227
|
metadata: BaseNodeMetaData & {
|
|
211
228
|
ts_name?: string;
|
|
212
229
|
};
|
|
@@ -226,11 +243,11 @@ declare module 'estree' {
|
|
|
226
243
|
|
|
227
244
|
export interface TextNode extends AST.BaseNode {
|
|
228
245
|
type: 'Text';
|
|
229
|
-
expression: Expression;
|
|
230
|
-
loc?: SourceLocation;
|
|
246
|
+
expression: AST.Expression;
|
|
247
|
+
loc?: AST.SourceLocation;
|
|
231
248
|
}
|
|
232
249
|
|
|
233
|
-
interface ServerBlock extends BaseNode {
|
|
250
|
+
interface ServerBlock extends AST.BaseNode {
|
|
234
251
|
type: 'ServerBlock';
|
|
235
252
|
body: BlockStatement;
|
|
236
253
|
metadata: BaseNodeMetaData & {
|
|
@@ -241,62 +258,62 @@ declare module 'estree' {
|
|
|
241
258
|
/**
|
|
242
259
|
* Tracked Expressions
|
|
243
260
|
*/
|
|
244
|
-
interface TrackedArrayExpression extends Omit<ArrayExpression, 'type'> {
|
|
261
|
+
interface TrackedArrayExpression extends Omit<AST.ArrayExpression, 'type'> {
|
|
245
262
|
type: 'TrackedArrayExpression';
|
|
246
|
-
elements: (Expression | SpreadElement | null)[];
|
|
263
|
+
elements: (AST.Expression | AST.SpreadElement | null)[];
|
|
247
264
|
}
|
|
248
265
|
|
|
249
|
-
interface TrackedExpression extends BaseNode {
|
|
250
|
-
argument: Expression;
|
|
266
|
+
interface TrackedExpression extends AST.BaseNode {
|
|
267
|
+
argument: AST.Expression;
|
|
251
268
|
type: 'TrackedExpression';
|
|
252
269
|
}
|
|
253
270
|
|
|
254
|
-
interface TrackedObjectExpression extends Omit<ObjectExpression, 'type'> {
|
|
271
|
+
interface TrackedObjectExpression extends Omit<AST.ObjectExpression, 'type'> {
|
|
255
272
|
type: 'TrackedObjectExpression';
|
|
256
|
-
properties: (Property | SpreadElement)[];
|
|
273
|
+
properties: (AST.Property | AST.SpreadElement)[];
|
|
257
274
|
}
|
|
258
275
|
|
|
259
|
-
interface TrackedMapExpression extends BaseNode {
|
|
276
|
+
interface TrackedMapExpression extends AST.BaseNode {
|
|
260
277
|
type: 'TrackedMapExpression';
|
|
261
|
-
arguments: (Expression | SpreadElement)[];
|
|
278
|
+
arguments: (AST.Expression | AST.SpreadElement)[];
|
|
262
279
|
}
|
|
263
280
|
|
|
264
|
-
interface TrackedSetExpression extends BaseNode {
|
|
281
|
+
interface TrackedSetExpression extends AST.BaseNode {
|
|
265
282
|
type: 'TrackedSetExpression';
|
|
266
|
-
arguments: (Expression | SpreadElement)[];
|
|
283
|
+
arguments: (AST.Expression | AST.SpreadElement)[];
|
|
267
284
|
}
|
|
268
285
|
|
|
269
286
|
/**
|
|
270
287
|
* Ripple attribute nodes
|
|
271
288
|
*/
|
|
272
|
-
interface Attribute extends BaseNode {
|
|
289
|
+
interface Attribute extends AST.BaseNode {
|
|
273
290
|
type: 'Attribute';
|
|
274
|
-
name: Identifier;
|
|
275
|
-
value: Expression | null;
|
|
276
|
-
loc?: SourceLocation;
|
|
291
|
+
name: AST.Identifier;
|
|
292
|
+
value: AST.Expression | null;
|
|
293
|
+
loc?: AST.SourceLocation;
|
|
277
294
|
shorthand?: boolean;
|
|
278
295
|
metadata: BaseNodeMetaData & {
|
|
279
296
|
delegated?: boolean;
|
|
280
297
|
};
|
|
281
298
|
}
|
|
282
299
|
|
|
283
|
-
interface RefAttribute extends BaseNode {
|
|
300
|
+
interface RefAttribute extends AST.BaseNode {
|
|
284
301
|
type: 'RefAttribute';
|
|
285
|
-
argument: Expression;
|
|
286
|
-
loc?: SourceLocation;
|
|
302
|
+
argument: AST.Expression;
|
|
303
|
+
loc?: AST.SourceLocation;
|
|
287
304
|
}
|
|
288
305
|
|
|
289
|
-
interface SpreadAttribute extends BaseNode {
|
|
306
|
+
interface SpreadAttribute extends AST.BaseNode {
|
|
290
307
|
type: 'SpreadAttribute';
|
|
291
|
-
argument: Expression;
|
|
292
|
-
loc?: SourceLocation;
|
|
308
|
+
argument: AST.Expression;
|
|
309
|
+
loc?: AST.SourceLocation;
|
|
293
310
|
}
|
|
294
311
|
|
|
295
312
|
/**
|
|
296
313
|
* Ripple's extended Declaration type that includes Component
|
|
297
|
-
* Use this instead of
|
|
314
|
+
* Use this instead of Declaration when you need Component support
|
|
298
315
|
*/
|
|
299
|
-
export type RippleDeclaration = AST.Declaration |
|
|
316
|
+
export type RippleDeclaration = AST.Declaration | Component | AST.TSDeclareFunction;
|
|
300
317
|
|
|
301
318
|
/**
|
|
302
319
|
* Ripple's extended ExportNamedDeclaration with Component support
|
|
@@ -308,8 +325,8 @@ declare module 'estree' {
|
|
|
308
325
|
/**
|
|
309
326
|
* Ripple's extended Program with Component support
|
|
310
327
|
*/
|
|
311
|
-
interface RippleProgram extends Omit<
|
|
312
|
-
body: (
|
|
328
|
+
interface RippleProgram extends Omit<Program, 'body'> {
|
|
329
|
+
body: (Program['body'][number] | Component)[];
|
|
313
330
|
}
|
|
314
331
|
|
|
315
332
|
export type RippleAttribute = Attribute | SpreadAttribute | RefAttribute;
|
|
@@ -491,7 +508,7 @@ declare module 'estree-jsx' {
|
|
|
491
508
|
|
|
492
509
|
interface JSXEmptyExpression {
|
|
493
510
|
loc: AST.SourceLocation;
|
|
494
|
-
innerComments?: Comment[];
|
|
511
|
+
innerComments?: AST.Comment[];
|
|
495
512
|
}
|
|
496
513
|
|
|
497
514
|
interface JSXOpeningFragment {
|
|
@@ -586,20 +603,24 @@ declare module 'estree' {
|
|
|
586
603
|
TSVoidKeyword: TSVoidKeyword;
|
|
587
604
|
TSParenthesizedType: TSParenthesizedType;
|
|
588
605
|
TSExpressionWithTypeArguments: TSExpressionWithTypeArguments;
|
|
606
|
+
TSClassImplements: TSClassImplements;
|
|
589
607
|
}
|
|
590
608
|
|
|
591
|
-
// Extend NodeMap to include TypeScript nodes
|
|
592
|
-
interface NodeMap extends TSNodeMap {}
|
|
593
|
-
|
|
594
609
|
// Create our version of TypeNode with modified types to be used in replacements
|
|
595
610
|
type TypeNode = TSNodeMap[keyof TSNodeMap];
|
|
611
|
+
|
|
612
|
+
// Extend NodeMap to include TypeScript nodes
|
|
613
|
+
interface NodeMap extends TSNodeMap {
|
|
614
|
+
TypeNode: TypeNode;
|
|
615
|
+
}
|
|
616
|
+
|
|
596
617
|
type EntityName = AST.Identifier | AST.ThisExpression | TSQualifiedName;
|
|
597
618
|
type Parameter =
|
|
598
|
-
| ArrayPattern
|
|
599
|
-
| AssignmentPattern
|
|
600
|
-
| Identifier
|
|
601
|
-
| ObjectPattern
|
|
602
|
-
| RestElement
|
|
619
|
+
| AST.ArrayPattern
|
|
620
|
+
| AST.AssignmentPattern
|
|
621
|
+
| AST.Identifier
|
|
622
|
+
| AST.ObjectPattern
|
|
623
|
+
| AST.RestElement
|
|
603
624
|
| TSParameterProperty;
|
|
604
625
|
type TypeElement =
|
|
605
626
|
| TSCallSignatureDeclaration
|
|
@@ -608,8 +629,8 @@ declare module 'estree' {
|
|
|
608
629
|
| TSMethodSignature
|
|
609
630
|
| TSPropertySignature;
|
|
610
631
|
type TSPropertySignature = TSPropertySignatureComputedName | TSPropertySignatureNonComputedName;
|
|
611
|
-
type PropertyNameComputed = Expression;
|
|
612
|
-
type PropertyNameNonComputed = Identifier | NumberLiteral | StringLiteral;
|
|
632
|
+
type PropertyNameComputed = AST.Expression;
|
|
633
|
+
type PropertyNameNonComputed = AST.Identifier | NumberLiteral | StringLiteral;
|
|
613
634
|
|
|
614
635
|
// TypeScript AST node interfaces from @sveltejs/acorn-typescript
|
|
615
636
|
// Based on TSESTree types but adapted for acorn's output format
|
|
@@ -646,7 +667,7 @@ declare module 'estree' {
|
|
|
646
667
|
extends Omit<AcornTSNode<TSESTree.TSConstructorType>, 'typeParameters' | 'params'> {
|
|
647
668
|
typeAnnotation: TSTypeAnnotation | undefined;
|
|
648
669
|
typeParameters: TSTypeParameterDeclaration | undefined;
|
|
649
|
-
parameters: Parameter[];
|
|
670
|
+
parameters: AST.Parameter[];
|
|
650
671
|
}
|
|
651
672
|
interface TSConstructSignatureDeclaration
|
|
652
673
|
extends Omit<
|
|
@@ -705,7 +726,7 @@ declare module 'estree' {
|
|
|
705
726
|
}
|
|
706
727
|
interface TSIndexSignature
|
|
707
728
|
extends Omit<AcornTSNode<TSESTree.TSIndexSignature>, 'parameters' | 'typeAnnotation'> {
|
|
708
|
-
parameters: Parameter[];
|
|
729
|
+
parameters: AST.Parameter[];
|
|
709
730
|
typeAnnotation: TSTypeAnnotation | undefined;
|
|
710
731
|
}
|
|
711
732
|
interface TSInferType extends Omit<AcornTSNode<TSESTree.TSInferType>, 'typeParameter'> {
|
|
@@ -735,9 +756,13 @@ declare module 'estree' {
|
|
|
735
756
|
literal: AST.Literal | AST.TemplateLiteral;
|
|
736
757
|
}
|
|
737
758
|
interface TSMappedType
|
|
738
|
-
extends Omit<
|
|
759
|
+
extends Omit<
|
|
760
|
+
AcornTSNode<TSESTree.TSMappedType>,
|
|
761
|
+
'typeParameter' | 'typeAnnotation' | 'nameType'
|
|
762
|
+
> {
|
|
739
763
|
typeAnnotation: TypeNode | undefined;
|
|
740
764
|
typeParameter: TSTypeParameter;
|
|
765
|
+
nameType: TypeNode | null;
|
|
741
766
|
}
|
|
742
767
|
interface TSMethodSignature
|
|
743
768
|
extends Omit<
|
|
@@ -870,6 +895,7 @@ declare module 'estree' {
|
|
|
870
895
|
type: 'TSExpressionWithTypeArguments';
|
|
871
896
|
}
|
|
872
897
|
|
|
898
|
+
interface TSClassImplements extends AcornTSNode<TSESTree.TSClassImplements> {}
|
|
873
899
|
interface TSUnknownKeyword extends AcornTSNode<TSESTree.TSUnknownKeyword> {}
|
|
874
900
|
interface TSVoidKeyword extends AcornTSNode<TSESTree.TSVoidKeyword> {}
|
|
875
901
|
interface NumberLiteral extends AcornTSNode<TSESTree.NumberLiteral> {}
|
|
@@ -891,7 +917,6 @@ declare module 'estree' {
|
|
|
891
917
|
}
|
|
892
918
|
|
|
893
919
|
import type { Comment, Position } from 'acorn';
|
|
894
|
-
import type { A, M } from 'vitest/dist/chunks/environment.d.cL3nLXbE.js';
|
|
895
920
|
|
|
896
921
|
/**
|
|
897
922
|
* Parse error information
|
|
@@ -1134,7 +1159,8 @@ export type Visitors<T extends AST.Node | AST.CSS.Node, U> = T['type'] extends '
|
|
|
1134
1159
|
? never
|
|
1135
1160
|
: SpecializedVisitors<T, U> & { _?: Visitor<T, U, T> };
|
|
1136
1161
|
|
|
1137
|
-
export interface Context<T, U>
|
|
1162
|
+
export interface Context<T, U>
|
|
1163
|
+
extends Omit<ESRap.Context, 'path' | 'state' | 'visit' | 'next' | 'stop'> {
|
|
1138
1164
|
next: (state?: U) => T | void;
|
|
1139
1165
|
path: T[];
|
|
1140
1166
|
state: U;
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
import type * as acorn from 'acorn';
|
|
14
14
|
import type * as AST from 'estree';
|
|
15
15
|
import type * as ESTreeJSX from 'estree-jsx';
|
|
16
|
+
import type * as ESRap from 'esrap';
|
|
17
|
+
import type * as SourceMap from '@jridgewell/sourcemap-codec';
|
|
18
|
+
import type * as RippleCompiler from '#compiler';
|
|
16
19
|
|
|
17
20
|
type ForInit = boolean | 'await';
|
|
18
21
|
|
|
@@ -33,7 +36,34 @@ declare module 'acorn' {
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
declare module 'esrap' {
|
|
40
|
+
export function print<V extends RippleCompiler.Visitors<AST.Node, any>>(
|
|
41
|
+
ast: AST.Node,
|
|
42
|
+
visitors: V,
|
|
43
|
+
options?: ESRap.PrintOptions,
|
|
44
|
+
): { code: string; map: SourceMap.SourceMapMappings };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare module 'esrap/languages/tsx' {
|
|
48
|
+
export default function tsx<V extends RippleCompiler.Visitors<AST.Node, any>>(
|
|
49
|
+
options: Parse.ESRapTSOptions,
|
|
50
|
+
): V;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare module 'zimmerframe' {
|
|
54
|
+
export function walk(
|
|
55
|
+
node: AST.Node,
|
|
56
|
+
state: any,
|
|
57
|
+
visitors: RippleCompiler.Visitors<AST.Node, any>,
|
|
58
|
+
): AST.Node;
|
|
59
|
+
}
|
|
60
|
+
|
|
36
61
|
export namespace Parse {
|
|
62
|
+
export interface ESRapTSOptions {
|
|
63
|
+
quotes?: 'double' | 'single';
|
|
64
|
+
comments?: AST.Comment[];
|
|
65
|
+
}
|
|
66
|
+
|
|
37
67
|
/**
|
|
38
68
|
* Destructuring errors object used during expression parsing
|
|
39
69
|
* See: https://github.com/acornjs/acorn/blob/main/acorn/src/parseutil.js
|