mirror of https://github.com/webpack/webpack.git
improve location reporting
This commit is contained in:
parent
cfac87382f
commit
085f3d7f89
|
@ -43,25 +43,27 @@ class UseEffectRulePlugin {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param {string} path options path
|
||||
* @param {string} defaultIdent default ident when none is provided
|
||||
* @param {object} item user provided use value
|
||||
* @returns {Effect|function(any): Effect[]} effect
|
||||
*/
|
||||
const useToEffect = (defaultIdent, item) => {
|
||||
const useToEffect = (path, defaultIdent, item) => {
|
||||
if (typeof item === "function") {
|
||||
return data => useToEffectsWithoutIdent(item(data));
|
||||
return data => useToEffectsWithoutIdent(path, item(data));
|
||||
} else {
|
||||
return useToEffectRaw(defaultIdent, item);
|
||||
return useToEffectRaw(path, defaultIdent, item);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} path options path
|
||||
* @param {string} defaultIdent default ident when none is provided
|
||||
* @param {object} item user provided use value
|
||||
* @returns {Effect} effect
|
||||
*/
|
||||
const useToEffectRaw = (defaultIdent, item) => {
|
||||
const useToEffectRaw = (path, defaultIdent, item) => {
|
||||
if (typeof item === "string") {
|
||||
return {
|
||||
type,
|
||||
|
@ -98,16 +100,17 @@ class UseEffectRulePlugin {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {string} path options path
|
||||
* @param {any} items user provided use value
|
||||
* @returns {Effect[]} effects
|
||||
*/
|
||||
const useToEffectsWithoutIdent = items => {
|
||||
const useToEffectsWithoutIdent = (path, items) => {
|
||||
if (Array.isArray(items)) {
|
||||
return items.map(item =>
|
||||
useToEffectRaw("[[missing ident]]", item)
|
||||
return items.map((item, idx) =>
|
||||
useToEffectRaw(`${path}[${idx}]`, "[[missing ident]]", item)
|
||||
);
|
||||
}
|
||||
return [useToEffectRaw("[[missing ident]]", items)];
|
||||
return [useToEffectRaw(path, "[[missing ident]]", items)];
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -117,15 +120,18 @@ class UseEffectRulePlugin {
|
|||
*/
|
||||
const useToEffects = (path, items) => {
|
||||
if (Array.isArray(items)) {
|
||||
return items.map((item, idx) =>
|
||||
useToEffect(`${path}[${idx}]`, item)
|
||||
);
|
||||
return items.map((item, idx) => {
|
||||
const subPath = `${path}[${idx}]`;
|
||||
return useToEffect(subPath, subPath, item);
|
||||
});
|
||||
}
|
||||
return [useToEffect(path, items)];
|
||||
return [useToEffect(path, path, items)];
|
||||
};
|
||||
|
||||
if (typeof use === "function") {
|
||||
result.effects.push(data => useToEffectsWithoutIdent(use(data)));
|
||||
result.effects.push(data =>
|
||||
useToEffectsWithoutIdent(`${path}.use`, use(data))
|
||||
);
|
||||
} else {
|
||||
for (const effect of useToEffects(`${path}.use`, use)) {
|
||||
result.effects.push(effect);
|
||||
|
|
Loading…
Reference in New Issue