Comparing version 0.0.5 to 0.0.6
@@ -113,17 +113,19 @@ var hasOwn = Object.prototype.hasOwnProperty; | ||
parts.push( | ||
"module.import(", | ||
parts.push(toModuleImport( | ||
this.code.slice(decl.source.start, | ||
decl.source.end) | ||
); | ||
decl.source.end), | ||
computeSpecifierMap(decl.specifiers) | ||
)); | ||
if (decl.specifiers.length === 0) { | ||
parts.push(");"); | ||
return parts.join(""); | ||
} | ||
return parts.join(""); | ||
}; | ||
parts.push(",{"); | ||
function computeSpecifierMap(specifiers) { | ||
var specifierMap; | ||
decl.specifiers.forEach(function (s, i) { | ||
var local = s.local.name; | ||
specifiers.forEach(function (s) { | ||
var local = | ||
s.type === "ExportSpecifier" ? s.exported.name : | ||
s.local.name; | ||
var imported = | ||
@@ -133,4 +135,27 @@ s.type === "ImportSpecifier" ? s.imported.name : | ||
s.type === "ImportNamespaceSpecifier" ? "*" : | ||
s.type === "ExportSpecifier" ? s.local.name : | ||
null; | ||
specifierMap = specifierMap || {}; | ||
specifierMap[local] = imported; | ||
}); | ||
return specifierMap; | ||
} | ||
function toModuleImport(source, specifierMap, returnTrue) { | ||
var parts = ["module.import(", source]; | ||
var locals = specifierMap && Object.keys(specifierMap); | ||
if (! locals || locals.length === 0) { | ||
parts.push(");"); | ||
return parts.join(""); | ||
} | ||
parts.push(",{"); | ||
locals.forEach(function (local, i) { | ||
var isLast = i === locals.length - 1; | ||
var imported = specifierMap[local]; | ||
var valueArg = "v"; | ||
@@ -143,3 +168,2 @@ if (valueArg === local) { | ||
var isLast = i === decl.specifiers.length - 1; | ||
parts.push( | ||
@@ -149,2 +173,3 @@ JSON.stringify(imported), | ||
local, "=", valueArg, | ||
returnTrue ? ";return true" : "", | ||
isLast ? "}" : "}," | ||
@@ -157,3 +182,3 @@ ); | ||
return parts.join(""); | ||
}; | ||
} | ||
@@ -179,3 +204,23 @@ Cp.ExportAllDeclaration = function (decl) { | ||
if (decl.specifiers) { | ||
// TODO | ||
if (decl.source) { | ||
var map = computeSpecifierMap(decl.specifiers); | ||
if (map) { | ||
var newMap = {}; | ||
Object.keys(map).forEach(function (local) { | ||
newMap["exports." + local] = map[local]; | ||
}); | ||
map = newMap; | ||
} | ||
return toModuleImport( | ||
this.code.slice(decl.source.start, | ||
decl.source.end), | ||
map, true | ||
); | ||
} else { | ||
// TODO | ||
} | ||
} | ||
@@ -182,0 +227,0 @@ |
{ | ||
"name": "reify", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": "Ben Newman <ben@benjamn.com>", |
@@ -8,3 +8,3 @@ # re•i•fy <sub>_verb, formal_</sub> [![Build Status](https://travis-ci.org/benjamn/reify.svg?branch=master)](https://travis-ci.org/benjamn/reify) | ||
Well, ok, one caveat: this package isn't ready for production use just yet. As of this writing, the repository is all of two days old! Watch this space to find out when `reify` is safe to use. | ||
Well, ok, one caveat: this package isn't ready for production use just yet. As of this writing, the repository is all of two days old! Watch this space to find out when `reify` is safe to use. | ||
@@ -11,0 +11,0 @@ Installation |
@@ -27,2 +27,8 @@ var assert = require("assert"); | ||
}); | ||
it("should allow named re-exports", function test() { | ||
import { a, v } from "./export-some.js"; | ||
assert.strictEqual(a, "a"); | ||
assert.strictEqual(v, "b"); | ||
}); | ||
}); | ||
@@ -32,3 +38,3 @@ | ||
it("should fire setters if already loaded", function () { | ||
// The "module" module is loaded in ../lib/node.js befoe we begin | ||
// The "module" module is required in ../lib/node.js before we begin | ||
// compiling anything. | ||
@@ -35,0 +41,0 @@ import { Module as M } from "module"; |
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
16688
16
382