@teambit/typescript 0.0.1118 → 0.0.1119

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.
Files changed (39) hide show
  1. package/dist/{preview-1690366266887.js → preview-1690443565721.js} +2 -2
  2. package/dist/sourceFileTransformers/class.js +26 -7
  3. package/dist/sourceFileTransformers/class.js.map +1 -1
  4. package/dist/sourceFileTransformers/expression-statement.js +26 -5
  5. package/dist/sourceFileTransformers/expression-statement.js.map +1 -1
  6. package/dist/sourceFileTransformers/function.js +8 -1
  7. package/dist/sourceFileTransformers/function.js.map +1 -1
  8. package/dist/sourceFileTransformers/index.d.ts +1 -0
  9. package/dist/sourceFileTransformers/index.js +13 -0
  10. package/dist/sourceFileTransformers/index.js.map +1 -1
  11. package/dist/sourceFileTransformers/interface.js +18 -6
  12. package/dist/sourceFileTransformers/interface.js.map +1 -1
  13. package/dist/sourceFileTransformers/replaceName.d.ts +1 -0
  14. package/dist/sourceFileTransformers/replaceName.js +23 -0
  15. package/dist/sourceFileTransformers/replaceName.js.map +1 -0
  16. package/dist/sourceFileTransformers/transform.js +0 -38
  17. package/dist/sourceFileTransformers/transform.js.map +1 -1
  18. package/dist/sourceFileTransformers/type-reference.d.ts +2 -0
  19. package/dist/sourceFileTransformers/type-reference.js +38 -0
  20. package/dist/sourceFileTransformers/type-reference.js.map +1 -0
  21. package/dist/sourceFileTransformers/typeAlias.js +9 -6
  22. package/dist/sourceFileTransformers/typeAlias.js.map +1 -1
  23. package/dist/sourceFileTransformers/variable.js +9 -6
  24. package/dist/sourceFileTransformers/variable.js.map +1 -1
  25. package/dist/transform-source-file.spec.js +31 -12
  26. package/dist/transform-source-file.spec.js.map +1 -1
  27. package/package-tar/teambit-typescript-0.0.1119.tgz +0 -0
  28. package/package.json +18 -18
  29. package/sourceFileTransformers/class.ts +55 -7
  30. package/sourceFileTransformers/expression-statement.ts +22 -15
  31. package/sourceFileTransformers/function.ts +2 -1
  32. package/sourceFileTransformers/index.ts +1 -0
  33. package/sourceFileTransformers/interface.ts +19 -6
  34. package/sourceFileTransformers/replaceName.ts +11 -0
  35. package/sourceFileTransformers/transform.ts +0 -37
  36. package/sourceFileTransformers/type-reference.ts +19 -0
  37. package/sourceFileTransformers/typeAlias.ts +3 -5
  38. package/sourceFileTransformers/variable.ts +3 -6
  39. package/package-tar/teambit-typescript-0.0.1118.tgz +0 -0
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.1118/dist/typescript.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.1118/dist/typescript.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.1119/dist/typescript.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.1119/dist/typescript.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- require("core-js/modules/es.regexp.constructor.js");
5
- require("core-js/modules/es.regexp.exec.js");
6
- require("core-js/modules/es.string.replace.js");
7
4
  Object.defineProperty(exports, "__esModule", {
8
5
  value: true
9
6
  });
@@ -15,6 +12,13 @@ function _typescript() {
15
12
  };
16
13
  return data;
17
14
  }
