add custom module formatters
This commit is contained in:
28
MODULES.md
28
MODULES.md
@@ -108,3 +108,31 @@ export function bar() {
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Custom
|
||||
|
||||
```javascript
|
||||
module.exports = ModuleFormatter;
|
||||
|
||||
function ModuleFormatter() {
|
||||
|
||||
}
|
||||
|
||||
ModuleFormatter.prototype.import = function (node, nodes) {
|
||||
// node is an ImportDeclaration
|
||||
};
|
||||
|
||||
ModuleFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
// specifier is an ImportSpecifier
|
||||
// node is an ImportDeclaration
|
||||
};
|
||||
|
||||
ModuleFormatter.prototype.export = function (node, nodes) {
|
||||
// node is an ExportDeclaration
|
||||
};
|
||||
|
||||
ModuleFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
// specifier is an ExportSpecifier
|
||||
// node is an ExportDeclaration
|
||||
};
|
||||
```
|
||||
|
||||
@@ -41,7 +41,16 @@ File.normaliseOptions = function (opts) {
|
||||
|
||||
File.prototype.getModuleFormatter = function (type) {
|
||||
var ModuleLoader = transform.moduleFormatters[type];
|
||||
if (!ModuleLoader) throw new ReferenceError("unknown module formatter type " + type);
|
||||
|
||||
if (!ModuleLoader) {
|
||||
var loc = util.resolve(type)
|
||||
if (loc) ModuleLoader = require(loc);
|
||||
}
|
||||
|
||||
if (!ModuleLoader) {
|
||||
throw new ReferenceError("unknown module formatter type " + type);
|
||||
}
|
||||
|
||||
return new ModuleLoader(this);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user