Socket
Socket
Sign inDemoInstall

hast-util-to-estree

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hast-util-to-estree - npm Package Compare versions

Comparing version 2.3.0 to 2.3.1

18

index.d.ts

@@ -1,10 +0,8 @@

export {handlers as defaultHandlers} from './lib/handlers/index.js'
export {toEstree} from './lib/index.js'
export type ElementAttributeNameCase =
import('./lib/state.js').ElementAttributeNameCase
export type Handle = import('./lib/state.js').Handle
export type Options = import('./lib/state.js').Options
export type Space = import('./lib/state.js').Space
export type State = import('./lib/state.js').State
export type StylePropertyNameCase =
import('./lib/state.js').StylePropertyNameCase
export { handlers as defaultHandlers } from "./lib/handlers/index.js";
export { toEstree } from "./lib/index.js";
export type ElementAttributeNameCase = import('./lib/state.js').ElementAttributeNameCase;
export type Handle = import('./lib/state.js').Handle;
export type Options = import('./lib/state.js').Options;
export type Space = import('./lib/state.js').Space;
export type State = import('./lib/state.js').State;
export type StylePropertyNameCase = import('./lib/state.js').StylePropertyNameCase;

@@ -17,9 +17,6 @@ /**

*/
export function comment(
node: import('hast').Comment,
state: State
): JsxExpressionContainer
export type Comment = import('estree').Comment
export type JsxExpressionContainer = import('estree-jsx').JSXExpressionContainer
export type JsxEmptyExpression = import('estree-jsx').JSXEmptyExpression
export type State = import('../state.js').State
export function comment(node: import('hast').Comment, state: State): JsxExpressionContainer;
export type Comment = import('estree').Comment;
export type JsxExpressionContainer = import('estree-jsx').JSXExpressionContainer;
export type JsxEmptyExpression = import('estree-jsx').JSXEmptyExpression;
export type State = import('../state.js').State;

@@ -11,9 +11,9 @@ /**

*/
export function element(node: Element, state: State): JsxElement
export type Element = import('hast').Element
export type Property = import('estree').Property
export type JsxElement = import('estree-jsx').JSXElement
export type JsxSpreadAttribute = import('estree-jsx').JSXSpreadAttribute
export type JsxAttribute = import('estree-jsx').JSXAttribute
export type State = import('../state.js').State
export type Style = Record<string, string>
export function element(node: Element, state: State): JsxElement;
export type Element = import('hast').Element;
export type Property = import('estree').Property;
export type JsxElement = import('estree-jsx').JSXElement;
export type JsxSpreadAttribute = import('estree-jsx').JSXSpreadAttribute;
export type JsxAttribute = import('estree-jsx').JSXAttribute;
export type State = import('../state.js').State;
export type Style = Record<string, string>;
export namespace handlers {
export {comment}
export {ignore as doctype}
export {element}
export {mdxExpression as mdxFlowExpression}
export {mdxExpression as mdxTextExpression}
export {mdxJsxElement as mdxJsxFlowElement}
export {mdxJsxElement as mdxJsxTextElement}
export {mdxjsEsm}
export {text}
export {root}
export { comment };
export { ignore as doctype };
export { element };
export { mdxExpression as mdxFlowExpression };
export { mdxExpression as mdxTextExpression };
export { mdxJsxElement as mdxJsxFlowElement };
export { mdxJsxElement as mdxJsxTextElement };
export { mdxjsEsm };
export { text };
export { root };
}
import {comment} from './comment.js'
import { comment } from "./comment.js";
/**

@@ -20,9 +20,9 @@ * Handle a node that is ignored.

*/
declare function ignore(): void
import {element} from './element.js'
import {mdxExpression} from './mdx-expression.js'
import {mdxJsxElement} from './mdx-jsx-element.js'
import {mdxjsEsm} from './mdxjs-esm.js'
import {text} from './text.js'
import {root} from './root.js'
export {}
declare function ignore(): void;
import { element } from "./element.js";
import { mdxExpression } from "./mdx-expression.js";
import { mdxJsxElement } from "./mdx-jsx-element.js";
import { mdxjsEsm } from "./mdxjs-esm.js";
import { text } from "./text.js";
import { root } from "./root.js";
export {};

