Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 3bfe9d2

Browse files
committed
refactor: Modernize ExtractedModule syntax
- Convert to ES6+ Class - Convert to ES6+ default export - Convert to const / let - Uses import syntax - Convert errors to templates
1 parent e3799dd commit 3bfe9d2

File tree

1 file changed

+59
-56
lines changed

1 file changed

+59
-56
lines changed

src/lib/ExtractedModule.js

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,70 @@
1-
/* eslint-disable */
2-
var SourceMapSource = require("webpack-sources").SourceMapSource;
3-
var RawSource = require("webpack-sources").RawSource;
1+
import { SourceMapSource, RawSource } from 'webpack-sources';
42

5-
function ExtractedModule(identifier, originalModule, source, sourceMap, addtitionalInformation, prevModules) {
6-
this._identifier = identifier;
7-
this._originalModule = originalModule;
8-
this._source = source;
9-
this._sourceMap = sourceMap;
10-
this._prevModules = prevModules;
11-
this.addtitionalInformation = addtitionalInformation;
12-
this.chunks = [];
13-
}
14-
module.exports = ExtractedModule;
3+
class ExtractedModule {
4+
constructor(
5+
identifier,
6+
originalModule,
7+
source,
8+
sourceMap,
9+
addtitionalInformation,
10+
prevModules) {
11+
this._identifier = identifier;
12+
this._originalModule = originalModule;
13+
this._source = source;
14+
this._sourceMap = sourceMap;
15+
this._prevModules = prevModules;
16+
this.addtitionalInformation = addtitionalInformation;
17+
this.chunks = [];
18+
}
19+
20+
getOrder() {
21+
// http://stackoverflow.com/a/14676665/1458162
22+
return /^@import url/.test(this._source) ? 0 : 1;
23+
}
1524

16-
ExtractedModule.prototype.getOrder = function() {
17-
// http://stackoverflow.com/a/14676665/1458162
18-
return /^@import url/.test(this._source) ? 0 : 1;
19-
};
25+
addChunk(chunk) {
26+
const idx = this.chunks.indexOf(chunk);
27+
if (idx < 0) { this.chunks.push(chunk); }
28+
}
2029

21-
ExtractedModule.prototype.addChunk = function(chunk) {
22-
var idx = this.chunks.indexOf(chunk);
23-
if(idx < 0)
24-
this.chunks.push(chunk);
25-
};
30+
removeChunk(chunk) {
31+
const idx = this.chunks.indexOf(chunk);
32+
if (idx >= 0) {
33+
this.chunks.splice(idx, 1);
34+
chunk.removeModule(this);
35+
return true;
36+
}
37+
return false;
38+
}
2639

27-
ExtractedModule.prototype.removeChunk = function(chunk) {
28-
var idx = this.chunks.indexOf(chunk);
29-
if(idx >= 0) {
30-
this.chunks.splice(idx, 1);
31-
chunk.removeModule(this);
32-
return true;
33-
}
34-
return false;
35-
};
40+
rewriteChunkInReasons(oldChunk, newChunks) { } // eslint-disable-line
3641

37-
ExtractedModule.prototype.rewriteChunkInReasons = function(oldChunk, newChunks) { };
42+
identifier() {
43+
return this._identifier;
44+
}
3845

39-
ExtractedModule.prototype.identifier = function() {
40-
return this._identifier;
41-
};
46+
source() {
47+
if (this._sourceMap) { return new SourceMapSource(this._source, null, this._sourceMap); }
48+
return new RawSource(this._source);
49+
}
4250

43-
ExtractedModule.prototype.source = function() {
44-
if(this._sourceMap)
45-
return new SourceMapSource(this._source, null, this._sourceMap);
46-
else
47-
return new RawSource(this._source);
48-
};
51+
getOriginalModule() {
52+
return this._originalModule;
53+
}
4954

50-
ExtractedModule.prototype.getOriginalModule = function() {
51-
return this._originalModule;
52-
};
55+
getPrevModules() {
56+
return this._prevModules;
57+
}
5358

54-
ExtractedModule.prototype.getPrevModules = function() {
55-
return this._prevModules;
56-
};
59+
addPrevModules(prevModules) {
60+
prevModules.forEach((m) => {
61+
if (this._prevModules.indexOf(m) < 0) { this._prevModules.push(m); }
62+
}, this);
63+
}
5764

58-
ExtractedModule.prototype.addPrevModules = function(prevModules) {
59-
prevModules.forEach(function(m) {
60-
if(this._prevModules.indexOf(m) < 0)
61-
this._prevModules.push(m);
62-
}, this);
63-
};
65+
setOriginalModule(originalModule) {
66+
this._originalModule = originalModule;
67+
}
68+
}
6469

65-
ExtractedModule.prototype.setOriginalModule = function(originalModule) {
66-
this._originalModule = originalModule;
67-
};
70+
export default ExtractedModule;

0 commit comments

Comments
 (0)