@effect/language-service 0.35.0 → 0.35.2

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/index.js CHANGED
@@ -1294,7 +1294,7 @@ function makeTypeScriptUtils(ts) {
1294
1294
  );
1295
1295
  if (fnName) {
1296
1296
  fnCall = ts.factory.createCallExpression(
1297
- fnName,
1297
+ fnCall,
1298
1298
  void 0,
1299
1299
  [ts.factory.createStringLiteral(fnName.text)]
1300
1300
  );
@@ -1542,6 +1542,38 @@ function makeTypeScriptUtils(ts) {
1542
1542
  )
1543
1543
  );
1544
1544
  }
1545
+ function createDataTaggedErrorDeclaration(dataModuleIdentifier, name, fields) {
1546
+ const invokeTaggedError = ts.factory.createCallExpression(
1547
+ ts.factory.createPropertyAccessExpression(
1548
+ ts.factory.createIdentifier(dataModuleIdentifier),
1549
+ "TaggedError"
1550
+ ),
1551
+ void 0,
1552
+ [
1553
+ ts.factory.createStringLiteral(name)
1554
+ ]
1555
+ );
1556
+ const withTypeFields = ts.factory.createExpressionWithTypeArguments(
1557
+ invokeTaggedError,
1558
+ [
1559
+ ts.factory.createTypeLiteralNode(fields)
1560
+ ]
1561
+ );
1562
+ return ts.factory.createClassDeclaration(
1563
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
1564
+ name,
1565
+ void 0,
1566
+ [
1567
+ ts.factory.createHeritageClause(
1568
+ ts.SyntaxKind.ExtendsKeyword,
1569
+ [
1570
+ withTypeFields
1571
+ ]
1572
+ )
1573
+ ],
1574
+ []
1575
+ );
1576
+ }
1545
1577
  return {
1546
1578
  findNodeAtPositionIncludingTrivia,
1547
1579
  parsePackageContentNameAndVersionFromScope,
@@ -1553,6 +1585,7 @@ function makeTypeScriptUtils(ts) {
1553
1585
  isNodeInRange,
1554
1586
  transformAsyncAwaitToEffectFn,
1555
1587
  transformAsyncAwaitToEffectGen,
1588
+ createDataTaggedErrorDeclaration,
1556
1589
  findImportedModuleIdentifierByPackageAndNameOrBarrel,
1557
1590
  simplifyTypeNode,
1558
1591
  tryPreserveDeclarationSemantics,
@@ -5542,6 +5575,13 @@ var makeAutoImportProvider = fn("TypeScriptApi")(function* (fromSourceFile) {
5542
5575
  exportName: namedExport.name
5543
5576
  }
5544
5577
  });
5578
+ mapFromBarrelToBarrel.set(reexportedFile.resolvedModule.resolvedFileName, {
5579
+ ...mapFromBarrelToBarrel.get(reexportedFile.resolvedModule.resolvedFileName) || {},
5580
+ [namedExport.name]: {
5581
+ fileName: reexportedFile.resolvedModule.resolvedFileName,
5582
+ exportName: namedExport.name
5583
+ }
5584
+ });
5545
5585
  }
5546
5586
  }
5547
5587
  }
@@ -10872,19 +10912,31 @@ var asyncAwaitToFnTryPromise = createRefactor({
10872
10912
  "effect",
10873
10913
  "Effect"
10874
10914
  ) || "Effect";
10915
+ const dataModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
10916
+ sourceFile,
10917
+ "effect",
10918
+ "Data"
10919
+ ) || "Data";
10875
10920
  let errorCount = 0;
10921
+ const errors = [];
10876
10922
  function createErrorADT() {
10877
10923
  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
- ]);
10924
+ const errorName = "Error" + errorCount;
10925
+ errors.push(tsUtils.createDataTaggedErrorDeclaration(dataModuleIdentifierName, errorName, [
10926
+ ts.factory.createPropertySignature(
10927
+ void 0,
10928
+ "cause",
10929
+ void 0,
10930
+ ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)
10931
+ )
10932
+ ]));
10933
+ return ts.factory.createNewExpression(
10934
+ ts.factory.createIdentifier(errorName),
10935
+ void 0,
10936
+ [ts.factory.createObjectLiteralExpression([
10937
+ ts.factory.createShorthandPropertyAssignment("cause")
10938
+ ])]
10939
+ );
10888
10940
  }
