1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-03 20:30:04 +02:00

add some babel stuff

This commit is contained in:
s2
2018-05-05 15:35:25 +02:00
parent d17c4fe70c
commit e76e795120
604 changed files with 103725 additions and 62 deletions

View File

@@ -0,0 +1,23 @@
# @babel/helper-split-export-declaration
## API
```js
declare export default splitExportDeclaration(path: NodePath);
```
## Usage
```js
import traverse from "@babel/traverse";
import splitExportDeclaration from "@babel/helper-split-export-declaration";
// ...
traverse(file, {
ExportDefaultDeclaration(path) {
if (!path.get("declaration").isClassDeclaration()) return;
splitExportDeclaration(path);
},
});
```

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = splitExportDeclaration;
function t() {
var data = _interopRequireWildcard(require("@babel/types"));
t = function t() {
return data;
};
return data;
}
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function splitExportDeclaration(exportDeclaration) {
if (!exportDeclaration.isExportDeclaration()) {
throw new Error("Only export declarations can be splitted.");
}
var isDefault = exportDeclaration.isExportDefaultDeclaration();
var declaration = exportDeclaration.get("declaration");
var isClassDeclaration = declaration.isClassDeclaration();
if (isDefault) {
var standaloneDeclaration = declaration.isFunctionDeclaration() || isClassDeclaration;
var scope = declaration.isScope() ? declaration.scope.parent : declaration.scope;
var id = declaration.node.id;
var needBindingRegistration = false;
if (!id) {
needBindingRegistration = true;
id = scope.generateUidIdentifier("default");
if (standaloneDeclaration || declaration.isFunctionExpression() || declaration.isClassExpression()) {
declaration.node.id = t().cloneNode(id);
}
}
var updatedDeclaration = standaloneDeclaration ? declaration : t().variableDeclaration("var", [t().variableDeclarator(t().cloneNode(id), declaration.node)]);
var updatedExportDeclaration = t().exportNamedDeclaration(null, [t().exportSpecifier(t().cloneNode(id), t().identifier("default"))]);
exportDeclaration.insertAfter(updatedExportDeclaration);
exportDeclaration.replaceWith(updatedDeclaration);
if (needBindingRegistration) {
scope.registerBinding(isClassDeclaration ? "let" : "var", exportDeclaration);
}
return exportDeclaration;
}
if (exportDeclaration.get("specifiers").length > 0) {
throw new Error("It doesn't make sense to split exported specifiers.");
}
var bindingIdentifiers = declaration.getOuterBindingIdentifiers();
var specifiers = Object.keys(bindingIdentifiers).map(function (name) {
return t().exportSpecifier(t().identifier(name), t().identifier(name));
});
var aliasDeclar = t().exportNamedDeclaration(null, specifiers);
exportDeclaration.insertAfter(aliasDeclar);
exportDeclaration.replaceWith(declaration.node);
return exportDeclaration;
}

View File

@@ -0,0 +1,40 @@
{
"_from": "@babel/helper-split-export-declaration@7.0.0-beta.46",
"_id": "@babel/helper-split-export-declaration@7.0.0-beta.46",
"_inBundle": false,
"_integrity": "sha512-UT7acgV7wsnBPwnqslqcnUFvsPBP4TtVaYM82xPGA7+evAa8q8HXOmFk08qsMK/pX/yy4+51gJJwyw2zofnacA==",
"_location": "/@babel/helper-split-export-declaration",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@babel/helper-split-export-declaration@7.0.0-beta.46",
"name": "@babel/helper-split-export-declaration",
"escapedName": "@babel%2fhelper-split-export-declaration",
"scope": "@babel",
"rawSpec": "7.0.0-beta.46",
"saveSpec": null,
"fetchSpec": "7.0.0-beta.46"
},
"_requiredBy": [
"/@babel/traverse"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.46.tgz",
"_shasum": "6903893c72bb2a3d54ed20b5ff2aa8a28e8d2ea1",
"_spec": "@babel/helper-split-export-declaration@7.0.0-beta.46",
"_where": "/home/s2/Documents/Code/minifyfromhtml/node_modules/@babel/traverse",
"bundleDependencies": false,
"dependencies": {
"@babel/types": "7.0.0-beta.46"
},
"deprecated": false,
"description": "## API",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-split-export-declaration",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-split-export-declaration"
},
"version": "7.0.0-beta.46"
}