Sha256: 2bfbef4c7795c084ec47f114f73ea258f9eef0a22d8a018e2901aab8d12d56c4

Contents?: true

Size: 1.75 KB

Versions: 27

Compression:

Stored size: 1.75 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Florent Cailhol @ooflorent
*/
"use strict";

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

class DependencyReference {
	// TODO webpack 5: module must be dynamic, you must pass a function returning a module
	// This is needed to remove the hack in ConcatenatedModule
	// The problem is that the `module` in Dependency could be replaced i. e. because of Scope Hoisting
	/**
	 *
	 * @param {Module} module the referenced module
	 * @param {string[] | boolean} importedNames imported named from the module
	 * @param {boolean=} weak if this is a weak reference
	 * @param {number} order the order information or NaN if don't care
	 */
	constructor(module, importedNames, weak = false, order = NaN) {
		// TODO webpack 5: make it a getter
		this.module = module;
		// true: full object
		// false: only sideeffects/no export
		// array of strings: the exports with this names
		this.importedNames = importedNames;
		this.weak = !!weak;
		this.order = order;
	}

	/**
	 * @param {DependencyReference[]} array an array (will be modified)
	 * @returns {DependencyReference[]} the array again
	 */
	static sort(array) {
		/** @type {WeakMap<DependencyReference, number>} */
		const originalOrder = new WeakMap();
		let i = 0;
		for (const ref of array) {
			originalOrder.set(ref, i++);
		}
		return array.sort((a, b) => {
			const aOrder = a.order;
			const bOrder = b.order;
			if (isNaN(aOrder)) {
				if (!isNaN(bOrder)) {
					return 1;
				}
			} else {
				if (isNaN(bOrder)) {
					return -1;
				}
				if (aOrder !== bOrder) {
					return aOrder - bOrder;
				}
			}
			const aOrg = originalOrder.get(a);
			const bOrg = originalOrder.get(b);
			return aOrg - bOrg;
		});
	}
}

module.exports = DependencyReference;

Version data entries

27 entries across 26 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.18.0 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.18.2 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.16.1 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.15.2 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.18.4 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.18.1 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.14.0 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
tang-0.2.1 spec/tang_app/node_modules/webpack/lib/dependencies/DependencyReference.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/webpack/lib/dependencies/DependencyReference.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/webpack/lib/dependencies/DependencyReference.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/webpack/lib/dependencies/DependencyReference.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/webpack/lib/dependencies/DependencyReference.js
tang-0.2.0 spec/tang_app/node_modules/webpack/lib/dependencies/DependencyReference.js
tang-0.1.0 spec/tang_app/node_modules/webpack/lib/dependencies/DependencyReference.js
tang-0.0.9 spec/tang_app/node_modules/webpack/lib/dependencies/DependencyReference.js
enju_library-0.3.8 spec/dummy/node_modules/webpack/lib/dependencies/DependencyReference.js
jester-data-8.0.0 node_modules/webpack/lib/dependencies/DependencyReference.js