This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

3
node_modules/estree-util-build-jsx/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export { buildJsx } from "./lib/index.js";
export type Options = import('./lib/index.js').Options;
export type Runtime = import('./lib/index.js').Runtime;

6
node_modules/estree-util-build-jsx/index.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
/**
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('./lib/index.js').Runtime} Runtime
*/
export {buildJsx} from './lib/index.js'

148
node_modules/estree-util-build-jsx/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,148 @@
/**
* Turn JSX in `tree` into function calls: `<x />` -> `h('x')`!
*
* ###### Algorithm
*
* In almost all cases, this utility is the same as the Babel plugin, except that
* they work on slightly different syntax trees.
*
* Some differences:
*
* * no pure annotations things
* * `this` is not a component: `<this>` -> `h('this')`, not `h(this)`
* * namespaces are supported: `<a:b c:d>` -> `h('a:b', {'c:d': true})`,
* which throws by default in Babel or can be turned on with `throwIfNamespace`
* * no `useSpread`, `useBuiltIns`, or `filter` options
*
* @param {Node} tree
* Tree to transform (typically `Program`).
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {undefined}
* Nothing.
*/
export function buildJsx(tree: Node, options?: Options | null | undefined): undefined;
export type Expression = import('estree-jsx').Expression;
export type Identifier = import('estree-jsx').Identifier;
export type ImportSpecifier = import('estree-jsx').ImportSpecifier;
export type JSXAttribute = import('estree-jsx').JSXAttribute;
export type JSXIdentifier = import('estree-jsx').JSXIdentifier;
export type JSXMemberExpression = import('estree-jsx').JSXMemberExpression;
export type JSXNamespacedName = import('estree-jsx').JSXNamespacedName;
export type Literal = import('estree-jsx').Literal;
export type MemberExpression = import('estree-jsx').MemberExpression;
export type Node = import('estree-jsx').Node;
export type ObjectExpression = import('estree-jsx').ObjectExpression;
export type Property = import('estree-jsx').Property;
export type SpreadElement = import('estree-jsx').SpreadElement;
/**
* How to transform JSX.
*/
export type Runtime = 'automatic' | 'classic';
/**
* Configuration.
*
* > 👉 **Note**: you can also configure `runtime`, `importSource`, `pragma`,
* > and `pragmaFrag` from within files through comments.
*/
export type Options = {
/**
* Choose the runtime (default: `'classic'`).
*
* Comment form: `@jsxRuntime theRuntime`.
*/
runtime?: Runtime | null | undefined;
/**
* Place to import `jsx`, `jsxs`, `jsxDEV`, and `Fragment` from, when the
* effective runtime is automatic (default: `'react'`).
*
* Comment form: `@jsxImportSource theSource`.
*
* > 👉 **Note**: `/jsx-runtime` or `/jsx-dev-runtime` is appended to this
* > provided source.
* > In CJS, that can resolve to a file (as in `theSource/jsx-runtime.js`),
* > but for ESM an export map needs to be set up to point to files:
* >
* > ```js
* > // …
* > "exports": {
* > // …
* > "./jsx-runtime": "./path/to/jsx-runtime.js",
* > "./jsx-dev-runtime": "./path/to/jsx-runtime.js"
* > // …
* > ```
*/
importSource?: string | null | undefined;
/**
* Identifier or member expression to call when the effective runtime is
* classic (default: `'React.createElement'`).
*
* Comment form: `@jsx identifier`.
*/
pragma?: string | null | undefined;
/**
* Identifier or member expression to use as a symbol for fragments when the
* effective runtime is classic (default: `'React.Fragment'`).
*
* Comment form: `@jsxFrag identifier`.
*/
pragmaFrag?: string | null | undefined;
/**
* When in the automatic runtime, whether to import
* `theSource/jsx-dev-runtime.js`, use `jsxDEV`, and pass location info when
* available (default: `false`).
*
* This helps debugging but adds a lot of code that you dont want in
* production.
*/
development?: boolean | null | undefined;
/**
* File path to the original source file (optional).
*
* Passed in location info to `jsxDEV` when using the automatic runtime with
* `development: true`.
*/
filePath?: string | null | undefined;
};
/**
* State where info from comments is gathered.
*/
export type Annotations = {
/**
* JSX identifier (`pragma`).
*/
jsx?: string | undefined;
/**
* JSX identifier of fragment (`pragmaFrag`).
*/
jsxFrag?: string | undefined;
/**
* Where to import an automatic JSX runtime from.
*/
jsxImportSource?: string | undefined;
/**
* Runtime.
*/
jsxRuntime?: Runtime | undefined;
};
/**
* State of used identifiers from the automatic runtime.
*/
export type Imports = {
/**
* Symbol of `Fragment`.
*/
fragment?: boolean | undefined;
/**
* Symbol of `jsx`.
*/
jsx?: boolean | undefined;
/**
* Symbol of `jsxs`.
*/
jsxs?: boolean | undefined;
/**
* Symbol of `jsxDEV`.
*/
jsxDEV?: boolean | undefined;
};

