Split export extensions into 2 different plugins, update stage presets (#6080)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
45
packages/babel-plugin-transform-export-namespace/README.md
Normal file
45
packages/babel-plugin-transform-export-namespace/README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# babel-plugin-transform-export-namespace
|
||||
|
||||
> Compile export-ns-from statements to ES2015
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
export * as ns from 'mod';
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save-dev babel-plugin-transform-export-namespace
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["transform-export-namespace"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins transform-export-namespace script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["transform-export-namespace"]
|
||||
});
|
||||
```
|
||||
## References
|
||||
|
||||
* ~~[Proposal: Additional export-from statements in ES7](https://github.com/leebyron/ecmascript-more-export-from)~~ (Withdrawn)
|
||||
* [ECMAScript Proposal: export ns from](https://github.com/leebyron/ecmascript-export-ns-from)
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "babel-plugin-transform-export-namespace",
|
||||
"version": "7.0.0-alpha.19",
|
||||
"description": "Compile export namespace to ES2015",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-export-namespace",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"babel-plugin-syntax-export-extensions": "7.0.0-alpha.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-helper-plugin-test-runner": "7.0.0-alpha.19"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import syntaxExportExtensions from "babel-plugin-syntax-export-extensions";
|
||||
|
||||
export default function({ types: t }) {
|
||||
function build(node, nodes, scope) {
|
||||
const hasNoExportNs = node.specifiers.every(
|
||||
specifier => !t.isExportNamespaceSpecifier(specifier),
|
||||
);
|
||||
if (hasNoExportNs) return;
|
||||
|
||||
const specifier = node.specifiers.shift();
|
||||
const uid = scope.generateUidIdentifier(specifier.exported.name);
|
||||
|
||||
let newSpecifier;
|
||||
if (t.isExportNamespaceSpecifier(specifier)) {
|
||||
newSpecifier = t.importNamespaceSpecifier(uid);
|
||||
} else {
|
||||
newSpecifier = t.importDefaultSpecifier(uid);
|
||||
}
|
||||
nodes.push(t.importDeclaration([newSpecifier], node.source));
|
||||
nodes.push(
|
||||
t.exportNamedDeclaration(null, [
|
||||
t.exportSpecifier(uid, specifier.exported),
|
||||
]),
|
||||
);
|
||||
|
||||
build(node, nodes, scope);
|
||||
}
|
||||
|
||||
return {
|
||||
inherits: syntaxExportExtensions,
|
||||
|
||||
visitor: {
|
||||
ExportNamedDeclaration(path) {
|
||||
const { node, scope } = path;
|
||||
const nodes = [];
|
||||
build(node, nodes, scope);
|
||||
if (!nodes.length) return;
|
||||
|
||||
if (node.specifiers.length >= 1) {
|
||||
nodes.push(node);
|
||||
}
|
||||
path.replaceWithMultiple(nodes);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export v, * as ns from "mod";
|
||||
@@ -0,0 +1,4 @@
|
||||
import _v from "mod";
|
||||
export { _v as v };
|
||||
import * as _ns from "mod";
|
||||
export { _ns as ns };
|
||||
@@ -0,0 +1 @@
|
||||
export * as default from "foo";
|
||||
@@ -0,0 +1,2 @@
|
||||
import * as _default from "foo";
|
||||
export { _default as default };
|
||||
@@ -0,0 +1 @@
|
||||
export * as foo from "bar";
|
||||
@@ -0,0 +1,2 @@
|
||||
import * as _foo from "bar";
|
||||
export { _foo as foo };
|
||||
3
packages/babel-plugin-transform-export-namespace/test/fixtures/export-namespace/options.json
vendored
Normal file
3
packages/babel-plugin-transform-export-namespace/test/fixtures/export-namespace/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "transform-export-namespace"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import runner from "babel-helper-plugin-test-runner";
|
||||
|
||||
runner(__dirname);
|
||||
Reference in New Issue
Block a user