@@ -11,13 +11,8 @@ /**

*/
export function mdxExpression(
node: MdxFlowExpression | MdxTextExpression,
state: State
): JsxExpressionContainer
export type MdxFlowExpression =
import('mdast-util-mdx-expression').MdxFlowExpression
export type MdxTextExpression =
import('mdast-util-mdx-expression').MdxTextExpression
export type Expression = import('estree').Expression
export type JsxEmptyExpression = import('estree-jsx').JSXEmptyExpression
export type JsxExpressionContainer = import('estree-jsx').JSXExpressionContainer
export type State = import('../state.js').State
export function mdxExpression(node: MdxFlowExpression | MdxTextExpression, state: State): JsxExpressionContainer;
export type MdxFlowExpression = import('mdast-util-mdx-expression').MdxFlowExpression;
export type MdxTextExpression = import('mdast-util-mdx-expression').MdxTextExpression;
export type Expression = import('estree').Expression;
export type JsxEmptyExpression = import('estree-jsx').JSXEmptyExpression;
export type JsxExpressionContainer = import('estree-jsx').JSXExpressionContainer;
export type State = import('../state.js').State;

@@ -11,13 +11,10 @@ /**

*/
export function mdxJsxElement(
node: MdxJsxFlowElement | MdxJsxTextElement,
state: State
): JsxElement | JsxFragment
export type MdxJsxFlowElement = import('mdast-util-mdx-jsx').MdxJsxFlowElement
export type MdxJsxTextElement = import('mdast-util-mdx-jsx').MdxJsxTextElement
export type Expression = import('estree').Expression
export type JsxElement = import('estree-jsx').JSXElement
export type JsxFragment = import('estree-jsx').JSXFragment
export type JsxAttribute = import('estree-jsx').JSXAttribute
export type JsxSpreadAttribute = import('estree-jsx').JSXSpreadAttribute
export type State = import('../state.js').State
export function mdxJsxElement(node: MdxJsxFlowElement | MdxJsxTextElement, state: State): JsxElement | JsxFragment;
export type MdxJsxFlowElement = import('mdast-util-mdx-jsx').MdxJsxFlowElement;
export type MdxJsxTextElement = import('mdast-util-mdx-jsx').MdxJsxTextElement;
export type Expression = import('estree').Expression;
export type JsxElement = import('estree-jsx').JSXElement;
export type JsxFragment = import('estree-jsx').JSXFragment;
export type JsxAttribute = import('estree-jsx').JSXAttribute;
export type JsxSpreadAttribute = import('estree-jsx').JSXSpreadAttribute;
export type State = import('../state.js').State;

@@ -11,4 +11,4 @@ /**

*/
export function mdxjsEsm(node: MdxjsEsm, state: State): void
export type MdxjsEsm = import('mdast-util-mdxjs-esm').MdxjsEsm
export type State = import('../state.js').State
export function mdxjsEsm(node: MdxjsEsm, state: State): void;
export type MdxjsEsm = import('mdast-util-mdxjs-esm').MdxjsEsm;
export type State = import('../state.js').State;

@@ -11,6 +11,6 @@ /**

*/
export function root(node: Root, state: State): JsxFragment
export type Root = import('hast').Root
export type JsxFragment = import('estree-jsx').JSXFragment
export type JsxChild = JsxFragment['children'][number]
export type State = import('../state.js').State
export function root(node: Root, state: State): JsxFragment;
export type Root = import('hast').Root;
export type JsxFragment = import('estree-jsx').JSXFragment;
export type JsxChild = JsxFragment['children'][number];
export type State = import('../state.js').State;

@@ -17,6 +17,6 @@ /**

*/
export function text(node: Text, state: State): JsxExpressionContainer | void
export type Text = import('hast').Text
export type Literal = import('estree').Literal
export type JsxExpressionContainer = import('estree-jsx').JSXExpressionContainer
export type State = import('../state.js').State
export function text(node: Text, state: State): JsxExpressionContainer | void;
export type Text = import('hast').Text;
export type Literal = import('estree').Literal;
export type JsxExpressionContainer = import('estree-jsx').JSXExpressionContainer;
export type State = import('../state.js').State;

