Skip to content

Commit

Permalink
Merge branch 'master' into prefetch-from-entry
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jun 4, 2018
2 parents db668b7 + fe3ca80 commit dc0e1ec
Show file tree
Hide file tree
Showing 75 changed files with 1,005 additions and 1,197 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Expand Up @@ -2,11 +2,11 @@ root = true

[*]
indent_style = tab
indent_size = 4
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 233
max_line_length = 80

[.prettierrc]
indent_style = space
Expand Down
24 changes: 21 additions & 3 deletions declarations.d.ts
Expand Up @@ -36,6 +36,7 @@ declare module "@webassemblyjs/ast" {
ModuleImport?: (p: NodePath<ModuleImport>) => void;
ModuleExport?: (p: NodePath<ModuleExport>) => void;
Start?: (p: NodePath<Start>) => void;
Global?: (p: NodePath<Global>) => void;
}
);
export class NodePath<T> {
Expand All @@ -60,16 +61,33 @@ declare module "@webassemblyjs/ast" {
}
export class ModuleExport extends Node {
name: string;
descr: {
type: string;
exportType: string;
id?: Identifier;
};
}
export class ModuleExportDescr extends Node {}
export class IndexLiteral extends Node {}
export class NumberLiteral extends Node {}
export class NumberLiteral extends Node {
value: number;
raw: string;
}
export class FloatLiteral extends Node {}
export class Global extends Node {}
export class GlobalType extends Node {
valtype: string;
}
export class Global extends Node {
init: Instruction[];
globalType: GlobalType;
}
export class FuncParam extends Node {
valtype: string;
}
export class Instruction extends Node {}
export class Instruction extends Node {
id: string;
args: NumberLiteral[];
}
export class CallInstruction extends Instruction {}
export class ObjectInstruction extends Instruction {}
export class Func extends Node {
Expand Down
8 changes: 4 additions & 4 deletions lib/AsyncDependencyToInitialChunkError.js
Expand Up @@ -16,13 +16,13 @@ class AsyncDependencyToInitialChunkError extends WebpackError {
* @param {TODO} loc location of dependency
*/
constructor(chunkName, module, loc) {
super();
super(
`It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`
);

this.name = "AsyncDependencyToInitialChunkError";
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`;
this.module = module;
this.origin = module;
this.originLoc = loc;
this.loc = loc;

Error.captureStackTrace(this, this.constructor);
}
Expand Down
86 changes: 41 additions & 45 deletions lib/CaseSensitiveModulesWarning.js
Expand Up @@ -8,64 +8,60 @@ const WebpackError = require("./WebpackError");

/** @typedef {import("./Module")} Module */

/**
* @param {Module[]} modules the modules to be sorted
* @returns {Module[]} sorted version of original modules
*/
const sortModules = modules => {
return modules.slice().sort((a, b) => {
a = a.identifier();
b = b.identifier();
/* istanbul ignore next */
if (a < b) return -1;
/* istanbul ignore next */
if (a > b) return 1;
/* istanbul ignore next */
return 0;
});
};

/**
* @param {Module[]} modules each module from throw
* @returns {string} each message from provided moduels
*/
const createModulesListMessage = modules => {
return modules
.map(m => {
let message = `* ${m.identifier()}`;
const validReasons = m.reasons.filter(reason => reason.module);

if (validReasons.length > 0) {
message += `\n Used by ${validReasons.length} module(s), i. e.`;
message += `\n ${validReasons[0].module.identifier()}`;
}
return message;
})
.join("\n");
};

class CaseSensitiveModulesWarning extends WebpackError {
/**
* Creates an instance of CaseSensitiveModulesWarning.
* @param {Module[]} modules modules that were detected
*/
constructor(modules) {
super();

this.name = "CaseSensitiveModulesWarning";
const sortedModules = this._sort(modules);
const modulesList = this._moduleMessages(sortedModules);
this.message = `There are multiple modules with names that only differ in casing.
const sortedModules = sortModules(modules);
const modulesList = createModulesListMessage(sortedModules);
super(`There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:
${modulesList}`;
${modulesList}`);

this.name = "CaseSensitiveModulesWarning";
this.origin = this.module = sortedModules[0];

Error.captureStackTrace(this, this.constructor);
}

/**
* @private
* @param {Module[]} modules the modules to be sorted
* @returns {Module[]} sorted version of original modules
*/
_sort(modules) {
return modules.slice().sort((a, b) => {
a = a.identifier();
b = b.identifier();
/* istanbul ignore next */
if (a < b) return -1;
/* istanbul ignore next */
if (a > b) return 1;
/* istanbul ignore next */
return 0;
});
}

/**
* @private
* @param {Module[]} modules each module from throw
* @returns {string} each message from provided moduels
*/
_moduleMessages(modules) {
return modules
.map(m => {
let message = `* ${m.identifier()}`;
const validReasons = m.reasons.filter(reason => reason.module);

if (validReasons.length > 0) {
message += `\n Used by ${validReasons.length} module(s), i. e.`;
message += `\n ${validReasons[0].module.identifier()}`;
}
return message;
})
.join("\n");
}
}

module.exports = CaseSensitiveModulesWarning;
22 changes: 22 additions & 0 deletions lib/CommentCompilationWarning.js
@@ -0,0 +1,22 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";

const WebpackError = require("./WebpackError");

class CommentCompilationWarning extends WebpackError {
constructor(message, module, loc) {
super(message);

this.name = "CommentCompilationWarning";

this.module = module;
this.loc = loc;

Error.captureStackTrace(this, this.constructor);
}
}

module.exports = CommentCompilationWarning;
3 changes: 2 additions & 1 deletion lib/Compilation.js
Expand Up @@ -487,6 +487,7 @@ class Compilation extends Tapable {

const errorAndCallback = err => {
err.origin = module;
err.dependencies = dependencies;
this.errors.push(err);
if (bail) {
callback(err);
Expand Down Expand Up @@ -531,7 +532,7 @@ class Compilation extends Tapable {
if (err) {
semaphore.release();
return errorOrWarningAndCallback(
new ModuleNotFoundError(module, err, dependencies)
new ModuleNotFoundError(module, err)
);
}
if (!dependentModule) {
Expand Down
3 changes: 1 addition & 2 deletions lib/EntryModuleNotFoundError.js
Expand Up @@ -8,10 +8,9 @@ const WebpackError = require("./WebpackError");

class EntryModuleNotFoundError extends WebpackError {
constructor(err) {
super();
super("Entry module not found: " + err);

this.name = "EntryModuleNotFoundError";
this.message = "Entry module not found: " + err;
this.details = err.details;
this.error = err;

Expand Down
3 changes: 1 addition & 2 deletions lib/HarmonyLinkingError.js
Expand Up @@ -8,9 +8,8 @@ const WebpackError = require("./WebpackError");
module.exports = class HarmonyLinkingError extends WebpackError {
/** @param {string} message Error message */
constructor(message) {
super();
super(message);
this.name = "HarmonyLinkingError";
this.message = message;
this.hideStack = true;

Error.captureStackTrace(this, this.constructor);
Expand Down
23 changes: 13 additions & 10 deletions lib/ModuleBuildError.js
Expand Up @@ -9,29 +9,32 @@ const { cutOffLoaderExecution } = require("./ErrorHelpers");

class ModuleBuildError extends WebpackError {
constructor(module, err) {
super();

this.name = "ModuleBuildError";
this.message = "Module build failed: ";
let message = "Module build failed: ";
let details = undefined;
if (err !== null && typeof err === "object") {
if (typeof err.stack === "string" && err.stack) {
var stack = cutOffLoaderExecution(err.stack);
if (!err.hideStack) {
this.message += stack;
message += stack;
} else {
this.details = stack;
details = stack;
if (typeof err.message === "string" && err.message) {
this.message += err.message;
message += err.message;
} else {
this.message += err;
message += err;
}
}
} else if (typeof err.message === "string" && err.message) {
this.message += err.message;
message += err.message;
} else {
this.message += err;
message += err;
}
}

super(message);

this.name = "ModuleBuildError";
this.details = details;
this.module = module;
this.error = err;

Expand Down
7 changes: 3 additions & 4 deletions lib/ModuleDependencyError.js
Expand Up @@ -5,7 +5,6 @@
"use strict";

const WebpackError = require("./WebpackError");
const formatLocation = require("./formatLocation");

/** @typedef {import("./Module")} Module */

Expand All @@ -17,15 +16,15 @@ class ModuleDependencyError extends WebpackError {
* @param {TODO} loc location of dependency
*/
constructor(module, err, loc) {
super();
super(err.message);

this.name = "ModuleDependencyError";
this.message = `${formatLocation(loc)} ${err.message}`;
this.details = err.stack
.split("\n")
.slice(1)
.join("\n");
this.origin = this.module = module;
this.module = module;
this.loc = loc;
this.error = err;

Error.captureStackTrace(this, this.constructor);
Expand Down
7 changes: 3 additions & 4 deletions lib/ModuleDependencyWarning.js
Expand Up @@ -5,19 +5,18 @@
"use strict";

const WebpackError = require("./WebpackError");
const formatLocation = require("./formatLocation");

module.exports = class ModuleDependencyWarning extends WebpackError {
constructor(module, err, loc) {
super();
super(err.message);

this.name = "ModuleDependencyWarning";
this.message = `${formatLocation(loc)} ${err.message}`;
this.details = err.stack
.split("\n")
.slice(1)
.join("\n");
this.origin = this.module = module;
this.module = module;
this.loc = loc;
this.error = err;

Error.captureStackTrace(this, this.constructor);
Expand Down
4 changes: 1 addition & 3 deletions lib/ModuleError.js
Expand Up @@ -9,12 +9,10 @@ const { cleanUp } = require("./ErrorHelpers");

class ModuleError extends WebpackError {
constructor(module, err) {
super();
super(err && typeof err === "object" && err.message ? err.message : err);

this.name = "ModuleError";
this.module = module;
this.message =
err && typeof err === "object" && err.message ? err.message : err;
this.error = err;
this.details =
err && typeof err === "object" && err.stack
Expand Down
7 changes: 2 additions & 5 deletions lib/ModuleNotFoundError.js
Expand Up @@ -7,16 +7,13 @@
const WebpackError = require("./WebpackError");

class ModuleNotFoundError extends WebpackError {
constructor(module, err, dependencies) {
super();
constructor(module, err) {
super("Module not found: " + err);

this.name = "ModuleNotFoundError";
this.message = "Module not found: " + err;
this.details = err.details;
this.missing = err.missing;
this.module = module;
this.origin = module;
this.dependencies = dependencies;
this.error = err;

Error.captureStackTrace(this, this.constructor);
Expand Down

0 comments on commit dc0e1ec

Please sign in to comment.