Skip to content

Commit cc1b19e

Browse files
committed
rename imported default to builder
1 parent 16cafc4 commit cc1b19e

10 files changed

+50
-50
lines changed

src/rules/default.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Exports from '../exportMapBuilder';
1+
import ExportMapBuilder from '../exportMapBuilder';
22
import docsUrl from '../docsUrl';
33

44
module.exports = {
@@ -19,7 +19,7 @@ module.exports = {
1919
);
2020

2121
if (!defaultSpecifier) { return; }
22-
const imports = Exports.get(node.source.value, context);
22+
const imports = ExportMapBuilder.get(node.source.value, context);
2323
if (imports == null) { return; }
2424

2525
if (imports.errors.length) {

src/rules/export.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ExportMap, { recursivePatternCapture } from '../exportMapBuilder';
1+
import ExportMapBuilder, { recursivePatternCapture } from '../exportMapBuilder';
22
import docsUrl from '../docsUrl';
33
import includes from 'array-includes';
44
import flatMap from 'array.prototype.flatmap';
@@ -197,7 +197,7 @@ module.exports = {
197197
// `export * as X from 'path'` does not conflict
198198
if (node.exported && node.exported.name) { return; }
199199

200-
const remoteExports = ExportMap.get(node.source.value, context);
200+
const remoteExports = ExportMapBuilder.get(node.source.value, context);
201201
if (remoteExports == null) { return; }
202202

203203
if (remoteExports.errors.length) {

src/rules/named.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path';
2-
import Exports from '../exportMapBuilder';
2+
import ExportMapBuilder from '../exportMapBuilder';
33
import docsUrl from '../docsUrl';
44

55
module.exports = {
@@ -41,7 +41,7 @@ module.exports = {
4141
return; // no named imports/exports
4242
}
4343

44-
const imports = Exports.get(node.source.value, context);
44+
const imports = ExportMapBuilder.get(node.source.value, context);
4545
if (imports == null || imports.parseGoal === 'ambiguous') {
4646
return;
4747
}
@@ -93,7 +93,7 @@ module.exports = {
9393
const call = node.init;
9494
const [source] = call.arguments;
9595
const variableImports = node.id.properties;
96-
const variableExports = Exports.get(source.value, context);
96+
const variableExports = ExportMapBuilder.get(source.value, context);
9797

9898
if (
9999
// return if it's not a commonjs require statement

src/rules/namespace.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import declaredScope from 'eslint-module-utils/declaredScope';
2-
import Exports from '../exportMapBuilder';
2+
import ExportMapBuilder from '../exportMapBuilder';
33
import ExportMap from '../exportMap';
44
import importDeclaration from '../importDeclaration';
55
import docsUrl from '../docsUrl';
@@ -9,7 +9,7 @@ function processBodyStatement(context, namespaces, declaration) {
99

1010
if (declaration.specifiers.length === 0) { return; }
1111

12-
const imports = Exports.get(declaration.source.value, context);
12+
const imports = ExportMapBuilder.get(declaration.source.value, context);
1313
if (imports == null) { return null; }
1414

1515
if (imports.errors.length > 0) {
@@ -89,7 +89,7 @@ module.exports = {
8989
ExportNamespaceSpecifier(namespace) {
9090
const declaration = importDeclaration(context);
9191

92-
const imports = Exports.get(declaration.source.value, context);
92+
const imports = ExportMapBuilder.get(declaration.source.value, context);
9393
if (imports == null) { return null; }
9494

9595
if (imports.errors.length) {

src/rules/no-cycle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import resolve from 'eslint-module-utils/resolve';
7-
import Exports from '../exportMapBuilder';
7+
import ExportMapBuilder from '../exportMapBuilder';
88
import { isExternalModule } from '../core/importType';
99
import moduleVisitor, { makeOptionsSchema } from 'eslint-module-utils/moduleVisitor';
1010
import docsUrl from '../docsUrl';
@@ -88,7 +88,7 @@ module.exports = {
8888
return; // ignore type imports
8989
}
9090

91-
const imported = Exports.get(sourceNode.value, context);
91+
const imported = ExportMapBuilder.get(sourceNode.value, context);
9292

9393
if (imported == null) {
9494
return; // no-unresolved territory

src/rules/no-deprecated.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import declaredScope from 'eslint-module-utils/declaredScope';
2-
import Exports from '../exportMapBuilder';
2+
import ExportMapBuilder from '../exportMapBuilder';
33
import ExportMap from '../exportMap';
44
import docsUrl from '../docsUrl';
55

@@ -32,7 +32,7 @@ module.exports = {
3232
if (node.type !== 'ImportDeclaration') { return; }
3333
if (node.source == null) { return; } // local export, ignore
3434

35-
const imports = Exports.get(node.source.value, context);
35+
const imports = ExportMapBuilder.get(node.source.value, context);
3636
if (imports == null) { return; }
3737

3838
const moduleDeprecation = imports.doc && imports.doc.tags.find((t) => t.title === 'deprecated');

src/rules/no-named-as-default-member.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @copyright 2016 Desmond Brand. All rights reserved.
55
* See LICENSE in root directory for full license.
66
*/
7-
import Exports from '../exportMapBuilder';
7+
import ExportMapBuilder from '../exportMapBuilder';
88
import importDeclaration from '../importDeclaration';
99
import docsUrl from '../docsUrl';
1010

@@ -36,7 +36,7 @@ module.exports = {
3636
return {
3737
ImportDefaultSpecifier(node) {
3838
const declaration = importDeclaration(context);
39-
const exportMap = Exports.get(declaration.source.value, context);
39+
const exportMap = ExportMapBuilder.get(declaration.source.value, context);
4040
if (exportMap == null) { return; }
4141

4242
if (exportMap.errors.length) {

src/rules/no-named-as-default.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Exports from '../exportMapBuilder';
1+
import ExportMapBuilder from '../exportMapBuilder';
22
import importDeclaration from '../importDeclaration';
33
import docsUrl from '../docsUrl';
44

@@ -20,7 +20,7 @@ module.exports = {
2020

2121
const declaration = importDeclaration(context);
2222

23-
const imports = Exports.get(declaration.source.value, context);
23+
const imports = ExportMapBuilder.get(declaration.source.value, context);
2424
if (imports == null) { return; }
2525

2626
if (imports.errors.length) {

src/rules/no-unused-modules.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import values from 'object.values';
1313
import includes from 'array-includes';
1414
import flatMap from 'array.prototype.flatmap';
1515

16-
import Exports, { recursivePatternCapture } from '../exportMapBuilder';
16+
import ExportMapBuilder, { recursivePatternCapture } from '../exportMapBuilder';
1717
import docsUrl from '../docsUrl';
1818

1919
let FileEnumerator;
@@ -194,7 +194,7 @@ const prepareImportsAndExports = (srcFiles, context) => {
194194
srcFiles.forEach((file) => {
195195
const exports = new Map();
196196
const imports = new Map();
197-
const currentExports = Exports.get(file, context);
197+
const currentExports = ExportMapBuilder.get(file, context);
198198
if (currentExports) {
199199
const {
200200
dependencies,

tests/src/core/getExports.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sinon from 'sinon';
44
import eslintPkg from 'eslint/package.json';
55
import typescriptPkg from 'typescript/package.json';
66
import * as tsConfigLoader from 'tsconfig-paths/lib/tsconfig-loader';
7-
import ExportMap from '../../../src/exportMapBuilder';
7+
import ExportMapBuilder from '../../../src/exportMapBuilder';
88

99
import * as fs from 'fs';
1010

@@ -28,7 +28,7 @@ describe('ExportMap', function () {
2828
it('handles ExportAllDeclaration', function () {
2929
let imports;
3030
expect(function () {
31-
imports = ExportMap.get('./export-all', fakeContext);
31+
imports = ExportMapBuilder.get('./export-all', fakeContext);
3232
}).not.to.throw(Error);
3333

3434
expect(imports).to.exist;
@@ -37,41 +37,41 @@ describe('ExportMap', function () {
3737
});
3838

3939
it('returns a cached copy on subsequent requests', function () {
40-
expect(ExportMap.get('./named-exports', fakeContext))
41-
.to.exist.and.equal(ExportMap.get('./named-exports', fakeContext));
40+
expect(ExportMapBuilder.get('./named-exports', fakeContext))
41+
.to.exist.and.equal(ExportMapBuilder.get('./named-exports', fakeContext));
4242
});
4343

4444
it('does not return a cached copy after modification', (done) => {
45-
const firstAccess = ExportMap.get('./mutator', fakeContext);
45+
const firstAccess = ExportMapBuilder.get('./mutator', fakeContext);
4646
expect(firstAccess).to.exist;
4747

4848
// mutate (update modified time)
4949
const newDate = new Date();
5050
fs.utimes(getFilename('mutator.js'), newDate, newDate, (error) => {
5151
expect(error).not.to.exist;
52-
expect(ExportMap.get('./mutator', fakeContext)).not.to.equal(firstAccess);
52+
expect(ExportMapBuilder.get('./mutator', fakeContext)).not.to.equal(firstAccess);
5353
done();
5454
});
5555
});
5656

5757
it('does not return a cached copy with different settings', () => {
58-
const firstAccess = ExportMap.get('./named-exports', fakeContext);
58+
const firstAccess = ExportMapBuilder.get('./named-exports', fakeContext);
5959
expect(firstAccess).to.exist;
6060

6161
const differentSettings = {
6262
...fakeContext,
6363
parserPath: 'espree',
6464
};
6565

66-
expect(ExportMap.get('./named-exports', differentSettings))
66+
expect(ExportMapBuilder.get('./named-exports', differentSettings))
6767
.to.exist.and
6868
.not.to.equal(firstAccess);
6969
});
7070

7171
it('does not throw for a missing file', function () {
7272
let imports;
7373
expect(function () {
74-
imports = ExportMap.get('./does-not-exist', fakeContext);
74+
imports = ExportMapBuilder.get('./does-not-exist', fakeContext);
7575
}).not.to.throw(Error);
7676

7777
expect(imports).not.to.exist;
@@ -81,7 +81,7 @@ describe('ExportMap', function () {
8181
it('exports explicit names for a missing file in exports', function () {
8282
let imports;
8383
expect(function () {
84-
imports = ExportMap.get('./exports-missing', fakeContext);
84+
imports = ExportMapBuilder.get('./exports-missing', fakeContext);
8585
}).not.to.throw(Error);
8686

8787
expect(imports).to.exist;
@@ -92,7 +92,7 @@ describe('ExportMap', function () {
9292
it('finds exports for an ES7 module with babel-eslint', function () {
9393
const path = getFilename('jsx/FooES7.js');
9494
const contents = fs.readFileSync(path, { encoding: 'utf8' });
95-
const imports = ExportMap.parse(
95+
const imports = ExportMapBuilder.parse(
9696
path,
9797
contents,
9898
{ parserPath: 'babel-eslint', settings: {} },
@@ -112,7 +112,7 @@ describe('ExportMap', function () {
112112
before('parse file', function () {
113113
const path = getFilename('deprecated.js');
114114
const contents = fs.readFileSync(path, { encoding: 'utf8' }).replace(/[\r]\n/g, lineEnding);
115-
imports = ExportMap.parse(path, contents, parseContext);
115+
imports = ExportMapBuilder.parse(path, contents, parseContext);
116116

117117
// sanity checks
118118
expect(imports.errors).to.be.empty;
@@ -181,7 +181,7 @@ describe('ExportMap', function () {
181181
before('parse file', function () {
182182
const path = getFilename('deprecated-file.js');
183183
const contents = fs.readFileSync(path, { encoding: 'utf8' });
184-
imports = ExportMap.parse(path, contents, parseContext);
184+
imports = ExportMapBuilder.parse(path, contents, parseContext);
185185

186186
// sanity checks
187187
expect(imports.errors).to.be.empty;
@@ -243,7 +243,7 @@ describe('ExportMap', function () {
243243
it('works with espree & traditional namespace exports', function () {
244244
const path = getFilename('deep/a.js');
245245
const contents = fs.readFileSync(path, { encoding: 'utf8' });
246-
const a = ExportMap.parse(path, contents, espreeContext);
246+
const a = ExportMapBuilder.parse(path, contents, espreeContext);
247247
expect(a.errors).to.be.empty;
248248
expect(a.get('b').namespace).to.exist;
249249
expect(a.get('b').namespace.has('c')).to.be.true;
@@ -252,7 +252,7 @@ describe('ExportMap', function () {
252252
it('captures namespace exported as default', function () {
253253
const path = getFilename('deep/default.js');
254254
const contents = fs.readFileSync(path, { encoding: 'utf8' });
255-
const def = ExportMap.parse(path, contents, espreeContext);
255+
const def = ExportMapBuilder.parse(path, contents, espreeContext);
256256
expect(def.errors).to.be.empty;
257257
expect(def.get('default').namespace).to.exist;
258258
expect(def.get('default').namespace.has('c')).to.be.true;
@@ -261,7 +261,7 @@ describe('ExportMap', function () {
261261
it('works with babel-eslint & ES7 namespace exports', function () {
262262
const path = getFilename('deep-es7/a.js');
263263
const contents = fs.readFileSync(path, { encoding: 'utf8' });
264-
const a = ExportMap.parse(path, contents, babelContext);
264+
const a = ExportMapBuilder.parse(path, contents, babelContext);
265265
expect(a.errors).to.be.empty;
266266
expect(a.get('b').namespace).to.exist;
267267
expect(a.get('b').namespace.has('c')).to.be.true;
@@ -278,7 +278,7 @@ describe('ExportMap', function () {
278278

279279
const path = getFilename('deep/cache-1.js');
280280
const contents = fs.readFileSync(path, { encoding: 'utf8' });
281-
a = ExportMap.parse(path, contents, espreeContext);
281+
a = ExportMapBuilder.parse(path, contents, espreeContext);
282282
expect(a.errors).to.be.empty;
283283

284284
expect(a.get('b').namespace).to.exist;
@@ -304,25 +304,25 @@ describe('ExportMap', function () {
304304
context('Map API', function () {
305305
context('#size', function () {
306306

307-
it('counts the names', () => expect(ExportMap.get('./named-exports', fakeContext))
307+
it('counts the names', () => expect(ExportMapBuilder.get('./named-exports', fakeContext))
308308
.to.have.property('size', 12));
309309

310-
it('includes exported namespace size', () => expect(ExportMap.get('./export-all', fakeContext))
310+
it('includes exported namespace size', () => expect(ExportMapBuilder.get('./export-all', fakeContext))
311311
.to.have.property('size', 1));
312312

313313
});
314314
});
315315

316316
context('issue #210: self-reference', function () {
317317
it(`doesn't crash`, function () {
318-
expect(() => ExportMap.get('./narcissist', fakeContext)).not.to.throw(Error);
318+
expect(() => ExportMapBuilder.get('./narcissist', fakeContext)).not.to.throw(Error);
319319
});
320320
it(`'has' circular reference`, function () {
321-
expect(ExportMap.get('./narcissist', fakeContext))
321+
expect(ExportMapBuilder.get('./narcissist', fakeContext))
322322
.to.exist.and.satisfy((m) => m.has('soGreat'));
323323
});
324324
it(`can 'get' circular reference`, function () {
325-
expect(ExportMap.get('./narcissist', fakeContext))
325+
expect(ExportMapBuilder.get('./narcissist', fakeContext))
326326
.to.exist.and.satisfy((m) => m.get('soGreat') != null);
327327
});
328328
});
@@ -335,7 +335,7 @@ describe('ExportMap', function () {
335335

336336
let imports;
337337
before('load imports', function () {
338-
imports = ExportMap.get('./typescript.ts', context);
338+
imports = ExportMapBuilder.get('./typescript.ts', context);
339339
});
340340

341341
it('returns nothing for a TypeScript file', function () {
@@ -372,7 +372,7 @@ describe('ExportMap', function () {
372372
before('load imports', function () {
373373
this.timeout(20e3); // takes a long time :shrug:
374374
sinon.spy(tsConfigLoader, 'tsConfigLoader');
375-
imports = ExportMap.get('./typescript.ts', context);
375+
imports = ExportMapBuilder.get('./typescript.ts', context);
376376
});
377377
after('clear spies', function () {
378378
tsConfigLoader.tsConfigLoader.restore();
@@ -414,9 +414,9 @@ describe('ExportMap', function () {
414414
},
415415
};
416416
expect(tsConfigLoader.tsConfigLoader.callCount).to.equal(0);
417-
ExportMap.parse('./baz.ts', 'export const baz = 5', customContext);
417+
ExportMapBuilder.parse('./baz.ts', 'export const baz = 5', customContext);
418418
expect(tsConfigLoader.tsConfigLoader.callCount).to.equal(1);
419-
ExportMap.parse('./baz.ts', 'export const baz = 5', customContext);
419+
ExportMapBuilder.parse('./baz.ts', 'export const baz = 5', customContext);
420420
expect(tsConfigLoader.tsConfigLoader.callCount).to.equal(1);
421421

422422
const differentContext = {
@@ -426,17 +426,17 @@ describe('ExportMap', function () {
426426
},
427427
};
428428

429-
ExportMap.parse('./baz.ts', 'export const baz = 5', differentContext);
429+
ExportMapBuilder.parse('./baz.ts', 'export const baz = 5', differentContext);
430430
expect(tsConfigLoader.tsConfigLoader.callCount).to.equal(2);
431431
});
432432

433433
it('should cache after parsing for an ambiguous module', function () {
434434
const source = './typescript-declare-module.ts';
435-
const parseSpy = sinon.spy(ExportMap, 'parse');
435+
const parseSpy = sinon.spy(ExportMapBuilder, 'parse');
436436

437-
expect(ExportMap.get(source, context)).to.be.null;
437+
expect(ExportMapBuilder.get(source, context)).to.be.null;
438438

439-
ExportMap.get(source, context);
439+
ExportMapBuilder.get(source, context);
440440

441441
expect(parseSpy.callCount).to.equal(1);
442442

0 commit comments

Comments
 (0)