@effect/language-service 0.33.2 → 0.35.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 +6 -4
- package/cli.js +139 -7
- package/cli.js.map +1 -1
- package/index.js +321 -54
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +164 -52
- package/transform.js.map +1 -1
package/index.js
CHANGED
|
@@ -135,9 +135,6 @@ var isObject = (input) => isRecordOrArray(input) || isFunction2(input);
|
|
|
135
135
|
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObject(self) && property in self);
|
|
136
136
|
var isRecord = (input) => isRecordOrArray(input) && !Array.isArray(input);
|
|
137
137
|
|
|
138
|
-
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/internal/errors.js
|
|
139
|
-
var getBugErrorMessage = (message) => `BUG: ${message} - please report an issue at https://github.com/Effect-TS/effect/issues`;
|
|
140
|
-
|
|
141
138
|
// node_modules/.pnpm/effect@3.17.1/node_modules/effect/dist/esm/Utils.js
|
|
142
139
|
var GenKindTypeId = /* @__PURE__ */ Symbol.for("effect/Gen/GenKind");
|
|
143
140
|
var GenKindImpl = class {
|
|
@@ -238,12 +235,6 @@ var YieldWrap = class {
|
|
|
238
235
|
return this.#value;
|
|
239
236
|
}
|
|
240
237
|
};
|
|
241
|
-
function yieldWrapGet(self) {
|
|
242
|
-
if (typeof self === "object" && self !== null && YieldWrapTypeId in self) {
|
|
243
|
-
return self[YieldWrapTypeId]();
|
|
244
|
-
}
|
|
245
|
-
throw new Error(getBugErrorMessage("yieldWrapGet"));
|
|
246
|
-
}
|
|
247
238
|
var structuralRegionState = /* @__PURE__ */ globalValue("effect/Utils/isStructuralRegion", () => ({
|
|
248
239
|
enabled: false,
|
|
249
240
|
tester: void 0
|
|
@@ -748,6 +739,31 @@ var NanoTag = class {
|
|
|
748
739
|
}
|
|
749
740
|
};
|
|
750
741
|
var Tag = (identifier) => new NanoTag(identifier);
|
|
742
|
+
var SingleShotGen2 = class _SingleShotGen {
|
|
743
|
+
called = false;
|
|
744
|
+
self;
|
|
745
|
+
constructor(self) {
|
|
746
|
+
this.self = self;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* @since 2.0.0
|
|
750
|
+
*/
|
|
751
|
+
next(a) {
|
|
752
|
+
return this.called ? {
|
|
753
|
+
value: a,
|
|
754
|
+
done: true
|
|
755
|
+
} : (this.called = true, {
|
|
756
|
+
value: this.self,
|
|
757
|
+
done: false
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* @since 2.0.0
|
|
762
|
+
*/
|
|
763
|
+
[Symbol.iterator]() {
|
|
764
|
+
return new _SingleShotGen(this.self);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
751
767
|
var evaluate = Symbol.for("Nano.evaluate");
|
|
752
768
|
var contA = Symbol.for("Nano.contA");
|
|
753
769
|
var contE = Symbol.for("Nano.contE");
|
|
@@ -762,7 +778,7 @@ var NanoDefectException = class {
|
|
|
762
778
|
};
|
|
763
779
|
var PrimitiveProto = {
|
|
764
780
|
[Symbol.iterator]() {
|
|
765
|
-
return new
|
|
781
|
+
return new SingleShotGen2(this);
|
|
766
782
|
}
|
|
767
783
|
};
|
|
768
784
|
var SucceedProto = {
|
|
@@ -885,7 +901,7 @@ var FromIteratorProto = {
|
|
|
885
901
|
const state = this[args][0].next(value);
|
|
886
902
|
if (state.done) return succeed(state.value);
|
|
887
903
|
fiber._stack.push(this);
|
|
888
|
-
return
|
|
904
|
+
return state.value;
|
|
889
905
|
},
|
|
890
906
|
[evaluate](fiber) {
|
|
891
907
|
return this[contA](this[args][1], fiber);
|
|
@@ -1256,7 +1272,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1256
1272
|
function isNodeInRange(textRange) {
|
|
1257
1273
|
return (node) => node.pos <= textRange.pos && node.end >= textRange.end;
|
|
1258
1274
|
}
|
|
1259
|
-
function
|
|
1275
|
+
function transformAsyncAwaitToEffectGeneratorBody(body, onAwait) {
|
|
1260
1276
|
function visitor(_) {
|
|
1261
1277
|
if (ts.isAwaitExpression(_)) {
|
|
1262
1278
|
const expression = ts.visitEachChild(_.expression, visitor, ts.nullTransformationContext);
|
|
@@ -1267,7 +1283,44 @@ function makeTypeScriptUtils(ts) {
|
|
|
1267
1283
|
}
|
|
1268
1284
|
return ts.visitEachChild(_, visitor, ts.nullTransformationContext);
|
|
1269
1285
|
}
|
|
1270
|
-
|
|
1286
|
+
return visitor(body);
|
|
1287
|
+
}
|
|
1288
|
+
function transformAsyncAwaitToEffectFn(node, effectModuleName, onAwait) {
|
|
1289
|
+
const generatorBody = transformAsyncAwaitToEffectGeneratorBody(node.body, onAwait);
|
|
1290
|
+
const fnName = node.name && ts.isIdentifier(node.name) ? node.name : ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name) && node.parent.initializer === node ? node.parent.name : void 0;
|
|
1291
|
+
let fnCall = ts.factory.createPropertyAccessExpression(
|
|
1292
|
+
ts.factory.createIdentifier(effectModuleName),
|
|
1293
|
+
"fn"
|
|
1294
|
+
);
|
|
1295
|
+
if (fnName) {
|
|
1296
|
+
fnCall = ts.factory.createCallExpression(
|
|
1297
|
+
fnName,
|
|
1298
|
+
void 0,
|
|
1299
|
+
[ts.factory.createStringLiteral(fnName.text)]
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
return tryPreserveDeclarationSemantics(
|
|
1303
|
+
node,
|
|
1304
|
+
ts.factory.createCallExpression(
|
|
1305
|
+
fnCall,
|
|
1306
|
+
void 0,
|
|
1307
|
+
[
|
|
1308
|
+
ts.factory.createFunctionExpression(
|
|
1309
|
+
void 0,
|
|
1310
|
+
ts.factory.createToken(ts.SyntaxKind.AsteriskToken),
|
|
1311
|
+
void 0,
|
|
1312
|
+
node.typeParameters,
|
|
1313
|
+
node.parameters,
|
|
1314
|
+
void 0,
|
|
1315
|
+
ts.isBlock(generatorBody) ? generatorBody : ts.factory.createBlock([ts.factory.createReturnStatement(generatorBody)])
|
|
1316
|
+
)
|
|
1317
|
+
]
|
|
1318
|
+
),
|
|
1319
|
+
true
|
|
1320
|
+
);
|
|
1321
|
+
}
|
|
1322
|
+
function transformAsyncAwaitToEffectGen(node, effectModuleName, onAwait) {
|
|
1323
|
+
const generatorBody = transformAsyncAwaitToEffectGeneratorBody(node.body, onAwait);
|
|
1271
1324
|
const effectGenCallExp = createEffectGenCallExpression(effectModuleName, generatorBody);
|
|
1272
1325
|
let currentFlags = ts.getCombinedModifierFlags(node);
|
|
1273
1326
|
currentFlags &= ~ts.ModifierFlags.Async;
|
|
@@ -1371,12 +1424,15 @@ function makeTypeScriptUtils(ts) {
|
|
|
1371
1424
|
}
|
|
1372
1425
|
return typeNode;
|
|
1373
1426
|
}
|
|
1374
|
-
function tryPreserveDeclarationSemantics(nodeToReplace, node) {
|
|
1427
|
+
function tryPreserveDeclarationSemantics(nodeToReplace, node, dropAsync) {
|
|
1375
1428
|
if (!ts.isExpression(node)) return node;
|
|
1376
1429
|
if (ts.isFunctionDeclaration(nodeToReplace)) {
|
|
1377
1430
|
if (!nodeToReplace.name) return node;
|
|
1431
|
+
let currentFlags = ts.getCombinedModifierFlags(nodeToReplace);
|
|
1432
|
+
currentFlags &= ~ts.ModifierFlags.Async;
|
|
1433
|
+
const newModifiers = dropAsync ? ts.factory.createModifiersFromModifierFlags(currentFlags) : nodeToReplace.modifiers;
|
|
1378
1434
|
return ts.factory.createVariableStatement(
|
|
1379
|
-
|
|
1435
|
+
newModifiers,
|
|
1380
1436
|
ts.factory.createVariableDeclarationList(
|
|
1381
1437
|
[ts.factory.createVariableDeclaration(
|
|
1382
1438
|
nodeToReplace.name,
|
|
@@ -1388,8 +1444,11 @@ function makeTypeScriptUtils(ts) {
|
|
|
1388
1444
|
)
|
|
1389
1445
|
);
|
|
1390
1446
|
} else if (ts.isMethodDeclaration(nodeToReplace)) {
|
|
1447
|
+
let currentFlags = ts.getCombinedModifierFlags(nodeToReplace);
|
|
1448
|
+
currentFlags &= ~ts.ModifierFlags.Async;
|
|
1449
|
+
const newModifiers = dropAsync ? ts.factory.createModifiersFromModifierFlags(currentFlags) : nodeToReplace.modifiers;
|
|
1391
1450
|
return ts.factory.createPropertyDeclaration(
|
|
1392
|
-
|
|
1451
|
+
newModifiers,
|
|
1393
1452
|
nodeToReplace.name,
|
|
1394
1453
|
void 0,
|
|
1395
1454
|
void 0,
|
|
@@ -1492,6 +1551,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1492
1551
|
getAncestorNodesInRange,
|
|
1493
1552
|
toTextRange,
|
|
1494
1553
|
isNodeInRange,
|
|
1554
|
+
transformAsyncAwaitToEffectFn,
|
|
1495
1555
|
transformAsyncAwaitToEffectGen,
|
|
1496
1556
|
findImportedModuleIdentifierByPackageAndNameOrBarrel,
|
|
1497
1557
|
simplifyTypeNode,
|
|
@@ -4475,6 +4535,68 @@ var outdatedEffectCodegen = createDiagnostic({
|
|
|
4475
4535
|
})
|
|
4476
4536
|
});
|
|
4477
4537
|
|
|
4538
|
+
// src/diagnostics/overriddenSchemaConstructor.ts
|
|
4539
|
+
var overriddenSchemaConstructor = createDiagnostic({
|
|
4540
|
+
name: "overriddenSchemaConstructor",
|
|
4541
|
+
code: 30,
|
|
4542
|
+
severity: "error",
|
|
4543
|
+
apply: fn("overriddenSchemaConstructor.apply")(function* (sourceFile, report) {
|
|
4544
|
+
const ts = yield* service(TypeScriptApi);
|
|
4545
|
+
const typeParser = yield* service(TypeParser);
|
|
4546
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
4547
|
+
const nodeToVisit = [];
|
|
4548
|
+
const appendNodeToVisit = (node) => {
|
|
4549
|
+
nodeToVisit.push(node);
|
|
4550
|
+
return void 0;
|
|
4551
|
+
};
|
|
4552
|
+
ts.forEachChild(sourceFile, appendNodeToVisit);
|
|
4553
|
+
while (nodeToVisit.length > 0) {
|
|
4554
|
+
const node = nodeToVisit.shift();
|
|
4555
|
+
if (ts.isClassDeclaration(node) && node.heritageClauses) {
|
|
4556
|
+
let extendsSchema = false;
|
|
4557
|
+
for (const heritageClause of node.heritageClauses) {
|
|
4558
|
+
if (heritageClause.token === ts.SyntaxKind.ExtendsKeyword) {
|
|
4559
|
+
for (const type of heritageClause.types) {
|
|
4560
|
+
const typeAtLocation = typeChecker.getTypeAtLocation(type.expression);
|
|
4561
|
+
const isSchema = yield* pipe(
|
|
4562
|
+
typeParser.effectSchemaType(typeAtLocation, type.expression),
|
|
4563
|
+
map3(() => true),
|
|
4564
|
+
orElse2(() => succeed(false))
|
|
4565
|
+
);
|
|
4566
|
+
if (isSchema) {
|
|
4567
|
+
extendsSchema = true;
|
|
4568
|
+
break;
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
if (extendsSchema) break;
|
|
4573
|
+
}
|
|
4574
|
+
if (extendsSchema) {
|
|
4575
|
+
const members = node.members;
|
|
4576
|
+
for (const member of members) {
|
|
4577
|
+
if (ts.isConstructorDeclaration(member)) {
|
|
4578
|
+
report({
|
|
4579
|
+
location: member,
|
|
4580
|
+
messageText: "Classes extending Schema must not override the constructor",
|
|
4581
|
+
fixes: [{
|
|
4582
|
+
fixName: "overriddenSchemaConstructor_fix",
|
|
4583
|
+
description: "Remove the constructor override",
|
|
4584
|
+
apply: gen(function* () {
|
|
4585
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
4586
|
+
changeTracker.delete(sourceFile, member);
|
|
4587
|
+
})
|
|
4588
|
+
}]
|
|
4589
|
+
});
|
|
4590
|
+
break;
|
|
4591
|
+
}
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4595
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
4596
|
+
}
|
|
4597
|
+
})
|
|
4598
|
+
});
|
|
4599
|
+
|
|
4478
4600
|
// src/diagnostics/returnEffectInGen.ts
|
|
4479
4601
|
var returnEffectInGen = createDiagnostic({
|
|
4480
4602
|
name: "returnEffectInGen",
|
|
@@ -4993,6 +5115,7 @@ var diagnostics = [
|
|
|
4993
5115
|
strictBooleanExpressions,
|
|
4994
5116
|
multipleEffectProvide,
|
|
4995
5117
|
outdatedEffectCodegen,
|
|
5118
|
+
overriddenSchemaConstructor,
|
|
4996
5119
|
unsupportedServiceAccessors
|
|
4997
5120
|
];
|
|
4998
5121
|
|
|
@@ -10659,6 +10782,156 @@ function quickInfo(sourceFile, position, quickInfo2) {
|
|
|
10659
10782
|
});
|
|
10660
10783
|
}
|
|
10661
10784
|
|
|
10785
|
+
// src/refactors/asyncAwaitToFn.ts
|
|
10786
|
+
var asyncAwaitToFn = createRefactor({
|
|
10787
|
+
name: "asyncAwaitToFn",
|
|
10788
|
+
description: "Convert to Effect.fn",
|
|
10789
|
+
apply: fn("asyncAwaitToFn.apply")(function* (sourceFile, textRange) {
|
|
10790
|
+
const ts = yield* service(TypeScriptApi);
|
|
10791
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10792
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
10793
|
+
const maybeNode = pipe(
|
|
10794
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10795
|
+
filter(
|
|
10796
|
+
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
10797
|
+
),
|
|
10798
|
+
filter((node2) => !!node2.body),
|
|
10799
|
+
filter((node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)),
|
|
10800
|
+
head
|
|
10801
|
+
);
|
|
10802
|
+
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
10803
|
+
const node = maybeNode.value;
|
|
10804
|
+
return {
|
|
10805
|
+
kind: "refactor.rewrite.effect.asyncAwaitToFn",
|
|
10806
|
+
description: "Rewrite to Effect.fn",
|
|
10807
|
+
apply: pipe(
|
|
10808
|
+
gen(function* () {
|
|
10809
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
10810
|
+
const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10811
|
+
sourceFile,
|
|
10812
|
+
"effect",
|
|
10813
|
+
"Effect"
|
|
10814
|
+
) || "Effect";
|
|
10815
|
+
const newDeclaration = tsUtils.transformAsyncAwaitToEffectFn(
|
|
10816
|
+
node,
|
|
10817
|
+
effectModuleIdentifierName,
|
|
10818
|
+
(expression) => ts.factory.createCallExpression(
|
|
10819
|
+
ts.factory.createPropertyAccessExpression(
|
|
10820
|
+
ts.factory.createIdentifier(effectModuleIdentifierName),
|
|
10821
|
+
"promise"
|
|
10822
|
+
),
|
|
10823
|
+
void 0,
|
|
10824
|
+
[
|
|
10825
|
+
ts.factory.createArrowFunction(
|
|
10826
|
+
void 0,
|
|
10827
|
+
void 0,
|
|
10828
|
+
[],
|
|
10829
|
+
void 0,
|
|
10830
|
+
void 0,
|
|
10831
|
+
expression
|
|
10832
|
+
)
|
|
10833
|
+
]
|
|
10834
|
+
)
|
|
10835
|
+
);
|
|
10836
|
+
changeTracker.replaceNode(sourceFile, node, newDeclaration);
|
|
10837
|
+
}),
|
|
10838
|
+
provideService(TypeScriptApi, ts),
|
|
10839
|
+
provideService(TypeCheckerApi, typeChecker)
|
|
10840
|
+
)
|
|
10841
|
+
};
|
|
10842
|
+
})
|
|
10843
|
+
});
|
|
10844
|
+
|
|
10845
|
+
// src/refactors/asyncAwaitToFnTryPromise.ts
|
|
10846
|
+
var asyncAwaitToFnTryPromise = createRefactor({
|
|
10847
|
+
name: "asyncAwaitToFnTryPromise",
|
|
10848
|
+
description: "Convert to Effect.fn with failures",
|
|
10849
|
+
apply: fn("asyncAwaitToFnTryPromise.apply")(function* (sourceFile, textRange) {
|
|
10850
|
+
const ts = yield* service(TypeScriptApi);
|
|
10851
|
+
const tsUtils = yield* service(TypeScriptUtils);
|
|
10852
|
+
const typeChecker = yield* service(TypeCheckerApi);
|
|
10853
|
+
const maybeNode = pipe(
|
|
10854
|
+
tsUtils.getAncestorNodesInRange(sourceFile, textRange),
|
|
10855
|
+
filter(
|
|
10856
|
+
(node2) => ts.isFunctionDeclaration(node2) || ts.isArrowFunction(node2) || ts.isFunctionExpression(node2)
|
|
10857
|
+
),
|
|
10858
|
+
filter((node2) => !!node2.body),
|
|
10859
|
+
filter((node2) => !!(ts.getCombinedModifierFlags(node2) & ts.ModifierFlags.Async)),
|
|
10860
|
+
head
|
|
10861
|
+
);
|
|
10862
|
+
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
10863
|
+
const node = maybeNode.value;
|
|
10864
|
+
return {
|
|
10865
|
+
kind: "refactor.rewrite.effect.asyncAwaitToFnTryPromise",
|
|
10866
|
+
description: "Rewrite to Effect.fn with failures",
|
|
10867
|
+
apply: pipe(
|
|
10868
|
+
gen(function* () {
|
|
10869
|
+
const changeTracker = yield* service(ChangeTracker);
|
|
10870
|
+
const effectModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
10871
|
+
sourceFile,
|
|
10872
|
+
"effect",
|
|
10873
|
+
"Effect"
|
|
10874
|
+
) || "Effect";
|
|
10875
|
+
let errorCount = 0;
|
|
10876
|
+
function createErrorADT() {
|
|
10877
|
+
errorCount++;
|
|
10878
|
+
return ts.factory.createObjectLiteralExpression([
|
|
10879
|
+
ts.factory.createPropertyAssignment(
|
|
10880
|
+
"_tag",
|
|
10881
|
+
ts.factory.createAsExpression(
|
|
10882
|
+
ts.factory.createStringLiteral("Error" + errorCount),
|
|
10883
|
+
ts.factory.createTypeReferenceNode("const")
|
|
10884
|
+
)
|
|
10885
|
+
),
|
|
10886
|
+
ts.factory.createShorthandPropertyAssignment("error")
|
|
10887
|
+
]);
|
|
10888
|
+
}
|
|
10889
|
+
const newDeclaration = tsUtils.transformAsyncAwaitToEffectFn(
|
|
10890
|
+
node,
|
|
10891
|
+
effectModuleIdentifierName,
|
|
10892
|
+
(expression) => ts.factory.createCallExpression(
|
|
10893
|
+
ts.factory.createPropertyAccessExpression(
|
|
10894
|
+
ts.factory.createIdentifier(effectModuleIdentifierName),
|
|
10895
|
+
"tryPromise"
|
|
10896
|
+
),
|
|
10897
|
+
void 0,
|
|
10898
|
+
[
|
|
10899
|
+
ts.factory.createObjectLiteralExpression([
|
|
10900
|
+
ts.factory.createPropertyAssignment(
|
|
10901
|
+
ts.factory.createIdentifier("try"),
|
|
10902
|
+
ts.factory.createArrowFunction(
|
|
10903
|
+
void 0,
|
|
10904
|
+
void 0,
|
|
10905
|
+
[],
|
|
10906
|
+
void 0,
|
|
10907
|
+
void 0,
|
|
10908
|
+
expression
|
|
10909
|
+
)
|
|
10910
|
+
),
|
|
10911
|
+
ts.factory.createPropertyAssignment(
|
|
10912
|
+
ts.factory.createIdentifier("catch"),
|
|
10913
|
+
ts.factory.createArrowFunction(
|
|
10914
|
+
void 0,
|
|
10915
|
+
void 0,
|
|
10916
|
+
[ts.factory.createParameterDeclaration(void 0, void 0, "error")],
|
|
10917
|
+
void 0,
|
|
10918
|
+
void 0,
|
|
10919
|
+
createErrorADT()
|
|
10920
|
+
)
|
|
10921
|
+
)
|
|
10922
|
+
])
|
|
10923
|
+
]
|
|
10924
|
+
)
|
|
10925
|
+
);
|
|
10926
|
+
changeTracker.replaceNode(sourceFile, node, newDeclaration);
|
|
10927
|
+
}),
|
|
10928
|
+
provideService(TypeScriptApi, ts),
|
|
10929
|
+
provideService(TypeCheckerApi, typeChecker)
|
|
10930
|
+
)
|
|
10931
|
+
};
|
|
10932
|
+
})
|
|
10933
|
+
});
|
|
10934
|
+
|
|
10662
10935
|
// src/refactors/asyncAwaitToGen.ts
|
|
10663
10936
|
var asyncAwaitToGen = createRefactor({
|
|
10664
10937
|
name: "asyncAwaitToGen",
|
|
@@ -10817,61 +11090,52 @@ var effectGenToFn = createRefactor({
|
|
|
10817
11090
|
const ts = yield* service(TypeScriptApi);
|
|
10818
11091
|
const tsUtils = yield* service(TypeScriptUtils);
|
|
10819
11092
|
const typeParser = yield* service(TypeParser);
|
|
10820
|
-
const
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
return { ...effectGen, pipeArgs: pipeArgs2, nodeToReplace: parent };
|
|
10831
|
-
}
|
|
10832
|
-
if (ts.isBlock(parent) && parent.statements.length === 1 && parent.statements[0] === nodeToReplace2) {
|
|
10833
|
-
nodeToReplace2 = parent;
|
|
10834
|
-
continue;
|
|
10835
|
-
}
|
|
10836
|
-
if (ts.isReturnStatement(parent) && parent.expression === nodeToReplace2) {
|
|
10837
|
-
nodeToReplace2 = parent;
|
|
10838
|
-
continue;
|
|
10839
|
-
}
|
|
10840
|
-
const maybePipe = yield* pipe(
|
|
10841
|
-
typeParser.pipeCall(parent),
|
|
10842
|
-
orElse2((e) => parent.parent ? typeParser.pipeCall(parent.parent) : fail(e)),
|
|
10843
|
-
option
|
|
10844
|
-
);
|
|
10845
|
-
if (isSome2(maybePipe) && maybePipe.value.subject === nodeToReplace2) {
|
|
10846
|
-
pipeArgs2 = ts.factory.createNodeArray(pipeArgs2.concat(maybePipe.value.args));
|
|
10847
|
-
nodeToReplace2 = maybePipe.value.node;
|
|
10848
|
-
continue;
|
|
11093
|
+
const skipReturnBlock = (node) => ts.isBlock(node) && node.statements.length === 1 && ts.isReturnStatement(node.statements[0]) && node.statements[0].expression ? node.statements[0].expression : node;
|
|
11094
|
+
const parseFunctionLikeReturnEffectGen = fn("parseFunctionLikeReturnEffect.apply")(function* (node) {
|
|
11095
|
+
if ((ts.isArrowFunction(node) || ts.isMethodDeclaration(node) || ts.isFunctionDeclaration(node)) && node.body) {
|
|
11096
|
+
let subject = skipReturnBlock(node.body);
|
|
11097
|
+
let pipeArgs2 = [];
|
|
11098
|
+
while (true) {
|
|
11099
|
+
const maybePipe = yield* option(typeParser.pipeCall(subject));
|
|
11100
|
+
if (isNone2(maybePipe)) break;
|
|
11101
|
+
subject = maybePipe.value.subject;
|
|
11102
|
+
pipeArgs2 = maybePipe.value.args.concat(pipeArgs2);
|
|
10849
11103
|
}
|
|
10850
|
-
|
|
11104
|
+
const fnIdentifier2 = node.name && ts.isIdentifier(node.name) ? node.name : ts.isVariableDeclaration(node.parent) && node.parent.name && ts.isIdentifier(node.parent.name) ? node.parent.name : void 0;
|
|
11105
|
+
const effectGen = yield* typeParser.effectGen(subject);
|
|
11106
|
+
return { ...effectGen, nodeToReplace: node, pipeArgs: pipeArgs2, fnIdentifier: fnIdentifier2 };
|
|
10851
11107
|
}
|
|
10852
11108
|
return yield* fail(new RefactorNotApplicableError());
|
|
10853
11109
|
});
|
|
11110
|
+
const parentNodes = tsUtils.getAncestorNodesInRange(sourceFile, textRange);
|
|
11111
|
+
if (parentNodes.length === 0) return yield* fail(new RefactorNotApplicableError());
|
|
11112
|
+
const nodesFromInitializers = pipe(
|
|
11113
|
+
parentNodes,
|
|
11114
|
+
filter((_) => ts.isVariableDeclaration(_) && _.initializer ? true : false),
|
|
11115
|
+
filter((_) => tsUtils.isNodeInRange(textRange)(_.name)),
|
|
11116
|
+
map4((_) => _.initializer)
|
|
11117
|
+
);
|
|
10854
11118
|
const maybeNode = yield* pipe(
|
|
10855
|
-
|
|
10856
|
-
map4(
|
|
11119
|
+
nodesFromInitializers.concat(parentNodes),
|
|
11120
|
+
map4(parseFunctionLikeReturnEffectGen),
|
|
10857
11121
|
firstSuccessOf,
|
|
10858
11122
|
option
|
|
10859
11123
|
);
|
|
10860
11124
|
if (isNone2(maybeNode)) return yield* fail(new RefactorNotApplicableError());
|
|
10861
|
-
const { effectModule, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value;
|
|
11125
|
+
const { effectModule, fnIdentifier, generatorFunction, nodeToReplace, pipeArgs } = maybeNode.value;
|
|
10862
11126
|
return {
|
|
10863
11127
|
kind: "refactor.rewrite.effect.effectGenToFn",
|
|
10864
|
-
description: "Convert to Effect.fn",
|
|
11128
|
+
description: fnIdentifier ? `Convert to Effect.fn("${fnIdentifier.text}")` : "Convert to Effect.fn",
|
|
10865
11129
|
apply: pipe(
|
|
10866
11130
|
gen(function* () {
|
|
10867
11131
|
const changeTracker = yield* service(ChangeTracker);
|
|
10868
|
-
const effectFn =
|
|
11132
|
+
const effectFn = fnIdentifier ? ts.factory.createCallExpression(
|
|
10869
11133
|
ts.factory.createPropertyAccessExpression(
|
|
10870
11134
|
effectModule,
|
|
10871
11135
|
"fn"
|
|
10872
11136
|
),
|
|
10873
11137
|
void 0,
|
|
10874
|
-
[ts.factory.createStringLiteral(
|
|
11138
|
+
[ts.factory.createStringLiteral(fnIdentifier.text)]
|
|
10875
11139
|
) : ts.factory.createPropertyAccessExpression(
|
|
10876
11140
|
effectModule,
|
|
10877
11141
|
"fn"
|
|
@@ -10892,7 +11156,7 @@ var effectGenToFn = createRefactor({
|
|
|
10892
11156
|
changeTracker.replaceNode(
|
|
10893
11157
|
sourceFile,
|
|
10894
11158
|
nodeToReplace,
|
|
10895
|
-
tsUtils.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator)
|
|
11159
|
+
tsUtils.tryPreserveDeclarationSemantics(nodeToReplace, effectFnCallWithGenerator, false)
|
|
10896
11160
|
);
|
|
10897
11161
|
}),
|
|
10898
11162
|
provideService(TypeScriptApi, ts)
|
|
@@ -10945,7 +11209,8 @@ var functionToArrow = createRefactor({
|
|
|
10945
11209
|
);
|
|
10946
11210
|
const newDeclaration = tsUtils.tryPreserveDeclarationSemantics(
|
|
10947
11211
|
node,
|
|
10948
|
-
arrowFunction
|
|
11212
|
+
arrowFunction,
|
|
11213
|
+
false
|
|
10949
11214
|
);
|
|
10950
11215
|
changeTracker.replaceNode(sourceFile, node, newDeclaration, {
|
|
10951
11216
|
leadingTriviaOption: ts.textChanges.LeadingTriviaOption.IncludeAll,
|
|
@@ -12161,6 +12426,8 @@ var wrapWithPipe = createRefactor({
|
|
|
12161
12426
|
var refactors = [
|
|
12162
12427
|
asyncAwaitToGen,
|
|
12163
12428
|
asyncAwaitToGenTryPromise,
|
|
12429
|
+
asyncAwaitToFn,
|
|
12430
|
+
asyncAwaitToFnTryPromise,
|
|
12164
12431
|
functionToArrow,
|
|
12165
12432
|
typeToEffectSchema,
|
|
12166
12433
|
typeToEffectSchemaClass,
|