@teambit/typescript 0.0.737 → 0.0.740

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.
Files changed (68) hide show
  1. package/dist/cmds/check-types.cmd.js.map +1 -1
  2. package/dist/cmds/init.cmd.js.map +1 -1
  3. package/dist/compiler-options.js.map +1 -1
  4. package/dist/exceptions/index.js.map +1 -1
  5. package/dist/exceptions/transformer-not-found.d.ts +2 -1
  6. package/dist/exceptions/transformer-not-found.js +3 -2
  7. package/dist/exceptions/transformer-not-found.js.map +1 -1
  8. package/dist/export-identifier.js.map +1 -1
  9. package/dist/export-list.js.map +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/schema-extractor-context.d.ts +4 -1
  12. package/dist/schema-extractor-context.js +20 -2
  13. package/dist/schema-extractor-context.js.map +1 -1
  14. package/dist/schema-transformer.js.map +1 -1
  15. package/dist/schema-transformer.plugin.js.map +1 -1
  16. package/dist/transformers/class-deceleration.js +9 -1
  17. package/dist/transformers/class-deceleration.js.map +1 -1
  18. package/dist/transformers/constructor.js.map +1 -1
  19. package/dist/transformers/enum-declaration.d.ts +10 -0
  20. package/dist/transformers/enum-declaration.js +60 -0
  21. package/dist/transformers/enum-declaration.js.map +1 -0
  22. package/dist/transformers/export-declaration.js.map +1 -1
  23. package/dist/transformers/function-declaration.js.map +1 -1
  24. package/dist/transformers/index-signature.js.map +1 -1
  25. package/dist/transformers/index.d.ts +1 -0
  26. package/dist/transformers/index.js +16 -0
  27. package/dist/transformers/index.js.map +1 -1
  28. package/dist/transformers/interface-declaration.js.map +1 -1
  29. package/dist/transformers/literal-type.js.map +1 -1
  30. package/dist/transformers/method-declaration.js.map +1 -1
  31. package/dist/transformers/method-signature.js.map +1 -1
  32. package/dist/transformers/property-declaration.js.map +1 -1
  33. package/dist/transformers/property-signature.js.map +1 -1
  34. package/dist/transformers/source-file-transformer.js.map +1 -1
  35. package/dist/transformers/type-alias.js.map +1 -1
  36. package/dist/transformers/utils/get-params.js +53 -7
  37. package/dist/transformers/utils/get-params.js.map +1 -1
  38. package/dist/transformers/utils/parse-type-from-quick-info.d.ts +1 -0
  39. package/dist/transformers/utils/parse-type-from-quick-info.js +12 -3
  40. package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
  41. package/dist/transformers/utils/to-function-schema.js.map +1 -1
  42. package/dist/transformers/utils/type-node-to-schema.js +34 -4
  43. package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
  44. package/dist/transformers/variable-declaration.js.map +1 -1
  45. package/dist/transformers/variable-statement.js.map +1 -1
  46. package/dist/typescript.aspect.js.map +1 -1
  47. package/dist/typescript.compiler.js.map +1 -1
  48. package/dist/typescript.compiler.spec.js.map +1 -1
  49. package/dist/typescript.composition.js.map +1 -1
  50. package/dist/typescript.extractor.d.ts +7 -1
  51. package/dist/typescript.extractor.js +30 -9
  52. package/dist/typescript.extractor.js.map +1 -1
  53. package/dist/typescript.main.runtime.d.ts +11 -2
  54. package/dist/typescript.main.runtime.js +17 -6
  55. package/dist/typescript.main.runtime.js.map +1 -1
  56. package/dist/typescript.parser.js.map +1 -1
  57. package/dist/typescript.parser.spec.js.map +1 -1
  58. package/exceptions/transformer-not-found.ts +4 -2
  59. package/package-tar/teambit-typescript-0.0.740.tgz +0 -0
  60. package/package.json +16 -15
  61. package/{preview-1652930732694.js → preview-1653449228788.js} +2 -2
  62. package/transformers/class-deceleration.ts +4 -1
  63. package/transformers/enum-declaration.ts +20 -0
  64. package/transformers/index.ts +1 -0
  65. package/transformers/utils/get-params.ts +53 -9
  66. package/transformers/utils/parse-type-from-quick-info.ts +9 -1
  67. package/transformers/utils/type-node-to-schema.ts +37 -4
  68. package/package-tar/teambit-typescript-0.0.737.tgz +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["typescript.parser.spec.ts"],"names":["describe","exampleArrowFunction","exampleFunction","exampleClass","it","ast","ts","createSourceFile","ScriptTarget","Latest","exports","TypeScriptParser","getExports","exportArrow","find","x","identifier","to","exist","exportFunction","exportClass","staticProperties","get","equal","exampleFile","parseStaticProperties","exportHello","undefined","has","be","false"],"mappings":";;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEAA,QAAQ,CAAC,kBAAD,EAAqB,MAAM;AACjCA,EAAAA,QAAQ,CAAC,YAAD,EAAe,MAAM;AAC3B,UAAMC,oBAAoB,GAAI;AAClC;AACA;AACA,KAHI;AAKA,UAAMC,eAAe,GAAI;AAC7B;AACA;AACA,KAHI;AAKA,UAAMC,YAAY,GAAI;AAC1B;AACA;AACA,KAHI;AAKAC,IAAAA,EAAE,CAAC,6BAAD,EAAgC,MAAM;AACtC,YAAMC,GAAG,GAAGC,sBAAGC,gBAAH,CAAoB,aAApB,EAAmCN,oBAAnC,EAAyDK,sBAAGE,YAAH,CAAgBC,MAAzE,CAAZ;;AACA,YAAMC,OAAO,GAAG,KAAIC,+BAAJ,IAAuBC,UAAvB,CAAkCP,GAAlC,CAAhB;AAEA,YAAMQ,WAAW,GAAGH,OAAO,CAACI,IAAR,CAAcC,CAAD,IAAOA,CAAC,CAACC,UAAF,KAAiB,OAArC,CAApB;AAEA,0BAAOH,WAAP,EAAoBI,EAApB,CAAuBC,KAAvB;AACD,KAPC,CAAF;AASAd,IAAAA,EAAE,CAAC,+BAAD,EAAkC,MAAM;AACxC,YAAMC,GAAG,GAAGC,sBAAGC,gBAAH,CAAoB,aAApB,EAAmCL,eAAnC,EAAoDI,sBAAGE,YAAH,CAAgBC,MAApE,CAAZ;;AACA,YAAMC,OAAO,GAAG,KAAIC,+BAAJ,IAAuBC,UAAvB,CAAkCP,GAAlC,CAAhB;AAEA,YAAMc,cAAc,GAAGT,OAAO,CAACI,IAAR,CAAcC,CAAD,IAAOA,CAAC,CAACC,UAAF,KAAiB,MAArC,CAAvB;AAEA,0BAAOG,cAAP,E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AAmCiB,WAAnC,EAAgDlB,sBAAGE,YAAH,CAAgBC,MAAhE,CAAZ;;AACA,YAAMY,gBAAgB,GAAG,KAAIV,+BAAJ,IAAuBc,qBAAvB,CAA6CpB,GAA7C,CAAzB;AACA,YAAMqB,WAAW,GAAGL,gBAAgB,CAACC,GAAjB,CAAqB,OAArB,CAApB;AAEA,0BAAOI,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAEE,GAAb,CAAiB,iBAAjB,CAAP,EAA4CX,EAA5C,CAA+CY,EAA/C,CAAkDC,KAAlD;AACD,KANC,CAAF;AAQA1B,IAAAA,EAAE,CAAC,uCAAD,EAA0C,MAAM;AAChD,YAAMC,GAAG,GAAGC,sBAAGC,gBAAH,CAAoB,aAApB,EAAmCiB,WAAnC,EAAgDlB,sBAAGE,YAAH,CAAgBC,MAAhE,CAAZ;;AACA,YAAMY,gBAAgB,GAAG,KAAIV,+BAAJ,IAAuBc,qBAAvB,CAA6CpB,GAA7C,CAAzB;AACA,YAAMqB,WAAW,GAAGL,gBAAgB,CAACC,GAAjB,CAAqB,OAArB,CAApB;AAEA,0BAAOI,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAEE,GAAb,CAAiB,qBAAjB,CAAP,EAAgDX,EAAhD,CAAmDY,EAAnD,CAAsDC,KAAtD;AACD,KANC,CAAF;AAOD,GAhDO,CAAR;AAiDD,CA3HO,CAAR","sourcesContent":["import ts from 'typescript';\nimport { expect } from 'chai';\n\nimport { TypeScriptParser } from './typescript.parser';\n\ndescribe('TypescriptParser', () => {\n describe('getExports', () => {\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 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 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"]}
