Skip to content

Commit

Permalink
Update to Prettier 2.3 (#13288)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed May 10, 2021
1 parent 5ae3a6c commit b2d9156
Show file tree
Hide file tree
Showing 45 changed files with 262 additions and 364 deletions.
10 changes: 5 additions & 5 deletions eslint/babel-eslint-parser/src/convert/convertTokens.js
@@ -1,10 +1,10 @@
import { tokTypes } from "@babel/core";

const tl = (process.env.BABEL_8_BREAKING
? Object.fromEntries
: p => p.reduce((o, [k, v]) => ({ ...o, [k]: v }), {}))(
Object.keys(tokTypes).map(key => [key, tokTypes[key].label]),
);
const tl = (
process.env.BABEL_8_BREAKING
? Object.fromEntries
: p => p.reduce((o, [k, v]) => ({ ...o, [k]: v }), {})
)(Object.keys(tokTypes).map(key => [key, tokTypes[key].label]));

function convertTemplateType(tokens) {
let curlyBrace = null;
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -63,7 +63,7 @@
"lint-staged": "^9.2.0",
"lodash": "^4.17.21",
"mergeiterator": "^1.2.5",
"prettier": "^2.2.1",
"prettier": "2.3.0",
"rollup": "^2.47.0",
"rollup-plugin-dts": "^2.0.0",
"rollup-plugin-node-polyfills": "^0.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/caching.ts
Expand Up @@ -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>,
Expand Down
16 changes: 9 additions & 7 deletions packages/babel-core/src/config/config-chain.ts
Expand Up @@ -497,7 +497,7 @@ function buildOverrideEnvDescriptors(
}

function makeChainWalker<
ArgT extends { options: ValidatedOptions; dirname: string }
ArgT extends { options: ValidatedOptions; dirname: string },
>({
root,
env,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];

Expand Down
48 changes: 22 additions & 26 deletions packages/babel-core/src/config/files/configuration.ts
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/files/index.ts
Expand Up @@ -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";

Expand Down
6 changes: 4 additions & 2 deletions packages/babel-core/src/config/files/plugins.ts
Expand Up @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions packages/babel-core/src/config/full.ts
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions packages/babel-core/src/config/index.ts
Expand Up @@ -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") {
Expand Down
6 changes: 2 additions & 4 deletions packages/babel-core/src/config/partial.ts
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/resolve-targets.ts
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/gensync-utils/async.ts
Expand Up @@ -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: (
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-core/src/transform-file.ts
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions packages/babel-core/src/transformation/file/file.ts
Expand Up @@ -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)) {
Expand Down
8 changes: 5 additions & 3 deletions packages/babel-core/src/transformation/normalize-file.ts
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-core/test/helpers/esm.js
Expand Up @@ -66,7 +66,8 @@ async function spawn(runner, filename, cwd = process.cwd()) {
{ cwd, env: process.env },
);

const EXPERIMENTAL_WARNING = /\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\./;
const EXPERIMENTAL_WARNING =
/\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\./;

if (stderr.replace(EXPERIMENTAL_WARNING, "").trim()) {
throw new Error(
Expand Down
18 changes: 4 additions & 14 deletions packages/babel-generator/src/buffer.ts
Expand Up @@ -81,13 +81,8 @@ export default class Buffer {

append(str: string): void {
this._flush();
const {
line,
column,
filename,
identifierName,
force,
} = this._sourcePosition;
const { line, column, filename, identifierName, force } =
this._sourcePosition;
this._append(str, line, column, identifierName, filename, force);
}

Expand All @@ -103,13 +98,8 @@ export default class Buffer {
}
}

const {
line,
column,
filename,
identifierName,
force,
} = this._sourcePosition;
const { line, column, filename, identifierName, force } =
this._sourcePosition;
this._queue.unshift([str, line, column, identifierName, filename, force]);
}

Expand Down
39 changes: 22 additions & 17 deletions packages/babel-generator/src/node/whitespace.ts
Expand Up @@ -200,16 +200,19 @@ export const nodes: {
* Test if Property needs whitespace.
*/

nodes.ObjectProperty = nodes.ObjectTypeProperty = nodes.ObjectMethod = function (
node: t.ObjectProperty | t.ObjectTypeProperty | t.ObjectMethod,
parent: any,
): WhitespaceObject | undefined | null {
if (parent.properties[0] === node) {
return {
before: true,
nodes.ObjectProperty =
nodes.ObjectTypeProperty =
nodes.ObjectMethod =
function (
node: t.ObjectProperty | t.ObjectTypeProperty | t.ObjectMethod,
parent: any,
): WhitespaceObject | undefined | null {
if (parent.properties[0] === node) {
return {
before: true,
};
}
};
}
};

nodes.ObjectTypeCallProperty = function (
node: t.ObjectTypeCallProperty,
Expand Down Expand Up @@ -287,14 +290,16 @@ export const list = {
* Add whitespace tests for nodes and their aliases.
*/

([
["Function", true],
["Class", true],
["Loop", true],
["LabeledStatement", true],
["SwitchStatement", true],
["TryStatement", true],
] as Array<[string, any]>).forEach(function ([type, amounts]) {
(
[
["Function", true],
["Class", true],
["Loop", true],
["LabeledStatement", true],
["SwitchStatement", true],
["TryStatement", true],
] as Array<[string, any]>
).forEach(function ([type, amounts]) {
if (typeof amounts === "boolean") {
amounts = { after: amounts, before: amounts };
}
Expand Down
26 changes: 11 additions & 15 deletions packages/babel-helper-create-class-features-plugin/src/index.js
Expand Up @@ -210,21 +210,17 @@ export function createClassFeaturePlugin({
));
} else {
keysNodes = extractComputedKeys(ref, path, computedPaths, this.file);
({
staticNodes,
pureStaticNodes,
instanceNodes,
wrapClass,
} = buildFieldsInitNodes(
ref,
path.node.superClass,
props,
privateNamesMap,
state,
setPublicClassFields ?? loose,
privateFieldsAsProperties ?? loose,
constantSuper ?? loose,
));
({ staticNodes, pureStaticNodes, instanceNodes, wrapClass } =
buildFieldsInitNodes(
ref,
path.node.superClass,
props,
privateNamesMap,
state,
setPublicClassFields ?? loose,
privateFieldsAsProperties ?? loose,
constantSuper ?? loose,
));
}

if (instanceNodes.length > 0) {
Expand Down

0 comments on commit b2d9156

Please sign in to comment.