Skip to content

Commit 79791a5

Browse files
Yuta HirotoTheLarkInn
authored andcommitted
refactor(ArrayMap): update ArrayMap to es2015 class (webpack#3613)
1 parent 4015882 commit 79791a5

3 files changed

Lines changed: 45 additions & 40 deletions

File tree

‎lib/ArrayMap.js‎

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,56 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
function ArrayMap() {
6-
this.keys = [];
7-
this.values = [];
8-
}
9-
module.exports = ArrayMap;
105

11-
ArrayMap.prototype.get = function(key) {
12-
for(var i = 0; i < this.keys.length; i++) {
13-
if(this.keys[i] === key) {
14-
return this.values[i];
6+
"use strict";
7+
8+
class ArrayMap {
9+
constructor() {
10+
this.keys = [];
11+
this.values = [];
12+
}
13+
14+
get(key) {
15+
for(let i = 0; i < this.keys.length; i++) {
16+
if(this.keys[i] === key) {
17+
return this.values[i];
18+
}
1519
}
20+
return;
1621
}
17-
return;
18-
};
19-
20-
ArrayMap.prototype.set = function(key, value) {
21-
for(var i = 0; i < this.keys.length; i++) {
22-
if(this.keys[i] === key) {
23-
this.values[i] = value;
24-
return this;
22+
23+
set(key, value) {
24+
for(let i = 0; i < this.keys.length; i++) {
25+
if(this.keys[i] === key) {
26+
this.values[i] = value;
27+
return this;
28+
}
2529
}
30+
this.keys.push(key);
31+
this.values.push(value);
32+
return this;
2633
}
27-
this.keys.push(key);
28-
this.values.push(value);
29-
return this;
30-
};
31-
32-
ArrayMap.prototype.remove = function(key) {
33-
for(var i = 0; i < this.keys.length; i++) {
34-
if(this.keys[i] === key) {
35-
this.keys.splice(i, 1);
36-
this.values.splice(i, 1);
37-
return true;
34+
35+
remove(key) {
36+
for(let i = 0; i < this.keys.length; i++) {
37+
if(this.keys[i] === key) {
38+
this.keys.splice(i, 1);
39+
this.values.splice(i, 1);
40+
return true;
41+
}
3842
}
43+
return false;
3944
}
40-
return false;
41-
};
42-
43-
ArrayMap.prototype.clone = function() {
44-
var newMap = new ArrayMap();
45-
for(var i = 0; i < this.keys.length; i++) {
46-
newMap.keys.push(this.keys[i]);
47-
newMap.values.push(this.values[i]);
45+
46+
clone() {
47+
const newMap = new ArrayMap();
48+
49+
for(let i = 0; i < this.keys.length; i++) {
50+
newMap.keys.push(this.keys[i]);
51+
newMap.values.push(this.values[i]);
52+
}
53+
return newMap;
4854
}
49-
return newMap;
50-
};
55+
}
56+
57+
module.exports = ArrayMap;

‎test/fixtures/temp-1000/file.js‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎test/fixtures/temp-1000/file2.js‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)