webpack/lib/dependencies/ImportContextDependency.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-12-03 18:36:10 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const ContextDependency = require("./ContextDependency");
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
2016-12-03 18:36:10 +08:00
2017-10-16 18:52:04 +08:00
function equalRegExp(a, b) {
if(a === b) return true;
if(typeof a !== "object" || typeof b !== "object") return false;
return a + "" === b + "";
}
class ImportContextDependency extends ContextDependency {
2017-10-16 18:52:04 +08:00
constructor(request, recursive, regExp, range, valueRange, options) {
super(request, recursive, regExp);
this.range = range;
this.valueRange = valueRange;
2017-10-16 18:52:04 +08:00
this.options = options;
}
isEqualResource(other) {
if(!super.isEqualResource(other)) return false;
if(!(other instanceof ImportContextDependency))
return false;
return this.options.async === other.options.async &&
this.options.chunkName === other.options.chunkName &&
equalRegExp(this.options.include, other.options.include) &&
equalRegExp(this.options.exclude, other.options.exclude);
}
get type() {
2017-10-16 18:52:04 +08:00
return `import() context ${this.options.async}`;
}
2016-12-03 18:36:10 +08:00
}
2016-12-03 18:36:10 +08:00
ImportContextDependency.Template = ContextDependencyTemplateAsRequireCall;
module.exports = ImportContextDependency;