Corrige le linting
parent
16743800df
commit
87de1210ee
|
@ -133,7 +133,7 @@ export const MarkdownWithAnchorLinks = ({
|
|||
)
|
||||
|
||||
const flatMapChildren = (children: React.ReactNode): Array<string> => {
|
||||
return React.Children.toArray(children).flatMap(child =>
|
||||
return React.Children.toArray(children).flatMap((child) =>
|
||||
typeof child !== 'object' || !('props' in child)
|
||||
? child
|
||||
: child.props?.value ?? flatMapChildren(child.props?.children)
|
||||
|
|
|
@ -5,7 +5,6 @@ import { ReplacementNode } from '../replacement'
|
|||
import { RuleNode } from '../rule'
|
||||
import { ASTNode, NodeKind, TraverseFunction } from './types'
|
||||
|
||||
|
||||
type TransformASTFunction = (n: ASTNode) => ASTNode
|
||||
/**
|
||||
This function creates a transormation of the AST from on a simpler
|
||||
|
@ -22,26 +21,26 @@ type TransformASTFunction = (n: ASTNode) => ASTNode
|
|||
by using the function passed as second argument. The returned value will be the
|
||||
transformed version of the node.
|
||||
*/
|
||||
export function updateAST(
|
||||
fn: (
|
||||
node: ASTNode,
|
||||
updateFn: TransformASTFunction
|
||||
) => ASTNode | undefined | false
|
||||
): TransformASTFunction {
|
||||
function traverseFn(node: ASTNode) {
|
||||
const updatedNode = fn(node, traverseFn)
|
||||
if (updatedNode === false) {
|
||||
return node
|
||||
}
|
||||
if (updatedNode === undefined) {
|
||||
return traverseASTNode(traverseFn, node)
|
||||
}
|
||||
return updatedNode
|
||||
export function updateAST(
|
||||
fn: (
|
||||
node: ASTNode,
|
||||
updateFn: TransformASTFunction
|
||||
) => ASTNode | undefined | false
|
||||
): TransformASTFunction {
|
||||
function traverseFn(node: ASTNode) {
|
||||
const updatedNode = fn(node, traverseFn)
|
||||
if (updatedNode === false) {
|
||||
return node
|
||||
}
|
||||
return traverseFn
|
||||
if (updatedNode === undefined) {
|
||||
return traverseASTNode(traverseFn, node)
|
||||
}
|
||||
return updatedNode
|
||||
}
|
||||
|
||||
/**
|
||||
return traverseFn
|
||||
}
|
||||
|
||||
/**
|
||||
This function allows to construct a specific value while exploring the AST with
|
||||
a simple reducing function as argument.
|
||||
|
||||
|
@ -57,22 +56,21 @@ type TransformASTFunction = (n: ASTNode) => ASTNode
|
|||
by using the function passed as second argument. The returned value will be the reduced version
|
||||
of the node
|
||||
*/
|
||||
|
||||
export function reduceAST<T>(
|
||||
fn: (acc: T, n: ASTNode, reduceFn: (n: ASTNode) => T) => T | undefined,
|
||||
start: T,
|
||||
node: ASTNode
|
||||
): T {
|
||||
function traverseFn(acc: T, node: ASTNode): T {
|
||||
const result = fn(acc, node, traverseFn.bind(null, start))
|
||||
if (result === undefined) {
|
||||
return gatherNodes(node).reduce(traverseFn, acc)
|
||||
}
|
||||
return result
|
||||
}
|
||||
return traverseFn(start, node)
|
||||
}
|
||||
|
||||
export function reduceAST<T>(
|
||||
fn: (acc: T, n: ASTNode, reduceFn: (n: ASTNode) => T) => T | undefined,
|
||||
start: T,
|
||||
node: ASTNode
|
||||
): T {
|
||||
function traverseFn(acc: T, node: ASTNode): T {
|
||||
const result = fn(acc, node, traverseFn.bind(null, start))
|
||||
if (result === undefined) {
|
||||
return gatherNodes(node).reduce(traverseFn, acc)
|
||||
}
|
||||
return result
|
||||
}
|
||||
return traverseFn(start, node)
|
||||
}
|
||||
|
||||
function gatherNodes(node: ASTNode): ASTNode[] {
|
||||
const nodes: ASTNode[] = []
|
||||
|
|
|
@ -8,7 +8,7 @@ import parsePublicodes, { disambiguateReference } from './parsePublicodes'
|
|||
import {
|
||||
getReplacements,
|
||||
inlineReplacements,
|
||||
ReplacementNode
|
||||
ReplacementNode,
|
||||
} from './replacement'
|
||||
import { Rule, RuleNode } from './rule'
|
||||
import * as utils from './ruleUtils'
|
||||
|
|
Loading…
Reference in New Issue