@elaraai/east-codex-plugin 1.0.105 → 1.0.107
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/.build/daemon/lsp.js +166 -10
- package/.build/daemon/server.js +166 -10
- package/.codex-plugin/plugin.json +1 -1
- package/index.json +1207 -75
- package/package.json +1 -1
- package/skills/e3/SKILL.md +3 -1
- package/skills/e3-ui/SKILL.md +65 -84
- package/skills/east/SKILL.md +2 -0
- package/skills/east-ui/SKILL.md +6 -1
package/.build/daemon/lsp.js
CHANGED
|
@@ -1065,9 +1065,9 @@ function plainLiteralInitializer(decl, t) {
|
|
|
1065
1065
|
const init2 = decl.initializer;
|
|
1066
1066
|
if (init2 === void 0)
|
|
1067
1067
|
return void 0;
|
|
1068
|
-
const
|
|
1069
|
-
if (t.isArrayLiteralExpression(
|
|
1070
|
-
return
|
|
1068
|
+
const unwrapped2 = t.isAsExpression(init2) || t.isSatisfiesExpression(init2) ? init2.expression : init2;
|
|
1069
|
+
if (t.isArrayLiteralExpression(unwrapped2) || t.isObjectLiteralExpression(unwrapped2)) {
|
|
1070
|
+
return unwrapped2;
|
|
1071
1071
|
}
|
|
1072
1072
|
return void 0;
|
|
1073
1073
|
}
|
|
@@ -2282,8 +2282,8 @@ function mentionsEastValueType(node, ctx, seen) {
|
|
|
2282
2282
|
if (node.kind === t.SyntaxKind.AnyKeyword || node.kind === t.SyntaxKind.UnknownKeyword)
|
|
2283
2283
|
return true;
|
|
2284
2284
|
if (t.isTypeReferenceNode(node)) {
|
|
2285
|
-
const
|
|
2286
|
-
const symbol =
|
|
2285
|
+
const named2 = ctx.checker.getSymbolAtLocation(node.typeName);
|
|
2286
|
+
const symbol = named2 !== void 0 && (named2.flags & t.SymbolFlags.Alias) !== 0 ? ctx.checker.getAliasedSymbol(named2) : named2;
|
|
2287
2287
|
const declarations = symbol?.declarations ?? [];
|
|
2288
2288
|
if (declarations.some((d) => declaredByEast(d) || t.isTypeParameterDeclaration(d)))
|
|
2289
2289
|
return true;
|
|
@@ -2999,6 +2999,152 @@ var noJsCollectionForEastCollection = {
|
|
|
2999
2999
|
}
|
|
3000
3000
|
};
|
|
3001
3001
|
|
|
3002
|
+
// ../east-diagnostics/dist/src/rules/no-struct-type-from-object.js
|
|
3003
|
+
var NAME32 = "no-struct-type-from-object";
|
|
3004
|
+
var CODE32 = 990037;
|
|
3005
|
+
function isArrayIndex(name) {
|
|
3006
|
+
return /^(?:0|[1-9][0-9]{0,9})$/.test(name) && Number(name) <= 4294967294;
|
|
3007
|
+
}
|
|
3008
|
+
function isStructTypeCall(call, ctx) {
|
|
3009
|
+
const t = ctx.ts;
|
|
3010
|
+
const callee = call.expression;
|
|
3011
|
+
if (t.isIdentifier(callee)) {
|
|
3012
|
+
return resolvesToEastImport(callee, ctx.checker, t) && importedNameOf(callee, ctx.checker, t) === "StructType";
|
|
3013
|
+
}
|
|
3014
|
+
return t.isPropertyAccessExpression(callee) && callee.name.text === "StructType" && t.isIdentifier(callee.expression) && resolvesToEastImport(callee.expression, ctx.checker, t);
|
|
3015
|
+
}
|
|
3016
|
+
function unwrapped(e, t) {
|
|
3017
|
+
while (t.isParenthesizedExpression(e) || t.isAsExpression(e) || t.isSatisfiesExpression(e) || t.isNonNullExpression(e) || t.isTypeAssertionExpression(e))
|
|
3018
|
+
e = e.expression;
|
|
3019
|
+
return e;
|
|
3020
|
+
}
|
|
3021
|
+
function isList(type, ctx) {
|
|
3022
|
+
const constraint = type.isTypeParameter() ? ctx.checker.getBaseConstraintOfType(type) : type;
|
|
3023
|
+
return constraint !== void 0 && (ctx.checker.isArrayType(constraint) || ctx.checker.isTupleType(constraint));
|
|
3024
|
+
}
|
|
3025
|
+
var ORDERED = { kind: "ordered" };
|
|
3026
|
+
var RUNTIME = { kind: "object" };
|
|
3027
|
+
function named(names) {
|
|
3028
|
+
const index = names.find(isArrayIndex);
|
|
3029
|
+
return index === void 0 ? ORDERED : { kind: "index", name: index };
|
|
3030
|
+
}
|
|
3031
|
+
function literalNames(type) {
|
|
3032
|
+
const names = [];
|
|
3033
|
+
for (const member of type.isUnion() ? type.types : [type]) {
|
|
3034
|
+
if (member.isStringLiteral())
|
|
3035
|
+
names.push(member.value);
|
|
3036
|
+
else if (member.isNumberLiteral())
|
|
3037
|
+
names.push(String(member.value));
|
|
3038
|
+
else
|
|
3039
|
+
return void 0;
|
|
3040
|
+
}
|
|
3041
|
+
return names;
|
|
3042
|
+
}
|
|
3043
|
+
function memberOf(member, ctx) {
|
|
3044
|
+
const t = ctx.ts;
|
|
3045
|
+
if (t.isSpreadAssignment(member))
|
|
3046
|
+
return fieldsOf(member.expression, ctx);
|
|
3047
|
+
const n = member.name;
|
|
3048
|
+
if (t.isIdentifier(n) || t.isStringLiteral(n) || t.isNumericLiteral(n) || t.isNoSubstitutionTemplateLiteral(n))
|
|
3049
|
+
return named([n.text]);
|
|
3050
|
+
if (t.isComputedPropertyName(n)) {
|
|
3051
|
+
const names = literalNames(ctx.checker.getTypeAtLocation(n.expression));
|
|
3052
|
+
return names === void 0 ? RUNTIME : named(names);
|
|
3053
|
+
}
|
|
3054
|
+
return RUNTIME;
|
|
3055
|
+
}
|
|
3056
|
+
function fieldsOfType(type, ctx) {
|
|
3057
|
+
for (const member of type.isUnion() ? type.types : [type]) {
|
|
3058
|
+
const constraint = member.isTypeParameter() ? ctx.checker.getBaseConstraintOfType(member) : member;
|
|
3059
|
+
if (constraint === void 0 || ctx.checker.getIndexInfosOfType(constraint).length > 0)
|
|
3060
|
+
return RUNTIME;
|
|
3061
|
+
const fields = named(ctx.checker.getPropertiesOfType(constraint).map((p) => p.getName()));
|
|
3062
|
+
if (fields.kind !== "ordered")
|
|
3063
|
+
return fields;
|
|
3064
|
+
}
|
|
3065
|
+
return ORDERED;
|
|
3066
|
+
}
|
|
3067
|
+
function fieldsOf(arg, ctx) {
|
|
3068
|
+
const t = ctx.ts;
|
|
3069
|
+
const e = unwrapped(arg, t);
|
|
3070
|
+
if (t.isArrayLiteralExpression(e))
|
|
3071
|
+
return ORDERED;
|
|
3072
|
+
if (t.isObjectLiteralExpression(e)) {
|
|
3073
|
+
let fields = ORDERED;
|
|
3074
|
+
for (const member of e.properties) {
|
|
3075
|
+
const part = memberOf(member, ctx);
|
|
3076
|
+
if (part.kind === "index")
|
|
3077
|
+
return part;
|
|
3078
|
+
if (part.kind === "object")
|
|
3079
|
+
fields = part;
|
|
3080
|
+
}
|
|
3081
|
+
return fields;
|
|
3082
|
+
}
|
|
3083
|
+
const type = ctx.checker.getTypeAtLocation(e);
|
|
3084
|
+
if ((type.flags & (t.TypeFlags.Any | t.TypeFlags.Unknown)) !== 0)
|
|
3085
|
+
return ORDERED;
|
|
3086
|
+
if (isList(type, ctx))
|
|
3087
|
+
return ORDERED;
|
|
3088
|
+
return fieldsOfType(type, ctx);
|
|
3089
|
+
}
|
|
3090
|
+
function entriesFix(arg, ctx) {
|
|
3091
|
+
const t = ctx.ts;
|
|
3092
|
+
const e = unwrapped(arg, t);
|
|
3093
|
+
if (!t.isCallExpression(e) || e.arguments.length !== 1)
|
|
3094
|
+
return void 0;
|
|
3095
|
+
const callee = e.expression;
|
|
3096
|
+
if (!t.isPropertyAccessExpression(callee) || callee.name.text !== "fromEntries" || !t.isIdentifier(callee.expression) || callee.expression.text !== "Object")
|
|
3097
|
+
return void 0;
|
|
3098
|
+
const entries = e.arguments[0];
|
|
3099
|
+
if (!isList(ctx.checker.getTypeAtLocation(entries), ctx))
|
|
3100
|
+
return void 0;
|
|
3101
|
+
const sf = ctx.sourceFile;
|
|
3102
|
+
const start = arg.getStart(sf);
|
|
3103
|
+
return {
|
|
3104
|
+
description: "Pass the entries as the field list",
|
|
3105
|
+
changes: [{ start, length: arg.getEnd() - start, newText: entries.getText(sf) }]
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
var noStructTypeFromObject = {
|
|
3109
|
+
name: NAME32,
|
|
3110
|
+
code: CODE32,
|
|
3111
|
+
description: "Flag StructType given an object whose fields are known only at run time, or naming a field like an integer \u2014 declare the fields as a list, StructType([[name, type], \u2026]), which keeps their order.",
|
|
3112
|
+
check(node, ctx) {
|
|
3113
|
+
const t = ctx.ts;
|
|
3114
|
+
if (!t.isCallExpression(node) || node.arguments.length !== 1)
|
|
3115
|
+
return;
|
|
3116
|
+
if (!isStructTypeCall(node, ctx))
|
|
3117
|
+
return;
|
|
3118
|
+
const arg = node.arguments[0];
|
|
3119
|
+
const fields = fieldsOf(arg, ctx);
|
|
3120
|
+
if (fields.kind === "ordered")
|
|
3121
|
+
return;
|
|
3122
|
+
const sf = ctx.sourceFile;
|
|
3123
|
+
const start = arg.getStart(sf);
|
|
3124
|
+
if (fields.kind === "index") {
|
|
3125
|
+
ctx.report({
|
|
3126
|
+
ruleName: NAME32,
|
|
3127
|
+
code: CODE32,
|
|
3128
|
+
start,
|
|
3129
|
+
length: arg.getEnd() - start,
|
|
3130
|
+
messageText: `\`StructType\` names a field "${fields.name}", like an integer: an object lists such a name before every other, wherever it is written, so \`StructType\` refuses it. Declare the fields as a list, in their order: \`StructType([[name, type], \u2026])\`.`,
|
|
3131
|
+
category: "error"
|
|
3132
|
+
});
|
|
3133
|
+
return;
|
|
3134
|
+
}
|
|
3135
|
+
const fix = entriesFix(arg, ctx);
|
|
3136
|
+
ctx.report({
|
|
3137
|
+
ruleName: NAME32,
|
|
3138
|
+
code: CODE32,
|
|
3139
|
+
start,
|
|
3140
|
+
length: arg.getEnd() - start,
|
|
3141
|
+
messageText: '`StructType` is given an object whose fields are known only at run time: an object lists a name like an integer ("2024") before every other, so it cannot keep such a field in its place, and `StructType` refuses one. Pass the fields as a list, in their order \u2014 `StructType(entries)`, `StructType(Object.entries(type.fields).map(\u2026))` \u2014 which keeps any.',
|
|
3142
|
+
category: "warning",
|
|
3143
|
+
...fix === void 0 ? {} : { fix }
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
};
|
|
3147
|
+
|
|
3002
3148
|
// ../east-diagnostics/dist/src/rules/index.js
|
|
3003
3149
|
var allRules = [
|
|
3004
3150
|
// East-side idiom hygiene (original set)
|
|
@@ -3040,7 +3186,10 @@ var allRules = [
|
|
|
3040
3186
|
noHostPrintOfEastValues,
|
|
3041
3187
|
noHostParseToEastValues,
|
|
3042
3188
|
noJsTypeDispatchOnEastValues,
|
|
3043
|
-
noJsCollectionForEastCollection
|
|
3189
|
+
noJsCollectionForEastCollection,
|
|
3190
|
+
// a struct's fields in their order, whatever their names (#1574): never an
|
|
3191
|
+
// object built at run time
|
|
3192
|
+
noStructTypeFromObject
|
|
3044
3193
|
];
|
|
3045
3194
|
|
|
3046
3195
|
// ../east-diagnostics/dist/src/run.js
|
|
@@ -3090,6 +3239,13 @@ function validate(candidate) {
|
|
|
3090
3239
|
return null;
|
|
3091
3240
|
if (mod["IntegerType"] === void 0)
|
|
3092
3241
|
return null;
|
|
3242
|
+
try {
|
|
3243
|
+
const listed = mod["StructType"]([["a", mod["IntegerType"]]]);
|
|
3244
|
+
if (Object.keys(listed.fields ?? {})[0] !== "a")
|
|
3245
|
+
return null;
|
|
3246
|
+
} catch {
|
|
3247
|
+
return null;
|
|
3248
|
+
}
|
|
3093
3249
|
return mod;
|
|
3094
3250
|
}
|
|
3095
3251
|
function getEastModule(projectDir) {
|
|
@@ -3201,12 +3357,12 @@ function reifyEncoding(ctx, type, tag) {
|
|
|
3201
3357
|
}
|
|
3202
3358
|
case "Struct": {
|
|
3203
3359
|
const fieldsType = propType(ctx, type, "fields") ?? bail();
|
|
3204
|
-
const fields =
|
|
3360
|
+
const fields = [];
|
|
3205
3361
|
for (const prop of checker.getPropertiesOfType(fieldsType)) {
|
|
3206
3362
|
const name = prop.getName();
|
|
3207
3363
|
if (name.startsWith("__@"))
|
|
3208
3364
|
continue;
|
|
3209
|
-
fields[name
|
|
3365
|
+
fields.push([name, reifyUnion(ctx, stripAbsent(ctx, checker.getTypeOfSymbol(prop)))]);
|
|
3210
3366
|
}
|
|
3211
3367
|
return east.StructType(fields);
|
|
3212
3368
|
}
|
|
@@ -3315,12 +3471,12 @@ function reifyRawValue(ctx, type) {
|
|
|
3315
3471
|
const props = checker.getPropertiesOfType(type);
|
|
3316
3472
|
if (props.length === 0)
|
|
3317
3473
|
bail();
|
|
3318
|
-
const fields =
|
|
3474
|
+
const fields = [];
|
|
3319
3475
|
for (const prop of props) {
|
|
3320
3476
|
const propName = prop.getName();
|
|
3321
3477
|
if (propName.startsWith("__@"))
|
|
3322
3478
|
continue;
|
|
3323
|
-
fields[propName
|
|
3479
|
+
fields.push([propName, reifyUnion(ctx, stripAbsent(ctx, checker.getTypeOfSymbol(prop)))]);
|
|
3324
3480
|
}
|
|
3325
3481
|
return east.StructType(fields);
|
|
3326
3482
|
}
|
package/.build/daemon/server.js
CHANGED
|
@@ -1069,9 +1069,9 @@ function plainLiteralInitializer(decl, t) {
|
|
|
1069
1069
|
const init2 = decl.initializer;
|
|
1070
1070
|
if (init2 === void 0)
|
|
1071
1071
|
return void 0;
|
|
1072
|
-
const
|
|
1073
|
-
if (t.isArrayLiteralExpression(
|
|
1074
|
-
return
|
|
1072
|
+
const unwrapped2 = t.isAsExpression(init2) || t.isSatisfiesExpression(init2) ? init2.expression : init2;
|
|
1073
|
+
if (t.isArrayLiteralExpression(unwrapped2) || t.isObjectLiteralExpression(unwrapped2)) {
|
|
1074
|
+
return unwrapped2;
|
|
1075
1075
|
}
|
|
1076
1076
|
return void 0;
|
|
1077
1077
|
}
|
|
@@ -2286,8 +2286,8 @@ function mentionsEastValueType(node, ctx, seen) {
|
|
|
2286
2286
|
if (node.kind === t.SyntaxKind.AnyKeyword || node.kind === t.SyntaxKind.UnknownKeyword)
|
|
2287
2287
|
return true;
|
|
2288
2288
|
if (t.isTypeReferenceNode(node)) {
|
|
2289
|
-
const
|
|
2290
|
-
const symbol =
|
|
2289
|
+
const named2 = ctx.checker.getSymbolAtLocation(node.typeName);
|
|
2290
|
+
const symbol = named2 !== void 0 && (named2.flags & t.SymbolFlags.Alias) !== 0 ? ctx.checker.getAliasedSymbol(named2) : named2;
|
|
2291
2291
|
const declarations = symbol?.declarations ?? [];
|
|
2292
2292
|
if (declarations.some((d) => declaredByEast(d) || t.isTypeParameterDeclaration(d)))
|
|
2293
2293
|
return true;
|
|
@@ -3003,6 +3003,152 @@ var noJsCollectionForEastCollection = {
|
|
|
3003
3003
|
}
|
|
3004
3004
|
};
|
|
3005
3005
|
|
|
3006
|
+
// ../east-diagnostics/dist/src/rules/no-struct-type-from-object.js
|
|
3007
|
+
var NAME32 = "no-struct-type-from-object";
|
|
3008
|
+
var CODE32 = 990037;
|
|
3009
|
+
function isArrayIndex(name) {
|
|
3010
|
+
return /^(?:0|[1-9][0-9]{0,9})$/.test(name) && Number(name) <= 4294967294;
|
|
3011
|
+
}
|
|
3012
|
+
function isStructTypeCall(call, ctx) {
|
|
3013
|
+
const t = ctx.ts;
|
|
3014
|
+
const callee = call.expression;
|
|
3015
|
+
if (t.isIdentifier(callee)) {
|
|
3016
|
+
return resolvesToEastImport(callee, ctx.checker, t) && importedNameOf(callee, ctx.checker, t) === "StructType";
|
|
3017
|
+
}
|
|
3018
|
+
return t.isPropertyAccessExpression(callee) && callee.name.text === "StructType" && t.isIdentifier(callee.expression) && resolvesToEastImport(callee.expression, ctx.checker, t);
|
|
3019
|
+
}
|
|
3020
|
+
function unwrapped(e, t) {
|
|
3021
|
+
while (t.isParenthesizedExpression(e) || t.isAsExpression(e) || t.isSatisfiesExpression(e) || t.isNonNullExpression(e) || t.isTypeAssertionExpression(e))
|
|
3022
|
+
e = e.expression;
|
|
3023
|
+
return e;
|
|
3024
|
+
}
|
|
3025
|
+
function isList(type, ctx) {
|
|
3026
|
+
const constraint = type.isTypeParameter() ? ctx.checker.getBaseConstraintOfType(type) : type;
|
|
3027
|
+
return constraint !== void 0 && (ctx.checker.isArrayType(constraint) || ctx.checker.isTupleType(constraint));
|
|
3028
|
+
}
|
|
3029
|
+
var ORDERED = { kind: "ordered" };
|
|
3030
|
+
var RUNTIME = { kind: "object" };
|
|
3031
|
+
function named(names) {
|
|
3032
|
+
const index = names.find(isArrayIndex);
|
|
3033
|
+
return index === void 0 ? ORDERED : { kind: "index", name: index };
|
|
3034
|
+
}
|
|
3035
|
+
function literalNames(type) {
|
|
3036
|
+
const names = [];
|
|
3037
|
+
for (const member of type.isUnion() ? type.types : [type]) {
|
|
3038
|
+
if (member.isStringLiteral())
|
|
3039
|
+
names.push(member.value);
|
|
3040
|
+
else if (member.isNumberLiteral())
|
|
3041
|
+
names.push(String(member.value));
|
|
3042
|
+
else
|
|
3043
|
+
return void 0;
|
|
3044
|
+
}
|
|
3045
|
+
return names;
|
|
3046
|
+
}
|
|
3047
|
+
function memberOf(member, ctx) {
|
|
3048
|
+
const t = ctx.ts;
|
|
3049
|
+
if (t.isSpreadAssignment(member))
|
|
3050
|
+
return fieldsOf(member.expression, ctx);
|
|
3051
|
+
const n = member.name;
|
|
3052
|
+
if (t.isIdentifier(n) || t.isStringLiteral(n) || t.isNumericLiteral(n) || t.isNoSubstitutionTemplateLiteral(n))
|
|
3053
|
+
return named([n.text]);
|
|
3054
|
+
if (t.isComputedPropertyName(n)) {
|
|
3055
|
+
const names = literalNames(ctx.checker.getTypeAtLocation(n.expression));
|
|
3056
|
+
return names === void 0 ? RUNTIME : named(names);
|
|
3057
|
+
}
|
|
3058
|
+
return RUNTIME;
|
|
3059
|
+
}
|
|
3060
|
+
function fieldsOfType(type, ctx) {
|
|
3061
|
+
for (const member of type.isUnion() ? type.types : [type]) {
|
|
3062
|
+
const constraint = member.isTypeParameter() ? ctx.checker.getBaseConstraintOfType(member) : member;
|
|
3063
|
+
if (constraint === void 0 || ctx.checker.getIndexInfosOfType(constraint).length > 0)
|
|
3064
|
+
return RUNTIME;
|
|
3065
|
+
const fields = named(ctx.checker.getPropertiesOfType(constraint).map((p) => p.getName()));
|
|
3066
|
+
if (fields.kind !== "ordered")
|
|
3067
|
+
return fields;
|
|
3068
|
+
}
|
|
3069
|
+
return ORDERED;
|
|
3070
|
+
}
|
|
3071
|
+
function fieldsOf(arg, ctx) {
|
|
3072
|
+
const t = ctx.ts;
|
|
3073
|
+
const e = unwrapped(arg, t);
|
|
3074
|
+
if (t.isArrayLiteralExpression(e))
|
|
3075
|
+
return ORDERED;
|
|
3076
|
+
if (t.isObjectLiteralExpression(e)) {
|
|
3077
|
+
let fields = ORDERED;
|
|
3078
|
+
for (const member of e.properties) {
|
|
3079
|
+
const part = memberOf(member, ctx);
|
|
3080
|
+
if (part.kind === "index")
|
|
3081
|
+
return part;
|
|
3082
|
+
if (part.kind === "object")
|
|
3083
|
+
fields = part;
|
|
3084
|
+
}
|
|
3085
|
+
return fields;
|
|
3086
|
+
}
|
|
3087
|
+
const type = ctx.checker.getTypeAtLocation(e);
|
|
3088
|
+
if ((type.flags & (t.TypeFlags.Any | t.TypeFlags.Unknown)) !== 0)
|
|
3089
|
+
return ORDERED;
|
|
3090
|
+
if (isList(type, ctx))
|
|
3091
|
+
return ORDERED;
|
|
3092
|
+
return fieldsOfType(type, ctx);
|
|
3093
|
+
}
|
|
3094
|
+
function entriesFix(arg, ctx) {
|
|
3095
|
+
const t = ctx.ts;
|
|
3096
|
+
const e = unwrapped(arg, t);
|
|
3097
|
+
if (!t.isCallExpression(e) || e.arguments.length !== 1)
|
|
3098
|
+
return void 0;
|
|
3099
|
+
const callee = e.expression;
|
|
3100
|
+
if (!t.isPropertyAccessExpression(callee) || callee.name.text !== "fromEntries" || !t.isIdentifier(callee.expression) || callee.expression.text !== "Object")
|
|
3101
|
+
return void 0;
|
|
3102
|
+
const entries = e.arguments[0];
|
|
3103
|
+
if (!isList(ctx.checker.getTypeAtLocation(entries), ctx))
|
|
3104
|
+
return void 0;
|
|
3105
|
+
const sf = ctx.sourceFile;
|
|
3106
|
+
const start = arg.getStart(sf);
|
|
3107
|
+
return {
|
|
3108
|
+
description: "Pass the entries as the field list",
|
|
3109
|
+
changes: [{ start, length: arg.getEnd() - start, newText: entries.getText(sf) }]
|
|
3110
|
+
};
|
|
3111
|
+
}
|
|
3112
|
+
var noStructTypeFromObject = {
|
|
3113
|
+
name: NAME32,
|
|
3114
|
+
code: CODE32,
|
|
3115
|
+
description: "Flag StructType given an object whose fields are known only at run time, or naming a field like an integer \u2014 declare the fields as a list, StructType([[name, type], \u2026]), which keeps their order.",
|
|
3116
|
+
check(node, ctx) {
|
|
3117
|
+
const t = ctx.ts;
|
|
3118
|
+
if (!t.isCallExpression(node) || node.arguments.length !== 1)
|
|
3119
|
+
return;
|
|
3120
|
+
if (!isStructTypeCall(node, ctx))
|
|
3121
|
+
return;
|
|
3122
|
+
const arg = node.arguments[0];
|
|
3123
|
+
const fields = fieldsOf(arg, ctx);
|
|
3124
|
+
if (fields.kind === "ordered")
|
|
3125
|
+
return;
|
|
3126
|
+
const sf = ctx.sourceFile;
|
|
3127
|
+
const start = arg.getStart(sf);
|
|
3128
|
+
if (fields.kind === "index") {
|
|
3129
|
+
ctx.report({
|
|
3130
|
+
ruleName: NAME32,
|
|
3131
|
+
code: CODE32,
|
|
3132
|
+
start,
|
|
3133
|
+
length: arg.getEnd() - start,
|
|
3134
|
+
messageText: `\`StructType\` names a field "${fields.name}", like an integer: an object lists such a name before every other, wherever it is written, so \`StructType\` refuses it. Declare the fields as a list, in their order: \`StructType([[name, type], \u2026])\`.`,
|
|
3135
|
+
category: "error"
|
|
3136
|
+
});
|
|
3137
|
+
return;
|
|
3138
|
+
}
|
|
3139
|
+
const fix = entriesFix(arg, ctx);
|
|
3140
|
+
ctx.report({
|
|
3141
|
+
ruleName: NAME32,
|
|
3142
|
+
code: CODE32,
|
|
3143
|
+
start,
|
|
3144
|
+
length: arg.getEnd() - start,
|
|
3145
|
+
messageText: '`StructType` is given an object whose fields are known only at run time: an object lists a name like an integer ("2024") before every other, so it cannot keep such a field in its place, and `StructType` refuses one. Pass the fields as a list, in their order \u2014 `StructType(entries)`, `StructType(Object.entries(type.fields).map(\u2026))` \u2014 which keeps any.',
|
|
3146
|
+
category: "warning",
|
|
3147
|
+
...fix === void 0 ? {} : { fix }
|
|
3148
|
+
});
|
|
3149
|
+
}
|
|
3150
|
+
};
|
|
3151
|
+
|
|
3006
3152
|
// ../east-diagnostics/dist/src/rules/index.js
|
|
3007
3153
|
var allRules = [
|
|
3008
3154
|
// East-side idiom hygiene (original set)
|
|
@@ -3044,7 +3190,10 @@ var allRules = [
|
|
|
3044
3190
|
noHostPrintOfEastValues,
|
|
3045
3191
|
noHostParseToEastValues,
|
|
3046
3192
|
noJsTypeDispatchOnEastValues,
|
|
3047
|
-
noJsCollectionForEastCollection
|
|
3193
|
+
noJsCollectionForEastCollection,
|
|
3194
|
+
// a struct's fields in their order, whatever their names (#1574): never an
|
|
3195
|
+
// object built at run time
|
|
3196
|
+
noStructTypeFromObject
|
|
3048
3197
|
];
|
|
3049
3198
|
|
|
3050
3199
|
// ../east-diagnostics/dist/src/run.js
|
|
@@ -3094,6 +3243,13 @@ function validate(candidate) {
|
|
|
3094
3243
|
return null;
|
|
3095
3244
|
if (mod["IntegerType"] === void 0)
|
|
3096
3245
|
return null;
|
|
3246
|
+
try {
|
|
3247
|
+
const listed = mod["StructType"]([["a", mod["IntegerType"]]]);
|
|
3248
|
+
if (Object.keys(listed.fields ?? {})[0] !== "a")
|
|
3249
|
+
return null;
|
|
3250
|
+
} catch {
|
|
3251
|
+
return null;
|
|
3252
|
+
}
|
|
3097
3253
|
return mod;
|
|
3098
3254
|
}
|
|
3099
3255
|
function getEastModule(projectDir) {
|
|
@@ -3205,12 +3361,12 @@ function reifyEncoding(ctx, type, tag) {
|
|
|
3205
3361
|
}
|
|
3206
3362
|
case "Struct": {
|
|
3207
3363
|
const fieldsType = propType(ctx, type, "fields") ?? bail();
|
|
3208
|
-
const fields =
|
|
3364
|
+
const fields = [];
|
|
3209
3365
|
for (const prop of checker.getPropertiesOfType(fieldsType)) {
|
|
3210
3366
|
const name = prop.getName();
|
|
3211
3367
|
if (name.startsWith("__@"))
|
|
3212
3368
|
continue;
|
|
3213
|
-
fields[name
|
|
3369
|
+
fields.push([name, reifyUnion(ctx, stripAbsent(ctx, checker.getTypeOfSymbol(prop)))]);
|
|
3214
3370
|
}
|
|
3215
3371
|
return east.StructType(fields);
|
|
3216
3372
|
}
|
|
@@ -3319,12 +3475,12 @@ function reifyRawValue(ctx, type) {
|
|
|
3319
3475
|
const props = checker.getPropertiesOfType(type);
|
|
3320
3476
|
if (props.length === 0)
|
|
3321
3477
|
bail();
|
|
3322
|
-
const fields =
|
|
3478
|
+
const fields = [];
|
|
3323
3479
|
for (const prop of props) {
|
|
3324
3480
|
const propName = prop.getName();
|
|
3325
3481
|
if (propName.startsWith("__@"))
|
|
3326
3482
|
continue;
|
|
3327
|
-
fields[propName
|
|
3483
|
+
fields.push([propName, reifyUnion(ctx, stripAbsent(ctx, checker.getTypeOfSymbol(prop)))]);
|
|
3328
3484
|
}
|
|
3329
3485
|
return east.StructType(fields);
|
|
3330
3486
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "east-codex-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.107",
|
|
4
4
|
"description": "East programming language ecosystem - a statically typed, expression-based language for business logic, data processing, UI definitions, and durable execution",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Elara AI",
|