Variable names changed when using import
awa2 opened this issue · 6 comments
// foo.ts
import Module from 'TypeScriptModule';
const module = new Module();
It transpiled below:
// foo.gs
var module = new TypeScriptModule_1["default"]()
So, TypeScriptModule_1 is not found
error has occuerd.
I know ignoring import/export statements has merged at issue#5, and it's a great work!
Adding _1
into module variable name when using TS module import, is it properly transpiling or not ?
If it's correct convert of TypeScript, I should update my TypeScript codes for Google Apps Script.
How should I do ?
@awa2 (cc @grant )
It looks like ts.transpileModule()
when given:
import Module from 'TypeScriptModule';
transpile it into
var TypeScriptModule_1 = require("TypeScriptModule");
var module = new TypeScriptModule_1["default"]();
and ts2gas is dropping the first statement.
Q: which version of ts2gas are you using?
Thank you, @PopGoesTheWza !
I got #17 and tried it.
It seemed that issue has fixed, but there are breaking changes from ts2gas@1.3.0.
Transpile differences between ts2gas@1.3.0
and ts2gas@
e955994 are below:
Original TS code
import Module from 'TypeScriptModule';
const module = new Module();
ts2gas@1.3.0 with typescript@3.2.2
// import Module from "TypeScriptModule";
var module = new Module();
This is what I expect.
ts2gas@e955994 with typescript@3.2.2
var module = new TypeScriptModule["default"]();
"TypeScriptModule" is not defined
error has occurred.
And also, require statements has something with wrong.
import { SubModule } from "TypeScriptModule";
const subModule = new SubModule();
vvv
var subModule = new ./TypeScriptModule.SubModule();
it makes syntax error.
I respect your TypeScript understanding and quick response for fixing.
I hope ts2gas@1.3.0 type convert because it makes to be useful for import/export using with Google Apps Script.
@awa2 i have var module = new Module();
fixed (no commit yet)
regarding the submodules, can you please try with ts2gas 1.3.0 and 1.5.0 the following:
import { SubModule1, Submodule2 } from "TypeScriptModule";
const subModule1 = new SubModule1();
const subModule2 = new SubModule2();
@awa2 if you want to test the latest PR which as been merged...
@PopGoesTheWza
I tested #20 , and it looks like all be good!
import { SubModule1, Submodule2 } from "TypeScriptModule";
const subModule1 = new SubModule1();
const subModule2 = new SubModule2();
vvv
//import { SubModule1, Submodule2 } from "TypeScriptModule";
var subModule1 = new SubModule1();
var subModule2 = new SubModule2();
Thank you!