Skip to content

Commit

Permalink
Rename checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed May 29, 2023
1 parent e7ceb45 commit 95681d1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/forgetti/src/core/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function isHookOrComponentName(ctx: StateContext, id: t.Identifier): bool

const FORGETTI_SKIP = /^\s*@forgetti skip\s*$/;

export function isNodeShouldBeSkipped(node: t.Node): boolean {
export function shouldSkipNode(node: t.Node): boolean {
// Node without leading comments shouldn't be skipped
if (node.leadingComments) {
for (let i = 0, len = node.leadingComments.length; i < len; i++) {
Expand All @@ -44,7 +44,7 @@ export function isNodeShouldBeSkipped(node: t.Node): boolean {

const FORGETTI_JSX_SKIP = /^\s*@forgetti jsx\s*$/;

export function isJSXShouldBeSkipped(node: t.Node): boolean {
export function shouldSkipJSX(node: t.Node): boolean {
// Node without leading comments shouldn't be skipped
if (node.leadingComments) {
for (let i = 0, len = node.leadingComments.length; i < len; i++) {
Expand All @@ -65,7 +65,7 @@ export function isComponentValid(
node.type !== 'ArrowFunctionExpression'
&& !!node.id
&& isHookOrComponentName(ctx, node.id)
&& !isNodeShouldBeSkipped(node)
&& !shouldSkipNode(node)
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/forgetti/src/core/is-constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import type * as babel from '@babel/core';
import * as t from '@babel/types';
import { isNestedExpression, isNodeShouldBeSkipped, isPathValid } from './checks';
import { isNestedExpression, shouldSkipNode, isPathValid } from './checks';
import type OptimizerScope from './optimizer-scope';
import getForeignBindings, { isForeignBinding } from './get-foreign-bindings';
import type { ComponentNode, StateContext } from './types';
Expand Down Expand Up @@ -343,7 +343,7 @@ function uncachedIsConstant(
instance: OptimizerInstance,
path: babel.NodePath<t.Expression>,
): boolean {
if (isNodeShouldBeSkipped(path.node)) {
if (shouldSkipNode(path.node)) {
return false;
}
if (isPathValid(path, isNestedExpression)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/forgetti/src/core/optimize-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from '@babel/types';
import type { ComponentNode, StateContext } from './types';
import getImportIdentifier from './get-import-identifier';
import { RUNTIME_MEMO } from './imports';
import { isJSXShouldBeSkipped, isPathValid } from './checks';
import { shouldSkipJSX, isPathValid } from './checks';
import type { ImportDefinition } from './presets';

interface JSXReplacement {
Expand Down Expand Up @@ -169,7 +169,7 @@ function transformJSX(
path: babel.NodePath<t.JSXElement | t.JSXFragment>,
memoDefinition: ImportDefinition,
): void {
if (isJSXShouldBeSkipped(path.node)) {
if (shouldSkipJSX(path.node)) {
return;
}
const state: State = {
Expand Down
8 changes: 4 additions & 4 deletions packages/forgetti/src/core/optimizer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import type * as babel from '@babel/core';
import * as t from '@babel/types';
import { isNestedExpression, isNodeShouldBeSkipped, isPathValid } from './checks';
import { isNestedExpression, shouldSkipNode, isPathValid } from './checks';
import getForeignBindings, { isForeignBinding } from './get-foreign-bindings';
import getImportIdentifier from './get-import-identifier';
import { RUNTIME_EQUALS } from './imports';
Expand Down Expand Up @@ -875,7 +875,7 @@ export default class Optimizer {
optimizeExpression(
path: babel.NodePath<t.Expression>,
): OptimizedExpression {
if (isNodeShouldBeSkipped(path.node)) {
if (shouldSkipNode(path.node)) {
return optimizedExpr(path.node, undefined, true);
}
if (isPathValid(path, isNestedExpression)) {
Expand Down Expand Up @@ -1006,7 +1006,7 @@ export default class Optimizer {
private optimizeBlock(
path: babel.NodePath<t.BlockStatement>,
): void {
if (isNodeShouldBeSkipped(path.node)) {
if (shouldSkipNode(path.node)) {
return;
}
const statements = path.get('body');
Expand Down Expand Up @@ -1152,7 +1152,7 @@ export default class Optimizer {
path: babel.NodePath<t.Statement>,
topBlock = false,
): void {
if (isNodeShouldBeSkipped(path.node)) {
if (shouldSkipNode(path.node)) {
return;
}
switch (path.type) {
Expand Down
6 changes: 3 additions & 3 deletions packages/forgetti/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
isComponentValid,
getImportSpecifierName,
isHookOrComponentName,
isNodeShouldBeSkipped,
shouldSkipNode,
} from './core/checks';
import Optimizer from './core/optimizer';
import type {
Expand Down Expand Up @@ -228,10 +228,10 @@ function transformVariableDeclarator(
path.node.init
&& path.node.id.type === 'Identifier'
&& isHookOrComponentName(ctx, path.node.id)
&& !isNodeShouldBeSkipped(path.node)
&& !shouldSkipNode(path.node)
&& (
path.parent.type === 'VariableDeclaration'
? !isNodeShouldBeSkipped(path.parent)
? !shouldSkipNode(path.parent)
: true
)
) {
Expand Down

0 comments on commit 95681d1

Please sign in to comment.