@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.
- package/dist/{preview-1690366266887.js → preview-1690443565721.js} +2 -2
- package/dist/sourceFileTransformers/class.js +26 -7
- package/dist/sourceFileTransformers/class.js.map +1 -1
- package/dist/sourceFileTransformers/expression-statement.js +26 -5
- package/dist/sourceFileTransformers/expression-statement.js.map +1 -1
- package/dist/sourceFileTransformers/function.js +8 -1
- package/dist/sourceFileTransformers/function.js.map +1 -1
- package/dist/sourceFileTransformers/index.d.ts +1 -0
- package/dist/sourceFileTransformers/index.js +13 -0
- package/dist/sourceFileTransformers/index.js.map +1 -1
- package/dist/sourceFileTransformers/interface.js +18 -6
- package/dist/sourceFileTransformers/interface.js.map +1 -1
- package/dist/sourceFileTransformers/replaceName.d.ts +1 -0
- package/dist/sourceFileTransformers/replaceName.js +23 -0
- package/dist/sourceFileTransformers/replaceName.js.map +1 -0
- package/dist/sourceFileTransformers/transform.js +0 -38
- package/dist/sourceFileTransformers/transform.js.map +1 -1
- package/dist/sourceFileTransformers/type-reference.d.ts +2 -0
- package/dist/sourceFileTransformers/type-reference.js +38 -0
- package/dist/sourceFileTransformers/type-reference.js.map +1 -0
- package/dist/sourceFileTransformers/typeAlias.js +9 -6
- package/dist/sourceFileTransformers/typeAlias.js.map +1 -1
- package/dist/sourceFileTransformers/variable.js +9 -6
- package/dist/sourceFileTransformers/variable.js.map +1 -1
- package/dist/transform-source-file.spec.js +31 -12
- package/dist/transform-source-file.spec.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.1119.tgz +0 -0
- package/package.json +18 -18
- package/sourceFileTransformers/class.ts +55 -7
- package/sourceFileTransformers/expression-statement.ts +22 -15
- package/sourceFileTransformers/function.ts +2 -1
- package/sourceFileTransformers/index.ts +1 -0
- package/sourceFileTransformers/interface.ts +19 -6
- package/sourceFileTransformers/replaceName.ts +11 -0
- package/sourceFileTransformers/transform.ts +0 -37
- package/sourceFileTransformers/type-reference.ts +19 -0
- package/sourceFileTransformers/typeAlias.ts +3 -5
- package/sourceFileTransformers/variable.ts +3 -6
- package/package-tar/teambit-typescript-0.0.1118.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","typeAliasNamesTransformer","nameMapping","context","factory","visit","node","ts","isTypeAliasDeclaration","oldName","name","text","newName","
|
|
1
|
+
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","typeAliasNamesTransformer","nameMapping","context","factory","visit","node","ts","isTypeAliasDeclaration","oldName","name","text","newName","replaceName","updateTypeAliasDeclaration","decorators","modifiers","createIdentifier","typeParameters","type","visitEachChild","child","visitNode"],"sources":["typeAlias.ts"],"sourcesContent":["import ts from 'typescript';\nimport { replaceName } from './replaceName';\n\nexport function typeAliasNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {\n return (context) => {\n const { factory } = context;\n const visit: ts.Visitor = (node) => {\n if (ts.isTypeAliasDeclaration(node)) {\n const oldName = node.name.text;\n const newName = replaceName(oldName, nameMapping);\n if (newName) {\n return factory.updateTypeAliasDeclaration(\n node,\n node.decorators,\n node.modifiers,\n factory.createIdentifier(newName),\n node.typeParameters,\n node.type\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;IAC3B,MAAME,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,sBAAsB,CAACF,IAAI,CAAC,EAAE;QACnC,MAAMG,OAAO,GAAGH,IAAI,CAACI,IAAI,CAACC,IAAI;QAC9B,MAAMC,OAAO,GAAG,IAAAC,0BAAW,EAACJ,OAAO,EAAEP,WAAW,CAAC;QACjD,IAAIU,OAAO,EAAE;UACX,OAAOR,OAAO,CAACU,0BAA0B,CACvCR,IAAI,EACJA,IAAI,CAACS,UAAU,EACfT,IAAI,CAACU,SAAS,EACdZ,OAAO,CAACa,gBAAgB,CAACL,OAAO,CAAC,EACjCN,IAAI,CAACY,cAAc,EACnBZ,IAAI,CAACa,IACP,CAAC;QACH;MACF;MACA,OAAOZ,qBAAE,CAACa,cAAc,CAACd,IAAI,EAAGe,KAAK,IAAKhB,KAAK,CAACgB,KAAK,CAAC,EAAElB,OAAO,CAAC;IAClE,CAAC;IACD,OAAQG,IAAI,IAAKC,qBAAE,CAACe,SAAS,CAAChB,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 variableNamesTransformer(nameMapping) {
|
|
19
23
|
return context => {
|
|
20
24
|
const {
|
|
@@ -23,10 +27,9 @@ function variableNamesTransformer(nameMapping) {
|
|
|
23
27
|
const visit = node => {
|
|
24
28
|
if (_typescript().default.isVariableDeclaration(node) && node.name.kind === _typescript().default.SyntaxKind.Identifier) {
|
|
25
29
|
const oldName = node.name.text;
|
|
26
|
-
const newName =
|
|
30
|
+
const newName = (0, _replaceName().replaceName)(oldName, nameMapping);
|
|
27
31
|
if (newName) {
|
|
28
|
-
|
|
29
|
-
return factory.updateVariableDeclaration(node, factory.createIdentifier(replacedName), node.exclamationToken, node.type, node.initializer);
|
|
32
|
+
return factory.updateVariableDeclaration(node, factory.createIdentifier(newName), node.exclamationToken, node.type, node.initializer);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
return _typescript().default.visitEachChild(node, child => visit(child), context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","variableNamesTransformer","nameMapping","context","factory","visit","node","ts","isVariableDeclaration","name","kind","SyntaxKind","Identifier","oldName","text","newName","
|
|
1
|
+
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","_replaceName","variableNamesTransformer","nameMapping","context","factory","visit","node","ts","isVariableDeclaration","name","kind","SyntaxKind","Identifier","oldName","text","newName","replaceName","updateVariableDeclaration","createIdentifier","exclamationToken","type","initializer","visitEachChild","child","visitNode"],"sources":["variable.ts"],"sourcesContent":["import ts from 'typescript';\nimport { replaceName } from './replaceName';\n\nexport function variableNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {\n return (context) => {\n const { factory } = context;\n const visit: ts.Visitor = (node) => {\n if (ts.isVariableDeclaration(node) && node.name.kind === ts.SyntaxKind.Identifier) {\n const oldName = node.name.text;\n const newName = replaceName(oldName, nameMapping);\n if (newName) {\n return factory.updateVariableDeclaration(\n node,\n factory.createIdentifier(newName),\n node.exclamationToken,\n node.type,\n node.initializer\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,wBAAwBA,CAACC,WAAmC,EAAwC;EAClH,OAAQC,OAAO,IAAK;IAClB,MAAM;MAAEC;IAAQ,CAAC,GAAGD,OAAO;IAC3B,MAAME,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,qBAAqB,CAACF,IAAI,CAAC,IAAIA,IAAI,CAACG,IAAI,CAACC,IAAI,KAAKH,qBAAE,CAACI,UAAU,CAACC,UAAU,EAAE;QACjF,MAAMC,OAAO,GAAGP,IAAI,CAACG,IAAI,CAACK,IAAI;QAC9B,MAAMC,OAAO,GAAG,IAAAC,0BAAW,EAACH,OAAO,EAAEX,WAAW,CAAC;QACjD,IAAIa,OAAO,EAAE;UACX,OAAOX,OAAO,CAACa,yBAAyB,CACtCX,IAAI,EACJF,OAAO,CAACc,gBAAgB,CAACH,OAAO,CAAC,EACjCT,IAAI,CAACa,gBAAgB,EACrBb,IAAI,CAACc,IAAI,EACTd,IAAI,CAACe,WACP,CAAC;QACH;MACF;MACA,OAAOd,qBAAE,CAACe,cAAc,CAAChB,IAAI,EAAGiB,KAAK,IAAKlB,KAAK,CAACkB,KAAK,CAAC,EAAEpB,OAAO,CAAC;IAClE,CAAC;IACD,OAAQG,IAAI,IAAKC,qBAAE,CAACiB,SAAS,CAAClB,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH"}
|
|
@@ -77,26 +77,45 @@ describe('transformSourceFile', () => {
|
|
|
77
77
|
},
|
|
78
78
|
expectedCode: 'let newVariableName = "test";'
|
|
79
79
|
}, {
|
|
80
|
-
transformer: _sourceFileTransformers().
|
|
81
|
-
sourceCode: '
|
|
80
|
+
transformer: _sourceFileTransformers().classNamesTransformer,
|
|
81
|
+
sourceCode: 'class TestClass { oldMethod() {} }',
|
|
82
82
|
nameMapping: {
|
|
83
|
-
|
|
83
|
+
TestClass: 'NewClassName',
|
|
84
|
+
oldMethod: 'newMethodName'
|
|
84
85
|
},
|
|
85
|
-
expectedCode: '
|
|
86
|
+
expectedCode: 'class NewClassName { newMethodName() {} }'
|
|
86
87
|
}, {
|
|
87
|
-
transformer: _sourceFileTransformers().
|
|
88
|
-
sourceCode: '
|
|
88
|
+
transformer: _sourceFileTransformers().classNamesTransformer,
|
|
89
|
+
sourceCode: 'class TestClass { oldMember: string; }',
|
|
89
90
|
nameMapping: {
|
|
90
|
-
|
|
91
|
+
TestClass: 'NewClassName',
|
|
92
|
+
oldMember: 'newMember'
|
|
91
93
|
},
|
|
92
|
-
expectedCode: '
|
|
94
|
+
expectedCode: 'class NewClassName { newMember: string; }'
|
|
93
95
|
}, {
|
|
94
|
-
transformer: _sourceFileTransformers().
|
|
95
|
-
sourceCode: '
|
|
96
|
+
transformer: _sourceFileTransformers().expressionStatementTransformer,
|
|
97
|
+
sourceCode: 'TestClass.staticMethod();',
|
|
96
98
|
nameMapping: {
|
|
97
|
-
|
|
99
|
+
TestClass: 'NewClassName',
|
|
100
|
+
staticMethod: 'newMethodName'
|
|
101
|
+
},
|
|
102
|
+
expectedCode: 'NewClassName.newMethodName();'
|
|
103
|
+
}, {
|
|
104
|
+
transformer: _sourceFileTransformers().expressionStatementTransformer,
|
|
105
|
+
sourceCode: 'let instance = new TestClass(); instance.method();',
|
|
106
|
+
nameMapping: {
|
|
107
|
+
TestClass: 'NewClassName',
|
|
108
|
+
method: 'newMethodName'
|
|
109
|
+
},
|
|
110
|
+
expectedCode: 'let instance = new NewClassName(); instance.newMethodName();'
|
|
111
|
+
}, {
|
|
112
|
+
transformer: _sourceFileTransformers().interfaceNamesTransformer,
|
|
113
|
+
sourceCode: 'interface TestInterface { oldMember: string; }',
|
|
114
|
+
nameMapping: {
|
|
115
|
+
TestInterface: 'NewInterfaceName',
|
|
116
|
+
oldMember: 'newMember'
|
|
98
117
|
},
|
|
99
|
-
expectedCode: '
|
|
118
|
+
expectedCode: 'interface NewInterfaceName { newMember: string; }'
|
|
100
119
|
}, {
|
|
101
120
|
transformer: _sourceFileTransformers().importTransformer,
|
|
102
121
|
sourceCode: 'const UI = require("@xxx/ui-library");',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","_sourceFileTransformers","normalizeFormatting","code","sourceFile","ts","createSourceFile","ScriptTarget","Latest","printer","createPrinter","newLine","NewLineKind","LineFeed","removeComments","printFile","describe","createTransformerTest","sourceCode","nameMapping","transformer","expectedCode","it","name","result","transformSourceFile","normalizedResult","normalizedExpectedCode","expect","toBe","testCases","classNamesTransformer","TestClass","functionNamesTransformer","testFunction","importTransformer","interfaceNamesTransformer","TestInterface","typeAliasNamesTransformer","TestType","variableNamesTransformer","testVariable","exportTransformer","normalizedSourceCode"],"sources":["transform-source-file.spec.ts"],"sourcesContent":["import ts from 'typescript';\nimport {\n transformSourceFile,\n classNamesTransformer,\n functionNamesTransformer,\n importTransformer,\n interfaceNamesTransformer,\n typeAliasNamesTransformer,\n variableNamesTransformer,\n exportTransformer,\n} from './sourceFileTransformers';\n\nfunction normalizeFormatting(code: string): string {\n const sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true);\n const printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n });\n return printer.printFile(sourceFile);\n}\n\ndescribe('transformSourceFile', () => {\n const createTransformerTest = (\n sourceCode: string,\n nameMapping: any,\n transformer: (nameMapping: any) => ts.TransformerFactory<ts.SourceFile>,\n expectedCode: string\n ) => {\n it(`should correctly transform source code with ${transformer.name}`, async () => {\n const result = await transformSourceFile('test.ts', sourceCode, [transformer(nameMapping)]);\n const normalizedResult = normalizeFormatting(result);\n const normalizedExpectedCode = normalizeFormatting(expectedCode);\n\n expect(normalizedResult).toBe(normalizedExpectedCode);\n });\n };\n\n const testCases = [\n {\n transformer: classNamesTransformer,\n sourceCode: 'class TestClass {}',\n nameMapping: { TestClass: 'NewClassName' },\n expectedCode: 'class NewClassName {}',\n },\n {\n transformer: functionNamesTransformer,\n sourceCode: 'function testFunction() {}',\n nameMapping: { testFunction: 'newFunctionName' },\n expectedCode: 'function newFunctionName() {}',\n },\n {\n transformer: importTransformer,\n sourceCode: 'import { Test } from \"./test\";',\n nameMapping: { './test': './newTest' },\n expectedCode: 'import { Test } from \"./newTest\";',\n },\n {\n transformer: interfaceNamesTransformer,\n sourceCode: 'interface TestInterface {}',\n nameMapping: { TestInterface: 'NewInterfaceName' },\n expectedCode: 'interface NewInterfaceName {}',\n },\n {\n transformer: typeAliasNamesTransformer,\n sourceCode: 'type TestType = string;',\n nameMapping: { TestType: 'NewTypeName' },\n expectedCode: 'type NewTypeName = string;',\n },\n {\n transformer: variableNamesTransformer,\n sourceCode: 'let testVariable = \"test\";',\n nameMapping: { testVariable: 'newVariableName' },\n expectedCode: 'let newVariableName = \"test\";',\n },\n {\n transformer: importTransformer,\n sourceCode: 'import { Component } from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'import { Component } from \"@abc/ui-library\";',\n },\n {\n transformer: importTransformer,\n sourceCode: 'import * as UI from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'import * as UI from \"@abc/ui-library\";',\n },\n {\n transformer: importTransformer,\n sourceCode: 'import UI from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'import UI from \"@abc/ui-library\";',\n },\n {\n transformer: importTransformer,\n sourceCode: 'const UI = require(\"@xxx/ui-library\");',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'const UI = require(\"@abc/ui-library\");',\n },\n {\n transformer: exportTransformer,\n sourceCode: 'export { Component } from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'export { Component } from \"@abc/ui-library\";',\n },\n {\n transformer: exportTransformer,\n sourceCode: 'export * from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'export * from \"@abc/ui-library\";',\n },\n {\n transformer: exportTransformer,\n sourceCode: 'export { default as UI } from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'export { default as UI } from \"@abc/ui-library\";',\n },\n ];\n\n for (const { transformer, sourceCode, nameMapping, expectedCode } of testCases) {\n createTransformerTest(sourceCode, nameMapping, transformer, expectedCode);\n }\n\n it('should return original source code if no transformations are applied', async () => {\n const sourceCode = 'class TestClass {} function testFunction() {}';\n const result = await transformSourceFile('test.ts', sourceCode, []);\n const normalizedResult = normalizeFormatting(result);\n const normalizedSourceCode = normalizeFormatting(sourceCode);\n expect(normalizedResult).toBe(normalizedSourceCode);\n });\n\n it('should handle multiple transformers', async () => {\n const sourceCode = 'class TestClass {} function testFunction() {}';\n const expectedCode = 'class NewClassName {} function newFunctionName() {}';\n const result = await transformSourceFile('test.ts', sourceCode, [\n classNamesTransformer({ TestClass: 'NewClassName' }),\n functionNamesTransformer({ testFunction: 'newFunctionName' }),\n ]);\n const normalizedResult = normalizeFormatting(result);\n const normalizedExpectedCode = normalizeFormatting(expectedCode);\n expect(normalizedResult).toBe(normalizedExpectedCode);\n });\n});\n"],"mappings":";;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,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,EAAC,SAAS,EAAEP,UAAU,EAAE,CAC9D,IAAAa,+CAAqB,EAAC;MAAEC,SAAS,EAAE;IAAe,CAAC,CAAC,EACpD,IAAAC,kDAAwB,EAAC;MAAEC,YAAY,EAAE;IAAkB,CAAC,CAAC,CAC9D,CAAC;IACF,MAAMR,gBAAgB,GAAGxB,mBAAmB,CAACsB,MAAM,CAAC;IACpD,MAAMG,sBAAsB,GAAGzB,mBAAmB,CAACmB,YAAY,CAAC;IAChEO,MAAM,CAACF,gBAAgB,CAAC,CAACG,IAAI,CAACF,sBAAsB,CAAC;EACvD,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","_sourceFileTransformers","normalizeFormatting","code","sourceFile","ts","createSourceFile","ScriptTarget","Latest","printer","createPrinter","newLine","NewLineKind","LineFeed","removeComments","printFile","describe","createTransformerTest","sourceCode","nameMapping","transformer","expectedCode","it","name","result","transformSourceFile","normalizedResult","normalizedExpectedCode","expect","toBe","testCases","classNamesTransformer","TestClass","functionNamesTransformer","testFunction","importTransformer","interfaceNamesTransformer","TestInterface","typeAliasNamesTransformer","TestType","variableNamesTransformer","testVariable","oldMethod","oldMember","expressionStatementTransformer","staticMethod","method","exportTransformer","normalizedSourceCode"],"sources":["transform-source-file.spec.ts"],"sourcesContent":["import ts from 'typescript';\nimport {\n transformSourceFile,\n classNamesTransformer,\n functionNamesTransformer,\n importTransformer,\n interfaceNamesTransformer,\n typeAliasNamesTransformer,\n variableNamesTransformer,\n expressionStatementTransformer,\n exportTransformer,\n} from './sourceFileTransformers';\n\nfunction normalizeFormatting(code: string): string {\n const sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true);\n const printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n });\n return printer.printFile(sourceFile);\n}\n\ndescribe('transformSourceFile', () => {\n const createTransformerTest = (\n sourceCode: string,\n nameMapping: any,\n transformer: (nameMapping: any) => ts.TransformerFactory<ts.SourceFile>,\n expectedCode: string\n ) => {\n it(`should correctly transform source code with ${transformer.name}`, async () => {\n const result = await transformSourceFile('test.ts', sourceCode, [transformer(nameMapping)]);\n const normalizedResult = normalizeFormatting(result);\n const normalizedExpectedCode = normalizeFormatting(expectedCode);\n\n expect(normalizedResult).toBe(normalizedExpectedCode);\n });\n };\n\n const testCases = [\n {\n transformer: classNamesTransformer,\n sourceCode: 'class TestClass {}',\n nameMapping: { TestClass: 'NewClassName' },\n expectedCode: 'class NewClassName {}',\n },\n {\n transformer: functionNamesTransformer,\n sourceCode: 'function testFunction() {}',\n nameMapping: { testFunction: 'newFunctionName' },\n expectedCode: 'function newFunctionName() {}',\n },\n {\n transformer: importTransformer,\n sourceCode: 'import { Test } from \"./test\";',\n nameMapping: { './test': './newTest' },\n expectedCode: 'import { Test } from \"./newTest\";',\n },\n {\n transformer: interfaceNamesTransformer,\n sourceCode: 'interface TestInterface {}',\n nameMapping: { TestInterface: 'NewInterfaceName' },\n expectedCode: 'interface NewInterfaceName {}',\n },\n {\n transformer: typeAliasNamesTransformer,\n sourceCode: 'type TestType = string;',\n nameMapping: { TestType: 'NewTypeName' },\n expectedCode: 'type NewTypeName = string;',\n },\n {\n transformer: variableNamesTransformer,\n sourceCode: 'let testVariable = \"test\";',\n nameMapping: { testVariable: 'newVariableName' },\n expectedCode: 'let newVariableName = \"test\";',\n },\n {\n transformer: classNamesTransformer,\n sourceCode: 'class TestClass { oldMethod() {} }',\n nameMapping: { TestClass: 'NewClassName', oldMethod: 'newMethodName' },\n expectedCode: 'class NewClassName { newMethodName() {} }',\n },\n {\n transformer: classNamesTransformer,\n sourceCode: 'class TestClass { oldMember: string; }',\n nameMapping: { TestClass: 'NewClassName', oldMember: 'newMember' },\n expectedCode: 'class NewClassName { newMember: string; }',\n },\n {\n transformer: expressionStatementTransformer,\n sourceCode: 'TestClass.staticMethod();',\n nameMapping: { TestClass: 'NewClassName', staticMethod: 'newMethodName' },\n expectedCode: 'NewClassName.newMethodName();',\n },\n {\n transformer: expressionStatementTransformer,\n sourceCode: 'let instance = new TestClass(); instance.method();',\n nameMapping: { TestClass: 'NewClassName', method: 'newMethodName' },\n expectedCode: 'let instance = new NewClassName(); instance.newMethodName();',\n },\n {\n transformer: interfaceNamesTransformer,\n sourceCode: 'interface TestInterface { oldMember: string; }',\n nameMapping: { TestInterface: 'NewInterfaceName', oldMember: 'newMember' },\n expectedCode: 'interface NewInterfaceName { newMember: string; }',\n },\n {\n transformer: importTransformer,\n sourceCode: 'const UI = require(\"@xxx/ui-library\");',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'const UI = require(\"@abc/ui-library\");',\n },\n {\n transformer: exportTransformer,\n sourceCode: 'export { Component } from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'export { Component } from \"@abc/ui-library\";',\n },\n {\n transformer: exportTransformer,\n sourceCode: 'export * from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'export * from \"@abc/ui-library\";',\n },\n {\n transformer: exportTransformer,\n sourceCode: 'export { default as UI } from \"@xxx/ui-library\";',\n nameMapping: { '@xxx/ui-library': '@abc/ui-library' },\n expectedCode: 'export { default as UI } from \"@abc/ui-library\";',\n },\n ];\n\n for (const { transformer, sourceCode, nameMapping, expectedCode } of testCases) {\n createTransformerTest(sourceCode, nameMapping, transformer, expectedCode);\n }\n\n it('should return original source code if no transformations are applied', async () => {\n const sourceCode = 'class TestClass {} function testFunction() {}';\n const result = await transformSourceFile('test.ts', sourceCode, []);\n const normalizedResult = normalizeFormatting(result);\n const normalizedSourceCode = normalizeFormatting(sourceCode);\n expect(normalizedResult).toBe(normalizedSourceCode);\n });\n\n it('should handle multiple transformers', async () => {\n const sourceCode = 'class TestClass {} function testFunction() {}';\n const expectedCode = 'class NewClassName {} function newFunctionName() {}';\n const result = await transformSourceFile('test.ts', sourceCode, [\n classNamesTransformer({ TestClass: 'NewClassName' }),\n functionNamesTransformer({ testFunction: 'newFunctionName' }),\n ]);\n const normalizedResult = normalizeFormatting(result);\n const normalizedExpectedCode = normalizeFormatting(expectedCode);\n expect(normalizedResult).toBe(normalizedExpectedCode);\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,wBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,uBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAYA,SAASI,mBAAmBA,CAACC,IAAY,EAAU;EACjD,MAAMC,UAAU,GAAGC,qBAAE,CAACC,gBAAgB,CAAC,SAAS,EAAEH,IAAI,EAAEE,qBAAE,CAACE,YAAY,CAACC,MAAM,EAAE,IAAI,CAAC;EACrF,MAAMC,OAAO,GAAGJ,qBAAE,CAACK,aAAa,CAAC;IAC/BC,OAAO,EAAEN,qBAAE,CAACO,WAAW,CAACC,QAAQ;IAChCC,cAAc,EAAE;EAClB,CAAC,CAAC;EACF,OAAOL,OAAO,CAACM,SAAS,CAACX,UAAU,CAAC;AACtC;AAEAY,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpC,MAAMC,qBAAqB,GAAGA,CAC5BC,UAAkB,EAClBC,WAAgB,EAChBC,WAAuE,EACvEC,YAAoB,KACjB;IACHC,EAAE,CAAE,+CAA8CF,WAAW,CAACG,IAAK,EAAC,EAAE,YAAY;MAChF,MAAMC,MAAM,GAAG,MAAM,IAAAC,6CAAmB,EAAC,SAAS,EAAEP,UAAU,EAAE,CAACE,WAAW,CAACD,WAAW,CAAC,CAAC,CAAC;MAC3F,MAAMO,gBAAgB,GAAGxB,mBAAmB,CAACsB,MAAM,CAAC;MACpD,MAAMG,sBAAsB,GAAGzB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version": "0.0.1119",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/typescript/typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.typescript",
|
|
8
8
|
"name": "typescript",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.1119"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -20,25 +20,25 @@
|
|
|
20
20
|
"core-js": "^3.0.0",
|
|
21
21
|
"@babel/runtime": "7.20.0",
|
|
22
22
|
"@teambit/harmony": "0.4.6",
|
|
23
|
-
"@teambit/compiler": "0.0.
|
|
23
|
+
"@teambit/compiler": "0.0.1119",
|
|
24
24
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.76",
|
|
25
|
-
"@teambit/builder": "0.0.
|
|
26
|
-
"@teambit/isolator": "0.0.
|
|
27
|
-
"@teambit/component": "0.0.
|
|
28
|
-
"@teambit/dependency-resolver": "0.0.
|
|
29
|
-
"@teambit/formatter": "0.0.
|
|
25
|
+
"@teambit/builder": "0.0.1119",
|
|
26
|
+
"@teambit/isolator": "0.0.1119",
|
|
27
|
+
"@teambit/component": "0.0.1119",
|
|
28
|
+
"@teambit/dependency-resolver": "0.0.1119",
|
|
29
|
+
"@teambit/formatter": "0.0.670",
|
|
30
30
|
"@teambit/semantics.entities.semantic-schema": "0.0.53",
|
|
31
31
|
"@teambit/ts-server": "0.0.48",
|
|
32
|
-
"@teambit/aspect-loader": "0.0.
|
|
33
|
-
"@teambit/envs": "0.0.
|
|
34
|
-
"@teambit/logger": "0.0.
|
|
35
|
-
"@teambit/workspace": "0.0.
|
|
32
|
+
"@teambit/aspect-loader": "0.0.1119",
|
|
33
|
+
"@teambit/envs": "0.0.1119",
|
|
34
|
+
"@teambit/logger": "0.0.843",
|
|
35
|
+
"@teambit/workspace": "0.0.1119",
|
|
36
36
|
"@teambit/bit-error": "0.0.402",
|
|
37
|
-
"@teambit/schema": "0.0.
|
|
38
|
-
"@teambit/scope": "0.0.
|
|
39
|
-
"@teambit/cli": "0.0.
|
|
40
|
-
"@teambit/pkg": "0.0.
|
|
41
|
-
"@teambit/watcher": "0.0.
|
|
37
|
+
"@teambit/schema": "0.0.1119",
|
|
38
|
+
"@teambit/scope": "0.0.1119",
|
|
39
|
+
"@teambit/cli": "0.0.750",
|
|
40
|
+
"@teambit/pkg": "0.0.1119",
|
|
41
|
+
"@teambit/watcher": "0.0.131"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/lodash": "4.14.165",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@teambit/typescript.aspect-docs.typescript": "0.0.154"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@teambit/legacy": "1.0.
|
|
57
|
+
"@teambit/legacy": "1.0.530",
|
|
58
58
|
"react": "^16.8.0 || ^17.0.0",
|
|
59
59
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
60
60
|
},
|
|
@@ -1,28 +1,76 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import { replaceName } from './replaceName';
|
|
2
3
|
|
|
3
4
|
export function classNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {
|
|
4
5
|
return (context) => {
|
|
5
6
|
const { factory } = context;
|
|
7
|
+
|
|
6
8
|
const visit: ts.Visitor = (node) => {
|
|
7
9
|
if (ts.isClassDeclaration(node) && node.name) {
|
|
8
10
|
const oldName = node.name.text;
|
|
9
|
-
const newName =
|
|
11
|
+
const newName = replaceName(oldName, nameMapping);
|
|
12
|
+
|
|
10
13
|
if (newName) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
const updatedMembers = node.members.map((member) => {
|
|
15
|
+
if (ts.isPropertyDeclaration(member)) {
|
|
16
|
+
const oldMemberName = member.name.getText();
|
|
17
|
+
const newMemberName = replaceName(oldMemberName, nameMapping);
|
|
18
|
+
return factory.updatePropertyDeclaration(
|
|
19
|
+
member,
|
|
20
|
+
member.decorators,
|
|
21
|
+
member.modifiers,
|
|
22
|
+
newMemberName ? ts.factory.createIdentifier(newMemberName) : member.name,
|
|
23
|
+
member.questionToken,
|
|
24
|
+
member.type,
|
|
25
|
+
member.initializer
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (ts.isMethodDeclaration(member)) {
|
|
30
|
+
const oldMemberName = member.name.getText();
|
|
31
|
+
const newMemberName = replaceName(oldMemberName, nameMapping);
|
|
32
|
+
|
|
33
|
+
const updatedParameters = member.parameters.map((param) => {
|
|
34
|
+
return ts.factory.updateParameterDeclaration(
|
|
35
|
+
param,
|
|
36
|
+
param.decorators,
|
|
37
|
+
param.modifiers,
|
|
38
|
+
param.dotDotDotToken,
|
|
39
|
+
param.name,
|
|
40
|
+
param.questionToken,
|
|
41
|
+
param.type,
|
|
42
|
+
param.initializer
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return factory.updateMethodDeclaration(
|
|
47
|
+
member,
|
|
48
|
+
member.decorators,
|
|
49
|
+
member.modifiers,
|
|
50
|
+
member.asteriskToken,
|
|
51
|
+
newMemberName ? ts.factory.createIdentifier(newMemberName) : member.name,
|
|
52
|
+
member.questionToken,
|
|
53
|
+
member.typeParameters,
|
|
54
|
+
updatedParameters,
|
|
55
|
+
member.type,
|
|
56
|
+
member.body
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return member;
|
|
60
|
+
});
|
|
61
|
+
|
|
14
62
|
return factory.updateClassDeclaration(
|
|
15
63
|
node,
|
|
16
64
|
node.decorators,
|
|
17
65
|
node.modifiers,
|
|
18
|
-
factory.createIdentifier(
|
|
66
|
+
factory.createIdentifier(newName),
|
|
19
67
|
node.typeParameters,
|
|
20
68
|
node.heritageClauses,
|
|
21
|
-
|
|
69
|
+
updatedMembers
|
|
22
70
|
);
|
|
23
71
|
}
|
|
24
72
|
}
|
|
25
|
-
return ts.visitEachChild(node,
|
|
73
|
+
return ts.visitEachChild(node, visit, context);
|
|
26
74
|
};
|
|
27
75
|
return (node) => ts.visitNode(node, visit);
|
|
28
76
|
};
|
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { SourceFileTransformer } from '.';
|
|
3
|
+
import { replaceName } from './replaceName';
|
|
3
4
|
|
|
4
5
|
export const expressionStatementTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {
|
|
5
6
|
return (context) => {
|
|
7
|
+
const replaceIdentifierText = (identifier: ts.Identifier) => {
|
|
8
|
+
try {
|
|
9
|
+
if (!identifier || !ts.isIdentifier(identifier)) return identifier;
|
|
10
|
+
const oldName = identifier.getText();
|
|
11
|
+
const newName = replaceName(oldName, mapping);
|
|
12
|
+
|
|
13
|
+
if (newName) {
|
|
14
|
+
return ts.factory.createIdentifier(newName);
|
|
15
|
+
}
|
|
16
|
+
return identifier;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return identifier;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
6
22
|
const visit: ts.Visitor = (node) => {
|
|
7
23
|
if (ts.isExpressionStatement(node)) {
|
|
8
24
|
return ts.factory.updateExpressionStatement(node, ts.visitNode(node.expression, visit));
|
|
9
25
|
}
|
|
10
26
|
|
|
11
|
-
if (ts.isCallExpression(node)) {
|
|
12
|
-
return ts.factory.updateCallExpression(
|
|
13
|
-
node,
|
|
14
|
-
ts.visitNode(node.expression, visit),
|
|
15
|
-
node.typeArguments,
|
|
16
|
-
node.arguments.map((arg) => ts.visitNode(arg, visit))
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
27
|
if (ts.isPropertyAccessExpression(node)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
28
|
+
let newName = node.name;
|
|
29
|
+
if (ts.isIdentifier(node.name)) {
|
|
30
|
+
newName = replaceIdentifierText(node.name);
|
|
31
|
+
}
|
|
32
|
+
return ts.factory.updatePropertyAccessExpression(node, ts.visitNode(node.expression, visit), newName);
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
if (ts.isIdentifier(node)) {
|
|
29
|
-
return
|
|
36
|
+
return replaceIdentifierText(node);
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
return ts.visitEachChild(node, visit, context);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { SourceFileTransformer } from '.';
|
|
3
|
+
import { replaceName } from './replaceName';
|
|
3
4
|
|
|
4
5
|
export const functionNamesTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {
|
|
5
6
|
return (context) => {
|
|
6
7
|
const updateTypeReference: ts.Visitor = (node) => {
|
|
7
8
|
if (ts.isTypeReferenceNode(node)) {
|
|
8
9
|
const typeName = node.typeName.getText();
|
|
9
|
-
const newTypeName = mapping
|
|
10
|
+
const newTypeName = replaceName(typeName, mapping);
|
|
10
11
|
if (newTypeName) {
|
|
11
12
|
return ts.factory.updateTypeReferenceNode(node, ts.factory.createIdentifier(newTypeName), node.typeArguments);
|
|
12
13
|
}
|
|
@@ -11,3 +11,4 @@ export { importTransformer } from './import';
|
|
|
11
11
|
export { expressionStatementTransformer } from './expression-statement';
|
|
12
12
|
export { exportTransformer } from './export';
|
|
13
13
|
export { transformSourceFile } from './transform';
|
|
14
|
+
export { typeReferenceTransformer } from './type-reference';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import { replaceName } from './replaceName';
|
|
2
3
|
|
|
3
4
|
export function interfaceNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {
|
|
4
5
|
return (context) => {
|
|
@@ -6,19 +7,31 @@ export function interfaceNamesTransformer(nameMapping: Record<string, string>):
|
|
|
6
7
|
const visit: ts.Visitor = (node) => {
|
|
7
8
|
if (ts.isInterfaceDeclaration(node)) {
|
|
8
9
|
const oldName = node.name.text;
|
|
9
|
-
const newName =
|
|
10
|
+
const newName = replaceName(oldName, nameMapping);
|
|
10
11
|
if (newName) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const newMembers = node.members.map((member) => {
|
|
13
|
+
if (ts.isPropertySignature(member) && ts.isIdentifier(member.name)) {
|
|
14
|
+
const memberName = member.name.text;
|
|
15
|
+
if (nameMapping[memberName]) {
|
|
16
|
+
return factory.updatePropertySignature(
|
|
17
|
+
member,
|
|
18
|
+
member.modifiers,
|
|
19
|
+
factory.createIdentifier(nameMapping[memberName]),
|
|
20
|
+
member.questionToken,
|
|
21
|
+
member.type
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return member;
|
|
26
|
+
});
|
|
14
27
|
return factory.updateInterfaceDeclaration(
|
|
15
28
|
node,
|
|
16
29
|
node.decorators,
|
|
17
30
|
node.modifiers,
|
|
18
|
-
factory.createIdentifier(
|
|
31
|
+
factory.createIdentifier(newName),
|
|
19
32
|
node.typeParameters,
|
|
20
33
|
node.heritageClauses,
|
|
21
|
-
|
|
34
|
+
newMembers
|
|
22
35
|
);
|
|
23
36
|
}
|
|
24
37
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function replaceName(oldName: string, nameMapping: Record<string, string>): string | undefined {
|
|
2
|
+
for (const old of Object.keys(nameMapping)) {
|
|
3
|
+
if (oldName.startsWith(old) || oldName === old) {
|
|
4
|
+
return oldName.replace(new RegExp(`^${old}`), nameMapping[old]);
|
|
5
|
+
}
|
|
6
|
+
if (oldName.endsWith(old)) {
|
|
7
|
+
return oldName.replace(new RegExp(`${old}$`), nameMapping[old]);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
@@ -47,13 +47,6 @@ export async function transformSourceFile(
|
|
|
47
47
|
);
|
|
48
48
|
const transformedSourceFile: ts.SourceFile = transformedResult.transformed[0] as ts.SourceFile;
|
|
49
49
|
|
|
50
|
-
// const _identifierTransformer = identifierTransformer(updates || {});
|
|
51
|
-
|
|
52
|
-
// const transformedResultWithIdentifiers: ts.TransformationResult<ts.SourceFile> =
|
|
53
|
-
// ts.transform<ts.SourceFile>(transformedSourceFile, []);
|
|
54
|
-
// const transformedSourceFileWithIdentifiers: ts.SourceFile
|
|
55
|
-
// = transformedResultWithIdentifiers.transformed[0] as ts.SourceFile;
|
|
56
|
-
|
|
57
50
|
const printer: ts.Printer = ts.createPrinter({
|
|
58
51
|
removeComments: false,
|
|
59
52
|
});
|
|
@@ -75,33 +68,3 @@ export async function transformSourceFile(
|
|
|
75
68
|
}
|
|
76
69
|
return transformedSourceFileStr;
|
|
77
70
|
}
|
|
78
|
-
|
|
79
|
-
// function createMarkingTransformer<T extends ts.Node>(innerTransformer: ts.TransformerFactory<T>)
|
|
80
|
-
// : ts.TransformerFactory<T> {
|
|
81
|
-
// return context => {
|
|
82
|
-
// const innerTransform = innerTransformer(context);
|
|
83
|
-
|
|
84
|
-
// return node => {
|
|
85
|
-
// const result = innerTransform(node);
|
|
86
|
-
|
|
87
|
-
// // Add a custom property to the node to mark it as transformed
|
|
88
|
-
// // Note: this relies on TypeScript's internal behavior and may not be stable across versions
|
|
89
|
-
// (result as any).__transformed = true;
|
|
90
|
-
|
|
91
|
-
// return result;
|
|
92
|
-
// };
|
|
93
|
-
// };
|
|
94
|
-
// }
|
|
95
|
-
|
|
96
|
-
// const defaultTransformer: ts.TransformerFactory<ts.SourceFile> = () => {
|
|
97
|
-
// const visit: ts.Visitor = node => {
|
|
98
|
-
// // If the node has been marked as transformed by a specific transformer, don't transform it
|
|
99
|
-
// if ((node as any).__transformed) {
|
|
100
|
-
// return node;
|
|
101
|
-
// }
|
|
102
|
-
|
|
103
|
-
// // Your transformation logic goes here...
|
|
104
|
-
// };
|
|
105
|
-
|
|
106
|
-
// return node => ts.visitNode(node, visit);
|
|
107
|
-
// };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { replaceName } from './replaceName';
|
|
3
|
+
|
|
4
|
+
export function typeReferenceTransformer(mapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {
|
|
5
|
+
return (context) => {
|
|
6
|
+
const visit: ts.Visitor = (node) => {
|
|
7
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
8
|
+
const oldName = node.typeName.getText();
|
|
9
|
+
const newName = replaceName(oldName, mapping);
|
|
10
|
+
if (newName) {
|
|
11
|
+
return ts.factory.updateTypeReferenceNode(node, ts.factory.createIdentifier(newName), node.typeArguments);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return ts.visitEachChild(node, visit, context);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return (node) => ts.visitNode(node, visit);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import { replaceName } from './replaceName';
|
|
2
3
|
|
|
3
4
|
export function typeAliasNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {
|
|
4
5
|
return (context) => {
|
|
@@ -6,16 +7,13 @@ export function typeAliasNamesTransformer(nameMapping: Record<string, string>):
|
|
|
6
7
|
const visit: ts.Visitor = (node) => {
|
|
7
8
|
if (ts.isTypeAliasDeclaration(node)) {
|
|
8
9
|
const oldName = node.name.text;
|
|
9
|
-
const newName =
|
|
10
|
+
const newName = replaceName(oldName, nameMapping);
|
|
10
11
|
if (newName) {
|
|
11
|
-
const replacedName = oldName.startsWith(newName)
|
|
12
|
-
? oldName.replace(newName, nameMapping[newName])
|
|
13
|
-
: oldName.replace(new RegExp(`${newName}$`), nameMapping[newName]);
|
|
14
12
|
return factory.updateTypeAliasDeclaration(
|
|
15
13
|
node,
|
|
16
14
|
node.decorators,
|
|
17
15
|
node.modifiers,
|
|
18
|
-
factory.createIdentifier(
|
|
16
|
+
factory.createIdentifier(newName),
|
|
19
17
|
node.typeParameters,
|
|
20
18
|
node.type
|
|
21
19
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import { replaceName } from './replaceName';
|
|
2
3
|
|
|
3
4
|
export function variableNamesTransformer(nameMapping: Record<string, string>): ts.TransformerFactory<ts.SourceFile> {
|
|
4
5
|
return (context) => {
|
|
@@ -6,15 +7,11 @@ export function variableNamesTransformer(nameMapping: Record<string, string>): t
|
|
|
6
7
|
const visit: ts.Visitor = (node) => {
|
|
7
8
|
if (ts.isVariableDeclaration(node) && node.name.kind === ts.SyntaxKind.Identifier) {
|
|
8
9
|
const oldName = node.name.text;
|
|
9
|
-
const newName =
|
|
10
|
+
const newName = replaceName(oldName, nameMapping);
|
|
10
11
|
if (newName) {
|
|
11
|
-
const replacedName = oldName.startsWith(newName)
|
|
12
|
-
? oldName.replace(newName, nameMapping[newName])
|
|
13
|
-
: oldName.replace(new RegExp(`${newName}$`), nameMapping[newName]);
|
|
14
|
-
|
|
15
12
|
return factory.updateVariableDeclaration(
|
|
16
13
|
node,
|
|
17
|
-
factory.createIdentifier(
|
|
14
|
+
factory.createIdentifier(newName),
|
|
18
15
|
node.exclamationToken,
|
|
19
16
|
node.type,
|
|
20
17
|
node.initializer
|
|
Binary file
|