@teambit/typescript 0.0.1101 → 0.0.1102
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/index.d.ts +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/{preview-1688959062567.js → preview-1689061040556.js} +2 -2
- package/dist/sourceFileTransformers/class.d.ts +2 -0
- package/dist/sourceFileTransformers/class.js +38 -0
- package/dist/sourceFileTransformers/class.js.map +1 -0
- package/dist/sourceFileTransformers/empty-line-encoder.d.ts +14 -0
- package/dist/sourceFileTransformers/empty-line-encoder.js +68 -0
- package/dist/sourceFileTransformers/empty-line-encoder.js.map +1 -0
- package/dist/sourceFileTransformers/export.d.ts +2 -0
- package/dist/sourceFileTransformers/export.js +61 -0
- package/dist/sourceFileTransformers/export.js.map +1 -0
- package/dist/sourceFileTransformers/function.d.ts +2 -0
- package/dist/sourceFileTransformers/function.js +110 -0
- package/dist/sourceFileTransformers/function.js.map +1 -0
- package/dist/sourceFileTransformers/identifier.d.ts +2 -0
- package/dist/sourceFileTransformers/identifier.js +38 -0
- package/dist/sourceFileTransformers/identifier.js.map +1 -0
- package/dist/sourceFileTransformers/import.d.ts +2 -0
- package/dist/sourceFileTransformers/import.js +74 -0
- package/dist/sourceFileTransformers/import.js.map +1 -0
- package/dist/sourceFileTransformers/index.d.ts +11 -0
- package/dist/sourceFileTransformers/index.js +124 -0
- package/dist/sourceFileTransformers/index.js.map +1 -0
- package/dist/sourceFileTransformers/interface.d.ts +2 -0
- package/dist/sourceFileTransformers/interface.js +38 -0
- package/dist/sourceFileTransformers/interface.js.map +1 -0
- package/dist/sourceFileTransformers/transform.d.ts +12 -0
- package/dist/sourceFileTransformers/transform.js +113 -0
- package/dist/sourceFileTransformers/transform.js.map +1 -0
- package/dist/sourceFileTransformers/typeAlias.d.ts +2 -0
- package/dist/sourceFileTransformers/typeAlias.js +38 -0
- package/dist/sourceFileTransformers/typeAlias.js.map +1 -0
- package/dist/sourceFileTransformers/variable.d.ts +2 -0
- package/dist/sourceFileTransformers/variable.js +38 -0
- package/dist/sourceFileTransformers/variable.js.map +1 -0
- package/dist/transform-source-file.spec.d.ts +1 -0
- package/dist/transform-source-file.spec.js +109 -0
- package/dist/transform-source-file.spec.js.map +1 -0
- package/package-tar/teambit-typescript-0.0.1102.tgz +0 -0
- package/package.json +19 -19
- package/sourceFileTransformers/class.ts +29 -0
- package/sourceFileTransformers/empty-line-encoder.ts +56 -0
- package/sourceFileTransformers/export.ts +65 -0
- package/sourceFileTransformers/function.ts +164 -0
- package/sourceFileTransformers/identifier.ts +24 -0
- package/sourceFileTransformers/import.ts +103 -0
- package/sourceFileTransformers/index.ts +13 -0
- package/sourceFileTransformers/interface.ts +29 -0
- package/sourceFileTransformers/transform.ts +100 -0
- package/sourceFileTransformers/typeAlias.ts +28 -0
- package/sourceFileTransformers/variable.ts +28 -0
- package/package-tar/teambit-typescript-0.0.1101.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export { TypescriptAspect } from './typescript.aspect';
|
|
|
7
7
|
export type { TypescriptCompilerInterface } from './typescript-compiler-interface';
|
|
8
8
|
export { expandIncludeExclude } from './expand-include-exclude';
|
|
9
9
|
export { GLOBAL_TYPES_DIR } from './ts-config-writer';
|
|
10
|
+
export * from './sourceFileTransformers';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
TypescriptConfigMutator: true,
|
|
8
|
+
TypeScriptExtractor: true,
|
|
9
|
+
TypescriptCompiler: true,
|
|
10
|
+
TypescriptAspect: true,
|
|
11
|
+
expandIncludeExclude: true,
|
|
12
|
+
GLOBAL_TYPES_DIR: true
|
|
13
|
+
};
|
|
6
14
|
Object.defineProperty(exports, "GLOBAL_TYPES_DIR", {
|
|
7
15
|
enumerable: true,
|
|
8
16
|
get: function () {
|
|
@@ -81,5 +89,17 @@ function _tsConfigWriter() {
|
|
|
81
89
|
};
|
|
82
90
|
return data;
|
|
83
91
|
}
|
|
92
|
+
var _sourceFileTransformers = require("./sourceFileTransformers");
|
|
93
|
+
Object.keys(_sourceFileTransformers).forEach(function (key) {
|
|
94
|
+
if (key === "default" || key === "__esModule") return;
|
|
95
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
96
|
+
if (key in exports && exports[key] === _sourceFileTransformers[key]) return;
|
|
97
|
+
Object.defineProperty(exports, key, {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return _sourceFileTransformers[key];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
84
104
|
|
|
85
105
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nexport { TypeScriptExtractor } from './typescript.extractor';\nexport { TypescriptCompiler } from './typescript.compiler';\nexport type { TypescriptMain, TsConfigTransformer } from './typescript.main.runtime';\nexport type { TypeScriptCompilerOptions, TsCompilerOptionsWithoutTsConfig } from './compiler-options';\nexport { TypescriptAspect } from './typescript.aspect';\nexport type { TypescriptCompilerInterface } from './typescript-compiler-interface';\nexport { expandIncludeExclude } from './expand-include-exclude';\nexport { GLOBAL_TYPES_DIR } from './ts-config-writer';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nexport { TypeScriptExtractor } from './typescript.extractor';\nexport { TypescriptCompiler } from './typescript.compiler';\nexport type { TypescriptMain, TsConfigTransformer } from './typescript.main.runtime';\nexport type { TypeScriptCompilerOptions, TsCompilerOptionsWithoutTsConfig } from './compiler-options';\nexport { TypescriptAspect } from './typescript.aspect';\nexport type { TypescriptCompilerInterface } from './typescript-compiler-interface';\nexport { expandIncludeExclude } from './expand-include-exclude';\nexport { GLOBAL_TYPES_DIR } from './ts-config-writer';\nexport * from './sourceFileTransformers';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.1102/dist/typescript.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.1102/dist/typescript.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
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
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.classNamesTransformer = classNamesTransformer;
|
|
11
|
+
function _typescript() {
|
|
12
|
+
const data = _interopRequireDefault(require("typescript"));
|
|
13
|
+
_typescript = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
function classNamesTransformer(nameMapping) {
|
|
19
|
+
return context => {
|
|
20
|
+
const {
|
|
21
|
+
factory
|
|
22
|
+
} = context;
|
|
23
|
+
const visit = node => {
|
|
24
|
+
if (_typescript().default.isClassDeclaration(node) && node.name) {
|
|
25
|
+
const oldName = node.name.text;
|
|
26
|
+
const newName = Object.keys(nameMapping).find(key => oldName.startsWith(key) || oldName.endsWith(key));
|
|
27
|
+
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);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return _typescript().default.visitEachChild(node, child => visit(child), context);
|
|
33
|
+
};
|
|
34
|
+
return node => _typescript().default.visitNode(node, visit);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,SAASA,qBAAqB,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,OAAO,CACb;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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export declare class EmptyLineEncoder {
|
|
3
|
+
static readonly defaultEmptyLineMarker: string;
|
|
4
|
+
static readonly defaultNewLine: string;
|
|
5
|
+
constructor(emptyLineMarker?: string, newLine?: string);
|
|
6
|
+
emptyLineMarker: string;
|
|
7
|
+
newLine: string;
|
|
8
|
+
encode(text: string): string;
|
|
9
|
+
decode(text: string): string;
|
|
10
|
+
addLeadingEmptyLineMarker<T extends ts.Node>(node: T): T;
|
|
11
|
+
}
|
|
12
|
+
export declare function encodeEmptyLines(text: string, emptyLineMarker?: string, newLine?: string): string;
|
|
13
|
+
export declare function decodeEmptyLines(text: string, emptyLineMarker?: string, newLine?: string): string;
|
|
14
|
+
export declare function addLeadingEmptyLineMarker<T extends ts.Node>(node: T, emptyLineMarker?: string): T;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
5
|
+
require("core-js/modules/es.string.trim.js");
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.EmptyLineEncoder = void 0;
|
|
10
|
+
exports.addLeadingEmptyLineMarker = addLeadingEmptyLineMarker;
|
|
11
|
+
exports.decodeEmptyLines = decodeEmptyLines;
|
|
12
|
+
exports.encodeEmptyLines = encodeEmptyLines;
|
|
13
|
+
function _defineProperty2() {
|
|
14
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
_defineProperty2 = function () {
|
|
16
|
+
return data;
|
|
17
|
+
};
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
function _typescript() {
|
|
21
|
+
const data = _interopRequireDefault(require("typescript"));
|
|
22
|
+
_typescript = function () {
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
class EmptyLineEncoder {
|
|
28
|
+
constructor(emptyLineMarker, newLine) {
|
|
29
|
+
(0, _defineProperty2().default)(this, "emptyLineMarker", void 0);
|
|
30
|
+
(0, _defineProperty2().default)(this, "newLine", void 0);
|
|
31
|
+
this.emptyLineMarker = emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker;
|
|
32
|
+
this.newLine = newLine || EmptyLineEncoder.defaultNewLine;
|
|
33
|
+
}
|
|
34
|
+
encode(text) {
|
|
35
|
+
return encodeEmptyLines(text, this.emptyLineMarker, this.newLine);
|
|
36
|
+
}
|
|
37
|
+
decode(text) {
|
|
38
|
+
return decodeEmptyLines(text, this.emptyLineMarker, this.newLine);
|
|
39
|
+
}
|
|
40
|
+
addLeadingEmptyLineMarker(node) {
|
|
41
|
+
return addLeadingEmptyLineMarker(node, this.emptyLineMarker);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.EmptyLineEncoder = EmptyLineEncoder;
|
|
45
|
+
(0, _defineProperty2().default)(EmptyLineEncoder, "defaultEmptyLineMarker", '!--empty-line--!');
|
|
46
|
+
(0, _defineProperty2().default)(EmptyLineEncoder, "defaultNewLine", '\r\n');
|
|
47
|
+
function encodeEmptyLines(text, emptyLineMarker, newLine) {
|
|
48
|
+
const marker = toComment(emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker);
|
|
49
|
+
const lines = text.split(/\r?\n/);
|
|
50
|
+
const commentedLines = lines.map(line => line.trim() === '' ? marker : line);
|
|
51
|
+
return commentedLines.join(newLine || EmptyLineEncoder.defaultNewLine);
|
|
52
|
+
}
|
|
53
|
+
function decodeEmptyLines(text, emptyLineMarker, newLine) {
|
|
54
|
+
const marker = toComment(emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker);
|
|
55
|
+
const lines = text.split(/\r?\n/);
|
|
56
|
+
const uncommentedLines = lines.map(line => line === marker ? '' : line);
|
|
57
|
+
return uncommentedLines.join(newLine || EmptyLineEncoder.defaultNewLine);
|
|
58
|
+
}
|
|
59
|
+
function addLeadingEmptyLineMarker(node, emptyLineMarker) {
|
|
60
|
+
return _typescript().default.addSyntheticLeadingComment(node, _typescript().default.SyntaxKind.MultiLineCommentTrivia, emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker,
|
|
61
|
+
// hasTrailingNewLine
|
|
62
|
+
true);
|
|
63
|
+
}
|
|
64
|
+
function toComment(marker) {
|
|
65
|
+
return `/*${marker}*/`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=empty-line-encoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EmptyLineEncoder","constructor","emptyLineMarker","newLine","defaultEmptyLineMarker","defaultNewLine","encode","text","encodeEmptyLines","decode","decodeEmptyLines","addLeadingEmptyLineMarker","node","marker","toComment","lines","split","commentedLines","map","line","trim","join","uncommentedLines","ts","addSyntheticLeadingComment","SyntaxKind","MultiLineCommentTrivia"],"sources":["empty-line-encoder.ts"],"sourcesContent":["import ts from 'typescript';\n\nexport class EmptyLineEncoder {\n static readonly defaultEmptyLineMarker: string = '!--empty-line--!';\n static readonly defaultNewLine: string = '\\r\\n';\n constructor(emptyLineMarker?: string, newLine?: string) {\n this.emptyLineMarker = emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker;\n this.newLine = newLine || EmptyLineEncoder.defaultNewLine;\n }\n emptyLineMarker: string;\n newLine: string;\n\n encode(text: string) {\n return encodeEmptyLines(text, this.emptyLineMarker, this.newLine);\n }\n decode(text: string) {\n return decodeEmptyLines(text, this.emptyLineMarker, this.newLine);\n }\n addLeadingEmptyLineMarker<T extends ts.Node>(node: T) {\n return addLeadingEmptyLineMarker(node, this.emptyLineMarker);\n }\n}\n\nexport function encodeEmptyLines(text: string, emptyLineMarker?: string, newLine?: string) {\n const marker = toComment(emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker);\n\n const lines = text.split(/\\r?\\n/);\n\n const commentedLines = lines.map((line) => (line.trim() === '' ? marker : line));\n\n return commentedLines.join(newLine || EmptyLineEncoder.defaultNewLine);\n}\n\nexport function decodeEmptyLines(text: string, emptyLineMarker?: string, newLine?: string) {\n const marker = toComment(emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker);\n\n const lines = text.split(/\\r?\\n/);\n\n const uncommentedLines = lines.map((line) => (line === marker ? '' : line));\n\n return uncommentedLines.join(newLine || EmptyLineEncoder.defaultNewLine);\n}\n\nexport function addLeadingEmptyLineMarker<T extends ts.Node>(node: T, emptyLineMarker?: string) {\n return ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.MultiLineCommentTrivia,\n emptyLineMarker || EmptyLineEncoder.defaultEmptyLineMarker,\n // hasTrailingNewLine\n true\n );\n}\n\nfunction toComment(marker: string) {\n return `/*${marker}*/`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,gBAAgB,CAA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AEpF,MAAMW,KAAK,GAAGR,IAAI,CAACS,KAAK,CAAC,OAAO,CAAC;EAEjC,MAAMM,gBAAgB,GAAGP,KAAK,CAACG,GAAG,CAAEC,IAAI,IAAMA,IAAI,KAAKN,MAAM,GAAG,EAAE,GAAGM,IAAK,CAAC;EAE3E,OAAOG,gBAAgB,CAACD,IAAI,CAAClB,OAAO,IAAIH,gBAAgB,CAACK,cAAc,CAAC;AAC1E;AAEO,SAASM,yBAAyB,CAAoBC,IAAO,EAAEV,eAAwB,EAAE;EAC9F,OAAOqB,qBAAE,CAACC,0BAA0B,CAClCZ,IAAI,EACJW,qBAAE,CAACE,UAAU,CAACC,sBAAsB,EACpCxB,eAAe,IAAIF,gBAAgB,CAACI,sBAAsB;EAC1D;EACA,IAAI,CACL;AACH;AAEA,SAASU,SAAS,CAACD,MAAc,EAAE;EACjC,OAAQ,KAAIA,MAAO,IAAG;AACxB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.array.iterator.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.exportTransformer = void 0;
|
|
11
|
+
function _typescript() {
|
|
12
|
+
const data = _interopRequireDefault(require("typescript"));
|
|
13
|
+
_typescript = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
const exportTransformer = mapping => {
|
|
19
|
+
return context => {
|
|
20
|
+
const visit = node => {
|
|
21
|
+
if (_typescript().default.isExportDeclaration(node)) {
|
|
22
|
+
var _node$moduleSpecifier;
|
|
23
|
+
let moduleSpecifier = (_node$moduleSpecifier = node.moduleSpecifier) === null || _node$moduleSpecifier === void 0 ? void 0 : _node$moduleSpecifier.getText().slice(1, -1);
|
|
24
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
25
|
+
if (moduleSpecifier && moduleSpecifier.includes(oldName)) {
|
|
26
|
+
moduleSpecifier = moduleSpecifier.replace(oldName, newName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (node.exportClause && _typescript().default.isNamedExports(node.exportClause)) {
|
|
30
|
+
const transformedElements = node.exportClause.elements.map(element => {
|
|
31
|
+
let newElementName = element.name.text;
|
|
32
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
33
|
+
if (newElementName.startsWith(oldName) || newElementName.endsWith(oldName)) {
|
|
34
|
+
newElementName = newElementName.replace(oldName, newName);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return _typescript().default.factory.updateExportSpecifier(element, false, element.propertyName, _typescript().default.factory.createIdentifier(newElementName));
|
|
38
|
+
});
|
|
39
|
+
const updatedExportClause = _typescript().default.factory.updateNamedExports(node.exportClause, transformedElements);
|
|
40
|
+
return _typescript().default.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, updatedExportClause, node.moduleSpecifier ? _typescript().default.factory.createStringLiteral(moduleSpecifier || '') : undefined, undefined);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (_typescript().default.isExportAssignment(node)) {
|
|
44
|
+
let expression = node.expression;
|
|
45
|
+
if (_typescript().default.isIdentifier(expression)) {
|
|
46
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
47
|
+
if (expression.getText().startsWith(oldName) || expression.getText().endsWith(oldName)) {
|
|
48
|
+
expression = _typescript().default.factory.createIdentifier(expression.getText().replace(oldName, newName));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return _typescript().default.factory.updateExportAssignment(node, node.decorators, node.modifiers, expression);
|
|
53
|
+
}
|
|
54
|
+
return _typescript().default.visitEachChild(node, visit, context);
|
|
55
|
+
};
|
|
56
|
+
return node => _typescript().default.visitNode(node, visit);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.exportTransformer = exportTransformer;
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["exportTransformer","mapping","context","visit","node","ts","isExportDeclaration","moduleSpecifier","getText","slice","oldName","newName","Object","entries","includes","replace","exportClause","isNamedExports","transformedElements","elements","map","element","newElementName","name","text","startsWith","endsWith","factory","updateExportSpecifier","propertyName","createIdentifier","updatedExportClause","updateNamedExports","updateExportDeclaration","decorators","modifiers","isTypeOnly","createStringLiteral","undefined","isExportAssignment","expression","isIdentifier","updateExportAssignment","visitEachChild","visitNode"],"sources":["export.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\n\nexport const exportTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const visit: ts.Visitor = (node) => {\n if (ts.isExportDeclaration(node)) {\n let moduleSpecifier = node.moduleSpecifier?.getText().slice(1, -1);\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier && moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n if (node.exportClause && ts.isNamedExports(node.exportClause)) {\n const transformedElements = node.exportClause.elements.map((element) => {\n let newElementName = element.name.text;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (newElementName.startsWith(oldName) || newElementName.endsWith(oldName)) {\n newElementName = newElementName.replace(oldName, newName);\n }\n }\n\n return ts.factory.updateExportSpecifier(\n element,\n false,\n element.propertyName,\n ts.factory.createIdentifier(newElementName)\n );\n });\n\n const updatedExportClause = ts.factory.updateNamedExports(node.exportClause, transformedElements);\n\n return ts.factory.updateExportDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.isTypeOnly,\n updatedExportClause,\n node.moduleSpecifier ? ts.factory.createStringLiteral(moduleSpecifier || '') : undefined,\n undefined\n );\n }\n }\n\n if (ts.isExportAssignment(node)) {\n let expression = node.expression;\n\n if (ts.isIdentifier(expression)) {\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (expression.getText().startsWith(oldName) || expression.getText().endsWith(oldName)) {\n expression = ts.factory.createIdentifier(expression.getText().replace(oldName, newName));\n }\n }\n }\n\n return ts.factory.updateExportAssignment(node, node.decorators, node.modifiers, expression);\n }\n\n return ts.visitEachChild(node, visit, context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,iBAAwC,GAAIC,OAA+B,IAAK;EAC3F,OAAQC,OAAO,IAAK;IAClB,MAAMC,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,mBAAmB,CAACF,IAAI,CAAC,EAAE;QAAA;QAChC,IAAIG,eAAe,4BAAGH,IAAI,CAACG,eAAe,0DAApB,sBAAsBC,OAAO,EAAE,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClE,KAAK,MAAM,CAACC,OAAO,EAAEC,OAAO,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACZ,OAAO,CAAC,EAAE;UACxD,IAAIM,eAAe,IAAIA,eAAe,CAACO,QAAQ,CAACJ,OAAO,CAAC,EAAE;YACxDH,eAAe,GAAGA,eAAe,CAACQ,OAAO,CAACL,OAAO,EAAEC,OAAO,CAAC;UAC7D;QACF;QAEA,IAAIP,IAAI,CAACY,YAAY,IAAIX,qBAAE,CAACY,cAAc,CAACb,IAAI,CAACY,YAAY,CAAC,EAAE;UAC7D,MAAME,mBAAmB,GAAGd,IAAI,CAACY,YAAY,CAACG,QAAQ,CAACC,GAAG,CAAEC,OAAO,IAAK;YACtE,IAAIC,cAAc,GAAGD,OAAO,CAACE,IAAI,CAACC,IAAI;YAEtC,KAAK,MAAM,CAACd,OAAO,EAAEC,OAAO,CA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AAChB,OAAO,CAAC,EAAE;cACtF8B,UAAU,GAAGnC,qBAAE,CAACsB,OAAO,CAACG,gBAAgB,CAACU,UAAU,CAAChC,OAAO,EAAE,CAACO,OAAO,CAACL,OAAO,EAAEC,OAAO,CAAC,CAAC;YAC1F;UACF;QACF;QAEA,OAAON,qBAAE,CAACsB,OAAO,CAACe,sBAAsB,CAACtC,IAAI,EAAEA,IAAI,CAAC8B,UAAU,EAAE9B,IAAI,CAAC+B,SAAS,EAAEK,UAAU,CAAC;MAC7F;MAEA,OAAOnC,qBAAE,CAACsC,cAAc,CAACvC,IAAI,EAAED,KAAK,EAAED,OAAO,CAAC;IAChD,CAAC;IACD,OAAQE,IAAI,IAAKC,qBAAE,CAACuC,SAAS,CAACxC,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.array.iterator.js");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.functionNamesTransformer = void 0;
|
|
9
|
+
function _typescript() {
|
|
10
|
+
const data = _interopRequireDefault(require("typescript"));
|
|
11
|
+
_typescript = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
const functionNamesTransformer = mapping => {
|
|
17
|
+
return context => {
|
|
18
|
+
const updateTypeReference = node => {
|
|
19
|
+
if (_typescript().default.isTypeReferenceNode(node)) {
|
|
20
|
+
const typeName = node.typeName.getText();
|
|
21
|
+
const newTypeName = mapping[typeName];
|
|
22
|
+
if (newTypeName) {
|
|
23
|
+
return _typescript().default.factory.updateTypeReferenceNode(node, _typescript().default.factory.createIdentifier(newTypeName), node.typeArguments);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return _typescript().default.visitEachChild(node, updateTypeReference, context);
|
|
27
|
+
};
|
|
28
|
+
const visit = node => {
|
|
29
|
+
if (_typescript().default.isFunctionDeclaration(node) || _typescript().default.isArrowFunction(node) || _typescript().default.isFunctionExpression(node)) {
|
|
30
|
+
var _node$name$getText, _node$name, _Object$entries$find$, _Object$entries$find;
|
|
31
|
+
const functionName = (_node$name$getText = (_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.getText()) !== null && _node$name$getText !== void 0 ? _node$name$getText : '';
|
|
32
|
+
const newName = (_Object$entries$find$ = (_Object$entries$find = Object.entries(mapping).find(([key]) => functionName.includes(key))) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[1]) !== null && _Object$entries$find$ !== void 0 ? _Object$entries$find$ : functionName;
|
|
33
|
+
const parameters = node.parameters.map(param => {
|
|
34
|
+
const newParamType = param.type ? _typescript().default.visitNode(param.type, updateTypeReference) : param.type;
|
|
35
|
+
if (_typescript().default.isIdentifier(param.name)) {
|
|
36
|
+
const oldName = param.name.getText();
|
|
37
|
+
const newParamName = Object.keys(mapping).find(key => oldName.includes(key));
|
|
38
|
+
if (newParamName) {
|
|
39
|
+
return _typescript().default.factory.updateParameterDeclaration(param, param.decorators, param.modifiers, param.dotDotDotToken, _typescript().default.factory.createIdentifier(newParamName), param.questionToken, newParamType, param.initializer);
|
|
40
|
+
}
|
|
41
|
+
} else if (_typescript().default.isObjectBindingPattern(param.name)) {
|
|
42
|
+
const elements = param.name.elements.map(element => {
|
|
43
|
+
const newElementName = mapping[element.name.getText()];
|
|
44
|
+
if (newElementName) {
|
|
45
|
+
return _typescript().default.factory.updateBindingElement(element, element.dotDotDotToken, element.propertyName, _typescript().default.factory.createIdentifier(newElementName), element.initializer);
|
|
46
|
+
}
|
|
47
|
+
return element;
|
|
48
|
+
});
|
|
49
|
+
const newParamName = _typescript().default.factory.createObjectBindingPattern(elements);
|
|
50
|
+
return _typescript().default.factory.updateParameterDeclaration(param, param.decorators, param.modifiers, param.dotDotDotToken, newParamName, param.questionToken, newParamType, param.initializer);
|
|
51
|
+
}
|
|
52
|
+
return param;
|
|
53
|
+
});
|
|
54
|
+
if (_typescript().default.isFunctionDeclaration(node)) {
|
|
55
|
+
const updatedBody = node.body && _typescript().default.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;
|
|
56
|
+
return _typescript().default.factory.updateFunctionDeclaration(node, node.decorators, node.modifiers, node.asteriskToken, newName ? _typescript().default.factory.createIdentifier(newName) : node.name, node.typeParameters, parameters, node.type, updatedBody);
|
|
57
|
+
}
|
|
58
|
+
if (_typescript().default.isArrowFunction(node)) {
|
|
59
|
+
const updatedBody = node.body && _typescript().default.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;
|
|
60
|
+
return _typescript().default.factory.updateArrowFunction(node, node.modifiers, node.typeParameters, parameters, node.type, node.equalsGreaterThanToken, updatedBody);
|
|
61
|
+
}
|
|
62
|
+
if (_typescript().default.isFunctionExpression(node)) {
|
|
63
|
+
const updatedBody = node.body && _typescript().default.isBlock(node.body) ? updateReturnStatement(node.body) : node.body;
|
|
64
|
+
return _typescript().default.factory.updateFunctionExpression(node, node.modifiers, node.asteriskToken, newName ? _typescript().default.factory.createIdentifier(newName) : node.name, node.typeParameters, parameters, node.type, updatedBody);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return _typescript().default.visitEachChild(node, visit, context);
|
|
68
|
+
};
|
|
69
|
+
function updateReturnStatement(body) {
|
|
70
|
+
if (_typescript().default.isBlock(body)) {
|
|
71
|
+
const updatedStatements = [];
|
|
72
|
+
for (const statement of body.statements) {
|
|
73
|
+
if (_typescript().default.isReturnStatement(statement) && statement.expression && _typescript().default.isJsxElement(statement.expression)) {
|
|
74
|
+
const jsxElement = statement.expression;
|
|
75
|
+
const openingElement = jsxElement.openingElement;
|
|
76
|
+
const tagName = openingElement.tagName.getText();
|
|
77
|
+
const newTagName = mapping[tagName];
|
|
78
|
+
if (newTagName) {
|
|
79
|
+
const updatedTagName = _typescript().default.factory.createIdentifier(newTagName);
|
|
80
|
+
const updatedOpeningElement = _typescript().default.factory.updateJsxOpeningElement(openingElement, updatedTagName, openingElement.typeArguments, openingElement.attributes);
|
|
81
|
+
const updatedClosingElement = jsxElement.closingElement ? _typescript().default.factory.updateJsxClosingElement(jsxElement.closingElement, updatedTagName) : _typescript().default.factory.createJsxClosingElement(updatedTagName);
|
|
82
|
+
const updatedJsxElement = _typescript().default.factory.createJsxElement(updatedOpeningElement, jsxElement.children, updatedClosingElement);
|
|
83
|
+
const updatedStatement = _typescript().default.factory.createReturnStatement(updatedJsxElement);
|
|
84
|
+
updatedStatements.push(updatedStatement);
|
|
85
|
+
} else {
|
|
86
|
+
updatedStatements.push(statement);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
updatedStatements.push(statement);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return _typescript().default.factory.updateBlock(body, updatedStatements);
|
|
93
|
+
}
|
|
94
|
+
if (_typescript().default.isExpressionStatement(body) && _typescript().default.isReturnStatement(body.expression) && body.expression.expression && _typescript().default.isIdentifier(body.expression.expression)) {
|
|
95
|
+
const oldName = body.expression.expression.text;
|
|
96
|
+
const newName = mapping[oldName];
|
|
97
|
+
if (newName) {
|
|
98
|
+
const updatedExpression = _typescript().default.factory.createIdentifier(newName);
|
|
99
|
+
const updatedReturnStatement = _typescript().default.factory.createReturnStatement(updatedExpression);
|
|
100
|
+
return _typescript().default.factory.createBlock([updatedReturnStatement], true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return _typescript().default.factory.createBlock([], true);
|
|
104
|
+
}
|
|
105
|
+
return node => _typescript().default.visitNode(node, visit);
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
exports.functionNamesTransformer = functionNamesTransformer;
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["functionNamesTransformer","mapping","context","updateTypeReference","node","ts","isTypeReferenceNode","typeName","getText","newTypeName","factory","updateTypeReferenceNode","createIdentifier","typeArguments","visitEachChild","visit","isFunctionDeclaration","isArrowFunction","isFunctionExpression","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"],"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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,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,EAAE;QACxC,MAAMC,WA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OAAO,CAAC;UAC9D,MAAMmE,sBAAsB,GAAGnF,qBAAE,CAACK,OAAO,CAACwE,qBAAqB,CAACK,iBAAiB,CAAC;UAClF,OAAOlF,qBAAE,CAACK,OAAO,CAAC+E,WAAW,CAAC,CAACD,sBAAsB,CAAC,EAAE,IAAI,CAAC;QAC/D;MACF;MACA,OAAOnF,qBAAE,CAACK,OAAO,CAAC+E,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC;IACzC;IACA,OAAQrF,IAAI,IAAKC,qBAAE,CAAC2B,SAAS,CAAC5B,IAAI,EAAEW,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.array.iterator.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.identifierTransformer = void 0;
|
|
11
|
+
function _typescript() {
|
|
12
|
+
const data = _interopRequireDefault(require("typescript"));
|
|
13
|
+
_typescript = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
const identifierTransformer = mapping => {
|
|
19
|
+
return context => {
|
|
20
|
+
const visit = node => {
|
|
21
|
+
if (_typescript().default.isIdentifier(node)) {
|
|
22
|
+
const identifierName = node.text;
|
|
23
|
+
let newIdentifierName = mapping[identifierName] || identifierName;
|
|
24
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
25
|
+
if (identifierName.startsWith(oldName) || identifierName.endsWith(oldName)) {
|
|
26
|
+
newIdentifierName = identifierName.replace(oldName, newName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return _typescript().default.factory.createIdentifier(newIdentifierName);
|
|
30
|
+
}
|
|
31
|
+
return _typescript().default.visitEachChild(node, visit, context);
|
|
32
|
+
};
|
|
33
|
+
return node => _typescript().default.visitNode(node, visit);
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.identifierTransformer = identifierTransformer;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=identifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["identifierTransformer","mapping","context","visit","node","ts","isIdentifier","identifierName","text","newIdentifierName","oldName","newName","Object","entries","startsWith","endsWith","replace","factory","createIdentifier","visitEachChild","visitNode"],"sources":["identifier.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\n\nexport const identifierTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const visit: ts.Visitor = (node) => {\n if (ts.isIdentifier(node)) {\n const identifierName = node.text;\n let newIdentifierName = mapping[identifierName] || identifierName;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (identifierName.startsWith(oldName) || identifierName.endsWith(oldName)) {\n newIdentifierName = identifierName.replace(oldName, newName);\n }\n }\n\n return ts.factory.createIdentifier(newIdentifierName);\n }\n\n return ts.visitEachChild(node, visit, context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,qBAA4C,GAAIC,OAA+B,IAAK;EAC/F,OAAQC,OAAO,IAAK;IAClB,MAAMC,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,YAAY,CAACF,IAAI,CAAC,EAAE;QACzB,MAAMG,cAAc,GAAGH,IAAI,CAACI,IAAI;QAChC,IAAIC,iBAAiB,GAAGR,OAAO,CAACM,cAAc,CAAC,IAAIA,cAAc;QAEjE,KAAK,MAAM,CAACG,OAAO,EAAEC,OAAO,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACZ,OAAO,CAAC,EAAE;UACxD,IAAIM,cAAc,CAACO,UAAU,CAACJ,OAAO,CAAC,IAAIH,cAAc,CAACQ,QAAQ,CAACL,OAAO,CAAC,EAAE;YAC1ED,iBAAiB,GAAGF,cAAc,CAACS,OAAO,CAACN,OAAO,EAAEC,OAAO,CAAC;UAC9D;QACF;QAEA,OAAON,qBAAE,CAACY,OAAO,CAACC,gBAAgB,CAACT,iBAAiB,CAAC;MACvD;MAEA,OAAOJ,qBAAE,CAACc,cAAc,CAACf,IAAI,EAAED,KAAK,EAAED,OAAO,CAAC;IAChD,CAAC;IACD,OAAQE,IAAI,IAAKC,qBAAE,CAACe,SAAS,CAAChB,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.array.iterator.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.importTransformer = void 0;
|
|
11
|
+
function _typescript() {
|
|
12
|
+
const data = _interopRequireDefault(require("typescript"));
|
|
13
|
+
_typescript = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
const importTransformer = mapping => {
|
|
19
|
+
return context => {
|
|
20
|
+
const visit = node => {
|
|
21
|
+
if (_typescript().default.isImportDeclaration(node)) {
|
|
22
|
+
var _node$importClause;
|
|
23
|
+
let moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);
|
|
24
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
25
|
+
if (moduleSpecifier.includes(oldName)) {
|
|
26
|
+
moduleSpecifier = moduleSpecifier.replace(oldName, newName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if ((_node$importClause = node.importClause) !== null && _node$importClause !== void 0 && _node$importClause.namedBindings && _typescript().default.isNamedImports(node.importClause.namedBindings)) {
|
|
30
|
+
const transformedBindings = node.importClause.namedBindings.elements.map(element => {
|
|
31
|
+
let newElementName = element.name.text;
|
|
32
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
33
|
+
if (newElementName.startsWith(oldName) || newElementName.endsWith(oldName)) {
|
|
34
|
+
newElementName = newElementName.replace(oldName, newName);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return _typescript().default.factory.updateImportSpecifier(element, false, element.propertyName ? _typescript().default.factory.createIdentifier(newElementName) : undefined, _typescript().default.factory.createIdentifier(newElementName));
|
|
38
|
+
});
|
|
39
|
+
const updatedImportClause = _typescript().default.factory.updateImportClause(node.importClause, node.importClause.isTypeOnly, node.importClause.name, _typescript().default.factory.createNamedImports(transformedBindings));
|
|
40
|
+
return _typescript().default.factory.updateImportDeclaration(node, node.decorators, node.modifiers, updatedImportClause, _typescript().default.factory.createStringLiteral(moduleSpecifier), undefined);
|
|
41
|
+
}
|
|
42
|
+
return _typescript().default.factory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, _typescript().default.factory.createStringLiteral(moduleSpecifier), undefined);
|
|
43
|
+
}
|
|
44
|
+
if (_typescript().default.isImportEqualsDeclaration(node)) {
|
|
45
|
+
let moduleSpecifier = node.moduleReference.getText().slice(1, -1);
|
|
46
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
47
|
+
if (moduleSpecifier.includes(oldName)) {
|
|
48
|
+
moduleSpecifier = moduleSpecifier.replace(oldName, newName);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const updatedImportEqualsDeclaration = _typescript().default.factory.updateImportEqualsDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, node.name, _typescript().default.factory.createExternalModuleReference(_typescript().default.factory.createStringLiteral(moduleSpecifier)));
|
|
52
|
+
return updatedImportEqualsDeclaration;
|
|
53
|
+
}
|
|
54
|
+
if (_typescript().default.isCallExpression(node) && _typescript().default.isIdentifier(node.expression) && node.expression.text === 'require') {
|
|
55
|
+
const [firstArg] = node.arguments;
|
|
56
|
+
if (_typescript().default.isStringLiteral(firstArg)) {
|
|
57
|
+
let moduleSpecifier = firstArg.text;
|
|
58
|
+
for (const [oldName, newName] of Object.entries(mapping)) {
|
|
59
|
+
if (moduleSpecifier.includes(oldName)) {
|
|
60
|
+
moduleSpecifier = moduleSpecifier.replace(oldName, newName);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const updatedArg = _typescript().default.factory.createStringLiteral(moduleSpecifier);
|
|
64
|
+
return _typescript().default.factory.updateCallExpression(node, node.expression, node.typeArguments, [updatedArg, ...node.arguments.slice(1)]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return _typescript().default.visitEachChild(node, visit, context);
|
|
68
|
+
};
|
|
69
|
+
return node => _typescript().default.visitNode(node, visit);
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
exports.importTransformer = importTransformer;
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["importTransformer","mapping","context","visit","node","ts","isImportDeclaration","moduleSpecifier","getText","slice","oldName","newName","Object","entries","includes","replace","importClause","namedBindings","isNamedImports","transformedBindings","elements","map","element","newElementName","name","text","startsWith","endsWith","factory","updateImportSpecifier","propertyName","createIdentifier","undefined","updatedImportClause","updateImportClause","isTypeOnly","createNamedImports","updateImportDeclaration","decorators","modifiers","createStringLiteral","isImportEqualsDeclaration","moduleReference","updatedImportEqualsDeclaration","updateImportEqualsDeclaration","createExternalModuleReference","isCallExpression","isIdentifier","expression","firstArg","arguments","isStringLiteral","updatedArg","updateCallExpression","typeArguments","visitEachChild","visitNode"],"sources":["import.ts"],"sourcesContent":["import ts from 'typescript';\nimport { SourceFileTransformer } from '.';\n\nexport const importTransformer: SourceFileTransformer = (mapping: Record<string, string>) => {\n return (context) => {\n const visit: ts.Visitor = (node) => {\n if (ts.isImportDeclaration(node)) {\n let moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {\n const transformedBindings = node.importClause.namedBindings.elements.map((element) => {\n let newElementName = element.name.text;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (newElementName.startsWith(oldName) || newElementName.endsWith(oldName)) {\n newElementName = newElementName.replace(oldName, newName);\n }\n }\n\n return ts.factory.updateImportSpecifier(\n element,\n false,\n element.propertyName ? ts.factory.createIdentifier(newElementName) : undefined,\n ts.factory.createIdentifier(newElementName)\n );\n });\n\n const updatedImportClause = ts.factory.updateImportClause(\n node.importClause,\n node.importClause.isTypeOnly,\n node.importClause.name,\n ts.factory.createNamedImports(transformedBindings)\n );\n\n return ts.factory.updateImportDeclaration(\n node,\n node.decorators,\n node.modifiers,\n updatedImportClause,\n ts.factory.createStringLiteral(moduleSpecifier),\n undefined\n );\n }\n\n return ts.factory.updateImportDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.importClause,\n ts.factory.createStringLiteral(moduleSpecifier),\n undefined\n );\n }\n if (ts.isImportEqualsDeclaration(node)) {\n let moduleSpecifier = node.moduleReference.getText().slice(1, -1);\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n const updatedImportEqualsDeclaration = ts.factory.updateImportEqualsDeclaration(\n node,\n node.decorators,\n node.modifiers,\n node.isTypeOnly,\n node.name,\n ts.factory.createExternalModuleReference(ts.factory.createStringLiteral(moduleSpecifier))\n );\n\n return updatedImportEqualsDeclaration;\n }\n\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'require') {\n const [firstArg] = node.arguments;\n\n if (ts.isStringLiteral(firstArg)) {\n let moduleSpecifier = firstArg.text;\n\n for (const [oldName, newName] of Object.entries(mapping)) {\n if (moduleSpecifier.includes(oldName)) {\n moduleSpecifier = moduleSpecifier.replace(oldName, newName);\n }\n }\n\n const updatedArg = ts.factory.createStringLiteral(moduleSpecifier);\n return ts.factory.updateCallExpression(node, node.expression, node.typeArguments, [\n updatedArg,\n ...node.arguments.slice(1),\n ]);\n }\n }\n\n return ts.visitEachChild(node, visit, context);\n };\n return (node) => ts.visitNode(node, visit);\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,iBAAwC,GAAIC,OAA+B,IAAK;EAC3F,OAAQC,OAAO,IAAK;IAClB,MAAMC,KAAiB,GAAIC,IAAI,IAAK;MAClC,IAAIC,qBAAE,CAACC,mBAAmB,CAACF,IAAI,CAAC,EAAE;QAAA;QAChC,IAAIG,eAAe,GAAGH,IAAI,CAACG,eAAe,CAACC,OAAO,EAAE,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjE,KAAK,MAAM,CAACC,OAAO,EAAEC,OAAO,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACZ,OAAO,CAAC,EAAE;UACxD,IAAIM,eAAe,CAACO,QAAQ,CAACJ,OAAO,CAAC,EAAE;YACrCH,eAAe,GAAGA,eAAe,CAACQ,OAAO,CAACL,OAAO,EAAEC,OAAO,CAAC;UAC7D;QACF;QAEA,IAAI,sBAAAP,IAAI,CAACY,YAAY,+CAAjB,mBAAmBC,aAAa,IAAIZ,qBAAE,CAACa,cAAc,CAACd,IAAI,CAACY,YAAY,CAACC,aAAa,CAAC,EAAE;UAC1F,MAAME,mBAAmB,GAAGf,IAAI,CAACY,YAAY,CAACC,aAAa,CAACG,QAAQ,CAAC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AAC,IAAIC,MAAM,CAACC,OAAO,CAACZ,OAAO,CAAC,EAAE;YACxD,IAAIM,eAAe,CAACO,QAAQ,CAACJ,OAAO,CAAC,EAAE;cACrCH,eAAe,GAAGA,eAAe,CAACQ,OAAO,CAACL,OAAO,EAAEC,OAAO,CAAC;YAC7D;UACF;UAEA,MAAMyC,UAAU,GAAG/C,qBAAE,CAACuB,OAAO,CAACY,mBAAmB,CAACjC,eAAe,CAAC;UAClE,OAAOF,qBAAE,CAACuB,OAAO,CAACyB,oBAAoB,CAACjD,IAAI,EAAEA,IAAI,CAAC4C,UAAU,EAAE5C,IAAI,CAACkD,aAAa,EAAE,CAChFF,UAAU,EACV,GAAGhD,IAAI,CAAC8C,SAAS,CAACzC,KAAK,CAAC,CAAC,CAAC,CAC3B,CAAC;QACJ;MACF;MAEA,OAAOJ,qBAAE,CAACkD,cAAc,CAACnD,IAAI,EAAED,KAAK,EAAED,OAAO,CAAC;IAChD,CAAC;IACD,OAAQE,IAAI,IAAKC,qBAAE,CAACmD,SAAS,CAACpD,IAAI,EAAED,KAAK,CAAC;EAC5C,CAAC;AACH,CAAC;AAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export declare type SourceFileTransformer = (mapping: Record<string, string>) => ts.TransformerFactory<ts.SourceFile>;
|
|
3
|
+
export { classNamesTransformer } from './class';
|
|
4
|
+
export { interfaceNamesTransformer } from './interface';
|
|
5
|
+
export { variableNamesTransformer } from './variable';
|
|
6
|
+
export { functionNamesTransformer } from './function';
|
|
7
|
+
export { typeAliasNamesTransformer } from './typeAlias';
|
|
8
|
+
export { importTransformer } from './import';
|
|
9
|
+
export { identifierTransformer } from './identifier';
|
|
10
|
+
export { exportTransformer } from './export';
|
|
11
|
+
export { transformSourceFile } from './transform';
|