grant/ts2gas

This is screwing up arguments with default values

paxperscientiam opened this issue · 5 comments

Hello,

The following only holds if Google is using your library, as it seems. Transpiled files now start with this commend: "// Compiled using ts2gas 1.5.0 (TypeScript 3.2.4)"

Just started getting "InternalErrors" in appscript recently and it seems due to how ts2gas handles arguments with default values.

For example,

function JsonResponseHandler(url: string, query = {}, params = {muteHttpExceptions: true}, cacheName: string, cacheTime = 3600) {
...
}

This is now getting converted to this:

function JsonResponseHandler(url, query, params, cacheName, cacheTime) {
    if (query === void 0) {  }
    if (params === void 0) {  }
    if (cacheTime === void 0) {  }
}

Which sucks, because I now need to rejigger my code to get around this as the ts2gas is getting rid of default values for arguments.

Is this a bug or a matter of adjusting my typescript code?

Thank you!

grant commented

I'm getting this in the lastest ts2gas:

# testDefaultParams
v--TS--v
function JsonResponseHandler(url, query, params, cacheName, cacheTime) {
    if (query === void 0) { query = {}; }
    if (params === void 0) { params = { muteHttpExceptions: true }; }
    if (cacheTime === void 0) { cacheTime = 3600; }
}
–––
// Compiled using ts2gas 1.5.0 (TypeScript 3.2.2)
var exports = exports || {};
var module = module || { exports: exports };
function JsonResponseHandler(url, query, params, cacheName, cacheTime) {
    if (query === void 0) {
        query = {};
    }
    if (params === void 0) {
        params = { muteHttpExceptions: true };
    }
    if (cacheTime === void 0) {
        cacheTime = 3600;
    }
}
 ^--GS--^

I created a test for it:
a47d2de#diff-9c706fb89ddc3725ae3168d13b1298eaR155

Perhaps we just need to update clasp's ts2gas?

@grant inded, using code from latest PR, seems ok to me:

v--TS--v
function JsonResponseHandler(
  url: string,
  query = {},
  params = {muteHttpExceptions: true}, cacheName: string, cacheTime = 3600
) {
return;

–––
// Compiled using ts2gas 1.5.2 (TypeScript 3.2.2)
var exports = exports || {};
var module = module || { exports: exports };
function JsonResponseHandler(url, query, params, cacheName, cacheTime) {
    if (query === void 0) { query = {}; }
    if (params === void 0) { params = { muteHttpExceptions: true }; }
    if (cacheTime === void 0) { cacheTime = 3600; }
    return;
}
 ^--GS--^

Hi @grant , OK, so i'm not losing my mind.

Also, I see now that I didn't include the file heading:

// Compiled using ts2gas 1.5.0 (TypeScript 3.2.4)
var exports = exports || {};
var module = module || { exports: exports };

I'll reference your comment in the issue I opened for clasp. Thanks 👍

grant commented

Closing as I can't repro this.
Please re-open if this is still an issue.
I just bumped clasp's ts2gas too.

@grant per my amended comment, the problem was with ts2gas 1.5