ripple 0.2.182 → 0.2.184
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 +4 -2
- package/src/compiler/errors.js +3 -1
- package/src/compiler/index.d.ts +2 -1
- package/src/compiler/phases/1-parse/index.js +525 -311
- package/src/compiler/phases/1-parse/style.js +3 -1
- package/src/compiler/phases/2-analyze/css-analyze.js +116 -97
- package/src/compiler/phases/2-analyze/index.js +81 -51
- package/src/compiler/phases/2-analyze/prune.js +200 -58
- package/src/compiler/phases/2-analyze/validation.js +9 -7
- package/src/compiler/phases/3-transform/client/index.js +871 -394
- package/src/compiler/phases/3-transform/segments.js +99 -53
- package/src/compiler/phases/3-transform/server/index.js +278 -121
- package/src/compiler/scope.js +51 -104
- package/src/compiler/types/index.d.ts +834 -197
- package/src/compiler/types/parse.d.ts +1668 -0
- package/src/compiler/utils.js +62 -74
- package/src/utils/ast.js +247 -192
- package/src/utils/builders.js +309 -247
- package/src/utils/sanitize_template_string.js +2 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
@import { CustomMappingData, PluginActionOverrides } from 'ripple/compiler';
|
|
3
|
+
@import { DocumentHighlightKind } from 'vscode-languageserver-types';
|
|
4
|
+
@import * as AST from 'estree';
|
|
5
|
+
@import * as ESTreeJSX from 'estree-jsx';
|
|
6
|
+
@import {MappingData, CodeMapping, VolarMappingsResult} from 'ripple/compiler';
|
|
7
|
+
@import {CodeMapping as VolarCodeMapping} from '@volar/language-core';
|
|
8
|
+
*/
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
|
-
* @typedef {import('estree').Position} Position
|
|
6
|
-
* @typedef {{start: Position, end: Position}} Location
|
|
7
|
-
* @typedef {import('@volar/language-core').CodeMapping} VolarCodeMapping
|
|
8
|
-
* @typedef {import('ripple/compiler').MappingData} MappingData
|
|
9
|
-
* @typedef {import('ripple/compiler').CodeMapping} CodeMapping
|
|
10
|
-
* @typedef {import('ripple/compiler').VolarMappingsResult} VolarMappingsResult
|
|
11
11
|
* @typedef {{
|
|
12
12
|
* start: number,
|
|
13
13
|
* end: number,
|
|
@@ -61,7 +61,7 @@ function loc_to_offset(line, column, line_offsets) {
|
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Extract CSS source regions from style elements in the AST
|
|
64
|
-
* @param {
|
|
64
|
+
* @param {AST.Node} ast - The parsed AST
|
|
65
65
|
* @param {string} source - Original source code
|
|
66
66
|
* @param {number[]} source_line_offsets
|
|
67
67
|
* @returns {CssSourceRegion[]}
|
|
@@ -74,13 +74,19 @@ function extractCssSourceRegions(ast, source, source_line_offsets) {
|
|
|
74
74
|
Element(node) {
|
|
75
75
|
// Check if this is a style element with CSS content
|
|
76
76
|
if (node.id?.name === 'style' && node.css) {
|
|
77
|
-
const openLoc =
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const openLoc = /** @type {ESTreeJSX.JSXOpeningElement & AST.NodeWithLocation} */ (
|
|
78
|
+
node.openingElement
|
|
79
|
+
).loc;
|
|
80
|
+
const cssStart = loc_to_offset(openLoc.end.line, openLoc.end.column, source_line_offsets);
|
|
80
81
|
|
|
81
|
-
const closeLoc =
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const closeLoc = /** @type {ESTreeJSX.JSXClosingElement & AST.NodeWithLocation} */ (
|
|
83
|
+
node.closingElement
|
|
84
|
+
).loc;
|
|
85
|
+
const cssEnd = loc_to_offset(
|
|
86
|
+
closeLoc.start.line,
|
|
87
|
+
closeLoc.start.column,
|
|
88
|
+
source_line_offsets,
|
|
89
|
+
);
|
|
84
90
|
|
|
85
91
|
regions.push({
|
|
86
92
|
start: cssStart,
|
|
@@ -100,8 +106,8 @@ function extractCssSourceRegions(ast, source, source_line_offsets) {
|
|
|
100
106
|
|
|
101
107
|
/**
|
|
102
108
|
* Create Volar mappings by walking the transformed AST
|
|
103
|
-
* @param {
|
|
104
|
-
* @param {
|
|
109
|
+
* @param {AST.Node} ast - The transformed AST
|
|
110
|
+
* @param {AST.Node} ast_from_source - The original AST from source
|
|
105
111
|
* @param {string} source - Original source code
|
|
106
112
|
* @param {string} generated_code - Generated code (returned in output, not used for searching)
|
|
107
113
|
* @param {object} esrap_source_map - Esrap source map for accurate position lookup
|
|
@@ -145,17 +151,18 @@ export function convert_source_map_to_mappings(
|
|
|
145
151
|
// All tokens must have source/generated text and loc property for accurate positioning
|
|
146
152
|
/**
|
|
147
153
|
* @type {Array<{
|
|
148
|
-
* source: string,
|
|
154
|
+
* source: string | null | undefined,
|
|
149
155
|
* generated: string,
|
|
150
156
|
* is_full_import_statement?: boolean,
|
|
151
|
-
* loc:
|
|
152
|
-
* end_loc?:
|
|
157
|
+
* loc: AST.SourceLocation,
|
|
158
|
+
* end_loc?: AST.SourceLocation,
|
|
153
159
|
* metadata?: PluginActionOverrides
|
|
154
160
|
* }>}
|
|
155
161
|
*/
|
|
156
162
|
const tokens = [];
|
|
157
163
|
|
|
158
164
|
// We have to visit everything in generated order to maintain correct indices
|
|
165
|
+
|
|
159
166
|
walk(ast, null, {
|
|
160
167
|
_(node, { visit }) {
|
|
161
168
|
// Collect key node types: Identifiers, Literals, and JSX Elements
|
|
@@ -229,7 +236,11 @@ export function convert_source_map_to_mappings(
|
|
|
229
236
|
} else if (node.type === 'ImportSpecifier') {
|
|
230
237
|
// If local and imported are the same, only visit local to avoid duplicates
|
|
231
238
|
// Otherwise visit both in order
|
|
232
|
-
if (
|
|
239
|
+
if (
|
|
240
|
+
node.imported &&
|
|
241
|
+
node.local &&
|
|
242
|
+
/** @type {AST.Identifier} */ (node.imported).name !== node.local.name
|
|
243
|
+
) {
|
|
233
244
|
visit(node.imported);
|
|
234
245
|
visit(node.local);
|
|
235
246
|
} else if (node.local) {
|
|
@@ -248,7 +259,12 @@ export function convert_source_map_to_mappings(
|
|
|
248
259
|
} else if (node.type === 'ExportSpecifier') {
|
|
249
260
|
// If local and exported are the same, only visit local to avoid duplicates
|
|
250
261
|
// Otherwise visit both in order
|
|
251
|
-
if (
|
|
262
|
+
if (
|
|
263
|
+
node.local &&
|
|
264
|
+
node.exported &&
|
|
265
|
+
/** @type {AST.Identifier} */ (node.local).name !==
|
|
266
|
+
/** @type {AST.Identifier} */ (node.exported).name
|
|
267
|
+
) {
|
|
252
268
|
visit(node.local);
|
|
253
269
|
visit(node.exported);
|
|
254
270
|
} else if (node.local) {
|
|
@@ -269,7 +285,7 @@ export function convert_source_map_to_mappings(
|
|
|
269
285
|
} else if (node.type === 'ExportDefaultDeclaration') {
|
|
270
286
|
// Visit the declaration
|
|
271
287
|
if (node.declaration) {
|
|
272
|
-
visit(node.declaration);
|
|
288
|
+
visit(/** @type {AST.Node} */ (node.declaration));
|
|
273
289
|
}
|
|
274
290
|
return;
|
|
275
291
|
} else if (node.type === 'ExportAllDeclaration') {
|
|
@@ -355,7 +371,7 @@ export function convert_source_map_to_mappings(
|
|
|
355
371
|
// 2. Visit children in order
|
|
356
372
|
if (node.children) {
|
|
357
373
|
for (const child of node.children) {
|
|
358
|
-
visit(child);
|
|
374
|
+
visit(/** @type {AST.Node} */ (child));
|
|
359
375
|
}
|
|
360
376
|
}
|
|
361
377
|
|
|
@@ -364,7 +380,9 @@ export function convert_source_map_to_mappings(
|
|
|
364
380
|
!node.openingElement?.selfClosing &&
|
|
365
381
|
node.closingElement?.name?.type === 'JSXIdentifier'
|
|
366
382
|
) {
|
|
367
|
-
const closingNameNode =
|
|
383
|
+
const closingNameNode = /** @type {ESTreeJSX.JSXIdentifier & AST.NodeWithLocation} */ (
|
|
384
|
+
node.closingElement.name
|
|
385
|
+
);
|
|
368
386
|
if (closingNameNode.metadata?.is_capitalized) {
|
|
369
387
|
tokens.push({
|
|
370
388
|
source: closingNameNode.metadata.original_name,
|
|
@@ -388,24 +406,25 @@ export function convert_source_map_to_mappings(
|
|
|
388
406
|
) {
|
|
389
407
|
// Add function/component keyword token
|
|
390
408
|
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
|
|
409
|
+
const node_fn = /** @type (typeof node) & AST.NodeWithLocation */ (node);
|
|
391
410
|
const source_keyword = node.metadata?.was_component ? 'component' : 'function';
|
|
392
411
|
// Add token for the keyword - esrap already mapped it via context.write('function', node)
|
|
393
412
|
tokens.push({
|
|
394
413
|
source: source_keyword,
|
|
395
414
|
generated: 'function',
|
|
396
415
|
loc: {
|
|
397
|
-
start: { line:
|
|
416
|
+
start: { line: node_fn.loc.start.line, column: node_fn.loc.start.column },
|
|
398
417
|
end: {
|
|
399
|
-
line:
|
|
400
|
-
column:
|
|
418
|
+
line: node_fn.loc.start.line,
|
|
419
|
+
column: node_fn.loc.start.column + source_keyword.length,
|
|
401
420
|
},
|
|
402
421
|
},
|
|
403
422
|
});
|
|
404
423
|
}
|
|
405
424
|
|
|
406
425
|
// Visit in source order: id, params, body
|
|
407
|
-
if (node.id) {
|
|
408
|
-
visit(node.id);
|
|
426
|
+
if (/** @type {AST.FunctionDeclaration | AST.FunctionExpression} */ (node).id) {
|
|
427
|
+
visit(/** @type {AST.FunctionDeclaration | AST.FunctionExpression} */ (node).id);
|
|
409
428
|
}
|
|
410
429
|
if (node.params) {
|
|
411
430
|
for (const param of node.params) {
|
|
@@ -476,8 +495,8 @@ export function convert_source_map_to_mappings(
|
|
|
476
495
|
visit(node.right);
|
|
477
496
|
}
|
|
478
497
|
// Ripple-specific: index variable
|
|
479
|
-
if (node.index) {
|
|
480
|
-
visit(node.index);
|
|
498
|
+
if (/** @type {AST.ForOfStatement} */ (node).index) {
|
|
499
|
+
visit(/** @type {AST.ForOfStatement} */ (node).index);
|
|
481
500
|
}
|
|
482
501
|
if (node.body) {
|
|
483
502
|
visit(node.body);
|
|
@@ -509,14 +528,17 @@ export function convert_source_map_to_mappings(
|
|
|
509
528
|
if (node.pending) {
|
|
510
529
|
// Add a special token for the 'pending' keyword with customData
|
|
511
530
|
// to suppress TypeScript diagnostics and provide custom hover/definition
|
|
531
|
+
const pending = /** @type {(typeof node.pending) & AST.NodeWithLocation} */ (
|
|
532
|
+
node.pending
|
|
533
|
+
);
|
|
512
534
|
const pendingKeywordLoc = {
|
|
513
535
|
start: {
|
|
514
|
-
line:
|
|
515
|
-
column:
|
|
536
|
+
line: pending.loc.start.line,
|
|
537
|
+
column: pending.loc.start.column - 'pending '.length,
|
|
516
538
|
},
|
|
517
539
|
end: {
|
|
518
|
-
line:
|
|
519
|
-
column:
|
|
540
|
+
line: pending.loc.start.line,
|
|
541
|
+
column: pending.loc.start.column - 1,
|
|
520
542
|
},
|
|
521
543
|
};
|
|
522
544
|
tokens.push({
|
|
@@ -762,8 +784,8 @@ export function convert_source_map_to_mappings(
|
|
|
762
784
|
if (node.argument) {
|
|
763
785
|
visit(node.argument);
|
|
764
786
|
// Visit type annotation if present (for RestElement)
|
|
765
|
-
if (node.argument.typeAnnotation) {
|
|
766
|
-
visit(node.argument.typeAnnotation);
|
|
787
|
+
if (/** @type {AST.Pattern} */ (node.argument).typeAnnotation) {
|
|
788
|
+
visit(/** @type {AST.Pattern} */ (node.argument).typeAnnotation);
|
|
767
789
|
}
|
|
768
790
|
}
|
|
769
791
|
// RestElement itself can have typeAnnotation
|
|
@@ -826,7 +848,7 @@ export function convert_source_map_to_mappings(
|
|
|
826
848
|
// Visit children in order
|
|
827
849
|
if (node.children) {
|
|
828
850
|
for (const child of node.children) {
|
|
829
|
-
visit(child);
|
|
851
|
+
visit(/** @type {AST.Node} */ (child));
|
|
830
852
|
}
|
|
831
853
|
}
|
|
832
854
|
return;
|
|
@@ -954,10 +976,11 @@ export function convert_source_map_to_mappings(
|
|
|
954
976
|
if (node.typeName) {
|
|
955
977
|
visit(node.typeName);
|
|
956
978
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
979
|
+
|
|
980
|
+
// typeParameters and typeArguments (different parsers use different names)
|
|
981
|
+
// tsTypeParameters is a bug in the estree-typescript
|
|
982
|
+
// but we fixed in the analyzer to typeArguments.
|
|
983
|
+
|
|
961
984
|
if (node.typeArguments) {
|
|
962
985
|
visit(node.typeArguments);
|
|
963
986
|
}
|
|
@@ -1002,8 +1025,13 @@ export function convert_source_map_to_mappings(
|
|
|
1002
1025
|
for (const param of node.parameters) {
|
|
1003
1026
|
visit(param);
|
|
1004
1027
|
// Visit type annotation on the parameter
|
|
1005
|
-
if (
|
|
1006
|
-
|
|
1028
|
+
if (
|
|
1029
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param).typeAnnotation
|
|
1030
|
+
) {
|
|
1031
|
+
visit(
|
|
1032
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param)
|
|
1033
|
+
.typeAnnotation,
|
|
1034
|
+
);
|
|
1007
1035
|
}
|
|
1008
1036
|
}
|
|
1009
1037
|
}
|
|
@@ -1040,8 +1068,13 @@ export function convert_source_map_to_mappings(
|
|
|
1040
1068
|
for (const param of node.parameters) {
|
|
1041
1069
|
visit(param);
|
|
1042
1070
|
// Visit type annotation on the parameter
|
|
1043
|
-
if (
|
|
1044
|
-
|
|
1071
|
+
if (
|
|
1072
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param).typeAnnotation
|
|
1073
|
+
) {
|
|
1074
|
+
visit(
|
|
1075
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param)
|
|
1076
|
+
.typeAnnotation,
|
|
1077
|
+
);
|
|
1045
1078
|
}
|
|
1046
1079
|
}
|
|
1047
1080
|
}
|
|
@@ -1055,8 +1088,13 @@ export function convert_source_map_to_mappings(
|
|
|
1055
1088
|
for (const param of node.parameters) {
|
|
1056
1089
|
visit(param);
|
|
1057
1090
|
// Visit type annotation on the parameter
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1091
|
+
if (
|
|
1092
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param).typeAnnotation
|
|
1093
|
+
) {
|
|
1094
|
+
visit(
|
|
1095
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param)
|
|
1096
|
+
.typeAnnotation,
|
|
1097
|
+
);
|
|
1060
1098
|
}
|
|
1061
1099
|
}
|
|
1062
1100
|
}
|
|
@@ -1076,8 +1114,13 @@ export function convert_source_map_to_mappings(
|
|
|
1076
1114
|
for (const param of node.parameters) {
|
|
1077
1115
|
visit(param);
|
|
1078
1116
|
// Visit type annotation on the parameter
|
|
1079
|
-
if (
|
|
1080
|
-
|
|
1117
|
+
if (
|
|
1118
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param).typeAnnotation
|
|
1119
|
+
) {
|
|
1120
|
+
visit(
|
|
1121
|
+
/** @type {Exclude<AST.Parameter, AST.TSParameterProperty>} */ (param)
|
|
1122
|
+
.typeAnnotation,
|
|
1123
|
+
);
|
|
1081
1124
|
}
|
|
1082
1125
|
}
|
|
1083
1126
|
}
|
|
@@ -1168,6 +1211,9 @@ export function convert_source_map_to_mappings(
|
|
|
1168
1211
|
if (node.exprName) {
|
|
1169
1212
|
visit(node.exprName);
|
|
1170
1213
|
}
|
|
1214
|
+
if (node.typeArguments) {
|
|
1215
|
+
visit(node.typeArguments);
|
|
1216
|
+
}
|
|
1171
1217
|
return;
|
|
1172
1218
|
} else if (node.type === 'TSInterfaceDeclaration') {
|
|
1173
1219
|
// Interface declaration
|
|
@@ -1325,7 +1371,7 @@ export function convert_source_map_to_mappings(
|
|
|
1325
1371
|
});
|
|
1326
1372
|
|
|
1327
1373
|
for (const token of tokens) {
|
|
1328
|
-
const source_text = token.source;
|
|
1374
|
+
const source_text = token.source ?? '';
|
|
1329
1375
|
const gen_text = token.generated;
|
|
1330
1376
|
|
|
1331
1377
|
const source_start = loc_to_offset(
|
|
@@ -1342,7 +1388,7 @@ export function convert_source_map_to_mappings(
|
|
|
1342
1388
|
let gen_start;
|
|
1343
1389
|
|
|
1344
1390
|
if (token.is_full_import_statement) {
|
|
1345
|
-
const end_loc = /** @type {
|
|
1391
|
+
const end_loc = /** @type {AST.SourceLocation} */ (token.end_loc).end;
|
|
1346
1392
|
const source_end = loc_to_offset(end_loc.line, end_loc.column, source_line_offsets);
|
|
1347
1393
|
|
|
1348
1394
|
// Look up where import keyword and source literal map to in generated code
|