grant / ts2gas

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

fix `export enum ...` output #31

Closed PopGoesTheWza closed 5 years ago

PopGoesTheWza commented 5 years ago

See my comments in #26:

export enum Languages ... produces an incorrect (Languages = Languages || (Languages = {})) trailing code. The correct resulting javascript should read (Languages = exports.Languages || (exports.Languages = {}))

grant commented 5 years ago

Please add a test case. Print the outputs of the test case in this PR.

PopGoesTheWza commented 5 years ago

There is already a test case with “export enum Language” defined. Actually, it is while checking this very test case that I found out the issue.

PopGoesTheWza commented 5 years ago

I will update with the output when done commuting

PopGoesTheWza commented 5 years ago
# testMultilineExports
v--TS--v
// next statement will be ignored
export { foo, bar }
  from "file";
// next statement will be preserved
/** Supported languages for localized data */
export enum Languages {
  /** English (USA) */
  eng_us = 'eng_us',
  /** French (France) */
  fre_fr = 'fre_fr',
}
export class Client {
  /** URL to the login endpoint */
  private readonly signinUrl: string;
}
export function foo() {}
export default Client;
export
  { ZipCodeValidator };
// now resume with next statement
–––
// Compiled using ts2gas 1.6.1 (TypeScript 3.3.3333)
var exports = exports || {};
var module = module || { exports: exports };
//export { foo, bar }\n  from "file";
// next statement will be preserved
/** Supported languages for localized data */
var Languages;
(function (Languages) {
    /** English (USA) */
    Languages["eng_us"] = "eng_us";
    /** French (France) */
    Languages["fre_fr"] = "fre_fr";
})(Languages = exports.Languages || (exports.Languages = {}));
var Client = /** @class */ (function () {
    function Client() {
    }
    return Client;
}());
exports.Client = Client;
function foo() { }
exports.foo = foo;
// now resume with next statement
 ^--GS--^
PopGoesTheWza commented 5 years ago

@grant please bear with me. I am confused about this close/reopen buttons. So this PR fixes an issue I ran into while investigating #26 Test case was already in there. I pasted the correct test output above. As per the issue itself, please take a moment to review it and comment.

grant commented 5 years ago

OK. Merged. I'll have to add actual tests instead of console.log-ing the test output.