Private field support in babel-template
See original GitHub issueCurrent Behavior An error is thrown when templates containing private fields are parsed.
Input Code
module.exports = function ({ template }) {
const set_private = template`this.#IDENT = VALUE`;
};
Expected behavior/code I would expect to be able to correctly parse and use templates containing private fields.
Environment (fairly certain none of this matters except Babel version)
- Babel version: 7.4.4
- Node/npm version: Node 12
- OS: Ubuntu 19.04
- Monorepo: no
- How you are using Babel: CLI
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Babel 7.14 enables class fields & private methods by default ...
Babel 7.14 enables class fields & private methods by default in @babel/preset-env ... Babel is a free and open-source JavaScript transcompiler. It ...
Read more >babel/template
You can use two different kinds of placeholders: syntactic placeholders (e.g. %%name%% ) or identifier placeholders (e.g. NAME ). @babel/template supports both ...
Read more >@babel/template | Yarn - Package Manager
(@nicolo-ribaudo); #10483 [parser] Add support for private fields in TypeScript. (@nicolo-ribaudo). babel-generator , babel-parser , babel-types.
Read more >@babel/template 7.7.0 on Node.js Yarn - NewReleases.io
(@nicolo-ribaudo); #10483 [parser] Add support for private fields in TypeScript. (@nicolo-ribaudo). babel-generator , babel-parser , babel-types.
Read more >How to remove the surround IIFE from @babel/template?
Thanks for the help of loganfsmyth on Slack, the problem was finally resolved. I should replace the node of whole export default but...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Currently it can be replaced with the following code:
Just for reference, here’s something that could trivially be replaced with a template if/when private fields (and other context-dependent nodes) are allowed within templates.
That could be trivially replaced with the following.
Needless to say the latter is far more readable and maintainable. It’s also trivial to write (I did it off the top of my head), where explicitly writing out the AST is tedious and error-prone.