Skip to content

Commit 6c4cf55

Browse files
committed
Merge pull request #877 from zeitgeist87/DFS-fix
Fix DFS bug
2 parents 4562b18 + b86c727 commit 6c4cf55

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

components/prism-core.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var Prism = (function(){
1616

1717
// Private helper vars
1818
var lang = /\blang(?:uage)?-(\w+)\b/i;
19+
var uniqueId = 0;
1920

2021
var _ = _self.Prism = {
2122
util: {
@@ -33,6 +34,13 @@ var _ = _self.Prism = {
3334
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
3435
},
3536

37+
objId: function (obj) {
38+
if (!obj['__id']) {
39+
Object.defineProperty(obj, '__id', { value: ++uniqueId });
40+
}
41+
return obj['__id'];
42+
},
43+
3644
// Deep clone a language definition (e.g. to extend it)
3745
clone: function (o) {
3846
var type = _.util.type(o);
@@ -131,12 +139,12 @@ var _ = _self.Prism = {
131139
if (o.hasOwnProperty(i)) {
132140
callback.call(o, i, o[i], type || i);
133141

134-
if (_.util.type(o[i]) === 'Object' && !visited[o[i]]) {
135-
visited[o[i]] = true;
142+
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
143+
visited[_.util.objId(o[i])] = true;
136144
_.languages.DFS(o[i], callback, null, visited);
137145
}
138-
else if (_.util.type(o[i]) === 'Array' && !visited[o[i]]) {
139-
visited[o[i]] = true;
146+
else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
147+
visited[_.util.objId(o[i])] = true;
140148
_.languages.DFS(o[i], callback, i, visited);
141149
}
142150
}

components/prism-core.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prism.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var Prism = (function(){
2121

2222
// Private helper vars
2323
var lang = /\blang(?:uage)?-(\w+)\b/i;
24+
var uniqueId = 0;
2425

2526
var _ = _self.Prism = {
2627
util: {
@@ -38,6 +39,13 @@ var _ = _self.Prism = {
3839
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
3940
},
4041

42+
objId: function (obj) {
43+
if (!obj['__id']) {
44+
Object.defineProperty(obj, '__id', { value: ++uniqueId });
45+
}
46+
return obj['__id'];
47+
},
48+
4149
// Deep clone a language definition (e.g. to extend it)
4250
clone: function (o) {
4351
var type = _.util.type(o);
@@ -136,12 +144,12 @@ var _ = _self.Prism = {
136144
if (o.hasOwnProperty(i)) {
137145
callback.call(o, i, o[i], type || i);
138146

139-
if (_.util.type(o[i]) === 'Object' && !visited[o[i]]) {
140-
visited[o[i]] = true;
147+
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
148+
visited[_.util.objId(o[i])] = true;
141149
_.languages.DFS(o[i], callback, null, visited);
142150
}
143-
else if (_.util.type(o[i]) === 'Array' && !visited[o[i]]) {
144-
visited[o[i]] = true;
151+
else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
152+
visited[_.util.objId(o[i])] = true;
145153
_.languages.DFS(o[i], callback, i, visited);
146154
}
147155
}

0 commit comments

Comments
 (0)