mirror of https://github.com/webpack/webpack.git
refactor: avoid boolean
This commit is contained in:
parent
591d3f4bd4
commit
83090d2189
|
@ -3008,7 +3008,7 @@ export interface JavascriptParserOptions {
|
||||||
/**
|
/**
|
||||||
* Specifies global fetchPriority for dynamic import.
|
* Specifies global fetchPriority for dynamic import.
|
||||||
*/
|
*/
|
||||||
dynamicImportFetchPriority?: ("low" | "high" | "auto") | boolean;
|
dynamicImportFetchPriority?: "low" | "high" | "auto" | false;
|
||||||
/**
|
/**
|
||||||
* Specifies global mode for dynamic import.
|
* Specifies global mode for dynamic import.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -223,9 +223,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
||||||
const expr = parser.evaluateExpression(
|
const expr = parser.evaluateExpression(
|
||||||
/** @type {Expression} */ (prop.value)
|
/** @type {Expression} */ (prop.value)
|
||||||
);
|
);
|
||||||
if (expr.isBoolean()) {
|
if (
|
||||||
groupOptions.fetchPriority = "auto";
|
|
||||||
} else if (
|
|
||||||
expr.isString() &&
|
expr.isString() &&
|
||||||
["high", "low", "auto"].includes(expr.string)
|
["high", "low", "auto"].includes(expr.string)
|
||||||
) {
|
) {
|
||||||
|
@ -235,10 +233,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
errors.push(
|
errors.push(
|
||||||
createPropertyParseError(
|
createPropertyParseError(prop, '"high"|"low"|"auto"')
|
||||||
prop,
|
|
||||||
'boolean|"high"|"low"|"auto"'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -65,10 +65,7 @@ class ImportParserPlugin {
|
||||||
dynamicImportFetchPriority !== undefined &&
|
dynamicImportFetchPriority !== undefined &&
|
||||||
dynamicImportFetchPriority !== false
|
dynamicImportFetchPriority !== false
|
||||||
)
|
)
|
||||||
groupOptions.fetchPriority =
|
groupOptions.fetchPriority = dynamicImportFetchPriority;
|
||||||
dynamicImportFetchPriority === true
|
|
||||||
? "auto"
|
|
||||||
: dynamicImportFetchPriority;
|
|
||||||
|
|
||||||
const { options: importOptions, errors: commentErrors } =
|
const { options: importOptions, errors: commentErrors } =
|
||||||
parser.parseCommentOptions(expr.range);
|
parser.parseCommentOptions(expr.range);
|
||||||
|
@ -154,9 +151,7 @@ class ImportParserPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (importOptions.webpackFetchPriority !== undefined) {
|
if (importOptions.webpackFetchPriority !== undefined) {
|
||||||
if (importOptions.webpackFetchPriority === true) {
|
if (
|
||||||
groupOptions.fetchPriority = "auto";
|
|
||||||
} else if (
|
|
||||||
typeof importOptions.webpackFetchPriority === "string" &&
|
typeof importOptions.webpackFetchPriority === "string" &&
|
||||||
["high", "low", "auto"].includes(importOptions.webpackFetchPriority)
|
["high", "low", "auto"].includes(importOptions.webpackFetchPriority)
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -174,7 +174,7 @@ interface ImportMeta {
|
||||||
exclude?: RegExp;
|
exclude?: RegExp;
|
||||||
preload?: boolean | number;
|
preload?: boolean | number;
|
||||||
prefetch?: boolean | number;
|
prefetch?: boolean | number;
|
||||||
fetchPriority?: boolean | "low" | "high" | "auto";
|
fetchPriority?: "low" | "high" | "auto";
|
||||||
chunkName?: string;
|
chunkName?: string;
|
||||||
exports?: string | string[][];
|
exports?: string | string[][];
|
||||||
mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
|
mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1634,14 +1634,7 @@
|
||||||
},
|
},
|
||||||
"dynamicImportFetchPriority": {
|
"dynamicImportFetchPriority": {
|
||||||
"description": "Specifies global fetchPriority for dynamic import.",
|
"description": "Specifies global fetchPriority for dynamic import.",
|
||||||
"anyOf": [
|
"enum": ["low", "high", "auto", false]
|
||||||
{
|
|
||||||
"enum": ["low", "high", "auto"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"dynamicImportMode": {
|
"dynamicImportMode": {
|
||||||
"description": "Specifies global mode for dynamic import.",
|
"description": "Specifies global mode for dynamic import.",
|
||||||
|
|
|
@ -6,7 +6,7 @@ it("should set fetchPriority", () => {
|
||||||
const script1 = document.head._children[1];
|
const script1 = document.head._children[1];
|
||||||
expect(script1._attributes.fetchpriority).toBe("low");
|
expect(script1._attributes.fetchpriority).toBe("low");
|
||||||
|
|
||||||
import(/* webpackFetchPriority: "high" */ "./c");
|
import(/* webpackPrefetch: true */ "./c");
|
||||||
expect(document.head._children).toHaveLength(3);
|
expect(document.head._children).toHaveLength(3);
|
||||||
const script2 = document.head._children[2];
|
const script2 = document.head._children[2];
|
||||||
expect(script2._attributes.fetchpriority).toBe("high");
|
expect(script2._attributes.fetchpriority).toBe("high");
|
||||||
|
|
|
@ -6016,7 +6016,7 @@ declare interface JavascriptParserOptions {
|
||||||
/**
|
/**
|
||||||
* Specifies global fetchPriority for dynamic import.
|
* Specifies global fetchPriority for dynamic import.
|
||||||
*/
|
*/
|
||||||
dynamicImportFetchPriority?: boolean | "auto" | "low" | "high";
|
dynamicImportFetchPriority?: false | "auto" | "low" | "high";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies global mode for dynamic import.
|
* Specifies global mode for dynamic import.
|
||||||
|
|
Loading…
Reference in New Issue