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