grant / ts2gas

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

Bug/#71 fix undefined import modules #80

Open BSteffaniak opened 1 year ago

BSteffaniak commented 1 year ago

Hi again, this is my naive attempt at fixing #71.

This PR is based on top of #79, so a lot of the file changes may appear duplicated from there.

I'm not sure if my implementation in index.ts#createMockModuleImportStatement is the idiomatic way to achieve this functionality, but it seems to be working for the previous test cases and the few new test cases I have added:

image

Here is an example typescript input:

import { func } from 'bob';
func();

and with this PR, the produced output looks like this:

// Compiled using ts2gas 4.2.0 (TypeScript 4.9.5)
var exports = exports || {};
var module = module || { exports: exports };
var bob_1 = bob_1 || { func: func }; //import { func } from 'bob';
(0, bob_1.func)();

I'm also not sure what determines the suffix on the module names (e.g. the _1 part of bob_1), so it's just hardcoded to that currently.

Again, I'm not super familiar with the typescript compiler structure, so let me know if this is completely incorrect.

Thanks!