@effect/language-service 0.36.0 → 0.38.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 +4 -1
- package/cli.js +108 -25
- package/cli.js.map +1 -1
- package/effect-lsp-patch-utils.js +407 -288
- package/effect-lsp-patch-utils.js.map +1 -1
- package/index.js +831 -308
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/transform.js +377 -262
- package/transform.js.map +1 -1
package/transform.js
CHANGED
|
@@ -331,10 +331,10 @@ var string = (str) => {
|
|
|
331
331
|
}
|
|
332
332
|
return optimize(h);
|
|
333
333
|
};
|
|
334
|
-
var structureKeys = (o,
|
|
334
|
+
var structureKeys = (o, keys2) => {
|
|
335
335
|
let h = 12289;
|
|
336
|
-
for (let i = 0; i <
|
|
337
|
-
h ^= pipe(string(
|
|
336
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
337
|
+
h ^= pipe(string(keys2[i]), combine(hash(o[keys2[i]])));
|
|
338
338
|
}
|
|
339
339
|
return optimize(h);
|
|
340
340
|
};
|
|
@@ -739,6 +739,18 @@ var isSome2 = isSome;
|
|
|
739
739
|
var orElse = /* @__PURE__ */ dual(2, (self, that) => isNone2(self) ? that() : self);
|
|
740
740
|
var fromNullable = (nullableValue) => nullableValue == null ? none2() : some2(nullableValue);
|
|
741
741
|
|
|
742
|
+
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Record.js
|
|
743
|
+
var map2 = /* @__PURE__ */ dual(2, (self, f) => {
|
|
744
|
+
const out = {
|
|
745
|
+
...self
|
|
746
|
+
};
|
|
747
|
+
for (const key of keys(self)) {
|
|
748
|
+
out[key] = f(self[key], key);
|
|
749
|
+
}
|
|
750
|
+
return out;
|
|
751
|
+
});
|
|
752
|
+
var keys = (self) => Object.keys(self);
|
|
753
|
+
|
|
742
754
|
// node_modules/.pnpm/effect@3.17.8/node_modules/effect/dist/esm/Array.js
|
|
743
755
|
var fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
|
|
744
756
|
var append = /* @__PURE__ */ dual(2, (self, last) => [...self, last]);
|
|
@@ -777,7 +789,7 @@ var intersectionWith = (isEquivalent) => {
|
|
|
777
789
|
};
|
|
778
790
|
var intersection = /* @__PURE__ */ intersectionWith(_equivalence);
|
|
779
791
|
var empty = () => [];
|
|
780
|
-
var
|
|
792
|
+
var map3 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
|
|
781
793
|
var flatMap = /* @__PURE__ */ dual(2, (self, f) => {
|
|
782
794
|
if (isEmptyReadonlyArray(self)) {
|
|
783
795
|
return [];
|
|
@@ -915,6 +927,7 @@ var NanoFiber = class {
|
|
|
915
927
|
_yielded = void 0;
|
|
916
928
|
_services = {};
|
|
917
929
|
_cache = {};
|
|
930
|
+
_perf = false;
|
|
918
931
|
runLoop(nano) {
|
|
919
932
|
let current = nano;
|
|
920
933
|
while (true) {
|
|
@@ -938,6 +951,34 @@ var NanoFiber = class {
|
|
|
938
951
|
return NanoYield;
|
|
939
952
|
}
|
|
940
953
|
};
|
|
954
|
+
var timings = {};
|
|
955
|
+
var timingsCount = {};
|
|
956
|
+
var WithSpanProto = {
|
|
957
|
+
...PrimitiveProto,
|
|
958
|
+
[evaluate](fiber) {
|
|
959
|
+
const [fa, name] = this[args];
|
|
960
|
+
if (!fiber._perf) return fa;
|
|
961
|
+
const start = performance.now();
|
|
962
|
+
timingsCount[name] = (timingsCount[name] || 0) + 1;
|
|
963
|
+
return match(fa, {
|
|
964
|
+
onSuccess: (_) => {
|
|
965
|
+
const end = performance.now();
|
|
966
|
+
timings[name] = (timings[name] || 0) + (end - start);
|
|
967
|
+
return succeed(_);
|
|
968
|
+
},
|
|
969
|
+
onFailure: (_) => {
|
|
970
|
+
const end = performance.now();
|
|
971
|
+
timings[name] = (timings[name] || 0) + (end - start);
|
|
972
|
+
return fail(_);
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
var withSpan = (name) => (fa) => {
|
|
978
|
+
const nano = Object.create(WithSpanProto);
|
|
979
|
+
nano[args] = [fa, name];
|
|
980
|
+
return nano;
|
|
981
|
+
};
|
|
941
982
|
var unsafeRun = (nano) => {
|
|
942
983
|
const fiber = new NanoFiber();
|
|
943
984
|
const result = fiber.runLoop(nano);
|
|
@@ -966,7 +1007,7 @@ var flatMap2 = dual(2, (fa, f) => {
|
|
|
966
1007
|
nano[contA] = f;
|
|
967
1008
|
return nano;
|
|
968
1009
|
});
|
|
969
|
-
var
|
|
1010
|
+
var map4 = dual(2, (fa, f) => flatMap2(fa, (_) => succeed(f(_))));
|
|
970
1011
|
var SyncProto = {
|
|
971
1012
|
...PrimitiveProto,
|
|
972
1013
|
[evaluate](fiber) {
|
|
@@ -999,7 +1040,7 @@ var unsafeFromIterator = (iterator, initial) => {
|
|
|
999
1040
|
return nano;
|
|
1000
1041
|
};
|
|
1001
1042
|
var gen = (...args2) => suspend(() => unsafeFromIterator(args2[0]()));
|
|
1002
|
-
var fn = (_) => (body) => (...args2) => suspend(() => unsafeFromIterator(body(...args2)));
|
|
1043
|
+
var fn = (_) => (body) => (...args2) => withSpan(_)(suspend(() => unsafeFromIterator(body(...args2))));
|
|
1003
1044
|
var MatchProto = {
|
|
1004
1045
|
...PrimitiveProto,
|
|
1005
1046
|
[evaluate](fiber) {
|
|
@@ -1125,7 +1166,7 @@ function parseDiagnosticSeverity(config) {
|
|
|
1125
1166
|
pipe(
|
|
1126
1167
|
Object.entries(config),
|
|
1127
1168
|
filter(([key, value]) => isString(key) && isString(value)),
|
|
1128
|
-
|
|
1169
|
+
map3(([key, value]) => [String(key).toLowerCase(), String(value).toLowerCase()]),
|
|
1129
1170
|
filter(
|
|
1130
1171
|
([_, value]) => value === "off" || value === "error" || value === "warning" || value === "message" || value === "suggestion"
|
|
1131
1172
|
)
|
|
@@ -1143,8 +1184,10 @@ var defaults = {
|
|
|
1143
1184
|
inlays: true,
|
|
1144
1185
|
allowedDuplicatedPackages: [],
|
|
1145
1186
|
namespaceImportPackages: [],
|
|
1187
|
+
topLevelNamedReexports: "ignore",
|
|
1146
1188
|
barrelImportPackages: [],
|
|
1147
|
-
|
|
1189
|
+
importAliases: {},
|
|
1190
|
+
renames: true
|
|
1148
1191
|
};
|
|
1149
1192
|
function parse(config) {
|
|
1150
1193
|
return {
|
|
@@ -1159,7 +1202,9 @@ function parse(config) {
|
|
|
1159
1202
|
allowedDuplicatedPackages: isObject(config) && hasProperty(config, "allowedDuplicatedPackages") && isArray(config.allowedDuplicatedPackages) && config.allowedDuplicatedPackages.every(isString) ? config.allowedDuplicatedPackages.map((_) => _.toLowerCase()) : defaults.allowedDuplicatedPackages,
|
|
1160
1203
|
namespaceImportPackages: isObject(config) && hasProperty(config, "namespaceImportPackages") && isArray(config.namespaceImportPackages) && config.namespaceImportPackages.every(isString) ? config.namespaceImportPackages.map((_) => _.toLowerCase()) : defaults.namespaceImportPackages,
|
|
1161
1204
|
barrelImportPackages: isObject(config) && hasProperty(config, "barrelImportPackages") && isArray(config.barrelImportPackages) && config.barrelImportPackages.every(isString) ? config.barrelImportPackages.map((_) => _.toLowerCase()) : defaults.barrelImportPackages,
|
|
1162
|
-
|
|
1205
|
+
importAliases: isObject(config) && hasProperty(config, "importAliases") && isRecord(config.importAliases) ? map2(config.importAliases, (value) => String(value)) : defaults.importAliases,
|
|
1206
|
+
topLevelNamedReexports: isObject(config) && hasProperty(config, "topLevelNamedReexports") && isString(config.topLevelNamedReexports) && ["ignore", "follow"].includes(config.topLevelNamedReexports.toLowerCase()) ? config.topLevelNamedReexports.toLowerCase() : defaults.topLevelNamedReexports,
|
|
1207
|
+
renames: isObject(config) && hasProperty(config, "renames") && isBoolean(config.renames) ? config.renames : defaults.renames
|
|
1163
1208
|
};
|
|
1164
1209
|
}
|
|
1165
1210
|
|
|
@@ -1223,7 +1268,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1223
1268
|
return pipe(
|
|
1224
1269
|
referencedPackages.concat(packageJsonScope?.referencedPackages || []),
|
|
1225
1270
|
dedupe,
|
|
1226
|
-
|
|
1271
|
+
map3((packageName) => packageName.toLowerCase()),
|
|
1227
1272
|
filter(
|
|
1228
1273
|
(packageName) => pattern.endsWith("*") && packageName.startsWith(pattern.toLowerCase().substring(0, pattern.length - 1))
|
|
1229
1274
|
)
|
|
@@ -1339,7 +1384,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1339
1384
|
fnCall = ts.factory.createCallExpression(
|
|
1340
1385
|
fnCall,
|
|
1341
1386
|
void 0,
|
|
1342
|
-
[ts.factory.createStringLiteral(fnName
|
|
1387
|
+
[ts.factory.createStringLiteral(ts.idText(fnName))]
|
|
1343
1388
|
);
|
|
1344
1389
|
}
|
|
1345
1390
|
return tryPreserveDeclarationSemantics(
|
|
@@ -1411,7 +1456,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1411
1456
|
if (!namedBindings) continue;
|
|
1412
1457
|
if (ts.isNamespaceImport(namedBindings)) {
|
|
1413
1458
|
if (test(namedBindings.name, statement.moduleSpecifier, none2())) {
|
|
1414
|
-
return namedBindings.name
|
|
1459
|
+
return ts.idText(namedBindings.name);
|
|
1415
1460
|
}
|
|
1416
1461
|
} else if (ts.isNamedImports(namedBindings)) {
|
|
1417
1462
|
for (const importSpecifier of namedBindings.elements) {
|
|
@@ -1419,7 +1464,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1419
1464
|
orElse(() => some2(importSpecifier.name))
|
|
1420
1465
|
);
|
|
1421
1466
|
if (test(importSpecifier.name, statement.moduleSpecifier, importProperty)) {
|
|
1422
|
-
return importSpecifier.name
|
|
1467
|
+
return ts.idText(importSpecifier.name);
|
|
1423
1468
|
}
|
|
1424
1469
|
}
|
|
1425
1470
|
}
|
|
@@ -1432,7 +1477,7 @@ function makeTypeScriptUtils(ts) {
|
|
|
1432
1477
|
if (isNone2(importProperty) && ts.isStringLiteral(fromModule) && fromModule.text === packageName + "/" + moduleName) {
|
|
1433
1478
|
return true;
|
|
1434
1479
|
}
|
|
1435
|
-
if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && importProperty.value
|
|
1480
|
+
if (isSome2(importProperty) && ts.isIdentifier(importProperty.value) && ts.idText(importProperty.value) === moduleName && ts.isStringLiteral(fromModule) && fromModule.text === packageName) {
|
|
1436
1481
|
return true;
|
|
1437
1482
|
}
|
|
1438
1483
|
return false;
|
|
@@ -1930,7 +1975,7 @@ var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sour
|
|
|
1930
1975
|
const edit = yield* codegen.apply(sourceFile, range);
|
|
1931
1976
|
const updateHashComment = pipe(
|
|
1932
1977
|
service(ChangeTracker),
|
|
1933
|
-
|
|
1978
|
+
map4((changeTracker) => {
|
|
1934
1979
|
changeTracker.deleteRange(sourceFile, range);
|
|
1935
1980
|
changeTracker.insertText(sourceFile, range.pos, `${codegen.name}:${edit.hash}`);
|
|
1936
1981
|
})
|
|
@@ -1944,191 +1989,12 @@ var getEditsForCodegen = fn("LSP.getEditsForCodegen")(function* (codegens2, sour
|
|
|
1944
1989
|
ignore: updateHashComment
|
|
1945
1990
|
};
|
|
1946
1991
|
});
|
|
1992
|
+
var getEffectLspPatchSourceFileMetadata = (sourceFile) => {
|
|
1993
|
+
return sourceFile["@effect-lsp-patch/metadata"];
|
|
1994
|
+
};
|
|
1947
1995
|
|
|
1948
1996
|
// src/core/TypeCheckerApi.ts
|
|
1949
1997
|
var TypeCheckerApi = Tag("TypeChecker");
|
|
1950
|
-
var deterministicTypeOrder = gen(function* () {
|
|
1951
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
1952
|
-
return make((a, b) => {
|
|
1953
|
-
const aName = typeChecker.typeToString(a);
|
|
1954
|
-
const bName = typeChecker.typeToString(b);
|
|
1955
|
-
if (aName < bName) return -1;
|
|
1956
|
-
if (aName > bName) return 1;
|
|
1957
|
-
return 0;
|
|
1958
|
-
});
|
|
1959
|
-
});
|
|
1960
|
-
var CannotFindAncestorConvertibleDeclarationError = class {
|
|
1961
|
-
constructor(node) {
|
|
1962
|
-
this.node = node;
|
|
1963
|
-
}
|
|
1964
|
-
_tag = "@effect/language-service/CannotFindAncestorConvertibleDeclarationError";
|
|
1965
|
-
};
|
|
1966
|
-
var getAncestorConvertibleDeclaration = fn(
|
|
1967
|
-
"TypeCheckerApi.getAncestorConvertibleDeclaration"
|
|
1968
|
-
)(function* (node) {
|
|
1969
|
-
const ts = yield* service(TypeScriptApi);
|
|
1970
|
-
let current = node;
|
|
1971
|
-
while (current) {
|
|
1972
|
-
if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
|
|
1973
|
-
return current;
|
|
1974
|
-
}
|
|
1975
|
-
current = current.parent;
|
|
1976
|
-
}
|
|
1977
|
-
return yield* fail(new CannotFindAncestorConvertibleDeclarationError(node));
|
|
1978
|
-
});
|
|
1979
|
-
var CannotInferReturnTypeFromEmptyBody = class {
|
|
1980
|
-
constructor(declaration) {
|
|
1981
|
-
this.declaration = declaration;
|
|
1982
|
-
}
|
|
1983
|
-
_tag = "@effect/language-service/CannotInferReturnTypeFromEmptyBody";
|
|
1984
|
-
};
|
|
1985
|
-
var CannotInferReturnType = class {
|
|
1986
|
-
constructor(declaration) {
|
|
1987
|
-
this.declaration = declaration;
|
|
1988
|
-
}
|
|
1989
|
-
_tag = "@effect/language-service/CannotInferReturnType";
|
|
1990
|
-
};
|
|
1991
|
-
var getInferredReturnType = fn("TypeCheckerApi.getInferredReturnType")(function* (declaration) {
|
|
1992
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
1993
|
-
const ts = yield* service(TypeScriptApi);
|
|
1994
|
-
if (!declaration.body) {
|
|
1995
|
-
return yield* fail(
|
|
1996
|
-
new CannotInferReturnTypeFromEmptyBody(declaration)
|
|
1997
|
-
);
|
|
1998
|
-
}
|
|
1999
|
-
let returnType;
|
|
2000
|
-
if (typeChecker.isImplementationOfOverload(declaration)) {
|
|
2001
|
-
const signatures = typeChecker.getSignaturesOfType(
|
|
2002
|
-
typeChecker.getTypeAtLocation(declaration),
|
|
2003
|
-
ts.SignatureKind.Call
|
|
2004
|
-
);
|
|
2005
|
-
if (signatures.length > 1) {
|
|
2006
|
-
returnType = typeChecker.getUnionType(
|
|
2007
|
-
signatures.map((s) => typeChecker.getReturnTypeOfSignature(s)).filter((_) => !!_)
|
|
2008
|
-
);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
if (!returnType) {
|
|
2012
|
-
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
2013
|
-
if (signature) {
|
|
2014
|
-
const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
|
|
2015
|
-
if (typePredicate && typePredicate.type) {
|
|
2016
|
-
return typePredicate.type;
|
|
2017
|
-
} else {
|
|
2018
|
-
returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
if (!returnType) {
|
|
2023
|
-
return yield* fail(
|
|
2024
|
-
new CannotInferReturnType(declaration)
|
|
2025
|
-
);
|
|
2026
|
-
}
|
|
2027
|
-
return returnType;
|
|
2028
|
-
});
|
|
2029
|
-
var expectedAndRealType = cachedBy(
|
|
2030
|
-
fn("TypeCheckerApi.expectedAndRealType")(function* (sourceFile) {
|
|
2031
|
-
const typeChecker = yield* service(TypeCheckerApi);
|
|
2032
|
-
const ts = yield* service(TypeScriptApi);
|
|
2033
|
-
const result = [];
|
|
2034
|
-
const nodeToVisit = [sourceFile];
|
|
2035
|
-
const appendNodeToVisit = (node) => {
|
|
2036
|
-
nodeToVisit.push(node);
|
|
2037
|
-
return void 0;
|
|
2038
|
-
};
|
|
2039
|
-
while (nodeToVisit.length > 0) {
|
|
2040
|
-
const node = nodeToVisit.shift();
|
|
2041
|
-
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
2042
|
-
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
2043
|
-
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
2044
|
-
result.push([node.name, expectedType, node.initializer, realType]);
|
|
2045
|
-
appendNodeToVisit(node.initializer);
|
|
2046
|
-
continue;
|
|
2047
|
-
} else if (ts.isCallExpression(node)) {
|
|
2048
|
-
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
2049
|
-
if (resolvedSignature) {
|
|
2050
|
-
resolvedSignature.parameters.map((parameter, index) => {
|
|
2051
|
-
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
2052
|
-
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
2053
|
-
result.push([
|
|
2054
|
-
node.arguments[index],
|
|
2055
|
-
expectedType,
|
|
2056
|
-
node.arguments[index],
|
|
2057
|
-
realType
|
|
2058
|
-
]);
|
|
2059
|
-
});
|
|
2060
|
-
}
|
|
2061
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2062
|
-
continue;
|
|
2063
|
-
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
2064
|
-
const parent = node.parent;
|
|
2065
|
-
if (ts.isObjectLiteralElement(parent)) {
|
|
2066
|
-
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
2067
|
-
const type = typeChecker.getContextualType(parent.parent);
|
|
2068
|
-
if (type) {
|
|
2069
|
-
const name = ts.isIdentifier(node) ? ts.idText(node) : ts.isStringLiteral(node) ? node.text : void 0;
|
|
2070
|
-
if (name) {
|
|
2071
|
-
const symbol3 = typeChecker.getPropertyOfType(type, name);
|
|
2072
|
-
if (symbol3) {
|
|
2073
|
-
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
2074
|
-
const realType = typeChecker.getTypeAtLocation(node);
|
|
2075
|
-
result.push([node, expectedType, node, realType]);
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2082
|
-
continue;
|
|
2083
|
-
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2084
|
-
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
2085
|
-
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
2086
|
-
result.push([node.left, expectedType, node.right, realType]);
|
|
2087
|
-
appendNodeToVisit(node.right);
|
|
2088
|
-
continue;
|
|
2089
|
-
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2090
|
-
const parentDeclaration = yield* option(getAncestorConvertibleDeclaration(node));
|
|
2091
|
-
if (isSome2(parentDeclaration)) {
|
|
2092
|
-
const expectedType = yield* option(getInferredReturnType(parentDeclaration.value));
|
|
2093
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2094
|
-
if (isSome2(expectedType)) {
|
|
2095
|
-
result.push([node, expectedType.value, node, realType]);
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2099
|
-
continue;
|
|
2100
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2101
|
-
const body = node.body;
|
|
2102
|
-
const expectedType = typeChecker.getContextualType(body);
|
|
2103
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2104
|
-
if (expectedType) {
|
|
2105
|
-
result.push([body, expectedType, body, realType]);
|
|
2106
|
-
}
|
|
2107
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2108
|
-
continue;
|
|
2109
|
-
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2110
|
-
const body = node.body;
|
|
2111
|
-
const expectedType = yield* option(getInferredReturnType(node));
|
|
2112
|
-
const realType = typeChecker.getTypeAtLocation(body);
|
|
2113
|
-
if (isSome2(expectedType)) {
|
|
2114
|
-
result.push([body, expectedType.value, body, realType]);
|
|
2115
|
-
}
|
|
2116
|
-
ts.forEachChild(body, appendNodeToVisit);
|
|
2117
|
-
continue;
|
|
2118
|
-
} else if (ts.isSatisfiesExpression(node)) {
|
|
2119
|
-
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2120
|
-
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2121
|
-
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2122
|
-
appendNodeToVisit(node.expression);
|
|
2123
|
-
continue;
|
|
2124
|
-
}
|
|
2125
|
-
ts.forEachChild(node, appendNodeToVisit);
|
|
2126
|
-
}
|
|
2127
|
-
return result;
|
|
2128
|
-
}),
|
|
2129
|
-
"TypeCheckerApi.expectedAndRealType",
|
|
2130
|
-
(sourceFile) => sourceFile
|
|
2131
|
-
);
|
|
2132
1998
|
function makeResolveExternalModuleName(typeChecker) {
|
|
2133
1999
|
if (!(hasProperty(typeChecker, "resolveExternalModuleName") && isFunction(typeChecker.resolveExternalModuleName))) {
|
|
2134
2000
|
return;
|
|
@@ -2241,12 +2107,161 @@ function makeTypeCheckerUtils(ts, typeChecker) {
|
|
|
2241
2107
|
};
|
|
2242
2108
|
}
|
|
2243
2109
|
);
|
|
2110
|
+
const deterministicTypeOrder = make((a, b) => {
|
|
2111
|
+
const aName = typeChecker.typeToString(a);
|
|
2112
|
+
const bName = typeChecker.typeToString(b);
|
|
2113
|
+
if (aName < bName) return -1;
|
|
2114
|
+
if (aName > bName) return 1;
|
|
2115
|
+
return 0;
|
|
2116
|
+
});
|
|
2117
|
+
const getAncestorConvertibleDeclaration = (node) => {
|
|
2118
|
+
let current = node;
|
|
2119
|
+
while (current) {
|
|
2120
|
+
if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current)) {
|
|
2121
|
+
return current;
|
|
2122
|
+
}
|
|
2123
|
+
current = current.parent;
|
|
2124
|
+
}
|
|
2125
|
+
};
|
|
2126
|
+
const getInferredReturnType = (declaration) => {
|
|
2127
|
+
if (!declaration.body) {
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2130
|
+
let returnType;
|
|
2131
|
+
if (typeChecker.isImplementationOfOverload(declaration)) {
|
|
2132
|
+
const signatures = typeChecker.getSignaturesOfType(
|
|
2133
|
+
typeChecker.getTypeAtLocation(declaration),
|
|
2134
|
+
ts.SignatureKind.Call
|
|
2135
|
+
);
|
|
2136
|
+
if (signatures.length > 1) {
|
|
2137
|
+
returnType = typeChecker.getUnionType(
|
|
2138
|
+
signatures.map((s) => typeChecker.getReturnTypeOfSignature(s)).filter((_) => !!_)
|
|
2139
|
+
);
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
if (!returnType) {
|
|
2143
|
+
const signature = typeChecker.getSignatureFromDeclaration(declaration);
|
|
2144
|
+
if (signature) {
|
|
2145
|
+
const typePredicate = typeChecker.getTypePredicateOfSignature(signature);
|
|
2146
|
+
if (typePredicate && typePredicate.type) {
|
|
2147
|
+
return typePredicate.type;
|
|
2148
|
+
} else {
|
|
2149
|
+
returnType = typeChecker.getReturnTypeOfSignature(signature);
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
return returnType;
|
|
2154
|
+
};
|
|
2155
|
+
const expectedAndRealTypeCache = /* @__PURE__ */ new WeakMap();
|
|
2156
|
+
const expectedAndRealType = (sourceFile) => {
|
|
2157
|
+
const cached2 = expectedAndRealTypeCache.get(sourceFile);
|
|
2158
|
+
if (cached2) return cached2;
|
|
2159
|
+
const result = [];
|
|
2160
|
+
const nodeToVisit = [sourceFile];
|
|
2161
|
+
const appendNodeToVisit = (node) => {
|
|
2162
|
+
nodeToVisit.push(node);
|
|
2163
|
+
return void 0;
|
|
2164
|
+
};
|
|
2165
|
+
while (nodeToVisit.length > 0) {
|
|
2166
|
+
const node = nodeToVisit.shift();
|
|
2167
|
+
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
2168
|
+
const expectedType = typeChecker.getTypeAtLocation(node.name);
|
|
2169
|
+
const realType = typeChecker.getTypeAtLocation(node.initializer);
|
|
2170
|
+
result.push([node.name, expectedType, node.initializer, realType]);
|
|
2171
|
+
appendNodeToVisit(node.initializer);
|
|
2172
|
+
continue;
|
|
2173
|
+
} else if (ts.isCallExpression(node)) {
|
|
2174
|
+
const resolvedSignature = typeChecker.getResolvedSignature(node);
|
|
2175
|
+
if (resolvedSignature) {
|
|
2176
|
+
resolvedSignature.parameters.map((parameter, index) => {
|
|
2177
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(parameter, node);
|
|
2178
|
+
const realType = typeChecker.getTypeAtLocation(node.arguments[index]);
|
|
2179
|
+
result.push([
|
|
2180
|
+
node.arguments[index],
|
|
2181
|
+
expectedType,
|
|
2182
|
+
node.arguments[index],
|
|
2183
|
+
realType
|
|
2184
|
+
]);
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2188
|
+
continue;
|
|
2189
|
+
} else if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
2190
|
+
const parent = node.parent;
|
|
2191
|
+
if (ts.isObjectLiteralElement(parent)) {
|
|
2192
|
+
if (ts.isObjectLiteralExpression(parent.parent) && parent.name === node) {
|
|
2193
|
+
const type = typeChecker.getContextualType(parent.parent);
|
|
2194
|
+
if (type) {
|
|
2195
|
+
const name = ts.isIdentifier(node) ? ts.idText(node) : ts.isStringLiteral(node) ? node.text : void 0;
|
|
2196
|
+
if (name) {
|
|
2197
|
+
const symbol3 = typeChecker.getPropertyOfType(type, name);
|
|
2198
|
+
if (symbol3) {
|
|
2199
|
+
const expectedType = typeChecker.getTypeOfSymbolAtLocation(symbol3, node);
|
|
2200
|
+
const realType = typeChecker.getTypeAtLocation(node);
|
|
2201
|
+
result.push([node, expectedType, node, realType]);
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2208
|
+
continue;
|
|
2209
|
+
} else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2210
|
+
const expectedType = typeChecker.getTypeAtLocation(node.left);
|
|
2211
|
+
const realType = typeChecker.getTypeAtLocation(node.right);
|
|
2212
|
+
result.push([node.left, expectedType, node.right, realType]);
|
|
2213
|
+
appendNodeToVisit(node.right);
|
|
2214
|
+
continue;
|
|
2215
|
+
} else if (ts.isReturnStatement(node) && node.expression) {
|
|
2216
|
+
const parentDeclaration = getAncestorConvertibleDeclaration(node);
|
|
2217
|
+
if (parentDeclaration) {
|
|
2218
|
+
const expectedType = getInferredReturnType(parentDeclaration);
|
|
2219
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2220
|
+
if (expectedType) {
|
|
2221
|
+
result.push([node, expectedType, node, realType]);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2225
|
+
continue;
|
|
2226
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length === 0 && ts.isExpression(node.body)) {
|
|
2227
|
+
const body = node.body;
|
|
2228
|
+
const expectedType = typeChecker.getContextualType(body);
|
|
2229
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2230
|
+
if (expectedType) {
|
|
2231
|
+
result.push([body, expectedType, body, realType]);
|
|
2232
|
+
}
|
|
2233
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2234
|
+
continue;
|
|
2235
|
+
} else if (ts.isArrowFunction(node) && (node.typeParameters || []).length > 0 && ts.isExpression(node.body)) {
|
|
2236
|
+
const body = node.body;
|
|
2237
|
+
const expectedType = getInferredReturnType(node);
|
|
2238
|
+
const realType = typeChecker.getTypeAtLocation(body);
|
|
2239
|
+
if (expectedType) {
|
|
2240
|
+
result.push([body, expectedType, body, realType]);
|
|
2241
|
+
}
|
|
2242
|
+
ts.forEachChild(body, appendNodeToVisit);
|
|
2243
|
+
continue;
|
|
2244
|
+
} else if (ts.isSatisfiesExpression(node)) {
|
|
2245
|
+
const expectedType = typeChecker.getTypeAtLocation(node.type);
|
|
2246
|
+
const realType = typeChecker.getTypeAtLocation(node.expression);
|
|
2247
|
+
result.push([node.expression, expectedType, node.expression, realType]);
|
|
2248
|
+
appendNodeToVisit(node.expression);
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
ts.forEachChild(node, appendNodeToVisit);
|
|
2252
|
+
}
|
|
2253
|
+
expectedAndRealTypeCache.set(sourceFile, result);
|
|
2254
|
+
return result;
|
|
2255
|
+
};
|
|
2244
2256
|
return {
|
|
2245
2257
|
isUnion,
|
|
2246
2258
|
getTypeParameterAtPosition,
|
|
2247
2259
|
getMissingTypeEntriesInTargetType,
|
|
2248
2260
|
unrollUnionMembers,
|
|
2249
|
-
appendToUniqueTypesMap
|
|
2261
|
+
appendToUniqueTypesMap,
|
|
2262
|
+
deterministicTypeOrder,
|
|
2263
|
+
getInferredReturnType,
|
|
2264
|
+
expectedAndRealType
|
|
2250
2265
|
};
|
|
2251
2266
|
}
|
|
2252
2267
|
|
|
@@ -2331,7 +2346,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2331
2346
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(propertySymbol, atLocation);
|
|
2332
2347
|
return invariantTypeArgument(propertyType);
|
|
2333
2348
|
};
|
|
2334
|
-
const effectVarianceStruct = (type, atLocation) =>
|
|
2349
|
+
const effectVarianceStruct = (type, atLocation) => map4(
|
|
2335
2350
|
all(
|
|
2336
2351
|
varianceStructCovariantType(type, atLocation, "_A"),
|
|
2337
2352
|
varianceStructCovariantType(type, atLocation, "_E"),
|
|
@@ -2339,7 +2354,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2339
2354
|
),
|
|
2340
2355
|
([A, E, R]) => ({ A, E, R })
|
|
2341
2356
|
);
|
|
2342
|
-
const layerVarianceStruct = (type, atLocation) =>
|
|
2357
|
+
const layerVarianceStruct = (type, atLocation) => map4(
|
|
2343
2358
|
all(
|
|
2344
2359
|
varianceStructContravariantType(type, atLocation, "_ROut"),
|
|
2345
2360
|
varianceStructCovariantType(type, atLocation, "_E"),
|
|
@@ -2478,6 +2493,21 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2478
2493
|
"TypeParser.importedEffectModule",
|
|
2479
2494
|
(node) => node
|
|
2480
2495
|
);
|
|
2496
|
+
const importedDataModule = cachedBy(
|
|
2497
|
+
fn("TypeParser.importedDataModule")(function* (node) {
|
|
2498
|
+
const type = typeChecker.getTypeAtLocation(node);
|
|
2499
|
+
const propertySymbol = typeChecker.getPropertyOfType(type, "TaggedError");
|
|
2500
|
+
if (!propertySymbol) {
|
|
2501
|
+
return yield* typeParserIssue("Type has no 'TaggedError' property", type, node);
|
|
2502
|
+
}
|
|
2503
|
+
if (!ts.isExpression(node)) {
|
|
2504
|
+
return yield* typeParserIssue("Node is not an expression", type, node);
|
|
2505
|
+
}
|
|
2506
|
+
return node;
|
|
2507
|
+
}),
|
|
2508
|
+
"TypeParser.importedDataModule",
|
|
2509
|
+
(node) => node
|
|
2510
|
+
);
|
|
2481
2511
|
const effectGen = cachedBy(
|
|
2482
2512
|
function(node) {
|
|
2483
2513
|
if (!ts.isCallExpression(node)) {
|
|
@@ -2497,12 +2527,12 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2497
2527
|
return typeParserIssue("Node is not a property access expression", void 0, node);
|
|
2498
2528
|
}
|
|
2499
2529
|
const propertyAccess = node.expression;
|
|
2500
|
-
if (propertyAccess.name.
|
|
2530
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "gen")) {
|
|
2501
2531
|
return typeParserIssue("Call expression name is not 'gen'", void 0, node);
|
|
2502
2532
|
}
|
|
2503
2533
|
return pipe(
|
|
2504
2534
|
importedEffectModule(propertyAccess.expression),
|
|
2505
|
-
|
|
2535
|
+
map4((effectModule) => ({
|
|
2506
2536
|
node,
|
|
2507
2537
|
effectModule,
|
|
2508
2538
|
generatorFunction,
|
|
@@ -2541,7 +2571,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2541
2571
|
);
|
|
2542
2572
|
}
|
|
2543
2573
|
const propertyAccess = node.expression;
|
|
2544
|
-
if (propertyAccess.name.
|
|
2574
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fnUntraced")) {
|
|
2545
2575
|
return typeParserIssue(
|
|
2546
2576
|
"Call expression name is not 'fnUntraced'",
|
|
2547
2577
|
void 0,
|
|
@@ -2550,7 +2580,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2550
2580
|
}
|
|
2551
2581
|
return pipe(
|
|
2552
2582
|
importedEffectModule(propertyAccess.expression),
|
|
2553
|
-
|
|
2583
|
+
map4((effectModule) => ({
|
|
2554
2584
|
node,
|
|
2555
2585
|
effectModule,
|
|
2556
2586
|
generatorFunction,
|
|
@@ -2594,7 +2624,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2594
2624
|
);
|
|
2595
2625
|
}
|
|
2596
2626
|
const propertyAccess = expressionToTest;
|
|
2597
|
-
if (propertyAccess.name.
|
|
2627
|
+
if (!(ts.isIdentifier(propertyAccess.name) && ts.idText(propertyAccess.name) === "fn")) {
|
|
2598
2628
|
return typeParserIssue(
|
|
2599
2629
|
"Call expression name is not 'fn'",
|
|
2600
2630
|
void 0,
|
|
@@ -2603,7 +2633,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2603
2633
|
}
|
|
2604
2634
|
return pipe(
|
|
2605
2635
|
importedEffectModule(propertyAccess.expression),
|
|
2606
|
-
|
|
2636
|
+
map4((effectModule) => ({
|
|
2607
2637
|
node,
|
|
2608
2638
|
generatorFunction,
|
|
2609
2639
|
effectModule,
|
|
@@ -2677,7 +2707,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2677
2707
|
"TypeParser.unnecessaryEffectGen",
|
|
2678
2708
|
(node) => node
|
|
2679
2709
|
);
|
|
2680
|
-
const effectSchemaVarianceStruct = (type, atLocation) =>
|
|
2710
|
+
const effectSchemaVarianceStruct = (type, atLocation) => map4(
|
|
2681
2711
|
all(
|
|
2682
2712
|
varianceStructInvariantType(type, atLocation, "_A"),
|
|
2683
2713
|
varianceStructInvariantType(type, atLocation, "_I"),
|
|
@@ -2709,7 +2739,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2709
2739
|
"TypeParser.effectSchemaType",
|
|
2710
2740
|
(type) => type
|
|
2711
2741
|
);
|
|
2712
|
-
const contextTagVarianceStruct = (type, atLocation) =>
|
|
2742
|
+
const contextTagVarianceStruct = (type, atLocation) => map4(
|
|
2713
2743
|
all(
|
|
2714
2744
|
varianceStructInvariantType(type, atLocation, "_Identifier"),
|
|
2715
2745
|
varianceStructInvariantType(type, atLocation, "_Service")
|
|
@@ -2748,7 +2778,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2748
2778
|
kind: "pipeable"
|
|
2749
2779
|
});
|
|
2750
2780
|
}
|
|
2751
|
-
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression
|
|
2781
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && ts.idText(node.expression) === "pipe" && node.arguments.length > 0) {
|
|
2752
2782
|
const [subject, ...args2] = node.arguments;
|
|
2753
2783
|
return succeed({ node, subject, args: args2, kind: "pipe" });
|
|
2754
2784
|
}
|
|
@@ -2873,7 +2903,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2873
2903
|
for (const typeX of heritageClause.types) {
|
|
2874
2904
|
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2875
2905
|
const expression = typeX.expression;
|
|
2876
|
-
if (ts.isCallExpression(expression)) {
|
|
2906
|
+
if (ts.isCallExpression(expression) && expression.arguments.length > 0) {
|
|
2877
2907
|
const schemaTaggedClassTCall = expression.expression;
|
|
2878
2908
|
if (ts.isCallExpression(schemaTaggedClassTCall) && schemaTaggedClassTCall.typeArguments && schemaTaggedClassTCall.typeArguments.length > 0) {
|
|
2879
2909
|
const selfTypeNode = schemaTaggedClassTCall.typeArguments[0];
|
|
@@ -2887,6 +2917,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2887
2917
|
return {
|
|
2888
2918
|
className: atLocation.name,
|
|
2889
2919
|
selfTypeNode,
|
|
2920
|
+
keyStringLiteral: schemaTaggedClassTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedClassTCall.arguments[0]) ? schemaTaggedClassTCall.arguments[0] : void 0,
|
|
2921
|
+
tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
|
|
2890
2922
|
Schema: parsedSchemaModule.value
|
|
2891
2923
|
};
|
|
2892
2924
|
}
|
|
@@ -2928,6 +2960,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2928
2960
|
return {
|
|
2929
2961
|
className: atLocation.name,
|
|
2930
2962
|
selfTypeNode,
|
|
2963
|
+
keyStringLiteral: schemaTaggedErrorTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedErrorTCall.arguments[0]) ? schemaTaggedErrorTCall.arguments[0] : void 0,
|
|
2964
|
+
tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
|
|
2931
2965
|
Schema: parsedSchemaModule.value
|
|
2932
2966
|
};
|
|
2933
2967
|
}
|
|
@@ -2942,6 +2976,82 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2942
2976
|
"TypeParser.extendsSchemaTaggedError",
|
|
2943
2977
|
(atLocation) => atLocation
|
|
2944
2978
|
);
|
|
2979
|
+
const extendsDataTaggedError = cachedBy(
|
|
2980
|
+
fn("TypeParser.extendsDataTaggedError")(function* (atLocation) {
|
|
2981
|
+
if (!atLocation.name) {
|
|
2982
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2983
|
+
}
|
|
2984
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
2985
|
+
if (!heritageClauses) {
|
|
2986
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
2987
|
+
}
|
|
2988
|
+
for (const heritageClause of heritageClauses) {
|
|
2989
|
+
for (const typeX of heritageClause.types) {
|
|
2990
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
2991
|
+
const expression = typeX.expression;
|
|
2992
|
+
if (ts.isCallExpression(expression)) {
|
|
2993
|
+
const dataTaggedErrorCall = expression;
|
|
2994
|
+
const dataIdentifier = dataTaggedErrorCall.expression;
|
|
2995
|
+
if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedError") {
|
|
2996
|
+
const parsedDataModule = yield* pipe(
|
|
2997
|
+
importedDataModule(dataIdentifier.expression),
|
|
2998
|
+
option
|
|
2999
|
+
);
|
|
3000
|
+
if (isSome2(parsedDataModule)) {
|
|
3001
|
+
return {
|
|
3002
|
+
className: atLocation.name,
|
|
3003
|
+
keyStringLiteral: dataTaggedErrorCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedErrorCall.arguments[0]) ? dataTaggedErrorCall.arguments[0] : void 0,
|
|
3004
|
+
Data: parsedDataModule.value
|
|
3005
|
+
};
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
return yield* typeParserIssue("Class does not extend Data.TaggedError", void 0, atLocation);
|
|
3013
|
+
}),
|
|
3014
|
+
"TypeParser.extendsDataTaggedError",
|
|
3015
|
+
(atLocation) => atLocation
|
|
3016
|
+
);
|
|
3017
|
+
const extendsDataTaggedClass = cachedBy(
|
|
3018
|
+
fn("TypeParser.extendsDataTaggedClass")(function* (atLocation) {
|
|
3019
|
+
if (!atLocation.name) {
|
|
3020
|
+
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3021
|
+
}
|
|
3022
|
+
const heritageClauses = atLocation.heritageClauses;
|
|
3023
|
+
if (!heritageClauses) {
|
|
3024
|
+
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
3025
|
+
}
|
|
3026
|
+
for (const heritageClause of heritageClauses) {
|
|
3027
|
+
for (const typeX of heritageClause.types) {
|
|
3028
|
+
if (ts.isExpressionWithTypeArguments(typeX)) {
|
|
3029
|
+
const expression = typeX.expression;
|
|
3030
|
+
if (ts.isCallExpression(expression)) {
|
|
3031
|
+
const dataTaggedClassCall = expression;
|
|
3032
|
+
const dataIdentifier = dataTaggedClassCall.expression;
|
|
3033
|
+
if (ts.isPropertyAccessExpression(dataIdentifier) && ts.isIdentifier(dataIdentifier.name) && ts.idText(dataIdentifier.name) === "TaggedClass") {
|
|
3034
|
+
const parsedDataModule = yield* pipe(
|
|
3035
|
+
importedDataModule(dataIdentifier.expression),
|
|
3036
|
+
option
|
|
3037
|
+
);
|
|
3038
|
+
if (isSome2(parsedDataModule)) {
|
|
3039
|
+
return {
|
|
3040
|
+
className: atLocation.name,
|
|
3041
|
+
keyStringLiteral: dataTaggedClassCall.arguments.length > 0 && ts.isStringLiteral(dataTaggedClassCall.arguments[0]) ? dataTaggedClassCall.arguments[0] : void 0,
|
|
3042
|
+
Data: parsedDataModule.value
|
|
3043
|
+
};
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
return yield* typeParserIssue("Class does not extend Data.TaggedClass", void 0, atLocation);
|
|
3051
|
+
}),
|
|
3052
|
+
"TypeParser.extendsDataTaggedClass",
|
|
3053
|
+
(atLocation) => atLocation
|
|
3054
|
+
);
|
|
2945
3055
|
const extendsSchemaTaggedRequest = cachedBy(
|
|
2946
3056
|
fn("TypeParser.extendsSchemaTaggedRequest")(function* (atLocation) {
|
|
2947
3057
|
if (!atLocation.name) {
|
|
@@ -2969,6 +3079,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2969
3079
|
return {
|
|
2970
3080
|
className: atLocation.name,
|
|
2971
3081
|
selfTypeNode,
|
|
3082
|
+
tagStringLiteral: expression.arguments.length > 0 && ts.isStringLiteral(expression.arguments[0]) ? expression.arguments[0] : void 0,
|
|
3083
|
+
keyStringLiteral: schemaTaggedRequestTCall.arguments.length > 0 && ts.isStringLiteral(schemaTaggedRequestTCall.arguments[0]) ? schemaTaggedRequestTCall.arguments[0] : void 0,
|
|
2972
3084
|
Schema: parsedSchemaModule.value
|
|
2973
3085
|
};
|
|
2974
3086
|
}
|
|
@@ -2988,9 +3100,6 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
2988
3100
|
if (!atLocation.name) {
|
|
2989
3101
|
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
2990
3102
|
}
|
|
2991
|
-
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
2992
|
-
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
2993
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
2994
3103
|
const heritageClauses = atLocation.heritageClauses;
|
|
2995
3104
|
if (!heritageClauses) {
|
|
2996
3105
|
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
@@ -3010,10 +3119,14 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3010
3119
|
option
|
|
3011
3120
|
);
|
|
3012
3121
|
if (isSome2(parsedContextModule)) {
|
|
3122
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3123
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3124
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3013
3125
|
const tagType = yield* contextTag(type, atLocation);
|
|
3014
3126
|
return {
|
|
3015
3127
|
className: atLocation.name,
|
|
3016
3128
|
selfTypeNode,
|
|
3129
|
+
keyStringLiteral: ts.isStringLiteral(contextTagCall.arguments[0]) ? contextTagCall.arguments[0] : void 0,
|
|
3017
3130
|
args: contextTagCall.arguments,
|
|
3018
3131
|
Identifier: tagType.Identifier,
|
|
3019
3132
|
Tag: parsedContextModule.value
|
|
@@ -3035,9 +3148,6 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3035
3148
|
if (!atLocation.name) {
|
|
3036
3149
|
return yield* typeParserIssue("Class has no name", void 0, atLocation);
|
|
3037
3150
|
}
|
|
3038
|
-
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3039
|
-
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3040
|
-
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3041
3151
|
const heritageClauses = atLocation.heritageClauses;
|
|
3042
3152
|
if (!heritageClauses) {
|
|
3043
3153
|
return yield* typeParserIssue("Class has no heritage clauses", void 0, atLocation);
|
|
@@ -3052,6 +3162,9 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3052
3162
|
const effectServiceIdentifier = effectServiceCall.expression;
|
|
3053
3163
|
const selfTypeNode = effectServiceCall.typeArguments[0];
|
|
3054
3164
|
if (ts.isPropertyAccessExpression(effectServiceIdentifier) && ts.isIdentifier(effectServiceIdentifier.name) && ts.idText(effectServiceIdentifier.name) === "Service") {
|
|
3165
|
+
const classSym = typeChecker.getSymbolAtLocation(atLocation.name);
|
|
3166
|
+
if (!classSym) return yield* typeParserIssue("Class has no symbol", void 0, atLocation);
|
|
3167
|
+
const type = typeChecker.getTypeOfSymbol(classSym);
|
|
3055
3168
|
const parsedContextTag = yield* pipe(
|
|
3056
3169
|
importedEffectModule(effectServiceIdentifier.expression),
|
|
3057
3170
|
flatMap2(() => contextTag(type, atLocation)),
|
|
@@ -3078,6 +3191,7 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3078
3191
|
className: atLocation.name,
|
|
3079
3192
|
selfTypeNode,
|
|
3080
3193
|
args: wholeCall.arguments,
|
|
3194
|
+
keyStringLiteral: ts.isStringLiteral(wholeCall.arguments[0]) ? wholeCall.arguments[0] : void 0,
|
|
3081
3195
|
options: wholeCall.arguments[1],
|
|
3082
3196
|
accessors: accessors2,
|
|
3083
3197
|
dependencies
|
|
@@ -3116,6 +3230,8 @@ function make2(ts, tsUtils, typeChecker, typeCheckerUtils) {
|
|
|
3116
3230
|
extendsSchemaClass,
|
|
3117
3231
|
extendsSchemaTaggedClass,
|
|
3118
3232
|
extendsSchemaTaggedError,
|
|
3233
|
+
extendsDataTaggedError,
|
|
3234
|
+
extendsDataTaggedClass,
|
|
3119
3235
|
extendsSchemaTaggedRequest
|
|
3120
3236
|
};
|
|
3121
3237
|
}
|
|
@@ -3248,13 +3364,13 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
3248
3364
|
if (expectedEffect.A.flags & ts.TypeFlags.Void) {
|
|
3249
3365
|
const voidValueTypes = typeCheckerUtils.unrollUnionMembers(realEffect.A);
|
|
3250
3366
|
const voidedEffect = yield* firstSuccessOf(
|
|
3251
|
-
voidValueTypes.map((_) =>
|
|
3367
|
+
voidValueTypes.map((_) => map4(typeParser.strictEffectType(_, node), () => _))
|
|
3252
3368
|
);
|
|
3253
3369
|
return { voidedEffect };
|
|
3254
3370
|
}
|
|
3255
3371
|
return yield* fail(typeParserIssue("expectedEffect success is not void"));
|
|
3256
3372
|
});
|
|
3257
|
-
const entries =
|
|
3373
|
+
const entries = typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
3258
3374
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
3259
3375
|
if (expectedType !== realType) {
|
|
3260
3376
|
yield* pipe(
|
|
@@ -3264,7 +3380,7 @@ var effectInVoidSuccess = createDiagnostic({
|
|
|
3264
3380
|
valueNode,
|
|
3265
3381
|
realType
|
|
3266
3382
|
),
|
|
3267
|
-
|
|
3383
|
+
map4(({ voidedEffect }) => {
|
|
3268
3384
|
report(
|
|
3269
3385
|
{
|
|
3270
3386
|
location: node,
|
|
@@ -3359,7 +3475,7 @@ var genericEffectServices = createDiagnostic({
|
|
|
3359
3475
|
for (const [type, reportAt] of typesToCheck) {
|
|
3360
3476
|
yield* pipe(
|
|
3361
3477
|
typeParser.contextTag(type, node),
|
|
3362
|
-
|
|
3478
|
+
map4(() => {
|
|
3363
3479
|
report({
|
|
3364
3480
|
location: reportAt,
|
|
3365
3481
|
messageText: `Effect Services with type parameters are not supported because they cannot be properly discriminated at runtime, which may cause unexpected behavior.`,
|
|
@@ -3523,7 +3639,6 @@ var leakingRequirements = createDiagnostic({
|
|
|
3523
3639
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3524
3640
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
3525
3641
|
const typeParser = yield* service(TypeParser);
|
|
3526
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
3527
3642
|
const parseLeakedRequirements = cachedBy(
|
|
3528
3643
|
fn("leakingServices.checkServiceLeaking")(
|
|
3529
3644
|
function* (service2, atLocation) {
|
|
@@ -3537,7 +3652,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3537
3652
|
let effectContextType = void 0;
|
|
3538
3653
|
yield* pipe(
|
|
3539
3654
|
typeParser.effectType(servicePropertyType, atLocation),
|
|
3540
|
-
|
|
3655
|
+
map4((_) => effectContextType = _.R),
|
|
3541
3656
|
orElse2(() => {
|
|
3542
3657
|
const servicePropertyCallSignatures = typeChecker.getSignaturesOfType(
|
|
3543
3658
|
servicePropertyType,
|
|
@@ -3549,7 +3664,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3549
3664
|
typeChecker.getReturnTypeOfSignature(servicePropertyCallSignatures[0]),
|
|
3550
3665
|
atLocation
|
|
3551
3666
|
),
|
|
3552
|
-
|
|
3667
|
+
map4((_) => {
|
|
3553
3668
|
effectContextType = _.R;
|
|
3554
3669
|
})
|
|
3555
3670
|
);
|
|
@@ -3567,7 +3682,7 @@ var leakingRequirements = createDiagnostic({
|
|
|
3567
3682
|
if (type.flags & ts.TypeFlags.Never) return succeed(true);
|
|
3568
3683
|
return pipe(
|
|
3569
3684
|
typeParser.scopeType(type, atLocation),
|
|
3570
|
-
|
|
3685
|
+
map4(() => true),
|
|
3571
3686
|
orElse2(() => succeed(false))
|
|
3572
3687
|
);
|
|
3573
3688
|
}
|
|
@@ -3626,7 +3741,9 @@ More info at https://effect.website/docs/requirements-management/layers/#avoidin
|
|
|
3626
3741
|
flatMap2(
|
|
3627
3742
|
({ Service }) => pipe(
|
|
3628
3743
|
parseLeakedRequirements(Service, node),
|
|
3629
|
-
|
|
3744
|
+
map4(
|
|
3745
|
+
(requirements) => reportLeakingRequirements(reportAt, sort(requirements, typeCheckerUtils.deterministicTypeOrder))
|
|
3746
|
+
)
|
|
3630
3747
|
)
|
|
3631
3748
|
),
|
|
3632
3749
|
orElse2(() => sync(() => ts.forEachChild(node, appendNodeToVisit))),
|
|
@@ -3645,22 +3762,21 @@ var missingEffectContext = createDiagnostic({
|
|
|
3645
3762
|
apply: fn("missingEffectContext.apply")(function* (sourceFile, report) {
|
|
3646
3763
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3647
3764
|
const typeParser = yield* service(TypeParser);
|
|
3648
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
3649
3765
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
3650
3766
|
const checkForMissingContextTypes = (node, expectedType, valueNode, realType) => pipe(
|
|
3651
3767
|
all(
|
|
3652
3768
|
typeParser.effectType(expectedType, node),
|
|
3653
3769
|
typeParser.effectType(realType, valueNode)
|
|
3654
3770
|
),
|
|
3655
|
-
|
|
3771
|
+
map4(
|
|
3656
3772
|
([expectedEffect, realEffect]) => typeCheckerUtils.getMissingTypeEntriesInTargetType(
|
|
3657
3773
|
realEffect.R,
|
|
3658
3774
|
expectedEffect.R
|
|
3659
3775
|
)
|
|
3660
3776
|
)
|
|
3661
3777
|
);
|
|
3662
|
-
const sortTypes = sort(
|
|
3663
|
-
const entries =
|
|
3778
|
+
const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
|
|
3779
|
+
const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
3664
3780
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
3665
3781
|
if (expectedType !== realType) {
|
|
3666
3782
|
yield* pipe(
|
|
@@ -3670,7 +3786,7 @@ var missingEffectContext = createDiagnostic({
|
|
|
3670
3786
|
valueNode,
|
|
3671
3787
|
realType
|
|
3672
3788
|
),
|
|
3673
|
-
|
|
3789
|
+
map4(
|
|
3674
3790
|
(missingTypes) => missingTypes.length > 0 ? report(
|
|
3675
3791
|
{
|
|
3676
3792
|
location: node,
|
|
@@ -3697,7 +3813,6 @@ var missingEffectError = createDiagnostic({
|
|
|
3697
3813
|
const typeChecker = yield* service(TypeCheckerApi);
|
|
3698
3814
|
const typeCheckerUtils = yield* service(TypeCheckerUtils);
|
|
3699
3815
|
const typeParser = yield* service(TypeParser);
|
|
3700
|
-
const typeOrder = yield* deterministicTypeOrder;
|
|
3701
3816
|
const effectModuleIdentifier = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
|
|
3702
3817
|
sourceFile,
|
|
3703
3818
|
"effect",
|
|
@@ -3716,7 +3831,7 @@ var missingEffectError = createDiagnostic({
|
|
|
3716
3831
|
typeParser.effectType(expectedType, node),
|
|
3717
3832
|
typeParser.effectType(realType, valueNode)
|
|
3718
3833
|
),
|
|
3719
|
-
|
|
3834
|
+
map4(
|
|
3720
3835
|
([expectedEffect, realEffect]) => pipe(
|
|
3721
3836
|
typeCheckerUtils.getMissingTypeEntriesInTargetType(
|
|
3722
3837
|
realEffect.E,
|
|
@@ -3726,8 +3841,8 @@ var missingEffectError = createDiagnostic({
|
|
|
3726
3841
|
)
|
|
3727
3842
|
)
|
|
3728
3843
|
);
|
|
3729
|
-
const sortTypes = sort(
|
|
3730
|
-
const entries =
|
|
3844
|
+
const sortTypes = sort(typeCheckerUtils.deterministicTypeOrder);
|
|
3845
|
+
const entries = getEffectLspPatchSourceFileMetadata(sourceFile)?.relationErrors || typeCheckerUtils.expectedAndRealType(sourceFile);
|
|
3731
3846
|
for (const [node, expectedType, valueNode, realType] of entries) {
|
|
3732
3847
|
if (expectedType !== realType) {
|
|
3733
3848
|
yield* pipe(
|
|
@@ -3737,7 +3852,7 @@ var missingEffectError = createDiagnostic({
|
|
|
3737
3852
|
valueNode,
|
|
3738
3853
|
realType
|
|
3739
3854
|
),
|
|
3740
|
-
|
|
3855
|
+
map4((result) => {
|
|
3741
3856
|
if (result.missingErrorTypes.length === 0) return;
|
|
3742
3857
|
const fixes = [];
|
|
3743
3858
|
if (ts.isExpression(valueNode) && result.expectedErrorType.flags & ts.TypeFlags.Never) {
|
|
@@ -3764,17 +3879,17 @@ var missingEffectError = createDiagnostic({
|
|
|
3764
3879
|
if (ts.isExpression(valueNode)) {
|
|
3765
3880
|
const propertyAssignments = pipe(
|
|
3766
3881
|
result.missingErrorTypes,
|
|
3767
|
-
|
|
3882
|
+
map3((_) => typeChecker.getPropertyOfType(_, "_tag")),
|
|
3768
3883
|
filter((_) => !!_),
|
|
3769
|
-
|
|
3884
|
+
map3((_) => typeChecker.getTypeOfSymbolAtLocation(_, valueNode)),
|
|
3770
3885
|
filter((_) => !!(_.flags & ts.TypeFlags.Literal)),
|
|
3771
|
-
|
|
3886
|
+
map3((_) => typeChecker.typeToTypeNode(_, void 0, ts.NodeBuilderFlags.NoTruncation)),
|
|
3772
3887
|
filter((_) => !!_ && ts.isLiteralTypeNode(_)),
|
|
3773
|
-
|
|
3888
|
+
map3((_) => _.literal),
|
|
3774
3889
|
filter((_) => ts.isLiteralExpression(_)),
|
|
3775
|
-
|
|
3890
|
+
map3((_) => _.text),
|
|
3776
3891
|
sort(string2),
|
|
3777
|
-
|
|
3892
|
+
map3(
|
|
3778
3893
|
(_) => ts.factory.createPropertyAssignment(
|
|
3779
3894
|
ts.factory.createIdentifier(_),
|
|
3780
3895
|
ts.factory.createArrowFunction(
|
|
@@ -4010,7 +4125,7 @@ var missingStarInYieldEffectGen = createDiagnostic({
|
|
|
4010
4125
|
typeParser.effectGen(effectGenNode),
|
|
4011
4126
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
4012
4127
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
4013
|
-
|
|
4128
|
+
map4(({ functionStar }) => {
|
|
4014
4129
|
if (functionStar) {
|
|
4015
4130
|
brokenGenerators.add(functionStar);
|
|
4016
4131
|
}
|
|
@@ -4080,7 +4195,7 @@ var multipleEffectProvide = createDiagnostic({
|
|
|
4080
4195
|
return pipe(
|
|
4081
4196
|
typeParser.importedEffectModule(node.expression.expression),
|
|
4082
4197
|
flatMap2(() => typeParser.layerType(type, layer)),
|
|
4083
|
-
|
|
4198
|
+
map4(() => ({ layer, node })),
|
|
4084
4199
|
orElse2(() => void_)
|
|
4085
4200
|
);
|
|
4086
4201
|
}
|
|
@@ -4171,7 +4286,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
4171
4286
|
),
|
|
4172
4287
|
void 0,
|
|
4173
4288
|
[
|
|
4174
|
-
ts.factory.createIdentifier(className2
|
|
4289
|
+
ts.factory.createIdentifier(ts.idText(className2)),
|
|
4175
4290
|
ts.factory.createArrowFunction(
|
|
4176
4291
|
void 0,
|
|
4177
4292
|
void 0,
|
|
@@ -4221,9 +4336,9 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
4221
4336
|
const generateReturnType = (type, atLocation2, className2) => pipe(
|
|
4222
4337
|
typeParser.effectType(type, atLocation2),
|
|
4223
4338
|
flatMap2((returnedEffect) => {
|
|
4224
|
-
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(className2
|
|
4339
|
+
const contextType = returnedEffect.R.flags & ts.TypeFlags.Never ? ts.factory.createTypeReferenceNode(ts.idText(className2)) : ts.factory.createUnionTypeNode(
|
|
4225
4340
|
[
|
|
4226
|
-
ts.factory.createTypeReferenceNode(className2
|
|
4341
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2)),
|
|
4227
4342
|
typeChecker.typeToTypeNode(returnedEffect.R, atLocation2, ts.NodeBuilderFlags.NoTruncation)
|
|
4228
4343
|
]
|
|
4229
4344
|
);
|
|
@@ -4271,7 +4386,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
4271
4386
|
ts.factory.createIdentifier("UnknownException")
|
|
4272
4387
|
)
|
|
4273
4388
|
),
|
|
4274
|
-
ts.factory.createTypeReferenceNode(className2
|
|
4389
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2))
|
|
4275
4390
|
]
|
|
4276
4391
|
));
|
|
4277
4392
|
})
|
|
@@ -4288,7 +4403,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
4288
4403
|
[
|
|
4289
4404
|
successType,
|
|
4290
4405
|
ts.factory.createTypeReferenceNode("never"),
|
|
4291
|
-
ts.factory.createTypeReferenceNode(className2
|
|
4406
|
+
ts.factory.createTypeReferenceNode(ts.idText(className2))
|
|
4292
4407
|
]
|
|
4293
4408
|
);
|
|
4294
4409
|
return succeed(typeNode);
|
|
@@ -4319,7 +4434,7 @@ var generate = fn("writeTagClassAccessors.generate")(function* (sourceFile, serv
|
|
|
4319
4434
|
for (const signature of typeChecker.getSignaturesOfType(propertyType, ts.SignatureKind.Call)) {
|
|
4320
4435
|
yield* pipe(
|
|
4321
4436
|
proxySignature(signature, atLocation, className),
|
|
4322
|
-
|
|
4437
|
+
map4((sig) => {
|
|
4323
4438
|
callSignatures.push(sig);
|
|
4324
4439
|
}),
|
|
4325
4440
|
ignore
|
|
@@ -4365,7 +4480,7 @@ var parse2 = fn("writeTagClassAccessors.parse")(function* (node) {
|
|
|
4365
4480
|
}
|
|
4366
4481
|
const hash2 = involvedMembers.map(({ property, propertyType }) => {
|
|
4367
4482
|
return ts.symbolName(property) + ": " + typeChecker.typeToString(propertyType);
|
|
4368
|
-
}).concat([className
|
|
4483
|
+
}).concat([ts.idText(className)]).join("\n");
|
|
4369
4484
|
return { Service, className, atLocation: node, hash: cyrb53(hash2), involvedMembers };
|
|
4370
4485
|
});
|
|
4371
4486
|
var writeTagClassAccessors = createRefactor({
|
|
@@ -4378,7 +4493,7 @@ var writeTagClassAccessors = createRefactor({
|
|
|
4378
4493
|
const typeParser = yield* service(TypeParser);
|
|
4379
4494
|
const parseNode = (node) => pipe(
|
|
4380
4495
|
parse2(node),
|
|
4381
|
-
|
|
4496
|
+
map4(({ Service, atLocation, className, involvedMembers }) => ({
|
|
4382
4497
|
kind: "refactor.rewrite.effect.writeTagClassAccessors",
|
|
4383
4498
|
description: "Implement Service accessors",
|
|
4384
4499
|
apply: pipe(
|
|
@@ -4410,7 +4525,7 @@ var accessors = createCodegen({
|
|
|
4410
4525
|
if (!nodeAndCommentRange) return yield* fail(new CodegenNotApplicableError("no node and comment range"));
|
|
4411
4526
|
return yield* pipe(
|
|
4412
4527
|
parse2(nodeAndCommentRange.node),
|
|
4413
|
-
|
|
4528
|
+
map4(
|
|
4414
4529
|
(_) => ({
|
|
4415
4530
|
hash: _.hash,
|
|
4416
4531
|
description: "Generate accessors for the service",
|
|
@@ -4441,7 +4556,7 @@ var outdatedEffectCodegen = createDiagnostic({
|
|
|
4441
4556
|
for (const { codegen, hash: hash2, range } of codegensWithRanges) {
|
|
4442
4557
|
yield* pipe(
|
|
4443
4558
|
getEditsForCodegen([codegen], sourceFile, range),
|
|
4444
|
-
|
|
4559
|
+
map4((applicable) => {
|
|
4445
4560
|
if (applicable.hash !== hash2) {
|
|
4446
4561
|
_report({
|
|
4447
4562
|
location: range,
|
|
@@ -4501,7 +4616,7 @@ var overriddenSchemaConstructor = createDiagnostic({
|
|
|
4501
4616
|
const typeAtLocation = typeChecker.getTypeAtLocation(type.expression);
|
|
4502
4617
|
const isSchema = yield* pipe(
|
|
4503
4618
|
typeParser.effectSchemaType(typeAtLocation, type.expression),
|
|
4504
|
-
|
|
4619
|
+
map4(() => true),
|
|
4505
4620
|
orElse2(() => succeed(false))
|
|
4506
4621
|
);
|
|
4507
4622
|
if (isSchema) {
|
|
@@ -4572,7 +4687,7 @@ var returnEffectInGen = createDiagnostic({
|
|
|
4572
4687
|
typeParser.effectGen(effectGenNode),
|
|
4573
4688
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
4574
4689
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
4575
|
-
|
|
4690
|
+
map4(() => {
|
|
4576
4691
|
const fix = node.expression ? [{
|
|
4577
4692
|
fixName: "returnEffectInGen_fix",
|
|
4578
4693
|
description: "Add yield* statement",
|
|
@@ -4635,7 +4750,7 @@ var scopeInLayerEffect = createDiagnostic({
|
|
|
4635
4750
|
const entries = typeCheckerUtils.unrollUnionMembers(type);
|
|
4636
4751
|
return pipe(
|
|
4637
4752
|
firstSuccessOf(entries.map((type2) => typeParser.scopeType(type2, node))),
|
|
4638
|
-
|
|
4753
|
+
map4(
|
|
4639
4754
|
() => report({
|
|
4640
4755
|
location: node,
|
|
4641
4756
|
messageText: `Seems like you are constructing a layer with a scope in the requirements.
|
|
@@ -4794,7 +4909,7 @@ var tryCatchInEffectGen = createDiagnostic({
|
|
|
4794
4909
|
typeParser.effectGen(effectGenNode),
|
|
4795
4910
|
orElse2(() => typeParser.effectFnUntracedGen(effectGenNode)),
|
|
4796
4911
|
orElse2(() => typeParser.effectFnGen(effectGenNode)),
|
|
4797
|
-
|
|
4912
|
+
map4(() => {
|
|
4798
4913
|
report({
|
|
4799
4914
|
location: node,
|
|
4800
4915
|
messageText: "Avoid using try/catch inside Effect generators. Use Effect's error handling mechanisms instead (e.g., Effect.try, Effect.tryPromise, Effect.catchAll, Effect.catchTag).",
|
|
@@ -4829,7 +4944,7 @@ var unnecessaryEffectGen = createDiagnostic({
|
|
|
4829
4944
|
if (ts.isCallExpression(node)) {
|
|
4830
4945
|
yield* pipe(
|
|
4831
4946
|
typeParser.unnecessaryEffectGen(node),
|
|
4832
|
-
|
|
4947
|
+
map4(
|
|
4833
4948
|
({ replacementNode }) => report({
|
|
4834
4949
|
location: node,
|
|
4835
4950
|
messageText: `This Effect.gen contains a single return statement.`,
|
|
@@ -4872,7 +4987,7 @@ var unnecessaryPipe = createDiagnostic({
|
|
|
4872
4987
|
if (ts.isCallExpression(node)) {
|
|
4873
4988
|
yield* pipe(
|
|
4874
4989
|
typeParser.pipeCall(node),
|
|
4875
|
-
|
|
4990
|
+
map4(({ args: args2, subject }) => {
|
|
4876
4991
|
if (args2.length === 0) {
|
|
4877
4992
|
report({
|
|
4878
4993
|
location: node,
|
|
@@ -4918,9 +5033,9 @@ var unnecessaryPipeChain = createDiagnostic({
|
|
|
4918
5033
|
yield* pipe(
|
|
4919
5034
|
typeParser.pipeCall(node),
|
|
4920
5035
|
flatMap2(
|
|
4921
|
-
(pipeCall) =>
|
|
5036
|
+
(pipeCall) => map4(typeParser.pipeCall(pipeCall.subject), (innerCall) => ({ pipeCall, innerCall }))
|
|
4922
5037
|
),
|
|
4923
|
-
|
|
5038
|
+
map4(({ innerCall, pipeCall }) => {
|
|
4924
5039
|
report({
|
|
4925
5040
|
location: node,
|
|
4926
5041
|
messageText: `Chained pipe calls can be simplified to a single pipe call`,
|
|
@@ -5077,7 +5192,7 @@ function transform_default(program, pluginConfig, { addDiagnostic, ts: tsInstanc
|
|
|
5077
5192
|
)
|
|
5078
5193
|
),
|
|
5079
5194
|
getOrElse(() => []),
|
|
5080
|
-
|
|
5195
|
+
map3(addDiagnostic)
|
|
5081
5196
|
);
|
|
5082
5197
|
return sourceFile;
|
|
5083
5198
|
};
|