Merge pull request #1189 from tivac/bundle-renaming
Make bundle collision renaming more strict
This commit is contained in:
commit
c5d3929b17
2 changed files with 26 additions and 22 deletions
|
|
@ -73,7 +73,8 @@ module.exports = function(input, output, options) {
|
||||||
|
|
||||||
function fixCollisions(code) {
|
function fixCollisions(code) {
|
||||||
for (var variable in usedVariables) {
|
for (var variable in usedVariables) {
|
||||||
var collision = new RegExp("([^\\.])" + variable + "\\b(?![\"'`])", "g")
|
var collision = new RegExp("([^\\.])\\b" + variable + "\\b(?![\"'`])", "g")
|
||||||
|
// var collision = new RegExp("([^\\.])" + variable + "\\b(?![\"'`])", "g")
|
||||||
var exported = new RegExp("module\\.exports\\s*=\\s*" + variable)
|
var exported = new RegExp("module\\.exports\\s*=\\s*" + variable)
|
||||||
if (collision.test(code) && !exported.test(code) && !globals[variable.match(/[^\.]+/)]) {
|
if (collision.test(code) && !exported.test(code) && !globals[variable.match(/[^\.]+/)]) {
|
||||||
var fixed = variable + usedVariables[variable]++
|
var fixed = variable + usedVariables[variable]++
|
||||||
|
|
|
||||||
45
mithril.js
45
mithril.js
|
|
@ -1,3 +1,4 @@
|
||||||
|
new function() {
|
||||||
"use strict"
|
"use strict"
|
||||||
var guid = 0, noop = function() {}, HALT = {}
|
var guid = 0, noop = function() {}, HALT = {}
|
||||||
function createStream() {
|
function createStream() {
|
||||||
|
|
@ -179,17 +180,17 @@ function merge(streams) {
|
||||||
}, streams)
|
}, streams)
|
||||||
}
|
}
|
||||||
var Stream = {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
var Stream = {stream: createStream, merge: merge, combine: combine, reject: reject, HALT: HALT}
|
||||||
function Node(tag, key, attrs, children, text, dom) {
|
function Vnode(tag, key, attrs, children, text, dom) {
|
||||||
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined}
|
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined}
|
||||||
}
|
}
|
||||||
Node.normalize = function(node) {
|
Vnode.normalize = function(node) {
|
||||||
if (node instanceof Array) return Node("[", undefined, undefined, Node.normalizeChildren(node), undefined, undefined)
|
if (node instanceof Array) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
|
||||||
else if (node != null && typeof node !== "object") return Node("#", undefined, undefined, node, undefined, undefined)
|
else if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node, undefined, undefined)
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
Node.normalizeChildren = function normalizeChildren(children) {
|
Vnode.normalizeChildren = function normalizeChildren(children) {
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
children[i] = Node.normalize(children[i])
|
children[i] = Vnode.normalize(children[i])
|
||||||
}
|
}
|
||||||
return children
|
return children
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +231,7 @@ function hyperscript(selector) {
|
||||||
}
|
}
|
||||||
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
if (children instanceof Array && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
|
||||||
else childList = children
|
else childList = children
|
||||||
return Node(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -247,8 +248,8 @@ function hyperscript(selector) {
|
||||||
children = []
|
children = []
|
||||||
for (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i])
|
for (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i])
|
||||||
}
|
}
|
||||||
if (typeof selector === "string") return selectorCache[selector](attrs || {}, Node.normalizeChildren(children))
|
if (typeof selector === "string") return selectorCache[selector](attrs || {}, Vnode.normalizeChildren(children))
|
||||||
return Node(selector, attrs && attrs.key, attrs || {}, Node.normalizeChildren(children), undefined, undefined)
|
return Vnode(selector, attrs && attrs.key, attrs || {}, Vnode.normalizeChildren(children), undefined, undefined)
|
||||||
}
|
}
|
||||||
var m = hyperscript
|
var m = hyperscript
|
||||||
var renderService = function($window) {
|
var renderService = function($window) {
|
||||||
|
|
@ -322,7 +323,7 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
if (vnode.text != null) {
|
if (vnode.text != null) {
|
||||||
if (vnode.text !== "") element.textContent = vnode.text
|
if (vnode.text !== "") element.textContent = vnode.text
|
||||||
else vnode.children = [Node("#", undefined, undefined, vnode.text, undefined, undefined)]
|
else vnode.children = [Vnode("#", undefined, undefined, vnode.text, undefined, undefined)]
|
||||||
}
|
}
|
||||||
if (vnode.children != null) {
|
if (vnode.children != null) {
|
||||||
var children = vnode.children
|
var children = vnode.children
|
||||||
|
|
@ -334,7 +335,7 @@ var renderService = function($window) {
|
||||||
function createComponent(vnode, hooks, ns) {
|
function createComponent(vnode, hooks, ns) {
|
||||||
vnode.state = copy(vnode.tag)
|
vnode.state = copy(vnode.tag)
|
||||||
initLifecycle(vnode.tag, vnode, hooks)
|
initLifecycle(vnode.tag, vnode, hooks)
|
||||||
vnode.instance = Node.normalize(vnode.tag.view.call(vnode.state, vnode))
|
vnode.instance = Vnode.normalize(vnode.tag.view.call(vnode.state, vnode))
|
||||||
if (vnode.instance != null) {
|
if (vnode.instance != null) {
|
||||||
var element = createNode(vnode.instance, hooks, ns)
|
var element = createNode(vnode.instance, hooks, ns)
|
||||||
vnode.dom = vnode.instance.dom
|
vnode.dom = vnode.instance.dom
|
||||||
|
|
@ -487,13 +488,13 @@ var renderService = function($window) {
|
||||||
if (old.text.toString() !== vnode.text.toString()) old.dom.firstChild.nodeValue = vnode.text
|
if (old.text.toString() !== vnode.text.toString()) old.dom.firstChild.nodeValue = vnode.text
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (old.text != null) old.children = [Node("#", undefined, undefined, old.text, undefined, old.dom.firstChild)]
|
if (old.text != null) old.children = [Vnode("#", undefined, undefined, old.text, undefined, old.dom.firstChild)]
|
||||||
if (vnode.text != null) vnode.children = [Node("#", undefined, undefined, vnode.text, undefined, undefined)]
|
if (vnode.text != null) vnode.children = [Vnode("#", undefined, undefined, vnode.text, undefined, undefined)]
|
||||||
updateNodes(element, old.children, vnode.children, hooks, null, ns)
|
updateNodes(element, old.children, vnode.children, hooks, null, ns)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) {
|
function updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) {
|
||||||
vnode.instance = Node.normalize(vnode.tag.view.call(vnode.state, vnode))
|
vnode.instance = Vnode.normalize(vnode.tag.view.call(vnode.state, vnode))
|
||||||
updateLifecycle(vnode.tag, vnode, hooks, recycling)
|
updateLifecycle(vnode.tag, vnode, hooks, recycling)
|
||||||
if (vnode.instance != null) {
|
if (vnode.instance != null) {
|
||||||
if (old.instance == null) insertNode(parent, createNode(vnode.instance, hooks, ns), nextSibling)
|
if (old.instance == null) insertNode(parent, createNode(vnode.instance, hooks, ns), nextSibling)
|
||||||
|
|
@ -574,11 +575,11 @@ var renderService = function($window) {
|
||||||
}
|
}
|
||||||
if (vnode.attrs && vnode.attrs.onbeforeremove) {
|
if (vnode.attrs && vnode.attrs.onbeforeremove) {
|
||||||
expected++
|
expected++
|
||||||
vnode.attrs.onbeforeremove.call(vnode, vnode, callback)
|
vnode.attrs.onbeforeremove.call(vnode.state, vnode, callback)
|
||||||
}
|
}
|
||||||
if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) {
|
if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) {
|
||||||
expected++
|
expected++
|
||||||
vnode.tag.onbeforeremove.call(vnode, vnode, callback)
|
vnode.tag.onbeforeremove.call(vnode.state, vnode, callback)
|
||||||
}
|
}
|
||||||
if (expected > 0) return
|
if (expected > 0) return
|
||||||
}
|
}
|
||||||
|
|
@ -746,7 +747,7 @@ var renderService = function($window) {
|
||||||
var active = $doc.activeElement
|
var active = $doc.activeElement
|
||||||
if (dom.vnodes == null) dom.vnodes = []
|
if (dom.vnodes == null) dom.vnodes = []
|
||||||
if (!(vnodes instanceof Array)) vnodes = [vnodes]
|
if (!(vnodes instanceof Array)) vnodes = [vnodes]
|
||||||
updateNodes(dom, dom.vnodes, Node.normalizeChildren(vnodes), hooks, null, undefined)
|
updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), hooks, null, undefined)
|
||||||
dom.vnodes = vnodes
|
dom.vnodes = vnodes
|
||||||
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
||||||
if ($doc.activeElement !== active) active.focus()
|
if ($doc.activeElement !== active) active.focus()
|
||||||
|
|
@ -785,7 +786,7 @@ var requestService = function($window) {
|
||||||
|
|
||||||
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
||||||
|
|
||||||
if (typeof args.serialize !== "function") args.serialize = args.data instanceof FormData ? function(value) {return value} : JSON.stringify
|
if (typeof args.serialize !== "function") args.serialize = typeof FormData !== "undefined" && args.data instanceof FormData ? function(value) {return value} : JSON.stringify
|
||||||
if (typeof args.deserialize !== "function") args.deserialize = deserialize
|
if (typeof args.deserialize !== "function") args.deserialize = deserialize
|
||||||
if (typeof args.extract !== "function") args.extract = extract
|
if (typeof args.extract !== "function") args.extract = extract
|
||||||
|
|
||||||
|
|
@ -1077,14 +1078,14 @@ m.route = function($window, renderer, pubsub) {
|
||||||
if (typeof payload.render !== "function") payload.render = function(vnode) {return vnode}
|
if (typeof payload.render !== "function") payload.render = function(vnode) {return vnode}
|
||||||
var render = function(component) {
|
var render = function(component) {
|
||||||
current.route = route, current.component = component
|
current.route = route, current.component = component
|
||||||
renderer.render(root, payload.render(Node(component, null, args, undefined, undefined, undefined)))
|
renderer.render(root, payload.render(Vnode(component, null, args, undefined, undefined, undefined)))
|
||||||
}
|
}
|
||||||
if (typeof payload.resolve !== "function") payload.resolve = function() {render(current.component)}
|
if (typeof payload.resolve !== "function") payload.resolve = function() {render(current.component)}
|
||||||
if (route !== current.route) payload.resolve(render, args, path, route)
|
if (route !== current.route) payload.resolve(render, args, path, route)
|
||||||
else render(current.component)
|
else render(current.component)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderer.render(root, Node(payload, null, args, undefined, undefined, undefined))
|
renderer.render(root, Vnode(payload, null, args, undefined, undefined, undefined))
|
||||||
}
|
}
|
||||||
}, function() {
|
}, function() {
|
||||||
router.setPath(defaultRoute, null, {replace: true})
|
router.setPath(defaultRoute, null, {replace: true})
|
||||||
|
|
@ -1107,7 +1108,7 @@ m.mount = function(renderer, pubsub) {
|
||||||
}
|
}
|
||||||
}(renderService, redrawService)
|
}(renderService, redrawService)
|
||||||
m.trust = function(html) {
|
m.trust = function(html) {
|
||||||
return Node("<", undefined, undefined, html, undefined, undefined)
|
return Vnode("<", undefined, undefined, html, undefined, undefined)
|
||||||
}
|
}
|
||||||
m.withAttr = function(attrName, callback, context) {
|
m.withAttr = function(attrName, callback, context) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
|
|
@ -1125,3 +1126,5 @@ m.request = requestService.xhr
|
||||||
m.jsonp = requestService.jsonp
|
m.jsonp = requestService.jsonp
|
||||||
m.version = "1.0.0"
|
m.version = "1.0.0"
|
||||||
module.exports = m
|
module.exports = m
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue