@glint/ember-tsc 1.6.0 → 1.6.1
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 +1 -0
- package/lib/cli/run-volar-tsc.d.ts +2 -0
- package/lib/cli/run-volar-tsc.d.ts.map +1 -0
- package/lib/cli/run-volar-tsc.js +32 -0
- package/lib/cli/run-volar-tsc.js.map +1 -0
- package/lib/config/config.d.ts +15 -0
- package/lib/config/config.d.ts.map +1 -0
- package/lib/config/config.js +21 -0
- package/lib/config/config.js.map +1 -0
- package/lib/config/environment.d.ts +26 -0
- package/lib/config/environment.d.ts.map +1 -0
- package/lib/config/environment.js +96 -0
- package/lib/config/environment.js.map +1 -0
- package/lib/config/index.d.ts +24 -0
- package/lib/config/index.d.ts.map +1 -0
- package/lib/config/index.js +37 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/loader.d.ts +28 -0
- package/lib/config/loader.d.ts.map +1 -0
- package/lib/config/loader.js +121 -0
- package/lib/config/loader.js.map +1 -0
- package/lib/config/types.cjs +3 -0
- package/lib/config/types.cjs.map +1 -0
- package/lib/config/types.d.cts +60 -0
- package/lib/config/types.d.cts.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/common.d.ts +13 -0
- package/lib/environment-ember-template-imports/-private/environment/common.d.ts.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/common.js +2 -0
- package/lib/environment-ember-template-imports/-private/environment/common.js.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/index.d.ts +3 -0
- package/lib/environment-ember-template-imports/-private/environment/index.d.ts.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/index.js +102 -0
- package/lib/environment-ember-template-imports/-private/environment/index.js.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/preprocess.d.ts +4 -0
- package/lib/environment-ember-template-imports/-private/environment/preprocess.d.ts.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/preprocess.js +42 -0
- package/lib/environment-ember-template-imports/-private/environment/preprocess.js.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/transform.d.ts +4 -0
- package/lib/environment-ember-template-imports/-private/environment/transform.d.ts.map +1 -0
- package/lib/environment-ember-template-imports/-private/environment/transform.js +134 -0
- package/lib/environment-ember-template-imports/-private/environment/transform.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/plugins/g-compiler-errors.d.ts +12 -0
- package/lib/plugins/g-compiler-errors.d.ts.map +1 -0
- package/lib/plugins/g-compiler-errors.js +58 -0
- package/lib/plugins/g-compiler-errors.js.map +1 -0
- package/lib/plugins/g-component-hover.d.ts +24 -0
- package/lib/plugins/g-component-hover.d.ts.map +1 -0
- package/lib/plugins/g-component-hover.js +135 -0
- package/lib/plugins/g-component-hover.js.map +1 -0
- package/lib/plugins/g-template-tag-symbols.d.ts +11 -0
- package/lib/plugins/g-template-tag-symbols.d.ts.map +1 -0
- package/lib/plugins/g-template-tag-symbols.js +48 -0
- package/lib/plugins/g-template-tag-symbols.js.map +1 -0
- package/lib/plugins/utils.d.ts +25 -0
- package/lib/plugins/utils.d.ts.map +1 -0
- package/lib/plugins/utils.js +63 -0
- package/lib/plugins/utils.js.map +1 -0
- package/lib/transform/diagnostics/augmentation.d.ts +4 -0
- package/lib/transform/diagnostics/augmentation.d.ts.map +1 -0
- package/lib/transform/diagnostics/augmentation.js +249 -0
- package/lib/transform/diagnostics/augmentation.js.map +1 -0
- package/lib/transform/diagnostics/index.d.ts +5 -0
- package/lib/transform/diagnostics/index.d.ts.map +1 -0
- package/lib/transform/diagnostics/index.js +2 -0
- package/lib/transform/diagnostics/index.js.map +1 -0
- package/lib/transform/index.d.ts +4 -0
- package/lib/transform/index.d.ts.map +1 -0
- package/lib/transform/index.js +2 -0
- package/lib/transform/index.js.map +1 -0
- package/lib/transform/template/code-features.d.ts +30 -0
- package/lib/transform/template/code-features.d.ts.map +1 -0
- package/lib/transform/template/code-features.js +26 -0
- package/lib/transform/template/code-features.js.map +1 -0
- package/lib/transform/template/glimmer-ast-mapping-tree.d.ts +80 -0
- package/lib/transform/template/glimmer-ast-mapping-tree.d.ts.map +1 -0
- package/lib/transform/template/glimmer-ast-mapping-tree.js +132 -0
- package/lib/transform/template/glimmer-ast-mapping-tree.js.map +1 -0
- package/lib/transform/template/inlining/index.d.ts +16 -0
- package/lib/transform/template/inlining/index.d.ts.map +1 -0
- package/lib/transform/template/inlining/index.js +21 -0
- package/lib/transform/template/inlining/index.js.map +1 -0
- package/lib/transform/template/inlining/tagged-strings.d.ts +8 -0
- package/lib/transform/template/inlining/tagged-strings.d.ts.map +1 -0
- package/lib/transform/template/inlining/tagged-strings.js +140 -0
- package/lib/transform/template/inlining/tagged-strings.js.map +1 -0
- package/lib/transform/template/map-template-contents.d.ts +121 -0
- package/lib/transform/template/map-template-contents.d.ts.map +1 -0
- package/lib/transform/template/map-template-contents.js +287 -0
- package/lib/transform/template/map-template-contents.js.map +1 -0
- package/lib/transform/template/rewrite-module.d.ts +22 -0
- package/lib/transform/template/rewrite-module.d.ts.map +1 -0
- package/lib/transform/template/rewrite-module.js +265 -0
- package/lib/transform/template/rewrite-module.js.map +1 -0
- package/lib/transform/template/scope-stack.d.ts +13 -0
- package/lib/transform/template/scope-stack.d.ts.map +1 -0
- package/lib/transform/template/scope-stack.js +28 -0
- package/lib/transform/template/scope-stack.js.map +1 -0
- package/lib/transform/template/template-to-typescript.d.ts +19 -0
- package/lib/transform/template/template-to-typescript.d.ts.map +1 -0
- package/lib/transform/template/template-to-typescript.js +1125 -0
- package/lib/transform/template/template-to-typescript.js.map +1 -0
- package/lib/transform/template/transformed-module.d.ts +111 -0
- package/lib/transform/template/transformed-module.d.ts.map +1 -0
- package/lib/transform/template/transformed-module.js +287 -0
- package/lib/transform/template/transformed-module.js.map +1 -0
- package/lib/transform/util.d.ts +7 -0
- package/lib/transform/util.d.ts.map +1 -0
- package/lib/transform/util.js +15 -0
- package/lib/transform/util.js.map +1 -0
- package/lib/volar/ember-language-plugin.d.ts +14 -0
- package/lib/volar/ember-language-plugin.d.ts.map +1 -0
- package/lib/volar/ember-language-plugin.js +91 -0
- package/lib/volar/ember-language-plugin.js.map +1 -0
- package/lib/volar/gts-virtual-code.d.ts +83 -0
- package/lib/volar/gts-virtual-code.d.ts.map +1 -0
- package/lib/volar/gts-virtual-code.js +210 -0
- package/lib/volar/gts-virtual-code.js.map +1 -0
- package/lib/volar/language-server.d.ts +2 -0
- package/lib/volar/language-server.d.ts.map +1 -0
- package/lib/volar/language-server.js +180 -0
- package/lib/volar/language-server.js.map +1 -0
- package/lib/volar/script-snapshot.d.ts +17 -0
- package/lib/volar/script-snapshot.d.ts.map +1 -0
- package/lib/volar/script-snapshot.js +24 -0
- package/lib/volar/script-snapshot.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { preprocess } from '@glimmer/syntax';
|
|
2
|
+
import { assert } from '../util.js';
|
|
3
|
+
import { codeFeatures } from './code-features.js';
|
|
4
|
+
import GlimmerASTMappingTree, { TemplateEmbedding, } from './glimmer-ast-mapping-tree.js';
|
|
5
|
+
/**
|
|
6
|
+
* @glimmer/syntax parses identifiers as strings. Aside from meaning
|
|
7
|
+
* we often have to reverse engineer location information for them
|
|
8
|
+
* by hand, it also means we can't treat mappings from identifiers
|
|
9
|
+
* consistently with how we treat mappings from other AST nodes.
|
|
10
|
+
*
|
|
11
|
+
* This class just gives us a uniform way to store identifiers
|
|
12
|
+
* or other nodes as the `source` for a mapping.
|
|
13
|
+
*/
|
|
14
|
+
export class Identifier {
|
|
15
|
+
constructor(name) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.type = 'Identifier';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Given the text of a handlebars template (either standalone .hbs file, or the contents
|
|
22
|
+
* of an embedded `<template>...</template>` within a .gts file), invokes the given callback
|
|
23
|
+
* with a set of tools to emit mapped contents corresponding to
|
|
24
|
+
* that template, tracking the text emitted in order to provide
|
|
25
|
+
* a mapping of ranges in the input to ranges in the output.
|
|
26
|
+
*/
|
|
27
|
+
export function mapTemplateContents(template, { embeddingSyntax }, callback) {
|
|
28
|
+
let ast = null;
|
|
29
|
+
let errors = [];
|
|
30
|
+
let lineOffsets = calculateLineOffsets(template, embeddingSyntax.prefix.length);
|
|
31
|
+
try {
|
|
32
|
+
ast = preprocess(template);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
let message = getErrorMessage(error);
|
|
36
|
+
let location;
|
|
37
|
+
if (isHBSSyntaxError(error)) {
|
|
38
|
+
location = {
|
|
39
|
+
start: lineOffsets[error.hash.loc.first_line] + error.hash.loc.first_column,
|
|
40
|
+
end: lineOffsets[error.hash.loc.last_line] + error.hash.loc.last_column,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
let match = /line (\d+) : column (\d+)/.exec(message);
|
|
45
|
+
if (match) {
|
|
46
|
+
let offset = lineOffsets[Number(match[1])] + Number(match[2]);
|
|
47
|
+
location = { start: offset, end: offset };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
errors.push({ message, location });
|
|
51
|
+
}
|
|
52
|
+
let segmentsStack = [[]];
|
|
53
|
+
let mappingsStack = [[]];
|
|
54
|
+
let indent = '';
|
|
55
|
+
let offset = 0;
|
|
56
|
+
let directives = [];
|
|
57
|
+
// Associates all content emitted during the given callback with the
|
|
58
|
+
// given range in the template source and corresponding AST node.
|
|
59
|
+
// If an exception is thrown while executing the callback, the error
|
|
60
|
+
// will be captured and associated with the given range, and no content
|
|
61
|
+
// will be emitted.
|
|
62
|
+
let captureMapping = (hbsRange, source, allowEmpty, callback, codeFeaturesForNode) => {
|
|
63
|
+
let start = offset;
|
|
64
|
+
let mappings = [];
|
|
65
|
+
let segments = [];
|
|
66
|
+
segmentsStack.unshift(segments);
|
|
67
|
+
mappingsStack.unshift(mappings);
|
|
68
|
+
try {
|
|
69
|
+
callback();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
errors.push({ message: getErrorMessage(error), location: hbsRange });
|
|
73
|
+
offset = start;
|
|
74
|
+
}
|
|
75
|
+
mappingsStack.shift();
|
|
76
|
+
segmentsStack.shift();
|
|
77
|
+
// If the offset didn't change (either because nothing was emitted
|
|
78
|
+
// or because an exception was thrown), don't add a new node to the
|
|
79
|
+
// mapping tree or flush any new content.
|
|
80
|
+
if (start !== offset || allowEmpty) {
|
|
81
|
+
let end = offset;
|
|
82
|
+
let tsRange = { start, end };
|
|
83
|
+
mappingsStack[0].push(new GlimmerASTMappingTree(tsRange, hbsRange, mappings, source,
|
|
84
|
+
// Prevent TS's semantic classifications (used for semantic highlighting, see
|
|
85
|
+
// https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide) from being
|
|
86
|
+
// source-mapped back to the glimmer template. These might be useful to reinstate at some
|
|
87
|
+
// point in the future but by default tends to make the highlighting in gts files look wrong.
|
|
88
|
+
codeFeaturesForNode ??
|
|
89
|
+
augmentCodeFeaturesWithIgnoreDirectivesSupport(codeFeatures.withoutHighlight, hbsRange)));
|
|
90
|
+
segmentsStack[0].push(...segments);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* This function will conditionally augment the CodeInformation object
|
|
95
|
+
* that's passed in for each mapping as a means to implement support for
|
|
96
|
+
* `@glint-expect-error` directives.
|
|
97
|
+
*/
|
|
98
|
+
function augmentCodeFeaturesWithIgnoreDirectivesSupport(features, hbsRange) {
|
|
99
|
+
if (features.verification) {
|
|
100
|
+
// If this code span requests verification (e.g. TS type-checking), then
|
|
101
|
+
// we potentially need to decorate the `verification` value that we pass
|
|
102
|
+
// back to Volar, in case we have active `glint-ignore/expect-error` directives
|
|
103
|
+
// in active effect.
|
|
104
|
+
let activeDirective;
|
|
105
|
+
for (let directive of directives) {
|
|
106
|
+
if (directive.areaOfEffect.start <= hbsRange.start &&
|
|
107
|
+
directive.areaOfEffect.end > hbsRange.start) {
|
|
108
|
+
if (!activeDirective) {
|
|
109
|
+
activeDirective = directive;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// More than one directive applies here; glint-nocheck, if present, always wins.
|
|
113
|
+
if (directive.kind === 'nocheck') {
|
|
114
|
+
activeDirective = directive;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!activeDirective) {
|
|
120
|
+
return features;
|
|
121
|
+
}
|
|
122
|
+
if (activeDirective.kind === 'ignore' || activeDirective.kind === 'nocheck') {
|
|
123
|
+
// We are currently in an ignored region of code, so don't
|
|
124
|
+
// even bother performing any type-checking: override verification (i.e. type-checking) to false
|
|
125
|
+
// for this mapping (note that the whole generated TS file will be type-checked but any
|
|
126
|
+
// diagnostics in this region will be suppressed by Volar)
|
|
127
|
+
return {
|
|
128
|
+
...features,
|
|
129
|
+
verification: false,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
else if (activeDirective.kind === 'expect-error') {
|
|
133
|
+
const expectErrorDirective = activeDirective;
|
|
134
|
+
return {
|
|
135
|
+
...features,
|
|
136
|
+
verification: {
|
|
137
|
+
shouldReport: () => {
|
|
138
|
+
// Keep track of any errors/diagnostics reported within this region of code...
|
|
139
|
+
expectErrorDirective.errorCount++;
|
|
140
|
+
// ...and suppress them from bubbling up as diagnostics/errrors/warnings.
|
|
141
|
+
return false;
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return features;
|
|
148
|
+
}
|
|
149
|
+
let mapper = {
|
|
150
|
+
indent() {
|
|
151
|
+
indent += ' ';
|
|
152
|
+
},
|
|
153
|
+
dedent() {
|
|
154
|
+
indent = indent.slice(2);
|
|
155
|
+
},
|
|
156
|
+
newline() {
|
|
157
|
+
offset += 1;
|
|
158
|
+
segmentsStack[0].push('\n');
|
|
159
|
+
},
|
|
160
|
+
text(value) {
|
|
161
|
+
offset += value.length;
|
|
162
|
+
segmentsStack[0].push(value);
|
|
163
|
+
},
|
|
164
|
+
synthetic(value) {
|
|
165
|
+
if (value.length) {
|
|
166
|
+
mapper.identifier(value, 0, 0);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
nothing(node, source = node) {
|
|
170
|
+
captureMapping(mapper.rangeForNode(node), source, true, () => { });
|
|
171
|
+
},
|
|
172
|
+
identifier(value, hbsOffset, hbsLength = value.length) {
|
|
173
|
+
let hbsRange = { start: hbsOffset, end: hbsOffset + hbsLength };
|
|
174
|
+
let source = new Identifier(value);
|
|
175
|
+
captureMapping(hbsRange, source, true, () => mapper.text(value));
|
|
176
|
+
},
|
|
177
|
+
forNode(node, callback, codeFeaturesForNode) {
|
|
178
|
+
captureMapping(mapper.rangeForNode(node), node, false, callback, codeFeaturesForNode);
|
|
179
|
+
},
|
|
180
|
+
forNodeWithSpan(node, span, callback, codeFeaturesForNode) {
|
|
181
|
+
captureMapping(mapper.rangeForNode(node, span), node, false, callback, codeFeaturesForNode);
|
|
182
|
+
},
|
|
183
|
+
error(message, location) {
|
|
184
|
+
errors.push({ message, location });
|
|
185
|
+
},
|
|
186
|
+
directive(kind, commentNode, location, areaOfEffect) {
|
|
187
|
+
const directive = {
|
|
188
|
+
kind,
|
|
189
|
+
commentNode,
|
|
190
|
+
location,
|
|
191
|
+
areaOfEffect,
|
|
192
|
+
errorCount: 0,
|
|
193
|
+
};
|
|
194
|
+
directives.push(directive);
|
|
195
|
+
},
|
|
196
|
+
emitDirectivePlaceholders() {
|
|
197
|
+
if (directives.length) {
|
|
198
|
+
mapper.text('// begin directive placeholders');
|
|
199
|
+
mapper.newline();
|
|
200
|
+
}
|
|
201
|
+
for (let directive of directives) {
|
|
202
|
+
if (directive.kind !== 'expect-error') {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
mapper.forNode(directive.commentNode, () => {
|
|
206
|
+
mapper.text(`// @ts-expect-error ${directive.kind}`);
|
|
207
|
+
}, {
|
|
208
|
+
...codeFeatures.withoutHighlight,
|
|
209
|
+
verification: {
|
|
210
|
+
shouldReport: () => {
|
|
211
|
+
// This determines whether we raise the placeholder "unused ts-expect-error" diagnostic.
|
|
212
|
+
// If errors were encountered in the region covered by the directive, then we suppress
|
|
213
|
+
// the "unused ts-expect-error" diagnostic here.
|
|
214
|
+
return directive.errorCount === 0;
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
mapper.newline();
|
|
219
|
+
mapper.text(';');
|
|
220
|
+
mapper.newline();
|
|
221
|
+
}
|
|
222
|
+
if (directives.length) {
|
|
223
|
+
mapper.text('// end directive placeholders');
|
|
224
|
+
mapper.newline();
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
rangeForNode: buildRangeForNode(lineOffsets),
|
|
228
|
+
rangeForLine: (line) => ({
|
|
229
|
+
start: lineOffsets[line],
|
|
230
|
+
end: lineOffsets[line + 1] ?? template.length,
|
|
231
|
+
}),
|
|
232
|
+
};
|
|
233
|
+
callback(ast, mapper);
|
|
234
|
+
assert(segmentsStack.length === 1);
|
|
235
|
+
let code = segmentsStack[0].join('');
|
|
236
|
+
let mapping = new GlimmerASTMappingTree({ start: 0, end: code.length }, {
|
|
237
|
+
start: 0,
|
|
238
|
+
end: embeddingSyntax.prefix.length + template.length + embeddingSyntax.suffix.length,
|
|
239
|
+
}, mappingsStack[0], new TemplateEmbedding(), codeFeatures.all);
|
|
240
|
+
return { errors, result: { code, directives, mapping } };
|
|
241
|
+
}
|
|
242
|
+
const LEADING_WHITESPACE = /^\s+/;
|
|
243
|
+
const TRAILING_WHITESPACE = /\s+$/;
|
|
244
|
+
function calculateLineOffsets(template, contentOffset) {
|
|
245
|
+
let lines = template.split('\n');
|
|
246
|
+
let total = contentOffset;
|
|
247
|
+
let offsets = [contentOffset];
|
|
248
|
+
for (let [index, line] of lines.entries()) {
|
|
249
|
+
// lines from @glimmer/syntax are 1-indexed
|
|
250
|
+
offsets[index + 1] = total;
|
|
251
|
+
total += line.length + 1;
|
|
252
|
+
}
|
|
253
|
+
return offsets;
|
|
254
|
+
}
|
|
255
|
+
function buildRangeForNode(offsets) {
|
|
256
|
+
return (node, span) => {
|
|
257
|
+
let { loc } = node;
|
|
258
|
+
if (span) {
|
|
259
|
+
loc = span;
|
|
260
|
+
}
|
|
261
|
+
let start = offsets[loc.start.line] + loc.start.column;
|
|
262
|
+
let end = offsets[loc.end.line] + loc.end.column;
|
|
263
|
+
// This makes error reporting for illegal text nodes (e.g. alongside named blocks)
|
|
264
|
+
// a bit nicer by only highlighting the content rather than all the surrounding
|
|
265
|
+
// newlines and attendant whitespace
|
|
266
|
+
if (node.type === 'TextNode') {
|
|
267
|
+
let leading = LEADING_WHITESPACE.exec(node.chars)?.[0].length ?? 0;
|
|
268
|
+
let trailing = TRAILING_WHITESPACE.exec(node.chars)?.[0].length ?? 0;
|
|
269
|
+
if (leading !== node.chars.length) {
|
|
270
|
+
start += leading;
|
|
271
|
+
end -= trailing;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return { start, end };
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function getErrorMessage(error) {
|
|
278
|
+
return error?.message ?? '(unknown error)';
|
|
279
|
+
}
|
|
280
|
+
function isHBSSyntaxError(error) {
|
|
281
|
+
if (typeof error === 'object' && !!error && 'hash' in error) {
|
|
282
|
+
let { hash } = error;
|
|
283
|
+
return typeof hash?.loc === 'object';
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=map-template-contents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-template-contents.js","sourceRoot":"","sources":["../../../src/transform/template/map-template-contents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,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OAAO,IAAI,EAAE,GAAG,KAAK,QAAQ,CAAC;IACvC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GlintEnvironment } from '../../config/index.js';
|
|
2
|
+
import { TSLib } from '../util.js';
|
|
3
|
+
import TransformedModule, { SourceFile } from './transformed-module.js';
|
|
4
|
+
/**
|
|
5
|
+
* Input to the process of rewriting a template, containing:
|
|
6
|
+
* script: the backing JS/TS module for a component, which may contain
|
|
7
|
+
* embedded templates depending on the environment
|
|
8
|
+
*/
|
|
9
|
+
export type RewriteInput = {
|
|
10
|
+
script: SourceFile;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Given the script and/or template that together comprise a component module,
|
|
14
|
+
* returns a `TransformedModule` representing the combined result, with the
|
|
15
|
+
* template(s), either alongside or inline, rewritten into equivalent TypeScript
|
|
16
|
+
* in terms of the active glint environment's exported types.
|
|
17
|
+
*
|
|
18
|
+
* May return `null` if an unrecoverable parse error occurs or if there is
|
|
19
|
+
* no transformation to be done.
|
|
20
|
+
*/
|
|
21
|
+
export declare function rewriteModule(ts: TSLib, { script }: RewriteInput, environment: GlintEnvironment, clientId?: string): TransformedModule | null;
|
|
22
|
+
//# sourceMappingURL=rewrite-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite-module.d.ts","sourceRoot":"","sources":["../../../src/transform/template/rewrite-module.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAU,KAAK,EAAE,MAAM,YAAY,CAAC;AAI3C,OAAO,iBAAiB,EAAE,EAGxB,UAAU,EAEX,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAElD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,KAAK,EACT,EAAE,MAAM,EAAE,EAAE,YAAY,EACxB,WAAW,EAAE,gBAAgB,EAC7B,QAAQ,CAAC,EAAE,MAAM,GAChB,iBAAiB,GAAG,IAAI,CAgB1B"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { assert } from '../util.js';
|
|
3
|
+
import { calculateTaggedTemplateSpans } from './inlining/tagged-strings.js';
|
|
4
|
+
import TransformedModule from './transformed-module.js';
|
|
5
|
+
/**
|
|
6
|
+
* Given the script and/or template that together comprise a component module,
|
|
7
|
+
* returns a `TransformedModule` representing the combined result, with the
|
|
8
|
+
* template(s), either alongside or inline, rewritten into equivalent TypeScript
|
|
9
|
+
* in terms of the active glint environment's exported types.
|
|
10
|
+
*
|
|
11
|
+
* May return `null` if an unrecoverable parse error occurs or if there is
|
|
12
|
+
* no transformation to be done.
|
|
13
|
+
*/
|
|
14
|
+
export function rewriteModule(ts, { script }, environment, clientId) {
|
|
15
|
+
let { errors, directives, partialSpans } = calculateCorrelatedSpans(ts, script, environment, clientId);
|
|
16
|
+
if (!partialSpans.length && !errors.length) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
let sparseSpans = completeCorrelatedSpans(partialSpans);
|
|
20
|
+
let { contents, correlatedSpans } = calculateTransformedSource(script, sparseSpans, directives);
|
|
21
|
+
return new TransformedModule(contents, errors, directives, correlatedSpans, script.filename);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Locates any embedded templates in the given AST and returns a corresponding
|
|
25
|
+
* `PartialCorrelatedSpan` for each, as well as any errors encountered. These
|
|
26
|
+
* spans are then used in `rewriteModule` above to calculate the full set of
|
|
27
|
+
* source-to-source location information as well as the final transformed source
|
|
28
|
+
* string.
|
|
29
|
+
*/
|
|
30
|
+
function calculateCorrelatedSpans(ts, script, environment, clientId) {
|
|
31
|
+
let directives = [];
|
|
32
|
+
let errors = [];
|
|
33
|
+
let partialSpans = [];
|
|
34
|
+
if (clientId === 'tsserver-plugin') {
|
|
35
|
+
partialSpans.push(generateAutoImportAnchor(script));
|
|
36
|
+
}
|
|
37
|
+
let { ast, emitMetadata, error } = parseScript(ts, script, environment);
|
|
38
|
+
if (error) {
|
|
39
|
+
if (typeof error === 'string') {
|
|
40
|
+
errors.push({
|
|
41
|
+
message: error,
|
|
42
|
+
location: { start: 0, end: script.contents.length - 1 },
|
|
43
|
+
source: script,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else if ('isContentTagError' in error && error.isContentTagError) {
|
|
47
|
+
// these lines exclude the line with the error, because
|
|
48
|
+
// adding the column offset will get us on to the line with the error
|
|
49
|
+
let lines = script.contents.split('\n').slice(0, error.line);
|
|
50
|
+
let start = lines.reduce((sum, line) => sum + line.length, 0) + error.column - 1;
|
|
51
|
+
let end = start + 1;
|
|
52
|
+
errors.push({
|
|
53
|
+
isContentTagError: true,
|
|
54
|
+
// we have to show the "help" because content-tag has different line numbers
|
|
55
|
+
// than we are able to discern ourselves.
|
|
56
|
+
message: error.message + '\n\n' + error.help,
|
|
57
|
+
source: script,
|
|
58
|
+
location: {
|
|
59
|
+
start,
|
|
60
|
+
end,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// We've hit a parsing error, so we need to immediately return as the parsed
|
|
65
|
+
// document must be correct before we can continue.
|
|
66
|
+
return { errors, directives, partialSpans };
|
|
67
|
+
}
|
|
68
|
+
ts.transform(ast, [
|
|
69
|
+
(context) => function visit(node) {
|
|
70
|
+
// Here we look for ```hbs``` tagged template expressions, originally introduced
|
|
71
|
+
// in the now-removed GlimmerX environment. We can consider getting rid of this, but
|
|
72
|
+
// then again there are still some use cases in the wild (e.g. Glimmer Next / GXT)
|
|
73
|
+
// where have tagged templates closing over outer scope is desirable:
|
|
74
|
+
// https://github.com/lifeart/glimmer-next/tree/master/glint-environment-gxt
|
|
75
|
+
// https://discord.com/channels/480462759797063690/717767358743183412/1259061848632721480
|
|
76
|
+
if (ts.isTaggedTemplateExpression(node)) {
|
|
77
|
+
let meta = emitMetadata.get(node);
|
|
78
|
+
let result = calculateTaggedTemplateSpans(ts, node, meta, script, environment);
|
|
79
|
+
directives.push(...result.directives);
|
|
80
|
+
errors.push(...result.errors);
|
|
81
|
+
partialSpans.push(...result.partialSpans);
|
|
82
|
+
}
|
|
83
|
+
else if (ts.isModuleDeclaration(node)) {
|
|
84
|
+
// don't traverse into declare module
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
return ts.visitEachChild(node, visit, context);
|
|
88
|
+
},
|
|
89
|
+
]);
|
|
90
|
+
return { errors, directives, partialSpans };
|
|
91
|
+
}
|
|
92
|
+
function parseScript(ts, script, environment) {
|
|
93
|
+
let { filename, contents } = script;
|
|
94
|
+
let extension = path.extname(filename);
|
|
95
|
+
let emitMetadata = new WeakMap();
|
|
96
|
+
let setEmitMetadata = (node, data) => void emitMetadata.set(node, Object.assign(emitMetadata.get(node) ?? {}, data));
|
|
97
|
+
let { preprocess, transform } = environment.getConfigForExtension(extension) ?? {};
|
|
98
|
+
let original = { contents, data: { templateLocations: [] } };
|
|
99
|
+
let preprocessed = original;
|
|
100
|
+
let error;
|
|
101
|
+
try {
|
|
102
|
+
preprocessed = preprocess?.(contents, filename) ?? original;
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
error = parseError(e, filename);
|
|
106
|
+
}
|
|
107
|
+
let ast = ts.createSourceFile(filename,
|
|
108
|
+
// contents will be transformed and placeholder'd content
|
|
109
|
+
// or, in the event of a parse error, the original content
|
|
110
|
+
// in which case, TS will report a ton of errors about some goofy syntax.
|
|
111
|
+
// We'll want to ignore all of that and only display our parsing error from content-tag.
|
|
112
|
+
preprocessed.contents, ts.ScriptTarget.Latest, true);
|
|
113
|
+
// Only transform if we don't have a parse error
|
|
114
|
+
if (!error && transform) {
|
|
115
|
+
let { transformed } = ts.transform(ast, [
|
|
116
|
+
(context) => transform(preprocessed.data, { ts, context, setEmitMetadata }),
|
|
117
|
+
]);
|
|
118
|
+
assert(transformed.length === 1 && ts.isSourceFile(transformed[0]));
|
|
119
|
+
ast = transformed[0];
|
|
120
|
+
}
|
|
121
|
+
return { ast, emitMetadata, error };
|
|
122
|
+
}
|
|
123
|
+
function parseError(e, filename) {
|
|
124
|
+
if (typeof e === 'object' && e !== null) {
|
|
125
|
+
// Parse Errors from the rust parser
|
|
126
|
+
if ('source_code' in e) {
|
|
127
|
+
// We remove the blank links in the error because swc
|
|
128
|
+
// pads errors with a leading and trailing blank line.
|
|
129
|
+
// the error is typically meant for the terminal, so making it
|
|
130
|
+
// stand out a bit more is a good, but that's more a presentation
|
|
131
|
+
// concern than just pure error information (which is what we need).
|
|
132
|
+
// @ts-expect-error object / property narrowing isn't available until TS 5.1
|
|
133
|
+
let lines = e.source_code.split('\n').filter(Boolean);
|
|
134
|
+
// Example:
|
|
135
|
+
// ' × Unexpected eof'
|
|
136
|
+
// ' ╭─[/home/nullvoxpopuli/Development/OpenSource/glint/test-packages/ts-template-imports-app/src/index.gts:6:1]'
|
|
137
|
+
// ' 6 │ '
|
|
138
|
+
// ' 7 │ export const X = <tem'
|
|
139
|
+
// ' ╰────'
|
|
140
|
+
let raw = lines.join('\n');
|
|
141
|
+
let message = lines[0].replace('×', '').trim();
|
|
142
|
+
let info = lines[1];
|
|
143
|
+
// a filename may have numbers in it, so we want to remove the filename
|
|
144
|
+
// before regex searching for numbers at the end of this line
|
|
145
|
+
let strippedInfo = info.replace(filename, '');
|
|
146
|
+
let matches = [...strippedInfo.matchAll(/\d+/g)];
|
|
147
|
+
let line = parseInt(matches[0][0], 10);
|
|
148
|
+
let column = parseInt(matches[1][0], 10);
|
|
149
|
+
// The help omits the original file name, because TS will provide that.
|
|
150
|
+
let help = lines.slice(2).join('\n');
|
|
151
|
+
return {
|
|
152
|
+
isContentTagError: true,
|
|
153
|
+
raw,
|
|
154
|
+
message,
|
|
155
|
+
line,
|
|
156
|
+
column,
|
|
157
|
+
file: filename,
|
|
158
|
+
help,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return `${e}`;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Given a sparse `CorrelatedSpan` array and the original source for a module,
|
|
166
|
+
* returns the resulting full transformed source string for that module, as
|
|
167
|
+
* well as a filled-in array of correlated spans that includes chunks of the
|
|
168
|
+
* original source that were not transformed.
|
|
169
|
+
*/
|
|
170
|
+
function calculateTransformedSource(originalFile, sparseSpans, directives) {
|
|
171
|
+
let correlatedSpans = [];
|
|
172
|
+
let originalOffset = 0;
|
|
173
|
+
let transformedOffset = 0;
|
|
174
|
+
for (let span of sparseSpans) {
|
|
175
|
+
let interstitial = originalFile.contents.slice(originalOffset, span.insertionPoint);
|
|
176
|
+
if (interstitial.length) {
|
|
177
|
+
correlatedSpans.push({
|
|
178
|
+
originalFile,
|
|
179
|
+
originalStart: originalOffset,
|
|
180
|
+
originalLength: interstitial.length,
|
|
181
|
+
insertionPoint: originalOffset,
|
|
182
|
+
transformedStart: transformedOffset,
|
|
183
|
+
transformedLength: interstitial.length,
|
|
184
|
+
transformedSource: interstitial,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
correlatedSpans.push(span);
|
|
188
|
+
transformedOffset += interstitial.length + span.transformedLength;
|
|
189
|
+
originalOffset +=
|
|
190
|
+
interstitial.length + (span.originalFile === originalFile ? span.originalLength : 0);
|
|
191
|
+
}
|
|
192
|
+
let trailingContent = originalFile.contents.slice(originalOffset);
|
|
193
|
+
const trailingSpan = {
|
|
194
|
+
originalFile,
|
|
195
|
+
originalStart: originalOffset,
|
|
196
|
+
originalLength: trailingContent.length + 1,
|
|
197
|
+
insertionPoint: originalOffset,
|
|
198
|
+
transformedStart: transformedOffset,
|
|
199
|
+
transformedLength: trailingContent.length + 1,
|
|
200
|
+
transformedSource: trailingContent,
|
|
201
|
+
};
|
|
202
|
+
correlatedSpans.push(trailingSpan);
|
|
203
|
+
const placeholderContent = '\n\n// @ts-expect-error placeholder for glint-expect-error\n;\n';
|
|
204
|
+
for (let directive of directives) {
|
|
205
|
+
if (directive.kind === 'expect-error') {
|
|
206
|
+
correlatedSpans.push({
|
|
207
|
+
originalFile,
|
|
208
|
+
originalStart: directive.location.start,
|
|
209
|
+
originalLength: directive.location.end - directive.location.start,
|
|
210
|
+
insertionPoint: originalOffset + trailingContent.length,
|
|
211
|
+
transformedSource: placeholderContent,
|
|
212
|
+
transformedStart: transformedOffset + trailingContent.length,
|
|
213
|
+
transformedLength: placeholderContent.length,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
contents: correlatedSpans.map((span) => span.transformedSource).join(''),
|
|
219
|
+
correlatedSpans,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Given an array of `PartialCorrelatedSpan`s for a file, calculates
|
|
224
|
+
* their `transformedLength` and `transformedStart` values, resulting
|
|
225
|
+
* in full `CorrelatedSpan`s.
|
|
226
|
+
*/
|
|
227
|
+
function completeCorrelatedSpans(partialSpans) {
|
|
228
|
+
let correlatedSpans = [];
|
|
229
|
+
for (let i = 0; i < partialSpans.length; i++) {
|
|
230
|
+
let current = partialSpans[i];
|
|
231
|
+
let transformedLength = current.transformedSource.length;
|
|
232
|
+
let transformedStart = current.insertionPoint;
|
|
233
|
+
if (i > 0) {
|
|
234
|
+
let previous = correlatedSpans[i - 1];
|
|
235
|
+
transformedStart =
|
|
236
|
+
previous.transformedStart +
|
|
237
|
+
previous.transformedSource.length +
|
|
238
|
+
(current.insertionPoint - previous.insertionPoint - previous.originalLength);
|
|
239
|
+
}
|
|
240
|
+
correlatedSpans.push({ ...current, transformedStart, transformedLength });
|
|
241
|
+
}
|
|
242
|
+
return correlatedSpans;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Insert a triple-slash reference directive to the top of the transformed file which provides
|
|
246
|
+
* an anchor/insertion point for auto-imports. This fixes an issue where auto-imports
|
|
247
|
+
* don't work for the first import in a file.
|
|
248
|
+
*
|
|
249
|
+
* Because we don't provide any mapping information to Volar, the internal error that
|
|
250
|
+
* this generates is quietly swallowed when Volar reverse source-maps the error back to
|
|
251
|
+
* .gts/.gjs. This is hacky but I don't know of any other (non-upstream) fix for this.
|
|
252
|
+
*
|
|
253
|
+
* Potential upstream Volar fix for this:
|
|
254
|
+
* https://github.com/volarjs/volar.js/pull/281
|
|
255
|
+
*/
|
|
256
|
+
function generateAutoImportAnchor(script) {
|
|
257
|
+
return {
|
|
258
|
+
originalFile: script,
|
|
259
|
+
originalStart: 0,
|
|
260
|
+
originalLength: 0,
|
|
261
|
+
insertionPoint: 0,
|
|
262
|
+
transformedSource: '/// <reference types="__GLINT_AUTO_IMPORT_ANCHOR__" />\n',
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=rewrite-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite-module.js","sourceRoot":"","sources":["../../../src/transform/template/rewrite-module.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,MAAM,EAAS,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,iBAKN,MAAM,yBAAyB,CAAC;AASjC;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,EAAS,EACT,EAAE,MAAM,EAAgB,EACxB,WAA6B,EAC7B,QAAiB;IAEjB,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,wBAAwB,CACjE,EAAE,EACF,MAAM,EACN,WAAW,EACX,QAAQ,CACT,CAAC;IAEF,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IA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E,iBAAiB,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,wBAAwB,CAAC,MAAkB;IAClD,OAAO;QACL,YAAY,EAAE,MAAM;QACpB,aAAa,EAAE,CAAC;QAChB,cAAc,EAAE,CAAC;QACjB,cAAc,EAAE,CAAC;QACjB,iBAAiB,EAAE,0DAA0D;KAC9E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `ScopeStack` is used while traversing a template
|
|
3
|
+
* to track what identifiers are currently in scope.
|
|
4
|
+
*/
|
|
5
|
+
export default class ScopeStack {
|
|
6
|
+
private stack;
|
|
7
|
+
constructor(identifiers: string[]);
|
|
8
|
+
push(identifiers: Array<string>): void;
|
|
9
|
+
pop(): void;
|
|
10
|
+
hasBinding(identifier: string): boolean;
|
|
11
|
+
private get top();
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=scope-stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-stack.d.ts","sourceRoot":"","sources":["../../../src/transform/template/scope-stack.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,KAAK,CAAqB;gBAEf,WAAW,EAAE,MAAM,EAAE;IAIjC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI;IAQtC,GAAG,IAAI,IAAI;IAKX,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAI9C,OAAO,KAAK,GAAG,GAEd;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { assert } from '../util.js';
|
|
2
|
+
/**
|
|
3
|
+
* A `ScopeStack` is used while traversing a template
|
|
4
|
+
* to track what identifiers are currently in scope.
|
|
5
|
+
*/
|
|
6
|
+
export default class ScopeStack {
|
|
7
|
+
constructor(identifiers) {
|
|
8
|
+
this.stack = [new Set(identifiers)];
|
|
9
|
+
}
|
|
10
|
+
push(identifiers) {
|
|
11
|
+
let scope = new Set(this.top);
|
|
12
|
+
for (let identifier of identifiers) {
|
|
13
|
+
scope.add(identifier);
|
|
14
|
+
}
|
|
15
|
+
this.stack.unshift(scope);
|
|
16
|
+
}
|
|
17
|
+
pop() {
|
|
18
|
+
assert(this.stack.length > 1);
|
|
19
|
+
this.stack.shift();
|
|
20
|
+
}
|
|
21
|
+
hasBinding(identifier) {
|
|
22
|
+
return this.top.has(identifier);
|
|
23
|
+
}
|
|
24
|
+
get top() {
|
|
25
|
+
return this.stack[0];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=scope-stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-stack.js","sourceRoot":"","sources":["../../../src/transform/template/scope-stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAG7B,YAAmB,WAAqB;QACtC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;IACtC,CAAC;IAEM,IAAI,CAAC,WAA0B;QACpC,IAAI,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,KAAK,IAAI,UAAU,IAAI,WAAW,EAAE,CAAC;YACnC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEM,GAAG;QACR,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAEM,UAAU,CAAC,UAAkB;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,IAAY,GAAG;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;CACF"}
|