@@ -51,31 +51,15 @@ /**

*/
export function toEstree(
tree: Node,
options?: Options | null | undefined
): Program
export type Content = import('hast').Content
export type Root = import('hast').Root
export type ExpressionStatement = import('estree').ExpressionStatement
export type Program = import('estree').Program
export type MdxJsxAttribute = import('mdast-util-mdx-jsx').MdxJsxAttribute
export type MdxJsxAttributeValueExpression =
import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression
export type MdxJsxExpressionAttribute =
import('mdast-util-mdx-jsx').MdxJsxExpressionAttribute
export type MdxJsxFlowElement = import('mdast-util-mdx-jsx').MdxJsxFlowElement
export type MdxJsxTextElement = import('mdast-util-mdx-jsx').MdxJsxTextElement
export type MdxFlowExpression =
import('mdast-util-mdx-expression').MdxFlowExpression
export type MdxTextExpression =
import('mdast-util-mdx-expression').MdxTextExpression
export type Options = import('./state.js').Options
export type Node =
| Root
| Content
| MdxJsxAttributeValueExpression
| MdxJsxAttribute
| MdxJsxExpressionAttribute
| MdxJsxFlowElement
| MdxJsxTextElement
| MdxFlowExpression
| MdxTextExpression
export function toEstree(tree: Node, options?: Options | null | undefined): Program;
export type Content = import('hast').Content;
export type Root = import('hast').Root;
export type ExpressionStatement = import('estree').ExpressionStatement;
export type Program = import('estree').Program;
export type MdxJsxAttribute = import('mdast-util-mdx-jsx').MdxJsxAttribute;
export type MdxJsxAttributeValueExpression = import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression;
export type MdxJsxExpressionAttribute = import('mdast-util-mdx-jsx').MdxJsxExpressionAttribute;
export type MdxJsxFlowElement = import('mdast-util-mdx-jsx').MdxJsxFlowElement;
export type MdxJsxTextElement = import('mdast-util-mdx-jsx').MdxJsxTextElement;
export type MdxFlowExpression = import('mdast-util-mdx-expression').MdxFlowExpression;
export type MdxTextExpression = import('mdast-util-mdx-expression').MdxTextExpression;
export type Options = import('./state.js').Options;
export type Node = Root | Content | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression;