640
node_modules/estree-util-build-jsx/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,640 @@
/**
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').ImportSpecifier} ImportSpecifier
* @typedef {import('estree-jsx').JSXAttribute} JSXAttribute
* @typedef {import('estree-jsx').JSXIdentifier} JSXIdentifier
* @typedef {import('estree-jsx').JSXMemberExpression} JSXMemberExpression
* @typedef {import('estree-jsx').JSXNamespacedName} JSXNamespacedName
* @typedef {import('estree-jsx').Literal} Literal
* @typedef {import('estree-jsx').MemberExpression} MemberExpression
* @typedef {import('estree-jsx').Node} Node
* @typedef {import('estree-jsx').ObjectExpression} ObjectExpression
* @typedef {import('estree-jsx').Property} Property
* @typedef {import('estree-jsx').SpreadElement} SpreadElement
*
* @typedef {'automatic' | 'classic'} Runtime
* How to transform JSX.
*
* @typedef Options
* Configuration.
*
* > 👉 **Note**: you can also configure `runtime`, `importSource`, `pragma`,
* > and `pragmaFrag` from within files through comments.
* @property {Runtime | null | undefined} [runtime='classic']
* Choose the runtime (default: `'classic'`).
*
* Comment form: `@jsxRuntime theRuntime`.
* @property {string | null | undefined} [importSource='react']
* Place to import `jsx`, `jsxs`, `jsxDEV`, and `Fragment` from, when the
* effective runtime is automatic (default: `'react'`).
*
* Comment form: `@jsxImportSource theSource`.
*
* > 👉 **Note**: `/jsx-runtime` or `/jsx-dev-runtime` is appended to this
* > provided source.
* > In CJS, that can resolve to a file (as in `theSource/jsx-runtime.js`),
* > but for ESM an export map needs to be set up to point to files:
* >
* > ```js
* > // …
* > "exports": {
* > // …
* > "./jsx-runtime": "./path/to/jsx-runtime.js",
* > "./jsx-dev-runtime": "./path/to/jsx-runtime.js"
* > // …
* > ```
* @property {string | null | undefined} [pragma='React.createElement']
* Identifier or member expression to call when the effective runtime is
* classic (default: `'React.createElement'`).
*
* Comment form: `@jsx identifier`.
* @property {string | null | undefined} [pragmaFrag='React.Fragment']
* Identifier or member expression to use as a symbol for fragments when the
* effective runtime is classic (default: `'React.Fragment'`).
*
* Comment form: `@jsxFrag identifier`.
* @property {boolean | null | undefined} [development=false]
* When in the automatic runtime, whether to import
* `theSource/jsx-dev-runtime.js`, use `jsxDEV`, and pass location info when
* available (default: `false`).
*
* This helps debugging but adds a lot of code that you dont want in
* production.
* @property {string | null | undefined} [filePath]
* File path to the original source file (optional).
*
* Passed in location info to `jsxDEV` when using the automatic runtime with
* `development: true`.
*
* @typedef Annotations
* State where info from comments is gathered.
* @property {string | undefined} [jsx]
* JSX identifier (`pragma`).
* @property {string | undefined} [jsxFrag]
* JSX identifier of fragment (`pragmaFrag`).
* @property {string | undefined} [jsxImportSource]
* Where to import an automatic JSX runtime from.
* @property {Runtime | undefined} [jsxRuntime]
* Runtime.
*
* @typedef Imports
* State of used identifiers from the automatic runtime.
* @property {boolean | undefined} [fragment]
* Symbol of `Fragment`.
* @property {boolean | undefined} [jsx]
* Symbol of `jsx`.
* @property {boolean | undefined} [jsxs]
* Symbol of `jsxs`.
* @property {boolean | undefined} [jsxDEV]
* Symbol of `jsxDEV`.
*/
import {ok as assert} from 'devlop'
import {name as isIdentifierName} from 'estree-util-is-identifier-name'
import {walk} from 'estree-walker'
const regex = /@(jsx|jsxFrag|jsxImportSource|jsxRuntime)\s+(\S+)/g
/**
* Turn JSX in `tree` into function calls: `<x />` -> `h('x')`!
*
* ###### Algorithm
*
* In almost all cases, this utility is the same as the Babel plugin, except that
* they work on slightly different syntax trees.
*
* Some differences:
*
* * no pure annotations things
* * `this` is not a component: `<this>` -> `h('this')`, not `h(this)`
* * namespaces are supported: `<a:b c:d>` -> `h('a:b', {'c:d': true})`,
* which throws by default in Babel or can be turned on with `throwIfNamespace`
* * no `useSpread`, `useBuiltIns`, or `filter` options
*
* @param {Node} tree
* Tree to transform (typically `Program`).
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {undefined}
* Nothing.
*/
export function buildJsx(tree, options) {
const config = options || {}
let automatic = config.runtime === 'automatic'
/** @type {Annotations} */
const annotations = {}
/** @type {Imports} */
const imports = {}
walk(tree, {
enter(node) {
if (node.type === 'Program') {
const comments = node.comments || []
let index = -1
while (++index < comments.length) {
regex.lastIndex = 0
let match = regex.exec(comments[index].value)
while (match) {
// @ts-expect-error: `match[1]` is always a key, `match[2]` when
// runtime is checked later.
annotations[match[1]] = match[2]
match = regex.exec(comments[index].value)
}
}
if (annotations.jsxRuntime) {
if (annotations.jsxRuntime === 'automatic') {
automatic = true
if (annotations.jsx) {
throw new Error('Unexpected `@jsx` pragma w/ automatic runtime')
}
if (annotations.jsxFrag) {
throw new Error(
'Unexpected `@jsxFrag` pragma w/ automatic runtime'
)
}
} else if (annotations.jsxRuntime === 'classic') {
automatic = false
if (annotations.jsxImportSource) {
throw new Error(
'Unexpected `@jsxImportSource` w/ classic runtime'
)
}
} else {
throw new Error(
'Unexpected `jsxRuntime` `' +
annotations.jsxRuntime +
'`, expected `automatic` or `classic`'
)
}
}
}
},
// eslint-disable-next-line complexity
leave(node) {
if (node.type === 'Program') {
/** @type {Array<ImportSpecifier>} */
const specifiers = []
if (imports.fragment) {
specifiers.push({
type: 'ImportSpecifier',
imported: {type: 'Identifier', name: 'Fragment'},
local: {type: 'Identifier', name: '_Fragment'}
})
}
if (imports.jsx) {
specifiers.push({
type: 'ImportSpecifier',
imported: {type: 'Identifier', name: 'jsx'},
local: {type: 'Identifier', name: '_jsx'}
})
}
if (imports.jsxs) {
specifiers.push({
type: 'ImportSpecifier',
imported: {type: 'Identifier', name: 'jsxs'},
local: {type: 'Identifier', name: '_jsxs'}
})
}
if (imports.jsxDEV) {
specifiers.push({
type: 'ImportSpecifier',
imported: {type: 'Identifier', name: 'jsxDEV'},
local: {type: 'Identifier', name: '_jsxDEV'}
})
}
if (specifiers.length > 0) {
let injectIndex = 0
while (injectIndex < node.body.length) {
const child = node.body[injectIndex]
if ('directive' in child && child.directive) {
injectIndex++
} else {
break
}
}
node.body.splice(injectIndex, 0, {
type: 'ImportDeclaration',
specifiers,
source: {
type: 'Literal',
value:
(annotations.jsxImportSource ||
config.importSource ||
'react') +
(config.development ? '/jsx-dev-runtime' : '/jsx-runtime')
}
})
}
}
if (node.type !== 'JSXElement' && node.type !== 'JSXFragment') {
return
}
/** @type {Array<Expression>} */
const children = []
let index = -1
// Figure out `children`.
while (++index < node.children.length) {
const child = node.children[index]
if (child.type === 'JSXExpressionContainer') {
// Ignore empty expressions.
if (child.expression.type !== 'JSXEmptyExpression') {
children.push(child.expression)
}
} else if (child.type === 'JSXText') {
const value = child.value
// Replace tabs w/ spaces.
.replace(/\t/g, ' ')
// Use line feeds, drop spaces around them.
.replace(/ *(\r?\n|\r) */g, '\n')
// Collapse multiple line feeds.
.replace(/\n+/g, '\n')
// Drop final line feeds.
.replace(/\n+$/, '')
// Drop first line feeds.
.replace(/^\n+/, '')
// Replace line feeds with spaces.
.replace(/\n/g, ' ')
// Ignore collapsible text.
if (value) {
/** @type {Node} */
const text = {type: 'Literal', value}
create(child, text)
children.push(text)
}
} else {
assert(
child.type !== 'JSXElement' &&
child.type !== 'JSXFragment' &&
child.type !== 'JSXSpreadChild'
)
children.push(child)
}
}
/** @type {Identifier | Literal | MemberExpression} */
let name
/** @type {Array<Property | SpreadElement>} */
const fields = []
/** @type {Array<Expression>} */
let parameters = []
/** @type {Expression | undefined} */
let key
// Do the stuff needed for elements.
if (node.type === 'JSXElement') {
name = toIdentifier(node.openingElement.name)
// If the name could be an identifier, but start with a lowercase letter,
// its not a component.
if (name.type === 'Identifier' && /^[a-z]/.test(name.name)) {
/** @type {Node} */
const next = {type: 'Literal', value: name.name}
create(name, next)
name = next
}
/** @type {boolean | undefined} */
let spread
const attributes = node.openingElement.attributes
let index = -1
// Place props in the right order, because we might have duplicates
// in them and whats spread in.
while (++index < attributes.length) {
const attribute = attributes[index]
if (attribute.type === 'JSXSpreadAttribute') {
if (attribute.argument.type === 'ObjectExpression') {
fields.push(...attribute.argument.properties)
} else {
fields.push({type: 'SpreadElement', argument: attribute.argument})
}
spread = true
} else {
const prop = toProperty(attribute)
if (
automatic &&
prop.key.type === 'Identifier' &&
prop.key.name === 'key'
) {
if (spread) {
throw new Error(
'Expected `key` to come before any spread expressions'
)
}
const value = prop.value
assert(
value.type !== 'AssignmentPattern' &&
value.type !== 'ArrayPattern' &&
value.type !== 'ObjectPattern' &&
value.type !== 'RestElement'
)
key = value
} else {
fields.push(prop)
}
}
}
}
// …and fragments.
else if (automatic) {
imports.fragment = true
name = {type: 'Identifier', name: '_Fragment'}
} else {
name = toMemberExpression(
annotations.jsxFrag || config.pragmaFrag || 'React.Fragment'
)
}
if (automatic) {
if (children.length > 0) {
fields.push({
type: 'Property',
key: {type: 'Identifier', name: 'children'},
value:
children.length > 1
? {type: 'ArrayExpression', elements: children}
: children[0],
kind: 'init',
method: false,
shorthand: false,
computed: false
})
}
} else {
parameters = children
}
/** @type {Identifier | Literal | MemberExpression} */
let callee
if (automatic) {
parameters.push({type: 'ObjectExpression', properties: fields})
if (key) {
parameters.push(key)
} else if (config.development) {
parameters.push({type: 'Identifier', name: 'undefined'})
}
const isStaticChildren = children.length > 1
if (config.development) {
imports.jsxDEV = true
callee = {
type: 'Identifier',
name: '_jsxDEV'
}
parameters.push({type: 'Literal', value: isStaticChildren})
/** @type {ObjectExpression} */
const source = {
type: 'ObjectExpression',
properties: [
{
type: 'Property',
method: false,
shorthand: false,
computed: false,
kind: 'init',
key: {type: 'Identifier', name: 'fileName'},
value: {
type: 'Literal',
value: config.filePath || '<source.js>'
}
}
]
}
if (node.loc) {
source.properties.push(
{
type: 'Property',
method: false,
shorthand: false,
computed: false,
kind: 'init',
key: {type: 'Identifier', name: 'lineNumber'},
value: {type: 'Literal', value: node.loc.start.line}
},
{
type: 'Property',
method: false,
shorthand: false,
computed: false,
kind: 'init',
key: {type: 'Identifier', name: 'columnNumber'},
value: {type: 'Literal', value: node.loc.start.column + 1}
}
)
}
parameters.push(source, {type: 'ThisExpression'})
} else if (isStaticChildren) {
imports.jsxs = true
callee = {type: 'Identifier', name: '_jsxs'}
} else {
imports.jsx = true
callee = {type: 'Identifier', name: '_jsx'}
}
}
// Classic.
else {
if (fields.length > 0) {
parameters.unshift({type: 'ObjectExpression', properties: fields})
} else if (parameters.length > 0) {
parameters.unshift({type: 'Literal', value: null})
}
callee = toMemberExpression(
annotations.jsx || config.pragma || 'React.createElement'
)
}
parameters.unshift(name)
/** @type {Node} */
const call = {
type: 'CallExpression',
callee,
arguments: parameters,
optional: false
}
create(node, call)
this.replace(call)
}
})
}
/**
* Turn a JSX attribute into a JavaScript property.
*
* @param {JSXAttribute} node
* JSX attribute.
* @returns {Property}
* JS property.
*/
function toProperty(node) {
/** @type {Expression} */
let value
if (node.value) {
if (node.value.type === 'JSXExpressionContainer') {
const valueExpression = node.value.expression
assert(
valueExpression.type !== 'JSXEmptyExpression',
'`JSXEmptyExpression` is not allowed in props.'
)
value = valueExpression
}
// Literal or call expression.
else {
const nodeValue = node.value
assert(
nodeValue.type !== 'JSXElement' && nodeValue.type !== 'JSXFragment',
'JSX{Element,Fragment} are already compiled to `CallExpression`'
)
value = nodeValue
delete value.raw
}
}
// Boolean prop.
else {
value = {type: 'Literal', value: true}
}
/** @type {Property} */
const replacement = {
type: 'Property',
key: toIdentifier(node.name),
value,
kind: 'init',
method: false,
shorthand: false,
computed: false
}
create(node, replacement)
return replacement
}
/**
* Turn a JSX identifier into a normal JS identifier.
*
* @param {JSXIdentifier | JSXMemberExpression | JSXNamespacedName} node
* JSX identifier.
* @returns {Identifier | Literal | MemberExpression}
* JS identifier.
*/
function toIdentifier(node) {
/** @type {Identifier | Literal | MemberExpression} */
let replace
if (node.type === 'JSXMemberExpression') {
// `property` is always a `JSXIdentifier`, but it could be something that
// isnt an ES identifier name.
const id = toIdentifier(node.property)
replace = {
type: 'MemberExpression',
object: toIdentifier(node.object),
property: id,
computed: id.type === 'Literal',
optional: false
}
} else if (node.type === 'JSXNamespacedName') {
replace = {
type: 'Literal',
value: node.namespace.name + ':' + node.name.name
}
}
// Must be `JSXIdentifier`.
else {
replace = isIdentifierName(node.name)
? {type: 'Identifier', name: node.name}
: {type: 'Literal', value: node.name}
}
create(node, replace)
return replace
}
/**
* Turn a dotted string into a member expression.
*
* @param {string} id
* Identifiers.
* @returns {Identifier | Literal | MemberExpression}
* Expression.
*/
function toMemberExpression(id) {
const identifiers = id.split('.')
let index = -1
/** @type {Identifier | Literal | MemberExpression | undefined} */
let result
while (++index < identifiers.length) {
/** @type {Identifier | Literal} */
const prop = isIdentifierName(identifiers[index])
? {type: 'Identifier', name: identifiers[index]}
: {type: 'Literal', value: identifiers[index]}
result = result
? {
type: 'MemberExpression',
object: result,
property: prop,
computed: Boolean(index && prop.type === 'Literal'),
optional: false
}
: prop
}
assert(result, 'always a result')
return result
}
/**
* Inherit some fields from `from` into `to`.
*
* @param {Node} from
* Node to inherit from.
* @param {Node} to
* Node to add to.
* @returns {undefined}
* Nothing.
*/
function create(from, to) {
const fields = ['start', 'end', 'loc', 'range', 'comments']
let index = -1
while (++index < fields.length) {
const field = fields[index]
if (field in from) {
// @ts-expect-error: indexable.
to[field] = from[field]
}
}
}

