@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
package/transform.js
CHANGED
|
@@ -24,7 +24,7 @@ __export(transform_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(transform_exports);
|
|
26
26
|
|
|
27
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
27
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Pipeable.js
|
|
28
28
|
var pipeArguments = (self, args3) => {
|
|
29
29
|
switch (args3.length) {
|
|
30
30
|
case 0:
|
|
@@ -57,7 +57,7 @@ var pipeArguments = (self, args3) => {
|
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
60
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Function.js
|
|
61
61
|
var dual = function(arity, body) {
|
|
62
62
|
if (typeof arity === "function") {
|
|
63
63
|
return function() {
|
|
@@ -105,7 +105,7 @@ function pipe(a, ...args3) {
|
|
|
105
105
|
return pipeArguments(a, args3);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
108
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/equal.js
|
|
109
109
|
var getAllObjectKeys = (obj) => {
|
|
110
110
|
const keys2 = new Set(Reflect.ownKeys(obj));
|
|
111
111
|
if (obj.constructor === Object) return keys2;
|
|
@@ -128,7 +128,7 @@ var getAllObjectKeys = (obj) => {
|
|
|
128
128
|
};
|
|
129
129
|
var byReferenceInstances = /* @__PURE__ */ new WeakSet();
|
|
130
130
|
|
|
131
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
131
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Predicate.js
|
|
132
132
|
function isString(input) {
|
|
133
133
|
return typeof input === "string";
|
|
134
134
|
}
|
|
@@ -149,7 +149,7 @@ function isObjectKeyword(input) {
|
|
|
149
149
|
}
|
|
150
150
|
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObjectKeyword(self) && property in self);
|
|
151
151
|
|
|
152
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
152
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Hash.js
|
|
153
153
|
var symbol = "~effect/interfaces/Hash";
|
|
154
154
|
var hash = (self) => {
|
|
155
155
|
switch (typeof self) {
|
|
@@ -268,7 +268,7 @@ function withVisitedTracking(obj, fn2) {
|
|
|
268
268
|
return result;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
271
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Equal.js
|
|
272
272
|
var symbol2 = "~effect/interfaces/Equal";
|
|
273
273
|
function equals() {
|
|
274
274
|
if (arguments.length === 1) {
|
|
@@ -430,7 +430,10 @@ var compareSets = /* @__PURE__ */ makeCompareSet(compareBoth);
|
|
|
430
430
|
var isEqual = (u) => hasProperty(u, symbol2);
|
|
431
431
|
var asEquivalence = () => equals;
|
|
432
432
|
|
|
433
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
433
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/array.js
|
|
434
|
+
var isArrayNonEmpty = (self) => self.length > 0;
|
|
435
|
+
|
|
436
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Redactable.js
|
|
434
437
|
var symbolRedactable = /* @__PURE__ */ Symbol.for("~effect/Inspectable/redactable");
|
|
435
438
|
var isRedactable = (u) => hasProperty(u, symbolRedactable);
|
|
436
439
|
function redact(u) {
|
|
@@ -449,7 +452,7 @@ var emptyServiceMap = {
|
|
|
449
452
|
}
|
|
450
453
|
};
|
|
451
454
|
|
|
452
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
455
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Formatter.js
|
|
453
456
|
function format(input, options) {
|
|
454
457
|
const space = options?.space ?? 0;
|
|
455
458
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
@@ -528,7 +531,7 @@ function safeToString(input) {
|
|
|
528
531
|
}
|
|
529
532
|
}
|
|
530
533
|
|
|
531
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
534
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Inspectable.js
|
|
532
535
|
var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
533
536
|
var toJson = (input) => {
|
|
534
537
|
try {
|
|
@@ -572,7 +575,7 @@ var Class = class {
|
|
|
572
575
|
}
|
|
573
576
|
};
|
|
574
577
|
|
|
575
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
578
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Utils.js
|
|
576
579
|
var GenKindTypeId = "~effect/Utils/GenKind";
|
|
577
580
|
var GenKindImpl = class {
|
|
578
581
|
value;
|
|
@@ -640,7 +643,7 @@ var internalCall = isNotOptimizedAway ? standard[InternalTypeId] : forced[Intern
|
|
|
640
643
|
var genConstructor = function* () {
|
|
641
644
|
}.constructor;
|
|
642
645
|
|
|
643
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
646
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/core.js
|
|
644
647
|
var EffectTypeId = `~effect/Effect`;
|
|
645
648
|
var ExitTypeId = `~effect/Exit`;
|
|
646
649
|
var effectVariance = {
|
|
@@ -987,7 +990,7 @@ var DoneVoid = {
|
|
|
987
990
|
value: void 0
|
|
988
991
|
};
|
|
989
992
|
|
|
990
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
993
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/option.js
|
|
991
994
|
var TypeId = "~effect/data/Option";
|
|
992
995
|
var CommonProto = {
|
|
993
996
|
[TypeId]: {
|
|
@@ -1052,7 +1055,7 @@ var some = (value) => {
|
|
|
1052
1055
|
return a;
|
|
1053
1056
|
};
|
|
1054
1057
|
|
|
1055
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1058
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/internal/result.js
|
|
1056
1059
|
var TypeId2 = "~effect/data/Result";
|
|
1057
1060
|
var CommonProto2 = {
|
|
1058
1061
|
[TypeId2]: {
|
|
@@ -1123,13 +1126,13 @@ var succeed = (success) => {
|
|
|
1123
1126
|
return a;
|
|
1124
1127
|
};
|
|
1125
1128
|
|
|
1126
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1129
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Order.js
|
|
1127
1130
|
function make(compare) {
|
|
1128
1131
|
return (self, that) => self === that ? 0 : compare(self, that);
|
|
1129
1132
|
}
|
|
1130
1133
|
var String2 = /* @__PURE__ */ make((self, that) => self < that ? -1 : 1);
|
|
1131
1134
|
|
|
1132
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1135
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Option.js
|
|
1133
1136
|
var none2 = () => none;
|
|
1134
1137
|
var some2 = some;
|
|
1135
1138
|
var isNone2 = isNone;
|
|
@@ -1139,7 +1142,7 @@ var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : se
|
|
|
1139
1142
|
var fromNullishOr = (a) => a == null ? none2() : some2(a);
|
|
1140
1143
|
var getOrUndefined = /* @__PURE__ */ getOrElse(constUndefined);
|
|
1141
1144
|
|
|
1142
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1145
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Result.js
|
|
1143
1146
|
var succeed2 = succeed;
|
|
1144
1147
|
var fail2 = fail;
|
|
1145
1148
|
var isFailure2 = isFailure;
|
|
@@ -1147,18 +1150,7 @@ var isSuccess2 = isSuccess;
|
|
|
1147
1150
|
var map = /* @__PURE__ */ dual(2, (self, f) => isSuccess2(self) ? succeed2(f(self.success)) : fail2(self.failure));
|
|
1148
1151
|
var getOrElse2 = /* @__PURE__ */ dual(2, (self, onFailure) => isFailure2(self) ? onFailure(self.failure) : self.success);
|
|
1149
1152
|
|
|
1150
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1151
|
-
var apply = (filter2, input, ...args3) => {
|
|
1152
|
-
const result = filter2(input, ...args3);
|
|
1153
|
-
if (result === true) return succeed2(input);
|
|
1154
|
-
if (result === false) return fail2(input);
|
|
1155
|
-
return result;
|
|
1156
|
-
};
|
|
1157
|
-
|
|
1158
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.14/node_modules/effect/dist/internal/array.js
|
|
1159
|
-
var isArrayNonEmpty = (self) => self.length > 0;
|
|
1160
|
-
|
|
1161
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.14/node_modules/effect/dist/Record.js
|
|
1153
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Record.js
|
|
1162
1154
|
var map2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
1163
1155
|
const out = {
|
|
1164
1156
|
...self
|
|
@@ -1170,7 +1162,7 @@ var map2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
|
1170
1162
|
});
|
|
1171
1163
|
var keys = (self) => Object.keys(self);
|
|
1172
1164
|
|
|
1173
|
-
// ../../node_modules/.pnpm/effect@4.0.0-beta.
|
|
1165
|
+
// ../../node_modules/.pnpm/effect@4.0.0-beta.27/node_modules/effect/dist/Array.js
|
|
1174
1166
|
var Array2 = globalThis.Array;
|
|
1175
1167
|
var fromIterable = (collection) => Array2.isArray(collection) ? collection : Array2.from(collection);
|
|
1176
1168
|
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
@@ -1233,13 +1225,12 @@ var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
|
|
|
1233
1225
|
return out;
|
|
1234
1226
|
});
|
|
1235
1227
|
var flatten = /* @__PURE__ */ flatMap(identity);
|
|
1236
|
-
var filter = /* @__PURE__ */ dual(2, (self,
|
|
1228
|
+
var filter = /* @__PURE__ */ dual(2, (self, predicate) => {
|
|
1237
1229
|
const as = fromIterable(self);
|
|
1238
1230
|
const out = [];
|
|
1239
1231
|
for (let i = 0; i < as.length; i++) {
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
out.push(result.success);
|
|
1232
|
+
if (predicate(as[i], i)) {
|
|
1233
|
+
out.push(as[i]);
|
|
1243
1234
|
}
|
|
1244
1235
|
}
|
|
1245
1236
|
return out;
|
|
@@ -1690,7 +1681,9 @@ function parse(config) {
|
|
|
1690
1681
|
keyPatterns: isObject(config) && hasProperty(config, "keyPatterns") && isArray(config.keyPatterns) ? parseKeyPatterns(config.keyPatterns) : defaults.keyPatterns,
|
|
1691
1682
|
extendedKeyDetection: isObject(config) && hasProperty(config, "extendedKeyDetection") && isBoolean(config.extendedKeyDetection) ? config.extendedKeyDetection : defaults.extendedKeyDetection,
|
|
1692
1683
|
pipeableMinArgCount: isObject(config) && hasProperty(config, "pipeableMinArgCount") && isNumber(config.pipeableMinArgCount) ? config.pipeableMinArgCount : defaults.pipeableMinArgCount,
|
|
1693
|
-
effectFn: isObject(config) && hasProperty(config, "effectFn") && isArray(config.effectFn) && config.effectFn.every(isString) ? config.effectFn.map(
|
|
1684
|
+
effectFn: isObject(config) && hasProperty(config, "effectFn") && isArray(config.effectFn) && config.effectFn.every(isString) ? config.effectFn.map(
|
|
1685
|
+
(_) => _.toLowerCase()
|
|
1686
|
+
) : defaults.effectFn,
|
|
1694
1687
|
layerGraphFollowDepth: isObject(config) && hasProperty(config, "layerGraphFollowDepth") && isNumber(config.layerGraphFollowDepth) ? config.layerGraphFollowDepth : defaults.layerGraphFollowDepth,
|
|
1695
1688
|
mermaidProvider: isObject(config) && hasProperty(config, "mermaidProvider") && isString(config.mermaidProvider) ? config.mermaidProvider : defaults.mermaidProvider
|
|
1696
1689
|
};
|
|
@@ -3377,6 +3370,14 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3377
3370
|
const layerType = cachedBy(
|
|
3378
3371
|
fn("TypeParser.layerType")(function* (type, atLocation) {
|
|
3379
3372
|
yield* pipeableType(type, atLocation);
|
|
3373
|
+
if (supportedEffect() === "v4") {
|
|
3374
|
+
const typeIdSymbol = typeChecker.getPropertyOfType(type, "~effect/Layer");
|
|
3375
|
+
if (typeIdSymbol) {
|
|
3376
|
+
const typeIdType = typeChecker.getTypeOfSymbolAtLocation(typeIdSymbol, atLocation);
|
|
3377
|
+
return yield* layerVarianceStruct(typeIdType, atLocation);
|
|
3378
|
+
}
|
|
3379
|
+
return yield* typeParserIssue("Type is not a layer", type, atLocation);
|
|
3380
|
+
}
|
|
3380
3381
|
const propertiesSymbols = typeChecker.getPropertiesOfType(type).filter(
|
|
3381
3382
|
(_) => _.flags & ts.SymbolFlags.Property && !(_.flags & ts.SymbolFlags.Optional) && _.valueDeclaration
|
|
3382
3383
|
);
|
|
@@ -3426,6 +3427,34 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
3426
3427
|
"TypeParser.effectSubtype",
|
|
3427
3428
|
(type) => type
|
|
3428
3429
|
);
|
|
3430
|
+
const effectYieldableType = cachedBy(
|
|
3431
|
+
fn("TypeParser.effectYieldableType")(function* (type, atLocation) {
|
|
3432
|
+
if (supportedEffect() === "v3") {
|
|
3433
|
+
return yield* effectType(type, atLocation);
|
|
3434
|
+
}
|
|
3435
|
+
return yield* firstSuccessOf([
|
|
3436
|
+
effectType(type, atLocation),
|
|
3437
|
+
gen(function* () {
|
|
3438
|
+
const asEffectSymbol = typeChecker.getPropertyOfType(type, "asEffect");
|
|
3439
|
+
if (!asEffectSymbol) {
|
|
3440
|
+
return yield* typeParserIssue("Type has no 'asEffect' property", type, atLocation);
|
|
3441
|
+
}
|
|
3442
|
+
const asEffectType = typeChecker.getTypeOfSymbolAtLocation(asEffectSymbol, atLocation);
|
|
3443
|
+
const asEffectSignatures = typeChecker.getSignaturesOfType(asEffectType, ts.SignatureKind.Call);
|
|
3444
|
+
if (asEffectSignatures.length === 0) {
|
|
3445
|
+
return yield* typeParserIssue("'asEffect' property is not callable", type, atLocation);
|
|
3446
|
+
}
|
|
3447
|
+
return yield* firstSuccessOf(
|
|
3448
|
+
asEffectSignatures.map(
|
|
3449
|
+
(signature) => effectType(typeChecker.getReturnTypeOfSignature(signature), atLocation)
|
|
3450
|
+
)
|
|
3451
|
+
);
|
|
3452
|
+
})
|
|
3453
|
+
]);
|
|
3454
|
+
}),
|
|
3455
|
+
"TypeParser.effectYieldableType",
|
|
3456
|
+
(type) => type
|
|
3457
|
+
);
|
|
3429
3458
|
const isEffectContextSourceFile = cachedBy(
|
|
3430
3459
|
fn("TypeParser.isEffectContextSourceFile")(function* (sourceFile) {
|
|
3431
3460
|
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
|
|
@@ -5053,6 +5082,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils, program) {
|
|
|
5053
5082
|
layerType,
|
|
5054
5083
|
fiberType,
|
|
5055
5084
|
effectSubtype,
|
|
5085
|
+
effectYieldableType,
|
|
5056
5086
|
importedEffectModule,
|
|
5057
5087
|
effectGen,
|
|
5058
5088
|
effectFnUntracedGen,
|
|
@@ -5765,16 +5795,16 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5765
5795
|
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
5766
5796
|
return node.name;
|
|
5767
5797
|
}
|
|
5768
|
-
if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
|
|
5798
|
+
if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name) && node.parent.initializer === node) {
|
|
5769
5799
|
return node.parent.name;
|
|
5770
5800
|
}
|
|
5771
|
-
if (node.parent && ts.isPropertyAssignment(node.parent)) {
|
|
5801
|
+
if (node.parent && ts.isPropertyAssignment(node.parent) && node.parent.initializer === node) {
|
|
5772
5802
|
const name = node.parent.name;
|
|
5773
5803
|
if (ts.isIdentifier(name) || ts.isStringLiteral(name)) {
|
|
5774
5804
|
return name;
|
|
5775
5805
|
}
|
|
5776
5806
|
}
|
|
5777
|
-
if (node.parent && ts.isPropertyDeclaration(node.parent)) {
|
|
5807
|
+
if (node.parent && ts.isPropertyDeclaration(node.parent) && node.parent.initializer === node) {
|
|
5778
5808
|
const name = node.parent.name;
|
|
5779
5809
|
if (ts.isIdentifier(name)) {
|
|
5780
5810
|
return name;
|
|
@@ -5782,6 +5812,190 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5782
5812
|
}
|
|
5783
5813
|
return void 0;
|
|
5784
5814
|
};
|
|
5815
|
+
const hasExportModifier = (node) => {
|
|
5816
|
+
if (!ts.canHaveModifiers(node)) return false;
|
|
5817
|
+
const modifiers = ts.getModifiers(node);
|
|
5818
|
+
return modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
5819
|
+
};
|
|
5820
|
+
const layerServiceNameFromExpression = (expression) => {
|
|
5821
|
+
if (expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
5822
|
+
const enclosingClass = ts.findAncestor(
|
|
5823
|
+
expression,
|
|
5824
|
+
(node) => ts.isClassDeclaration(node)
|
|
5825
|
+
);
|
|
5826
|
+
if (enclosingClass?.name) {
|
|
5827
|
+
return ts.idText(enclosingClass.name);
|
|
5828
|
+
}
|
|
5829
|
+
}
|
|
5830
|
+
if (ts.isIdentifier(expression)) return ts.idText(expression);
|
|
5831
|
+
return sourceFile.text.slice(expression.pos, expression.end).trim();
|
|
5832
|
+
};
|
|
5833
|
+
const tryGetLayerApiMethod = (node) => pipe(
|
|
5834
|
+
typeParser.isNodeReferenceToEffectLayerModuleApi("effect")(node),
|
|
5835
|
+
map4(() => "effect"),
|
|
5836
|
+
orElse2(
|
|
5837
|
+
() => pipe(
|
|
5838
|
+
typeParser.isNodeReferenceToEffectLayerModuleApi("succeed")(node),
|
|
5839
|
+
map4(() => "succeed"),
|
|
5840
|
+
orElse2(
|
|
5841
|
+
() => pipe(
|
|
5842
|
+
typeParser.isNodeReferenceToEffectLayerModuleApi("sync")(node),
|
|
5843
|
+
map4(() => "sync"),
|
|
5844
|
+
orElse2(() => succeed3(void 0))
|
|
5845
|
+
)
|
|
5846
|
+
)
|
|
5847
|
+
)
|
|
5848
|
+
)
|
|
5849
|
+
);
|
|
5850
|
+
const verifyLayerMethodAtCall = fn("effectFnOpportunity.verifyLayerMethodAtCall")(
|
|
5851
|
+
function* (callExpression, method, implementationExpression) {
|
|
5852
|
+
const directMethod = yield* tryGetLayerApiMethod(callExpression.expression);
|
|
5853
|
+
if (directMethod === method && callExpression.arguments.length >= 2 && callExpression.arguments[1] === implementationExpression) {
|
|
5854
|
+
return layerServiceNameFromExpression(callExpression.arguments[0]);
|
|
5855
|
+
}
|
|
5856
|
+
if (ts.isCallExpression(callExpression.expression)) {
|
|
5857
|
+
const innerCall = callExpression.expression;
|
|
5858
|
+
const innerMethod = yield* tryGetLayerApiMethod(innerCall.expression);
|
|
5859
|
+
if (innerMethod === method && innerCall.arguments.length >= 1 && callExpression.arguments.length >= 1 && callExpression.arguments[0] === implementationExpression) {
|
|
5860
|
+
return layerServiceNameFromExpression(innerCall.arguments[0]);
|
|
5861
|
+
}
|
|
5862
|
+
}
|
|
5863
|
+
return void 0;
|
|
5864
|
+
}
|
|
5865
|
+
);
|
|
5866
|
+
const tryMatchLayerSucceedInference = fn("effectFnOpportunity.tryMatchLayerSucceedInference")(
|
|
5867
|
+
function* (objectLiteral) {
|
|
5868
|
+
const callExpression = objectLiteral.parent;
|
|
5869
|
+
if (!callExpression || !ts.isCallExpression(callExpression)) return void 0;
|
|
5870
|
+
return yield* verifyLayerMethodAtCall(callExpression, "succeed", objectLiteral);
|
|
5871
|
+
}
|
|
5872
|
+
);
|
|
5873
|
+
const tryMatchLayerSyncInference = fn("effectFnOpportunity.tryMatchLayerSyncInference")(
|
|
5874
|
+
function* (objectLiteral) {
|
|
5875
|
+
const returnStatement = objectLiteral.parent;
|
|
5876
|
+
if (!returnStatement || !ts.isReturnStatement(returnStatement)) return void 0;
|
|
5877
|
+
const functionBody = returnStatement.parent;
|
|
5878
|
+
if (!functionBody || !ts.isBlock(functionBody)) return void 0;
|
|
5879
|
+
const lazyFunction = functionBody.parent;
|
|
5880
|
+
if (!lazyFunction || !ts.isArrowFunction(lazyFunction) && !ts.isFunctionExpression(lazyFunction)) {
|
|
5881
|
+
return void 0;
|
|
5882
|
+
}
|
|
5883
|
+
const callExpression = lazyFunction.parent;
|
|
5884
|
+
if (!callExpression || !ts.isCallExpression(callExpression)) return void 0;
|
|
5885
|
+
return yield* verifyLayerMethodAtCall(callExpression, "sync", lazyFunction);
|
|
5886
|
+
}
|
|
5887
|
+
);
|
|
5888
|
+
const tryMatchLayerEffectInference = fn("effectFnOpportunity.tryMatchLayerEffectInference")(
|
|
5889
|
+
function* (objectLiteral) {
|
|
5890
|
+
const returnStatement = objectLiteral.parent;
|
|
5891
|
+
if (!returnStatement || !ts.isReturnStatement(returnStatement)) return void 0;
|
|
5892
|
+
const generatorBody = returnStatement.parent;
|
|
5893
|
+
if (!generatorBody || !ts.isBlock(generatorBody)) return void 0;
|
|
5894
|
+
const generatorFunction = generatorBody.parent;
|
|
5895
|
+
if (!generatorFunction || !ts.isFunctionExpression(generatorFunction) || !generatorFunction.asteriskToken) {
|
|
5896
|
+
return void 0;
|
|
5897
|
+
}
|
|
5898
|
+
const genCall = generatorFunction.parent;
|
|
5899
|
+
if (!genCall || !ts.isCallExpression(genCall)) return void 0;
|
|
5900
|
+
const parsedEffectGen = yield* option(typeParser.effectGen(genCall));
|
|
5901
|
+
if (parsedEffectGen._tag === "None" || parsedEffectGen.value.generatorFunction !== generatorFunction) {
|
|
5902
|
+
return void 0;
|
|
5903
|
+
}
|
|
5904
|
+
const layerCall = genCall.parent;
|
|
5905
|
+
if (!layerCall || !ts.isCallExpression(layerCall)) return void 0;
|
|
5906
|
+
return yield* verifyLayerMethodAtCall(layerCall, "effect", genCall);
|
|
5907
|
+
}
|
|
5908
|
+
);
|
|
5909
|
+
const tryMatchOfInference = fn("effectFnOpportunity.tryMatchOfInference")(
|
|
5910
|
+
function* (objectLiteral) {
|
|
5911
|
+
const callExpression = objectLiteral.parent;
|
|
5912
|
+
if (!callExpression || !ts.isCallExpression(callExpression)) return void 0;
|
|
5913
|
+
if (callExpression.arguments.length < 1 || callExpression.arguments[0] !== objectLiteral) return void 0;
|
|
5914
|
+
if (!ts.isPropertyAccessExpression(callExpression.expression)) return void 0;
|
|
5915
|
+
if (ts.idText(callExpression.expression.name) !== "of") return void 0;
|
|
5916
|
+
const serviceTagExpression = callExpression.expression.expression;
|
|
5917
|
+
const serviceTagType = typeCheckerUtils.getTypeAtLocation(serviceTagExpression);
|
|
5918
|
+
if (!serviceTagType) return void 0;
|
|
5919
|
+
const isTagLike = yield* pipe(
|
|
5920
|
+
typeParser.contextTag(serviceTagType, serviceTagExpression),
|
|
5921
|
+
orElse2(() => typeParser.serviceType(serviceTagType, serviceTagExpression)),
|
|
5922
|
+
option
|
|
5923
|
+
);
|
|
5924
|
+
if (isTagLike._tag === "None") return void 0;
|
|
5925
|
+
return layerServiceNameFromExpression(serviceTagExpression);
|
|
5926
|
+
}
|
|
5927
|
+
);
|
|
5928
|
+
const tryMatchServiceMapMakeInference = fn("effectFnOpportunity.tryMatchServiceMapMakeInference")(
|
|
5929
|
+
function* (objectLiteral) {
|
|
5930
|
+
const returnStatement = objectLiteral.parent;
|
|
5931
|
+
if (!returnStatement || !ts.isReturnStatement(returnStatement)) return void 0;
|
|
5932
|
+
const generatorBody = returnStatement.parent;
|
|
5933
|
+
if (!generatorBody || !ts.isBlock(generatorBody)) return void 0;
|
|
5934
|
+
const generatorFunction = generatorBody.parent;
|
|
5935
|
+
if (!generatorFunction || !ts.isFunctionExpression(generatorFunction) || !generatorFunction.asteriskToken) {
|
|
5936
|
+
return void 0;
|
|
5937
|
+
}
|
|
5938
|
+
const genCall = generatorFunction.parent;
|
|
5939
|
+
if (!genCall || !ts.isCallExpression(genCall)) return void 0;
|
|
5940
|
+
const parsedEffectGen = yield* option(typeParser.effectGen(genCall));
|
|
5941
|
+
if (parsedEffectGen._tag === "None" || parsedEffectGen.value.generatorFunction !== generatorFunction) {
|
|
5942
|
+
return void 0;
|
|
5943
|
+
}
|
|
5944
|
+
const makeProperty = genCall.parent;
|
|
5945
|
+
if (!makeProperty || !ts.isPropertyAssignment(makeProperty)) return void 0;
|
|
5946
|
+
if (makeProperty.initializer !== genCall) return void 0;
|
|
5947
|
+
if (!ts.isIdentifier(makeProperty.name) || ts.idText(makeProperty.name) !== "make") return void 0;
|
|
5948
|
+
let currentNode = makeProperty.parent;
|
|
5949
|
+
let classDeclaration = void 0;
|
|
5950
|
+
while (currentNode) {
|
|
5951
|
+
if (ts.isClassDeclaration(currentNode)) {
|
|
5952
|
+
classDeclaration = currentNode;
|
|
5953
|
+
break;
|
|
5954
|
+
}
|
|
5955
|
+
currentNode = currentNode.parent;
|
|
5956
|
+
}
|
|
5957
|
+
if (!classDeclaration || !classDeclaration.name) return void 0;
|
|
5958
|
+
const parsedServiceMapService = yield* option(typeParser.extendsServiceMapService(classDeclaration));
|
|
5959
|
+
if (parsedServiceMapService._tag === "None") return void 0;
|
|
5960
|
+
return ts.idText(classDeclaration.name);
|
|
5961
|
+
}
|
|
5962
|
+
);
|
|
5963
|
+
const tryGetLayerInferredTraceName = fn("effectFnOpportunity.tryGetLayerInferredTraceName")(
|
|
5964
|
+
function* (node, suggestedTraceName) {
|
|
5965
|
+
if (!suggestedTraceName) return void 0;
|
|
5966
|
+
if (!(node.parent && ts.isPropertyAssignment(node.parent) && node.parent.initializer === node && node.parent.parent && ts.isObjectLiteralExpression(node.parent.parent))) {
|
|
5967
|
+
return void 0;
|
|
5968
|
+
}
|
|
5969
|
+
const objectLiteral = node.parent.parent;
|
|
5970
|
+
const succeedServiceName = yield* tryMatchLayerSucceedInference(objectLiteral);
|
|
5971
|
+
if (succeedServiceName) return `${succeedServiceName}.${suggestedTraceName}`;
|
|
5972
|
+
const syncServiceName = yield* tryMatchLayerSyncInference(objectLiteral);
|
|
5973
|
+
if (syncServiceName) return `${syncServiceName}.${suggestedTraceName}`;
|
|
5974
|
+
const effectServiceName = yield* tryMatchLayerEffectInference(objectLiteral);
|
|
5975
|
+
if (effectServiceName) return `${effectServiceName}.${suggestedTraceName}`;
|
|
5976
|
+
const ofServiceName = yield* tryMatchOfInference(objectLiteral);
|
|
5977
|
+
if (ofServiceName) return `${ofServiceName}.${suggestedTraceName}`;
|
|
5978
|
+
const serviceMapMakeServiceName = yield* tryMatchServiceMapMakeInference(objectLiteral);
|
|
5979
|
+
return serviceMapMakeServiceName ? `${serviceMapMakeServiceName}.${suggestedTraceName}` : void 0;
|
|
5980
|
+
}
|
|
5981
|
+
);
|
|
5982
|
+
const getInferredTraceName = fn("effectFnOpportunity.getInferredTraceName")(
|
|
5983
|
+
function* (node, suggestedTraceName) {
|
|
5984
|
+
const inferredFromLayer = yield* tryGetLayerInferredTraceName(node, suggestedTraceName);
|
|
5985
|
+
if (inferredFromLayer) return inferredFromLayer;
|
|
5986
|
+
if (ts.isFunctionDeclaration(node) && node.name && hasExportModifier(node)) {
|
|
5987
|
+
return ts.idText(node.name);
|
|
5988
|
+
}
|
|
5989
|
+
if (node.parent && ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name) && node.parent.initializer === node) {
|
|
5990
|
+
const variableDeclarationList = node.parent.parent;
|
|
5991
|
+
const variableStatement = variableDeclarationList?.parent;
|
|
5992
|
+
if (variableDeclarationList && ts.isVariableDeclarationList(variableDeclarationList) && variableStatement && ts.isVariableStatement(variableStatement) && hasExportModifier(variableStatement) && (variableDeclarationList.flags & ts.NodeFlags.Const) !== 0) {
|
|
5993
|
+
return ts.idText(node.parent.name);
|
|
5994
|
+
}
|
|
5995
|
+
}
|
|
5996
|
+
return void 0;
|
|
5997
|
+
}
|
|
5998
|
+
);
|
|
5785
5999
|
const areParametersReferencedIn = (fnNode, nodes) => {
|
|
5786
6000
|
if (fnNode.parameters.length === 0 || nodes.length === 0) return false;
|
|
5787
6001
|
const firstParam = fnNode.parameters[0];
|
|
@@ -5866,7 +6080,10 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5866
6080
|
);
|
|
5867
6081
|
};
|
|
5868
6082
|
const parseEffectFnOpportunityTargetGen = fn("effectFnOpportunity.parseEffectFnOpportunityTarget")(
|
|
5869
|
-
function* (node, returnType,
|
|
6083
|
+
function* (node, returnType, nameIdentifier) {
|
|
6084
|
+
const suggestedTraceName = nameIdentifier ? ts.isIdentifier(nameIdentifier) ? ts.idText(nameIdentifier) : nameIdentifier.text : void 0;
|
|
6085
|
+
const inferredTraceName = yield* getInferredTraceName(node, suggestedTraceName);
|
|
6086
|
+
const hasStrictLayerInferredName = inferredTraceName !== void 0 && inferredTraceName !== suggestedTraceName;
|
|
5870
6087
|
if (yield* isInsideEffectFn(node)) {
|
|
5871
6088
|
return yield* TypeParserIssue.issue;
|
|
5872
6089
|
}
|
|
@@ -5875,11 +6092,11 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5875
6092
|
const opportunity = yield* pipe(
|
|
5876
6093
|
tryParseGenOpportunity(node),
|
|
5877
6094
|
orElse2(() => {
|
|
5878
|
-
if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) {
|
|
6095
|
+
if (ts.isArrowFunction(node) && !ts.isBlock(node.body) && !hasStrictLayerInferredName) {
|
|
5879
6096
|
return TypeParserIssue.issue;
|
|
5880
6097
|
}
|
|
5881
6098
|
const body = ts.isArrowFunction(node) ? node.body : node.body;
|
|
5882
|
-
if (!body || !ts.isBlock(body) || body.statements.length <= 5) {
|
|
6099
|
+
if ((!body || !ts.isBlock(body) || body.statements.length <= 5) && !hasStrictLayerInferredName) {
|
|
5883
6100
|
return TypeParserIssue.issue;
|
|
5884
6101
|
}
|
|
5885
6102
|
return succeed3({
|
|
@@ -5894,7 +6111,8 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5894
6111
|
node,
|
|
5895
6112
|
nameIdentifier,
|
|
5896
6113
|
effectModuleName: opportunity.effectModuleName,
|
|
5897
|
-
inferredTraceName
|
|
6114
|
+
inferredTraceName,
|
|
6115
|
+
suggestedTraceName,
|
|
5898
6116
|
explicitTraceExpression: opportunity.explicitTraceExpression,
|
|
5899
6117
|
pipeArguments: opportunity.pipeArguments,
|
|
5900
6118
|
generatorFunction: opportunity.generatorFunction,
|
|
@@ -5904,27 +6122,26 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5904
6122
|
);
|
|
5905
6123
|
const parseEffectFnOpportunityTarget = (node) => {
|
|
5906
6124
|
if (!ts.isFunctionExpression(node) && !ts.isArrowFunction(node) && !ts.isFunctionDeclaration(node)) {
|
|
5907
|
-
return
|
|
6125
|
+
return;
|
|
5908
6126
|
}
|
|
5909
6127
|
if ((ts.isFunctionExpression(node) || ts.isFunctionDeclaration(node)) && node.asteriskToken) {
|
|
5910
|
-
return
|
|
6128
|
+
return;
|
|
5911
6129
|
}
|
|
5912
6130
|
if (ts.isFunctionExpression(node) && node.name) {
|
|
5913
|
-
return
|
|
6131
|
+
return;
|
|
5914
6132
|
}
|
|
5915
6133
|
if (node.type) {
|
|
5916
|
-
return
|
|
6134
|
+
return;
|
|
5917
6135
|
}
|
|
5918
6136
|
const functionType = typeChecker.getTypeAtLocation(node);
|
|
5919
|
-
if (!functionType) return
|
|
6137
|
+
if (!functionType) return;
|
|
5920
6138
|
const callSignatures = typeChecker.getSignaturesOfType(functionType, ts.SignatureKind.Call);
|
|
5921
|
-
if (callSignatures.length !== 1) return
|
|
6139
|
+
if (callSignatures.length !== 1) return;
|
|
5922
6140
|
const signature = callSignatures[0];
|
|
5923
6141
|
const returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
5924
6142
|
const nameIdentifier = getNameIdentifier(node);
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
return parseEffectFnOpportunityTargetGen(node, returnType, traceName, nameIdentifier);
|
|
6143
|
+
if (!nameIdentifier) return;
|
|
6144
|
+
return parseEffectFnOpportunityTargetGen(node, returnType, nameIdentifier);
|
|
5928
6145
|
};
|
|
5929
6146
|
const getFunctionBodyBlock = (node) => {
|
|
5930
6147
|
if (ts.isArrowFunction(node)) {
|
|
@@ -5998,18 +6215,21 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
5998
6215
|
while (nodeToVisit.length > 0) {
|
|
5999
6216
|
const node = nodeToVisit.shift();
|
|
6000
6217
|
ts.forEachChild(node, appendNodeToVisit);
|
|
6001
|
-
const
|
|
6002
|
-
if (
|
|
6003
|
-
|
|
6218
|
+
const test = parseEffectFnOpportunityTarget(node);
|
|
6219
|
+
if (!test) continue;
|
|
6220
|
+
const target = yield* orUndefined(test);
|
|
6221
|
+
if (!target) continue;
|
|
6222
|
+
if (target.hasParamsInPipeArgs) continue;
|
|
6004
6223
|
const {
|
|
6005
6224
|
effectModuleName,
|
|
6006
6225
|
explicitTraceExpression,
|
|
6007
6226
|
inferredTraceName,
|
|
6008
6227
|
nameIdentifier,
|
|
6009
6228
|
node: targetNode,
|
|
6010
|
-
pipeArguments: pipeArguments2
|
|
6011
|
-
|
|
6012
|
-
|
|
6229
|
+
pipeArguments: pipeArguments2,
|
|
6230
|
+
suggestedTraceName
|
|
6231
|
+
} = target;
|
|
6232
|
+
const innerFunction = target.generatorFunction ?? targetNode;
|
|
6013
6233
|
const fixes = [];
|
|
6014
6234
|
if (pluginOptions.effectFn.includes("span") && explicitTraceExpression) {
|
|
6015
6235
|
fixes.push({
|
|
@@ -6029,7 +6249,7 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6029
6249
|
})
|
|
6030
6250
|
});
|
|
6031
6251
|
}
|
|
6032
|
-
if (pluginOptions.effectFn.includes("untraced") && target.
|
|
6252
|
+
if (pluginOptions.effectFn.includes("untraced") && target.generatorFunction) {
|
|
6033
6253
|
fixes.push({
|
|
6034
6254
|
fixName: "effectFnOpportunity_toEffectFnUntraced",
|
|
6035
6255
|
description: "Convert to Effect.fnUntraced",
|
|
@@ -6051,22 +6271,41 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6051
6271
|
})
|
|
6052
6272
|
});
|
|
6053
6273
|
}
|
|
6054
|
-
if (
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6274
|
+
if (!explicitTraceExpression) {
|
|
6275
|
+
if (pluginOptions.effectFn.includes("inferred-span") && inferredTraceName) {
|
|
6276
|
+
fixes.push({
|
|
6277
|
+
fixName: "effectFnOpportunity_toEffectFnSpanInferred",
|
|
6278
|
+
description: `Convert to Effect.fn("${inferredTraceName}")`,
|
|
6279
|
+
apply: gen(function* () {
|
|
6280
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
6281
|
+
const newNode = createEffectFnNode(
|
|
6282
|
+
targetNode,
|
|
6283
|
+
innerFunction,
|
|
6284
|
+
effectModuleName,
|
|
6285
|
+
inferredTraceName,
|
|
6286
|
+
pipeArguments2
|
|
6287
|
+
);
|
|
6288
|
+
changeTracker.replaceNode(sourceFile, targetNode, newNode);
|
|
6289
|
+
})
|
|
6290
|
+
});
|
|
6291
|
+
}
|
|
6292
|
+
if (pluginOptions.effectFn.includes("suggested-span") && suggestedTraceName && (!pluginOptions.effectFn.includes("inferred-span") || suggestedTraceName !== inferredTraceName)) {
|
|
6293
|
+
fixes.push({
|
|
6294
|
+
fixName: "effectFnOpportunity_toEffectFnSpanSuggested",
|
|
6295
|
+
description: `Convert to Effect.fn("${suggestedTraceName}")`,
|
|
6296
|
+
apply: gen(function* () {
|
|
6297
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
6298
|
+
const newNode = createEffectFnNode(
|
|
6299
|
+
targetNode,
|
|
6300
|
+
innerFunction,
|
|
6301
|
+
effectModuleName,
|
|
6302
|
+
suggestedTraceName,
|
|
6303
|
+
pipeArguments2
|
|
6304
|
+
);
|
|
6305
|
+
changeTracker.replaceNode(sourceFile, targetNode, newNode);
|
|
6306
|
+
})
|
|
6307
|
+
});
|
|
6308
|
+
}
|
|
6070
6309
|
}
|
|
6071
6310
|
if (fixes.length === 0) continue;
|
|
6072
6311
|
const generateExpectedSignature = () => {
|
|
@@ -6079,7 +6318,7 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6079
6318
|
}
|
|
6080
6319
|
return "_";
|
|
6081
6320
|
}).join(", ");
|
|
6082
|
-
const fnSignature = `function*${typeParamNames}(${paramNames}) { ... }`;
|
|
6321
|
+
const fnSignature = ts.isArrowFunction(innerFunction) ? `${typeParamNames}(${paramNames}) => { ... }` : isGeneratorFunction(innerFunction) ? `function*${typeParamNames}(${paramNames}) { ... }` : `function${typeParamNames}(${paramNames}) { ... }`;
|
|
6083
6322
|
const pipeArgsForWithSpan = pipeArguments2.slice(0, -1);
|
|
6084
6323
|
const pipeArgsSuffix = (args3) => args3.length > 0 ? ", ...pipeTransformations" : "";
|
|
6085
6324
|
switch (firstFix.fixName) {
|
|
@@ -6093,6 +6332,8 @@ var effectFnOpportunity = createDiagnostic({
|
|
|
6093
6332
|
return `${effectModuleName}.fn(${fnSignature}${pipeArgsSuffix(pipeArguments2)})`;
|
|
6094
6333
|
case "effectFnOpportunity_toEffectFnSpanInferred":
|
|
6095
6334
|
return `${effectModuleName}.fn("${inferredTraceName}")(${fnSignature}${pipeArgsSuffix(pipeArguments2)})`;
|
|
6335
|
+
case "effectFnOpportunity_toEffectFnSpanSuggested":
|
|
6336
|
+
return `${effectModuleName}.fn("${suggestedTraceName}")(${fnSignature}${pipeArgsSuffix(pipeArguments2)})`;
|
|
6096
6337
|
default:
|
|
6097
6338
|
return `${effectModuleName}.fn(${fnSignature})`;
|
|
6098
6339
|
}
|
|
@@ -6145,6 +6386,70 @@ var effectGenUsesAdapter = createDiagnostic({
|
|
|
6145
6386
|
})
|
|
6146
6387
|
});
|
|
6147
6388
|
|
|
6389
|
+
// src/diagnostics/effectInFailure.ts
|
|
6390
|
+
var effectInFailure = createDiagnostic({
|
|
6391
|
+
name: "effectInFailure",
|
|
6392
|
+
code: 49,
|
|
6393
|
+
description: "Warns when an Effect is used inside an Effect failure channel",
|
|
6394
|
+
severity: "warning",
|
|
6395
|
+
apply: fn("effectInFailure.apply")(function* (sourceFile, report) {
|
|
6396
|
+
const ts = yield* service(TypeScriptApi);
|
|
6397
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
6398
|
+
const typeParser = yield* service(TypeParser);
|
|
6399
|
+
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
6400
|
+
const isStrictEffectType = cachedBy(
|
|
6401
|
+
fn("effectInFailure.isStrictEffectType")(function* (type, atLocation) {
|
|
6402
|
+
yield* typeParser.strictEffectType(type, atLocation);
|
|
6403
|
+
return true;
|
|
6404
|
+
}),
|
|
6405
|
+
"effectInFailure.isStrictEffectType",
|
|
6406
|
+
(type) => type
|
|
6407
|
+
);
|
|
6408
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
6409
|
+
const stack = [sourceFile];
|
|
6410
|
+
const shouldSkipBecauseChildMatched = /* @__PURE__ */ new WeakSet();
|
|
6411
|
+
while (stack.length > 0) {
|
|
6412
|
+
const node = stack.pop();
|
|
6413
|
+
if (!visited.has(node)) {
|
|
6414
|
+
visited.add(node);
|
|
6415
|
+
stack.push(node);
|
|
6416
|
+
ts.forEachChild(node, (child) => {
|
|
6417
|
+
stack.push(child);
|
|
6418
|
+
return void 0;
|
|
6419
|
+
});
|
|
6420
|
+
continue;
|
|
6421
|
+
}
|
|
6422
|
+
if (shouldSkipBecauseChildMatched.has(node)) {
|
|
6423
|
+
if (node.parent) shouldSkipBecauseChildMatched.add(node.parent);
|
|
6424
|
+
continue;
|
|
6425
|
+
}
|
|
6426
|
+
const type = typeCheckerUtils.getTypeAtLocation(node);
|
|
6427
|
+
if (!type) continue;
|
|
6428
|
+
const effect = yield* orUndefined(typeParser.strictEffectType(type, node));
|
|
6429
|
+
if (!effect) continue;
|
|
6430
|
+
const failureMembers = typeCheckerUtils.unrollUnionMembers(effect.E);
|
|
6431
|
+
let memberWithEffect = void 0;
|
|
6432
|
+
for (const member of failureMembers) {
|
|
6433
|
+
const isMemberEffect = yield* orUndefined(isStrictEffectType(member, node));
|
|
6434
|
+
if (isMemberEffect) {
|
|
6435
|
+
memberWithEffect = member;
|
|
6436
|
+
break;
|
|
6437
|
+
}
|
|
6438
|
+
}
|
|
6439
|
+
if (!memberWithEffect) continue;
|
|
6440
|
+
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.`;
|
|
6441
|
+
report({
|
|
6442
|
+
location: node,
|
|
6443
|
+
messageText,
|
|
6444
|
+
fixes: []
|
|
6445
|
+
});
|
|
6446
|
+
if (node.parent) {
|
|
6447
|
+
shouldSkipBecauseChildMatched.add(node.parent);
|
|
6448
|
+
}
|
|
6449
|
+
}
|
|
6450
|
+
})
|
|
6451
|
+
});
|
|
6452
|
+
|
|
6148
6453
|
// src/diagnostics/effectInVoidSuccess.ts
|
|
6149
6454
|
var effectInVoidSuccess = createDiagnostic({
|
|
6150
6455
|
name: "effectInVoidSuccess",
|
|
@@ -7513,6 +7818,7 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
7513
7818
|
const ts = yield* service(TypeScriptApi);
|
|
7514
7819
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
7515
7820
|
const typeParser = yield* service(TypeParser);
|
|
7821
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
7516
7822
|
const nodeToVisit = [];
|
|
7517
7823
|
const appendNodeToVisit = (node) => {
|
|
7518
7824
|
nodeToVisit.push(node);
|
|
@@ -7522,50 +7828,32 @@ var missingReturnYieldStar = createDiagnostic({
|
|
|
7522
7828
|
while (nodeToVisit.length > 0) {
|
|
7523
7829
|
const node = nodeToVisit.shift();
|
|
7524
7830
|
ts.forEachChild(node, appendNodeToVisit);
|
|
7525
|
-
if (ts.
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
node,
|
|
7552
|
-
ts.factory.createReturnStatement(
|
|
7553
|
-
node
|
|
7554
|
-
)
|
|
7555
|
-
);
|
|
7556
|
-
})
|
|
7557
|
-
}] : [];
|
|
7558
|
-
report({
|
|
7559
|
-
location: node,
|
|
7560
|
-
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.`,
|
|
7561
|
-
fixes: fix
|
|
7562
|
-
});
|
|
7563
|
-
}
|
|
7564
|
-
}
|
|
7565
|
-
}
|
|
7566
|
-
}
|
|
7567
|
-
}
|
|
7568
|
-
}
|
|
7831
|
+
if (!ts.isExpressionStatement(node)) continue;
|
|
7832
|
+
const unwrapped = tsUtils.skipOuterExpressions(node.expression);
|
|
7833
|
+
if (!ts.isYieldExpression(unwrapped) || !unwrapped.expression || !unwrapped.asteriskToken) continue;
|
|
7834
|
+
const type = typeCheckerUtils.getTypeAtLocation(unwrapped.expression);
|
|
7835
|
+
if (!type) continue;
|
|
7836
|
+
const maybeEffect = yield* option(typeParser.effectYieldableType(type, unwrapped.expression));
|
|
7837
|
+
if (!(isSome2(maybeEffect) && maybeEffect.value.A.flags & ts.TypeFlags.Never)) continue;
|
|
7838
|
+
const { effectGen, scopeNode } = yield* typeParser.findEnclosingScopes(node);
|
|
7839
|
+
if (!effectGen || scopeNode && scopeNode !== effectGen.generatorFunction) continue;
|
|
7840
|
+
const fix = [{
|
|
7841
|
+
fixName: "missingReturnYieldStar_fix",
|
|
7842
|
+
description: "Add return statement",
|
|
7843
|
+
apply: gen(function* () {
|
|
7844
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
7845
|
+
changeTracker.replaceNode(
|
|
7846
|
+
sourceFile,
|
|
7847
|
+
node,
|
|
7848
|
+
ts.factory.createReturnStatement(node.expression)
|
|
7849
|
+
);
|
|
7850
|
+
})
|
|
7851
|
+
}];
|
|
7852
|
+
report({
|
|
7853
|
+
location: unwrapped,
|
|
7854
|
+
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.`,
|
|
7855
|
+
fixes: fix
|
|
7856
|
+
});
|
|
7569
7857
|
}
|
|
7570
7858
|
})
|
|
7571
7859
|
});
|
|
@@ -7882,9 +8170,7 @@ var effectModuleMigrationDb = {
|
|
|
7882
8170
|
"failSync": asUnchanged,
|
|
7883
8171
|
"fiberId": asUnchanged,
|
|
7884
8172
|
"filter": asUnchanged,
|
|
7885
|
-
"filterMap":
|
|
7886
|
-
"Use Effect.filter or Effect.map with Option instead."
|
|
7887
|
-
),
|
|
8173
|
+
"filterMap": asUnchanged,
|
|
7888
8174
|
"filterOrElse": asUnchanged,
|
|
7889
8175
|
"filterOrFail": asUnchanged,
|
|
7890
8176
|
"flatMap": asUnchanged,
|
|
@@ -8172,9 +8458,7 @@ var effectModuleMigrationDb = {
|
|
|
8172
8458
|
"finalizersMask": asRemoved(
|
|
8173
8459
|
"Finalizer masking has been removed in Effect v4."
|
|
8174
8460
|
),
|
|
8175
|
-
"findFirst":
|
|
8176
|
-
"Use Effect.forEach with early return instead."
|
|
8177
|
-
),
|
|
8461
|
+
"findFirst": asUnchanged,
|
|
8178
8462
|
"firstSuccessOf": asRemoved(
|
|
8179
8463
|
"Use Effect.raceAll instead."
|
|
8180
8464
|
),
|
|
@@ -11042,6 +11326,7 @@ var diagnostics = [
|
|
|
11042
11326
|
missingEffectServiceDependency,
|
|
11043
11327
|
missingLayerContext,
|
|
11044
11328
|
floatingEffect,
|
|
11329
|
+
effectInFailure,
|
|
11045
11330
|
missingStarInYieldEffectGen,
|
|
11046
11331
|
unnecessaryEffectGen,
|
|
11047
11332
|
unnecessaryFailYieldableError,
|