Conversation
c1b0a3c to
86492ff
Compare
86492ff to
f26d470
Compare
src/transformation/utils/export.ts
Outdated
| // ts.Iterator is not a ES6-compatible iterator, because TypeScript targets ES5 | ||
| const it: Iterable<ts.Symbol> = { [Symbol.iterator]: () => scopeSymbol!.exports!.values() }; | ||
| return [...it].includes(symbol); | ||
| if (symbol.declarations.find(d => findFirstNodeAbove(d, ts.isBlock))) { |
There was a problem hiding this comment.
Having a block above isn't enough to match symbol identities there
export let a = 1;
(() => {
a = 2;
})();export let a = 1;
switch (0 as any) {
case 1:
let a = 2;
case 2:
a = 3
}There was a problem hiding this comment.
No longer using ts.isBlock
But I am curious about what is expected to happen in a switch statement like this
|
Actually, that's a much more complex problem than I've expected. Initially I've thought that exported symbol would have the same reference as local one, and so it would be possible to just use the old symbol matching logic there, but looking at it more, it actually makes sense that they are different. For example, it should be possible to give exported symbol a different name with I'm not sure what would be the best way to go with this issue for now. If we're okay to go with incomplete (but better than nothing) support, I think the simplest thing would be to move export statements to the bottom of generated file. At least it would be enough to support the example from OP. |
|
I think I managed to get around it without changing the existing export logic too much It should now be possible to export a variable under different names with export specifiers When reassigning the variable synchronisation should still occur let x = false;
export { x as a };
export { x as b };
x = true; // a and b now become truex = true;
// becomes `exports.b = exports.a = x = true;` in TypeScript -> JavaScript
// becomes `____exports.b = <iife chain>` in TypeScript -> Lua |
ark120202
left a comment
There was a problem hiding this comment.
The new symbol-based binding approach look very good!
Closes #430
x should now be
true.