grant / ts2gas

A function that transpiles TypeScript to Google Apps Script.
http://npmjs.com/ts2gas
MIT License
88 stars 11 forks source link

Support transpilation for V8 runtime #46

Closed shinout closed 4 years ago

shinout commented 4 years ago

Related to https://github.com/google/clasp/issues/735 https://developers.google.com/apps-script/guides/v8-runtime/migration

Now that we can use V8 runtime in GAS, it's better to generate less-transpiled files for it. There are some options for the way to support the feature.

  1. make "target" option injectable.
  2. pass runtimeType as the third argument // type RuntimeType = "V8" | "Rhino"
  3. export two functions: ts2gasV8 and ts2GasRhino

If you tell me which one is the best, I'm ready for PR for this.

PopGoesTheWza commented 4 years ago

I did some tests... https://docs.google.com/spreadsheets/d/1JIJac5lsS2d1Gm7u8Zk-cLAaGLIxh_wVlU44Iez96bU/edit?usp=sharing

It looks like the V8 runtime supports all ES2019 features.

ts2gas already supports transpileOptions as its second argument:

https://github.com/grant/ts2gas/blob/84d2d534769bd202b80e993b8b2309f11ff33add/src/index.ts#L9

So one could use something like:

const transpileOptions ={
    compilerOptions: {
      target: 'es2019',
    },
  }

But for it to work, the current target should be moved from statics to defaults

https://github.com/grant/ts2gas/blob/84d2d534769bd202b80e993b8b2309f11ff33add/src/index.ts#L176-L179

https://github.com/grant/ts2gas/blob/84d2d534769bd202b80e993b8b2309f11ff33add/src/index.ts#L157-L160

This small change should be reflected in the https://github.com/grant/ts2gas/blob/master/README.md

And add some basic test maybe.

shinout commented 4 years ago

@PopGoesTheWza Thanks:+1: Totally agree with your idea. Also thanks for your contribution.

PopGoesTheWza commented 4 years ago

ts2gas@3.5.1 released