@generaltranslation/vue-extractor 0.0.0
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/LICENSE.md +105 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/internal/compilerAst.d.ts +43 -0
- package/dist/internal/compilerAst.js +77 -0
- package/dist/internal/compilerAst.js.map +1 -0
- package/dist/internal/config/resolveVueCompilerOptions.d.ts +23 -0
- package/dist/internal/config/resolveVueCompilerOptions.js +987 -0
- package/dist/internal/config/resolveVueCompilerOptions.js.map +1 -0
- package/dist/internal/extractFromVueSource.d.ts +9 -0
- package/dist/internal/extractFromVueSource.js +332 -0
- package/dist/internal/extractFromVueSource.js.map +1 -0
- package/dist/internal/script/analyze.d.ts +13 -0
- package/dist/internal/script/analyze.js +4761 -0
- package/dist/internal/script/analyze.js.map +1 -0
- package/dist/internal/script/jsx.d.ts +36 -0
- package/dist/internal/script/jsx.js +667 -0
- package/dist/internal/script/jsx.js.map +1 -0
- package/dist/internal/script/knownValues.d.ts +14 -0
- package/dist/internal/script/knownValues.js +148 -0
- package/dist/internal/script/knownValues.js.map +1 -0
- package/dist/internal/script/localModules.d.ts +80 -0
- package/dist/internal/script/localModules.js +364 -0
- package/dist/internal/script/localModules.js.map +1 -0
- package/dist/internal/script/model.d.ts +317 -0
- package/dist/internal/script/model.js +1 -0
- package/dist/internal/script/parser.d.ts +3 -0
- package/dist/internal/script/parser.js +21 -0
- package/dist/internal/script/parser.js.map +1 -0
- package/dist/internal/script/replay.d.ts +53 -0
- package/dist/internal/script/replay.js +1611 -0
- package/dist/internal/script/replay.js.map +1 -0
- package/dist/internal/script/snapshot.d.ts +25 -0
- package/dist/internal/script/snapshot.js +293 -0
- package/dist/internal/script/snapshot.js.map +1 -0
- package/dist/internal/script/syntax.d.ts +21 -0
- package/dist/internal/script/syntax.js +46 -0
- package/dist/internal/script/syntax.js.map +1 -0
- package/dist/internal/script.d.ts +2 -0
- package/dist/internal/script.js +2 -0
- package/dist/internal/stringCalls.d.ts +7 -0
- package/dist/internal/stringCalls.js +82 -0
- package/dist/internal/stringCalls.js.map +1 -0
- package/dist/internal/template.d.ts +4 -0
- package/dist/internal/template.js +2198 -0
- package/dist/internal/template.js.map +1 -0
- package/dist/internal/templatePath.d.ts +12 -0
- package/dist/internal/templatePath.js +23 -0
- package/dist/internal/templatePath.js.map +1 -0
- package/dist/internal/types.d.ts +69 -0
- package/dist/internal/types.js +1 -0
- package/dist/internal/utils.d.ts +19 -0
- package/dist/internal/utils.js +149 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/internal/vueCompiler.d.ts +35 -0
- package/dist/internal/vueCompiler.js +320 -0
- package/dist/internal/vueCompiler.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.js +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import type { Binding, NodePath, Scope } from '@babel/traverse';
|
|
2
|
+
import type * as t from '@babel/types';
|
|
3
|
+
import type { GTComponentName, StringFunctionKind, TemplateContainerKind, VueBuiltinName } from '../types.js';
|
|
4
|
+
import type { LocalModuleResolver } from './localModules.js';
|
|
5
|
+
/** A statically recognized value that affects Vue translation extraction. */
|
|
6
|
+
export type KnownValue = {
|
|
7
|
+
type: 'component';
|
|
8
|
+
name: GTComponentName;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'hook';
|
|
11
|
+
kind: Exclude<StringFunctionKind, 'msg'>;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'string';
|
|
14
|
+
kind: StringFunctionKind;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'namespace';
|
|
17
|
+
source: 'gt-vue' | 'vue';
|
|
18
|
+
/** CommonJS namespace objects can be mutated through member writes. */
|
|
19
|
+
mutable: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
/** Immutable ESM namespace imported from a statically resolved barrel. */
|
|
22
|
+
type: 'local-namespace';
|
|
23
|
+
modulePath: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'vue-builtin';
|
|
26
|
+
name: VueBuiltinName;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'vue-call';
|
|
29
|
+
name: 'createVNode' | 'defineAsyncComponent' | 'h';
|
|
30
|
+
} | {
|
|
31
|
+
type: 'container-wrapper';
|
|
32
|
+
kind: ContainerWrapperKind;
|
|
33
|
+
writePolicy: ContainerWritePolicy;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'vue-wrapper';
|
|
36
|
+
kind: 'computed' | 'ref';
|
|
37
|
+
} | {
|
|
38
|
+
type: 'identity';
|
|
39
|
+
} | {
|
|
40
|
+
type: 'defineComponent';
|
|
41
|
+
};
|
|
42
|
+
export type ContainerWritePolicy = 'forward' | 'readonly-deep' | 'readonly-shallow';
|
|
43
|
+
export type ContainerWrapperKind = 'reactive' | 'readonly' | 'shallow-reactive' | 'shallow-readonly' | 'to-raw' | 'unref';
|
|
44
|
+
/** Import information shared by the two script blocks of one Vue SFC. */
|
|
45
|
+
export type VueScriptAnalysis = {
|
|
46
|
+
/** Optional visit counters used by deterministic complexity regressions. */
|
|
47
|
+
stats?: VueScriptAnalysisStats;
|
|
48
|
+
/** Absolute path of the source file currently being extracted. */
|
|
49
|
+
entryFile?: string;
|
|
50
|
+
/** Read-only local ESM graph used to resolve application barrels. */
|
|
51
|
+
localModules?: LocalModuleResolver;
|
|
52
|
+
/** Lengths of statically known, non-mutated normal-script arrays. */
|
|
53
|
+
arrayLengths: Map<string, number>;
|
|
54
|
+
/** Normal-script callables that may return a GT or Vue component. */
|
|
55
|
+
componentFactories: Set<string>;
|
|
56
|
+
/** Statically known normal-script container paths. */
|
|
57
|
+
containerKinds: Map<string, TemplateContainerKind>;
|
|
58
|
+
/** Normal-script names that take precedence over component registrations. */
|
|
59
|
+
directBindings: Set<string>;
|
|
60
|
+
/** Normal-script callables that may specifically return a GT component. */
|
|
61
|
+
gtComponentFactories: Set<string>;
|
|
62
|
+
/** Statically visible string alternatives for non-singleton expressions. */
|
|
63
|
+
possibleStaticStrings: Map<string, Set<string>>;
|
|
64
|
+
/** Container or factory paths whose selected value can be `<T>`. */
|
|
65
|
+
possibleGTContainers: Set<string>;
|
|
66
|
+
/** Normal-script callables returning containers that may directly contain T. */
|
|
67
|
+
gtContainerFactories: Set<string>;
|
|
68
|
+
staticValues: Map<string, string | number | bigint | boolean | null>;
|
|
69
|
+
/** Values exposed to templates after Vue's top-level ref unwrapping. */
|
|
70
|
+
templateValues: Map<string, KnownValue>;
|
|
71
|
+
/** Cross-block component bindings whose runtime identity is not provable. */
|
|
72
|
+
uncertainComponents: Set<string>;
|
|
73
|
+
/** Cross-block aliases that can specifically resolve to a GT component. */
|
|
74
|
+
uncertainGTComponents: Set<string>;
|
|
75
|
+
/** Cross-block aliases that may resolve to a gt-vue string function. */
|
|
76
|
+
uncertainStringFunctions: Set<string>;
|
|
77
|
+
/** Mutable local helpers that are unsafe only when passed a translator. */
|
|
78
|
+
uncertainTranslationHelpers: Set<string>;
|
|
79
|
+
values: Map<string, KnownValue>;
|
|
80
|
+
};
|
|
81
|
+
/** Internal analyzer visits whose growth should remain bounded by source size. */
|
|
82
|
+
export type VueScriptAnalysisStats = {
|
|
83
|
+
arrayEntryVisits: number;
|
|
84
|
+
containerKindVisits: number;
|
|
85
|
+
finalContainerSnapshotReads: number;
|
|
86
|
+
knownExpressionVisits: number;
|
|
87
|
+
stringFunctionVisits: number;
|
|
88
|
+
transformArrayEntryVisits: number;
|
|
89
|
+
};
|
|
90
|
+
/** Babel expression paired with the lexical scope in which it is evaluated. */
|
|
91
|
+
export type ScopedExpression = {
|
|
92
|
+
node: t.Node;
|
|
93
|
+
scope: Scope;
|
|
94
|
+
};
|
|
95
|
+
export type ComponentKind = 'translation' | 'vue' | 'T';
|
|
96
|
+
export type TemplateKnownValue = Extract<KnownValue, {
|
|
97
|
+
type: 'component' | 'string' | 'vue-builtin';
|
|
98
|
+
}>;
|
|
99
|
+
export type ComponentMemberCandidate = {
|
|
100
|
+
certain: boolean;
|
|
101
|
+
name: string;
|
|
102
|
+
value: TemplateKnownValue;
|
|
103
|
+
};
|
|
104
|
+
export type ComponentFactoryCandidate = {
|
|
105
|
+
gt: boolean;
|
|
106
|
+
name: string;
|
|
107
|
+
};
|
|
108
|
+
export type ObjectEntryResult = {
|
|
109
|
+
status: 'absent';
|
|
110
|
+
} | {
|
|
111
|
+
status: 'known';
|
|
112
|
+
expression: ScopedExpression;
|
|
113
|
+
} | {
|
|
114
|
+
status: 'unknown';
|
|
115
|
+
};
|
|
116
|
+
export type CollectedObjectEntries = {
|
|
117
|
+
entries: Map<string, ScopedExpression>;
|
|
118
|
+
unknownAll: boolean;
|
|
119
|
+
unknownNames: Set<string>;
|
|
120
|
+
};
|
|
121
|
+
export type TemplateExposure = {
|
|
122
|
+
type: 'known';
|
|
123
|
+
value: KnownValue;
|
|
124
|
+
} | {
|
|
125
|
+
type: 'container';
|
|
126
|
+
kind?: TemplateContainerKind;
|
|
127
|
+
length?: number;
|
|
128
|
+
possibleGT?: true;
|
|
129
|
+
} | {
|
|
130
|
+
type: 'uncertain';
|
|
131
|
+
component: boolean;
|
|
132
|
+
gtComponent: boolean;
|
|
133
|
+
stringFunction: boolean;
|
|
134
|
+
} | {
|
|
135
|
+
type: 'factory';
|
|
136
|
+
gt: boolean;
|
|
137
|
+
gtContainer?: boolean;
|
|
138
|
+
} | {
|
|
139
|
+
type: 'possible-static-strings';
|
|
140
|
+
values: Set<string>;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'static';
|
|
143
|
+
value: string | number | bigint | boolean | null;
|
|
144
|
+
};
|
|
145
|
+
export type GTContainerExposure = {
|
|
146
|
+
containers: Set<string>;
|
|
147
|
+
factories: Set<string>;
|
|
148
|
+
};
|
|
149
|
+
export type FinalContainerSnapshot = {
|
|
150
|
+
kind: 'array';
|
|
151
|
+
entries: Array<ScopedExpression | undefined>;
|
|
152
|
+
} | {
|
|
153
|
+
kind: 'object';
|
|
154
|
+
entries: Map<string, ScopedExpression>;
|
|
155
|
+
};
|
|
156
|
+
export type FinalContainerOperation = {
|
|
157
|
+
position: number;
|
|
158
|
+
apply: (snapshot: FinalContainerSnapshot) => FinalContainerSnapshot | undefined;
|
|
159
|
+
};
|
|
160
|
+
export type ContainerIdentityReplay = {
|
|
161
|
+
unsafeBindings: Set<Binding>;
|
|
162
|
+
values: Map<Binding, ReplayValue | undefined>;
|
|
163
|
+
};
|
|
164
|
+
export type ReplayValue = ReplayCollectionReference | ReplayComputedReference | ReplayContainerReference | ReplayFunctionReference | ReplayGetterReference | ReplayLeaf | ReplayMethodReference | ReplayRefReference | ReplayUnsafe;
|
|
165
|
+
export type ReplayContainerReference = {
|
|
166
|
+
type: 'container';
|
|
167
|
+
identity: ReplayContainerIdentity;
|
|
168
|
+
writePolicy: ContainerWritePolicy;
|
|
169
|
+
};
|
|
170
|
+
export type ReplayContainerIdentity = {
|
|
171
|
+
escaped: boolean;
|
|
172
|
+
snapshot: ReplayContainerSnapshot;
|
|
173
|
+
};
|
|
174
|
+
export type ReplayRefReference = {
|
|
175
|
+
type: 'ref';
|
|
176
|
+
identity: ReplayRefIdentity;
|
|
177
|
+
writePolicy: ContainerWritePolicy;
|
|
178
|
+
};
|
|
179
|
+
export type ReplayRefIdentity = {
|
|
180
|
+
escaped: boolean;
|
|
181
|
+
value: ReplayValue | undefined;
|
|
182
|
+
};
|
|
183
|
+
export type ReplayComputedReference = {
|
|
184
|
+
type: 'computed';
|
|
185
|
+
getter: ScopedExpression & {
|
|
186
|
+
node: t.Function;
|
|
187
|
+
};
|
|
188
|
+
writePolicy: ContainerWritePolicy;
|
|
189
|
+
};
|
|
190
|
+
export type ReplayGetterReference = {
|
|
191
|
+
type: 'getter';
|
|
192
|
+
getter: ScopedExpression & {
|
|
193
|
+
node: t.Function;
|
|
194
|
+
};
|
|
195
|
+
substitutions: Map<Binding, ReplayValue>;
|
|
196
|
+
};
|
|
197
|
+
export type ReplayFunctionReference = {
|
|
198
|
+
type: 'function';
|
|
199
|
+
boundArguments: ReplayValue[];
|
|
200
|
+
callable: ScopedExpression & {
|
|
201
|
+
node: t.Function;
|
|
202
|
+
};
|
|
203
|
+
substitutions: Map<Binding, ReplayValue>;
|
|
204
|
+
thisValue?: ReplayValue;
|
|
205
|
+
};
|
|
206
|
+
export type ReplayMethodReference = {
|
|
207
|
+
type: 'method';
|
|
208
|
+
callable: ScopedExpression & {
|
|
209
|
+
node: t.Function;
|
|
210
|
+
};
|
|
211
|
+
receiver?: ReplayContainerReference;
|
|
212
|
+
substitutions: Map<Binding, ReplayValue>;
|
|
213
|
+
};
|
|
214
|
+
export type ReplayCollectionReference = {
|
|
215
|
+
type: 'collection';
|
|
216
|
+
identity: ReplayCollectionIdentity;
|
|
217
|
+
iteration: 'entries' | 'values';
|
|
218
|
+
writePolicy: ContainerWritePolicy;
|
|
219
|
+
};
|
|
220
|
+
export type ReplayCollectionIdentity = {
|
|
221
|
+
entries: Map<string, ReplayValue>;
|
|
222
|
+
escaped: boolean;
|
|
223
|
+
kind: 'map' | 'set';
|
|
224
|
+
templateKeys: Map<string, string>;
|
|
225
|
+
};
|
|
226
|
+
export type ReplayContainerSnapshot = {
|
|
227
|
+
kind: 'array';
|
|
228
|
+
entries: Array<ReplayValue | undefined>;
|
|
229
|
+
} | {
|
|
230
|
+
kind: 'object';
|
|
231
|
+
entries: Map<string, ReplayValue>;
|
|
232
|
+
prototype?: ReplayContainerReference;
|
|
233
|
+
setters?: Map<string, ReplayMethodReference>;
|
|
234
|
+
};
|
|
235
|
+
export type ReplayLeaf = {
|
|
236
|
+
type: 'leaf';
|
|
237
|
+
exactSelection?: boolean;
|
|
238
|
+
expression: ScopedExpression;
|
|
239
|
+
hasGT: boolean | undefined;
|
|
240
|
+
knownValue?: TemplateKnownValue;
|
|
241
|
+
selectionKind?: 'collection' | 'getter' | 'member' | 'ref';
|
|
242
|
+
};
|
|
243
|
+
export type ReplayUnsafe = {
|
|
244
|
+
type: 'unsafe';
|
|
245
|
+
};
|
|
246
|
+
export type ReplayEvaluationContext = {
|
|
247
|
+
/** Enables getter side effects only while replaying actual program execution. */
|
|
248
|
+
allowGetterEffects?: boolean;
|
|
249
|
+
substitutions: Map<Binding, ReplayValue>;
|
|
250
|
+
thisValue?: ReplayValue;
|
|
251
|
+
unsafeBindings: Set<Binding>;
|
|
252
|
+
values: Map<Binding, ReplayValue | undefined>;
|
|
253
|
+
};
|
|
254
|
+
export type ReplayLeafState = {
|
|
255
|
+
status: 'leaf';
|
|
256
|
+
value: ReplayLeaf;
|
|
257
|
+
} | {
|
|
258
|
+
status: 'unsafe';
|
|
259
|
+
};
|
|
260
|
+
/** Mutable analysis caches shared by one parsed script block. */
|
|
261
|
+
export type ScriptState = {
|
|
262
|
+
activeComponentFunctions: Set<t.Function>;
|
|
263
|
+
activeReplayFunctions: Set<t.Function>;
|
|
264
|
+
activeStringFunctions: Set<t.Function>;
|
|
265
|
+
activeTranslationFunctions: Set<t.Function>;
|
|
266
|
+
analysis: VueScriptAnalysis;
|
|
267
|
+
attachedLocalModules: Set<string>;
|
|
268
|
+
arrayEntries: Map<Binding, Array<ScopedExpression | undefined> | null>;
|
|
269
|
+
arrayEntriesInProgress: Set<Binding>;
|
|
270
|
+
componentPossibilities: Map<Binding, Map<ComponentKind | 'any', boolean>>;
|
|
271
|
+
componentFactoryCandidates: Map<Binding, ComponentFactoryCandidate[]>;
|
|
272
|
+
componentFactoryCandidatesInProgress: Set<Binding>;
|
|
273
|
+
bindings: Map<Binding, KnownValue>;
|
|
274
|
+
containerKindSnapshots: Map<Binding, {
|
|
275
|
+
arrayLengths: Map<string, number>;
|
|
276
|
+
kinds: Map<string, TemplateContainerKind>;
|
|
277
|
+
}>;
|
|
278
|
+
containerKindSnapshotsInProgress: Set<Binding>;
|
|
279
|
+
containerIdentityReplays: WeakMap<t.Node, ContainerIdentityReplay>;
|
|
280
|
+
containerWritePolicies: Map<Binding, ContainerWritePolicy | undefined>;
|
|
281
|
+
/** Immutable aliases proven to hold a non-callable or known non-string value. */
|
|
282
|
+
definiteNonStringFunctionBindings: Set<Binding>;
|
|
283
|
+
definiteNonStringFunctionBindingsInProgress: Set<Binding>;
|
|
284
|
+
entryProgram: t.Program;
|
|
285
|
+
finalContainerSnapshots: Map<Binding, FinalContainerSnapshot>;
|
|
286
|
+
finalContainerSnapshotsInProgress: Set<Binding>;
|
|
287
|
+
gtContainerPossibilities: Map<Binding, boolean>;
|
|
288
|
+
gtContainerPossibilitiesInProgress: Set<Binding>;
|
|
289
|
+
gtContainerPaths: Map<Binding, Set<string>>;
|
|
290
|
+
gtContainerPathsInProgress: Set<Binding>;
|
|
291
|
+
localCallableBindings: Map<Binding, ScopedExpression & {
|
|
292
|
+
node: t.Function;
|
|
293
|
+
}>;
|
|
294
|
+
mutationGTContainerPaths: Map<Binding, Set<string>>;
|
|
295
|
+
mutationGTContainerPathsInProgress: Set<Binding>;
|
|
296
|
+
mutationPossibleStaticStrings: Map<Binding, Map<string, Set<string>>>;
|
|
297
|
+
mutationPossibleStaticStringsInProgress: Set<Binding>;
|
|
298
|
+
mutableImportSources: Map<Binding, 'gt-vue' | 'vue'>;
|
|
299
|
+
nextReplayIdentityKey: number;
|
|
300
|
+
parameterSubstitutions: Array<Map<Binding, ScopedExpression>>;
|
|
301
|
+
paths: WeakMap<t.Node, NodePath<t.Node>>;
|
|
302
|
+
possibleStaticStrings: Map<Binding, Set<string>>;
|
|
303
|
+
possibleStaticStringsInProgress: Set<Binding>;
|
|
304
|
+
possibleStaticStringMembers: Map<Binding, Map<string, Set<string>>>;
|
|
305
|
+
possibleStaticStringMembersInProgress: Set<Binding>;
|
|
306
|
+
readonlyContainerUses: Map<Binding, boolean>;
|
|
307
|
+
readonlyContainerUsesInProgress: Set<Binding>;
|
|
308
|
+
replayIdentityKeys: WeakMap<object, string>;
|
|
309
|
+
resolvedBindings: Set<Binding>;
|
|
310
|
+
scopes: WeakMap<t.Node, Scope>;
|
|
311
|
+
thisSubstitutions: ScopedExpression[];
|
|
312
|
+
transformArrayEntries: Map<Binding, Array<ScopedExpression | undefined> | null>;
|
|
313
|
+
transformArrayEntriesInProgress: Set<Binding>;
|
|
314
|
+
/** Import and alias bindings that may call a forwarded translator. */
|
|
315
|
+
uncertainTranslationHelperBindings: Set<Binding>;
|
|
316
|
+
unsafeMutableNamespaceSources: Set<'gt-vue' | 'vue'>;
|
|
317
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
//#region src/internal/script/parser.ts
|
|
3
|
+
/** Returns the Babel syntax plugins accepted by a Vue script language. */
|
|
4
|
+
function getParserPlugins(language) {
|
|
5
|
+
const normalizedLanguage = language?.toLowerCase();
|
|
6
|
+
const plugins = ["decorators-legacy"];
|
|
7
|
+
if (normalizedLanguage === "ts" || normalizedLanguage === "tsx") plugins.push("typescript");
|
|
8
|
+
if (normalizedLanguage === "jsx" || normalizedLanguage === "tsx") plugins.push("jsx");
|
|
9
|
+
return plugins;
|
|
10
|
+
}
|
|
11
|
+
/** Parses one JavaScript or TypeScript block using Vue-compatible syntax. */
|
|
12
|
+
function parseScriptAst(source, language) {
|
|
13
|
+
return parse(source, {
|
|
14
|
+
plugins: getParserPlugins(language),
|
|
15
|
+
sourceType: "module"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { parseScriptAst };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","names":[],"sources":["../../../src/internal/script/parser.ts"],"sourcesContent":["import { parse, type ParserPlugin } from '@babel/parser';\nimport type * as t from '@babel/types';\n\n/** Returns the Babel syntax plugins accepted by a Vue script language. */\nfunction getParserPlugins(language: string | undefined): ParserPlugin[] {\n const normalizedLanguage = language?.toLowerCase();\n const plugins: ParserPlugin[] = ['decorators-legacy'];\n if (normalizedLanguage === 'ts' || normalizedLanguage === 'tsx') {\n plugins.push('typescript');\n }\n if (normalizedLanguage === 'jsx' || normalizedLanguage === 'tsx') {\n plugins.push('jsx');\n }\n return plugins;\n}\n\n/** Parses one JavaScript or TypeScript block using Vue-compatible syntax. */\nexport function parseScriptAst(\n source: string,\n language: string | undefined\n): t.File {\n return parse(source, {\n plugins: getParserPlugins(language),\n sourceType: 'module',\n });\n}\n"],"mappings":";;;AAIA,SAAS,iBAAiB,UAA8C;CACtE,MAAM,qBAAqB,UAAU,aAAa;CAClD,MAAM,UAA0B,CAAC,oBAAoB;AACrD,KAAI,uBAAuB,QAAQ,uBAAuB,MACxD,SAAQ,KAAK,aAAa;AAE5B,KAAI,uBAAuB,SAAS,uBAAuB,MACzD,SAAQ,KAAK,MAAM;AAErB,QAAO;;;AAIT,SAAgB,eACd,QACA,UACQ;AACR,QAAO,MAAM,QAAQ;EACnB,SAAS,iBAAiB,SAAS;EACnC,YAAY;EACb,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Binding, Scope } from '@babel/traverse';
|
|
2
|
+
import type * as t from '@babel/types';
|
|
3
|
+
import type { TemplateContainerKind } from '../types.js';
|
|
4
|
+
import { type StaticPrimitiveResult } from '../utils.js';
|
|
5
|
+
import type { ComponentFactoryCandidate, ComponentMemberCandidate, ContainerWrapperKind, ContainerWritePolicy, KnownValue, ReplayLeaf, ReplayLeafState, ReplayValue, ScopedExpression, ScriptState, VueScriptAnalysis } from './model.js';
|
|
6
|
+
/** Static-analysis operations consumed by the source-ordered replay SCC. */
|
|
7
|
+
export type ReplayAnalysisDependencies = {
|
|
8
|
+
ordinaryGlobalValues: ReadonlySet<string>;
|
|
9
|
+
readonlyArrayTransforms: ReadonlySet<string>;
|
|
10
|
+
bindingReadsUnsafeMutableImport: (binding: Binding, state: ScriptState) => boolean;
|
|
11
|
+
collectFunctionReturnExpressions: (fn: t.Function, scope: Scope, state: ScriptState) => ScopedExpression[];
|
|
12
|
+
collectPatternBindingNames: (pattern: t.Node) => string[];
|
|
13
|
+
composeContainerWritePolicy: (wrapper: ContainerWrapperKind, inner: ContainerWritePolicy | undefined) => ContainerWritePolicy;
|
|
14
|
+
knownValueKey: (value: KnownValue) => string;
|
|
15
|
+
readDefiniteArrayInteger: (node: t.Node | undefined, fallback: number, scope: Scope, state: ScriptState) => number | undefined;
|
|
16
|
+
readResolvedMemberPath: (node: t.Node, scope: Scope, state: ScriptState) => string | undefined;
|
|
17
|
+
readResolvedMemberProperty: (node: t.MemberExpression | t.OptionalMemberExpression, scope: Scope, state: ScriptState) => string | undefined;
|
|
18
|
+
readResolvedPropertyKey: (property: {
|
|
19
|
+
computed: boolean;
|
|
20
|
+
key: t.Node;
|
|
21
|
+
}, scope: Scope, state: ScriptState) => string | undefined;
|
|
22
|
+
readStaticFromScope: (node: t.Node | null | undefined, scope: Scope, seen: Set<Binding>, atPosition: number, analysis?: VueScriptAnalysis, allowNumericGlobals?: boolean) => StaticPrimitiveResult;
|
|
23
|
+
resolveCalledFunction: (node: t.Node | null | undefined, scope: Scope, state: ScriptState, seen: Set<t.Node>) => (ScopedExpression & {
|
|
24
|
+
node: t.Function;
|
|
25
|
+
}) | undefined;
|
|
26
|
+
resolveComputedGetter: (node: t.Node, scope: Scope, state: ScriptState) => (ScopedExpression & {
|
|
27
|
+
node: t.Function;
|
|
28
|
+
}) | undefined;
|
|
29
|
+
resolveKnownExpression: (node: t.Node | null | undefined, scope: Scope, state: ScriptState, seen: Set<Binding>) => KnownValue | undefined;
|
|
30
|
+
};
|
|
31
|
+
/** Narrow replay queries used by the surrounding script analyzer. */
|
|
32
|
+
export type ReplayAnalysis = {
|
|
33
|
+
evaluateReplayAtPosition: (node: t.Node, scope: Scope, atPosition: number, state: ScriptState) => ReplayValue | undefined;
|
|
34
|
+
readDefiniteReplayGTContainerPaths: (binding: Binding, state: ScriptState) => Set<string> | null | undefined;
|
|
35
|
+
readReplayComponentCandidates: (binding: Binding, basePath: string, state: ScriptState) => ComponentMemberCandidate[] | undefined;
|
|
36
|
+
readReplayComponentFactoryCandidates: (binding: Binding, basePath: string, state: ScriptState) => ComponentFactoryCandidate[] | undefined;
|
|
37
|
+
readReplayContainerMetadata: (binding: Binding, basePath: string, state: ScriptState) => {
|
|
38
|
+
arrayLengths: Map<string, number>;
|
|
39
|
+
kinds: Map<string, TemplateContainerKind>;
|
|
40
|
+
} | undefined;
|
|
41
|
+
readReplayLeafState: (binding: Binding, state: ScriptState) => ReplayLeafState | undefined;
|
|
42
|
+
readSafeReplayLeafOverride: (binding: Binding, replayLeaf: ReplayLeafState | undefined, state: ScriptState) => Extract<ReplayLeafState, {
|
|
43
|
+
status: 'leaf';
|
|
44
|
+
}> | undefined;
|
|
45
|
+
isReplayGetterStringLeaf: (value: ReplayLeaf) => boolean;
|
|
46
|
+
replayBindingRetainsUnsafeIdentity: (binding: Binding, state: ScriptState) => boolean;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Creates the finite source-ordered identity analyzer used by script analysis.
|
|
50
|
+
* Dependencies are injected so the replay evaluator remains one cohesive SCC
|
|
51
|
+
* without creating a runtime import cycle back to the script orchestrator.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createReplayAnalysis({ ordinaryGlobalValues: ORDINARY_GLOBAL_VALUES, readonlyArrayTransforms: READONLY_ARRAY_TRANSFORMS, bindingReadsUnsafeMutableImport, collectFunctionReturnExpressions, collectPatternBindingNames, composeContainerWritePolicy, knownValueKey, readDefiniteArrayInteger, readResolvedMemberPath, readResolvedMemberProperty, readResolvedPropertyKey, readStaticFromScope, resolveCalledFunction, resolveComputedGetter, resolveKnownExpression, }: ReplayAnalysisDependencies): ReplayAnalysis;
|