简体   繁体   English

为babel 6编写语法插件

[英]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. 现在我想尝试编写一个可以做到这一点的babel插件。

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 . 我认为我需要改变 - 或覆盖甚至 - es2015babel类型

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. 我没有找到关于babel的defineType工作或当前ImportDeclaration实现如何工作的大量文档或有用的帖子。

Can someone give me pointers on how the babel-types system works, specifically in relation to the ImportDeclaration ? 有人可以指点一下babel-type系统是如何工作的,特别是与ImportDeclaration

This repository seems to be building a babel-syntax plugin, but using a different method (via a babylon plugin). 这个存储库似乎正在构建一个babel语法插件,但使用不同的方法(通过babylon插件)。 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自己的语法插件只是空壳,在其他地方切换某些行为,这有点令人困惑: 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. 不幸的是,Babel / Babylon目前不支持任意自定义语法扩展,而且我们目前还没有对PR尚未达到阶段0的非官方语法扩展感兴趣。我们确实希望支持那一天,但不明显如何一旦你到达许多插件正在运行的点,这样做的方式实际上可以很好地协同工作。

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 该插件使用非官方API直接进入babylonhttps//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. lib文件夹不是公共文件夹,不受支持。 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 这也是为什么这个插件固定在一个特定的和过时的Babylon版本的原因: https//github.com/mbrowne/babel-dci/blob/master/babel-plugin-syntax-dci/package.json#L11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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