@@ -9,53 +9,37 @@ /**

*/
export function createState(options: Options): State
export type UnistParent = import('unist').Parent
export type Content = import('hast').Content
export type Root = import('hast').Root
export type Comment = import('estree').Comment
export type Directive = import('estree').Directive
export type ModuleDeclaration = import('estree').ModuleDeclaration
export type EstreeNode = import('estree').Node
export type Statement = import('estree').Statement
export type JsxAttribute = import('estree-jsx').JSXAttribute
export type JsxElement = import('estree-jsx').JSXElement
export type JsxIdentifier = import('estree-jsx').JSXIdentifier
export type JsxMemberExpression = import('estree-jsx').JSXMemberExpression
export type JsxNamespacedName = import('estree-jsx').JSXNamespacedName
export type MdxJsxAttribute = import('mdast-util-mdx-jsx').MdxJsxAttribute
export type MdxJsxAttributeValueExpression =
import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression
export type MdxJsxExpressionAttribute =
import('mdast-util-mdx-jsx').MdxJsxExpressionAttribute
export type MdxJsxFlowElement = import('mdast-util-mdx-jsx').MdxJsxFlowElement
export type MdxJsxTextElement = import('mdast-util-mdx-jsx').MdxJsxTextElement
export type MdxFlowExpression =
import('mdast-util-mdx-expression').MdxFlowExpression
export type MdxTextExpression =
import('mdast-util-mdx-expression').MdxTextExpression
export type Schema = import('property-information').Schema
export type Node =
| Root
| Content
| MdxJsxAttributeValueExpression
| MdxJsxAttribute
| MdxJsxExpressionAttribute
| MdxJsxFlowElement
| MdxJsxTextElement
| MdxFlowExpression
| MdxTextExpression
export type Parent = Extract<Node, UnistParent>
export type JsxElementName = JsxElement['openingElement']['name']
export type JsxAttributeName = JsxAttribute['name']
export type JsxChild = JsxElement['children'][number]
export function createState(options: Options): State;
export type UnistParent = import('unist').Parent;
export type Content = import('hast').Content;
export type Root = import('hast').Root;
export type Comment = import('estree').Comment;
export type Directive = import('estree').Directive;
export type ModuleDeclaration = import('estree').ModuleDeclaration;
export type EstreeNode = import('estree').Node;
export type Statement = import('estree').Statement;
export type JsxAttribute = import('estree-jsx').JSXAttribute;
export type JsxElement = import('estree-jsx').JSXElement;
export type JsxIdentifier = import('estree-jsx').JSXIdentifier;
export type JsxMemberExpression = import('estree-jsx').JSXMemberExpression;
export type JsxNamespacedName = import('estree-jsx').JSXNamespacedName;
export type MdxJsxAttribute = import('mdast-util-mdx-jsx').MdxJsxAttribute;
export type MdxJsxAttributeValueExpression = import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression;
export type MdxJsxExpressionAttribute = import('mdast-util-mdx-jsx').MdxJsxExpressionAttribute;
export type MdxJsxFlowElement = import('mdast-util-mdx-jsx').MdxJsxFlowElement;
export type MdxJsxTextElement = import('mdast-util-mdx-jsx').MdxJsxTextElement;
export type MdxFlowExpression = import('mdast-util-mdx-expression').MdxFlowExpression;
export type MdxTextExpression = import('mdast-util-mdx-expression').MdxTextExpression;
export type Schema = import('property-information').Schema;
export type Node = Root | Content | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression;
export type Parent = Extract<Node, UnistParent>;
export type JsxElementName = JsxElement['openingElement']['name'];
export type JsxAttributeName = JsxAttribute['name'];
export type JsxChild = JsxElement['children'][number];
/**
* Namespace.
*/
export type Space = 'html' | 'svg'
export type Space = 'html' | 'svg';
/**
* Turn a hast node into an estree node.
*/
export type Handle = (
node: any,
state: State
) => JsxChild | null | undefined | void
export type Handle = (node: any, state: State) => JsxChild | null | undefined | void;
/**

@@ -67,3 +51,3 @@ * Specify casing to use for attribute names.

*/
export type ElementAttributeNameCase = 'html' | 'react'
export type ElementAttributeNameCase = 'html' | 'react';
/**

@@ -75,3 +59,3 @@ * Casing to use for property names in `style` objects.

*/
export type StylePropertyNameCase = 'css' | 'dom'
export type StylePropertyNameCase = 'css' | 'dom';
/**

@@ -81,29 +65,29 @@ * Configuration.

export type Options = {
/**
* Specify casing to use for attribute names.
*
* This casing is used for hast elements, not for embedded MDX JSX nodes
* (components that someone authored manually).
*/
elementAttributeNameCase?: ElementAttributeNameCase | null | undefined
/**
* Custom handlers.
*/
handlers?: Record<string, Handle | null | undefined> | null | undefined
/**
* Which space the document is in.
*
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
*/
space?: Space | null | undefined
/**
* Specify casing to use for property names in `style` objects.
*
* This casing is used for hast elements, not for embedded MDX JSX nodes
* (components that someone authored manually).
*/
stylePropertyNameCase?: StylePropertyNameCase | null | undefined
}
/**
* Specify casing to use for attribute names.
*
* This casing is used for hast elements, not for embedded MDX JSX nodes
* (components that someone authored manually).
*/
elementAttributeNameCase?: ElementAttributeNameCase | null | undefined;
/**
* Custom handlers.
*/
handlers?: Record<string, Handle | null | undefined> | null | undefined;
/**
* Which space the document is in.
*
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
*/
space?: Space | null | undefined;
/**
* Specify casing to use for property names in `style` objects.
*
* This casing is used for hast elements, not for embedded MDX JSX nodes
* (components that someone authored manually).
*/
stylePropertyNameCase?: StylePropertyNameCase | null | undefined;
};
/**

@@ -113,46 +97,46 @@ * Info passed around about the current state.

export type State = {
/**
* Current schema.
*/
schema: Schema
/**
* Casing to use for attribute names.
*/
elementAttributeNameCase: ElementAttributeNameCase
/**
* Casing to use for property names in `style` objects.
*/
stylePropertyNameCase: StylePropertyNameCase
/**
* List of estree comments.
*/
comments: Array<Comment>
/**
* List of top-level estree nodes.
*/
esm: Array<Directive | Statement | ModuleDeclaration>
/**
* Transform a hast node to estree.
*/
handle: (node: any) => JsxChild | null | undefined | void
/**
* Transform children of a hast parent to estree.
*/
all: (parent: Parent) => Array<JsxChild>
/**
* Take positional info from `from` (use `inherit` if you also want data).
*/
patch: (from: Node, to: EstreeNode | Comment) => void
/**
* Take positional info and data from `from` (use `patch` if you don’t want data).
*/
inherit: (from: Node, to: EstreeNode | Comment) => void
/**
* Create a JSX attribute name.
*/
createJsxAttributeName: (name: string) => JsxAttributeName
/**
* Create a JSX element name.
*/
createJsxElementName: (name: string) => JsxElementName
}
/**
* Current schema.
*/
schema: Schema;
/**
* Casing to use for attribute names.
*/
elementAttributeNameCase: ElementAttributeNameCase;
/**
* Casing to use for property names in `style` objects.
*/
stylePropertyNameCase: StylePropertyNameCase;
/**
* List of estree comments.
*/
comments: Array<Comment>;
/**
* List of top-level estree nodes.
*/
esm: Array<Directive | Statement | ModuleDeclaration>;
/**
* Transform a hast node to estree.
*/
handle: (node: any) => JsxChild | null | undefined | void;
/**
* Transform children of a hast parent to estree.
*/
all: (parent: Parent) => Array<JsxChild>;
/**
* Take positional info from `from` (use `inherit` if you also want data).
*/
patch: (from: Node, to: EstreeNode | Comment) => void;
/**
* Take positional info and data from `from` (use `patch` if you don’t want data).
*/
inherit: (from: Node, to: EstreeNode | Comment) => void;
/**
* Create a JSX attribute name.
*/
createJsxAttributeName: (name: string) => JsxAttributeName;
/**
* Create a JSX element name.
*/
createJsxElementName: (name: string) => JsxElementName;
};
/**
* @typedef {import('unist').Parent} UnistParent
*
* @typedef {import('hast').Content} Content
* @typedef {import('hast').Root} Root
*
* @typedef {import('estree').Comment} Comment

@@ -19,2 +14,8 @@ * @typedef {import('estree').Directive} Directive

*
* @typedef {import('hast').Content} Content
* @typedef {import('hast').Root} Root
*
* @typedef {import('mdast-util-mdx-expression').MdxFlowExpression} MdxFlowExpression
* @typedef {import('mdast-util-mdx-expression').MdxTextExpression} MdxTextExpression
*
* @typedef {import('mdast-util-mdx-jsx').MdxJsxAttribute} MdxJsxAttribute

@@ -26,10 +27,9 @@ * @typedef {import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression

*
* @typedef {import('mdast-util-mdx-expression').MdxFlowExpression} MdxFlowExpression
* @typedef {import('mdast-util-mdx-expression').MdxTextExpression} MdxTextExpression
* @typedef {import('property-information').Schema} Schema
*
* @typedef {import('property-information').Schema} Schema
* @typedef {import('unist').Parent} UnistParent
*/
/**
* @typedef {Root | Content | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression} Node
* @typedef {Content | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression | Root} Node
* @typedef {Extract<Node, UnistParent>} Parent

@@ -118,11 +118,15 @@ * @typedef {JsxElement['openingElement']['name']} JsxElementName

const tableElements = new Set([
'table',
'thead',
'tbody',
'tfoot',
'tr',
'th',
'td'
])
// `react-dom` triggers a warning for *any* white space in tables.
// To follow GFM, `mdast-util-to-hast` injects line endings between elements.
// Other tools might do so too, but they don’t do here, so we remove all of
// that.
//
// See: <https://github.com/facebook/react/pull/7081>.
// See: <https://github.com/facebook/react/pull/7515>.
// See: <https://github.com/remarkjs/remark-react/issues/64>.
// See: <https://github.com/rehypejs/rehype-react/pull/29>.
// See: <https://github.com/rehypejs/rehype-react/pull/32>.
// See: <https://github.com/rehypejs/rehype-react/pull/45>.
// See: <https://github.com/mdx-js/mdx/issues/2000>
const tableElements = new Set(['table', 'thead', 'tbody', 'tfoot', 'tr'])

@@ -211,8 +215,2 @@ /**

const results = []
// Currently, a warning is triggered by react for *any* white space in
// tables.
// So we remove the pretty lines for now.
// See: <https://github.com/facebook/react/pull/7081>.
// See: <https://github.com/facebook/react/pull/7515>.
// See: <https://github.com/remarkjs/remark-react/issues/64>.
const ignoreLineBreak =

@@ -256,3 +254,2 @@ this.schema.space === 'html' &&

/** @type {Record<string, unknown> | undefined} */
// @ts-expect-error: custom data.
const left = from.data

@@ -259,0 +256,0 @@ /** @type {Record<string, unknown> | undefined} */

{
"name": "hast-util-to-estree",
"version": "2.3.0",
"version": "2.3.1",
"description": "hast utility to transform to estree (JavaScript AST) JSX",

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc