Update to Prettier 2.3 (#13288)
This commit is contained in:
@@ -208,7 +208,7 @@ function updateFunctionCache<
|
||||
ArgT,
|
||||
ResultT,
|
||||
SideChannel,
|
||||
Cache extends CacheMap<ArgT, ResultT, SideChannel>
|
||||
Cache extends CacheMap<ArgT, ResultT, SideChannel>,
|
||||
>(
|
||||
cache: Cache,
|
||||
config: CacheConfigurator<SideChannel>,
|
||||
|
||||
@@ -497,7 +497,7 @@ function buildOverrideEnvDescriptors(
|
||||
}
|
||||
|
||||
function makeChainWalker<
|
||||
ArgT extends { options: ValidatedOptions; dirname: string }
|
||||
ArgT extends { options: ValidatedOptions; dirname: string },
|
||||
>({
|
||||
root,
|
||||
env,
|
||||
@@ -582,8 +582,12 @@ function makeChainWalker<
|
||||
// that we don't do extra work loading extended configs if a file is
|
||||
// ignored.
|
||||
if (
|
||||
flattenedConfigs.some(({ config: { options: { ignore, only } } }) =>
|
||||
shouldIgnore(context, ignore, only, dirname),
|
||||
flattenedConfigs.some(
|
||||
({
|
||||
config: {
|
||||
options: { ignore, only },
|
||||
},
|
||||
}) => shouldIgnore(context, ignore, only, dirname),
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
@@ -713,10 +717,8 @@ function normalizeOptions(opts: ValidatedOptions): ValidatedOptions {
|
||||
function dedupDescriptors(
|
||||
items: Array<UnloadedDescriptor>,
|
||||
): Array<UnloadedDescriptor> {
|
||||
const map: Map<
|
||||
Function,
|
||||
Map<string | void, { value: UnloadedDescriptor }>
|
||||
> = new Map();
|
||||
const map: Map<Function, Map<string | void, { value: UnloadedDescriptor }>> =
|
||||
new Map();
|
||||
|
||||
const descriptors = [];
|
||||
|
||||
|
||||
@@ -205,9 +205,7 @@ const readConfigJS = makeStrongCache(function* readConfigJS(
|
||||
// @ts-expect-error - if we want to make it possible to use async configs
|
||||
yield* [];
|
||||
|
||||
options = ((options as any) as (api: ConfigAPI) => {})(
|
||||
makeConfigAPI(cache),
|
||||
);
|
||||
options = (options as any as (api: ConfigAPI) => {})(makeConfigAPI(cache));
|
||||
|
||||
assertCache = true;
|
||||
}
|
||||
@@ -256,32 +254,30 @@ const packageToBabelConfig = makeWeakCacheSync(
|
||||
},
|
||||
);
|
||||
|
||||
const readConfigJSON5 = makeStaticFileCache(
|
||||
(filepath, content): ConfigFile => {
|
||||
let options;
|
||||
try {
|
||||
options = json5.parse(content);
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while parsing config - ${err.message}`;
|
||||
throw err;
|
||||
}
|
||||
const readConfigJSON5 = makeStaticFileCache((filepath, content): ConfigFile => {
|
||||
let options;
|
||||
try {
|
||||
options = json5.parse(content);
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while parsing config - ${err.message}`;
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (!options) throw new Error(`${filepath}: No config detected`);
|
||||
if (!options) throw new Error(`${filepath}: No config detected`);
|
||||
|
||||
if (typeof options !== "object") {
|
||||
throw new Error(`${filepath}: Config returned typeof ${typeof options}`);
|
||||
}
|
||||
if (Array.isArray(options)) {
|
||||
throw new Error(`${filepath}: Expected config object but found array`);
|
||||
}
|
||||
if (typeof options !== "object") {
|
||||
throw new Error(`${filepath}: Config returned typeof ${typeof options}`);
|
||||
}
|
||||
if (Array.isArray(options)) {
|
||||
throw new Error(`${filepath}: Expected config object but found array`);
|
||||
}
|
||||
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options,
|
||||
};
|
||||
},
|
||||
);
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options,
|
||||
};
|
||||
});
|
||||
|
||||
const readIgnoreConfig = makeStaticFileCache((filepath, content) => {
|
||||
const ignoreDir = path.dirname(filepath);
|
||||
|
||||
@@ -3,7 +3,7 @@ type indexType = typeof import("./index");
|
||||
|
||||
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||
// exports of index-browser, since this file may be replaced at bundle time with index-browser.
|
||||
((({} as any) as indexBrowserType) as indexType);
|
||||
({} as any as indexBrowserType as indexType);
|
||||
|
||||
export { findPackageData } from "./package";
|
||||
|
||||
|
||||
@@ -17,8 +17,10 @@ const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-plugin-)/;
|
||||
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-preset-)/;
|
||||
const BABEL_PLUGIN_ORG_RE = /^(@babel\/)(?!plugin-|[^/]+\/)/;
|
||||
const BABEL_PRESET_ORG_RE = /^(@babel\/)(?!preset-|[^/]+\/)/;
|
||||
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-plugin(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-preset(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_PLUGIN_ORG_RE =
|
||||
/^(@(?!babel\/)[^/]+\/)(?![^/]*babel-plugin(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_PRESET_ORG_RE =
|
||||
/^(@(?!babel\/)[^/]+\/)(?![^/]*babel-preset(?:-|\/|$)|[^/]+\/)/;
|
||||
const OTHER_ORG_DEFAULT_RE = /^(@(?!babel$)[^/]+)$/;
|
||||
|
||||
export function resolvePlugin(name: string, dirname: string): string | null {
|
||||
|
||||
@@ -279,14 +279,10 @@ const makeDescriptorLoader = <Context, API>(
|
||||
return { value: item, options, dirname, alias };
|
||||
});
|
||||
|
||||
const pluginDescriptorLoader = makeDescriptorLoader<
|
||||
Context.SimplePlugin,
|
||||
PluginAPI
|
||||
>(makePluginAPI);
|
||||
const presetDescriptorLoader = makeDescriptorLoader<
|
||||
Context.SimplePreset,
|
||||
PresetAPI
|
||||
>(makePresetAPI);
|
||||
const pluginDescriptorLoader =
|
||||
makeDescriptorLoader<Context.SimplePlugin, PluginAPI>(makePluginAPI);
|
||||
const presetDescriptorLoader =
|
||||
makeDescriptorLoader<Context.SimplePreset, PresetAPI>(makePresetAPI);
|
||||
|
||||
/**
|
||||
* Instantiate a plugin for the given descriptor, returning the plugin/options pair.
|
||||
|
||||
@@ -24,9 +24,10 @@ const loadOptionsRunner = gensync<(opts: unknown) => any>(function* (opts) {
|
||||
return config?.options ?? null;
|
||||
});
|
||||
|
||||
const createConfigItemRunner = gensync<
|
||||
(...args: Parameters<typeof createConfigItemImpl>) => ConfigItem
|
||||
>(createConfigItemImpl);
|
||||
const createConfigItemRunner =
|
||||
gensync<(...args: Parameters<typeof createConfigItemImpl>) => ConfigItem>(
|
||||
createConfigItemImpl,
|
||||
);
|
||||
|
||||
const maybeErrback = runner => (opts: unknown, callback?: Function) => {
|
||||
if (callback === undefined && typeof opts === "function") {
|
||||
|
||||
@@ -169,10 +169,8 @@ export const loadPartialConfig = gensync<
|
||||
({ showIgnoredFiles, ...opts } = opts);
|
||||
}
|
||||
|
||||
const result:
|
||||
| PrivPartialConfig
|
||||
| undefined
|
||||
| null = yield* loadPrivatePartialConfig(opts);
|
||||
const result: PrivPartialConfig | undefined | null =
|
||||
yield* loadPrivatePartialConfig(opts);
|
||||
if (!result) return null;
|
||||
|
||||
const { options, babelrc, ignore, config, fileHandling, files } = result;
|
||||
|
||||
@@ -3,7 +3,7 @@ type nodeType = typeof import("./resolve-targets");
|
||||
|
||||
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||
// exports of index-browser, since this file may be replaced at bundle time with index-browser.
|
||||
((({} as any) as browserType) as nodeType);
|
||||
({} as any as browserType as nodeType);
|
||||
|
||||
import type { ValidatedOptions } from "./validation/options";
|
||||
import path from "path";
|
||||
|
||||
@@ -67,7 +67,7 @@ const withKind = gensync<(cb: (kind: "sync" | "async") => any) => any>({
|
||||
// )
|
||||
export function forwardAsync<
|
||||
Action extends (...args: unknown[]) => any,
|
||||
Return
|
||||
Return,
|
||||
>(
|
||||
action: (...args: Parameters<Action>) => Handler<ReturnType<Action>>,
|
||||
cb: (
|
||||
|
||||
@@ -12,7 +12,7 @@ type transformFileType = typeof import("./transform-file");
|
||||
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||
// exports of transform-file-browser, since this file may be replaced at bundle time with
|
||||
// transform-file-browser.
|
||||
((({} as any) as transformFileBrowserType) as transformFileType);
|
||||
({} as any as transformFileBrowserType as transformFileType);
|
||||
|
||||
type TransformFile = {
|
||||
(filename: string, callback: FileResultCallback): void;
|
||||
|
||||
@@ -187,9 +187,8 @@ export default class File {
|
||||
// make sure that the helper exists
|
||||
helpers.ensure(name, File);
|
||||
|
||||
const uid = (this.declarations[name] = this.scope.generateUidIdentifier(
|
||||
name,
|
||||
));
|
||||
const uid = (this.declarations[name] =
|
||||
this.scope.generateUidIdentifier(name));
|
||||
|
||||
const dependencies = {};
|
||||
for (const dep of helpers.getDependencies(name)) {
|
||||
|
||||
@@ -76,7 +76,7 @@ export default function* normalizeFile(
|
||||
} else {
|
||||
inputMap = convertSourceMap.fromJSON(
|
||||
// todo:
|
||||
(inputMapContent as unknown) as string,
|
||||
inputMapContent as unknown as string,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -99,8 +99,10 @@ export default function* normalizeFile(
|
||||
// but without // or /* at the beginning of the comment.
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/;
|
||||
const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/;
|
||||
const INLINE_SOURCEMAP_REGEX =
|
||||
/^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/;
|
||||
const EXTERNAL_SOURCEMAP_REGEX =
|
||||
/^[@#][ \t]+sourceMappingURL=([^\s'"`]+)[ \t]*$/;
|
||||
|
||||
function extractCommentsFromList(regex, comments, lastComment) {
|
||||
if (comments) {
|
||||
|
||||
Reference in New Issue
Block a user