Created
August 26, 2014 15:47
-
-
Save matthewrobb/28ee13f11433131a28dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.setters = {}; | |
var __es6__import__ = function(name, setter) { | |
require(name); | |
var resolvedPath = require.resolve(name); | |
require.cache[resolvedPath].dependants.push(module); | |
module.setters[resolvedPath] = setter; | |
}; | |
module.dependants = []; | |
var __es6__export__ = (function() { | |
var values = Object.create(null), proxy = module.exports = Object.create(null); | |
return function(identifier, value) { | |
values[identifier] = value; | |
module.dependants.forEach(function(mod) { | |
mod.setters[module.filename](values); | |
}); | |
if (!Object.getOwnPropertyDescriptor(proxy, identifier)) { | |
Object.defineProperty(proxy, identifier, { | |
enumerable: true, | |
get: function() { | |
return values[identifier]; | |
} | |
}); | |
} | |
return value; | |
} | |
})(); | |
// export var bar; | |
var bar = __es6__export__("bar"); | |
// bar = 99; | |
bar = __es6__export__("bar", 99); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.setters = {}; | |
var __es6__import__ = function(name, setter) { | |
require(name); | |
var resolvedPath = require.resolve(name); | |
require.cache[resolvedPath].dependants.push(module); | |
module.setters[resolvedPath] = setter; | |
}; | |
module.dependants = []; | |
var __es6__export__ = (function() { | |
var values = Object.create(null), proxy = module.exports = Object.create(null); | |
return function(identifier, value) { | |
values[identifier] = value; | |
module.dependants.forEach(function(mod) { | |
mod.setters[module.filename](values); | |
}); | |
if (!Object.getOwnPropertyDescriptor(proxy, identifier)) { | |
Object.defineProperty(proxy, identifier, { | |
enumerable: true, | |
get: function() { | |
return values[identifier]; | |
} | |
}); | |
} | |
return value; | |
} | |
})(); | |
// import { bar } from "./bar"; | |
var bar; | |
__es6__import__("./bar", function(m) { | |
bar = m.bar; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment