Skip to content

Commit

Permalink
chore: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
rasendubi committed Nov 14, 2023
1 parent e71a8a8 commit 875b0c2
Show file tree
Hide file tree
Showing 30 changed files with 1,653 additions and 1,559 deletions.
2 changes: 1 addition & 1 deletion examples/next-blog-starter/components/cover-image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cn from 'classnames';
import Link from 'next/link';
import Image from "next/legacy/image";
import Image from 'next/legacy/image';

export default function CoverImage({ title, src, slug, height, width }) {
const image = (
Expand Down
6 changes: 5 additions & 1 deletion examples/next-blog-starter/components/hero-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export default function HeroPost({
<div className="md:grid md:grid-cols-2 md:gap-x-16 lg:gap-x-8 mb-20 md:mb-28">
<div>
<h3 className="mb-4 text-4xl lg:text-6xl leading-tight">
<Link as={`/posts/${slug}`} href="/posts/[slug]" className="hover:underline">
<Link
as={`/posts/${slug}`}
href="/posts/[slug]"
className="hover:underline"
>
{title}
</Link>
</h3>
Expand Down
6 changes: 5 additions & 1 deletion examples/next-blog-starter/components/post-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export default function PostPreview({
/>
</div>
<h3 className="text-3xl mb-3 leading-snug">
<Link as={`/posts/${slug}`} href="/posts/[slug]" className="hover:underline">
<Link
as={`/posts/${slug}`}
href="/posts/[slug]"
className="hover:underline"
>
{title}
</Link>
</h3>
Expand Down
10 changes: 5 additions & 5 deletions packages/orgx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @typedef {import('./lib/evaluate.js').EvaluateOptions} EvaluateOptions
*/

export {createProcessor} from './lib/core.js'
export {compile, compileSync} from './lib/compile.js'
export {evaluate, evaluateSync} from './lib/evaluate.js'
export {run, runSync} from './lib/run.js'
export {nodeTypes} from './lib/node-types.js'
export { createProcessor } from './lib/core.js';
export { compile, compileSync } from './lib/compile.js';
export { evaluate, evaluateSync } from './lib/evaluate.js';
export { run, runSync } from './lib/run.js';
export { nodeTypes } from './lib/node-types.js';
2 changes: 1 addition & 1 deletion packages/orgx/lib/condition.browser.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const development = false
export const development = false;
4 changes: 2 additions & 2 deletions packages/orgx/lib/condition.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import process from 'process'
import process from 'process';

export const development = process.env.NODE_ENV === 'development'
export const development = process.env.NODE_ENV === 'development';
14 changes: 7 additions & 7 deletions packages/orgx/lib/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* @typedef {import('mdx/types').MDXModule} ExportMap
*/

import {compile, compileSync} from './compile.js'
import {run, runSync} from './run.js'
import {resolveEvaluateOptions} from './util/resolve-evaluate-options.js'
import { compile, compileSync } from './compile.js';
import { run, runSync } from './run.js';
import { resolveEvaluateOptions } from './util/resolve-evaluate-options.js';

/**
* Evaluate MDX.
Expand All @@ -19,10 +19,10 @@ import {resolveEvaluateOptions} from './util/resolve-evaluate-options.js'
* @return {Promise<ExportMap>}
*/
export async function evaluate(vfileCompatible, evaluateOptions) {
const {compiletime, runtime} = resolveEvaluateOptions(evaluateOptions)
const { compiletime, runtime } = resolveEvaluateOptions(evaluateOptions);
// V8 on Erbium.
/* c8 ignore next 2 */
return run(await compile(vfileCompatible, compiletime), runtime)
return run(await compile(vfileCompatible, compiletime), runtime);
}

/**
Expand All @@ -35,6 +35,6 @@ export async function evaluate(vfileCompatible, evaluateOptions) {
* @return {ExportMap}
*/
export function evaluateSync(vfileCompatible, evaluateOptions) {
const {compiletime, runtime} = resolveEvaluateOptions(evaluateOptions)
return runSync(compileSync(vfileCompatible, compiletime), runtime)
const { compiletime, runtime } = resolveEvaluateOptions(evaluateOptions);
return runSync(compileSync(vfileCompatible, compiletime), runtime);
}
4 changes: 2 additions & 2 deletions packages/orgx/lib/node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const nodeTypes = [
'mdxJsxFlowElement',
'mdxJsxTextElement',
'mdxTextExpression',
'mdxjsEsm'
]
'mdxjsEsm',
];
16 changes: 8 additions & 8 deletions packages/orgx/lib/plugin/recma-jsx-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* `arguments[0]` instead.
*/

import {buildJsx} from 'estree-util-build-jsx'
import {specifiersToDeclarations} from '../util/estree-util-specifiers-to-declarations.js'
import {toIdOrMemberExpression} from '../util/estree-util-to-id-or-member-expression.js'
import { buildJsx } from 'estree-util-build-jsx';
import { specifiersToDeclarations } from '../util/estree-util-specifiers-to-declarations.js';
import { toIdOrMemberExpression } from '../util/estree-util-to-id-or-member-expression.js';

/**
* A plugin to build JSX into function calls.
Expand All @@ -19,10 +19,10 @@ import {toIdOrMemberExpression} from '../util/estree-util-to-id-or-member-expres
* @type {import('unified').Plugin<[BuildJsxOptions & RecmaJsxBuildOptions?], Program>}
*/
export function recmaJsxBuild(options = {}) {
const {development, outputFormat} = options
const { development, outputFormat } = options;

return (tree, file) => {
buildJsx(tree, {development, filePath: file.history[0]})
buildJsx(tree, { development, filePath: file.history[0] });

// When compiling to a function body, replace the import that was just
// generated, and get `jsx`, `jsxs`, and `Fragment` from `arguments[0]`
Expand All @@ -40,8 +40,8 @@ export function recmaJsxBuild(options = {}) {
declarations: specifiersToDeclarations(
tree.body[0].specifiers,
toIdOrMemberExpression(['arguments', 0])
)
}
),
};
}
}
};
}
43 changes: 21 additions & 22 deletions packages/orgx/lib/plugin/recma-jsx-rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export function recmaJsxRewrite(options = {}) {
walk(tree, {
enter(_node) {
const node = /** @type {Node} */ (_node);
const newScope = /** @type {Scope|undefined} */ (scopeInfo.map.get(
node
));
const newScope = /** @type {Scope|undefined} */ (
scopeInfo.map.get(node)
);

if (
node.type === 'FunctionDeclaration' ||
Expand Down Expand Up @@ -142,7 +142,9 @@ export function recmaJsxRewrite(options = {}) {
const isInScope = inScope(currentScope, id);

if (!own.call(fnScope.references, fullId)) {
const parentScope = /** @type {Scope|null} */ (currentScope.parent);
const parentScope = /** @type {Scope|null} */ (
currentScope.parent
);
if (
!isInScope ||
// If the parent scope is `_createContent`, then this
Expand Down Expand Up @@ -198,9 +200,8 @@ export function recmaJsxRewrite(options = {}) {
/** @type {Array<string | number>} */
let jsxIdExpression = ['_components', id];
if (isIdentifierName(id) === false) {
let invalidComponentName = fnScope.idToInvalidComponentName.get(
id
);
let invalidComponentName =
fnScope.idToInvalidComponentName.get(id);
if (invalidComponentName === undefined) {
invalidComponentName = `_component${fnScope.idToInvalidComponentName.size}`;
fnScope.idToInvalidComponentName.set(id, invalidComponentName);
Expand All @@ -209,14 +210,12 @@ export function recmaJsxRewrite(options = {}) {
jsxIdExpression = [invalidComponentName];
}

node.openingElement.name = toJsxIdOrMemberExpression(
jsxIdExpression
);
node.openingElement.name =
toJsxIdOrMemberExpression(jsxIdExpression);

if (node.closingElement) {
node.closingElement.name = toJsxIdOrMemberExpression(
jsxIdExpression
);
node.closingElement.name =
toJsxIdOrMemberExpression(jsxIdExpression);
}
}
}
Expand Down Expand Up @@ -315,15 +314,15 @@ export function recmaJsxRewrite(options = {}) {
optional: false,
}
: parameters[0].type === 'MemberExpression'
? // If we’re only getting components from `props.components`,
// make sure it’s defined.
{
type: 'LogicalExpression',
operator: '||',
left: parameters[0],
right: { type: 'ObjectExpression', properties: [] },
}
: parameters[0];
? // If we’re only getting components from `props.components`,
// make sure it’s defined.
{
type: 'LogicalExpression',
operator: '||',
left: parameters[0],
right: { type: 'ObjectExpression', properties: [] },
}
: parameters[0];

/** @type {ObjectPattern|undefined} */
let componentsPattern;
Expand Down
14 changes: 7 additions & 7 deletions packages/orgx/lib/plugin/recma-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* in.
*/

import {toJs, jsx} from 'estree-util-to-js'
import { toJs, jsx } from 'estree-util-to-js';

/**
* A plugin that adds an esast compiler: a small wrapper around `astring` to add
Expand All @@ -18,22 +18,22 @@ import {toJs, jsx} from 'estree-util-to-js'
* @type {import('unified').Plugin<[RecmaStringifyOptions]|[], Program, string>}
*/
export function recmaStringify(options = {}) {
const {SourceMapGenerator} = options
const { SourceMapGenerator } = options;

Object.assign(this, {Compiler: compiler})
Object.assign(this, { Compiler: compiler });

/** @type {import('unified').CompilerFunction<Program, string>} */
function compiler(tree, file) {
const result = SourceMapGenerator
? toJs(tree, {
filePath: file.path || 'unknown.mdx',
SourceMapGenerator,
handlers: jsx
handlers: jsx,
})
: toJs(tree, {handlers: jsx})
: toJs(tree, { handlers: jsx });

file.map = result.map
file.map = result.map;

return result.value
return result.value;
}
}
4 changes: 2 additions & 2 deletions packages/orgx/lib/plugin/rehype-recma.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @typedef {import('hast').Root} Root
*/

import {toEstree} from 'hast-util-to-estree'
import { toEstree } from 'hast-util-to-estree';

/**
* A plugin to transform an HTML (hast) tree to a JS (estree).
Expand All @@ -12,5 +12,5 @@ import {toEstree} from 'hast-util-to-estree'
* @type {import('unified').Plugin<Array<void>, Root, Program>}
*/
export function rehypeRecma() {
return (tree) => toEstree(tree)
return (tree) => toEstree(tree);
}
10 changes: 5 additions & 5 deletions packages/orgx/lib/plugin/rehype-remove-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @typedef {import('hast').Root} Root
*/

import {visit} from 'unist-util-visit'
import { visit } from 'unist-util-visit';

/**
* A tiny plugin that removes raw HTML.
Expand All @@ -15,9 +15,9 @@ export function rehypeRemoveRaw() {
return (tree) => {
visit(tree, 'raw', (_, index, parent) => {
if (parent && typeof index === 'number') {
parent.children.splice(index, 1)
return index
parent.children.splice(index, 1);
return index;
}
})
}
});
};
}
6 changes: 3 additions & 3 deletions packages/orgx/lib/run.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {new (code: string, ...args: Array<unknown>) => Function} **/
const AsyncFunction = Object.getPrototypeOf(run).constructor
const AsyncFunction = Object.getPrototypeOf(run).constructor;

/**
* Asynchronously run code.
Expand All @@ -12,7 +12,7 @@ const AsyncFunction = Object.getPrototypeOf(run).constructor
export async function run(file, options) {
// V8 on Erbium.
/* c8 ignore next 2 */
return new AsyncFunction(String(file))(options)
return new AsyncFunction(String(file))(options);
}

/**
Expand All @@ -25,5 +25,5 @@ export async function run(file, options) {
*/
export function runSync(file, options) {
// eslint-disable-next-line no-new-func
return new Function(String(file))(options)
return new Function(String(file))(options);
}
10 changes: 5 additions & 5 deletions packages/orgx/lib/util/estree-util-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
export function create(template, node) {
/** @type {Array<keyof template>} */
// @ts-expect-error: `start`, `end`, `comments` are custom Acorn fields.
const fields = ['start', 'end', 'loc', 'range', 'comments']
let index = -1
const fields = ['start', 'end', 'loc', 'range', 'comments'];
let index = -1;

while (++index < fields.length) {
const field = fields[index]
const field = fields[index];

if (field in template) {
// @ts-expect-error: assume they’re settable.
node[field] = template[field]
node[field] = template[field];
}
}

return node
return node;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
*/
export function declarationToExpression(declaration) {
if (declaration.type === 'FunctionDeclaration') {
return {...declaration, type: 'FunctionExpression'}
return { ...declaration, type: 'FunctionExpression' };
}

if (declaration.type === 'ClassDeclaration') {
return {...declaration, type: 'ClassExpression'}
return { ...declaration, type: 'ClassExpression' };
/* Internal utility so the next shouldn’t happen or a maintainer is making a
* mistake. */
/* c8 ignore next 4 */
}

// Probably `VariableDeclaration`.
throw new Error('Cannot turn `' + declaration.type + '` into an expression')
throw new Error('Cannot turn `' + declaration.type + '` into an expression');
}
4 changes: 2 additions & 2 deletions packages/orgx/lib/util/estree-util-is-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
export function isDeclaration(node) {
/** @type {string} */
// @ts-expect-error Hush typescript, looks like `type` is available.
const type = node && typeof node === 'object' && node.type
const type = node && typeof node === 'object' && node.type;
return Boolean(
type === 'FunctionDeclaration' ||
type === 'ClassDeclaration' ||
type === 'VariableDeclaration'
)
);
}
Loading

0 comments on commit 875b0c2

Please sign in to comment.