Last active
August 29, 2015 14:19
-
-
Save IngwiePhoenix/e3743bcd3bc6bbdcf43f to your computer and use it in GitHub Desktop.
WebPack and OJ aren't behaving well. Showcasing issue I am having.
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
webpackJsonp([0,1],[ | |
/* 0 */ | |
/***/ function(module, exports, __webpack_require__) { | |
__webpack_require__(1); | |
__webpack_require__(2); | |
__webpack_require__(3); | |
console.log("main.js"); | |
/***/ }, | |
/* 1 */ | |
/***/ function(module, exports, __webpack_require__) { | |
var oj = $oj_oj = __webpack_require__(4) | |
var Foo = $oj_oj._registerClass({ $oj_c_Foo:1 }, null, function($oj_s, $oj_m) { function Foo() { this.constructor = Foo;this.$oj_id = ++$oj_oj._id;} | |
$oj_s.$oj_f_bard = function() { | |
console.log("Foo is in Baz' bar."); | |
} | |
$oj_s.$oj_f_getme = function() { | |
console.log(("3.0.0-dev.65")); | |
} | |
return Foo;}); | |
console.log($oj_oj.msgSend($oj_oj._cls.$oj_c_Foo,{ $oj_f_bard: 1 })); | |
/***/ }, | |
/* 2 */ | |
/***/ function(module, exports, __webpack_require__) { | |
var oj = $oj_oj = __webpack_require__(4) | |
var Bar = $oj_oj._registerClass({ $oj_c_Bar:1 }, { $oj_c_Foo:1 }, function($oj_s, $oj_m) { function Bar() { $oj_oj._cls.$oj_c_Foo.call(this);this.constructor = Bar;this.$oj_id = ++$oj_oj._id;} | |
$oj_s.$oj_f_isBard = function() { return true; } | |
return Bar;}); | |
/***/ }, | |
/* 3 */ | |
/***/ function(module, exports, __webpack_require__) { | |
var oj = $oj_oj = __webpack_require__(4) | |
var Foo; | |
console.log($oj_oj.msgSend(Foo,{ $oj_f_bard: 1 })); | |
/***/ }, | |
/* 4 */ | |
/***/ function(module, exports, __webpack_require__) { | |
/* WEBPACK VAR INJECTION */(function(global) {/* | |
runtime.js, runtime for the oj language | |
by musictheory.net, LLC. | |
Public Domain. | |
*/ | |
;(function() { "use strict"; | |
var root = this; | |
var previousOj = root.oj; | |
var sDebugStackDepth = 0; | |
var sDebugCallbacks = null; | |
var _classNameToMakerArrayMap = { }; | |
var _classNameToClassMap = { }; | |
var _classNameToSuperNameMap = { }; | |
function create(o) | |
{ | |
function f() {} | |
f.prototype = o; | |
return new f(); | |
} | |
function hop(obj, prop) | |
{ | |
return Object.prototype.hasOwnProperty.call(obj, prop); | |
} | |
function mixin(from, to, overwrite, callback) | |
{ | |
for (var key in from) { if (hop(from, key) && (overwrite || !hop(to, key))) { | |
var value = from[key]; | |
if (callback) callback(key, value); | |
to[key] = value; | |
}} | |
} | |
function _getDisplayName(className, methodName, prefix) | |
{ | |
if (className.indexOf("$oj$") != 0) { | |
className = _getReadableForRawName(className); | |
} | |
if (methodName.indexOf("$oj$") != 0) { | |
methodName = _getReadableForRawName(methodName); | |
methodName = methodName.replace(/([A-Za-z0-9])_/g, "$1:"); | |
} | |
return [ prefix, "[", className, " ", methodName, "]" ].join(""); | |
} | |
function throwUnrecognizedSelector(receiver, selector) | |
{ | |
throw new Error("Unrecognized selector: " + sel_getName(selector) + " sent to instance " + receiver); | |
} | |
function _registerClass(nameObject, superObject, callback) | |
{ | |
var isSubclassOfBase = false; | |
if (!superObject) { | |
superObject = { BaseObject: 1 }; | |
isSubclassOfBase = true; | |
} | |
var name = _getRawName(nameObject); | |
var superName = _getRawName(superObject); | |
var makerArray; | |
var cls; | |
_classNameToSuperNameMap[name] = superName; | |
var maker = function() { | |
var superclass = isSubclassOfBase ? BaseObject : _classNameToClassMap[superName]; | |
if (!superclass) return; | |
var instance_methods = { }; | |
var class_methods = { }; | |
cls = callback(class_methods, instance_methods); | |
cls.displayName = name; | |
cls["$oj_name"] = name; | |
cls["$oj_super"] = superclass; | |
cls.prototype = new superclass(); | |
mixin(superclass, cls); | |
mixin(class_methods, cls, true, function(key, method) { | |
method.displayName = _getDisplayName(name, key, "+"); | |
}); | |
mixin(instance_methods, cls.prototype, true, function(key, method) { | |
method.displayName = _getDisplayName(name, key, "-"); | |
}); | |
_classNameToClassMap[name] = cls; | |
var makerArray = _classNameToMakerArrayMap[name]; | |
if (makerArray) { | |
for (var i = 0, length = makerArray.length; i < length; i++) { | |
makerArray[i](); | |
} | |
} | |
} | |
if (isSubclassOfBase || _classNameToClassMap[superName]) { | |
maker(); | |
} else { | |
makerArray = _classNameToMakerArrayMap[superName]; | |
if (makerArray) { | |
makerArray.push(maker); | |
} else { | |
_classNameToMakerArrayMap[superName] = [ maker ] | |
} | |
} | |
} | |
function noConflict() | |
{ | |
root.oj = previousOj; | |
} | |
function getClassList() | |
{ | |
var results = [ ]; | |
for (var key in _classNameToClassMap) { if (hop(_classNameToClassMap, key)) { | |
results.append(_classNameToClassMap[key]); | |
}} | |
return results; | |
} | |
function getSubclassesOfClass(cls) | |
{ | |
if (!cls) return null; | |
var results = [ ]; | |
var name = cls["$oj_name"]; | |
for (var key in _classNameToSuperNameMap) { if (hop(_classNameToSuperNameMap, key)) { | |
var superName = _classNameToSuperNameMap[key]; | |
if (superName == name) { | |
results.push(_classNameToClassMap[key]); | |
} | |
}} | |
return results; | |
} | |
function isObject(object) | |
{ | |
return !!(object && object.constructor["$oj_name"]); | |
} | |
function setDebugCallbacks(callbacks) | |
{ | |
sDebugCallbacks = callbacks; | |
} | |
function _getRawName(selector) | |
{ | |
if (!selector) return null; | |
var name = Object.keys && Object.keys(selector)[0]; | |
if (!name) { | |
for (var key in selector) { if (selector.hasOwnProperty(key)) { | |
return key; | |
}} | |
} | |
return name; | |
} | |
function _getReadableForRawName(inName) | |
{ | |
if (inName.indexOf("$oj$") != 0) { | |
return inName.substr(6); | |
} | |
return inName; | |
} | |
function sel_getName(selector) | |
{ | |
if (!selector) return null; | |
var name = _getRawName(selector); | |
if (name) name = name.substr(6); | |
return name; | |
} | |
function sel_isEqual(sel1, sel2) | |
{ | |
return _getRawName(sel1) == _getRawName(sel2); | |
} | |
function class_getName(cls) | |
{ | |
if (cls && cls["$oj_name"]) { | |
return _getReadableForRawName(cls["$oj_name"]); | |
} | |
return null; | |
} | |
function class_getSuperclass(cls) | |
{ | |
return cls["$oj_super"]; | |
} | |
function class_isSubclassOf(cls, superclass) | |
{ | |
while (cls) { | |
if (cls === superclass) return true; | |
cls = class_getSuperclass(cls); | |
} | |
return false; | |
} | |
function object_getClass(object) | |
{ | |
return object.constructor; | |
} | |
function class_respondsToSelector(cls, selector) | |
{ | |
return !!cls.prototype[_getRawName(selector)]; | |
} | |
function msgSend(receiver, selector) | |
{ | |
return receiver ? ( | |
receiver[_getRawName(selector)] || | |
throwUnrecognizedSelector(receiver, selector) | |
).apply(receiver, Array.prototype.slice.call(arguments, 2)) : receiver; | |
} | |
msgSend.displayName = "oj.msgSend"; | |
function msgSend_Object_keys(receiver, selector) | |
{ | |
return receiver ? ( | |
receiver[Object.keys(selector)[0]] || | |
throwUnrecognizedSelector(receiver, selector) | |
).apply(receiver, Array.prototype.slice.call(arguments, 2)) : receiver; | |
} | |
msgSend_Object_keys.displayName = "oj.msgSend"; | |
function msgSend_debug(receiver, selector) | |
{ | |
if (!receiver) return receiver; | |
var name = _getRawName(selector); | |
var imp = receiver[imp]; | |
if (!imp) { | |
throwUnrecognizedSelector(receiver, selector) | |
} | |
if (++sDebugStackDepth > 256) { | |
throw new Error("Maximum call stack depth exceeded."); | |
} | |
var result; | |
try { | |
if (sDebugCallbacks && sDebugCallbacks.willSendMessage) sDebugCallbacks.willSendMessage(arguments); | |
result = receiver.apply(Array.prototype.slice.call(arguments, 2)); | |
if (sDebugCallbacks && sDebugCallbacks.didSendMessage) sDebugCallbacks.didSendMessage(arguments); | |
} finally { | |
sDebugStackDepth--; | |
} | |
return result; | |
} | |
msgSend_debug.displayName = "oj.msgSend"; | |
var oj = { | |
_id: 0, | |
_registerClass: _registerClass, | |
_cls: _classNameToClassMap, | |
noConflict: noConflict, | |
getClassList: getClassList, | |
getSubclassesOfClass: getSubclassesOfClass, | |
getSuperclass: class_getSuperclass, | |
isObject: isObject, | |
sel_getName: sel_getName, | |
sel_isEqual: sel_isEqual, | |
class_getName: class_getName, | |
class_getSuperclass: class_getSuperclass, | |
class_isSubclassOf: class_isSubclassOf, | |
class_respondsToSelector: class_respondsToSelector, | |
object_getClass: object_getClass, | |
msgSend: Object.keys ? msgSend_Object_keys : msgSend, | |
msgSend_debug: msgSend_debug, | |
setDebugCallbacks: setDebugCallbacks | |
} | |
var BaseObject = function BaseObject() { } | |
BaseObject.alloc = function() { return new this(); } | |
BaseObject["class"] = function() { return this; } | |
BaseObject.superclass = function() { return class_getSuperclass(this); } | |
BaseObject.className = function() { return class_getName(this); } | |
BaseObject.respondsToSelector_ = function(aSelector) { return !!this[_getRawName(aSelector)]; } | |
BaseObject.instancesRespondToSelector_ = function(aSelector) { return class_respondsToSelector(this, aSelector); } | |
BaseObject.isKindOfClass_ = function(cls) { return class_isSubclassOf(this, cls); } | |
BaseObject.isMemberOfClass_ = function(cls) { return this === cls; } | |
BaseObject.isSubclassOfClass_ = function(cls) { return class_isSubclassOf(this, cls); } | |
BaseObject.isEqual_ = function(other) { return this === other; } | |
BaseObject.prototype.init = function() { return this; } | |
BaseObject.prototype.copy = function() { return object_getClass(this).alloc().init(); } | |
BaseObject.prototype.superclass = function() { return class_getSuperclass(object_getClass(this)); } | |
BaseObject.prototype["class"] = function() { return object_getClass(this); } | |
BaseObject.prototype.className = function() { return class_getName(object_getClass(this)); } | |
BaseObject.prototype.respondsToSelector_ = function(aSelector) { return class_respondsToSelector(object_getClass(this), aSelector); } | |
BaseObject.prototype.performSelector_ = function(aSelector) { return oj.msgSend(this, aSelector); } | |
BaseObject.prototype.performSelector_withObject_ = function(aSelector, object) { return oj.msgSend(this, aSelector, object); } | |
BaseObject.prototype.performSelector_withObject_withObject_ = function(aSelector, o1, o2) { return oj.msgSend(this, aSelector, o1, o2); } | |
BaseObject.prototype.description = function() { return "<" + this.className() + " " + this["$oj_id"] + ">" } | |
BaseObject.prototype.toString = function() { return this.description(); } | |
BaseObject.prototype.isKindOfClass_ = function(cls) { return class_isSubclassOf(object_getClass(this), cls); } | |
BaseObject.prototype.isMemberOfClass_ = function(cls) { return object_getClass(this) === cls; } | |
BaseObject.prototype.isEqual_ = function(other) { return this === other; } | |
_classNameToClassMap["BaseObject"] = BaseObject; | |
if (true) { | |
module.exports = oj; | |
if (typeof global != "undefined" && typeof global != "function") { | |
global["$oj_oj"] = oj; | |
} | |
} else if (typeof define === "function" && define.amd) { | |
define(oj); | |
} else { | |
root.oj = root["$oj_oj"] = oj; | |
} | |
}).call(this); | |
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) | |
/***/ } | |
]); |
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
var ojc = require("ojc").compile; | |
var lu = require("loader-utils"); | |
var path = require("path"); | |
// Compiler | |
module.exports = function OJ(source,map) { | |
// Header | |
var header = [ | |
// Import the runtime | |
"var oj = require('!!ojc/src/runtime')", | |
].join("\n"); | |
// OJ is cool like this. | |
if(this.cacheable) this.cacheable(); | |
// The query should be - almost! - the OJ options | |
var options = lu.parseQuery(this.query); | |
var rawFile = this.resourcePath.replace(this.options.context, ""); | |
if(rawFile.charAt(0)) rawFile = rawFile.substr(1); | |
options.files = [{ | |
path: rawFile, | |
contents: source | |
}]; | |
// Make WebPack aware of what we are planning. | |
this.addDependency(require.resolve("ojc/src/runtime.js")); | |
// Do it. | |
var _this = this; | |
var cb = this.async(); | |
if(!cb) { | |
throw new Error([ | |
"The OJ loader must run in async manners.", | |
"Check your config/invocation." | |
].join(" ")); | |
} | |
ojc(options, function(err, result){ | |
if(err) { | |
cb(err); | |
} else { | |
for(var i in result.warnings) { | |
var warning = result.warnings[i]; | |
_this.emitWarning(warning); | |
} | |
cb(err, header+result.code, result.map); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment