@effect/language-service 0.77.0 → 0.78.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/README.md +2 -1
- package/cli.js +1447 -761
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +409 -124
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +425 -147
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +409 -124
- package/transform.js.map +1 -1
|
@@ -27,7 +27,7 @@ __export(effect_lsp_patch_utils_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(effect_lsp_patch_utils_exports);
|
|
29
29
|
|
|
30
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
30
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Pipeable.js
|
|
31
31
|
var pipeArguments = (self, args3) => {
|
|
32
32
|
switch (args3.length) {
|
|
33
33
|
case 0:
|
|
@@ -60,7 +60,7 @@ var pipeArguments = (self, args3) => {
|
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
63
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Function.js
|
|
64
64
|
var dual = function(arity, body) {
|
|
65
65
|
if (typeof arity === "function") {
|
|
66
66
|
return function() {
|
|
@@ -108,7 +108,7 @@ function pipe(a, ...args3) {
|
|
|
108
108
|
return pipeArguments(a, args3);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
111
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/equal.js
|
|
112
112
|
var getAllObjectKeys = (obj) => {
|
|
113
113
|
const keys2 = new Set(Reflect.ownKeys(obj));
|
|
114
114
|
if (obj.constructor === Object) return keys2;
|
|
@@ -131,7 +131,7 @@ var getAllObjectKeys = (obj) => {
|
|
|
131
131
|
};
|
|
132
132
|
var byReferenceInstances = /* @__PURE__ */ new WeakSet();
|
|
133
133
|
|
|
134
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
134
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Predicate.js
|
|
135
135
|
function isString(input) {
|
|
136
136
|
return typeof input === "string";
|
|
137
137
|
}
|
|
@@ -152,7 +152,7 @@ function isObjectKeyword(input) {
|
|
|
152
152
|
}
|
|
153
153
|
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObjectKeyword(self) && property in self);
|
|
154
154
|
|
|
155
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
155
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Hash.js
|
|
156
156
|
var symbol = "~effect/interfaces/Hash";
|
|
157
157
|
var hash = (self) => {
|
|
158
158
|
switch (typeof self) {
|
|
@@ -271,7 +271,7 @@ function withVisitedTracking(obj, fn2) {
|
|
|
271
271
|
return result;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
274
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Equal.js
|
|
275
275
|
var symbol2 = "~effect/interfaces/Equal";
|
|
276
276
|
function equals() {
|
|
277
277
|
if (arguments.length === 1) {
|
|
@@ -433,7 +433,10 @@ var compareSets = /* @__PURE__ */ makeCompareSet(compareBoth);
|
|
|
433
433
|
var isEqual = (u) => hasProperty(u, symbol2);
|
|
434
434
|
var asEquivalence = () => equals;
|
|
435
435
|
|
|
436
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
436
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/array.js
|
|
437
|
+
var isArrayNonEmpty = (self) => self.length > 0;
|
|
438
|
+
|
|
439
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Redactable.js
|
|
437
440
|
var symbolRedactable = /* @__PURE__ */ Symbol.for("~effect/Inspectable/redactable");
|
|
438
441
|
var isRedactable = (u) => hasProperty(u, symbolRedactable);
|
|
439
442
|
function redact(u) {
|
|
@@ -452,7 +455,7 @@ var emptyServiceMap = {
|
|
|
452
455
|
}
|
|
453
456
|
};
|
|
454
457
|
|
|
455
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
458
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Formatter.js
|
|
456
459
|
function format(input, options) {
|
|
457
460
|
const space = options?.space ?? 0;
|
|
458
461
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
@@ -531,7 +534,7 @@ function safeToString(input) {
|
|
|
531
534
|
}
|
|
532
535
|
}
|
|
533
536
|
|
|
534
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
537
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Inspectable.js
|
|
535
538
|
var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
536
539
|
var toJson = (input) => {
|
|
537
540
|
try {
|
|
@@ -575,7 +578,7 @@ var Class = class {
|
|
|
575
578
|
}
|
|
576
579
|
};
|
|
577
580
|
|
|
578
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
581
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Utils.js
|
|
579
582
|
var GenKindTypeId = "~effect/Utils/GenKind";
|
|
580
583
|
var GenKindImpl = class {
|
|
581
584
|
value;
|
|
@@ -643,7 +646,7 @@ var internalCall = isNotOptimizedAway ? standard[InternalTypeId] : forced[Intern
|
|
|
643
646
|
var genConstructor = function* () {
|
|
644
647
|
}.constructor;
|
|
645
648
|
|
|
646
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
649
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/core.js
|
|
647
650
|
var EffectTypeId = `~effect/Effect`;
|
|
648
651
|
var ExitTypeId = `~effect/Exit`;
|
|
649
652
|
var effectVariance = {
|
|
@@ -990,7 +993,7 @@ var DoneVoid = {
|
|
|
990
993
|
value: void 0
|
|
991
994
|
};
|
|
992
995
|
|
|
993
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
996
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/option.js
|
|
994
997
|
var TypeId = "~effect/data/Option";
|
|
995
998
|
var CommonProto = {
|
|
996
999
|
[TypeId]: {
|
|
@@ -1055,7 +1058,7 @@ var some = (value) => {
|
|
|
1055
1058
|
return a;
|
|
1056
1059
|
};
|
|
1057
1060
|
|
|
1058
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1061
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/result.js
|
|
1059
1062
|
var TypeId2 = "~effect/data/Result";
|
|
1060
1063
|
var CommonProto2 = {
|
|
1061
1064
|
[TypeId2]: {
|
|
@@ -1126,13 +1129,13 @@ var succeed = (success) => {
|
|
|
1126
1129
|
return a;
|
|
1127
1130
|
};
|
|
1128
1131
|
|
|
1129
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1132
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Order.js
|
|
1130
1133
|
function make(compare) {
|
|
1131
1134
|
return (self, that) => self === that ? 0 : compare(self, that);
|
|
1132
1135
|
}
|
|
1133
1136
|
var String2 = /* @__PURE__ */ make((self, that) => self < that ? -1 : 1);
|
|
1134
1137
|
|
|
1135
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1138
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Option.js
|
|
1136
1139
|
var none2 = () => none;
|
|
1137
1140
|
var some2 = some;
|
|
1138
1141
|
var isNone2 = isNone;
|
|
@@ -1142,7 +1145,7 @@ var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : se
|
|
|
1142
1145
|
var fromNullishOr = (a) => a == null ? none2() : some2(a);
|
|
1143
1146
|
var getOrUndefined = /* @__PURE__ */ getOrElse(constUndefined);
|
|
1144
1147
|
|
|
1145
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1148
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Result.js
|
|
1146
1149
|
var succeed2 = succeed;
|
|
1147
1150
|
var fail2 = fail;
|
|
1148
1151
|
var isFailure2 = isFailure;
|
|
@@ -1150,18 +1153,7 @@ var isSuccess2 = isSuccess;
|
|
|
1150
1153
|
var map = /* @__PURE__ */ dual(2, (self, f) => isSuccess2(self) ? succeed2(f(self.success)) : fail2(self.failure));
|
|
1151
1154
|
var getOrElse2 = /* @__PURE__ */ dual(2, (self, onFailure) => isFailure2(self) ? onFailure(self.failure) : self.success);
|
|
1152
1155
|
|
|
1153
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1154
|
-
var apply = (filter2, input, ...args3) => {
|
|
1155
|
-
const result = filter2(input, ...args3);
|
|
1156
|
-
if (result === true) return succeed2(input);
|
|
1157
|
-
if (result === false) return fail2(input);
|
|
1158
|
-
return result;
|
|
1159
|
-
};
|
|
1160
|
-
|
|
1161
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.14/node_modules/effect/dist/internal/array.js
|
|
1162
|
-
var isArrayNonEmpty = (self) => self.length > 0;
|
|
1163
|
-
|
|
1164
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.14/node_modules/effect/dist/Record.js
|
|
1156
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Record.js
|
|
1165
1157
|
var map2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1166
1158
|
const out = {
|
|
1167
1159
|
...self
|
|
@@ -1173,7 +1165,7 @@ var map2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
|
1173
1165
|
});
|
|
1174
1166
|
var keys = (self) => Object.keys(self);
|
|
1175
1167
|
|
|
1176
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1168
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Array.js
|
|
1177
1169
|
var Array2 = globalThis.Array;
|
|
1178
1170
|
var fromIterable = (collection) => Array2.isArray(collection) ? collection : Array2.from(collection);
|
|
1179
1171
|
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
@@ -1236,13 +1228,12 @@ var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
|
|
|
1236
1228
|
return out;
|
|
1237
1229
|
});
|
|
1238
1230
|
var flatten = /* @__PURE__ */ flatMap(identity);
|
|
1239
|
-
var filter = /* @__PURE__ */ dual(2, (self,
|
|
1231
|
+
var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
|
|
1240
1232
|
const as = fromIterable(self);
|
|
1241
1233
|
const out = [];
|
|
1242
1234
|
for (let i = 0; i < as.length; i++) {
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
out.push(result.success);
|
|
1235
|
+
if (predicate(as[i], i)) {
|
|
1236
|
+
out.push(as[i]);
|
|
1246
1237
|
}
|
|
1247
1238
|
}
|
|
1248
1239
|
return out;
|
|
@@ -1689,7 +1680,9 @@ function parse(config) {
|
|
|
1689
1680
|
keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns,
|
|
1690
1681
|
extendedKeyDetection: isObject(config) && hasProperty(config, "extendedKeyDetection") && isBoolean(config.extendedKeyDetection) ? config.extendedKeyDetection : defaults.extendedKeyDetection,
|
|
1691
1682
|
pipeableMinArgCount: isObject(config) && hasProperty(config, "pipeableMinArgCount") && isNumber(config.pipeableMinArgCount) ? config.pipeableMinArgCount : defaults.pipeableMinArgCount,
|
|
1692
|
-
effectFn: isObject(config) && hasProperty(config, "effectFn") && isArray(config.effectFn) && config.effectFn.every(isString) ? config.effectFn.map(
|
|
1683
|
+
effectFn: isObject(config) && hasProperty(config, "effectFn") && isArray(config.effectFn) && config.effectFn.every(isString) ? config.effectFn.map(
|
|
1684
|
+
(_) => _.toLowerCase()
|
|
1685
|
+
) : defaults.effectFn,
|
|
1693
1686
|
layerGraphFollowDepth: isObject(config) && hasProperty(config, "layerGraphFollowDepth") && isNumber(config.layerGraphFollowDepth) ? config.layerGraphFollowDepth : defaults.layerGraphFollowDepth,
|
|
1694
1687
|
mermaidProvider: isObject(config) && hasProperty(config, "mermaidProvider") && isString(config.mermaidProvider) ? config.mermaidProvider : defaults.mermaidProvider
|
|
1695
1688
|
};
|
|
@@ -3381,6 +3374,14 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3381
3374
|
const layerType = cachedBy(
|
|
3382
3375
|
fn("TypeParser.layerType")(function* (type, atLocation) {
|
|
3383
3376
|
yield* pipeableType(type, atLocation);
|
|
3377
|
+
if (supportedEffect() === "v4") {
|
|
3378
|
+
const typeIdSymbol = typeChecker.getPropertyOfType(type, "~effect/Layer");
|
|
3379
|
+
if (typeIdSymbol) {
|
|
3380
|
+
const typeIdType = typeChecker.getTypeOfSymbolAtLocation(typeIdSymbol, atLocation);
|
|
3381
|
+
return yield* layerVarianceStruct(typeIdType, atLocation);
|
|
3382
|
+
}
|
|
3383
|
+
return yield* typeParserIssue("Type is not a layer", type, atLocation);
|
|
3384
|
+
}
|
|
3384
3385
|
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
3385
3386
|
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
|
|
3386
3387
|
);
|
|
@@ -3430,6 +3431,34 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3430
3431
|
"TypeParser.effectSubtype",
|
|
3431
3432
|
(type) => type
|
|
3432
3433
|
);
|
|
3434
|
+
const effectYieldableType = cachedBy(
|
|
3435
|
+
fn("TypeParser.effectYieldableType")(function* (type, atLocation) {
|
|
3436
|
+
if (supportedEffect() === "v3") {
|
|
3437
|
+
return yield* effectType(type, atLocation);
|
|
3438
|
+
}
|
|
3439
|
+
return yield* firstSuccessOf([
|
|
3440
|
+
effectType(type, atLocation),
|
|
3441
|
+
gen(function* () {
|
|
3442
|
+
const asEffectSymbol = typeChecker.getPropertyOfType(type, "asEffect");
|
|
3443
|
+
if (!asEffectSymbol) {
|
|
3444
|
+
return yield* typeParserIssue("Type has no 'asEffect' property", type, atLocation);
|
|
3445
|
+
}
|
|
3446
|
+
const asEffectType = typeChecker.getTypeOfSymbolAtLocation(asEffectSymbol, atLocation);
|
|
3447
|
+
const asEffectSignatures = typeChecker.getSignaturesOfType(asEffectType, ts.SignatureKind.Call);
|
|
3448
|
+
if (asEffectSignatures.length === 0) {
|
|
3449
|
+
return yield* typeParserIssue("'asEffect' property is not callable", type, atLocation);
|
|
3450
|
+
}
|
|
3451
|
+
return yield* firstSuccessOf(
|
|
3452
|
+
asEffectSignatures.map(
|
|
3453
|
+
(signature) => effectType(typeChecker.getReturnTypeOfSignature(signature), atLocation)
|
|
3454
|
+
)
|
|
3455
|
+
);
|
|
3456
|
+
})
|
|
3457
|
+
]);
|
|
3458
|
+
}),
|
|
3459
|
+
"TypeParser.effectYieldableType",
|
|
3460
|
+
(type) => type
|
|
3461
|
+
);
|
|
3433
3462
|
const isEffectContextSourceFile = cachedBy(
|
|
3434
3463
|
fn("TypeParser.isEffectContextSourceFile")(function* (sourceFile) {
|
|
3435
3464
|
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
@@ -5057,6 +5086,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
5057
5086
|
layerType,
|
|
5058
5087
|
fiberType,
|
|
5059
5088
|
effectSubtype,
|
|
5089
|
+
effectYieldableType,
|
|
5060
5090
|
importedEffectModule,
|
|
5061
5091
|
effectGen,
|
|
5062
5092
|
effectFnUntracedGen,
|
|
@@ -5769,16 +5799,16 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5769
5799
|
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
5770
5800
|
return node.name;
|
|
5771
5801
|
}
|
|
5772
|
-
if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
|
|
5802
|
+
if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name) && node.parent.initializer === node) {
|
|
5773
5803
|
return node.parent.name;
|
|
5774
5804
|
}
|
|
5775
|
-
if (node.parent && ts.isPropertyAssignment(node.parent)) {
|
|
5805
|
+
if (node.parent && ts.isPropertyAssignment(node.parent) && node.parent.initializer === node) {
|
|
5776
5806
|
const name = node.parent.name;
|
|
5777
5807
|
if (ts.isIdentifier(name) || ts.isStringLiteral(name)) {
|
|
5778
5808
|
return name;
|
|
5779
5809
|
}
|
|
5780
5810
|
}
|
|
5781
|
-
if (node.parent && ts.isPropertyDeclaration(node.parent)) {
|
|
5811
|
+
if (node.parent && ts.isPropertyDeclaration(node.parent) && node.parent.initializer === node) {
|
|
5782
5812
|
const name = node.parent.name;
|
|
5783
5813
|
if (ts.isIdentifier(name)) {
|
|
5784
5814
|
return name;
|
|
@@ -5786,6 +5816,190 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5786
5816
|
}
|
|
5787
5817
|
return void 0;
|
|
5788
5818
|
};
|
|
5819
|
+
const hasExportModifier = (node) => {
|
|
5820
|
+
if (!ts.canHaveModifiers(node)) return false;
|
|
5821
|
+
const modifiers = ts.getModifiers(node);
|
|
5822
|
+
return modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
5823
|
+
};
|
|
5824
|
+
const layerServiceNameFromExpression = (expression) => {
|
|
5825
|
+
if (expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
5826
|
+
const enclosingClass = ts.findAncestor(
|
|
5827
|
+
expression,
|
|
5828
|
+
(node) => ts.isClassDeclaration(node)
|
|
5829
|
+
);
|
|
5830
|
+
if (enclosingClass?.name) {
|
|
5831
|
+
return ts.idText(enclosingClass.name);
|
|
5832
|
+
}
|
|
5833
|
+
}
|
|
5834
|
+
if (ts.isIdentifier(expression)) return ts.idText(expression);
|
|
5835
|
+
return sourceFile.text.slice(expression.pos, expression.end).trim();
|
|
5836
|
+
};
|
|
5837
|
+
const tryGetLayerApiMethod = (node) => pipe(
|
|
5838
|
+
typeParser.isNodeReferenceToEffectLayerModuleApi("effect")(node),
|
|
5839
|
+
map4(() => "effect"),
|
|
5840
|
+
orElse2(
|
|
5841
|
+
() => pipe(
|
|
5842
|
+
typeParser.isNodeReferenceToEffectLayerModuleApi("succeed")(node),
|
|
5843
|
+
map4(() => "succeed"),
|
|
5844
|
+
orElse2(
|
|
5845
|
+
() => pipe(
|
|
5846
|
+
typeParser.isNodeReferenceToEffectLayerModuleApi("sync")(node),
|
|
5847
|
+
map4(() => "sync"),
|
|
5848
|
+
orElse2(() => succeed3(void 0))
|
|
5849
|
+
)
|
|
5850
|
+
)
|
|
5851
|
+
)
|
|
5852
|
+
)
|
|
5853
|
+
);
|
|
5854
|
+
const verifyLayerMethodAtCall = fn("effectFnOpportunity.verifyLayerMethodAtCall")(
|
|
5855
|
+
function* (callExpression, method, implementationExpression) {
|
|
5856
|
+
const directMethod = yield* tryGetLayerApiMethod(callExpression.expression);
|
|
5857
|
+
if (directMethod === method && callExpression.arguments.length >= 2 && callExpression.arguments[1] === implementationExpression) {
|
|
5858
|
+
return layerServiceNameFromExpression(callExpression.arguments[0]);
|
|
5859
|
+
}
|
|
5860
|
+
if (ts.isCallExpression(callExpression.expression)) {
|
|
5861
|
+
const innerCall = callExpression.expression;
|
|
5862
|
+
const innerMethod = yield* tryGetLayerApiMethod(innerCall.expression);
|
|
5863
|
+
if (innerMethod === method && innerCall.arguments.length >= 1 && callExpression.arguments.length >= 1 && callExpression.arguments[0] === implementationExpression) {
|
|
5864
|
+
return layerServiceNameFromExpression(innerCall.arguments[0]);
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
5867
|
+
return void 0;
|
|
5868
|
+
}
|
|
5869
|
+
);
|
|
5870
|
+
const tryMatchLayerSucceedInference = fn("effectFnOpportunity.tryMatchLayerSucceedInference")(
|
|
5871
|
+
function* (objectLiteral) {
|
|
5872
|
+
const callExpression = objectLiteral.parent;
|
|
5873
|
+
if (!callExpression || !ts.isCallExpression(callExpression)) return void 0;
|
|
5874
|
+
return yield* verifyLayerMethodAtCall(callExpression, "succeed", objectLiteral);
|
|
5875
|
+
}
|
|
5876
|
+
);
|
|
5877
|
+
const tryMatchLayerSyncInference = fn("effectFnOpportunity.tryMatchLayerSyncInference")(
|
|
5878
|
+
function* (objectLiteral) {
|
|
5879
|
+
const returnStatement = objectLiteral.parent;
|
|
5880
|
+
if (!returnStatement || !ts.isReturnStatement(returnStatement)) return void 0;
|
|
5881
|
+
const functionBody = returnStatement.parent;
|
|
5882
|
+
if (!functionBody || !ts.isBlock(functionBody)) return void 0;
|
|
5883
|
+
const lazyFunction = functionBody.parent;
|
|
5884
|
+
if (!lazyFunction || !ts.isArrowFunction(lazyFunction) && !ts.isFunctionExpression(lazyFunction)) {
|
|
5885
|
+
return void 0;
|
|
5886
|
+
}
|
|
5887
|
+
const callExpression = lazyFunction.parent;
|
|
5888
|
+
if (!callExpression || !ts.isCallExpression(callExpression)) return void 0;
|
|
5889
|
+
return yield* verifyLayerMethodAtCall(callExpression, "sync", lazyFunction);
|
|
5890
|
+
}
|
|
5891
|
+
);
|
|
5892
|
+
const tryMatchLayerEffectInference = fn("effectFnOpportunity.tryMatchLayerEffectInference")(
|
|
5893
|
+
function* (objectLiteral) {
|
|
5894
|
+
const returnStatement = objectLiteral.parent;
|
|
5895
|
+
if (!returnStatement || !ts.isReturnStatement(returnStatement)) return void 0;
|
|
5896
|
+
const generatorBody = returnStatement.parent;
|
|
5897
|
+
if (!generatorBody || !ts.isBlock(generatorBody)) return void 0;
|
|
5898
|
+
const generatorFunction = generatorBody.parent;
|
|
5899
|
+
if (!generatorFunction || !ts.isFunctionExpression(generatorFunction) || !generatorFunction.asteriskToken) {
|
|
5900
|
+
return void 0;
|
|
5901
|
+
}
|
|
5902
|
+
const genCall = generatorFunction.parent;
|
|
5903
|
+
if (!genCall || !ts.isCallExpression(genCall)) return void 0;
|
|
5904
|
+
const parsedEffectGen = yield* option(typeParser.effectGen(genCall));
|
|
5905
|
+
if (parsedEffectGen._tag === "None" || parsedEffectGen.value.generatorFunction !== generatorFunction) {
|
|
5906
|
+
return void 0;
|
|
5907
|
+
}
|
|
5908
|
+
const layerCall = genCall.parent;
|
|
5909
|
+
if (!layerCall || !ts.isCallExpression(layerCall)) return void 0;
|
|
5910
|
+
return yield* verifyLayerMethodAtCall(layerCall, "effect", genCall);
|
|
5911
|
+
}
|
|
5912
|
+
);
|
|
5913
|
+
const tryMatchOfInference = fn("effectFnOpportunity.tryMatchOfInference")(
|
|
5914
|
+
function* (objectLiteral) {
|
|
5915
|
+
const callExpression = objectLiteral.parent;
|
|
5916
|
+
if (!callExpression || !ts.isCallExpression(callExpression)) return void 0;
|
|
5917
|
+
if (callExpression.arguments.length < 1 || callExpression.arguments[0] !== objectLiteral) return void 0;
|
|
5918
|
+
if (!ts.isPropertyAccessExpression(callExpression.expression)) return void 0;
|
|
5919
|
+
if (ts.idText(callExpression.expression.name) !== "of") return void 0;
|
|
5920
|
+
const serviceTagExpression = callExpression.expression.expression;
|
|
5921
|
+
const serviceTagType = typeCheckerUtils.getTypeAtLocation(serviceTagExpression);
|
|
5922
|
+
if (!serviceTagType) return void 0;
|
|
5923
|
+
const isTagLike = yield* pipe(
|
|
5924
|
+
typeParser.contextTag(serviceTagType, serviceTagExpression),
|
|
5925
|
+
orElse2(() => typeParser.serviceType(serviceTagType, serviceTagExpression)),
|
|
5926
|
+
option
|
|
5927
|
+
);
|
|
5928
|
+
if (isTagLike._tag === "None") return void 0;
|
|
5929
|
+
return layerServiceNameFromExpression(serviceTagExpression);
|
|
5930
|
+
}
|
|
5931
|
+
);
|
|
5932
|
+
const tryMatchServiceMapMakeInference = fn("effectFnOpportunity.tryMatchServiceMapMakeInference")(
|
|
5933
|
+
function* (objectLiteral) {
|
|
5934
|
+
const returnStatement = objectLiteral.parent;
|
|
5935
|
+
if (!returnStatement || !ts.isReturnStatement(returnStatement)) return void 0;
|
|
5936
|
+
const generatorBody = returnStatement.parent;
|
|
5937
|
+
if (!generatorBody || !ts.isBlock(generatorBody)) return void 0;
|
|
5938
|
+
const generatorFunction = generatorBody.parent;
|
|
5939
|
+
if (!generatorFunction || !ts.isFunctionExpression(generatorFunction) || !generatorFunction.asteriskToken) {
|
|
5940
|
+
return void 0;
|
|
5941
|
+
}
|
|
5942
|
+
const genCall = generatorFunction.parent;
|
|
5943
|
+
if (!genCall || !ts.isCallExpression(genCall)) return void 0;
|
|
5944
|
+
const parsedEffectGen = yield* option(typeParser.effectGen(genCall));
|
|
5945
|
+
if (parsedEffectGen._tag === "None" || parsedEffectGen.value.generatorFunction !== generatorFunction) {
|
|
5946
|
+
return void 0;
|
|
5947
|
+
}
|
|
5948
|
+
const makeProperty = genCall.parent;
|
|
5949
|
+
if (!makeProperty || !ts.isPropertyAssignment(makeProperty)) return void 0;
|
|
5950
|
+
if (makeProperty.initializer !== genCall) return void 0;
|
|
5951
|
+
if (!ts.isIdentifier(makeProperty.name) || ts.idText(makeProperty.name) !== "make") return void 0;
|
|
5952
|
+
let currentNode = makeProperty.parent;
|
|
5953
|
+
let classDeclaration = void 0;
|
|
5954
|
+
while (currentNode) {
|
|
5955
|
+
if (ts.isClassDeclaration(currentNode)) {
|
|
5956
|
+
classDeclaration = currentNode;
|
|
5957
|
+
break;
|
|
5958
|
+
}
|
|
5959
|
+
currentNode = currentNode.parent;
|
|
5960
|
+
}
|
|
5961
|
+
if (!classDeclaration || !classDeclaration.name) return void 0;
|
|
5962
|
+
const parsedServiceMapService = yield* option(typeParser.extendsServiceMapService(classDeclaration));
|
|
5963
|
+
if (parsedServiceMapService._tag === "None") return void 0;
|
|
5964
|
+
return ts.idText(classDeclaration.name);
|
|
5965
|
+
}
|
|
5966
|
+
);
|
|
5967
|
+
const tryGetLayerInferredTraceName = fn("effectFnOpportunity.tryGetLayerInferredTraceName")(
|
|
5968
|
+
function* (node, suggestedTraceName) {
|
|
5969
|
+
if (!suggestedTraceName) return void 0;
|
|
5970
|
+
if (!(node.parent && ts.isPropertyAssignment(node.parent) && node.parent.initializer === node && node.parent.parent && ts.isObjectLiteralExpression(node.parent.parent))) {
|
|
5971
|
+
return void 0;
|
|
5972
|
+
}
|
|
5973
|
+
const objectLiteral = node.parent.parent;
|
|
5974
|
+
const succeedServiceName = yield* tryMatchLayerSucceedInference(objectLiteral);
|
|
5975
|
+
if (succeedServiceName) return `${succeedServiceName}.${suggestedTraceName}`;
|
|
5976
|
+
const syncServiceName = yield* tryMatchLayerSyncInference(objectLiteral);
|
|
5977
|
+
if (syncServiceName) return `${syncServiceName}.${suggestedTraceName}`;
|
|
5978
|
+
const effectServiceName = yield* tryMatchLayerEffectInference(objectLiteral);
|
|
5979
|
+
if (effectServiceName) return `${effectServiceName}.${suggestedTraceName}`;
|
|
5980
|
+
const ofServiceName = yield* tryMatchOfInference(objectLiteral);
|
|
5981
|
+
if (ofServiceName) return `${ofServiceName}.${suggestedTraceName}`;
|
|
5982
|
+
const serviceMapMakeServiceName = yield* tryMatchServiceMapMakeInference(objectLiteral);
|
|
5983
|
+
return serviceMapMakeServiceName ? `${serviceMapMakeServiceName}.${suggestedTraceName}` : void 0;
|
|
5984
|
+
}
|
|
5985
|
+
);
|
|
5986
|
+
const getInferredTraceName = fn("effectFnOpportunity.getInferredTraceName")(
|
|
5987
|
+
function* (node, suggestedTraceName) {
|
|
5988
|
+
const inferredFromLayer = yield* tryGetLayerInferredTraceName(node, suggestedTraceName);
|
|
5989
|
+
if (inferredFromLayer) return inferredFromLayer;
|
|
5990
|
+
if (ts.isFunctionDeclaration(node) && node.name && hasExportModifier(node)) {
|
|
5991
|
+
return ts.idText(node.name);
|
|
5992
|
+
}
|
|
5993
|
+
if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name) && node.parent.initializer === node) {
|
|
5994
|
+
const variableDeclarationList = node.parent.parent;
|
|
5995
|
+
const variableStatement = variableDeclarationList?.parent;
|
|
5996
|
+
if (variableDeclarationList && ts.isVariableDeclarationList(variableDeclarationList) && variableStatement && ts.isVariableStatement(variableStatement) && hasExportModifier(variableStatement) && (variableDeclarationList.flags & ts.NodeFlags.Const) !== 0) {
|
|
5997
|
+
return ts.idText(node.parent.name);
|
|
5998
|
+
}
|
|
5999
|
+
}
|
|
6000
|
+
return void 0;
|
|
6001
|
+
}
|
|
6002
|
+
);
|
|
5789
6003
|
const areParametersReferencedIn = (fnNode, nodes) => {
|
|
5790
6004
|
if (fnNode.parameters.length === 0 || nodes.length === 0) return false;
|
|
5791
6005
|
const firstParam = fnNode.parameters[0];
|
|
@@ -5870,7 +6084,10 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5870
6084
|
);
|
|
5871
6085
|
};
|
|
5872
6086
|
const parseEffectFnOpportunityTargetGen = fn("effectFnOpportunity.parseEffectFnOpportunityTarget")(
|
|
5873
|
-
function* (node, returnType,
|
|
6087
|
+
function* (node, returnType, nameIdentifier) {
|
|
6088
|
+
const suggestedTraceName = nameIdentifier ? ts.isIdentifier(nameIdentifier) ? ts.idText(nameIdentifier) : nameIdentifier.text : void 0;
|
|
6089
|
+
const inferredTraceName = yield* getInferredTraceName(node, suggestedTraceName);
|
|
6090
|
+
const hasStrictLayerInferredName = inferredTraceName !== void 0 && inferredTraceName !== suggestedTraceName;
|
|
5874
6091
|
if (yield* isInsideEffectFn(node)) {
|
|
5875
6092
|
return yield* TypeParserIssue.issue;
|
|
5876
6093
|
}
|
|
@@ -5879,11 +6096,11 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5879
6096
|
const opportunity = yield* pipe(
|
|
5880
6097
|
tryParseGenOpportunity(node),
|
|
5881
6098
|
orElse2(() => {
|
|
5882
|
-
if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) {
|
|
6099
|
+
if (ts.isArrowFunction(node) && !ts.isBlock(node.body) && !hasStrictLayerInferredName) {
|
|
5883
6100
|
return TypeParserIssue.issue;
|
|
5884
6101
|
}
|
|
5885
6102
|
const body = ts.isArrowFunction(node) ? node.body : node.body;
|
|
5886
|
-
if (!body || !ts.isBlock(body) || body.statements.length <= 5) {
|
|
6103
|
+
if ((!body || !ts.isBlock(body) || body.statements.length <= 5) && !hasStrictLayerInferredName) {
|
|
5887
6104
|
return TypeParserIssue.issue;
|
|
5888
6105
|
}
|
|
5889
6106
|
return succeed3({
|
|
@@ -5898,7 +6115,8 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5898
6115
|
node,
|
|
5899
6116
|
nameIdentifier,
|
|
5900
6117
|
effectModuleName: opportunity.effectModuleName,
|
|
5901
|
-
inferredTraceName
|
|
6118
|
+
inferredTraceName,
|
|
6119
|
+
suggestedTraceName,
|
|
5902
6120
|
explicitTraceExpression: opportunity.explicitTraceExpression,
|
|
5903
6121
|
pipeArguments: opportunity.pipeArguments,
|
|
5904
6122
|
generatorFunction: opportunity.generatorFunction,
|
|
@@ -5908,27 +6126,26 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5908
6126
|
);
|
|
5909
6127
|
const parseEffectFnOpportunityTarget = (node) => {
|
|
5910
6128
|
if (!ts.isFunctionExpression(node) && !ts.isArrowFunction(node) && !ts.isFunctionDeclaration(node)) {
|
|
5911
|
-
return
|
|
6129
|
+
return;
|
|
5912
6130
|
}
|
|
5913
6131
|
if ((ts.isFunctionExpression(node) || ts.isFunctionDeclaration(node)) && node.asteriskToken) {
|
|
5914
|
-
return
|
|
6132
|
+
return;
|
|
5915
6133
|
}
|
|
5916
6134
|
if (ts.isFunctionExpression(node) && node.name) {
|
|
5917
|
-
return
|
|
6135
|
+
return;
|
|
5918
6136
|
}
|
|
5919
6137
|
if (node.type) {
|
|
5920
|
-
return
|
|
6138
|
+
return;
|
|
5921
6139
|
}
|
|
5922
6140
|
const functionType = typeChecker.getTypeAtLocation(node);
|
|
5923
|
-
if (!functionType) return
|
|
6141
|
+
if (!functionType) return;
|
|
5924
6142
|
const callSignatures = typeChecker.getSignaturesOfType(functionType, ts.SignatureKind.Call);
|
|
5925
|
-
if (callSignatures.length !== 1) return
|
|
6143
|
+
if (callSignatures.length !== 1) return;
|
|
5926
6144
|
const signature = callSignatures[0];
|
|
5927
6145
|
const returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
5928
6146
|
const nameIdentifier = getNameIdentifier(node);
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
return parseEffectFnOpportunityTargetGen(node, returnType, traceName, nameIdentifier);
|
|
6147
|
+
if (!nameIdentifier) return;
|
|
6148
|
+
return parseEffectFnOpportunityTargetGen(node, returnType, nameIdentifier);
|
|
5932
6149
|
};
|
|
5933
6150
|
const getFunctionBodyBlock = (node) => {
|
|
5934
6151
|
if (ts.isArrowFunction(node)) {
|
|
@@ -6002,18 +6219,21 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6002
6219
|
while (nodeToVisit.length > 0) {
|
|
6003
6220
|
const node = nodeToVisit.shift();
|
|
6004
6221
|
ts.forEachChild(node, appendNodeToVisit);
|
|
6005
|
-
const
|
|
6006
|
-
if (
|
|
6007
|
-
|
|
6222
|
+
const test = parseEffectFnOpportunityTarget(node);
|
|
6223
|
+
if (!test) continue;
|
|
6224
|
+
const target = yield* orUndefined(test);
|
|
6225
|
+
if (!target) continue;
|
|
6226
|
+
if (target.hasParamsInPipeArgs) continue;
|
|
6008
6227
|
const {
|
|
6009
6228
|
effectModuleName,
|
|
6010
6229
|
explicitTraceExpression,
|
|
6011
6230
|
inferredTraceName,
|
|
6012
6231
|
nameIdentifier,
|
|
6013
6232
|
node: targetNode,
|
|
6014
|
-
pipeArguments: pipeArguments2
|
|
6015
|
-
|
|
6016
|
-
|
|
6233
|
+
pipeArguments: pipeArguments2,
|
|
6234
|
+
suggestedTraceName
|
|
6235
|
+
} = target;
|
|
6236
|
+
const innerFunction = target.generatorFunction ?? targetNode;
|
|
6017
6237
|
const fixes = [];
|
|
6018
6238
|
if (pluginOptions.effectFn.includes("span") && explicitTraceExpression) {
|
|
6019
6239
|
fixes.push({
|
|
@@ -6033,7 +6253,7 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6033
6253
|
})
|
|
6034
6254
|
});
|
|
6035
6255
|
}
|
|
6036
|
-
if (pluginOptions.effectFn.includes("untraced") && target.
|
|
6256
|
+
if (pluginOptions.effectFn.includes("untraced") && target.generatorFunction) {
|
|
6037
6257
|
fixes.push({
|
|
6038
6258
|
fixName: "effectFnOpportunity_toEffectFnUntraced",
|
|
6039
6259
|
description: "Convert to Effect.fnUntraced",
|
|
@@ -6055,22 +6275,41 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6055
6275
|
})
|
|
6056
6276
|
});
|
|
6057
6277
|
}
|
|
6058
|
-
if (
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6278
|
+
if (!explicitTraceExpression) {
|
|
6279
|
+
if (pluginOptions.effectFn.includes("inferred-span") && inferredTraceName) {
|
|
6280
|
+
fixes.push({
|
|
6281
|
+
fixName: "effectFnOpportunity_toEffectFnSpanInferred",
|
|
6282
|
+
description: `Convert to Effect.fn("${inferredTraceName}")`,
|
|
6283
|
+
apply: gen(function* () {
|
|
6284
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
6285
|
+
const newNode = createEffectFnNode(
|
|
6286
|
+
targetNode,
|
|
6287
|
+
innerFunction,
|
|
6288
|
+
effectModuleName,
|
|
6289
|
+
inferredTraceName,
|
|
6290
|
+
pipeArguments2
|
|
6291
|
+
);
|
|
6292
|
+
changeTracker.replaceNode(sourceFile, targetNode, newNode);
|
|
6293
|
+
})
|
|
6294
|
+
});
|
|
6295
|
+
}
|
|
6296
|
+
if (pluginOptions.effectFn.includes("suggested-span") && suggestedTraceName && (!pluginOptions.effectFn.includes("inferred-span") || suggestedTraceName !== inferredTraceName)) {
|
|
6297
|
+
fixes.push({
|
|
6298
|
+
fixName: "effectFnOpportunity_toEffectFnSpanSuggested",
|
|
6299
|
+
description: `Convert to Effect.fn("${suggestedTraceName}")`,
|
|
6300
|
+
apply: gen(function* () {
|
|
6301
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
6302
|
+
const newNode = createEffectFnNode(
|
|
6303
|
+
targetNode,
|
|
6304
|
+
innerFunction,
|
|
6305
|
+
effectModuleName,
|
|
6306
|
+
suggestedTraceName,
|
|
6307
|
+
pipeArguments2
|
|
6308
|
+
);
|
|
6309
|
+
changeTracker.replaceNode(sourceFile, targetNode, newNode);
|
|
6310
|
+
})
|
|
6311
|
+
});
|
|
6312
|
+
}
|
|
6074
6313
|
}
|
|
6075
6314
|
if (fixes.length === 0) continue;
|
|
6076
6315
|
const generateExpectedSignature = () => {
|
|
@@ -6083,7 +6322,7 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6083
6322
|
}
|
|
6084
6323
|
return "_";
|
|
6085
6324
|
}).join(", ");
|
|
6086
|
-
const fnSignature = `function*${typeParamNames}(${paramNames}) { ... }`;
|
|
6325
|
+
const fnSignature = ts.isArrowFunction(innerFunction) ? `${typeParamNames}(${paramNames}) => { ... }` : isGeneratorFunction(innerFunction) ? `function*${typeParamNames}(${paramNames}) { ... }` : `function${typeParamNames}(${paramNames}) { ... }`;
|
|
6087
6326
|
const pipeArgsForWithSpan = pipeArguments2.slice(0, -1);
|
|
6088
6327
|
const pipeArgsSuffix = (args3) => args3.length > 0 ? ", ...pipeTransformations" : "";
|
|
6089
6328
|
switch (firstFix.fixName) {
|
|
@@ -6097,6 +6336,8 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6097
6336
|
return `${effectModuleName}.fn(${fnSignature}${pipeArgsSuffix(pipeArguments2)})`;
|
|
6098
6337
|
case "effectFnOpportunity_toEffectFnSpanInferred":
|
|
6099
6338
|
return `${effectModuleName}.fn("${inferredTraceName}")(${fnSignature}${pipeArgsSuffix(pipeArguments2)})`;
|
|
6339
|
+
case "effectFnOpportunity_toEffectFnSpanSuggested":
|
|
6340
|
+
return `${effectModuleName}.fn("${suggestedTraceName}")(${fnSignature}${pipeArgsSuffix(pipeArguments2)})`;
|
|
6100
6341
|
default:
|
|
6101
6342
|
return `${effectModuleName}.fn(${fnSignature})`;
|
|
6102
6343
|
}
|
|
@@ -6149,6 +6390,70 @@ var effectGenUsesAdapter = createDiagnostic({
|
|
|
6149
6390
|
})
|
|
6150
6391
|
});
|
|
6151
6392
|
|
|
6393
|
+
// src/diagnostics/effectInFailure.ts
|
|
6394
|
+
var effectInFailure = createDiagnostic({
|
|
6395
|
+
name: "effectInFailure",
|
|
6396
|
+
code: 49,
|
|
6397
|
+
description: "Warns when an Effect is used inside an Effect failure channel",
|
|
6398
|
+
severity: "warning",
|
|
6399
|
+
apply: fn("effectInFailure.apply")(function* (sourceFile, report) {
|
|
6400
|
+
const ts = yield* service(TypeScriptApi);
|
|
6401
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
6402
|
+
const typeParser = yield* service(TypeParser);
|
|
6403
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
6404
|
+
const isStrictEffectType = cachedBy(
|
|
6405
|
+
fn("effectInFailure.isStrictEffectType")(function* (type, atLocation) {
|
|
6406
|
+
yield* typeParser.strictEffectType(type, atLocation);
|
|
6407
|
+
return true;
|
|
6408
|
+
}),
|
|
6409
|
+
"effectInFailure.isStrictEffectType",
|
|
6410
|
+
(type) => type
|
|
6411
|
+
);
|
|
6412
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
6413
|
+
const stack = [sourceFile];
|
|
6414
|
+
const shouldSkipBecauseChildMatched = /* @__PURE__ */ new WeakSet();
|
|
6415
|
+
while (stack.length > 0) {
|
|
6416
|
+
const node = stack.pop();
|
|
6417
|
+
if (!visited.has(node)) {
|
|
6418
|
+
visited.add(node);
|
|
6419
|
+
stack.push(node);
|
|
6420
|
+
ts.forEachChild(node, (child) => {
|
|
6421
|
+
stack.push(child);
|
|
6422
|
+
return void 0;
|
|
6423
|
+
});
|
|
6424
|
+
continue;
|
|
6425
|
+
}
|
|
6426
|
+
if (shouldSkipBecauseChildMatched.has(node)) {
|
|
6427
|
+
if (node.parent) shouldSkipBecauseChildMatched.add(node.parent);
|
|
6428
|
+
continue;
|
|
6429
|
+
}
|
|
6430
|
+
const type = typeCheckerUtils.getTypeAtLocation(node);
|
|
6431
|
+
if (!type) continue;
|
|
6432
|
+
const effect = yield* orUndefined(typeParser.strictEffectType(type, node));
|
|
6433
|
+
if (!effect) continue;
|
|
6434
|
+
const failureMembers = typeCheckerUtils.unrollUnionMembers(effect.E);
|
|
6435
|
+
let memberWithEffect = void 0;
|
|
6436
|
+
for (const member of failureMembers) {
|
|
6437
|
+
const isMemberEffect = yield* orUndefined(isStrictEffectType(member, node));
|
|
6438
|
+
if (isMemberEffect) {
|
|
6439
|
+
memberWithEffect = member;
|
|
6440
|
+
break;
|
|
6441
|
+
}
|
|
6442
|
+
}
|
|
6443
|
+
if (!memberWithEffect) continue;
|
|
6444
|
+
const messageText = `The error channel contains an Effect (${typeChecker.typeToString(memberWithEffect)}). Putting Effect computations in the failure channel is not intended; keep only failure types there.`;
|
|
6445
|
+
report({
|
|
6446
|
+
location: node,
|
|
6447
|
+
messageText,
|
|
6448
|
+
fixes: []
|
|
6449
|
+
});
|
|
6450
|
+
if (node.parent) {
|
|
6451
|
+
shouldSkipBecauseChildMatched.add(node.parent);
|
|
6452
|
+
}
|
|
6453
|
+
}
|
|
6454
|
+
})
|
|
6455
|
+
});
|
|
6456
|
+
|
|
6152
6457
|
// src/diagnostics/effectInVoidSuccess.ts
|
|
6153
6458
|
var effectInVoidSuccess = createDiagnostic({
|
|
6154
6459
|
name: "effectInVoidSuccess",
|
|
@@ -7517,6 +7822,7 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
7517
7822
|
const ts = yield* service(TypeScriptApi);
|
|
7518
7823
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
7519
7824
|
const typeParser = yield* service(TypeParser);
|
|
7825
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
7520
7826
|
const nodeToVisit = [];
|
|
7521
7827
|
const appendNodeToVisit = (node) => {
|
|
7522
7828
|
nodeToVisit.push(node);
|
|
@@ -7526,50 +7832,32 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
7526
7832
|
while (nodeToVisit.length > 0) {
|
|
7527
7833
|
const node = nodeToVisit.shift();
|
|
7528
7834
|
ts.forEachChild(node, appendNodeToVisit);
|
|
7529
|
-
if (ts.
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
node,
|
|
7556
|
-
ts.factory.createReturnStatement(
|
|
7557
|
-
node
|
|
7558
|
-
)
|
|
7559
|
-
);
|
|
7560
|
-
})
|
|
7561
|
-
}] : [];
|
|
7562
|
-
report({
|
|
7563
|
-
location: node,
|
|
7564
|
-
messageText: `It is recommended to use return yield* for Effects that never succeed to signal a definitive exit point for type narrowing and tooling support.`,
|
|
7565
|
-
fixes: fix
|
|
7566
|
-
});
|
|
7567
|
-
}
|
|
7568
|
-
}
|
|
7569
|
-
}
|
|
7570
|
-
}
|
|
7571
|
-
}
|
|
7572
|
-
}
|
|
7835
|
+
if (!ts.isExpressionStatement(node)) continue;
|
|
7836
|
+
const unwrapped = tsUtils.skipOuterExpressions(node.expression);
|
|
7837
|
+
if (!ts.isYieldExpression(unwrapped) || !unwrapped.expression || !unwrapped.asteriskToken) continue;
|
|
7838
|
+
const type = typeCheckerUtils.getTypeAtLocation(unwrapped.expression);
|
|
7839
|
+
if (!type) continue;
|
|
7840
|
+
const maybeEffect = yield* option(typeParser.effectYieldableType(type, unwrapped.expression));
|
|
7841
|
+
if (!(isSome2(maybeEffect) && maybeEffect.value.A.flags & ts.TypeFlags.Never)) continue;
|
|
7842
|
+
const { effectGen, scopeNode } = yield* typeParser.findEnclosingScopes(node);
|
|
7843
|
+
if (!effectGen || scopeNode && scopeNode !== effectGen.generatorFunction) continue;
|
|
7844
|
+
const fix = [{
|
|
7845
|
+
fixName: "missingReturnYieldStar_fix",
|
|
7846
|
+
description: "Add return statement",
|
|
7847
|
+
apply: gen(function* () {
|
|
7848
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
7849
|
+
changeTracker.replaceNode(
|
|
7850
|
+
sourceFile,
|
|
7851
|
+
node,
|
|
7852
|
+
ts.factory.createReturnStatement(node.expression)
|
|
7853
|
+
);
|
|
7854
|
+
})
|
|
7855
|
+
}];
|
|
7856
|
+
report({
|
|
7857
|
+
location: unwrapped,
|
|
7858
|
+
messageText: `It is recommended to use return yield* for Effects that never succeed to signal a definitive exit point for type narrowing and tooling support.`,
|
|
7859
|
+
fixes: fix
|
|
7860
|
+
});
|
|
7573
7861
|
}
|
|
7574
7862
|
})
|
|
7575
7863
|
});
|
|
@@ -7886,9 +8174,7 @@ var effectModuleMigrationDb = {
|
|
|
7886
8174
|
"failSync": asUnchanged,
|
|
7887
8175
|
"fiberId": asUnchanged,
|
|
7888
8176
|
"filter": asUnchanged,
|
|
7889
|
-
"filterMap":
|
|
7890
|
-
"Use Effect.filter or Effect.map with Option instead."
|
|
7891
|
-
),
|
|
8177
|
+
"filterMap": asUnchanged,
|
|
7892
8178
|
"filterOrElse": asUnchanged,
|
|
7893
8179
|
"filterOrFail": asUnchanged,
|
|
7894
8180
|
"flatMap": asUnchanged,
|
|
@@ -8176,9 +8462,7 @@ var effectModuleMigrationDb = {
|
|
|
8176
8462
|
"finalizersMask": asRemoved(
|
|
8177
8463
|
"Finalizer masking has been removed in Effect v4."
|
|
8178
8464
|
),
|
|
8179
|
-
"findFirst":
|
|
8180
|
-
"Use Effect.forEach with early return instead."
|
|
8181
|
-
),
|
|
8465
|
+
"findFirst": asUnchanged,
|
|
8182
8466
|
"firstSuccessOf": asRemoved(
|
|
8183
8467
|
"Use Effect.raceAll instead."
|
|
8184
8468
|
),
|
|
@@ -11046,6 +11330,7 @@ var diagnostics = [
|
|
|
11046
11330
|
missingEffectServiceDependency,
|
|
11047
11331
|
missingLayerContext,
|
|
11048
11332
|
floatingEffect,
|
|
11333
|
+
effectInFailure,
|
|
11049
11334
|
missingStarInYieldEffectGen,
|
|
11050
11335
|
unnecessaryEffectGen,
|
|
11051
11336
|
unnecessaryFailYieldableError,
|