10889
10941
  const newDeclaration = tsUtils.transformAsyncAwaitToEffectFn(
10890
10942
  node,
@@ -10913,7 +10965,7 @@ var asyncAwaitToFnTryPromise = createRefactor({
10913
10965
  ts.factory.createArrowFunction(
10914
10966
  void 0,
10915
10967
  void 0,
10916
- [ts.factory.createParameterDeclaration(void 0, void 0, "error")],
10968
+ [ts.factory.createParameterDeclaration(void 0, void 0, "cause")],
10917
10969
  void 0,
10918
10970
  void 0,
10919
10971
  createErrorADT()
@@ -10923,6 +10975,13 @@ var asyncAwaitToFnTryPromise = createRefactor({
10923
10975
  ]
10924
10976
  )
10925
10977
  );
10978
+ let beforeNode = node;
10979
+ while (beforeNode.parent && !ts.isSourceFile(beforeNode.parent)) {
10980
+ beforeNode = beforeNode.parent;
10981
+ }
10982
+ for (const error of errors) {
10983
+ changeTracker.insertNodeBefore(sourceFile, beforeNode, error, true);
10984
+ }
10926
10985
  changeTracker.replaceNode(sourceFile, node, newDeclaration);
10927
10986
  }),
10928
10987
  provideService(TypeScriptApi, ts),
@@ -11022,19 +11081,31 @@ var asyncAwaitToGenTryPromise = createRefactor({
11022
11081
  "effect",
11023
11082
  "Effect"
11024
11083
  ) || "Effect";
11084
+ const dataModuleIdentifierName = tsUtils.findImportedModuleIdentifierByPackageAndNameOrBarrel(
11085
+ sourceFile,
11086
+ "effect",
11087
+ "Data"
11088
+ ) || "Data";
11025
11089
  let errorCount = 0;
11090
+ const errors = [];
11026
11091
  function createErrorADT() {
11027
11092
  errorCount++;
11028
- return ts.factory.createObjectLiteralExpression([
11029
- ts.factory.createPropertyAssignment(
11030
- "_tag",
11031
- ts.factory.createAsExpression(
11032
- ts.factory.createStringLiteral("Error" + errorCount),
11033
- ts.factory.createTypeReferenceNode("const")
11034
- )
11035
- ),
11036
- ts.factory.createShorthandPropertyAssignment("error")
11037
- ]);
11093
+ const errorName = "Error" + errorCount;
11094
+ errors.push(tsUtils.createDataTaggedErrorDeclaration(dataModuleIdentifierName, errorName, [
11095
+ ts.factory.createPropertySignature(
11096
+ void 0,
11097
+ "cause",
11098
+ void 0,
11099
+ ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)
11100
+ )
11101
+ ]));
11102
+ return ts.factory.createNewExpression(
11103
+ ts.factory.createIdentifier(errorName),
11104
+ void 0,
11105
+ [ts.factory.createObjectLiteralExpression([
11106
+ ts.factory.createShorthandPropertyAssignment("cause")
11107
+ ])]
11108
+ );
11038
11109
  }
11039
11110
  const newDeclaration = tsUtils.transformAsyncAwaitToEffectGen(
11040
11111
  node,
@@ -11063,7 +11134,7 @@ var asyncAwaitToGenTryPromise = createRefactor({
11063
11134
  ts.factory.createArrowFunction(
11064
11135
  void 0,
11065
11136
  void 0,
11066
- [ts.factory.createParameterDeclaration(void 0, void 0, "error")],
11137
+ [ts.factory.createParameterDeclaration(void 0, void 0, "cause")],
11067
11138
  void 0,
11068
11139
  void 0,
11069
11140
  createErrorADT()
@@ -11073,6 +11144,13 @@ var asyncAwaitToGenTryPromise = createRefactor({
11073
11144
  ]
11074
11145
  )
11075
11146
  );
11147
+ let beforeNode = node;
11148
+ while (beforeNode.parent && !ts.isSourceFile(beforeNode.parent)) {
11149
+ beforeNode = beforeNode.parent;
11150
+ }
11151
+ for (const error of errors) {
11152
+ changeTracker.insertNodeBefore(sourceFile, beforeNode, error, true);
11153
+ }
11076
11154
  changeTracker.replaceNode(sourceFile, node, newDeclaration);
11077
11155
  }),
11078
11156
  provideService(TypeScriptApi, ts),