Permalink
Browse files

Fix DFS bug

The DFS function uses an object as a key into another object. This
doesn't work, because the key gets stringified to "[object
Object]" and is therefore useless.
  • Loading branch information...
zeitgeist87 committed Feb 3, 2016
1 parent 4562b18 commit b86c727a6c44f628d808bfc8f8ddcea9d0d8c858
Showing with 25 additions and 9 deletions.
  1. +12 −4 components/prism-core.js
  2. +1 −1 components/prism-core.min.js
  3. +12 −4 prism.js
@@ -16,6 +16,7 @@ var Prism = (function(){
// Private helper vars
var lang = /\blang(?:uage)?-(\w+)\b/i;
var uniqueId = 0;
var _ = _self.Prism = {
util: {
@@ -33,6 +34,13 @@ var _ = _self.Prism = {
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
},
objId: function (obj) {
if (!obj['__id']) {
Object.defineProperty(obj, '__id', { value: ++uniqueId });
}
return obj['__id'];
},
// Deep clone a language definition (e.g. to extend it)
clone: function (o) {
var type = _.util.type(o);
@@ -131,12 +139,12 @@ var _ = _self.Prism = {
if (o.hasOwnProperty(i)) {
callback.call(o, i, o[i], type || i);
if (_.util.type(o[i]) === 'Object' && !visited[o[i]]) {
visited[o[i]] = true;
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
visited[_.util.objId(o[i])] = true;
_.languages.DFS(o[i], callback, null, visited);
}
else if (_.util.type(o[i]) === 'Array' && !visited[o[i]]) {
visited[o[i]] = true;
else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
visited[_.util.objId(o[i])] = true;
_.languages.DFS(o[i], callback, i, visited);
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -21,6 +21,7 @@ var Prism = (function(){
// Private helper vars
var lang = /\blang(?:uage)?-(\w+)\b/i;
var uniqueId = 0;
var _ = _self.Prism = {
util: {
@@ -38,6 +39,13 @@ var _ = _self.Prism = {
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
},
objId: function (obj) {
if (!obj['__id']) {
Object.defineProperty(obj, '__id', { value: ++uniqueId });
}
return obj['__id'];
},
// Deep clone a language definition (e.g. to extend it)
clone: function (o) {
var type = _.util.type(o);
@@ -136,12 +144,12 @@ var _ = _self.Prism = {
if (o.hasOwnProperty(i)) {
callback.call(o, i, o[i], type || i);
if (_.util.type(o[i]) === 'Object' && !visited[o[i]]) {
visited[o[i]] = true;
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
visited[_.util.objId(o[i])] = true;
_.languages.DFS(o[i], callback, null, visited);
}
else if (_.util.type(o[i]) === 'Array' && !visited[o[i]]) {
visited[o[i]] = true;
else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
visited[_.util.objId(o[i])] = true;
_.languages.DFS(o[i], callback, i, visited);
}
}

0 comments on commit b86c727

Please sign in to comment.