Conversation
- also remove unused param - call callback outside of method call
…module" variable
| module._compile(code, filename); | ||
| return module.exports; | ||
| }, | ||
| resolve: function(context, request, callback) { |
| return this.applyNoParseRule(noParseRule, request); | ||
| } | ||
|
|
||
| for(let i = 0; i < noParseRule.length; i++) { |
There was a problem hiding this comment.
Please add a tests for this. It's new and not tested.
| super.disconnect(); | ||
| } | ||
|
|
||
| markModuleAsErrored() { |
There was a problem hiding this comment.
Could you rewrite this method to take an error argument and be the only place where this.error = error is set? This should reduce the number of places where this.error is written and make the control flow more clear.
| } | ||
|
|
||
| source(dependencyTemplates, outputOptions, requestShortener) { | ||
| let hash = require("crypto").createHash("md5"); |
There was a problem hiding this comment.
require crypto on top of the his file.
| if(varNames.length === 0) return; | ||
| varStartCode += "/* WEBPACK VAR INJECTION */(function(" + varNames.join(", ") + ") {"; | ||
| // exports === this in the topLevelBlock, but exports do compress better... | ||
| varEndCode = (topLevelBlock === block ? "}.call(" + (topLevelBlock.exportsArgument || "exports") + ", " : "}.call(this, ") + |
There was a problem hiding this comment.
Could you make this line more readable? i. e. by moving some parts into local variables.
| needRebuild(fileTimestamps, contextTimestamps) { | ||
| const highestFileDepTimestamp = this.getHighestTimestamp( | ||
| this.fileDependencies, fileTimestamps); | ||
| // if the hightest is Infinity, we need a needRebuild |
There was a problem hiding this comment.
we need a needRebuild -> we need a rebuild
|
will do the tasks tomorrow! :) tasks:
|
…s called with an error
| // check if module should not be parsed | ||
| // returns "true" if the module should !not! be parsed | ||
| // returns "false" if the module !must! be parsed | ||
| preventParsing(noParseRule, request) { |
There was a problem hiding this comment.
preventParsing -> isParsingPrevented
| } | ||
|
|
||
| variableInjectionFunctionWrapperStartCode(varNames) { | ||
| const openingIIFEParanthesis = "("; |
There was a problem hiding this comment.
This is an overkill. Just add the ( to the string and add a comment if you want to make it clear.
| variableInjectionFunctionWrapperEndCode(varExpressions, block) { | ||
| const firstParam = this.contextArgument(block); | ||
| const furtherParams = varExpressions.map(e => e.source()).join(", "); | ||
| const closingIIFEParanthesis = ")"; |
| } | ||
|
|
||
| splitVariablesInUniqueNamedChunks(vars) { | ||
| const chunkCollection = vars.reduce((chunkCol, variable) => { |
There was a problem hiding this comment.
This can be simplied to not require a tempChunk.
return vars.reduce((chunks, variable) => {
const current = chunks[chunks.length - 1];
if(current.some(v => v.name === variable.name)) {
chunks.push([variable]);
} else {
current.push(variable);
}
return chunks;
}, [[]]);| source: source, | ||
| hash: hashDigest | ||
| }; | ||
| const topLevelBlock = this; |
There was a problem hiding this comment.
just realized that even the parameter this resembles doesnt even exist :)
| name: "baz" | ||
| }, | ||
| { | ||
| name: "wurst" |
| loaders = []; | ||
| resource = "some/resource"; | ||
| parser = { | ||
| parser() {} |
There was a problem hiding this comment.
This is weird. A Parser doesn't have a parser method. I would expect constructor() {} or parse() {}.
There was a problem hiding this comment.
this was supposed to be parse! nice catch
| describe("given a noParseRule", function() { | ||
| let returnValOfSpy; | ||
| beforeEach(function() { | ||
| returnValOfSpy = Math.random() >= 0.5 ? true : false; |
There was a problem hiding this comment.
Never use Math.random in tests. They should be deterministic.
There was a problem hiding this comment.
i kind of wanted to make them be random, but i guess that doesnt help should one ever try to debug such a test. will change
| let someRules; | ||
| beforeEach(function() { | ||
| someRules = [ | ||
| Math.random() >= 0.5 ? "some rule" : /some rule/, |
There was a problem hiding this comment.
Never use Math.random in tests. They should be deterministic.
| beforeEach(function() { | ||
| variables = [{ | ||
| name: "foo" | ||
| }, |
There was a problem hiding this comment.
The array styling looks weird.
The following should be accepted by the linter:
variables = [{
name: "foo"
}, {
name: "bar"
}]There was a problem hiding this comment.
it does look weird
but if i do what you suggest (what i tried in the first place) the linter complains.
Having it not like that makes eslint complain though.
The two linters should be aligned at some point
There was a problem hiding this comment.
+++ test/NormalModule.test.js
@@ -245,22 +245,22 @@
describe("#splitVariablesInUniqueNamedChunks", function() {
let variables;
beforeEach(function() {
variables = [{
- name: "foo"
- },
- {
- name: "bar"
- },
- {
- name: "baz"
- },
- {
- name: "some"
- },
- {
- name: "more"
- }
+ name: "foo"
+ },
+ {
+ name: "bar"
+ },
+ {
+ name: "baz"
+ },
+ {
+ name: "some"
+ },
+ {
+ name: "more"
+ }
];
});
There was a problem hiding this comment.
Try it with }, { in between. See my above example.
|
Thanks |
What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
N/A
If relevant, link to documentation update:
N/A
Summary
refactor NormalModule to es6
Does this PR introduce a breaking change?
No
Other information
Some refactorings to split up bigger method bodies in smaller ones. (to make it easier to read for stupid people like me :D )