Skip to content

Commit d8ec5da

Browse files
authored
refactor(exported-extractor): Use Map object instead of Object.create(null) (#730)
The map object provides a cleaner and more predictable way to deal with indexed data in JavaScript. I wrote something about that here http://www.macwright.org/2017/03/13/maps-not-strictly-better.html
1 parent fc1cd13 commit d8ec5da

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/extractors/exported.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function walkExported(
2828
) {
2929
var newResults = [];
3030
var filename = data.file;
31-
var dataCache = Object.create(null);
31+
var dataCache = new Map();
3232

3333
function addBlankComment(data, path, node) {
3434
return addComment(data, '', node.loc, path, node.loc, true);
@@ -178,7 +178,7 @@ function getCachedData(dataCache, filePath) {
178178
path = require.resolve(path);
179179
}
180180

181-
var value = dataCache[path];
181+
var value = dataCache.get(path);
182182
if (!value) {
183183
var input = fs.readFileSync(path, 'utf-8');
184184
var ast = parseToAst(input, path);
@@ -189,7 +189,7 @@ function getCachedData(dataCache, filePath) {
189189
},
190190
ast
191191
};
192-
dataCache[path] = value;
192+
dataCache.set(path, value);
193193
}
194194
return value;
195195
}

0 commit comments

Comments
 (0)