Skip to content

Commit

Permalink
Core: Avoid redeclaring variables in util.clone (#1778)
Browse files Browse the repository at this point in the history
This changes util.clone to be more readable and to avoid redeclaring the `clone` and `id` variables.
  • Loading branch information
ExE-Boss authored and RunDevelopment committed Mar 1, 2019
1 parent 289ddd9 commit b06f532
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
15 changes: 8 additions & 7 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ var _ = _self.Prism = {

// Deep clone a language definition (e.g. to extend it)
clone: function deepClone(o, visited) {
var type = _.util.type(o);
var clone, id, type = _.util.type(o);
visited = visited || {};

switch (type) {
case 'Object':
var id = _.util.objId(o);
id = _.util.objId(o);
if (visited[id]) {
return visited[id];
}
var clone = {};
clone = {};
visited[id] = clone;

for (var key in o) {
Expand All @@ -66,21 +66,22 @@ var _ = _self.Prism = {
return clone;

case 'Array':
var id = _.util.objId(o);
id = _.util.objId(o);
if (visited[id]) {
return visited[id];
}
var clone = [];
clone = [];
visited[id] = clone;

o.forEach(function (v, i) {
clone[i] = deepClone(v, visited);
});

return clone;
}

return o;
default:
return o;
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ var _ = _self.Prism = {

// Deep clone a language definition (e.g. to extend it)
clone: function deepClone(o, visited) {
var type = _.util.type(o);
var clone, id, type = _.util.type(o);
visited = visited || {};

switch (type) {
case 'Object':
var id = _.util.objId(o);
id = _.util.objId(o);
if (visited[id]) {
return visited[id];
}
var clone = {};
clone = {};
visited[id] = clone;

for (var key in o) {
Expand All @@ -71,21 +71,22 @@ var _ = _self.Prism = {
return clone;

case 'Array':
var id = _.util.objId(o);
id = _.util.objId(o);
if (visited[id]) {
return visited[id];
}
var clone = [];
clone = [];
visited[id] = clone;

o.forEach(function (v, i) {
clone[i] = deepClone(v, visited);
});

return clone;
}

return o;
default:
return o;
}
}
},

Expand Down

0 comments on commit b06f532

Please sign in to comment.