Simplify the printing logic for ( before ambiguous tokens#16651
Simplify the printing logic for ( before ambiguous tokens#16651nicolo-ribaudo merged 1 commit intobabel:mainfrom
( before ambiguous tokens#16651Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57371 |
liuxingbaoyu
left a comment
There was a problem hiding this comment.
Amazing!
I ran a benchmark and in Babel 7 it's just as fast as before.
And in Babel 8 we can enable babelPluginInlineConstNumericObjects for generator to make it even faster!
| // @ts-expect-error todo(flow->ts) can this be removed? `.optional` looks to be not existing property | ||
| node.optional | ||
| ) { | ||
| this.token("?"); |
There was a problem hiding this comment.
This looks like the case for:
const ast = Babel.packages.parser.parse("type x = ? number; /**/", {plugins: ['flow']});
Babel.packages.generator.default(ast);
// Outputs: {code: 'type x = ?number; /**/', decodedMap: undefined}(but I can't test it easily through debugging or stepping into the code, since the repl build is helplessly minified - would be nice if a PR preview was readable/debuggable)
There was a problem hiding this comment.
https://astexplorer.net/#/gist/65e561e94ad90a154646cfd21be92f52/26ebbf2128f469b1469f574a3fb76b167b53f8e2
You can use it.
Also I remember that the repl has source maps, so debugging should be possible. :)
There was a problem hiding this comment.
@liuxingbaoyu Thank you! Good point, it works very nicely. Somehow I went through babeljs.io in source tab and not output.circle-artifacts.com... now that I could set a breakpoint I realized my code snippet wasn't for that case (so the comment may be correct lol).
Only strange thing is it's called optional in different places too, even though it's just nullable (optional in JS means some type or undefined).
There was a problem hiding this comment.
Thanks for the investigation, I'll re-check and see what we need to do here :)
Fixes #1, Fixes #2See #16648. With this change we don't need to manually list cases where
(is needed anymore, and we do not need to walk up in the tree.