15
+ function _replaceName() {
16
+ const data = require("./replaceName");
17
+ _replaceName = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
18
22
  function classNamesTransformer(nameMapping) {
19
23
  return context => {
20
24
  const {
@@ -23,13 +27,28 @@ function classNamesTransformer(nameMapping) {
23
27
  const visit = node => {
24
28
  if (_typescript().default.isClassDeclaration(node) && node.name) {
25
29
  const oldName = node.name.text;
26
- const newName = Object.keys(nameMapping).find(key => oldName.startsWith(key) || oldName.endsWith(key));
30
+ const newName = (0, _replaceName().replaceName)(oldName, nameMapping);
27
31
  if (newName) {
28
- const replacedName = oldName.startsWith(newName) ? oldName.replace(newName, nameMapping[newName]) : oldName.replace(new RegExp(`${newName}$`), nameMapping[newName]);
29
- return factory.updateClassDeclaration(node, node.decorators, node.modifiers, factory.createIdentifier(replacedName), node.typeParameters, node.heritageClauses, node.members);
32
+ const updatedMembers = node.members.map(member => {
33
+ if (_typescript().default.isPropertyDeclaration(member)) {
34
+ const oldMemberName = member.name.getText();
35
+ const newMemberName = (0, _replaceName().replaceName)(oldMemberName, nameMapping);
36
+ return factory.updatePropertyDeclaration(member, member.decorators, member.modifiers, newMemberName ? _typescript().default.factory.createIdentifier(newMemberName) : member.name, member.questionToken, member.type, member.initializer);
37
+ }
38
+ if (_typescript().default.isMethodDeclaration(member)) {
39
+ const oldMemberName = member.name.getText();
40
+ const newMemberName = (0, _replaceName().replaceName)(oldMemberName, nameMapping);
41
+ const updatedParameters = member.parameters.map(param => {
42
+ return _typescript().default.factory.updateParameterDeclaration(param, param.decorators, param.modifiers, param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
43
+ });
44
+ return factory.updateMethodDeclaration(member, member.decorators, member.modifiers, member.asteriskToken, newMemberName ? _typescript().default.factory.createIdentifier(newMemberName) : member.name, member.questionToken, member.typeParameters, updatedParameters, member.type, member.body);
45
+ }
46
+ return member;
47
+ });
48
+ return factory.updateClassDeclaration(node, node.decorators, node.modifiers, factory.createIdentifier(newName), node.typeParameters, node.heritageClauses, updatedMembers);
30
49
  }
31
50
  }
32
- return _typescript().default.visitEachChild(node, child => visit(child), context);
51
+ return _typescript().default.visitEachChild(node, visit, context);
33
52
  };
34
53
  return node => _typescript().default.visitNode(node, visit);
35
54
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","classNamesTransformer","nameMapping","context","factory","visit","node","ts","isClassDeclaration","name","oldName","text","newName","Object","keys","find","key","startsWith","endsWith","replacedName","replace","RegExp","updateClassDeclaration","decorators","modifiers","createIdentifier","typeParameters","heritageClauses","members","visitEachChild","child","visitNode"],"sources":["class.ts"],"sourcesContent":["import ts from 'typescript';\n\nexport function classNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {\n return (context) => {\n const { factory } = context;\n const visit: ts.Visitor = (node) => {\n if (ts.isClassDeclaration(node) && node.name) {\n const oldName = node.name.text;\n const newName = Object.keys(nameMapping).find((key) => oldName.startsWith(key) || oldName.endsWith(key));\n if (newName) {\n const replacedName = oldName.startsWith(newName)\n ? oldName.replace(newName, nameMapping[newName])\n : oldName.replace(new RegExp(`${newName}$`), nameMapping[newName]);\n return factory.updateClassDeclaration(\n node,\n node.decorators,\n node.modifiers,\n factory.createIdentifier(replacedName),\n node.typeParameters,\n node.heritageClauses,\n node.members\n );\n }\n }\n return ts.visitEachChild(node, (child) => visit(child), context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASG,qBAAqBA,CAACC,WAAmC,EAAwC;EAC/G,OAAQC,OAAO,IAAK;IAClB,MAAM;MAAEC;IAAQ,CAAC,GAAGD,OAAO;IAC3B,MAAME,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,kBAAkB,CAACF,IAAI,CAAC,IAAIA,IAAI,CAACG,IAAI,EAAE;QAC5C,MAAMC,OAAO,GAAGJ,IAAI,CAACG,IAAI,CAACE,IAAI;QAC9B,MAAMC,OAAO,GAAGC,MAAM,CAACC,IAAI,CAACZ,WAAW,CAAC,CAACa,IAAI,CAAEC,GAAG,IAAKN,OAAO,CAACO,UAAU,CAACD,GAAG,CAAC,IAAIN,OAAO,CAACQ,QAAQ,CAACF,GAAG,CAAC,CAAC;QACxG,IAAIJ,OAAO,EAAE;UACX,MAAMO,YAAY,GAAGT,OAAO,CAACO,UAAU,CAACL,OAAO,CAAC,GAC5CF,OAAO,CAACU,OAAO,CAACR,OAAO,EAAEV,WAAW,CAACU,OAAO,CAAC,CAAC,GAC9CF,OAAO,CAACU,OAAO,CAAC,IAAIC,MAAM,CAAE,GAAET,OAAQ,GAAE,CAAC,EAAEV,WAAW,CAACU,OAAO,CAAC,CAAC;UACpE,OAAOR,OAAO,CAACkB,sBAAsB,CACnChB,IAAI,EACJA,IAAI,CAACiB,UAAU,EACfjB,IAAI,CAACkB,SAAS,EACdpB,OAAO,CAACqB,gBAAgB,CAACN,YAAY,CAAC,EACtCb,IAAI,CAACoB,cAAc,EACnBpB,IAAI,CAACqB,eAAe,EACpBrB,IAAI,CAACsB,OACP,CAAC;QACH;MACF;MACA,OAAOrB,qBAAE,CAACsB,cAAc,CAACvB,IAAI,EAAGwB,KAAK,IAAKzB,KAAK,CAACyB,KAAK,CAAC,EAAE3B,OAAO,CAAC;IAClE,CAAC;IACD,OAAQG,IAAI,IAAKC,qBAAE,CAACwB,SAAS,CAACzB,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","classNamesTransformer","nameMapping","context","factory","visit","node","ts","isClassDeclaration","name","oldName","text","newName","replaceName","updatedMembers","members","map","member","isPropertyDeclaration","oldMemberName","getText","newMemberName","updatePropertyDeclaration","decorators","modifiers","createIdentifier","questionToken","type","initializer","isMethodDeclaration","updatedParameters","parameters","param","updateParameterDeclaration","dotDotDotToken","updateMethodDeclaration","asteriskToken","typeParameters","body","updateClassDeclaration","heritageClauses","visitEachChild","visitNode"],"sources":["class.ts"],"sourcesContent":["import ts from 'typescript';\nimport { replaceName } from './replaceName';\n\nexport function classNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {\n return (context) => {\n const { factory } = context;\n\n const visit: ts.Visitor = (node) => {\n if (ts.isClassDeclaration(node) && node.name) {\n const oldName = node.name.text;\n const newName = replaceName(oldName, nameMapping);\n\n if (newName) {\n const updatedMembers = node.members.map((member) => {\n if (ts.isPropertyDeclaration(member)) {\n const oldMemberName = member.name.getText();\n const newMemberName = replaceName(oldMemberName, nameMapping);\n return factory.updatePropertyDeclaration(\n member,\n member.decorators,\n member.modifiers,\n newMemberName ? ts.factory.createIdentifier(newMemberName) : member.name,\n member.questionToken,\n member.type,\n member.initializer\n );\n }\n\n if (ts.isMethodDeclaration(member)) {\n const oldMemberName = member.name.getText();\n const newMemberName = replaceName(oldMemberName, nameMapping);\n\n const updatedParameters = member.parameters.map((param) => {\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n param.name,\n param.questionToken,\n param.type,\n param.initializer\n );\n });\n\n return factory.updateMethodDeclaration(\n member,\n member.decorators,\n member.modifiers,\n member.asteriskToken,\n newMemberName ? ts.factory.createIdentifier(newMemberName) : member.name,\n member.questionToken,\n member.typeParameters,\n updatedParameters,\n member.type,\n member.body\n );\n }\n return member;\n });\n\n return factory.updateClassDeclaration(\n node,\n node.decorators,\n node.modifiers,\n factory.createIdentifier(newName),\n node.typeParameters,\n node.heritageClauses,\n updatedMembers\n );\n }\n }\n return ts.visitEachChild(node, visit, context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,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,MAAM4B,iBAAiB,GAAGb,MAAM,CAACc,UAAU,CAACf,GAAG,CAAEgB,KAAK,IAAK;gBACzD,OAAOzB,qBAAE,CAACH,OAAO,CAAC6B,0BAA0B,CAC1CD,KAAK,EACLA,KAAK,CAACT,UAAU,EAChBS,KAAK,CAACR,SAAS,EACfQ,KAAK,CAACE,cAAc,EACpBF,KAAK,CAACvB,IAAI,EACVuB,KAAK,CAACN,aAAa,EACnBM,KAAK,CAACL,IAAI,EACVK,KAAK,CAACJ,WACR,CAAC;cACH,CAAC,CAAC;cAEF,OAAOxB,OAAO,CAAC+B,uBAAuB,CACpClB,MAAM,EACNA,MAAM,CAACM,UAAU,EACjBN,MAAM,CAACO,SAAS,EAChBP,MAAM,CAACmB,aAAa,EACpBf,aAAa,GAAGd,qBAAE,CAACH,OAAO,CAACqB,gBAAgB,CAACJ,aAAa,CAAC,GAAGJ,MAAM,CAACR,IAAI,EACxEQ,MAAM,CAACS,aAAa,EACpBT,MAAM,CAACoB,cAAc,EACrBP,iBAAiB,EACjBb,MAAM,CAACU,IAAI,EACXV,MAAM,CAACqB,IACT,CAAC;YACH;YACA,OAAOrB,MAAM;UACf,CAAC,CAAC;UAEF,OAAOb,OAAO,CAACmC,sBAAsB,CACnCjC,IAAI,EACJA,IAAI,CAACiB,UAAU,EACfjB,IAAI,CAACkB,SAAS,EACdpB,OAAO,CAACqB,gBAAgB,CAACb,OAAO,CAAC,EACjCN,IAAI,CAAC+B,cAAc,EACnB/B,IAAI,CAACkC,eAAe,EACpB1B,cACF,CAAC;QACH;MACF;MACA,OAAOP,qBAAE,CAACkC,cAAc,CAACnC,IAAI,EAAED,KAAK,EAAEF,OAAO,CAAC;IAChD,CAAC;IACD,OAAQG,IAAI,IAAKC,qBAAE,CAACmC,SAAS,CAACpC,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH"}
@@ -12,20 +12,41 @@ function _typescript() {
12
12
  };
13
13
  return data;
14
14
  }
15
+ function _replaceName() {
16
+ const data = require("./replaceName");
17
+ _replaceName = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
15
22
  const expressionStatementTransformer = mapping => {
16
23
  return context => {
24
+ const replaceIdentifierText = identifier => {
25
+ try {
26
+ if (!identifier || !_typescript().default.isIdentifier(identifier)) return identifier;
27
+ const oldName = identifier.getText();
28
+ const newName = (0, _replaceName().replaceName)(oldName, mapping);
29
+ if (newName) {
30
+ return _typescript().default.factory.createIdentifier(newName);
31
+ }
32
+ return identifier;
33
+ } catch (e) {
34
+ return identifier;
35
+ }
36
+ };
17
37
  const visit = node => {
18
38
  if (_typescript().default.isExpressionStatement(node)) {
19
39
  return _typescript().default.factory.updateExpressionStatement(node, _typescript().default.visitNode(node.expression, visit));
20
40
  }
21
- if (_typescript().default.isCallExpression(node)) {
22
- return _typescript().default.factory.updateCallExpression(node, _typescript().default.visitNode(node.expression, visit), node.typeArguments, node.arguments.map(arg => _typescript().default.visitNode(arg, visit)));
23
- }
24
41
  if (_typescript().default.isPropertyAccessExpression(node)) {
25
- return _typescript().default.factory.updatePropertyAccessExpression(node, _typescript().default.visitNode(node.expression, visit), typeof mapping[node.name.text] === 'string' ? _typescript().default.factory.createIdentifier(mapping[node.name.text]) : node.name);
42
+ let newName = node.name;
43
+ if (_typescript().default.isIdentifier(node.name)) {
44
+ newName = replaceIdentifierText(node.name);
45
+ }
46
+ return _typescript().default.factory.updatePropertyAccessExpression(node, _typescript().default.visitNode(node.expression, visit), newName);
26
47
  }
27
48
  if (_typescript().default.isIdentifier(node)) {
28
- return typeof mapping[node.text] === 'string' ? _typescript().default.factory.createIdentifier(mapping[node.text]) : node;
49
+ return replaceIdentifierText(node);
29
50
  }
30
51
  return _typescript().default.visitEachChild(node, visit, context);
31
52
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","expressionStatementTransformer","mapping","context","visit","node","ts","isExpressionStatement","factory","updateExpressionStatement","visitNode","expression","isCallExpression","updateCallExpression","typeArguments","arguments","map","arg","isPropertyAccessExpression","updatePropertyAccessExpression","name","text","createIdentifier","isIdentifier","visitEachChild","exports"],"sources":["expression-statement.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\n\nexport const expressionStatementTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const visit: ts.Visitor = (node) => {\n if (ts.isExpressionStatement(node)) {\n return ts.factory.updateExpressionStatement(node, ts.visitNode(node.expression, visit));\n }\n\n if (ts.isCallExpression(node)) {\n return ts.factory.updateCallExpression(\n node,\n ts.visitNode(node.expression, visit),\n node.typeArguments,\n node.arguments.map((arg) => ts.visitNode(arg, visit))\n );\n }\n\n if (ts.isPropertyAccessExpression(node)) {\n return ts.factory.updatePropertyAccessExpression(\n node,\n ts.visitNode(node.expression, visit),\n typeof mapping[node.name.text] === 'string' ? ts.factory.createIdentifier(mapping[node.name.text]) : node.name\n );\n }\n\n if (ts.isIdentifier(node)) {\n return typeof mapping[node.text] === 'string' ? ts.factory.createIdentifier(mapping[node.text]) : node;\n }\n\n return ts.visitEachChild(node, visit, context);\n };\n\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGO,MAAMG,8BAAqD,GAAIC,OAA+B,IAAK;EACxG,OAAQC,OAAO,IAAK;IAClB,MAAMC,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,qBAAqB,CAACF,IAAI,CAAC,EAAE;QAClC,OAAOC,qBAAE,CAACE,OAAO,CAACC,yBAAyB,CAACJ,IAAI,EAAEC,qBAAE,CAACI,SAAS,CAACL,IAAI,CAACM,UAAU,EAAEP,KAAK,CAAC,CAAC;MACzF;MAEA,IAAIE,qBAAE,CAACM,gBAAgB,CAACP,IAAI,CAAC,EAAE;QAC7B,OAAOC,qBAAE,CAACE,OAAO,CAACK,oBAAoB,CACpCR,IAAI,EACJC,qBAAE,CAACI,SAAS,CAACL,IAAI,CAACM,UAAU,EAAEP,KAAK,CAAC,EACpCC,IAAI,CAACS,aAAa,EAClBT,IAAI,CAACU,SAAS,CAACC,GAAG,CAAEC,GAAG,IAAKX,qBAAE,CAACI,SAAS,CAACO,GAAG,EAAEb,KAAK,CAAC,CACtD,CAAC;MACH;MAEA,IAAIE,qBAAE,CAACY,0BAA0B,CAACb,IAAI,CAAC,EAAE;QACvC,OAAOC,qBAAE,CAACE,OAAO,CAACW,8BAA8B,CAC9Cd,IAAI,EACJC,qBAAE,CAACI,SAAS,CAACL,IAAI,CAACM,UAAU,EAAEP,KAAK,CAAC,EACpC,OAAOF,OAAO,CAACG,IAAI,CAACe,IAAI,CAACC,IAAI,CAAC,KAAK,QAAQ,GAAGf,qBAAE,CAACE,OAAO,CAACc,gBAAgB,CAACpB,OAAO,CAACG,IAAI,CAACe,IAAI,CAACC,IAAI,CAAC,CAAC,GAAGhB,IAAI,CAACe,IAC5G,CAAC;MACH;MAEA,IAAId,qBAAE,CAACiB,YAAY,CAAClB,IAAI,CAAC,EAAE;QACzB,OAAO,OAAOH,OAAO,CAACG,IAAI,CAACgB,IAAI,CAAC,KAAK,QAAQ,GAAGf,qBAAE,CAACE,OAAO,CAACc,gBAAgB,CAACpB,OAAO,CAACG,IAAI,CAACgB,IAAI,CAAC,CAAC,GAAGhB,IAAI;MACxG;MAEA,OAAOC,qBAAE,CAACkB,cAAc,CAACnB,IAAI,EAAED,KAAK,EAAED,OAAO,CAAC;IAChD,CAAC;IAED,OAAQE,IAAI,IAAKC,qBAAE,CAACI,SAAS,CAACL,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAACqB,OAAA,CAAAxB,8BAAA,GAAAA,8BAAA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","expressionStatementTransformer","mapping","context","replaceIdentifierText","identifier","ts","isIdentifier","oldName","getText","newName","replaceName","factory","createIdentifier","e","visit","node","isExpressionStatement","updateExpressionStatement","visitNode","expression","isPropertyAccessExpression","name","updatePropertyAccessExpression","visitEachChild","exports"],"sources":["expression-statement.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\nimport { replaceName } from './replaceName';\n\nexport const expressionStatementTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const replaceIdentifierText = (identifier: ts.Identifier) => {\n try {\n if (!identifier || !ts.isIdentifier(identifier)) return identifier;\n const oldName = identifier.getText();\n const newName = replaceName(oldName, mapping);\n\n if (newName) {\n return ts.factory.createIdentifier(newName);\n }\n return identifier;\n } catch (e) {\n return identifier;\n }\n };\n\n const visit: ts.Visitor = (node) => {\n if (ts.isExpressionStatement(node)) {\n return ts.factory.updateExpressionStatement(node, ts.visitNode(node.expression, visit));\n }\n\n if (ts.isPropertyAccessExpression(node)) {\n let newName = node.name;\n if (ts.isIdentifier(node.name)) {\n newName = replaceIdentifierText(node.name);\n }\n return ts.factory.updatePropertyAccessExpression(node, ts.visitNode(node.expression, visit), newName);\n }\n\n if (ts.isIdentifier(node)) {\n return replaceIdentifierText(node);\n }\n\n return ts.visitEachChild(node, visit, context);\n };\n\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAMI,8BAAqD,GAAIC,OAA+B,IAAK;EACxG,OAAQC,OAAO,IAAK;IAClB,MAAMC,qBAAqB,GAAIC,UAAyB,IAAK;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,CAAC;IAChD,CAAC;IAED,OAAQa,IAAI,IAAKV,qBAAE,CAACa,SAAS,CAACH,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAACU,OAAA,CAAAxB,8BAAA,GAAAA,8BAAA"}
@@ -13,12 +13,19 @@ function _typescript() {
13
13
  };
14
14
  return data;
15
15
  }
16
+ function _replaceName() {
17
+ const data = require("./replaceName");
18
+ _replaceName = function () {
19
+ return data;
20
+ };
21
+ return data;
22
+ }
16
23
  const functionNamesTransformer = mapping => {
17
24
  return context => {
18
25
  const updateTypeReference = node => {
19
26
  if (_typescript().default.isTypeReferenceNode(node)) {
20
27
  const typeName = node.typeName.getText();
21
- const newTypeName = mapping[typeName];
28
+ const newTypeName = (0, _replaceName().replaceName)(typeName, mapping);
22
29
  if (newTypeName) {
23
30
  return _typescript().default.factory.updateTypeReferenceNode(node, _typescript().default.factory.createIdentifier(newTypeName), node.typeArguments);
24
31
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","functionNamesTransformer","mapping","context","updateTypeReference","node","ts","isTypeReferenceNode","typeName","getText","newTypeName","factory","updateTypeReferenceNode","createIdentifier","typeArguments","visitEachChild","visit","isFunctionDeclaration","isArrowFunction","isFunctionExpression","_node$name$getText","_node$name","_Object$entries$find$","_Object$entries$find","functionName","name","newName","Object","entries","find","key","includes","parameters","map","param","newParamType","type","visitNode","isIdentifier","oldName","newParamName","keys","updateParameterDeclaration","decorators","modifiers","dotDotDotToken","questionToken","initializer","isObjectBindingPattern","elements","element","newElementName","updateBindingElement","propertyName","createObjectBindingPattern","updatedBody","body","isBlock","updateReturnStatement","updateFunctionDeclaration","asteriskToken","typeParameters","updateArrowFunction","equalsGreaterThanToken","updateFunctionExpression","updatedStatements","statement","statements","isReturnStatement","expression","isJsxElement","jsxElement","openingElement","tagName","newTagName","updatedTagName","updatedOpeningElement","updateJsxOpeningElement","attributes","updatedClosingElement","closingElement","updateJsxClosingElement","createJsxClosingElement","updatedJsxElement","createJsxElement","children","updatedStatement","createReturnStatement","push","updateBlock","isExpressionStatement","text","updatedExpression","updatedReturnStatement","createBlock","exports"],"sources":["function.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\n\nexport const functionNamesTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const updateTypeReference: ts.Visitor = (node) => {\n if (ts.isTypeReferenceNode(node)) {\n const typeName = node.typeName.getText();\n const newTypeName = mapping[typeName];\n if (newTypeName) {\n return ts.factory.updateTypeReferenceNode(node, ts.factory.createIdentifier(newTypeName), node.typeArguments);\n }\n }\n return ts.visitEachChild(node, updateTypeReference, context);\n };\n\n const visit: ts.Visitor = (node) => {\n if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n const functionName = node.name?.getText() ?? '';\n const newName = Object.entries(mapping).find(([key]) => functionName.includes(key))?.[1] ?? functionName;\n const parameters = node.parameters.map((param) => {\n const newParamType = param.type ? ts.visitNode(param.type, updateTypeReference) : param.type;\n if (ts.isIdentifier(param.name)) {\n const oldName = param.name.getText();\n const newParamName = Object.keys(mapping).find((key) => oldName.includes(key));\n if (newParamName) {\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n ts.factory.createIdentifier(newParamName),\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n } else if (ts.isObjectBindingPattern(param.name)) {\n const elements = param.name.elements.map((element) => {\n const newElementName = mapping[element.name.getText()];\n if (newElementName) {\n return ts.factory.updateBindingElement(\n element,\n element.dotDotDotToken,\n element.propertyName,\n ts.factory.createIdentifier(newElementName),\n element.initializer\n );\n }\n return element;\n });\n const newParamName = ts.factory.createObjectBindingPattern(elements);\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n newParamName,\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n return param;\n });\n\n if (ts.isFunctionDeclaration(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n if (ts.isArrowFunction(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateArrowFunction(\n node,\n node.modifiers,\n node.typeParameters,\n parameters,\n node.type,\n node.equalsGreaterThanToken,\n updatedBody\n );\n }\n if (ts.isFunctionExpression(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionExpression(\n node,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n }\n return ts.visitEachChild(node, visit, context);\n };\n\n function updateReturnStatement(body: ts.ConciseBody): ts.Block {\n if (ts.isBlock(body)) {\n const updatedStatements: ts.Statement[] = [];\n for (const statement of body.statements) {\n if (ts.isReturnStatement(statement) && statement.expression && ts.isJsxElement(statement.expression)) {\n const jsxElement = statement.expression;\n const openingElement = jsxElement.openingElement;\n const tagName = openingElement.tagName.getText();\n const newTagName = mapping[tagName];\n if (newTagName) {\n const updatedTagName = ts.factory.createIdentifier(newTagName);\n const updatedOpeningElement = ts.factory.updateJsxOpeningElement(\n openingElement,\n updatedTagName,\n openingElement.typeArguments,\n openingElement.attributes\n );\n const updatedClosingElement = jsxElement.closingElement\n ? ts.factory.updateJsxClosingElement(jsxElement.closingElement, updatedTagName)\n : ts.factory.createJsxClosingElement(updatedTagName);\n const updatedJsxElement = ts.factory.createJsxElement(\n updatedOpeningElement,\n jsxElement.children,\n updatedClosingElement\n );\n const updatedStatement = ts.factory.createReturnStatement(updatedJsxElement);\n updatedStatements.push(updatedStatement);\n } else {\n updatedStatements.push(statement);\n }\n } else {\n updatedStatements.push(statement);\n }\n }\n return ts.factory.updateBlock(body, updatedStatements);\n }\n if (\n ts.isExpressionStatement(body) &&\n ts.isReturnStatement(body.expression) &&\n body.expression.expression &&\n ts.isIdentifier(body.expression.expression)\n ) {\n const oldName = body.expression.expression.text;\n const newName = mapping[oldName];\n if (newName) {\n const updatedExpression = ts.factory.createIdentifier(newName);\n const updatedReturnStatement = ts.factory.createReturnStatement(updatedExpression);\n return ts.factory.createBlock([updatedReturnStatement], true);\n }\n }\n return ts.factory.createBlock([], true);\n }\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGO,MAAMG,wBAA+C,GAAIC,OAA+B,IAAK;EAClG,OAAQC,OAAO,IAAK;IAClB,MAAMC,mBAA+B,GAAIC,IAAI,IAAK;MAChD,IAAIC,qBAAE,CAACC,mBAAmB,CAACF,IAAI,CAAC,EAAE;QAChC,MAAMG,QAAQ,GAAGH,IAAI,CAACG,QAAQ,CAACC,OAAO,CAAC,CAAC;QACxC,MAAMC,WAAW,GAAGR,OAAO,CAACM,QAAQ,CAAC;QACrC,IAAIE,WAAW,EAAE;UACf,OAAOJ,qBAAE,CAACK,OAAO,CAACC,uBAAuB,CAACP,IAAI,EAAEC,qBAAE,CAACK,OAAO,CAACE,gBAAgB,CAACH,WAAW,CAAC,EAAEL,IAAI,CAACS,aAAa,CAAC;QAC/G;MACF;MACA,OAAOR,qBAAE,CAACS,cAAc,CAACV,IAAI,EAAED,mBAAmB,EAAED,OAAO,CAAC;IAC9D,CAAC;IAED,MAAMa,KAAiB,GAAIX,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACW,qBAAqB,CAACZ,IAAI,CAAC,IAAIC,qBAAE,CAACY,eA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F,qBAAE,CAACK,OAAO,CAACmF,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC;IACzC;IACA,OAAQzF,IAAI,IAAKC,qBAAE,CAAC+B,SAAS,CAAChC,IAAI,EAAEW,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAAC+E,OAAA,CAAA9F,wBAAA,GAAAA,wBAAA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","functionNamesTransformer","mapping","context","updateTypeReference","node","ts","isTypeReferenceNode","typeName","getText","newTypeName","replaceName","factory","updateTypeReferenceNode","createIdentifier","typeArguments","visitEachChild","visit","isFunctionDeclaration","isArrowFunction","isFunctionExpression","_node$name$getText","_node$name","_Object$entries$find$","_Object$entries$find","functionName","name","newName","Object","entries","find","key","includes","parameters","map","param","newParamType","type","visitNode","isIdentifier","oldName","newParamName","keys","updateParameterDeclaration","decorators","modifiers","dotDotDotToken","questionToken","initializer","isObjectBindingPattern","elements","element","newElementName","updateBindingElement","propertyName","createObjectBindingPattern","updatedBody","body","isBlock","updateReturnStatement","updateFunctionDeclaration","asteriskToken","typeParameters","updateArrowFunction","equalsGreaterThanToken","updateFunctionExpression","updatedStatements","statement","statements","isReturnStatement","expression","isJsxElement","jsxElement","openingElement","tagName","newTagName","updatedTagName","updatedOpeningElement","updateJsxOpeningElement","attributes","updatedClosingElement","closingElement","updateJsxClosingElement","createJsxClosingElement","updatedJsxElement","createJsxElement","children","updatedStatement","createReturnStatement","push","updateBlock","isExpressionStatement","text","updatedExpression","updatedReturnStatement","createBlock","exports"],"sources":["function.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\nimport { replaceName } from './replaceName';\n\nexport const functionNamesTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const updateTypeReference: ts.Visitor = (node) => {\n if (ts.isTypeReferenceNode(node)) {\n const typeName = node.typeName.getText();\n const newTypeName = replaceName(typeName, mapping);\n if (newTypeName) {\n return ts.factory.updateTypeReferenceNode(node, ts.factory.createIdentifier(newTypeName), node.typeArguments);\n }\n }\n return ts.visitEachChild(node, updateTypeReference, context);\n };\n\n const visit: ts.Visitor = (node) => {\n if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n const functionName = node.name?.getText() ?? '';\n const newName = Object.entries(mapping).find(([key]) => functionName.includes(key))?.[1] ?? functionName;\n const parameters = node.parameters.map((param) => {\n const newParamType = param.type ? ts.visitNode(param.type, updateTypeReference) : param.type;\n if (ts.isIdentifier(param.name)) {\n const oldName = param.name.getText();\n const newParamName = Object.keys(mapping).find((key) => oldName.includes(key));\n if (newParamName) {\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n ts.factory.createIdentifier(newParamName),\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n } else if (ts.isObjectBindingPattern(param.name)) {\n const elements = param.name.elements.map((element) => {\n const newElementName = mapping[element.name.getText()];\n if (newElementName) {\n return ts.factory.updateBindingElement(\n element,\n element.dotDotDotToken,\n element.propertyName,\n ts.factory.createIdentifier(newElementName),\n element.initializer\n );\n }\n return element;\n });\n const newParamName = ts.factory.createObjectBindingPattern(elements);\n return ts.factory.updateParameterDeclaration(\n param,\n param.decorators,\n param.modifiers,\n param.dotDotDotToken,\n newParamName,\n param.questionToken,\n newParamType,\n param.initializer\n );\n }\n return param;\n });\n\n if (ts.isFunctionDeclaration(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n if (ts.isArrowFunction(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateArrowFunction(\n node,\n node.modifiers,\n node.typeParameters,\n parameters,\n node.type,\n node.equalsGreaterThanToken,\n updatedBody\n );\n }\n if (ts.isFunctionExpression(node)) {\n const updatedBody = node.body && ts.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;\n return ts.factory.updateFunctionExpression(\n node,\n node.modifiers,\n node.asteriskToken,\n newName ? ts.factory.createIdentifier(newName) : node.name,\n node.typeParameters,\n parameters,\n node.type,\n updatedBody\n );\n }\n }\n return ts.visitEachChild(node, visit, context);\n };\n\n function updateReturnStatement(body: ts.ConciseBody): ts.Block {\n if (ts.isBlock(body)) {\n const updatedStatements: ts.Statement[] = [];\n for (const statement of body.statements) {\n if (ts.isReturnStatement(statement) && statement.expression && ts.isJsxElement(statement.expression)) {\n const jsxElement = statement.expression;\n const openingElement = jsxElement.openingElement;\n const tagName = openingElement.tagName.getText();\n const newTagName = mapping[tagName];\n if (newTagName) {\n const updatedTagName = ts.factory.createIdentifier(newTagName);\n const updatedOpeningElement = ts.factory.updateJsxOpeningElement(\n openingElement,\n updatedTagName,\n openingElement.typeArguments,\n openingElement.attributes\n );\n const updatedClosingElement = jsxElement.closingElement\n ? ts.factory.updateJsxClosingElement(jsxElement.closingElement, updatedTagName)\n : ts.factory.createJsxClosingElement(updatedTagName);\n const updatedJsxElement = ts.factory.createJsxElement(\n updatedOpeningElement,\n jsxElement.children,\n updatedClosingElement\n );\n const updatedStatement = ts.factory.createReturnStatement(updatedJsxElement);\n updatedStatements.push(updatedStatement);\n } else {\n updatedStatements.push(statement);\n }\n } else {\n updatedStatements.push(statement);\n }\n }\n return ts.factory.updateBlock(body, updatedStatements);\n }\n if (\n ts.isExpressionStatement(body) &&\n ts.isReturnStatement(body.expression) &&\n body.expression.expression &&\n ts.isIdentifier(body.expression.expression)\n ) {\n const oldName = body.expression.expression.text;\n const newName = mapping[oldName];\n if (newName) {\n const updatedExpression = ts.factory.createIdentifier(newName);\n const updatedReturnStatement = ts.factory.createReturnStatement(updatedExpression);\n return ts.factory.createBlock([updatedReturnStatement], true);\n }\n }\n return ts.factory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AAA,GAAAA,wBAAA"}
@@ -9,3 +9,4 @@ export { importTransformer } from './import';
9
9
  export { expressionStatementTransformer } from './expression-statement';
10
10
  export { exportTransformer } from './export';
11
11
  export { transformSourceFile } from './transform';
12
+ export { typeReferenceTransformer } from './type-reference';
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "typeAliasNamesTransformer", {
51
51
  return _typeAlias().typeAliasNamesTransformer;
52
52
  }
53
53
  });
54
+ Object.defineProperty(exports, "typeReferenceTransformer", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _typeReference().typeReferenceTransformer;
58
+ }
59
+ });
54
60
  Object.defineProperty(exports, "variableNamesTransformer", {
55
61
  enumerable: true,
56
62
  get: function () {
@@ -120,5 +126,12 @@ function _transform() {
120
126
  };
121
127
  return data;
122
128
  }
129
+ function _typeReference() {
130
+ const data = require("./type-reference");
131
+ _typeReference = function () {
132
+ return data;
133
+ };
134
+ return data;
135
+ }
123
136
 
124
137
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_class","data","require","_interface","_variable","_function","_typeAlias","_import","_expressionStatement","_export","_transform"],"sources":["index.ts"],"sourcesContent":["import ts from 'typescript';\n\nexport type SourceFileTransformer = (mapping: Record<string, string>) => ts.TransformerFactory<ts.SourceFile>;\n\nexport { classNamesTransformer } from './class';\nexport { interfaceNamesTransformer } from './interface';\nexport { variableNamesTransformer } from './variable';\nexport { functionNamesTransformer } from './function';\nexport { typeAliasNamesTransformer } from './typeAlias';\nexport { importTransformer } from './import';\nexport { expressionStatementTransformer } from './expression-statement';\nexport { exportTransformer } from './export';\nexport { transformSourceFile } from './transform';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,WAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,UAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,SAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,WAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,UAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,QAAA;EAAA,MAAAN,IAAA,GAAAC,OAAA;EAAAK,OAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,qBAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,oBAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,QAAA;EAAA,MAAAR,IAAA,GAAAC,OAAA;EAAAO,OAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAS,WAAA;EAAA,MAAAT,IAAA,GAAAC,OAAA;EAAAQ,UAAA,YAAAA,CAAA;IAAA,OAAAT,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA"}
1
+ {"version":3,"names":["_class","data","require","_interface","_variable","_function","_typeAlias","_import","_expressionStatement","_export","_transform","_typeReference"],"sources":["index.ts"],"sourcesContent":["import ts from 'typescript';\n\nexport type SourceFileTransformer = (mapping: Record<string, string>) => ts.TransformerFactory<ts.SourceFile>;\n\nexport { classNamesTransformer } from './class';\nexport { interfaceNamesTransformer } from './interface';\nexport { variableNamesTransformer } from './variable';\nexport { functionNamesTransformer } from './function';\nexport { typeAliasNamesTransformer } from './typeAlias';\nexport { importTransformer } from './import';\nexport { expressionStatementTransformer } from './expression-statement';\nexport { exportTransformer } from './export';\nexport { transformSourceFile } from './transform';\nexport { typeReferenceTransformer } from './type-reference';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,WAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,UAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,SAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,WAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,UAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,QAAA;EAAA,MAAAN,IAAA,GAAAC,OAAA;EAAAK,OAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,qBAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,oBAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,QAAA;EAAA,MAAAR,IAAA,GAAAC,OAAA;EAAAO,OAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAS,WAAA;EAAA,MAAAT,IAAA,GAAAC,OAAA;EAAAQ,UAAA,YAAAA,CAAA;IAAA,OAAAT,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAU,eAAA;EAAA,MAAAV,IAAA,GAAAC,OAAA;EAAAS,cAAA,YAAAA,CAAA;IAAA,OAAAV,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA"}
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- require("core-js/modules/es.regexp.constructor.js");
5
- require("core-js/modules/es.regexp.exec.js");
6
- require("core-js/modules/es.string.replace.js");
7
4
  Object.defineProperty(exports, "__esModule", {
8
5
  value: true
9
6
  });
@@ -15,6 +12,13 @@ function _typescript() {
15
12
  };
16
13
  return data;
17
14
  }
15
+ function _replaceName() {
16
+ const data = require("./replaceName");
17
+ _replaceName = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
18
22
  function interfaceNamesTransformer(nameMapping) {
19
23
  return context => {
20
24
  const {
@@ -23,10 +27,18 @@ function interfaceNamesTransformer(nameMapping) {
23
27
  const visit = node => {
24
28
  if (_typescript().default.isInterfaceDeclaration(node)) {
25
29
  const oldName = node.name.text;
26
- const newName = Object.keys(nameMapping).find(key => oldName.startsWith(key) || oldName.endsWith(key));
30
+ const newName = (0, _replaceName().replaceName)(oldName, nameMapping);
27
31
  if (newName) {
28
- const replacedName = oldName.startsWith(newName) ? oldName.replace(newName, nameMapping[newName]) : oldName.replace(new RegExp(`${newName}$`), nameMapping[newName]);
29
- return factory.updateInterfaceDeclaration(node, node.decorators, node.modifiers, factory.createIdentifier(replacedName), node.typeParameters, node.heritageClauses, node.members);
32
+ const newMembers = node.members.map(member => {
33
+ if (_typescript().default.isPropertySignature(member) && _typescript().default.isIdentifier(member.name)) {
34
+ const memberName = member.name.text;
35
+ if (nameMapping[memberName]) {
36
+ return factory.updatePropertySignature(member, member.modifiers, factory.createIdentifier(nameMapping[memberName]), member.questionToken, member.type);
37
+ }
38
+ }
39
+ return member;
40
+ });
41
+ return factory.updateInterfaceDeclaration(node, node.decorators, node.modifiers, factory.createIdentifier(newName), node.typeParameters, node.heritageClauses, newMembers);
30
42
  }
31
43
  }
32
44
  return _typescript().default.visitEachChild(node, child => visit(child), context);
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","interfaceNamesTransformer","nameMapping","context","factory","visit","node","ts","isInterfaceDeclaration","oldName","name","text","newName","Object","keys","find","key","startsWith","endsWith","replacedName","replace","RegExp","updateInterfaceDeclaration","decorators","modifiers","createIdentifier","typeParameters","heritageClauses","members","visitEachChild","child","visitNode"],"sources":["interface.ts"],"sourcesContent":["import ts from 'typescript';\n\nexport function interfaceNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {\n return (context) => {\n const { factory } = context;\n const visit: ts.Visitor = (node) => {\n if (ts.isInterfaceDeclaration(node)) {\n const oldName = node.name.text;\n const newName = Object.keys(nameMapping).find((key) => oldName.startsWith(key) || oldName.endsWith(key));\n if (newName) {\n const replacedName = oldName.startsWith(newName)\n ? oldName.replace(newName, nameMapping[newName])\n : oldName.replace(new RegExp(`${newName}$`), nameMapping[newName]);\n return factory.updateInterfaceDeclaration(\n node,\n node.decorators,\n node.modifiers,\n factory.createIdentifier(replacedName),\n node.typeParameters,\n node.heritageClauses,\n node.members\n );\n }\n }\n return ts.visitEachChild(node, (child) => visit(child), context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAE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ault","require","_replaceName","interfaceNamesTransformer","nameMapping","context","factory","visit","node","ts","isInterfaceDeclaration","oldName","name","text","newName","replaceName","newMembers","members","map","member","isPropertySignature","isIdentifier","memberName","updatePropertySignature","modifiers","createIdentifier","questionToken","type","updateInterfaceDeclaration","decorators","typeParameters","heritageClauses","visitEachChild","child","visitNode"],"sources":["interface.ts"],"sourcesContent":["import ts from 'typescript';\nimport { replaceName } from './replaceName';\n\nexport function interfaceNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {\n return (context) => {\n const { factory } = context;\n const visit: ts.Visitor = (node) => {\n if (ts.isInterfaceDeclaration(node)) {\n const oldName = node.name.text;\n const newName = replaceName(oldName, nameMapping);\n if (newName) {\n const newMembers = node.members.map((member) => {\n if (ts.isPropertySignature(member) && ts.isIdentifier(member.name)) {\n const memberName = member.name.text;\n if (nameMapping[memberName]) {\n return factory.updatePropertySignature(\n member,\n member.modifiers,\n factory.createIdentifier(nameMapping[memberName]),\n member.questionToken,\n member.type\n );\n }\n }\n return member;\n });\n return factory.updateInterfaceDeclaration(\n node,\n node.decorators,\n node.modifiers,\n factory.createIdentifier(newName),\n node.typeParameters,\n node.heritageClauses,\n newMembers\n );\n }\n }\n return ts.visitEachChild(node, (child) => visit(child), context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASI,yBAAyBA,CAACC,WAAmC,EAAwC;EACnH,OAAQC,OAAO,IAAK;IAClB,MAAM;MAAEC;IAAQ,CAAC,GAAGD,OAAO;IAC3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C;AACH"}
@@ -0,0 +1 @@
1
+ export declare function replaceName(oldName: string, nameMapping: Record<string, string>): string | undefined;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.array.iterator.js");
4
+ require("core-js/modules/es.regexp.constructor.js");
5
+ require("core-js/modules/es.regexp.exec.js");
6
+ require("core-js/modules/es.string.replace.js");
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.replaceName = replaceName;
11
+ function replaceName(oldName, nameMapping) {
12
+ for (const old of Object.keys(nameMapping)) {
13
+ if (oldName.startsWith(old) || oldName === old) {
14
+ return oldName.replace(new RegExp(`^${old}`), nameMapping[old]);
15
+ }
16
+ if (oldName.endsWith(old)) {
17
+ return oldName.replace(new RegExp(`${old}$`), nameMapping[old]);
18
+ }
19
+ }
20
+ return undefined;
21
+ }
22
+
23
+ //# sourceMappingURL=replaceName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["replaceName","oldName","nameMapping","old","Object","keys","startsWith","replace","RegExp","endsWith","undefined"],"sources":["replaceName.ts"],"sourcesContent":["export function replaceName(oldName: string, nameMapping: Record<string, string>): string | undefined {\n for (const old of Object.keys(nameMapping)) {\n if (oldName.startsWith(old) || oldName === old) {\n return oldName.replace(new RegExp(`^${old}`), nameMapping[old]);\n }\n if (oldName.endsWith(old)) {\n return oldName.replace(new RegExp(`${old}$`), nameMapping[old]);\n }\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;AAAO,SAASA,WAAWA,CAACC,OAAe,EAAEC,WAAmC,EAAsB;EACpG,KAAK,MAAMC,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACH,WAAW,CAAC,EAAE;IAC1C,IAAID,OAAO,CAACK,UAAU,CAACH,GAAG,CAAC,IAAIF,OAAO,KAAKE,GAAG,EAAE;MAC9C,OAAOF,OAAO,CAACM,OAAO,CAAC,IAAIC,MAAM,CAAE,IAAGL,GAAI,EAAC,CAAC,EAAED,WAAW,CAACC,GAAG,CAAC,CAAC;IACjE;IACA,IAAIF,OAAO,CAACQ,QAAQ,CAACN,GAAG,CAAC,EAAE;MACzB,OAAOF,OAAO,CAACM,OAAO,CAAC,IAAIC,MAAM,CAAE,GAAEL,GAAI,GAAE,CAAC,EAAED,WAAW,CAACC,GAAG,CAAC,CAAC;IACjE;EACF;EACA,OAAOO,SAAS;AAClB"}
@@ -59,14 +59,6 @@ async function transformSourceFile(sourceFilePath, sourceFileContent, transforme
59
59
  const sourceFile = _typescript().default.createSourceFile(sourceFilePath, sourceFileContent, _typescript().default.ScriptTarget.Latest, true, _typescript().default.ScriptKind.TSX);
60
60
  const transformedResult = _typescript().default.transform(sourceFile, transformers);
61
61
  const transformedSourceFile = transformedResult.transformed[0];
62
-
63
- // const _identifierTransformer = identifierTransformer(updates || {});
64
-
65
- // const transformedResultWithIdentifiers: ts.TransformationResult<ts.SourceFile> =
66
- // ts.transform<ts.SourceFile>(transformedSourceFile, []);
67
- // const transformedSourceFileWithIdentifiers: ts.SourceFile
68
- // = transformedResultWithIdentifiers.transformed[0] as ts.SourceFile;
69
-
70
62
  const printer = _typescript().default.createPrinter({
71
63
  removeComments: false
72
64
  });
@@ -87,34 +79,4 @@ async function transformSourceFile(sourceFilePath, sourceFileContent, transforme
87
79
  return transformedSourceFileStr;
88
80
  }
89
81
 
90
- // function createMarkingTransformer<T extends ts.Node>(innerTransformer: ts.TransformerFactory<T>)
91
- // : ts.TransformerFactory<T> {
92
- // return context => {
93
- // const innerTransform = innerTransformer(context);
94
-
95
- // return node => {
96
- // const result = innerTransform(node);
97
-
98
- // // Add a custom property to the node to mark it as transformed
99
- // // Note: this relies on TypeScript's internal behavior and may not be stable across versions
100
- // (result as any).__transformed = true;
101
-
102
- // return result;
103
- // };
104
- // };
105
- // }
106
-
107
- // const defaultTransformer: ts.TransformerFactory<ts.SourceFile> = () => {
108
- // const visit: ts.Visitor = node => {
109
- // // If the node has been marked as transformed by a specific transformer, don't transform it
110
- // if ((node as any).__transformed) {
111
- // return node;
112
- // }
113
-
114
- // // Your transformation logic goes here...
115
- // };
116
-
117
- // return node => ts.visitNode(node, visit);
118
- // };
119
-
120
82
  //# sourceMappingURL=transform.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_typescript","data","_interopRequireDefault","require","path","_interopRequireWildcard","_emptyLineEncoder","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","transformSourceFile","sourceFilePath","sourceFileContent","transformers","formatter","updates","ext","extname","compatibleExts","includes","transformed","entries","forEach","oldStr","newStr","oldStringRegex","RegExp","replace","encoder","EmptyLineEncoder","encode","sourceFile","ts","createSourceFile","ScriptTarget","Latest","ScriptKind","TSX","transformedResult","transform","transformedSourceFile","printer","createPrinter","removeComments","transformedSourceFileStr","printFile","decode","emptyLineComment","emptyLineMarker","regex","formattedSourceFileStr","formatSnippet","_unused"],"sources":["transform.ts"],"sourcesContent":["import { Formatter } from '@teambit/formatter';\nimport ts from 'typescript';\nimport * as path from 'path';\nimport { EmptyLineEncoder } from './empty-line-encoder';\n/**\n * Transforms a TypeScript source file using the provided transformer.\n *\n * @param sourceFilePath Path to the TypeScript source file.\n * @param sourceFileContent The content of the source file.\n * @param transformers The transformers to be applied on the source file.\n * @param formatter (Optional) An optional formatter to format the transformed code. If no formatter is provided, the function returns the transformed source file as a string without any formatting.\n * @returns A promise that resolves to the transformed source file as a string.\n */\nexport async function transformSourceFile(\n sourceFilePath: string,\n sourceFileContent: string,\n transformers: ts.TransformerFactory<ts.SourceFile>[],\n formatter?: Formatter,\n updates?: Record<string, string>\n): Promise<string> {\n const ext = path.extname(sourceFilePath);\n const compatibleExts = ['.ts', '.tsx', '.js', '.jsx'];\n if (!compatibleExts.includes(ext)) {\n if (!updates) return sourceFileContent;\n let transformed = sourceFileContent;\n Object.entries(updates).forEach(([oldStr, newStr]) => {\n const oldStringRegex = new RegExp(oldStr, 'g');\n transformed = transformed.replace(oldStringRegex, newStr);\n });\n return transformed;\n }\n\n const encoder = new EmptyLineEncoder();\n sourceFileContent = encoder.encode(sourceFileContent);\n\n const sourceFile = ts.createSourceFile(\n sourceFilePath,\n sourceFileContent,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TSX\n );\n\n const transformedResult: ts.TransformationResult<ts.SourceFile> = ts.transform<ts.SourceFile>(\n sourceFile,\n transformers\n );\n const transformedSourceFile: ts.SourceFile = transformedResult.transformed[0] as ts.SourceFile;\n\n // const _identifierTransformer = identifierTransformer(updates || {});\n\n // const transformedResultWithIdentifiers: ts.TransformationResult<ts.SourceFile> =\n // ts.transform<ts.SourceFile>(transformedSourceFile, []);\n // const transformedSourceFileWithIdentifiers: ts.SourceFile\n // = transformedResultWithIdentifiers.transformed[0] as ts.SourceFile;\n\n const printer: ts.Printer = ts.createPrinter({\n removeComments: false,\n });\n\n let transformedSourceFileStr = printer.printFile(transformedSourceFile);\n transformedSourceFileStr = encoder.decode(transformedSourceFileStr);\n // Remove trailing empty line markers\n const emptyLineComment = `\\\\s*\\\\/\\\\*${encoder.emptyLineMarker}\\\\*\\\\/\\\\s*$`;\n const regex = new RegExp(emptyLineComment, 'g');\n transformedSourceFileStr = transformedSourceFileStr.replace(regex, '');\n\n try {\n const formattedSourceFileStr = await formatter?.formatSnippet(transformedSourceFileStr);\n return formattedSourceFileStr || transformedSourceFileStr;\n } catch {\n // We can ignore if the formatter fails\n // TODO: log the error\n // ignore\n }\n return transformedSourceFileStr;\n}\n\n// function createMarkingTransformer<T extends ts.Node>(innerTransformer: ts.TransformerFactory<T>)\n// : ts.TransformerFactory<T> {\n// return context => {\n// const innerTransform = innerTransformer(context);\n\n// return node => {\n// const result = innerTransform(node);\n\n// // Add a custom property to the node to mark it as transformed\n// // Note: this relies on TypeScript's internal behavior and may not be stable across versions\n// (result as any).__transformed = true;\n\n// return result;\n// };\n// };\n// }\n\n// const defaultTransformer: ts.TransformerFactory<ts.SourceFile> = () => {\n// const visit: ts.Visitor = node => {\n// // If the node has been marked as transformed by a specific transformer, don't transform it\n// if ((node as any).__transformed) {\n// return node;\n// }\n\n// // Your transformation logic goes here...\n// };\n\n// return node => ts.visitNode(node, visit);\n// };\n"],"mappings":";;;;;;;;;;;;AACA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,kBAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,iBAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAwD,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QA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A;AACA;;AAEA;AACA;;AAEA;AACA"}
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","path","_interopRequireWildcard","_emptyLineEncoder","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","transformSourceFile","sourceFilePath","sourceFileContent","transformers","formatter","updates","ext","extname","compatibleExts","includes","transformed","entries","forEach","oldStr","newStr","oldStringRegex","RegExp","replace","encoder","EmptyLineEncoder","encode","sourceFile","ts","createSourceFile","ScriptTarget","Latest","ScriptKind","TSX","transformedResult","transform","transformedSourceFile","printer","createPrinter","removeComments","transformedSourceFileStr","printFile","decode","emptyLineComment","emptyLineMarker","regex","formattedSourceFileStr","formatSnippet","_unused"],"sources":["transform.ts"],"sourcesContent":["import { Formatter } from '@teambit/formatter';\nimport ts from 'typescript';\nimport * as path from 'path';\nimport { EmptyLineEncoder } from './empty-line-encoder';\n/**\n * Transforms a TypeScript source file using the provided transformer.\n *\n * @param sourceFilePath Path to the TypeScript source file.\n * @param sourceFileContent The content of the source file.\n * @param transformers The transformers to be applied on the source file.\n * @param formatter (Optional) An optional formatter to format the transformed code. If no formatter is provided, the function returns the transformed source file as a string without any formatting.\n * @returns A promise that resolves to the transformed source file as a string.\n */\nexport async function transformSourceFile(\n sourceFilePath: string,\n sourceFileContent: string,\n transformers: ts.TransformerFactory<ts.SourceFile>[],\n formatter?: Formatter,\n updates?: Record<string, string>\n): Promise<string> {\n const ext = path.extname(sourceFilePath);\n const compatibleExts = ['.ts', '.tsx', '.js', '.jsx'];\n if (!compatibleExts.includes(ext)) {\n if (!updates) return sourceFileContent;\n let transformed = sourceFileContent;\n Object.entries(updates).forEach(([oldStr, newStr]) => {\n const oldStringRegex = new RegExp(oldStr, 'g');\n transformed = transformed.replace(oldStringRegex, newStr);\n });\n return transformed;\n }\n\n const encoder = new EmptyLineEncoder();\n sourceFileContent = encoder.encode(sourceFileContent);\n\n const sourceFile = ts.createSourceFile(\n sourceFilePath,\n sourceFileContent,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TSX\n );\n\n const transformedResult: ts.TransformationResult<ts.SourceFile> = ts.transform<ts.SourceFile>(\n sourceFile,\n transformers\n );\n const transformedSourceFile: ts.SourceFile = transformedResult.transformed[0] as ts.SourceFile;\n\n const printer: ts.Printer = ts.createPrinter({\n removeComments: false,\n });\n\n let transformedSourceFileStr = printer.printFile(transformedSourceFile);\n transformedSourceFileStr = encoder.decode(transformedSourceFileStr);\n // Remove trailing empty line markers\n const emptyLineComment = `\\\\s*\\\\/\\\\*${encoder.emptyLineMarker}\\\\*\\\\/\\\\s*$`;\n const regex = new RegExp(emptyLineComment, 'g');\n transformedSourceFileStr = transformedSourceFileStr.replace(regex, '');\n\n try {\n const formattedSourceFileStr = await formatter?.formatSnippet(transformedSourceFileStr);\n return formattedSourceFileStr || transformedSourceFileStr;\n } catch {\n // We can ignore if the formatter fails\n // TODO: log the error\n // ignore\n }\n return transformedSourceFileStr;\n}\n"],"mappings":";;;;;;;;;;;;AACA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,kBAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,iBAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAwD,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAA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AAMC,KAAK,GAAG,IAAIvB,MAAM,CAACqB,gBAAgB,EAAE,GAAG,CAAC;EAC/CH,wBAAwB,GAAGA,wBAAwB,CAACjB,OAAO,CAACsB,KAAK,EAAE,EAAE,CAAC;EAEtE,IAAI;IACF,MAAMC,sBAAsB,GAAG,OAAMpC,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEqC,aAAa,CAACP,wBAAwB,CAAC;IACvF,OAAOM,sBAAsB,IAAIN,wBAAwB;EAC3D,CAAC,CAAC,OAAAQ,OAAA,EAAM;IACN;IACA;IACA;EAAA;EAEF,OAAOR,wBAAwB;AACjC"}
@@ -0,0 +1,2 @@
1
+ import ts from 'typescript';
2
+ export declare function typeReferenceTransformer(mapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.typeReferenceTransformer = typeReferenceTransformer;
8
+ function _typescript() {
9
+ const data = _interopRequireDefault(require("typescript"));
10
+ _typescript = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _replaceName() {
16
+ const data = require("./replaceName");
17
+ _replaceName = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
22
+ function typeReferenceTransformer(mapping) {
23
+ return context => {
24
+ const visit = node => {
25
+ if (_typescript().default.isTypeReferenceNode(node)) {
26
+ const oldName = node.typeName.getText();
27
+ const newName = (0, _replaceName().replaceName)(oldName, mapping);
28
+ if (newName) {
29
+ return _typescript().default.factory.updateTypeReferenceNode(node, _typescript().default.factory.createIdentifier(newName), node.typeArguments);
30
+ }
31
+ }
32
+ return _typescript().default.visitEachChild(node, visit, context);
33
+ };
34
+ return node => _typescript().default.visitNode(node, visit);
35
+ };
36
+ }
37
+
38
+ //# sourceMappingURL=type-reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","typeReferenceTransformer","mapping","context","visit","node","ts","isTypeReferenceNode","oldName","typeName","getText","newName","replaceName","factory","updateTypeReferenceNode","createIdentifier","typeArguments","visitEachChild","visitNode"],"sources":["type-reference.ts"],"sourcesContent":["import ts from 'typescript';\nimport { replaceName } from './replaceName';\n\nexport function typeReferenceTransformer(mapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {\n return (context) => {\n const visit: ts.Visitor = (node) => {\n if (ts.isTypeReferenceNode(node)) {\n const oldName = node.typeName.getText();\n const newName = replaceName(oldName, mapping);\n if (newName) {\n return ts.factory.updateTypeReferenceNode(node, ts.factory.createIdentifier(newName), node.typeArguments);\n }\n }\n return ts.visitEachChild(node, visit, context);\n };\n\n return (node) => ts.visitNode(node, visit);\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASI,wBAAwBA,CAACC,OAA+B,EAAwC;EAC9G,OAAQC,OAAO,IAAK;IAClB,MAAMC,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,mBAAmB,CAACF,IAAI,CAAC,EAAE;QAChC,MAAMG,OAAO,GAAGH,IAAI,CAACI,QAAQ,CAACC,OAAO,CAAC,CAAC;QACvC,MAAMC,OAAO,GAAG,IAAAC,0BAAW,EAACJ,OAAO,EAAEN,OAAO,CAAC;QAC7C,IAAIS,OAAO,EAAE;UACX,OAAOL,qBAAE,CAACO,OAAO,CAACC,uBAAuB,CAACT,IAAI,EAAEC,qBAAE,CAACO,OAAO,CAACE,gBAAgB,CAACJ,OAAO,CAAC,EAAEN,IAAI,CAACW,aAAa,CAAC;QAC3G;MACF;MACA,OAAOV,qBAAE,CAACW,cAAc,CAACZ,IAAI,EAAED,KAAK,EAAED,OAAO,CAAC;IAChD,CAAC;IAED,OAAQE,IAAI,IAAKC,qBAAE,CAACY,SAAS,CAACb,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH"}
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- require("core-js/modules/es.regexp.constructor.js");
5
- require("core-js/modules/es.regexp.exec.js");
6
- require("core-js/modules/es.string.replace.js");
7
4
  Object.defineProperty(exports, "__esModule", {
8
5
  value: true
9
6
  });
@@ -15,6 +12,13 @@ function _typescript() {
15
12
  };
16
13
  return data;
17
14
  }
15
+ function _replaceName() {
16
+ const data = require("./replaceName");
17
+ _replaceName = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
18
22
  function typeAliasNamesTransformer(nameMapping) {
19
23
  return context => {
20
24
  const {
@@ -23,10 +27,9 @@ function typeAliasNamesTransformer(nameMapping) {
23
27
  const visit = node => {
24
28
  if (_typescript().default.isTypeAliasDeclaration(node)) {
25
29
  const oldName = node.name.text;
26
- const newName = Object.keys(nameMapping).find(key => oldName.startsWith(key) || oldName.endsWith(key));
30
+ const newName = (0, _replaceName().replaceName)(oldName, nameMapping);
27
31
  if (newName) {
28
- const replacedName = oldName.startsWith(newName) ? oldName.replace(newName, nameMapping[newName]) : oldName.replace(new RegExp(`${newName}$`), nameMapping[newName]);
29
- return factory.updateTypeAliasDeclaration(node, node.decorators, node.modifiers, factory.createIdentifier(replacedName), node.typeParameters, node.type);
32
+ return factory.updateTypeAliasDeclaration(node, node.decorators, node.modifiers, factory.createIdentifier(newName), node.typeParameters, node.type);
30
33
  }
31
34
  }
32
35
  return _typescript().default.visitEachChild(node, child => visit(child), context);