@babel/helper-split-export-declaration
Advanced tools
+8
-12
@@ -20,12 +20,9 @@ "use strict"; | ||
| function splitExportDeclaration(exportDeclaration) { | ||
| if (!exportDeclaration.isExportDeclaration()) { | ||
| throw new Error("Only export declarations can be split."); | ||
| if (!exportDeclaration.isExportDeclaration() || exportDeclaration.isExportAllDeclaration()) { | ||
| throw new Error("Only default and named export declarations can be split."); | ||
| } | ||
| const isDefault = exportDeclaration.isExportDefaultDeclaration(); | ||
| const declaration = exportDeclaration.get("declaration"); | ||
| const isClassDeclaration = declaration.isClassDeclaration(); | ||
| if (isDefault) { | ||
| const standaloneDeclaration = declaration.isFunctionDeclaration() || isClassDeclaration; | ||
| if (exportDeclaration.isExportDefaultDeclaration()) { | ||
| const declaration = exportDeclaration.get("declaration"); | ||
| const standaloneDeclaration = declaration.isFunctionDeclaration() || declaration.isClassDeclaration(); | ||
| const scope = declaration.isScope() ? declaration.scope.parent : declaration.scope; | ||
@@ -44,3 +41,3 @@ let id = declaration.node.id; | ||
| const updatedDeclaration = standaloneDeclaration ? declaration : variableDeclaration("var", [variableDeclarator(cloneNode(id), declaration.node)]); | ||
| const updatedDeclaration = standaloneDeclaration ? declaration.node : variableDeclaration("var", [variableDeclarator(cloneNode(id), declaration.node)]); | ||
| const updatedExportDeclaration = exportNamedDeclaration(null, [exportSpecifier(cloneNode(id), identifier("default"))]); | ||
@@ -55,8 +52,7 @@ exportDeclaration.insertAfter(updatedExportDeclaration); | ||
| return exportDeclaration; | ||
| } | ||
| if (exportDeclaration.get("specifiers").length > 0) { | ||
| } else if (exportDeclaration.get("specifiers").length > 0) { | ||
| throw new Error("It doesn't make sense to split exported specifiers."); | ||
| } | ||
| const declaration = exportDeclaration.get("declaration"); | ||
| const bindingIdentifiers = declaration.getOuterBindingIdentifiers(); | ||
@@ -63,0 +59,0 @@ const specifiers = Object.keys(bindingIdentifiers).map(name => { |
+4
-3
| { | ||
| "name": "@babel/helper-split-export-declaration", | ||
| "version": "7.16.7", | ||
| "version": "7.18.6", | ||
| "description": "", | ||
@@ -17,3 +17,3 @@ "repository": { | ||
| "dependencies": { | ||
| "@babel/types": "^7.16.7" | ||
| "@babel/types": "^7.18.6" | ||
| }, | ||
@@ -23,3 +23,4 @@ "engines": { | ||
| }, | ||
| "author": "The Babel Team (https://babel.dev/team)" | ||
| "author": "The Babel Team (https://babel.dev/team)", | ||
| "type": "commonjs" | ||
| } |
4389
1.71%51
-3.77%Updated