8000 Core: Avoid redeclaring variables in util.clone (#1778) · PrismJS/prism@b06f532 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b06f532

Browse files
ExE-BossRunDevelopment
authored andcommitted
Core: Avoid redeclaring variables in util.clone (#1778)
This changes util.clone to be more readable and to avoid redeclaring the `clone` and `id` variables.
1 parent 289ddd9 commit b06f532

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

components/prism-core.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ var _ = _self.Prism = {
4545

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

5151
switch (type) {
5252
case 'Object':
53-
var id = _.util.objId(o);
53+
id = _.util.objId(o);
5454
if (visited[id]) {
5555
return visited[id];
5656
}
57-
var clone = {};
57+
clone = {};
5858
visited[id] = clone;
5959

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

6868
case 'Array':
69-
var id = _.util.objId(o);
69+
id = _.util.objId(o);
7070
if (visited[id]) {
7171
return visited[id];
7272
}
73-
var clone = [];
73+
clone = [];
7474
visited[id] = clone;
7575

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

8080
return clone;
81-
}
8281

83-
return o;
82+
default:
83+
return o;
84+
}
8485
}
8586
},
8687

components/prism-core.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prism.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ var _ = _self.Prism = {
5050

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

5656
switch (type) {
5757
case 'Object':
58-
var id = _.util.objId(o);
58+
id = _.util.objId(o);
5959
if (visited[id]) {
6060
return visited[id];
6161
}
62-
var clone = {};
62+
clone = {};
6363
visited[id] = clone;
6464

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

7373
case 'Array':
74-
var id = _.util.objId(o);
74+
id = _.util.objId(o);
7575
if (visited[id]) {
7676
return visited[id];
7777
}
78-
var clone = [];
78+
clone = [];
7979
visited[id] = clone;
8080

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

8585
return clone;
86-
}
8786

88-
return o;
87+
default:
88+
return o;
89+
}
8990
}
9091
},
9192

0 commit comments

Comments
 (0)
0