daml/language-support
Martin Huschenbett d48698e43b
daml2ts: Fix the A:X vs A.B bug (#5226)
* daml2ts: Fix the A:X vs A.B bug

Currently, the TypeScript generated by `daml2ts` does not compile when
there are a modules `A` and `A.B` which both contain serializable types.
(Note: there can't be a type called `B` in `A` due to the name collision
check.)

Since fixing this within the current layout using TypeScript
namespaces would be very challenging since we would need to inject
subnamespaces into existing namespaces. Thus, we switch the code
generation to use ES2015 modules. Since TypeScript namespaces are
considered (somewhat) deprecated, this is a good move anyway.

As a result of this change to ES2015 we need to write `index.ts` files
at each node of the module hierarchy. These `index.ts` files reexport
the module at the current node (if present) and all child modules.

At the same time we also remove the default export of the top-level
`index.ts` file. It is not clear if they are actually useful and to
add them to the new scheme requires a technique that feels like a hack.

To give an example, assume we have modules `A` and `A.B.C`. We now write
the following directory structure:
```
src/
+- index.ts             <- reexports A
+- A/
   +- index.ts          <- reexports module.ts and B
   +- module.ts
   +- B/
      +- index.ts       <- reexport C
      +- C/
         +- index.ts    <- reexports module.ts
         +- module.ts
```
If you import the package like
```typescript
import * as foo from '@daml.js/foo-1.0.0';
```
you can acces the `A` and `A.B.C` modules as `foo.A` and `foo.A.B.C`.

CHANGELOG_BEGIN
CHANGELOG_END

* Adapt build-and-lint-test

CHANGELOG_BEGIN
CHANGELOG_END

* Add new test

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-27 10:27:18 +01:00
..
codegen-common replace DAML Authors with DA in copyright headers (#5228) 2020-03-27 01:26:10 +01:00
codegen-main replace DAML Authors with DA in copyright headers (#5228) 2020-03-27 01:26:10 +01:00
hs/bindings replace DAML Authors with DA in copyright headers (#5228) 2020-03-27 01:26:10 +01:00
java replace DAML Authors with DA in copyright headers (#5228) 2020-03-27 01:26:10 +01:00
scala replace DAML Authors with DA in copyright headers (#5228) 2020-03-27 01:26:10 +01:00
ts daml2ts: Fix the A:X vs A.B bug (#5226) 2020-03-27 10:27:18 +01:00