@teambit/typescript 0.0.1112 → 0.0.1114
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-1689909446382.js → preview-1690168610397.js} +2 -2
- package/dist/sourceFileTransformers/export.js +3 -2
- package/dist/sourceFileTransformers/export.js.map +1 -1
- package/dist/transform-source-file.spec.js +49 -0
- package/dist/transform-source-file.spec.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.1114.tgz +0 -0
- package/package.json +18 -18
- package/sourceFileTransformers/export.ts +12 -11
- package/package-tar/teambit-typescript-0.0.1112.tgz +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
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.1114/dist/typescript.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.1114/dist/typescript.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -26,6 +26,7 @@ const exportTransformer = mapping => {
|
|
|
26
26
|
moduleSpecifier = moduleSpecifier.replace(oldName, newName);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
let updatedExportClause;
|
|
29
30
|
if (node.exportClause && _typescript().default.isNamedExports(node.exportClause)) {
|
|
30
31
|
const transformedElements = node.exportClause.elements.map(element => {
|
|
31
32
|
let newElementName = element.name.text;
|
|
@@ -36,9 +37,9 @@ const exportTransformer = mapping => {
|
|
|
36
37
|
}
|
|
37
38
|
return _typescript().default.factory.updateExportSpecifier(element, false, element.propertyName, _typescript().default.factory.createIdentifier(newElementName));
|
|
38
39
|
});
|
|
39
|
-
|
|
40
|
-
return _typescript().default.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, updatedExportClause, node.moduleSpecifier ? _typescript().default.factory.createStringLiteral(moduleSpecifier || '') : undefined, undefined);
|
|
40
|
+
updatedExportClause = _typescript().default.factory.updateNamedExports(node.exportClause, transformedElements);
|
|
41
41
|
}
|
|
42
|
+
return _typescript().default.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, updatedExportClause, node.moduleSpecifier ? _typescript().default.factory.createStringLiteral(moduleSpecifier || '') : undefined, undefined);
|
|
42
43
|
}
|
|
43
44
|
if (_typescript().default.isExportAssignment(node)) {
|
|
44
45
|
let expression = node.expression;
|
|
@@ -1 +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","
|
|
1
|
+
{"version":3,"names":["exportTransformer","mapping","context","visit","node","ts","isExportDeclaration","moduleSpecifier","getText","slice","oldName","newName","Object","entries","includes","replace","updatedExportClause","exportClause","isNamedExports","transformedElements","elements","map","element","newElementName","name","text","startsWith","endsWith","factory","updateExportSpecifier","propertyName","createIdentifier","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 let updatedExportClause;\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 updatedExportClause = ts.factory.updateNamedExports(node.exportClause, transformedElements);\n }\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 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,0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ableName'
|
|
77
77
|
},
|
|
78
78
|
expectedCode: 'let newVariableName = "test";'
|
|
79
|
+
}, {
|
|
80
|
+
transformer: _sourceFileTransformers().importTransformer,
|
|
81
|
+
sourceCode: 'import { Component } from "@xxx/ui-library";',
|
|
82
|
+
nameMapping: {
|
|
83
|
+
'@xxx/ui-library': '@abc/ui-library'
|
|
84
|
+
},
|
|
85
|
+
expectedCode: 'import { Component } from "@abc/ui-library";'
|
|
86
|
+
}, {
|
|
87
|
+
transformer: _sourceFileTransformers().importTransformer,
|
|
88
|
+
sourceCode: 'import * as UI from "@xxx/ui-library";',
|
|
89
|
+
nameMapping: {
|
|
90
|
+
'@xxx/ui-library': '@abc/ui-library'
|
|
91
|
+
},
|
|
92
|
+
expectedCode: 'import * as UI from "@abc/ui-library";'
|
|
93
|
+
}, {
|
|
94
|
+
transformer: _sourceFileTransformers().importTransformer,
|
|
95
|
+
sourceCode: 'import UI from "@xxx/ui-library";',
|
|
96
|
+
nameMapping: {
|
|
97
|
+
'@xxx/ui-library': '@abc/ui-library'
|
|
98
|
+
},
|
|
99
|
+
expectedCode: 'import UI from "@abc/ui-library";'
|
|
100
|
+
}, {
|
|
101
|
+
transformer: _sourceFileTransformers().importTransformer,
|
|
102
|
+
sourceCode: 'const UI = require("@xxx/ui-library");',
|
|
103
|
+
nameMapping: {
|
|
104
|
+
'@xxx/ui-library': '@abc/ui-library'
|
|
105
|
+
},
|
|
106
|
+
expectedCode: 'const UI = require("@abc/ui-library");'
|
|
107
|
+
}, {
|
|
108
|
+
transformer: _sourceFileTransformers().exportTransformer,
|
|
109
|
+
sourceCode: 'export { Component } from "@xxx/ui-library";',
|
|
110
|
+
nameMapping: {
|
|
111
|
+
'@xxx/ui-library': '@abc/ui-library'
|
|
112
|
+
},
|
|
113
|
+
expectedCode: 'export { Component } from "@abc/ui-library";'
|
|
114
|
+
}, {
|
|
115
|
+
transformer: _sourceFileTransformers().exportTransformer,
|
|
116
|
+
sourceCode: 'export * from "@xxx/ui-library";',
|
|
117
|
+
nameMapping: {
|
|
118
|
+
'@xxx/ui-library': '@abc/ui-library'
|
|
119
|
+
},
|
|
120
|
+
expectedCode: 'export * from "@abc/ui-library";'
|
|
121
|
+
}, {
|
|
122
|
+
transformer: _sourceFileTransformers().exportTransformer,
|
|
123
|
+
sourceCode: 'export { default as UI } from "@xxx/ui-library";',
|
|
124
|
+
nameMapping: {
|
|
125
|
+
'@xxx/ui-library': '@abc/ui-library'
|
|
126
|
+
},
|
|
127
|
+
expectedCode: 'export { default as UI } from "@abc/ui-library";'
|
|
79
128
|
}];
|
|
80
129
|
for (const {
|
|
81
130
|
transformer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["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","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} 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\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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;
|
|
1
|
+
{"version":3,"names":["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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWA,SAASA,mBAAmB,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;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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1114",
|
|
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.1114"
|
|
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.1114",
|
|
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.1114",
|
|
26
|
+
"@teambit/isolator": "0.0.1114",
|
|
27
|
+
"@teambit/component": "0.0.1114",
|
|
28
|
+
"@teambit/dependency-resolver": "0.0.1114",
|
|
29
|
+
"@teambit/formatter": "0.0.665",
|
|
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.1114",
|
|
33
|
+
"@teambit/envs": "0.0.1114",
|
|
34
|
+
"@teambit/logger": "0.0.839",
|
|
35
|
+
"@teambit/workspace": "0.0.1114",
|
|
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.1114",
|
|
38
|
+
"@teambit/scope": "0.0.1114",
|
|
39
|
+
"@teambit/cli": "0.0.746",
|
|
40
|
+
"@teambit/pkg": "0.0.1114",
|
|
41
|
+
"@teambit/watcher": "0.0.126"
|
|
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.526",
|
|
58
58
|
"react": "^16.8.0 || ^17.0.0",
|
|
59
59
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
60
60
|
},
|
|
@@ -11,6 +11,7 @@ export const exportTransformer: SourceFileTransformer = (mapping: Record<string,
|
|
|
11
11
|
moduleSpecifier = moduleSpecifier.replace(oldName, newName);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
let updatedExportClause;
|
|
14
15
|
|
|
15
16
|
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
|
|
16
17
|
const transformedElements = node.exportClause.elements.map((element) => {
|
|
@@ -30,18 +31,18 @@ export const exportTransformer: SourceFileTransformer = (mapping: Record<string,
|
|
|
30
31
|
);
|
|
31
32
|
});
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return ts.factory.updateExportDeclaration(
|
|
36
|
-
node,
|
|
37
|
-
node.decorators,
|
|
38
|
-
node.modifiers,
|
|
39
|
-
node.isTypeOnly,
|
|
40
|
-
updatedExportClause,
|
|
41
|
-
node.moduleSpecifier ? ts.factory.createStringLiteral(moduleSpecifier || '') : undefined,
|
|
42
|
-
undefined
|
|
43
|
-
);
|
|
34
|
+
updatedExportClause = ts.factory.updateNamedExports(node.exportClause, transformedElements);
|
|
44
35
|
}
|
|
36
|
+
|
|
37
|
+
return ts.factory.updateExportDeclaration(
|
|
38
|
+
node,
|
|
39
|
+
node.decorators,
|
|
40
|
+
node.modifiers,
|
|
41
|
+
node.isTypeOnly,
|
|
42
|
+
updatedExportClause,
|
|
43
|
+
node.moduleSpecifier ? ts.factory.createStringLiteral(moduleSpecifier || '') : undefined,
|
|
44
|
+
undefined
|
|
45
|
+
);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
if (ts.isExportAssignment(node)) {
|
|
Binary file
|