brackets-babel-module-formatter
Advanced tools
Comparing version 1.0.0 to 1.1.0
39
index.js
@@ -1,4 +0,10 @@ | ||
var util = require('babel-core/lib/util'); | ||
var t = require('babel-core/lib/types'); | ||
/* eslint-env node */ | ||
/* eslint no-unused-vars:[2, {"vars": "all", "args": "none"}] */ | ||
"use strict"; | ||
// var util = require("babel-core/lib/util"); | ||
var t = require("babel-core/lib/types"); | ||
var EXPORT_NAME = "__export__"; | ||
module.exports = ModuleFormatter; | ||
@@ -11,6 +17,4 @@ | ||
// feel free to modify this however | ||
// save the original body | ||
var body = ast.body; | ||
// put together params for the wrapper function | ||
@@ -22,12 +26,14 @@ var params = [ | ||
]; | ||
// exports object | ||
var exportObj = t.variableDeclaration("var", [t.variableDeclarator(t.identifier(EXPORT_NAME), t.objectExpression([]))]); | ||
body.unshift(exportObj); | ||
var moduleExports = t.memberExpression(t.identifier("module"), t.identifier("exports")); | ||
var moduleExportsAssign = t.assignmentExpression("=", moduleExports, t.identifier(EXPORT_NAME)); | ||
body.push(t.expressionStatement(moduleExportsAssign)); | ||
// wrap the original body in a function | ||
var container = t.functionExpression(null, params, t.blockStatement(body)); | ||
// make a define call with the wrapper body | ||
var call = t.callExpression(t.identifier("define"), [container]); | ||
// assign a new body to the ast | ||
ast.body = [t.expressionStatement(call)]; | ||
}; | ||
@@ -43,8 +49,6 @@ | ||
var ref = t.callExpression(t.identifier("require"), [node.source]); | ||
if (specifier.imported) { | ||
ref = t.memberExpression(ref, specifier.imported); | ||
} | ||
nodes.push(t.variableDeclaration('var', [t.variableDeclarator(specifier.local, ref)])); | ||
} | ||
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(specifier.local, ref)])); | ||
}; | ||
@@ -54,2 +58,6 @@ | ||
// node is an ExportDeclaration | ||
if (node.declaration) { | ||
var assign = t.assignmentExpression("=", t.identifier(EXPORT_NAME), node.declaration); | ||
nodes.push(t.expressionStatement(assign)); | ||
} | ||
}; | ||
@@ -60,2 +68,7 @@ | ||
// node is an ExportDeclaration | ||
}; | ||
if (specifier.exported) { | ||
var left = t.memberExpression(t.identifier(EXPORT_NAME), specifier.exported); | ||
var assign = t.assignmentExpression("=", left, specifier.local); | ||
nodes.push(t.expressionStatement(assign)); | ||
} | ||
}; |
{ | ||
"name": "brackets-babel-module-formatter", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3171
60