🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

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

@ -0,0 +1,7 @@
export {buildJsx} from './lib/index.js'
export type Options = import('./lib/index.js').Options
export type Runtime = import('./lib/index.js').Runtime
/**
* To do: remove next major (replaced by `Options` ).
*/
export type BuildJsxOptions = Options

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

@ -0,0 +1,9 @@
/**
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('./lib/index.js').Runtime} Runtime
*
* @typedef {Options} BuildJsxOptions
* To do: remove next major (replaced by `Options` ).
*/
export {buildJsx} from './lib/index.js'

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

@ -0,0 +1,153 @@
/**
* 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
*
* @template {Node} Tree
* Node type.
* @param {Tree} tree
* Tree to transform (typically `Program`).
* @param {Options | null | undefined} [options={}]
* Configuration (optional).
* @returns {Tree}
* Given, modified, `tree`.
*/
export function buildJsx<Tree extends import('estree').Node>(
tree: Tree,
options?: Options | null | undefined
): Tree
export type Node = import('estree-jsx').Node
export type Expression = import('estree-jsx').Expression
export type ObjectExpression = import('estree-jsx').ObjectExpression
export type Property = import('estree-jsx').Property
export type ImportSpecifier = import('estree-jsx').ImportSpecifier
export type SpreadElement = import('estree-jsx').SpreadElement
export type MemberExpression = import('estree-jsx').MemberExpression
export type Literal = import('estree-jsx').Literal
export type Identifier = import('estree-jsx').Identifier
export type JSXAttribute = import('estree-jsx').JSXAttribute
export type JSXMemberExpression = import('estree-jsx').JSXMemberExpression
export type JSXNamespacedName = import('estree-jsx').JSXNamespacedName
export type JSXIdentifier = import('estree-jsx').JSXIdentifier
/**
* 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.
*
* Comment form: `@jsxRuntime theRuntime`.
*/
runtime?: Runtime | null | undefined
/**
* Place to import `jsx`, `jsxs`, `jsxDEV`, and `Fragment` from, when the
* effective runtime is automatic.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* 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 = {
/**
* Runtime.
*/
jsxRuntime?: Runtime | undefined
/**
* 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
}
/**
* 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
}

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

@ -0,0 +1,619 @@
/**
* @typedef {import('estree-jsx').Node} Node
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').ObjectExpression} ObjectExpression
* @typedef {import('estree-jsx').Property} Property
* @typedef {import('estree-jsx').ImportSpecifier} ImportSpecifier
* @typedef {import('estree-jsx').SpreadElement} SpreadElement
* @typedef {import('estree-jsx').MemberExpression} MemberExpression
* @typedef {import('estree-jsx').Literal} Literal
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').JSXAttribute} JSXAttribute
* @typedef {import('estree-jsx').JSXMemberExpression} JSXMemberExpression
* @typedef {import('estree-jsx').JSXNamespacedName} JSXNamespacedName
* @typedef {import('estree-jsx').JSXIdentifier} JSXIdentifier
*
* @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.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* Passed in location info to `jsxDEV` when using the automatic runtime with
* `development: true`.
*
* @typedef Annotations
* State where info from comments is gathered.
* @property {Runtime | undefined} [jsxRuntime]
* Runtime.
* @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.
*
* @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 {walk} from 'estree-walker'
import {name as isIdentifierName} from 'estree-util-is-identifier-name'
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
*
* @template {Node} Tree
* Node type.
* @param {Tree} tree
* Tree to transform (typically `Program`).
* @param {Options | null | undefined} [options={}]
* Configuration (optional).
* @returns {Tree}
* Given, modified, `tree`.
*/
// To do next major: do not return the given Node.
export function buildJsx(tree, options) {
const config = options || {}
let automatic = config.runtime === 'automatic'
/** @type {Annotations} */
const annotations = {}
/** @type {Imports} */
const imports = {}
walk(tree, {
// @ts-expect-error: hush, `estree-walker` is broken.
enter(/** @type {Node} */ 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: indexable.
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`'
)
}
}
}
},
// @ts-expect-error: hush, `estree-walker` is broken.
// eslint-disable-next-line complexity
leave(/** @type {Node} */ 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) {
node.body.unshift({
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) {
children.push(create(child, {type: 'Literal', value}))
}
} else {
// @ts-expect-error JSX{Element,Fragment} have already been compiled,
// and `JSXSpreadChild` is not supported in Babel either, so ignore
// it.
children.push(child)
}
}
/** @type {MemberExpression | Literal | Identifier} */
let name
/** @type {Array<Property>} */
let fields = []
/** @type {Array<Expression>} */
const objects = []
/** @type {Array<Expression | SpreadElement>} */
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)) {
name = create(name, {type: 'Literal', value: name.name})
}
/** @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 (fields.length > 0) {
objects.push({type: 'ObjectExpression', properties: fields})
fields = []
}
objects.push(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'
)
}
// @ts-expect-error I cant see object patterns being used as
// attribute values? 🤷‍♂️
key = prop.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
}
if (fields.length > 0) {
objects.push({type: 'ObjectExpression', properties: fields})
}
/** @type {Expression | undefined} */
let props
/** @type {MemberExpression | Literal | Identifier} */
let callee
if (objects.length > 1) {
// Dont mutate the first object, shallow clone instead.
if (objects[0].type !== 'ObjectExpression') {
objects.unshift({type: 'ObjectExpression', properties: []})
}
props = {
type: 'CallExpression',
callee: toMemberExpression('Object.assign'),
arguments: objects,
optional: false
}
} else if (objects.length > 0) {
props = objects[0]
}
if (automatic) {
parameters.push(props || {type: 'ObjectExpression', properties: []})
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 {
// There are props or children.
if (props || parameters.length > 0) {
parameters.unshift(props || {type: 'Literal', value: null})
}
callee = toMemberExpression(
annotations.jsx || config.pragma || 'React.createElement'
)
}
parameters.unshift(name)
// Types of `estree-walker` are wrong
this.replace(
create(node, {
type: 'CallExpression',
callee,
arguments: parameters,
optional: false
})
)
}
})
return tree
}
/**
* @param {JSXAttribute} node
* @returns {Property}
*/
function toProperty(node) {
/** @type {Expression} */
let value
if (node.value) {
if (node.value.type === 'JSXExpressionContainer') {
// @ts-expect-error `JSXEmptyExpression` is not allowed in props.
value = node.value.expression
}
// Literal or call expression.
else {
// @ts-expect-error: JSX{Element,Fragment} are already compiled to
// `CallExpression`.
value = node.value
// @ts-expect-error Remove `raw` so we dont get character references in
// strings.
delete value.raw
}
}
// Boolean prop.
else {
value = {type: 'Literal', value: true}
}
return create(node, {
type: 'Property',
key: toIdentifier(node.name),
value,
kind: 'init',
method: false,
shorthand: false,
computed: false
})
}
/**
* @param {JSXMemberExpression | JSXNamespacedName | JSXIdentifier} node
* @returns {MemberExpression | Identifier | Literal}
*/
function toIdentifier(node) {
/** @type {MemberExpression | Identifier | Literal} */
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}
}
return create(node, replace)
}
/**
* @param {string} id
* @returns {Identifier | Literal | MemberExpression}
*/
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
}
// @ts-expect-error: always a result.
return result
}
/**
* @template {Node} T
* @param {Node} from
* @param {T} node
* @returns {T}
*/
function create(from, node) {
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.
node[field] = from[field]
}
}
return node
}

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.

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

@ -0,0 +1,94 @@
{
"name": "estree-util-build-jsx",
"version": "2.2.2",
"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",
"recast",
"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",
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/estree-jsx": "^1.0.0",
"estree-util-is-identifier-name": "^2.0.0",
"estree-walker": "^3.0.0"
},
"devDependencies": {
"@types/escodegen": "^0.0.7",
"@types/node": "^18.0.0",
"acorn": "^8.0.0",
"acorn-jsx": "^5.0.0",
"astring": "^1.0.0",
"c8": "^7.0.0",
"escodegen": "^2.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"recast": "^0.22.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

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

@ -0,0 +1,353 @@
# 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)
* [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 14.14+ and 16.0+), 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@2'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {buildJsx} from 'https://esm.sh/estree-util-build-jsx@2?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 {fromJs} from 'esast-util-from-js'
import {buildJsx} from 'estree-util-build-jsx'
import {toJs} from 'estree-util-to-js'
import jsx from 'acorn-jsx'
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`][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`][options], optional)
— configuration
###### Returns
Given, modified, `tree` ([`Node`][node]).
### `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`][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` and `Runtime`.
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## 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/bundlephobia/minzip/estree-util-build-jsx.svg
[size]: https://bundlephobia.com/result?p=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
[build-jsx]: #buildjsxtree-options
[options]: #options
[runtime]: #runtime