22
node_modules/estree-util-build-jsx/license generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

93
node_modules/estree-util-build-jsx/package.json generated vendored Normal file
View File

@@ -0,0 +1,93 @@
{
"name": "estree-util-build-jsx",
"version": "3.0.1",
"description": "Transform JSX in estrees to function calls (for react, preact, and most hyperscript interfaces)",
"license": "MIT",
"keywords": [
"estree",
"ast",
"ecmascript",
"javascript",
"tree",
"jsx",
"xml",
"build",
"hyperscript",
"compile",
"call",
"acorn",
"espree",
"react",
"preact"
],
"repository": "syntax-tree/estree-util-build-jsx",
"bugs": "https://github.com/syntax-tree/estree-util-build-jsx/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/estree-jsx": "^1.0.0",
"devlop": "^1.0.0",
"estree-util-is-identifier-name": "^3.0.0",
"estree-walker": "^3.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"acorn": "^8.0.0",
"acorn-jsx": "^5.0.0",
"astring": "^1.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.56.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"bracketSpacing": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"unicorn/prefer-string-replace-all": "off"
}
}
}

357
node_modules/estree-util-build-jsx/readme.md generated vendored Normal file
View File

@@ -0,0 +1,357 @@
# estree-util-build-jsx
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[estree][] utility to turn JSX into function calls: `<x />` -> `h('x')`!
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`buildJsx(tree[, options])`](#buildjsxtree-options)
* [`Options`](#options)
* [`Runtime`](#runtime-1)
* [Examples](#examples)
* [Example: use with Acorn](#example-use-with-acorn)
* [Types](#types)
* [Compatibility](#compatibility)
* [Related](#related)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a utility that takes an [estree][] (JavaScript) syntax tree as
input that contains embedded JSX nodes (elements, fragments) and turns them into
function calls.
## When should I use this?
If you already have a tree and only need to compile JSX away, use this.
If you have code, use something like [SWC][] or [esbuild][] instead.
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install estree-util-build-jsx
```
In Deno with [`esm.sh`][esmsh]:
```js
import {buildJsx} from 'https://esm.sh/estree-util-build-jsx@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {buildJsx} from 'https://esm.sh/estree-util-build-jsx@3?bundle'
</script>
```
## Use
Say we have the following `example.jsx`:
```js
import x from 'xastscript'
console.log(
<album id={123}>
<name>Born in the U.S.A.</name>
<artist>Bruce Springsteen</artist>
<releasedate date="1984-04-06">April 6, 1984</releasedate>
</album>
)
console.log(
<>
{1 + 1}
<self-closing />
<x name key="value" key={expression} {...spread} />
</>
)
```
…and next to it a module `example.js`:
```js
import fs from 'node:fs/promises'
import jsx from 'acorn-jsx'
import {fromJs} from 'esast-util-from-js'
import {buildJsx} from 'estree-util-build-jsx'
import {toJs} from 'estree-util-to-js'
const doc = String(await fs.readFile('example.jsx'))
const tree = fromJs(doc, {module: true, plugins: [jsx()]})
buildJsx(tree, {pragma: 'x', pragmaFrag: 'null'})
console.log(toJs(tree).value)
```
…now running `node example.js` yields:
```js
import x from "xastscript";
console.log(x("album", {
id: 123
}, x("name", null, "Born in the U.S.A."), x("artist", null, "Bruce Springsteen"), x("releasedate", {
date: "1984-04-06"
}, "April 6, 1984")));
console.log(x(null, null, 1 + 1, x("self-closing"), x("x", Object.assign({
name: true,
key: "value",
key: expression
}, spread))));
```
## API
This package exports the identifier [`buildJsx`][api-build-jsx].
There is no default export.
### `buildJsx(tree[, options])`
Turn JSX in `tree` into function calls: `<x />` -> `h('x')`!
###### Algorithm
In almost all cases, this utility is the same as the Babel plugin, except that
they work on slightly different syntax trees.
Some differences:
* no pure annotations things
* `this` is not a component: `<this>` -> `h('this')`, not `h(this)`
* namespaces are supported: `<a:b c:d>` -> `h('a:b', {'c:d': true})`,
which throws by default in Babel or can be turned on with `throwIfNamespace`
* no `useSpread`, `useBuiltIns`, or `filter` options
###### Parameters
* `tree` ([`Node`][node])
— tree to transform (typically [`Program`][program])
* `options` ([`Options`][api-options], optional)
— configuration
###### Returns
Nothing (`undefined`).
### `Options`
Configuration (TypeScript type).
> 👉 **Note**: you can also configure `runtime`, `importSource`, `pragma`, and
> `pragmaFrag` from within files through comments.
##### Fields
###### `runtime`
Choose the [runtime][jsx-runtime] ([`Runtime`][api-runtime], default: `'classic'`).
Comment form: `@jsxRuntime theRuntime`.
###### `importSource`
Place to import `jsx`, `jsxs`, `jsxDEV`, and `Fragment` from, when the
effective runtime is automatic (`string`, default: `'react'`).
Comment form: `@jsxImportSource theSource`.
> 👉 **Note**: `/jsx-runtime` or `/jsx-dev-runtime` is appended to this provided
> source.
> In CJS, that can resolve to a file (as in `theSource/jsx-runtime.js`), but for
> ESM an export map needs to be set up to point to files:
>
> ```js
> // …
> "exports": {
> // …
> "./jsx-runtime": "./path/to/jsx-runtime.js",
> "./jsx-dev-runtime": "./path/to/jsx-runtime.js"
> // …
> ```
###### `pragma`
Identifier or member expression to call when the effective runtime is classic
(`string`, default: `'React.createElement'`).
Comment form: `@jsx identifier`.
###### `pragmaFrag`
Identifier or member expression to use as a symbol for fragments when the
effective runtime is classic (`string`, default: `'React.Fragment'`).
Comment form: `@jsxFrag identifier`.
###### `development`
When in the automatic runtime, whether to import `theSource/jsx-dev-runtime.js`,
use `jsxDEV`, and pass location info when available (`boolean`, default: `false`).
This helps debugging but adds a lot of code that you dont want in production.
###### `filePath`
File path to the original source file (`string`, example: `'path/to/file.js'`).
Passed in location info to `jsxDEV` when using the automatic runtime with
`development: true`.
### `Runtime`
How to transform JSX (TypeScript type).
###### Type
```ts
type Runtime = 'automatic' | 'classic'
```
## Examples
### Example: use with Acorn
To support configuration from comments in Acorn, those comments have to be in
the program.
This is done by [`espree`][espree] but not automatically by [`acorn`][acorn]:
```js
import {Parser} from 'acorn'
import jsx from 'acorn-jsx'
const doc = '' // To do: get `doc` somehow.
const comments = []
const tree = Parser.extend(jsx()).parse(doc, {onComment: comments})
tree.comments = comments
```
## Types
This package is fully typed with [TypeScript][].
It exports the additional type [`Options`][api-options] and
[`Runtime`][api-runtime].
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `estree-util-build-jsx@^3`,
compatible with Node.js 166.
## Related
* [`syntax-tree/hast-util-to-estree`](https://github.com/syntax-tree/hast-util-to-estree)
— turn [hast](https://github.com/syntax-tree/hast) (HTML) to [estree][]
JSX
* [`coderaiser/estree-to-babel`](https://github.com/coderaiser/estree-to-babel)
— turn [estree][] to Babel trees
## Security
This package is safe.
## Contribute
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/syntax-tree/estree-util-build-jsx/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/estree-util-build-jsx/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/estree-util-build-jsx.svg
[coverage]: https://codecov.io/github/syntax-tree/estree-util-build-jsx
[downloads-badge]: https://img.shields.io/npm/dm/estree-util-build-jsx.svg
[downloads]: https://www.npmjs.com/package/estree-util-build-jsx
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=estree-util-build-jsx
[size]: https://bundlejs.com/?q=estree-util-build-jsx
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install
[esmsh]: https://esm.sh
[license]: license
[author]: https://wooorm.com
[typescript]: https://www.typescriptlang.org
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[acorn]: https://github.com/acornjs/acorn
[estree]: https://github.com/estree/estree
[espree]: https://github.com/eslint/espree
[node]: https://github.com/estree/estree/blob/master/es5.md#node-objects
[program]: https://github.com/estree/estree/blob/master/es5.md#programs
[jsx-runtime]: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
[swc]: https://swc.rs
[esbuild]: https://esbuild.github.io
[api-build-jsx]: #buildjsxtree-options
[api-options]: #options
[api-runtime]: #runtime-1