pulumi/tools/cocojs
joeduffy ead6a107ee Implement record types and primary properties
This change emits all CocoJS interfaces as records.  This allows us to
safely construct instances of them from Python using anonymous properties,
essentially emulating object literals.

For example, given a CocoJs interface defined as such:

    interface Foo {
        x;
        y?;
        z;
    }

we can easily construct fresh instances using normal JS literals:

    let f = { x: 42, z: "bar" };

But, Python doesn't have the equivalent literal syntax, wedging us.
It's now possible to initialize an instance from CocoPy as follows:

    let f = Foo(x=42, z="bar")

This leverages the notion of records and primary properties, as
described in our CocoPack/CocoIL design documents.
2017-04-11 11:37:24 -07:00
..
cmd Update copyright notices from 2016 to 2017 2017-03-14 19:26:14 -07:00
lib Implement record types and primary properties 2017-04-11 11:37:24 -07:00
tests Implement record types and primary properties 2017-04-11 11:37:24 -07:00
.gitignore Coconut! 2017-02-25 07:25:33 -08:00
cocojs Coconut! 2017-02-25 07:25:33 -08:00
package.json Coconut! 2017-02-25 07:25:33 -08:00
README.md Add comment about adding cocojs to $PATH 2017-02-26 12:14:49 -08:00
tsconfig.json Coconut! 2017-02-25 07:25:33 -08:00
tslint.json Coconut! 2017-02-25 07:25:33 -08:00
yarn.lock Coconut! 2017-02-25 07:25:33 -08:00

CocoJS

This directory contains Coconut's JavaScript compiler.

It implements a subset of JavaScript, with optional TypeScript-style type annotations, and compiles that subset into CocoPack/IL.

Building and Testing

CocoJS is built independent from the overall Coconut toolchain. First clone and cd to the right place:

$ git clone git@github.com:pulumi/coconut
$ cd coconut/tools/cocojs

Next, install dependencies, ideally using Yarn:

$ yarn install

(NPM can be used instead, but Yarn offers better performance, reliability, and security, so it's what we use below.)

From there, to build:

$ yarn run build

It's possible to simply run the TypeScript compiler using tsc, however the Yarn build step performs a couple extra steps; namely, it runs TSLint and also copies some test baseline files into the right place.

Next, to test, simply run:

$ yarn run test

It will be obvious if the tests passed or failed and, afterwards, code coverage data will be output to the console.

After building, a typical developer setup would be to add tools/cocojs/ to your $PATH; there is a cocojs executable in the root directory that conveniently wraps invocation of the compiler, passing through any arguments.

Libraries

In order to use the Coconut libraries -- including the standard library -- you will need to do a few additional steps to prepare your developer workspace. Please see this document for details on how to do this.