@llui/vite-plugin 0.0.34 → 0.0.36
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/dist/cross-file-resolver.d.ts.map +1 -1
- package/dist/cross-file-resolver.js +93 -26
- package/dist/cross-file-resolver.js.map +1 -1
- package/dist/msg-schema.d.ts +38 -6
- package/dist/msg-schema.d.ts.map +1 -1
- package/dist/msg-schema.js +365 -19
- package/dist/msg-schema.js.map +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +40 -4
- package/dist/transform.js.map +1 -1
- package/package.json +1 -1
package/dist/transform.js
CHANGED
|
@@ -2260,15 +2260,21 @@ function buildFieldDescriptorExpr(descriptor, f) {
|
|
|
2260
2260
|
if (descriptor.hint !== undefined) {
|
|
2261
2261
|
props.push(f.createPropertyAssignment('hint', f.createStringLiteral(descriptor.hint)));
|
|
2262
2262
|
}
|
|
2263
|
+
if (descriptor.validates !== undefined) {
|
|
2264
|
+
props.push(f.createPropertyAssignment('validates', f.createStringLiteral(descriptor.validates)));
|
|
2265
|
+
}
|
|
2263
2266
|
return f.createObjectLiteralExpression(props);
|
|
2264
2267
|
}
|
|
2265
2268
|
// The remaining cases are bare type-shape variants emitted by
|
|
2266
|
-
// `resolveFieldType`: enum, object, array.
|
|
2267
|
-
// key is present so we never confuse an inline
|
|
2268
|
-
// ({enum: [...]}) with a deeply-nested shape descriptor.
|
|
2269
|
+
// `resolveFieldType`: enum, object, array, discriminated-union.
|
|
2270
|
+
// Discriminate by which key is present so we never confuse an inline
|
|
2271
|
+
// object literal ({enum: [...]}) with a deeply-nested shape descriptor.
|
|
2269
2272
|
if ('enum' in descriptor) {
|
|
2273
|
+
// Mixed-typed enum values (string/number/boolean). Each enum entry
|
|
2274
|
+
// emits with its native literal kind so JSON round-trips preserve
|
|
2275
|
+
// the type information — `1` stays a number, not stringified.
|
|
2270
2276
|
return f.createObjectLiteralExpression([
|
|
2271
|
-
f.createPropertyAssignment('enum', f.createArrayLiteralExpression(descriptor.enum.map((v) =>
|
|
2277
|
+
f.createPropertyAssignment('enum', f.createArrayLiteralExpression(descriptor.enum.map((v) => emitEnumValue(v, f)))),
|
|
2272
2278
|
]);
|
|
2273
2279
|
}
|
|
2274
2280
|
if ('kind' in descriptor && descriptor.kind === 'object') {
|
|
@@ -2284,12 +2290,42 @@ function buildFieldDescriptorExpr(descriptor, f) {
|
|
|
2284
2290
|
f.createPropertyAssignment('shape', f.createObjectLiteralExpression(shapeProps)),
|
|
2285
2291
|
]);
|
|
2286
2292
|
}
|
|
2293
|
+
if ('kind' in descriptor && descriptor.kind === 'discriminated-union') {
|
|
2294
|
+
// Inner-union variants are themselves field maps (per branch),
|
|
2295
|
+
// recursed through the same builder. Symmetric with how the
|
|
2296
|
+
// top-level Msg union's variants are represented.
|
|
2297
|
+
const variantProps = [];
|
|
2298
|
+
for (const [discValue, fields] of Object.entries(descriptor.variants)) {
|
|
2299
|
+
const fieldProps = [];
|
|
2300
|
+
for (const [k, v] of Object.entries(fields)) {
|
|
2301
|
+
fieldProps.push(f.createPropertyAssignment(f.createStringLiteral(k), buildFieldDescriptorExpr(v, f)));
|
|
2302
|
+
}
|
|
2303
|
+
variantProps.push(f.createPropertyAssignment(f.createStringLiteral(discValue), f.createObjectLiteralExpression(fieldProps, true)));
|
|
2304
|
+
}
|
|
2305
|
+
return f.createObjectLiteralExpression([
|
|
2306
|
+
f.createPropertyAssignment('kind', f.createStringLiteral('discriminated-union')),
|
|
2307
|
+
f.createPropertyAssignment('discriminant', f.createStringLiteral(descriptor.discriminant)),
|
|
2308
|
+
f.createPropertyAssignment('variants', f.createObjectLiteralExpression(variantProps, true)),
|
|
2309
|
+
]);
|
|
2310
|
+
}
|
|
2287
2311
|
// Array — `{kind: 'array', element: <bare type>}`.
|
|
2288
2312
|
return f.createObjectLiteralExpression([
|
|
2289
2313
|
f.createPropertyAssignment('kind', f.createStringLiteral('array')),
|
|
2290
2314
|
f.createPropertyAssignment('element', buildFieldDescriptorExpr(descriptor.element, f)),
|
|
2291
2315
|
]);
|
|
2292
2316
|
}
|
|
2317
|
+
/**
|
|
2318
|
+
* Emit a single enum value as the right TS literal kind. Numbers as
|
|
2319
|
+
* numeric literals, booleans as keyword expressions, strings as string
|
|
2320
|
+
* literals — preserves the type at the wire (JSON round-trips correctly).
|
|
2321
|
+
*/
|
|
2322
|
+
function emitEnumValue(v, f) {
|
|
2323
|
+
if (typeof v === 'string')
|
|
2324
|
+
return f.createStringLiteral(v);
|
|
2325
|
+
if (typeof v === 'number')
|
|
2326
|
+
return f.createNumericLiteral(v);
|
|
2327
|
+
return v ? f.createTrue() : f.createFalse();
|
|
2328
|
+
}
|
|
2293
2329
|
function hasNonDefaultAnnotation(a) {
|
|
2294
2330
|
for (const v of Object.values(a)) {
|
|
2295
2331
|
if (v.intent !== null)
|