简体   繁体   中英

Writing a syntax plugin for babel 6

I've recently posted a proposal to es-discuss about an idea I've had. And now I want to try and write a babel plugin that would do this.

Short version, I want to do/support this:

import { x, y, z } as myLib from 'lib';

I think I need to change -or overwrite even- the babel-types for es2015 .

I'm not finding a lot of documentation or helpful posts about about the babel's defineType works or how the the current ImportDeclaration implementation works.

Can someone give me pointers on how the babel-types system works, specifically in relation to the ImportDeclaration ?

This repository seems to be building a babel-syntax plugin, but using a different method (via a babylon plugin). Is this the way to do it?

It's a bit confusing to see all of babel's own syntax plugin are just empty shells that toggle some behavior somewhere else: babel-plugin-syntax-class-properties/src/index.js

Babel and babylon are amazing, I'd like to send out a big thanks to the people who are making it happen!

Unfortunately, Babel/Babylon does not currently support arbitrary custom syntax extensions, and we're not currently interested in PRs for unofficial syntax extensions that had not yet reached stage 0. We do want to support that one day, but it's not obvious how to do that in a way that would actually play nicely together once you get to a point where many plugins are running.

That plugin is using an unofficial API by reaching directly into babylon : https://github.com/mbrowne/babel-dci/blob/a766680b060ab1aa9601c4c14c5b1e0d514ec314/babel-plugin-syntax-dci/src/babylonPlugin.js#L6

import { types as tt } from "babylon/lib/tokenizer/types";
import Parser from "babylon/lib/parser";

The lib folder is not public and is not supported. This is also why this plugin has pinned itself to a specific and outdated version of Babylon: https://github.com/mbrowne/babel-dci/blob/master/babel-plugin-syntax-dci/package.json#L11

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM