2013-01-31 01:49:25 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2017-01-08 12:03:25 +08:00
|
|
|
"use strict";
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2017-01-08 12:03:25 +08:00
|
|
|
const Dependency = require("../Dependency");
|
2018-07-23 23:33:29 +08:00
|
|
|
const DependencyTemplate = require("../DependencyTemplate");
|
2017-10-03 17:26:05 +08:00
|
|
|
const CriticalDependencyWarning = require("./CriticalDependencyWarning");
|
2013-01-31 01:49:25 +08:00
|
|
|
|
2018-02-25 09:00:20 +08:00
|
|
|
const regExpToString = r => (r ? r + "" : "");
|
2017-11-19 07:22:38 +08:00
|
|
|
|
2017-01-08 12:03:25 +08:00
|
|
|
class ContextDependency extends Dependency {
|
2018-04-16 16:27:22 +08:00
|
|
|
// options: { request, recursive, regExp, include, exclude, mode, chunkName, groupOptions }
|
2017-10-16 19:19:53 +08:00
|
|
|
constructor(options) {
|
2017-01-08 12:03:25 +08:00
|
|
|
super();
|
2017-10-16 19:19:53 +08:00
|
|
|
this.options = options;
|
|
|
|
this.userRequest = this.options.request;
|
2018-04-11 23:43:56 +08:00
|
|
|
/** @type {false | string} */
|
2018-04-11 02:58:32 +08:00
|
|
|
this.critical = false;
|
2017-10-03 17:26:05 +08:00
|
|
|
this.hadGlobalOrStickyRegExp = false;
|
2018-02-25 09:00:20 +08:00
|
|
|
if (this.options.regExp.global || this.options.regExp.sticky) {
|
2017-10-16 19:19:53 +08:00
|
|
|
this.options.regExp = null;
|
2017-10-03 17:26:05 +08:00
|
|
|
this.hadGlobalOrStickyRegExp = true;
|
|
|
|
}
|
2018-07-23 23:33:29 +08:00
|
|
|
this.request = undefined;
|
|
|
|
this.range = undefined;
|
|
|
|
this.valueRange = undefined;
|
|
|
|
// TODO refactor this
|
|
|
|
this.prepend = undefined;
|
|
|
|
// TODO refactor this
|
|
|
|
this.replaces = undefined;
|
2017-01-08 12:03:25 +08:00
|
|
|
}
|
|
|
|
|
2017-11-19 07:22:38 +08:00
|
|
|
getResourceIdentifier() {
|
2018-02-25 09:00:20 +08:00
|
|
|
return (
|
|
|
|
`context${this.options.request} ${this.options.recursive} ` +
|
|
|
|
`${regExpToString(this.options.regExp)} ${regExpToString(
|
|
|
|
this.options.include
|
|
|
|
)} ${regExpToString(this.options.exclude)} ` +
|
2018-04-16 16:27:22 +08:00
|
|
|
`${this.options.mode} ${this.options.chunkName} ` +
|
|
|
|
`${JSON.stringify(this.options.groupOptions)}`
|
2018-02-25 09:00:20 +08:00
|
|
|
);
|
2017-01-08 12:03:25 +08:00
|
|
|
}
|
2017-10-03 17:26:05 +08:00
|
|
|
|
|
|
|
getWarnings() {
|
|
|
|
let warnings = super.getWarnings() || [];
|
2018-02-25 09:00:20 +08:00
|
|
|
if (this.critical) {
|
2017-10-03 17:26:05 +08:00
|
|
|
warnings.push(new CriticalDependencyWarning(this.critical));
|
|
|
|
}
|
2018-02-25 09:00:20 +08:00
|
|
|
if (this.hadGlobalOrStickyRegExp) {
|
|
|
|
warnings.push(
|
|
|
|
new CriticalDependencyWarning(
|
|
|
|
"Contexts can't use RegExps with the 'g' or 'y' flags."
|
|
|
|
)
|
|
|
|
);
|
2017-10-03 17:26:05 +08:00
|
|
|
}
|
|
|
|
return warnings;
|
|
|
|
}
|
2013-01-31 01:49:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
ContextDependency.Template = DependencyTemplate;
|
|
|
|
|
2017-01-08 12:03:25 +08:00
|
|
|
module.exports = ContextDependency;
|