@teambit/typescript 1.0.107 → 1.0.108
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/compiler-options.ts +27 -0
- package/dedupe-path.spec.ts +34 -0
- package/dist/cmds/write-tsconfig.cmd.d.ts +2 -2
- package/dist/compiler-options.d.ts +2 -2
- package/dist/extractor-options.d.ts +1 -1
- package/dist/identifier-list.d.ts +1 -1
- package/dist/identifier.d.ts +3 -3
- package/dist/{preview-1703590665075.js → preview-1703647408454.js} +2 -2
- package/dist/schema-extractor-context.d.ts +11 -11
- package/dist/schema-extractor-context.js +13 -17
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/schema-transformer.d.ts +2 -2
- package/dist/sourceFileTransformers/export.js +1 -2
- package/dist/sourceFileTransformers/export.js.map +1 -1
- package/dist/sourceFileTransformers/function.js +2 -3
- package/dist/sourceFileTransformers/function.js.map +1 -1
- package/dist/sourceFileTransformers/import.js +1 -2
- package/dist/sourceFileTransformers/import.js.map +1 -1
- package/dist/sourceFileTransformers/index.d.ts +1 -1
- package/dist/sourceFileTransformers/transform.js +1 -1
- package/dist/sourceFileTransformers/transform.js.map +1 -1
- package/dist/transformers/binding-element.js +1 -2
- package/dist/transformers/binding-element.js.map +1 -1
- package/dist/transformers/class-declaration.js +3 -6
- package/dist/transformers/class-declaration.js.map +1 -1
- package/dist/transformers/constructor.js +3 -4
- package/dist/transformers/constructor.js.map +1 -1
- package/dist/transformers/enum-declaration.js +1 -2
- package/dist/transformers/enum-declaration.js.map +1 -1
- package/dist/transformers/export-declaration.js +5 -7
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/function-like.js +5 -8
- package/dist/transformers/function-like.js.map +1 -1
- package/dist/transformers/get-accessor.js +1 -2
- package/dist/transformers/get-accessor.js.map +1 -1
- package/dist/transformers/import-declaration.js +2 -3
- package/dist/transformers/import-declaration.js.map +1 -1
- package/dist/transformers/interface-declaration.js +1 -2
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/parameter.js +1 -2
- package/dist/transformers/parameter.js.map +1 -1
- package/dist/transformers/property-declaration.js +1 -2
- package/dist/transformers/property-declaration.js.map +1 -1
- package/dist/transformers/source-file-transformer.js +3 -5
- package/dist/transformers/source-file-transformer.js.map +1 -1
- package/dist/transformers/utils/jsdoc-to-doc-schema.js +2 -4
- package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -1
- package/dist/transformers/utils/parse-type-from-quick-info.js +1 -2
- package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
- package/dist/transformers/variable-declaration.js +8 -12
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/tsconfig-writer.d.ts +2 -2
- package/dist/tsconfig-writer.js +1 -4
- package/dist/tsconfig-writer.js.map +1 -1
- package/dist/typescript.composition.d.ts +2 -2
- package/dist/typescript.extractor.d.ts +3 -3
- package/dist/typescript.extractor.js +5 -7
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +7 -7
- package/dist/typescript.main.runtime.js +1 -2
- package/dist/typescript.main.runtime.js.map +1 -1
- package/dist/typescript.parser.js +7 -8
- package/dist/typescript.parser.js.map +1 -1
- package/dist/typescript.parser.spec.js +12 -15
- package/dist/typescript.parser.spec.js.map +1 -1
- package/export-identifier.ts +14 -0
- package/extractor-options.ts +21 -0
- package/identifier-list.ts +14 -0
- package/identifier.ts +23 -0
- package/index.ts +14 -0
- package/package.json +27 -34
- package/remove-types-task.ts +33 -0
- package/schema-extractor-context.ts +625 -0
- package/schema-transformer.plugin.ts +14 -0
- package/schema-transformer.ts +23 -0
- package/transform-source-file.spec.ts +155 -0
- package/tsconfig-writer.ts +249 -0
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
- package/typescript.aspect.ts +5 -0
- package/typescript.compiler.spec.ts +63 -0
- package/typescript.compiler.ts +286 -0
- package/typescript.extractor.ts +247 -0
- package/typescript.main.runtime.ts +442 -0
- package/typescript.parser.spec.ts +221 -0
- package/typescript.parser.ts +123 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_semanticsEntities","data","require","_fsExtra","_typescript","_interopRequireDefault","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","TypeScriptParser","getExports","sourceFile","staticProperties","parseStaticProperties","exportModels","statements","forEach","statement","ts","isExportAssignment","isExportDeclaration","exportClause","isNamedExports","elements","element","name","escapedText","toString","push","Export","get","isNamespaceExport","modifiers","some","modifier","kind","SyntaxKind","ExportKeyword","isVariableStatement","child","declarationList","declarations","isIdentifier","isFunctionDeclaration","isClassDeclaration","withoutEmpty","filter","exportModel","undefined","parseModule","modulePath","content","ast","createSourceFile","readFileSync","ScriptTarget","Latest","moduleExports","exportStaticProperties","Map","isExpressionStatement","isBinaryExpression","expression","operatorToken","EqualsToken","isPropertyAccessExpression","left","targetName","text","propertyName","has","set","existingProperties","isStringLiteral","right","isNumericLiteral","UndefinedKeyword","NullKeyword","TrueKeyword","FalseKeyword","err","_this$logger","logger","error","constructor","exports"],"sources":["typescript.parser.ts"],"sourcesContent":["import { Parser } from '@teambit/schema';\nimport { Export, StaticProperties } from '@teambit/semantics.entities.semantic-schema';\nimport { Logger } from '@teambit/logger';\nimport { readFileSync } from 'fs-extra';\nimport ts from 'typescript';\n\nexport class TypeScriptParser implements Parser {\n public extension = /^.*\\.(js|jsx|ts|tsx)$/;\n\n getExports(sourceFile: ts.SourceFile): Export[] {\n const staticProperties = this.parseStaticProperties(sourceFile);\n const exportModels: Export[] = [];\n\n sourceFile.statements.forEach((statement) => {\n // export default\n if (ts.isExportAssignment(statement)) {\n // export default\n }\n\n // export declarations or re-exports\n if (ts.isExportDeclaration(statement)) {\n if (statement.exportClause) {\n if (ts.isNamedExports(statement.exportClause)) {\n statement.exportClause.elements.forEach((element) => {\n const name = element.name.escapedText.toString();\n if (name !== 'default') {\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n });\n }\n if (ts.isNamespaceExport(statement.exportClause)) {\n const name = statement.exportClause.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n }\n }\n\n // export modifiers\n // - variable statement\n // - function statement\n // - class statement\n if (statement.modifiers) {\n statement.modifiers.some((modifier) => {\n if (modifier.kind === ts.SyntaxKind.ExportKeyword) {\n if (ts.isVariableStatement(statement)) {\n const child = statement.declarationList.declarations[0];\n if (ts.isIdentifier(child.name)) {\n const name = child.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n } else if (ts.isFunctionDeclaration(statement)) {\n if (statement.name) {\n const name = statement.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n } else if (ts.isClassDeclaration(statement)) {\n if (statement.name) {\n const name = statement.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n }\n return true;\n }\n return false;\n });\n }\n });\n\n const withoutEmpty = exportModels.filter((exportModel) => exportModel !== undefined);\n // @ts-ignore\n return withoutEmpty;\n }\n\n parseModule(modulePath: string, content?: string) {\n const ast = ts.createSourceFile(modulePath, content || readFileSync(modulePath, 'utf8'), ts.ScriptTarget.Latest);\n\n const moduleExports = this.getExports(ast);\n return moduleExports;\n }\n\n parseStaticProperties(sourceFile: ts.SourceFile) {\n // TODO - should we also parse staticProperties inside classes / objects?\n\n const exportStaticProperties = new Map<string, StaticProperties>();\n\n sourceFile.statements.forEach((statement) => {\n try {\n if (!ts.isExpressionStatement(statement)) return;\n if (!ts.isBinaryExpression(statement.expression)) return;\n if (statement.expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken) return;\n if (!ts.isPropertyAccessExpression(statement.expression.left)) return;\n if (!ts.isIdentifier(statement.expression.left.expression)) return;\n\n const targetName = statement.expression.left.expression.text;\n const propertyName = statement.expression.left.name.text;\n\n if (!exportStaticProperties.has(targetName)) exportStaticProperties.set(targetName, new Map());\n\n const existingProperties = exportStaticProperties.get(targetName);\n\n if (ts.isStringLiteral(statement.expression.right)) {\n existingProperties?.set(propertyName, statement.expression.right.text);\n } else if (ts.isNumericLiteral(statement.expression.right)) {\n existingProperties?.set(propertyName, +statement.expression.right.text);\n } else if (statement.expression.right.kind === ts.SyntaxKind.UndefinedKeyword) {\n existingProperties?.set(propertyName, undefined);\n } else if (statement.expression.right.kind === ts.SyntaxKind.NullKeyword) {\n existingProperties?.set(propertyName, null);\n } else if (statement.expression.right.kind === ts.SyntaxKind.TrueKeyword) {\n existingProperties?.set(propertyName, true);\n } else if (statement.expression.right.kind === ts.SyntaxKind.FalseKeyword) {\n existingProperties?.set(propertyName, false);\n }\n } catch (err) {\n this.logger?.error('failed parsing static properties', err);\n }\n });\n\n return exportStaticProperties;\n }\n\n constructor(private logger?: Logger | undefined) {}\n}\n"],"mappings":";;;;;;AACA,SAAAA,mBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,kBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA4B,SAAAI,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAJ,GAAA,IAAAO,MAAA,CAAAC,cAAA,CAAAR,GAAA,EAAAI,GAAA,IAAAC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AA,gBAAA"}
|
|
1
|
+
{"version":3,"names":["_semanticsEntities","data","require","_fsExtra","_typescript","_interopRequireDefault","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","TypeScriptParser","getExports","sourceFile","staticProperties","parseStaticProperties","exportModels","statements","forEach","statement","ts","isExportAssignment","isExportDeclaration","exportClause","isNamedExports","elements","element","name","escapedText","toString","push","Export","get","isNamespaceExport","modifiers","some","modifier","kind","SyntaxKind","ExportKeyword","isVariableStatement","child","declarationList","declarations","isIdentifier","isFunctionDeclaration","isClassDeclaration","withoutEmpty","filter","exportModel","undefined","parseModule","modulePath","content","ast","createSourceFile","readFileSync","ScriptTarget","Latest","moduleExports","exportStaticProperties","Map","isExpressionStatement","isBinaryExpression","expression","operatorToken","EqualsToken","isPropertyAccessExpression","left","targetName","text","propertyName","has","set","existingProperties","isStringLiteral","right","isNumericLiteral","UndefinedKeyword","NullKeyword","TrueKeyword","FalseKeyword","err","logger","error","constructor","exports"],"sources":["typescript.parser.ts"],"sourcesContent":["import { Parser } from '@teambit/schema';\nimport { Export, StaticProperties } from '@teambit/semantics.entities.semantic-schema';\nimport { Logger } from '@teambit/logger';\nimport { readFileSync } from 'fs-extra';\nimport ts from 'typescript';\n\nexport class TypeScriptParser implements Parser {\n public extension = /^.*\\.(js|jsx|ts|tsx)$/;\n\n getExports(sourceFile: ts.SourceFile): Export[] {\n const staticProperties = this.parseStaticProperties(sourceFile);\n const exportModels: Export[] = [];\n\n sourceFile.statements.forEach((statement) => {\n // export default\n if (ts.isExportAssignment(statement)) {\n // export default\n }\n\n // export declarations or re-exports\n if (ts.isExportDeclaration(statement)) {\n if (statement.exportClause) {\n if (ts.isNamedExports(statement.exportClause)) {\n statement.exportClause.elements.forEach((element) => {\n const name = element.name.escapedText.toString();\n if (name !== 'default') {\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n });\n }\n if (ts.isNamespaceExport(statement.exportClause)) {\n const name = statement.exportClause.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n }\n }\n\n // export modifiers\n // - variable statement\n // - function statement\n // - class statement\n if (statement.modifiers) {\n statement.modifiers.some((modifier) => {\n if (modifier.kind === ts.SyntaxKind.ExportKeyword) {\n if (ts.isVariableStatement(statement)) {\n const child = statement.declarationList.declarations[0];\n if (ts.isIdentifier(child.name)) {\n const name = child.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n } else if (ts.isFunctionDeclaration(statement)) {\n if (statement.name) {\n const name = statement.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n } else if (ts.isClassDeclaration(statement)) {\n if (statement.name) {\n const name = statement.name.escapedText.toString();\n exportModels.push(new Export(name, staticProperties.get(name)));\n }\n }\n return true;\n }\n return false;\n });\n }\n });\n\n const withoutEmpty = exportModels.filter((exportModel) => exportModel !== undefined);\n // @ts-ignore\n return withoutEmpty;\n }\n\n parseModule(modulePath: string, content?: string) {\n const ast = ts.createSourceFile(modulePath, content || readFileSync(modulePath, 'utf8'), ts.ScriptTarget.Latest);\n\n const moduleExports = this.getExports(ast);\n return moduleExports;\n }\n\n parseStaticProperties(sourceFile: ts.SourceFile) {\n // TODO - should we also parse staticProperties inside classes / objects?\n\n const exportStaticProperties = new Map<string, StaticProperties>();\n\n sourceFile.statements.forEach((statement) => {\n try {\n if (!ts.isExpressionStatement(statement)) return;\n if (!ts.isBinaryExpression(statement.expression)) return;\n if (statement.expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken) return;\n if (!ts.isPropertyAccessExpression(statement.expression.left)) return;\n if (!ts.isIdentifier(statement.expression.left.expression)) return;\n\n const targetName = statement.expression.left.expression.text;\n const propertyName = statement.expression.left.name.text;\n\n if (!exportStaticProperties.has(targetName)) exportStaticProperties.set(targetName, new Map());\n\n const existingProperties = exportStaticProperties.get(targetName);\n\n if (ts.isStringLiteral(statement.expression.right)) {\n existingProperties?.set(propertyName, statement.expression.right.text);\n } else if (ts.isNumericLiteral(statement.expression.right)) {\n existingProperties?.set(propertyName, +statement.expression.right.text);\n } else if (statement.expression.right.kind === ts.SyntaxKind.UndefinedKeyword) {\n existingProperties?.set(propertyName, undefined);\n } else if (statement.expression.right.kind === ts.SyntaxKind.NullKeyword) {\n existingProperties?.set(propertyName, null);\n } else if (statement.expression.right.kind === ts.SyntaxKind.TrueKeyword) {\n existingProperties?.set(propertyName, true);\n } else if (statement.expression.right.kind === ts.SyntaxKind.FalseKeyword) {\n existingProperties?.set(propertyName, false);\n }\n } catch (err) {\n this.logger?.error('failed parsing static properties', err);\n }\n });\n\n return exportStaticProperties;\n }\n\n constructor(private logger?: Logger | undefined) {}\n}\n"],"mappings":";;;;;;AACA,SAAAA,mBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,kBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA4B,SAAAI,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAJ,GAAA,IAAAO,MAAA,CAAAC,cAAA,CAAAR,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAA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AC7EJ,kBAAkB,EAAED,GAAG,CAACF,YAAY,EAAErB,SAAS,CAAC;QAClD,CAAC,MAAM,IAAI/B,SAAS,CAAC6C,UAAU,CAACY,KAAK,CAACvC,IAAI,KAAKjB,qBAAE,CAACkB,UAAU,CAACyC,WAAW,EAAE;UACxEL,kBAAkB,EAAED,GAAG,CAACF,YAAY,EAAE,IAAI,CAAC;QAC7C,CAAC,MAAM,IAAIpD,SAAS,CAAC6C,UAAU,CAACY,KAAK,CAACvC,IAAI,KAAKjB,qBAAE,CAACkB,UAAU,CAAC0C,WAAW,EAAE;UACxEN,kBAAkB,EAAED,GAAG,CAACF,YAAY,EAAE,IAAI,CAAC;QAC7C,CAAC,MAAM,IAAIpD,SAAS,CAAC6C,UAAU,CAACY,KAAK,CAACvC,IAAI,KAAKjB,qBAAE,CAACkB,UAAU,CAAC2C,YAAY,EAAE;UACzEP,kBAAkB,EAAED,GAAG,CAACF,YAAY,EAAE,KAAK,CAAC;QAC9C;MACF,CAAC,CAAC,OAAOW,GAAG,EAAE;QACZ,IAAI,CAACC,MAAM,EAAEC,KAAK,CAAC,kCAAkC,EAAEF,GAAG,CAAC;MAC7D;IACF,CAAC,CAAC;IAEF,OAAOtB,sBAAsB;EAC/B;EAEAyB,WAAWA,CAASF,MAA2B,EAAE;IAAA,KAA7BA,MAA2B,GAA3BA,MAA2B;IAAA5F,eAAA,oBAlH5B,uBAAuB;EAkHQ;AACpD;AAAC+F,OAAA,CAAA3E,gBAAA,GAAAA,gBAAA"}
|
|
@@ -125,25 +125,22 @@ describe('TypescriptParser', () => {
|
|
|
125
125
|
});
|
|
126
126
|
describe('staticProperties', () => {
|
|
127
127
|
it('should include staticProperties, when on arrowFunctions', () => {
|
|
128
|
-
var _exportArrow$staticPr;
|
|
129
128
|
const ast = _typescript().default.createSourceFile('example.tsx', exampleArrowFunction, _typescript().default.ScriptTarget.Latest);
|
|
130
129
|
const exports = new (_typescript2().TypeScriptParser)().getExports(ast);
|
|
131
130
|
const exportArrow = exports.find(x => x.identifier === 'arrow');
|
|
132
|
-
(0, _chai().expect)(exportArrow
|
|
131
|
+
(0, _chai().expect)(exportArrow?.staticProperties?.get('textProperty')).to.equal('propertyValue');
|
|
133
132
|
});
|
|
134
133
|
it('should include staticProperties, when on regular functions', () => {
|
|
135
|
-
var _exportClass$staticPr;
|
|
136
134
|
const ast = _typescript().default.createSourceFile('example.tsx', exampleFunction, _typescript().default.ScriptTarget.Latest);
|
|
137
135
|
const exports = new (_typescript2().TypeScriptParser)().getExports(ast);
|
|
138
136
|
const exportClass = exports.find(x => x.identifier === 'func');
|
|
139
|
-
(0, _chai().expect)(exportClass
|
|
137
|
+
(0, _chai().expect)(exportClass?.staticProperties?.get('textProperty')).to.equal('propertyValue');
|
|
140
138
|
});
|
|
141
139
|
it('should include staticProperties, when on classes', () => {
|
|
142
|
-
var _exportClass$staticPr2;
|
|
143
140
|
const ast = _typescript().default.createSourceFile('example.tsx', exampleClass, _typescript().default.ScriptTarget.Latest);
|
|
144
141
|
const exports = new (_typescript2().TypeScriptParser)().getExports(ast);
|
|
145
142
|
const exportClass = exports.find(x => x.identifier === 'classy');
|
|
146
|
-
(0, _chai().expect)(exportClass
|
|
143
|
+
(0, _chai().expect)(exportClass?.staticProperties?.get('textProperty')).to.equal('propertyValue');
|
|
147
144
|
});
|
|
148
145
|
});
|
|
149
146
|
});
|
|
@@ -166,25 +163,25 @@ describe('TypescriptParser', () => {
|
|
|
166
163
|
(0, _chai().expect)(staticProperties).to.exist;
|
|
167
164
|
const exportHello = staticProperties.get('hello');
|
|
168
165
|
(0, _chai().expect)(exportHello).to.exist;
|
|
169
|
-
(0, _chai().expect)(exportHello
|
|
170
|
-
(0, _chai().expect)(exportHello
|
|
171
|
-
(0, _chai().expect)(exportHello
|
|
172
|
-
(0, _chai().expect)(exportHello
|
|
173
|
-
(0, _chai().expect)(exportHello
|
|
174
|
-
(0, _chai().expect)(exportHello
|
|
175
|
-
(0, _chai().expect)(exportHello
|
|
166
|
+
(0, _chai().expect)(exportHello?.get('text')).to.equal('is');
|
|
167
|
+
(0, _chai().expect)(exportHello?.get('count')).to.equal(3);
|
|
168
|
+
(0, _chai().expect)(exportHello?.get('nullish')).to.equal(null);
|
|
169
|
+
(0, _chai().expect)(exportHello?.get('undef')).to.equal(undefined);
|
|
170
|
+
(0, _chai().expect)(exportHello?.get('disable')).to.equal(false);
|
|
171
|
+
(0, _chai().expect)(exportHello?.get('enable')).to.equal(true);
|
|
172
|
+
(0, _chai().expect)(exportHello?.has('complextLiteral')).to.be.false;
|
|
176
173
|
});
|
|
177
174
|
it('should skip non primitive values', () => {
|
|
178
175
|
const ast = _typescript().default.createSourceFile('example.tsx', exampleFile, _typescript().default.ScriptTarget.Latest);
|
|
179
176
|
const staticProperties = new (_typescript2().TypeScriptParser)().parseStaticProperties(ast);
|
|
180
177
|
const exportHello = staticProperties.get('hello');
|
|
181
|
-
(0, _chai().expect)(exportHello
|
|
178
|
+
(0, _chai().expect)(exportHello?.has('complextLiteral')).to.be.false;
|
|
182
179
|
});
|
|
183
180
|
it('should skip non assignment statements', () => {
|
|
184
181
|
const ast = _typescript().default.createSourceFile('example.tsx', exampleFile, _typescript().default.ScriptTarget.Latest);
|
|
185
182
|
const staticProperties = new (_typescript2().TypeScriptParser)().parseStaticProperties(ast);
|
|
186
183
|
const exportHello = staticProperties.get('hello');
|
|
187
|
-
(0, _chai().expect)(exportHello
|
|
184
|
+
(0, _chai().expect)(exportHello?.has('nonAssignedProperty')).to.be.false;
|
|
188
185
|
});
|
|
189
186
|
});
|
|
190
187
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","_chai","_typescript2","obj","__esModule","default","describe","exampleArrowFunction","exampleFunction","exampleClass","exampleStatement","exampleRenamedStatement","exampleReExport","exampleReExportDefault","exampleRenamedReExportAll","exampleExportDefault","it","ast","ts","createSourceFile","ScriptTarget","Latest","exports","TypeScriptParser","getExports","exportArrow","find","x","identifier","expect","to","exist","exportFunction","exportClass","exportVariable","exportFunction1","exportFunction2","not","length","equal","_exportArrow$staticPr","staticProperties","get","_exportClass$staticPr","_exportClass$staticPr2","exampleFile","parseStaticProperties","exportHello","undefined","has","be","false"],"sources":["typescript.parser.spec.ts"],"sourcesContent":["import ts from 'typescript';\nimport { expect } from 'chai';\n\nimport { TypeScriptParser } from './typescript.parser';\n\ndescribe('TypescriptParser', () => {\n describe('getExports', () => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export\n // https://www.typescriptlang.org/docs/handbook/modules.html#export\n\n const exampleArrowFunction = `\n export const arrow = () => { return 3; }\n arrow.textProperty = \"propertyValue\";\n `;\n\n const exampleFunction = `\n export function func() { return 3; }\n func.textProperty = \"propertyValue\";\n `;\n\n const exampleClass = `\n export class classy{ render() { return 3; } }\n classy.textProperty = \"propertyValue\";\n `;\n\n const exampleStatement = `\n function myFunction2 () { return 3; }\n const myVariable2 = 3;\n export { myFunction2, myVariable2 };\n `;\n\n const exampleRenamedStatement = `\n function myFunction2 () { return 3; }\n const myVariable2 = 3;\n export { myFunction2, myVariable2 as myVariable2Alias };\n `;\n\n const exampleReExport = `\n export { default as function1, function2 } from \"bar.js\";\n `;\n\n const exampleReExportDefault = `\n export { default, function2 } from \"bar.js\";\n `;\n\n const exampleRenamedReExportAll = `\n export * as ns from \"mod\";\n `;\n\n const exampleExportDefault = `\n const a: number = 1\n export default { a };\n `;\n\n it('should parse arrowFunctions', () => {\n const ast = ts.createSourceFile('example.tsx', exampleArrowFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportArrow = exports.find((x) => x.identifier === 'arrow');\n\n expect(exportArrow).to.exist;\n });\n\n it('should parse function exports', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction = exports.find((x) => x.identifier === 'func');\n\n expect(exportFunction).to.exist;\n });\n\n it('should parse classes', () => {\n const ast = ts.createSourceFile('example.tsx', exampleClass, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportClass = exports.find((x) => x.identifier === 'classy');\n\n expect(exportClass).to.exist;\n });\n\n it('should parse declarations', () => {\n const ast = ts.createSourceFile('example.tsx', exampleStatement, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction = exports.find((x) => x.identifier === 'myFunction2');\n const exportVariable = exports.find((x) => x.identifier === 'myVariable2');\n\n expect(exportFunction).to.exist;\n expect(exportVariable).to.exist;\n });\n\n it('should parse renamed declarations', () => {\n const ast = ts.createSourceFile('example.tsx', exampleRenamedStatement, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction = exports.find((x) => x.identifier === 'myFunction2');\n const exportVariable = exports.find((x) => x.identifier === 'myVariable2Alias');\n\n expect(exportFunction).to.exist;\n expect(exportVariable).to.exist;\n });\n\n it('should parse re-exports', () => {\n const ast = ts.createSourceFile('example.tsx', exampleReExport, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction1 = exports.find((x) => x.identifier === 'function1');\n const exportFunction2 = exports.find((x) => x.identifier === 'function2');\n\n expect(exportFunction1).to.exist;\n expect(exportFunction2).to.exist;\n });\n\n it('should parse re-exports with default', () => {\n const ast = ts.createSourceFile('example.tsx', exampleReExportDefault, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction1 = exports.find((x) => x.identifier === 'default');\n const exportFunction2 = exports.find((x) => x.identifier === 'function2');\n\n expect(exportFunction1).not.to.exist;\n expect(exportFunction2).to.exist;\n });\n\n it('should parse renamed re-exports all', () => {\n const ast = ts.createSourceFile('example.tsx', exampleRenamedReExportAll, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction1 = exports.find((x) => x.identifier === 'ns');\n\n expect(exportFunction1).to.exist;\n });\n\n it('should parse default exports', () => {\n const ast = ts.createSourceFile('example.tsx', exampleExportDefault, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n expect(exports.length).to.equal(0);\n });\n\n describe('staticProperties', () => {\n it('should include staticProperties, when on arrowFunctions', () => {\n const ast = ts.createSourceFile('example.tsx', exampleArrowFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportArrow = exports.find((x) => x.identifier === 'arrow');\n\n expect(exportArrow?.staticProperties?.get('textProperty')).to.equal('propertyValue');\n });\n\n it('should include staticProperties, when on regular functions', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportClass = exports.find((x) => x.identifier === 'func');\n\n expect(exportClass?.staticProperties?.get('textProperty')).to.equal('propertyValue');\n });\n\n it('should include staticProperties, when on classes', () => {\n const ast = ts.createSourceFile('example.tsx', exampleClass, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportClass = exports.find((x) => x.identifier === 'classy');\n\n expect(exportClass?.staticProperties?.get('textProperty')).to.equal('propertyValue');\n });\n });\n });\n\n describe('collectStaticProperties', () => {\n const exampleFile = `\n export const hello = () => { return 3; }\n\n hello.text = \"is\";\n hello.count = 3;\n hello.nullish = null;\n hello.undef = undefined;\n hello.disable = false;\n hello.enable = true;\n hello.complextLiteral = \\`what \\${hello.text} it?\\`;\n hello.nonAssignedProperty += 'value';\n `;\n\n it('should parse all primitive values', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFile, ts.ScriptTarget.Latest);\n const staticProperties = new TypeScriptParser().parseStaticProperties(ast);\n\n expect(staticProperties).to.exist;\n\n const exportHello = staticProperties.get('hello');\n expect(exportHello).to.exist;\n\n expect(exportHello?.get('text')).to.equal('is');\n expect(exportHello?.get('count')).to.equal(3);\n expect(exportHello?.get('nullish')).to.equal(null);\n expect(exportHello?.get('undef')).to.equal(undefined);\n expect(exportHello?.get('disable')).to.equal(false);\n expect(exportHello?.get('enable')).to.equal(true);\n\n expect(exportHello?.has('complextLiteral')).to.be.false;\n });\n\n it('should skip non primitive values', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFile, ts.ScriptTarget.Latest);\n const staticProperties = new TypeScriptParser().parseStaticProperties(ast);\n const exportHello = staticProperties.get('hello');\n\n expect(exportHello?.has('complextLiteral')).to.be.false;\n });\n\n it('should skip non assignment statements', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFile, ts.ScriptTarget.Latest);\n const staticProperties = new TypeScriptParser().parseStaticProperties(ast);\n const exportHello = staticProperties.get('hello');\n\n expect(exportHello?.has('nonAssignedProperty')).to.be.false;\n });\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,MAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,YAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAuD,SAAAC,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEvDG,QAAQ,CAAC,kBAAkB,EAAE,MAAM;EACjCA,QAAQ,CAAC,YAAY,EAAE,MAAM;IAC3B;IACA;;IAEA,MAAMC,oBAAoB,GAAI;AAClC;AACA;AACA,KAAK;IAED,MAAMC,eAAe,GAAI;AAC7B;AACA;AACA,KAAK;IAED,MAAMC,YAAY,GAAI;AAC1B;AACA;AACA,KAAK;IAED,MAAMC,gB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;IACzD,CAAC,CAAC;IAEFnC,EAAE,CAAC,uCAAuC,EAAE,MAAM;MAChD,MAAMC,GAAG,GAAGC,qBAAE,CAACC,gBAAgB,CAAC,aAAa,EAAE0B,WAAW,EAAE3B,qBAAE,CAACE,YAAY,CAACC,MAAM,CAAC;MACnF,MAAMoB,gBAAgB,GAAG,KAAIlB,+BAAgB,EAAC,CAAC,CAACuB,qBAAqB,CAAC7B,GAAG,CAAC;MAC1E,MAAM8B,WAAW,GAAGN,gBAAgB,CAACC,GAAG,CAAC,OAAO,CAAC;MAEjD,IAAAb,cAAM,EAACkB,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAEE,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAACnB,EAAE,CAACoB,EAAE,CAACC,KAAK;IAC7D,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"names":["_typescript","data","_interopRequireDefault","require","_chai","_typescript2","obj","__esModule","default","describe","exampleArrowFunction","exampleFunction","exampleClass","exampleStatement","exampleRenamedStatement","exampleReExport","exampleReExportDefault","exampleRenamedReExportAll","exampleExportDefault","it","ast","ts","createSourceFile","ScriptTarget","Latest","exports","TypeScriptParser","getExports","exportArrow","find","x","identifier","expect","to","exist","exportFunction","exportClass","exportVariable","exportFunction1","exportFunction2","not","length","equal","staticProperties","get","exampleFile","parseStaticProperties","exportHello","undefined","has","be","false"],"sources":["typescript.parser.spec.ts"],"sourcesContent":["import ts from 'typescript';\nimport { expect } from 'chai';\n\nimport { TypeScriptParser } from './typescript.parser';\n\ndescribe('TypescriptParser', () => {\n describe('getExports', () => {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export\n // https://www.typescriptlang.org/docs/handbook/modules.html#export\n\n const exampleArrowFunction = `\n export const arrow = () => { return 3; }\n arrow.textProperty = \"propertyValue\";\n `;\n\n const exampleFunction = `\n export function func() { return 3; }\n func.textProperty = \"propertyValue\";\n `;\n\n const exampleClass = `\n export class classy{ render() { return 3; } }\n classy.textProperty = \"propertyValue\";\n `;\n\n const exampleStatement = `\n function myFunction2 () { return 3; }\n const myVariable2 = 3;\n export { myFunction2, myVariable2 };\n `;\n\n const exampleRenamedStatement = `\n function myFunction2 () { return 3; }\n const myVariable2 = 3;\n export { myFunction2, myVariable2 as myVariable2Alias };\n `;\n\n const exampleReExport = `\n export { default as function1, function2 } from \"bar.js\";\n `;\n\n const exampleReExportDefault = `\n export { default, function2 } from \"bar.js\";\n `;\n\n const exampleRenamedReExportAll = `\n export * as ns from \"mod\";\n `;\n\n const exampleExportDefault = `\n const a: number = 1\n export default { a };\n `;\n\n it('should parse arrowFunctions', () => {\n const ast = ts.createSourceFile('example.tsx', exampleArrowFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportArrow = exports.find((x) => x.identifier === 'arrow');\n\n expect(exportArrow).to.exist;\n });\n\n it('should parse function exports', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction = exports.find((x) => x.identifier === 'func');\n\n expect(exportFunction).to.exist;\n });\n\n it('should parse classes', () => {\n const ast = ts.createSourceFile('example.tsx', exampleClass, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportClass = exports.find((x) => x.identifier === 'classy');\n\n expect(exportClass).to.exist;\n });\n\n it('should parse declarations', () => {\n const ast = ts.createSourceFile('example.tsx', exampleStatement, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction = exports.find((x) => x.identifier === 'myFunction2');\n const exportVariable = exports.find((x) => x.identifier === 'myVariable2');\n\n expect(exportFunction).to.exist;\n expect(exportVariable).to.exist;\n });\n\n it('should parse renamed declarations', () => {\n const ast = ts.createSourceFile('example.tsx', exampleRenamedStatement, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction = exports.find((x) => x.identifier === 'myFunction2');\n const exportVariable = exports.find((x) => x.identifier === 'myVariable2Alias');\n\n expect(exportFunction).to.exist;\n expect(exportVariable).to.exist;\n });\n\n it('should parse re-exports', () => {\n const ast = ts.createSourceFile('example.tsx', exampleReExport, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction1 = exports.find((x) => x.identifier === 'function1');\n const exportFunction2 = exports.find((x) => x.identifier === 'function2');\n\n expect(exportFunction1).to.exist;\n expect(exportFunction2).to.exist;\n });\n\n it('should parse re-exports with default', () => {\n const ast = ts.createSourceFile('example.tsx', exampleReExportDefault, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction1 = exports.find((x) => x.identifier === 'default');\n const exportFunction2 = exports.find((x) => x.identifier === 'function2');\n\n expect(exportFunction1).not.to.exist;\n expect(exportFunction2).to.exist;\n });\n\n it('should parse renamed re-exports all', () => {\n const ast = ts.createSourceFile('example.tsx', exampleRenamedReExportAll, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportFunction1 = exports.find((x) => x.identifier === 'ns');\n\n expect(exportFunction1).to.exist;\n });\n\n it('should parse default exports', () => {\n const ast = ts.createSourceFile('example.tsx', exampleExportDefault, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n expect(exports.length).to.equal(0);\n });\n\n describe('staticProperties', () => {\n it('should include staticProperties, when on arrowFunctions', () => {\n const ast = ts.createSourceFile('example.tsx', exampleArrowFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportArrow = exports.find((x) => x.identifier === 'arrow');\n\n expect(exportArrow?.staticProperties?.get('textProperty')).to.equal('propertyValue');\n });\n\n it('should include staticProperties, when on regular functions', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFunction, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportClass = exports.find((x) => x.identifier === 'func');\n\n expect(exportClass?.staticProperties?.get('textProperty')).to.equal('propertyValue');\n });\n\n it('should include staticProperties, when on classes', () => {\n const ast = ts.createSourceFile('example.tsx', exampleClass, ts.ScriptTarget.Latest);\n const exports = new TypeScriptParser().getExports(ast);\n\n const exportClass = exports.find((x) => x.identifier === 'classy');\n\n expect(exportClass?.staticProperties?.get('textProperty')).to.equal('propertyValue');\n });\n });\n });\n\n describe('collectStaticProperties', () => {\n const exampleFile = `\n export const hello = () => { return 3; }\n\n hello.text = \"is\";\n hello.count = 3;\n hello.nullish = null;\n hello.undef = undefined;\n hello.disable = false;\n hello.enable = true;\n hello.complextLiteral = \\`what \\${hello.text} it?\\`;\n hello.nonAssignedProperty += 'value';\n `;\n\n it('should parse all primitive values', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFile, ts.ScriptTarget.Latest);\n const staticProperties = new TypeScriptParser().parseStaticProperties(ast);\n\n expect(staticProperties).to.exist;\n\n const exportHello = staticProperties.get('hello');\n expect(exportHello).to.exist;\n\n expect(exportHello?.get('text')).to.equal('is');\n expect(exportHello?.get('count')).to.equal(3);\n expect(exportHello?.get('nullish')).to.equal(null);\n expect(exportHello?.get('undef')).to.equal(undefined);\n expect(exportHello?.get('disable')).to.equal(false);\n expect(exportHello?.get('enable')).to.equal(true);\n\n expect(exportHello?.has('complextLiteral')).to.be.false;\n });\n\n it('should skip non primitive values', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFile, ts.ScriptTarget.Latest);\n const staticProperties = new TypeScriptParser().parseStaticProperties(ast);\n const exportHello = staticProperties.get('hello');\n\n expect(exportHello?.has('complextLiteral')).to.be.false;\n });\n\n it('should skip non assignment statements', () => {\n const ast = ts.createSourceFile('example.tsx', exampleFile, ts.ScriptTarget.Latest);\n const staticProperties = new TypeScriptParser().parseStaticProperties(ast);\n const exportHello = staticProperties.get('hello');\n\n expect(exportHello?.has('nonAssignedProperty')).to.be.false;\n });\n });\n});\n"],"mappings":";;AAAA,SAAAA,YAAA;EAAA,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AC1B,GAAG,CAAC;MAC1E,MAAM2B,WAAW,GAAGJ,gBAAgB,CAACC,GAAG,CAAC,OAAO,CAAC;MAEjD,IAAAZ,cAAM,EAACe,WAAW,EAAEE,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAChB,EAAE,CAACiB,EAAE,CAACC,KAAK;IACzD,CAAC,CAAC;IAEFhC,EAAE,CAAC,uCAAuC,EAAE,MAAM;MAChD,MAAMC,GAAG,GAAGC,qBAAE,CAACC,gBAAgB,CAAC,aAAa,EAAEuB,WAAW,EAAExB,qBAAE,CAACE,YAAY,CAACC,MAAM,CAAC;MACnF,MAAMmB,gBAAgB,GAAG,KAAIjB,+BAAgB,EAAC,CAAC,CAACoB,qBAAqB,CAAC1B,GAAG,CAAC;MAC1E,MAAM2B,WAAW,GAAGJ,gBAAgB,CAACC,GAAG,CAAC,OAAO,CAAC;MAEjD,IAAAZ,cAAM,EAACe,WAAW,EAAEE,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAChB,EAAE,CAACiB,EAAE,CAACC,KAAK;IAC7D,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Identifier } from './identifier';
|
|
2
|
+
|
|
3
|
+
export class ExportIdentifier extends Identifier {
|
|
4
|
+
exported: true;
|
|
5
|
+
|
|
6
|
+
constructor(id: string, filePath: string, aliasId?: string, sourceFilePath?: string) {
|
|
7
|
+
super(id, filePath, aliasId, sourceFilePath);
|
|
8
|
+
this.exported = true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static isExportIdentifier(identifier: Identifier): identifier is ExportIdentifier {
|
|
12
|
+
return 'exported' in identifier;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type ExtractorOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* name of the string.
|
|
4
|
+
*/
|
|
5
|
+
name?: string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* tsconfig string path.
|
|
9
|
+
*/
|
|
10
|
+
tsconfig?: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* TODO: support typescript module path.
|
|
14
|
+
*/
|
|
15
|
+
// typescript?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* typescript compiler options. always overrides all.
|
|
19
|
+
*/
|
|
20
|
+
compilerOptions?: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Identifier } from './identifier';
|
|
2
|
+
|
|
3
|
+
export class IdentifierList {
|
|
4
|
+
constructor(readonly identifiers: Identifier[]) {}
|
|
5
|
+
|
|
6
|
+
find(identifier: Identifier) {
|
|
7
|
+
const result = this.identifiers.find((_identifier) => _identifier.isEqual(identifier));
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
includes(identifier: Identifier) {
|
|
12
|
+
return Boolean(this.find(identifier));
|
|
13
|
+
}
|
|
14
|
+
}
|
package/identifier.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class Identifier {
|
|
2
|
+
constructor(
|
|
3
|
+
readonly id: string,
|
|
4
|
+
readonly filePath: string,
|
|
5
|
+
readonly aliasId?: string,
|
|
6
|
+
readonly sourceFilePath?: string
|
|
7
|
+
) {}
|
|
8
|
+
|
|
9
|
+
isEqual(identifier: Identifier): boolean {
|
|
10
|
+
if (this.filePath !== identifier.filePath) return false;
|
|
11
|
+
if (Identifier.isDefault(identifier) && Identifier.isDefault(this)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (Identifier.isDefault(identifier) || Identifier.isDefault(this)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return this.id === identifier.id;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static isDefault(identifier: Identifier) {
|
|
21
|
+
return identifier.id === 'default';
|
|
22
|
+
}
|
|
23
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';
|
|
2
|
+
export { TypeScriptExtractor } from './typescript.extractor';
|
|
3
|
+
export { TypescriptCompiler } from './typescript.compiler';
|
|
4
|
+
export type {
|
|
5
|
+
TypescriptMain,
|
|
6
|
+
TsConfigTransformer,
|
|
7
|
+
SchemaTransformerSlot,
|
|
8
|
+
APITransformerSlot,
|
|
9
|
+
} from './typescript.main.runtime';
|
|
10
|
+
export type { TypeScriptCompilerOptions, TsCompilerOptionsWithoutTsConfig } from './compiler-options';
|
|
11
|
+
export { TypescriptAspect } from './typescript.aspect';
|
|
12
|
+
export * from './sourceFileTransformers';
|
|
13
|
+
export type { SchemaNodeTransformer, SchemaTransformer } from './schema-transformer';
|
|
14
|
+
export { SchemaExtractorContext } from './schema-extractor-context';
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/typescript",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.108",
|
|
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": "1.0.
|
|
9
|
+
"version": "1.0.108"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -17,46 +17,42 @@
|
|
|
17
17
|
"fs-extra": "10.0.0",
|
|
18
18
|
"yesno": "0.4.0",
|
|
19
19
|
"get-tsconfig": "4.2.0",
|
|
20
|
-
"core-js": "^3.0.0",
|
|
21
|
-
"@babel/runtime": "7.20.0",
|
|
22
20
|
"@teambit/semantics.entities.semantic-schema": "0.0.59",
|
|
23
21
|
"@teambit/harmony": "0.4.6",
|
|
24
22
|
"@teambit/bit-error": "0.0.404",
|
|
25
|
-
"@teambit/compiler": "1.0.
|
|
23
|
+
"@teambit/compiler": "1.0.108",
|
|
26
24
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.80",
|
|
27
|
-
"@teambit/builder": "1.0.
|
|
28
|
-
"@teambit/isolator": "1.0.
|
|
29
|
-
"@teambit/component": "1.0.
|
|
30
|
-
"@teambit/dependency-resolver": "1.0.
|
|
31
|
-
"@teambit/formatter": "1.0.
|
|
32
|
-
"@teambit/ts-server": "0.0.
|
|
33
|
-
"@teambit/aspect-loader": "1.0.
|
|
34
|
-
"@teambit/envs": "1.0.
|
|
35
|
-
"@teambit/logger": "0.0.
|
|
36
|
-
"@teambit/workspace": "1.0.
|
|
37
|
-
"@teambit/schema": "1.0.
|
|
38
|
-
"@teambit/scope": "1.0.
|
|
39
|
-
"@teambit/cli": "0.0.
|
|
40
|
-
"@teambit/pkg": "1.0.
|
|
41
|
-
"@teambit/watcher": "1.0.
|
|
25
|
+
"@teambit/builder": "1.0.108",
|
|
26
|
+
"@teambit/isolator": "1.0.108",
|
|
27
|
+
"@teambit/component": "1.0.108",
|
|
28
|
+
"@teambit/dependency-resolver": "1.0.108",
|
|
29
|
+
"@teambit/formatter": "1.0.108",
|
|
30
|
+
"@teambit/ts-server": "0.0.53",
|
|
31
|
+
"@teambit/aspect-loader": "1.0.108",
|
|
32
|
+
"@teambit/envs": "1.0.108",
|
|
33
|
+
"@teambit/logger": "0.0.933",
|
|
34
|
+
"@teambit/workspace": "1.0.108",
|
|
35
|
+
"@teambit/schema": "1.0.108",
|
|
36
|
+
"@teambit/scope": "1.0.108",
|
|
37
|
+
"@teambit/cli": "0.0.840",
|
|
38
|
+
"@teambit/pkg": "1.0.108",
|
|
39
|
+
"@teambit/watcher": "1.0.108"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
44
42
|
"@types/lodash": "4.14.165",
|
|
45
43
|
"@types/fs-extra": "9.0.7",
|
|
46
44
|
"@types/chai": "4.2.15",
|
|
47
45
|
"chai": "4.3.0",
|
|
48
|
-
"@types/react": "^17.0.8",
|
|
49
46
|
"@types/mocha": "9.1.0",
|
|
50
|
-
"@types/
|
|
51
|
-
"@types/
|
|
52
|
-
"@
|
|
53
|
-
"@types/testing-library__jest-dom": "5.9.5",
|
|
47
|
+
"@types/jest": "^29.2.2",
|
|
48
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
|
49
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13",
|
|
54
50
|
"@teambit/typescript.aspect-docs.typescript": "0.0.165"
|
|
55
51
|
},
|
|
56
52
|
"peerDependencies": {
|
|
57
|
-
"
|
|
58
|
-
"react": "^
|
|
59
|
-
"
|
|
53
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
54
|
+
"@types/react": "^18.2.12",
|
|
55
|
+
"@teambit/legacy": "1.0.624"
|
|
60
56
|
},
|
|
61
57
|
"license": "Apache-2.0",
|
|
62
58
|
"optionalDependencies": {},
|
|
@@ -70,7 +66,7 @@
|
|
|
70
66
|
},
|
|
71
67
|
"private": false,
|
|
72
68
|
"engines": {
|
|
73
|
-
"node": ">=
|
|
69
|
+
"node": ">=16.0.0"
|
|
74
70
|
},
|
|
75
71
|
"repository": {
|
|
76
72
|
"type": "git",
|
|
@@ -79,12 +75,9 @@
|
|
|
79
75
|
"keywords": [
|
|
80
76
|
"bit",
|
|
81
77
|
"bit-aspect",
|
|
78
|
+
"bit-core-aspect",
|
|
82
79
|
"components",
|
|
83
80
|
"collaboration",
|
|
84
|
-
"web"
|
|
85
|
-
"react",
|
|
86
|
-
"react-components",
|
|
87
|
-
"angular",
|
|
88
|
-
"angular-components"
|
|
81
|
+
"web"
|
|
89
82
|
]
|
|
90
83
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';
|
|
2
|
+
import { Network } from '@teambit/isolator';
|
|
3
|
+
import { BuildContext, BuildTask, BuiltTaskResult } from '@teambit/builder';
|
|
4
|
+
import { TypescriptAspect } from './typescript.aspect';
|
|
5
|
+
|
|
6
|
+
export class RemoveTypesTask implements BuildTask {
|
|
7
|
+
readonly aspectId = TypescriptAspect.id;
|
|
8
|
+
readonly name = 'RemoveTypesProp';
|
|
9
|
+
readonly description = 'remove the types prop from package.json';
|
|
10
|
+
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
11
|
+
await this.removeTypesFromPkgJson(context.capsuleNetwork);
|
|
12
|
+
|
|
13
|
+
const result = {
|
|
14
|
+
componentsResults: [],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
private async removeTypesFromPkgJson(capsuleNetwork: Network) {
|
|
20
|
+
await Promise.all(
|
|
21
|
+
capsuleNetwork.seedersCapsules.map(async (capsule) => {
|
|
22
|
+
const packageJson = PackageJsonFile.loadFromCapsuleSync(capsule.path);
|
|
23
|
+
// the types['index.ts'] is needed only during the build to avoid errors when tsc finds the
|
|
24
|
+
// same type once in the d.ts and once in the ts file.
|
|
25
|
+
// the reason for `packageJson.packageJsonObject.main` is that .d.ts components don't have a main file and they do need the types prop
|
|
26
|
+
if (packageJson.packageJsonObject.types && packageJson.packageJsonObject.main) {
|
|
27
|
+
delete packageJson.packageJsonObject.types;
|
|
28
|
+
await packageJson.write();
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|