@teambit/typescript 1.0.108 → 1.0.109
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/artifacts/__bit_junit.xml +49 -0
- package/artifacts/preview/teambit_typescript_typescript-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
- package/package.json +18 -18
- package/compiler-options.ts +0 -27
- package/dedupe-path.spec.ts +0 -34
- package/export-identifier.ts +0 -14
- package/extractor-options.ts +0 -21
- package/identifier-list.ts +0 -14
- package/identifier.ts +0 -23
- package/index.ts +0 -14
- package/remove-types-task.ts +0 -33
- package/schema-extractor-context.ts +0 -625
- package/schema-transformer.plugin.ts +0 -14
- package/schema-transformer.ts +0 -23
- package/transform-source-file.spec.ts +0 -155
- package/tsconfig-writer.ts +0 -249
- package/typescript.aspect.ts +0 -5
- package/typescript.compiler.spec.ts +0 -63
- package/typescript.compiler.ts +0 -286
- package/typescript.extractor.ts +0 -247
- package/typescript.main.runtime.ts +0 -442
- package/typescript.parser.spec.ts +0 -221
- package/typescript.parser.ts +0 -123
package/typescript.parser.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { Parser } from '@teambit/schema';
|
|
2
|
-
import { Export, StaticProperties } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
-
import { Logger } from '@teambit/logger';
|
|
4
|
-
import { readFileSync } from 'fs-extra';
|
|
5
|
-
import ts from 'typescript';
|
|
6
|
-
|
|
7
|
-
export class TypeScriptParser implements Parser {
|
|
8
|
-
public extension = /^.*\.(js|jsx|ts|tsx)$/;
|
|
9
|
-
|
|
10
|
-
getExports(sourceFile: ts.SourceFile): Export[] {
|
|
11
|
-
const staticProperties = this.parseStaticProperties(sourceFile);
|
|
12
|
-
const exportModels: Export[] = [];
|
|
13
|
-
|
|
14
|
-
sourceFile.statements.forEach((statement) => {
|
|
15
|
-
// export default
|
|
16
|
-
if (ts.isExportAssignment(statement)) {
|
|
17
|
-
// export default
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// export declarations or re-exports
|
|
21
|
-
if (ts.isExportDeclaration(statement)) {
|
|
22
|
-
if (statement.exportClause) {
|
|
23
|
-
if (ts.isNamedExports(statement.exportClause)) {
|
|
24
|
-
statement.exportClause.elements.forEach((element) => {
|
|
25
|
-
const name = element.name.escapedText.toString();
|
|
26
|
-
if (name !== 'default') {
|
|
27
|
-
exportModels.push(new Export(name, staticProperties.get(name)));
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (ts.isNamespaceExport(statement.exportClause)) {
|
|
32
|
-
const name = statement.exportClause.name.escapedText.toString();
|
|
33
|
-
exportModels.push(new Export(name, staticProperties.get(name)));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// export modifiers
|
|
39
|
-
// - variable statement
|
|
40
|
-
// - function statement
|
|
41
|
-
// - class statement
|
|
42
|
-
if (statement.modifiers) {
|
|
43
|
-
statement.modifiers.some((modifier) => {
|
|
44
|
-
if (modifier.kind === ts.SyntaxKind.ExportKeyword) {
|
|
45
|
-
if (ts.isVariableStatement(statement)) {
|
|
46
|
-
const child = statement.declarationList.declarations[0];
|
|
47
|
-
if (ts.isIdentifier(child.name)) {
|
|
48
|
-
const name = child.name.escapedText.toString();
|
|
49
|
-
exportModels.push(new Export(name, staticProperties.get(name)));
|
|
50
|
-
}
|
|
51
|
-
} else if (ts.isFunctionDeclaration(statement)) {
|
|
52
|
-
if (statement.name) {
|
|
53
|
-
const name = statement.name.escapedText.toString();
|
|
54
|
-
exportModels.push(new Export(name, staticProperties.get(name)));
|
|
55
|
-
}
|
|
56
|
-
} else if (ts.isClassDeclaration(statement)) {
|
|
57
|
-
if (statement.name) {
|
|
58
|
-
const name = statement.name.escapedText.toString();
|
|
59
|
-
exportModels.push(new Export(name, staticProperties.get(name)));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const withoutEmpty = exportModels.filter((exportModel) => exportModel !== undefined);
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
return withoutEmpty;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
parseModule(modulePath: string, content?: string) {
|
|
75
|
-
const ast = ts.createSourceFile(modulePath, content || readFileSync(modulePath, 'utf8'), ts.ScriptTarget.Latest);
|
|
76
|
-
|
|
77
|
-
const moduleExports = this.getExports(ast);
|
|
78
|
-
return moduleExports;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
parseStaticProperties(sourceFile: ts.SourceFile) {
|
|
82
|
-
// TODO - should we also parse staticProperties inside classes / objects?
|
|
83
|
-
|
|
84
|
-
const exportStaticProperties = new Map<string, StaticProperties>();
|
|
85
|
-
|
|
86
|
-
sourceFile.statements.forEach((statement) => {
|
|
87
|
-
try {
|
|
88
|
-
if (!ts.isExpressionStatement(statement)) return;
|
|
89
|
-
if (!ts.isBinaryExpression(statement.expression)) return;
|
|
90
|
-
if (statement.expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken) return;
|
|
91
|
-
if (!ts.isPropertyAccessExpression(statement.expression.left)) return;
|
|
92
|
-
if (!ts.isIdentifier(statement.expression.left.expression)) return;
|
|
93
|
-
|
|
94
|
-
const targetName = statement.expression.left.expression.text;
|
|
95
|
-
const propertyName = statement.expression.left.name.text;
|
|
96
|
-
|
|
97
|
-
if (!exportStaticProperties.has(targetName)) exportStaticProperties.set(targetName, new Map());
|
|
98
|
-
|
|
99
|
-
const existingProperties = exportStaticProperties.get(targetName);
|
|
100
|
-
|
|
101
|
-
if (ts.isStringLiteral(statement.expression.right)) {
|
|
102
|
-
existingProperties?.set(propertyName, statement.expression.right.text);
|
|
103
|
-
} else if (ts.isNumericLiteral(statement.expression.right)) {
|
|
104
|
-
existingProperties?.set(propertyName, +statement.expression.right.text);
|
|
105
|
-
} else if (statement.expression.right.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
106
|
-
existingProperties?.set(propertyName, undefined);
|
|
107
|
-
} else if (statement.expression.right.kind === ts.SyntaxKind.NullKeyword) {
|
|
108
|
-
existingProperties?.set(propertyName, null);
|
|
109
|
-
} else if (statement.expression.right.kind === ts.SyntaxKind.TrueKeyword) {
|
|
110
|
-
existingProperties?.set(propertyName, true);
|
|
111
|
-
} else if (statement.expression.right.kind === ts.SyntaxKind.FalseKeyword) {
|
|
112
|
-
existingProperties?.set(propertyName, false);
|
|
113
|
-
}
|
|
114
|
-
} catch (err) {
|
|
115
|
-
this.logger?.error('failed parsing static properties', err);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
return exportStaticProperties;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
constructor(private logger?: Logger | undefined) {}
|
|
123
|
-
}
|