asarazan / martok

https://www.npmjs.com/package/martok
10 stars 0 forks source link

Support complex types with type expansion #70

Closed sam-bunger closed 1 year ago

sam-bunger commented 1 year ago

Flattening Expansion Support

This serves to flatten certain complex typescript types for the purpose of parsing a much simpler typescript AST.

To do this, I created a Flattener class which is responsible for flattening types and recompiling the code to create a new ts.Program object.

How to use

Add the flag --experimentalTypeExpansion or -f

Tests

Additional changes

type NullFoo = { bar: string | null; // This field will be treated at optional in kotlin }

github-actions[bot] commented 1 year ago

Coverage report

St.:grey_question:
Category Percentage Covered / Total
🟒 Statements
94.17% (-0.05% πŸ”»)
1050/1115
🟒 Branches
88.31% (-0.64% πŸ”»)
491/556
🟒 Functions
95.39% (+1.03% πŸ”Ό)
207/217
🟒 Lines
95.56% (+0.15% πŸ”Ό)
990/1036
Show new covered files 🐣
|
St.:grey_question:
| File | Statements | Branches | Functions | Lines | | :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------- | :--------- | :------- | :-------- | :---- | | 🟒 |
`...` / TypeExpander.ts
| 97.44% | 84.62% | 100% | 100% | | 🟒 |
`...` / TsCompiler.ts
| 90.91% | 0% | 100% | 100% |
Show files with reduced coverage πŸ”»
|
St.:grey_question:
| File | Statements | Branches | Functions | Lines | | :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------- | :------------------------------------------------------------- | :-------------------------------------------------------------- | :------------------------------------------------------------- | :------------------------------------------------------------- | | 🟒 |
`...` / ImportGenerator.ts
|
90.32% (-5.97% πŸ”»)
|
61.54% (-11.19% πŸ”»)
| 100% |
96.43% (-3.57% πŸ”»)
| | 🟒 |
`...` / KlassGenerator.ts
|
95.93% (-0.16% πŸ”»)
| 93.16% | 100% |
95.69% (-0.14% πŸ”»)
| | 🟒 | kotlin/Klass.ts |
81.13% (-3.77% πŸ”»)
| 100% |
76.19% (-4.76% πŸ”»)
|
81.13% (-3.77% πŸ”»)
| | 🟒 |
`...` / MemberHelpers.ts
|
91.96% (-3.78% πŸ”»)
|
91.21% (-2.77% πŸ”»)
| 100% |
94.06% (-4.74% πŸ”»)
|

Test suite run success

39 tests passing in 5 suites.

Report generated by πŸ§ͺjest coverage report action from 8193cedc217f133d61fac51992cec7fc9fd05702

sam-bunger commented 1 year ago

not sure why that test is failing, testing out rn

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 95.75% and project coverage change: +0.06 :tada:

Comparison is base (e6015ac) 95.12% compared to head (8193ced) 95.18%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #70 +/- ## ========================================== + Coverage 95.12% 95.18% +0.06% ========================================== Files 28 29 +1 Lines 1087 1205 +118 Branches 257 279 +22 ========================================== + Hits 1034 1147 +113 - Misses 50 55 +5 Partials 3 3 ``` | [Impacted Files](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan) | Coverage Ξ” | | |---|---|---| | [src/martok/declarations/DeclarationGenerator.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9kZWNsYXJhdGlvbnMvRGVjbGFyYXRpb25HZW5lcmF0b3IudHM=) | `100.00% <ΓΈ> (ΓΈ)` | | | [src/martok/processing/SanitizeNames.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9wcm9jZXNzaW5nL1Nhbml0aXplTmFtZXMudHM=) | `100.00% <ΓΈ> (ΓΈ)` | | | [src/martok/ImportGenerator.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9JbXBvcnRHZW5lcmF0b3IudHM=) | `96.87% <75.00%> (-3.13%)` | :arrow_down: | | [src/typescript/MemberHelpers.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL3R5cGVzY3JpcHQvTWVtYmVySGVscGVycy50cw==) | `93.65% <76.66%> (-4.41%)` | :arrow_down: | | [src/martok/Martok.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9NYXJ0b2sudHM=) | `87.96% <94.44%> (+0.33%)` | :arrow_up: | | [src/kotlin/KlassPrinter.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL2tvdGxpbi9LbGFzc1ByaW50ZXIudHM=) | `98.29% <100.00%> (ΓΈ)` | | | [src/martok/TsCompiler.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9Uc0NvbXBpbGVyLnRz) | `100.00% <100.00%> (ΓΈ)` | | | [src/martok/declarations/EnumGenerator.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9kZWNsYXJhdGlvbnMvRW51bUdlbmVyYXRvci50cw==) | `100.00% <100.00%> (ΓΈ)` | | | [src/martok/declarations/KlassGenerator.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9kZWNsYXJhdGlvbnMvS2xhc3NHZW5lcmF0b3IudHM=) | `96.35% <100.00%> (-0.11%)` | :arrow_down: | | [src/martok/declarations/StringEnumGenerator.ts](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan#diff-c3JjL21hcnRvay9kZWNsYXJhdGlvbnMvU3RyaW5nRW51bUdlbmVyYXRvci50cw==) | `100.00% <100.00%> (ΓΈ)` | | | ... and [5 more](https://codecov.io/gh/asarazan/martok/pull/70?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan) | | ... and [1 file with indirect coverage changes](https://codecov.io/gh/asarazan/martok/pull/70/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan) Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Aaron+Sarazan)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

sam-bunger commented 1 year ago

Ooo more test coverage!

sam-bunger commented 1 year ago

I renamed the Flattener class to TypeExpander. I did this because I feel like expanding is a better word to describe what the user see happening to these types. So now if the user want's a type to be fully expanded, they add the @expand tag in their JSDocs.