Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/webpack/webpack into type-s…
Browse files Browse the repository at this point in the history
…ortable-set
  • Loading branch information
mohsen1 committed Jun 9, 2018
2 parents 1d39cce + 02a955b commit ce6ac00
Show file tree
Hide file tree
Showing 55 changed files with 896 additions and 401 deletions.
27 changes: 6 additions & 21 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@ declare namespace NodeJS {
}
}

// There are no typings for chrome-trace-event
declare module "chrome-trace-event" {
interface Event {
name: string;
id?: number;
cat: string[];
args?: Object;
}

export class Tracer {
constructor(options: { noStream: boolean });
pipe(stream: NodeJS.WritableStream): void;
instantEvent(event: Event): void;
counter: number;
trace: {
begin(event: Event): void;
end(event: Event): void;
};
}
}

// There are no typings for @webassemblyjs/ast
declare module "@webassemblyjs/ast" {
export function traverse(
Expand Down Expand Up @@ -139,6 +118,12 @@ declare module "@webassemblyjs/ast" {
args: string[];
result: string[];
}

// Node matcher
export function isGlobalType(n: Node): boolean;
export function isTable(n: Node): boolean;
export function isMemory(n: Node): boolean;
export function isFuncImportDescr(n: Node): boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/dll-app-and-vendor/0-vendor/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This is the vendor build part.

It's built separately from the app part. The vendors dll is only built when vendors has changed and not while the normal development cycle.
It's built separately from the app part. The vendors dll is only built when the array of vendors has changed and not during the normal development cycle.

The DllPlugin in combination with the `output.library` option exposes the internal require function as global variable in the target environment.

Expand Down
2 changes: 1 addition & 1 deletion examples/dll-app-and-vendor/0-vendor/template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This is the vendor build part.

It's built separately from the app part. The vendors dll is only built when vendors has changed and not while the normal development cycle.
It's built separately from the app part. The vendors dll is only built when the array of vendors has changed and not during the normal development cycle.

The DllPlugin in combination with the `output.library` option exposes the internal require function as global variable in the target environment.

Expand Down
8 changes: 4 additions & 4 deletions lib/CaseSensitiveModulesWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const WebpackError = require("./WebpackError");
*/
const sortModules = modules => {
return modules.slice().sort((a, b) => {
a = a.identifier();
b = b.identifier();
const aIdent = a.identifier();
const bIdent = b.identifier();
/* istanbul ignore next */
if (a < b) return -1;
if (aIdent < bIdent) return -1;
/* istanbul ignore next */
if (a > b) return 1;
if (aIdent > bIdent) return 1;
/* istanbul ignore next */
return 0;
});
Expand Down
7 changes: 6 additions & 1 deletion lib/HotModuleReplacement.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module.exports = function() {
for (var name in $require$) {
if (
Object.prototype.hasOwnProperty.call($require$, name) &&
name !== "e"
name !== "e" &&
name !== "t"
) {
Object.defineProperty(fn, name, ObjectFactory(name));
}
Expand All @@ -80,6 +81,10 @@ module.exports = function() {
}
}
};
fn.t = function(value, mode) {
if (mode & 1) value = fn(value);
return $require$.t(value, mode & ~1);
};
return fn;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,12 @@ Object.defineProperty(Module.prototype, "meta", {
}, "Module.meta was renamed to Module.buildMeta")
});

/** @type {function(): string} */
Module.prototype.identifier = null;

/** @type {function(RequestShortener): string} */
Module.prototype.readableIdentifier = null;

Module.prototype.build = null;
Module.prototype.source = null;
Module.prototype.size = null;
Expand Down
13 changes: 10 additions & 3 deletions lib/ModuleBuildError.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ const WebpackError = require("./WebpackError");
const { cutOffLoaderExecution } = require("./ErrorHelpers");

class ModuleBuildError extends WebpackError {
constructor(module, err) {
let message = "Module build failed: ";
constructor(module, err, { from = null } = {}) {
let message = "Module build failed";
let details = undefined;
if (from) {
message += ` (from ${from}):\n`;
} else {
message += ": ";
}
if (err !== null && typeof err === "object") {
if (typeof err.stack === "string" && err.stack) {
var stack = cutOffLoaderExecution(err.stack);
const stack = cutOffLoaderExecution(err.stack);
if (!err.hideStack) {
message += stack;
} else {
Expand All @@ -29,6 +34,8 @@ class ModuleBuildError extends WebpackError {
} else {
message += err;
}
} else {
message = err;
}

super(message);
Expand Down
16 changes: 13 additions & 3 deletions lib/ModuleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ const WebpackError = require("./WebpackError");
const { cleanUp } = require("./ErrorHelpers");

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

constructor(module, err, { from = null } = {}) {
let message = "Module Error";
if (from) {
message += ` (from ${from}):\n`;
} else {
message += ": ";
}
if (err && typeof err === "object" && err.message) {
message += err.message;
} else if (err) {
message += err;
}
super(message);
this.name = "ModuleError";
this.module = module;
this.error = err;
Expand Down
20 changes: 13 additions & 7 deletions lib/ModuleWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ const WebpackError = require("./WebpackError");
const { cleanUp } = require("./ErrorHelpers");

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

constructor(module, warning, { from = null } = {}) {
let message = "Module Warning";
if (from) {
message += ` (from ${from}):\n`;
} else {
message += ": ";
}
if (warning && typeof warning === "object" && warning.message) {
message += warning.message;
} else if (warning) {
message += warning;
}
super(message);
this.name = "ModuleWarning";
this.module = module;
this.warning = warning;
Expand Down
53 changes: 47 additions & 6 deletions lib/NormalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,30 @@ class NormalModule extends Module {
}

createLoaderContext(resolver, options, compilation, fs) {
const requestShortener = compilation.runtimeTemplate.requestShortener;
const loaderContext = {
version: 2,
emitWarning: warning => {
if (!(warning instanceof Error)) {
warning = new NonErrorEmittedError(warning);
}
this.warnings.push(new ModuleWarning(this, warning));
const currentLoader = this.getCurrentLoader(loaderContext);
this.warnings.push(
new ModuleWarning(this, warning, {
from: requestShortener.shorten(currentLoader.loader)
})
);
},
emitError: error => {
if (!(error instanceof Error)) {
error = new NonErrorEmittedError(error);
}
this.errors.push(new ModuleError(this, error));
const currentLoader = this.getCurrentLoader(loaderContext);
this.errors.push(
new ModuleError(this, error, {
from: requestShortener.shorten(currentLoader.loader)
})
);
},
exec: (code, filename) => {
// @ts-ignore Argument of type 'this' is not assignable to parameter of type 'Module'.
Expand Down Expand Up @@ -219,6 +230,19 @@ class NormalModule extends Module {
return loaderContext;
}

getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) {
if (
this.loaders &&
this.loaders.length &&
index < this.loaders.length &&
index >= 0 &&
this.loaders[index]
) {
return this.loaders[index];
}
return null;
}

createSource(source, resourceBuffer, sourceMap) {
// if there is no identifier return raw source
if (!this.identifier) {
Expand Down Expand Up @@ -272,7 +296,17 @@ class NormalModule extends Module {
}

if (err) {
const error = new ModuleBuildError(this, err);
if (!(err instanceof Error)) {
err = new NonErrorEmittedError(err);
}
const currentLoader = this.getCurrentLoader(loaderContext);
const error = new ModuleBuildError(this, err, {
from:
currentLoader &&
compilation.runtimeTemplate.requestShortener.shorten(
currentLoader.loader
)
});
return callback(error);
}

Expand All @@ -282,10 +316,17 @@ class NormalModule extends Module {
const extraInfo = result.result.length >= 2 ? result.result[2] : null;

if (!Buffer.isBuffer(source) && typeof source !== "string") {
const error = new ModuleBuildError(
this,
new Error("Final loader didn't return a Buffer or String")
const currentLoader = this.getCurrentLoader(loaderContext, 0);
const err = new Error(
`Final loader (${
currentLoader
? compilation.runtimeTemplate.requestShortener.shorten(
currentLoader.loader
)
: "unknown"
}) didn't return a Buffer or String`
);
const error = new ModuleBuildError(this, err);
return callback(error);
}

Expand Down
10 changes: 8 additions & 2 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const joinRanges = (startRange, endRange) => {
const defaultParserOptions = {
ranges: true,
locations: true,
ecmaVersion: 2018,
ecmaVersion: 2019,
sourceType: "module",
onComment: null,
plugins: {
Expand All @@ -34,6 +34,8 @@ const defaultParserOptions = {
// regexp to match at lease one "magic comment"
const webpackCommentRegExp = new RegExp(/(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/);

const EMPTY_ARRAY = [];

const EMPTY_COMMENT_OPTIONS = {
options: null,
errors: null
Expand Down Expand Up @@ -1356,7 +1358,11 @@ class Parser extends Tapable {
}

walkCatchClause(catchClause) {
this.inScope([catchClause.param], () => {
// Error binding is optional in catch clause since ECMAScript 2019
const errorBinding =
catchClause.param === null ? EMPTY_ARRAY : [catchClause.param];

this.inScope(errorBinding, () => {
this.prewalkStatement(catchClause.body);
this.walkStatement(catchClause.body);
});
Expand Down
Loading

0 comments on commit ce6ac00

Please sign in to comment.