1
+ {"version":3,"names":["describe","exampleArrowFunction","exampleFunction","exampleClass","it","ast","ts","createSourceFile","ScriptTarget","Latest","exports","TypeScriptParser","getExports","exportArrow","find","x","identifier","expect","to","exist","exportFunction","exportClass","staticProperties","get","equal","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 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 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 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;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEAA,QAAQ,CAAC,kBAAD,EAAqB,MAAM;EACjCA,QAAQ,CAAC,YAAD,EAAe,MAAM;IAC3B,MAAMC,oBAAoB,GAAI;AAClC;AACA;AACA,KAHI;IAKA,MAAMC,eAAe,GAAI;AAC7B;AACA;AACA,KAHI;IAKA,MAAMC,YAAY,GAAI;AAC1B;AACA;AACA,KAHI;IAKAC,EAAE,CAAC,6B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AAW,CAAEE,GAAb,CAAiB,iBAAjB,CAAP,EAA4CX,EAA5C,CAA+CY,EAA/C,CAAkDC,KAAlD;IACD,CANC,CAAF;IAQA3B,EAAE,CAAC,uCAAD,EAA0C,MAAM;MAChD,MAAMC,GAAG,GAAGC,qBAAA,CAAGC,gBAAH,CAAoB,aAApB,EAAmCkB,WAAnC,EAAgDnB,qBAAA,CAAGE,YAAH,CAAgBC,MAAhE,CAAZ;;MACA,MAAMa,gBAAgB,GAAG,KAAIX,+BAAJ,IAAuBe,qBAAvB,CAA6CrB,GAA7C,CAAzB;MACA,MAAMsB,WAAW,GAAGL,gBAAgB,CAACC,GAAjB,CAAqB,OAArB,CAApB;MAEA,IAAAN,cAAA,EAAOU,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAEE,GAAb,CAAiB,qBAAjB,CAAP,EAAgDX,EAAhD,CAAmDY,EAAnD,CAAsDC,KAAtD;IACD,CANC,CAAF;EAOD,CAhDO,CAAR;AAiDD,CA3HO,CAAR"}
@@ -1,13 +1,15 @@
1
1
  import ts, { Node } from 'typescript';
2
2
  import { Component } from '@teambit/component';
3
+ import { Location } from '@teambit/semantics.entities.semantic-schema';
3
4
 
4
5
  export class TransformerNotFound extends Error {
5
- constructor(readonly node: Node, readonly component: Component) {
6
+ constructor(readonly node: Node, readonly component: Component, location: Location) {
6
7
  super(
7
8
  `typescript: could not find schema transformer for node of kind ${node.kind} (${
8
9
  ts.SyntaxKind[node.kind]
9
10
  }) in component ${component.id.toString()}.
10
- node text: ${node.getText()}`
11
+ location: ${location.file}, line: ${location.line}, character: ${location.character}.
12
+ node-text: ${node.getText()}`
11
13
  );
12
14
  }
13
15
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/typescript",
3
- "version": "0.0.737",
3
+ "version": "0.0.740",
4
4
  "homepage": "https://bit.dev/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.737"
9
+ "version": "0.0.740"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -18,20 +18,21 @@
18
18
  "@babel/runtime": "7.12.18",
19
19
  "core-js": "^3.0.0",
20
20
  "@teambit/harmony": "0.3.3",
21
- "@teambit/compiler": "0.0.737",
21
+ "@teambit/compiler": "0.0.740",
22
22
  "@teambit/typescript.modules.ts-config-mutator": "0.0.68",
23
- "@teambit/component": "0.0.737",
24
- "@teambit/semantics.entities.semantic-schema": "0.0.11",
23
+ "@teambit/component": "0.0.740",
24
+ "@teambit/dependency-resolver": "0.0.740",
25
+ "@teambit/semantics.entities.semantic-schema": "0.0.13",
25
26
  "@teambit/ts-server": "0.0.32",
26
- "@teambit/aspect-loader": "0.0.737",
27
+ "@teambit/aspect-loader": "0.0.740",
27
28
  "@teambit/bit-error": "0.0.394",
28
- "@teambit/builder": "0.0.737",
29
- "@teambit/isolator": "0.0.737",
30
- "@teambit/logger": "0.0.583",
31
- "@teambit/schema": "0.0.737",
32
- "@teambit/cli": "0.0.491",
33
- "@teambit/pkg": "0.0.737",
34
- "@teambit/workspace": "0.0.737"
29
+ "@teambit/builder": "0.0.740",
30
+ "@teambit/isolator": "0.0.740",
31
+ "@teambit/logger": "0.0.584",
32
+ "@teambit/schema": "0.0.740",
33
+ "@teambit/workspace": "0.0.740",
34
+ "@teambit/cli": "0.0.492",
35
+ "@teambit/pkg": "0.0.740"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/lodash": "4.14.165",
@@ -47,7 +48,7 @@
47
48
  "@teambit/typescript.aspect-docs.typescript": "0.0.137"
48
49
  },
49
50
  "peerDependencies": {
50
- "@teambit/legacy": "1.0.271",
51
+ "@teambit/legacy": "1.0.272",
51
52
  "react-dom": "^16.8.0 || ^17.0.0",
52
53
  "react": "^16.8.0 || ^17.0.0"
53
54
  },
@@ -75,7 +76,7 @@
75
76
  "react": "-"
76
77
  },
77
78
  "peerDependencies": {
78
- "@teambit/legacy": "1.0.271",
79
+ "@teambit/legacy": "1.0.272",
79
80
  "react-dom": "^16.8.0 || ^17.0.0",
80
81
  "react": "^16.8.0 || ^17.0.0"
81
82
  }
@@ -1,2 +1,2 @@
1
- export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.737/dist/typescript.composition.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.737/dist/typescript.docs.mdx')]
1
+ export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.740/dist/typescript.composition.js')]
2
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.740/dist/typescript.docs.mdx')]
@@ -1,7 +1,7 @@
1
1
  import pMapSeries from 'p-map-series';
2
2
  import { compact } from 'lodash';
3
3
  import { ClassSchema, GetAccessorSchema, SetAccessorSchema } from '@teambit/semantics.entities.semantic-schema';
4
- import ts, { Node, ClassDeclaration } from 'typescript';
4
+ import ts, { Node, ClassDeclaration, isSemicolonClassElement } from 'typescript';
5
5
  import { SchemaTransformer } from '../schema-transformer';
6
6
  import { SchemaExtractorContext } from '../schema-extractor-context';
7
7
  import { ExportIdentifier } from '../export-identifier';
@@ -29,6 +29,9 @@ export class ClassDecelerationTransformer implements SchemaTransformer {
29
29
  if (isPrivate) {
30
30
  return null;
31
31
  }
32
+ if (isSemicolonClassElement(member)) {
33
+ return null;
34
+ }
32
35
  switch (member.kind) {
33
36
  case ts.SyntaxKind.GetAccessor: {
34
37
  const getter = member as ts.GetAccessorDeclaration;
@@ -0,0 +1,20 @@
1
+ import ts, { Node, EnumDeclaration } from 'typescript';
2
+ import { EnumSchema } from '@teambit/semantics.entities.semantic-schema';
3
+ import { SchemaTransformer } from '../schema-transformer';
4
+ import { SchemaExtractorContext } from '../schema-extractor-context';
5
+ import { ExportIdentifier } from '../export-identifier';
6
+
7
+ export class EnumDeclarationTransformer implements SchemaTransformer {
8
+ predicate(node: Node) {
9
+ return node.kind === ts.SyntaxKind.EnumDeclaration;
10
+ }
11
+
12
+ async getIdentifiers(node: EnumDeclaration): Promise<ExportIdentifier[]> {
13
+ return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];
14
+ }
15
+
16
+ async transform(enumDec: EnumDeclaration, context: SchemaExtractorContext) {
17
+ const members = enumDec.members.map((member) => member.name.getText());
18
+ return new EnumSchema(context.getLocation(enumDec), enumDec.name.getText(), members);
19
+ }
20
+ }
@@ -13,3 +13,4 @@ export { LiteralTypeTransformer } from './literal-type';
13
13
  export { IndexSignature } from './index-signature';
14
14
  export { InterfaceDeclarationTransformer } from './interface-declaration';
15
15
  export { MethodSignatureTransformer } from './method-signature';
16
+ export { EnumDeclarationTransformer } from './enum-declaration';
@@ -1,6 +1,19 @@
1
- import { ParameterSchema, SchemaNode, TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';
1
+ import {
2
+ InferenceTypeSchema,
3
+ ParameterSchema,
4
+ TupleTypeSchema,
5
+ TypeLiteralSchema,
6
+ SchemaNode,
7
+ } from '@teambit/semantics.entities.semantic-schema';
2
8
  import pMapSeries from 'p-map-series';
3
- import { ParameterDeclaration, NodeArray } from 'typescript';
9
+ import {
10
+ SyntaxKind,
11
+ ParameterDeclaration,
12
+ NodeArray,
13
+ isIdentifier,
14
+ BindingElement,
15
+ ArrayBindingElement,
16
+ } from 'typescript';
4
17
  import { SchemaExtractorContext } from '../../schema-extractor-context';
5
18
  import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
6
19
  import { typeNodeToSchema } from './type-node-to-schema';
@@ -12,22 +25,53 @@ export async function getParams(
12
25
  return pMapSeries(parameterNodes, async (param) => {
13
26
  return new ParameterSchema(
14
27
  context.getLocation(param),
15
- param.name.getText(),
28
+ getParamName(param),
16
29
  await getParamType(param, context),
17
30
  param.initializer ? param.initializer.getText() : undefined
18
31
  );
19
32
  });
20
33
  }
21
34
 
22
- /**
23
- * @todo: probably not needed. just call context.resolveType instead.
24
- */
35
+ function getParamName(param: ParameterDeclaration): string {
36
+ if (isIdentifier(param.name)) {
37
+ return param.name.getText();
38
+ }
39
+ // it's binding pattern, either an array or an object
40
+ const elements = param.name.elements.map((elem) => elem.getText());
41
+ const elementsStr = elements.join(', ');
42
+ if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
43
+ return `[ ${elementsStr} ]`;
44
+ }
45
+ // it's an object binding
46
+ return `{ ${elementsStr} }`;
47
+ }
48
+
25
49
  async function getParamType(param: ParameterDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {
26
50
  if (param.type) {
27
51
  const type = param.type;
28
52
  return typeNodeToSchema(type, context);
29
53
  }
30
- const info = await context.getQuickInfo(param.name);
31
- const parsed = parseTypeFromQuickInfo(info);
32
- return new TypeRefSchema(context.getLocation(param), parsed || 'any');
54
+ if (isIdentifier(param.name)) {
55
+ const info = await context.getQuickInfo(param.name);
56
+ const parsed = parseTypeFromQuickInfo(info);
57
+ return new InferenceTypeSchema(context.getLocation(param), parsed);
58
+ }
59
+ // it's binding pattern, either an array or an object
60
+ if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
61
+ const elements = await pMapSeries(param.name.elements, async (elem: ArrayBindingElement) => {
62
+ const info = await context.getQuickInfo(elem);
63
+ const parsed = parseTypeFromQuickInfo(info);
64
+ return new InferenceTypeSchema(context.getLocation(param), parsed);
65
+ });
66
+ return new TupleTypeSchema(context.getLocation(param), elements);
67
+ }
68
+ if (param.name.kind === SyntaxKind.ObjectBindingPattern) {
69
+ const elements = await pMapSeries(param.name.elements, async (elem: BindingElement) => {
70
+ const info = await context.getQuickInfo(elem.name);
71
+ const parsed = parseTypeFromQuickInfo(info);
72
+ return new InferenceTypeSchema(context.getLocation(param), parsed, elem.name.getText());
73
+ });
74
+ return new TypeLiteralSchema(context.getLocation(param), elements);
75
+ }
76
+ throw new Error(`unknown param type`);
33
77
  }
@@ -1,6 +1,8 @@
1
1
  // eslint-disable-next-line import/no-unresolved
2
2
  import protocol from 'typescript/lib/protocol';
3
3
 
4
+ export const UNRESOLVED = '<<unresolved>>';
5
+
4
6
  /**
5
7
  * try to parse the type from the quickinfo.
6
8
  * this is an error-prone process, we do our best here.
@@ -49,7 +51,13 @@ export function parseTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | u
49
51
  case 'function': {
50
52
  const split = displayString.split('): ');
51
53
  if (split.length !== 2) {
52
- throw new Error(`quickinfo of a function below was not implemented.\n${displayString}`);
54
+ // it's hard to determine where the return-type is. so it's better to show unresolved.
55
+ // maybe, in the UI, in this case, it's best to show the signature.
56
+ // e.g.
57
+ // (method) IssuesList.getIssue<T extends ComponentIssue>(IssueClass: {
58
+ // new (): T;
59
+ // }): T | undefined
60
+ return UNRESOLVED;
53
61
  }
54
62
  return split[1].trim();
55
63
  }
@@ -11,9 +11,14 @@ import {
11
11
  IntersectionTypeNode,
12
12
  UnionTypeNode,
13
13
  TypeLiteralNode,
14
+ ParenthesizedTypeNode,
15
+ TypePredicateNode,
16
+ isIdentifier,
17
+ IndexedAccessTypeNode,
14
18
  } from 'typescript';
15
19
  import {
16
20
  SchemaNode,
21
+ TypeRefSchema,
17
22
  TypeIntersectionSchema,
18
23
  TypeUnionSchema,
19
24
  TypeLiteralSchema,
@@ -24,6 +29,9 @@ import {
24
29
  TypeOperatorSchema,
25
30
  TupleTypeSchema,
26
31
  FunctionLikeSchema,
32
+ ParenthesizedTypeSchema,
33
+ TypePredicateSchema,
34
+ IndexedAccessSchema,
27
35
  } from '@teambit/semantics.entities.semantic-schema';
28
36
  import pMapSeries from 'p-map-series';
29
37
  import { SchemaExtractorContext } from '../../schema-extractor-context';
@@ -56,16 +64,19 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
56
64
  return typeOperator(node as TypeOperatorNode, context);
57
65
  case SyntaxKind.TupleType:
58
66
  return tupleType(node as TupleTypeNode, context);
67
+ case SyntaxKind.ParenthesizedType:
68
+ return parenthesizedType(node as ParenthesizedTypeNode, context);
59
69
  case SyntaxKind.TypePredicate:
70
+ return typePredicate(node as TypePredicateNode, context);
71
+ case SyntaxKind.IndexedAccessType:
72
+ return indexedAccessType(node as IndexedAccessTypeNode, context);
60
73
  case SyntaxKind.ConstructorType:
61
74
  case SyntaxKind.NamedTupleMember:
62
75
  case SyntaxKind.OptionalType:
63
76
  case SyntaxKind.RestType:
64
77
  case SyntaxKind.ConditionalType:
65
78
  case SyntaxKind.InferType:
66
- case SyntaxKind.ParenthesizedType:
67
79
  case SyntaxKind.ThisType:
68
- case SyntaxKind.IndexedAccessType:
69
80
  case SyntaxKind.MappedType:
70
81
  case SyntaxKind.TemplateLiteralType:
71
82
  case SyntaxKind.TemplateLiteralTypeSpan:
@@ -82,10 +93,10 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
82
93
  case SyntaxKind.JSDocNamepathType:
83
94
  case SyntaxKind.JSDocSignature:
84
95
  case SyntaxKind.JSDocTypeLiteral:
85
- throw new Error(`TypeNode "${SyntaxKind[node.kind]}" was not implemented yet.
96
+ throw new Error(`TypeNode ${node.kind} (probably ${SyntaxKind[node.kind]}) was not implemented yet.
86
97
  context: ${node.getText()}`);
87
98
  default:
88
- throw new Error(`Node "${SyntaxKind[node.kind]}" is not a TypeNode.
99
+ throw new Error(`Node ${node.kind} (probably ${SyntaxKind[node.kind]}) is not a TypeNode.
89
100
  context: ${node.getText()}`);
90
101
  }
91
102
  }
@@ -154,6 +165,10 @@ async function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContex
154
165
  async function typeReference(node: TypeReferenceNode, context: SchemaExtractorContext) {
155
166
  const name = node.typeName.getText();
156
167
  const type = await context.resolveType(node, name, false);
168
+ if (node.typeArguments && type instanceof TypeRefSchema) {
169
+ const args = await pMapSeries(node.typeArguments, (arg) => typeNodeToSchema(arg, context));
170
+ type.typeArgs = args;
171
+ }
157
172
  return type;
158
173
  }
159
174
 
@@ -210,3 +225,21 @@ async function tupleType(node: TupleTypeNode, context: SchemaExtractorContext) {
210
225
  });
211
226
  return new TupleTypeSchema(context.getLocation(node), elements);
212
227
  }
228
+
229
+ async function parenthesizedType(node: ParenthesizedTypeNode, context: SchemaExtractorContext) {
230
+ const type = await typeNodeToSchema(node.type, context);
231
+ return new ParenthesizedTypeSchema(context.getLocation(node), type);
232
+ }
233
+
234
+ async function typePredicate(node: TypePredicateNode, context: SchemaExtractorContext) {
235
+ const parameterName = isIdentifier(node.parameterName) ? node.parameterName.getText() : 'this';
236
+ const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;
237
+ const hasAssertsModifier = Boolean(node.assertsModifier);
238
+ return new TypePredicateSchema(context.getLocation(node), parameterName, type, hasAssertsModifier);
239
+ }
240
+
241
+ async function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExtractorContext) {
242
+ const objectType = await typeNodeToSchema(node.objectType, context);
243
+ const indexType = await typeNodeToSchema(node.indexType, context);
244
+ return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);
245
+ }