zwitterion
zwitterion copied to clipboard
Whitespace transformation
Thanks so much for providing this tool! I've been frustrated at the lack of forthcoming workflows for developing with ESM for the browser. Today I installed zwitterion and I'm having a fantastic developer experience.
But
I rely heavily on returns in my code which normally allows for breakpoint-based debugging, and I can't find a way to avoid zwitterion eating up some of these in transpilation. For example, the following source:
export default function * crawl(node){
yield node
if(Array.isArray(node))
for(const child of node)
yield * crawl(child)
else
for(const subtree of ['instance', 'children'])
if(node[subtree])
return yield * crawl(node[subtree])
}
...Is served as follows:
var process = window.process;
if (!window.ZWITTERION_SOCKET) {
window.ZWITTERION_SOCKET = new WebSocket('ws://localhost:5001');
window.ZWITTERION_SOCKET.addEventListener('message', (message) => {
window.location.reload();
});
}
export default function* crawl(node) {
yield node;
if (Array.isArray(node)) for (const child of node) yield* crawl(child);else for (const subtree of ['instance', 'children']) if (node[subtree]) return yield* crawl(node[subtree]);
}
I believe this is an upstream longstanding bug with TypeScript (https://github.com/Microsoft/TypeScript/issues/843) - is there a way of avoiding TypeScript compilation, or is it essential to import transpilation?
Sorry, coming back to all of this after a long and interesting break. As far as I can remember, TypeScript transpilation is not essential, but I haven't put in the options for other compilation methods. To keep things as simple as possible starting out, I've just used the TypeScript compiler for everything. With recent developments in Babel, notably Babel 7 providing parsing for TypeScript if I'm not mistaken, this could change. It would probably be a good idea to allow options for which compiler to use, Babel, TypeScript, or even other compilers. That's all a bit in the future though. Another solution to your issue could be good sourcemap support, which wouldn't be too difficult to add.
I'm about to begin working on using babel to compile everything, we'll see if that helps.