Open smcjones opened 1 year ago
@smcjones I was facing this same issue and have proposed a PR to potentially fix this issue in #80.
Here is an example typescript input:
import { func } from 'bob';
func();
and with the 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)();
It's not the same solution you were proposing, but I think it would work for you and be the most compatible with how the typescript compiler generates its code.
Hey! I think this may or may not be related to an issue I have been encountering recently. I created a separate, simple project to see if I could replicate the issue and indeed I did. On my local machine, we have two typescript files, one that imports the other:
// functionA.ts
export function functionA(): void {
console.log('functionA')
}
// functionB.ts
import { functionA } from "./functionA";
export function functionB(): void {
functionA();
console.log('functionB');
}
After running a clasp push
...
// functionA.gs
// Compiled using ts2gas-test 1.0.0 (TypeScript 4.9.5)
var exports = exports || {};
var module = module || { exports: exports };
exports.functionA = void 0;
function functionA() {
console.log('functionA');
}
exports.functionA = functionA;
// functionB.gs
// Compiled using ts2gas-test 1.0.0 (TypeScript 4.9.5)
var exports = exports || {};
var module = module || { exports: exports };
exports.functionB = void 0;
//import { functionA } from "./functionA";
function functionB() {
(0, functionA_1.functionA)();
console.log('functionB');
}
exports.functionB = functionB;
If you try to run functionB
using the manual run button in the GAS IDE, you'll get this error:
ReferenceError: functionA_1 is not defined
functionB @ functionB.gs:7
Would be happy to connect with anyone about this issue, been a huge bummer for me lately. Curious to see if PR #80 might fix this
I posted a sub-optimal workaround on Stack Overflow to get around this issue. It's sub-optimal because you need to rewrite your functions as classes, which is obviously a huge pain in the neck.
I wrote a test:
Here's the output:
Expected output:
Alternatively, if
another_place.ts
exports files, a different expectation would be foranother_place.ts
to defineanother_place_1
as its export variable:Or a namespace...
another_place.ts
main.ts