feat(ui): finalize E-TIB modernization with footer redesign, video optimization, and TS fixes
Former-commit-id: 67ac02c8404cc66893fdf97308574701cca6000c
This commit is contained in:
Generated
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../astring@1.9.0/node_modules/astring
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @typedef {import('./lib/index.js').Handler} Handler
|
||||
* @typedef {import('./lib/index.js').Handlers} Handlers
|
||||
* @typedef {import('./lib/index.js').Options} Options
|
||||
* @typedef {import('./lib/index.js').Result} Result
|
||||
* @typedef {import('./lib/index.js').State} State
|
||||
*/
|
||||
|
||||
export {toJs} from './lib/index.js'
|
||||
export {jsx} from './lib/jsx.js'
|
||||
Generated
Vendored
+145
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* @typedef {import('astring').State} State
|
||||
* @typedef {import('estree-jsx').Node} Nodes
|
||||
* @typedef {import('estree-jsx').Program} Program
|
||||
* @typedef {typeof import('source-map').SourceMapGenerator} SourceMapGenerator
|
||||
* @typedef {import('source-map').RawSourceMap} Map
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Record<Nodes['type'], Handler>} Generator
|
||||
*
|
||||
* @callback Handler
|
||||
* Handle a particular node.
|
||||
* @param {Generator} this
|
||||
* `astring` generator.
|
||||
* @param {any} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*
|
||||
* @typedef {Partial<import('astring').Generator>} Handlers
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {OptionsWithMaybeMapGenerator} Options
|
||||
* Configuration.
|
||||
*
|
||||
* @typedef OptionsFieldsBase
|
||||
* Base shared option fields.
|
||||
* @property {Handlers | null | undefined} [handlers]
|
||||
* Object mapping node types to functions handling the corresponding nodes.
|
||||
*
|
||||
* @typedef OptionsFieldsWithoutSourceMapGenerator
|
||||
* Extra option fields where there’s definitely no source map generator.
|
||||
* @property {null | undefined} [SourceMapGenerator]
|
||||
* Generate a source map by passing a `SourceMapGenerator` from `source-map`
|
||||
* in; this works if there is positional info on nodes.
|
||||
* @property {null | undefined} [filePath]
|
||||
* Path to input file; only used in source map.
|
||||
*
|
||||
* @typedef OptionsFieldsWithSourceMapGenerator
|
||||
* Extra option fields where there’s definitely a source map generator.
|
||||
* @property {SourceMapGenerator} SourceMapGenerator
|
||||
* Generate a source map by passing a `SourceMapGenerator` from `source-map`
|
||||
* in; this works if there is positional info on nodes.
|
||||
* @property {string | null | undefined} [filePath]
|
||||
* Path to input file; only used in source map.
|
||||
*
|
||||
* @typedef OptionsFieldsMaybeSourceMapGenerator
|
||||
* Extra option fields where there may or may not be a source map generator.
|
||||
* @property {SourceMapGenerator | null | undefined} [SourceMapGenerator]
|
||||
* Generate a source map by passing a `SourceMapGenerator` from `source-map`
|
||||
* in; this works if there is positional info on nodes.
|
||||
* @property {string | null | undefined} [filePath]
|
||||
* Path to input file; only used in source map.
|
||||
*
|
||||
* @typedef {OptionsFieldsBase & OptionsFieldsWithoutSourceMapGenerator} OptionsWithoutSourceMapGenerator
|
||||
* Options where there’s definitely no source map generator.
|
||||
* @typedef {OptionsFieldsBase & OptionsFieldsWithSourceMapGenerator} OptionsWithSourceMapGenerator
|
||||
* Options where there’s definitely a source map generator.
|
||||
* @typedef {OptionsFieldsBase & OptionsFieldsMaybeSourceMapGenerator} OptionsWithMaybeMapGenerator
|
||||
* Options where there may or may not be a source map generator.
|
||||
*
|
||||
* @typedef {ResultWithMaybeSourceMapGenerator} Result
|
||||
* Result.
|
||||
*
|
||||
* @typedef ResultFieldsBase
|
||||
* Base shared result fields.
|
||||
* @property {string} value
|
||||
* Serialized JavaScript.
|
||||
*
|
||||
* @typedef ResultFieldsWithoutSourceMapGenerator
|
||||
* Extra result fields where there’s definitely no source map generator.
|
||||
* @property {undefined} map
|
||||
* Source map as (parsed) JSON, if `SourceMapGenerator` is passed.
|
||||
*
|
||||
* @typedef ResultFieldsWithSourceMapGenerator
|
||||
* Extra result fields where there’s definitely a source map generator.
|
||||
* @property {Map} map
|
||||
* Source map as (parsed) JSON, if `SourceMapGenerator` is not passed.
|
||||
*
|
||||
* @typedef ResultFieldsMaybeSourceMapGenerator
|
||||
* Extra result fields where there may or may not be a source map generator.
|
||||
* @property {Map | undefined} map
|
||||
* Source map as (parsed) JSON, if `SourceMapGenerator` might be passed.
|
||||
*
|
||||
* @typedef {ResultFieldsBase & ResultFieldsWithoutSourceMapGenerator} ResultWithoutSourceMapGenerator
|
||||
* Result where there’s definitely no source map generator.
|
||||
* @typedef {ResultFieldsBase & ResultFieldsWithSourceMapGenerator} ResultWithSourceMapGenerator
|
||||
* Result where there’s definitely a source map generator.
|
||||
* @typedef {ResultFieldsBase & ResultFieldsMaybeSourceMapGenerator} ResultWithMaybeSourceMapGenerator
|
||||
* Result where there may or may not be a source map generator.
|
||||
*/
|
||||
|
||||
import {GENERATOR, generate} from 'astring'
|
||||
|
||||
/** @type {Options} */
|
||||
const emptyOptions = {}
|
||||
|
||||
/**
|
||||
* Serialize an estree as JavaScript.
|
||||
*
|
||||
* @overload
|
||||
* @param {Program} tree
|
||||
* @param {OptionsWithSourceMapGenerator} options
|
||||
* @returns {ResultWithSourceMapGenerator}
|
||||
*
|
||||
* @overload
|
||||
* @param {Program} tree
|
||||
* @param {OptionsWithMaybeMapGenerator} options
|
||||
* @returns {ResultWithMaybeSourceMapGenerator}
|
||||
*
|
||||
* @overload
|
||||
* @param {Program} tree
|
||||
* @param {OptionsWithoutSourceMapGenerator | null | undefined} [options]
|
||||
* @returns {ResultWithoutSourceMapGenerator}
|
||||
*
|
||||
* @param {Program} tree
|
||||
* Estree (esast).
|
||||
* @param {Options | null | undefined} [options]
|
||||
* Configuration (optional).
|
||||
* @returns {Result}
|
||||
* Result, optionally with source map.
|
||||
*/
|
||||
export function toJs(tree, options) {
|
||||
const {SourceMapGenerator, filePath, handlers} = options || emptyOptions
|
||||
const sourceMap = SourceMapGenerator
|
||||
? new SourceMapGenerator({file: filePath || '<unknown>.js'})
|
||||
: undefined
|
||||
|
||||
const value = generate(
|
||||
tree,
|
||||
// @ts-expect-error: `sourceMap` can be undefined, `astring` types are buggy.
|
||||
{
|
||||
comments: true,
|
||||
generator: {...GENERATOR, ...handlers},
|
||||
sourceMap: sourceMap || undefined
|
||||
}
|
||||
)
|
||||
const map = sourceMap ? sourceMap.toJSON() : undefined
|
||||
|
||||
return {value, map}
|
||||
}
|
||||
Generated
Vendored
+364
@@ -0,0 +1,364 @@
|
||||
/**
|
||||
* @typedef {import('estree-jsx').JSXAttribute} JsxAttribute
|
||||
* @typedef {import('estree-jsx').JSXClosingElement} JsxClosingElement
|
||||
* @typedef {import('estree-jsx').JSXClosingFragment} JsxClosingFragment
|
||||
* @typedef {import('estree-jsx').JSXElement} JsxElement
|
||||
* @typedef {import('estree-jsx').JSXExpressionContainer} JsxExpressionContainer
|
||||
* @typedef {import('estree-jsx').JSXFragment} JsxFragment
|
||||
* @typedef {import('estree-jsx').JSXIdentifier} JsxIdentifier
|
||||
* @typedef {import('estree-jsx').JSXMemberExpression} JsxMemberExpression
|
||||
* @typedef {import('estree-jsx').JSXNamespacedName} JsxNamespacedName
|
||||
* @typedef {import('estree-jsx').JSXOpeningElement} JsxOpeningElement
|
||||
* @typedef {import('estree-jsx').JSXOpeningFragment} JsxOpeningFragment
|
||||
* @typedef {import('estree-jsx').JSXSpreadAttribute} JsxSpreadAttribute
|
||||
* @typedef {import('estree-jsx').JSXText} JsxText
|
||||
*
|
||||
* @typedef {import('./index.js').Generator} Generator
|
||||
* @typedef {import('./index.js').State} State
|
||||
*/
|
||||
|
||||
export const jsx = {
|
||||
JSXAttribute: jsxAttribute,
|
||||
JSXClosingElement: jsxClosingElement,
|
||||
JSXClosingFragment: jsxClosingFragment,
|
||||
JSXElement: jsxElement,
|
||||
JSXEmptyExpression: jsxEmptyExpression,
|
||||
JSXExpressionContainer: jsxExpressionContainer,
|
||||
JSXFragment: jsxFragment,
|
||||
JSXIdentifier: jsxIdentifier,
|
||||
JSXMemberExpression: jsxMemberExpression,
|
||||
JSXNamespacedName: jsxNamespacedName,
|
||||
JSXOpeningElement: jsxOpeningElement,
|
||||
JSXOpeningFragment: jsxOpeningFragment,
|
||||
JSXSpreadAttribute: jsxSpreadAttribute,
|
||||
JSXText: jsxText
|
||||
}
|
||||
|
||||
/**
|
||||
* `attr`
|
||||
* `attr="something"`
|
||||
* `attr={1}`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxAttribute} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxAttribute(node, state) {
|
||||
this[node.name.type](node.name, state)
|
||||
|
||||
if (node.value !== null && node.value !== undefined) {
|
||||
state.write('=')
|
||||
|
||||
// Encode double quotes in attribute values.
|
||||
if (node.value.type === 'Literal') {
|
||||
state.write(
|
||||
'"' + encodeJsx(String(node.value.value)).replace(/"/g, '"') + '"',
|
||||
node
|
||||
)
|
||||
} else {
|
||||
this[node.value.type](node.value, state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `</div>`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxClosingElement} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxClosingElement(node, state) {
|
||||
state.write('</')
|
||||
this[node.name.type](node.name, state)
|
||||
state.write('>')
|
||||
}
|
||||
|
||||
/**
|
||||
* `</>`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxClosingFragment} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxClosingFragment(node, state) {
|
||||
state.write('</>', node)
|
||||
}
|
||||
|
||||
/**
|
||||
* `<div />`
|
||||
* `<div></div>`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxElement} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxElement(node, state) {
|
||||
let index = -1
|
||||
|
||||
this[node.openingElement.type](node.openingElement, state)
|
||||
|
||||
if (node.children) {
|
||||
while (++index < node.children.length) {
|
||||
const child = node.children[index]
|
||||
|
||||
// Supported in types but not by Acorn.
|
||||
/* c8 ignore next 3 */
|
||||
if (child.type === 'JSXSpreadChild') {
|
||||
throw new Error('JSX spread children are not supported')
|
||||
}
|
||||
|
||||
this[child.type](child, state)
|
||||
}
|
||||
}
|
||||
|
||||
if (node.closingElement) {
|
||||
this[node.closingElement.type](node.closingElement, state)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `{}` (always in a `JSXExpressionContainer`, which does the curlies)
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxEmptyExpression() {}
|
||||
|
||||
/**
|
||||
* `{expression}`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxExpressionContainer} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxExpressionContainer(node, state) {
|
||||
state.write('{')
|
||||
this[node.expression.type](node.expression, state)
|
||||
state.write('}')
|
||||
}
|
||||
|
||||
/**
|
||||
* `<></>`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxFragment} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxFragment(node, state) {
|
||||
let index = -1
|
||||
|
||||
this[node.openingFragment.type](node.openingFragment, state)
|
||||
|
||||
if (node.children) {
|
||||
while (++index < node.children.length) {
|
||||
const child = node.children[index]
|
||||
|
||||
// Supported in types but not by Acorn.
|
||||
/* c8 ignore next 3 */
|
||||
if (child.type === 'JSXSpreadChild') {
|
||||
throw new Error('JSX spread children are not supported')
|
||||
}
|
||||
|
||||
this[child.type](child, state)
|
||||
}
|
||||
}
|
||||
|
||||
this[node.closingFragment.type](node.closingFragment, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* `div`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxIdentifier} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxIdentifier(node, state) {
|
||||
state.write(node.name, node)
|
||||
}
|
||||
|
||||
/**
|
||||
* `member.expression`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxMemberExpression} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxMemberExpression(node, state) {
|
||||
this[node.object.type](node.object, state)
|
||||
state.write('.')
|
||||
this[node.property.type](node.property, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* `ns:name`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxNamespacedName} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxNamespacedName(node, state) {
|
||||
this[node.namespace.type](node.namespace, state)
|
||||
state.write(':')
|
||||
this[node.name.type](node.name, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* `<div>`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxOpeningElement} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxOpeningElement(node, state) {
|
||||
let index = -1
|
||||
|
||||
state.write('<')
|
||||
this[node.name.type](node.name, state)
|
||||
|
||||
if (node.attributes) {
|
||||
while (++index < node.attributes.length) {
|
||||
state.write(' ')
|
||||
this[node.attributes[index].type](node.attributes[index], state)
|
||||
}
|
||||
}
|
||||
|
||||
state.write(node.selfClosing ? ' />' : '>')
|
||||
}
|
||||
|
||||
/**
|
||||
* `<>`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxOpeningFragment} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxOpeningFragment(node, state) {
|
||||
state.write('<>', node)
|
||||
}
|
||||
|
||||
/**
|
||||
* `{...argument}`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxSpreadAttribute} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxSpreadAttribute(node, state) {
|
||||
state.write('{')
|
||||
// eslint-disable-next-line new-cap
|
||||
this.SpreadElement(node, state)
|
||||
state.write('}')
|
||||
}
|
||||
|
||||
/**
|
||||
* `!`
|
||||
*
|
||||
* @this {Generator}
|
||||
* `astring` generator.
|
||||
* @param {JsxText} node
|
||||
* Node to serialize.
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function jsxText(node, state) {
|
||||
state.write(encodeJsx(node.value).replace(/[<>{}]/g, replaceJsxChar), node)
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that character references don’t pop up.
|
||||
*
|
||||
* For example, the text `©` should stay that way, and not turn into `©`.
|
||||
* We could encode all `&` (easy but verbose) or look for actual valid
|
||||
* references (complex but cleanest output).
|
||||
* Looking for the 2nd character gives us a middle ground.
|
||||
* The `#` is for (decimal and hexadecimal) numeric references, the letters
|
||||
* are for the named references.
|
||||
*
|
||||
* @param {string} value
|
||||
* Value to encode.
|
||||
* @returns {string}
|
||||
* Encoded value.
|
||||
*/
|
||||
function encodeJsx(value) {
|
||||
return value.replace(/&(?=[#a-z])/gi, '&')
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} $0
|
||||
* @returns {string}
|
||||
*/
|
||||
function replaceJsxChar($0) {
|
||||
return $0 === '<'
|
||||
? '<'
|
||||
: $0 === '>'
|
||||
? '>'
|
||||
: $0 === '{'
|
||||
? '{'
|
||||
: '}'
|
||||
}
|
||||
Generated
Vendored
+90
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"name": "estree-util-to-js",
|
||||
"version": "2.0.0",
|
||||
"description": "estree (and esast) utility to serialize to JavaScript",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"estree",
|
||||
"estree-util",
|
||||
"esast",
|
||||
"esast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"js",
|
||||
"serialize",
|
||||
"stringify",
|
||||
"tostring",
|
||||
"astring"
|
||||
],
|
||||
"repository": "syntax-tree/estree-util-to-js",
|
||||
"bugs": "https://github.com/syntax-tree/estree-util-to-js/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",
|
||||
"astring": "^1.8.0",
|
||||
"source-map": "^0.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.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.55.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/index.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,
|
||||
"#": "needed `any`s",
|
||||
"ignoreFiles": [
|
||||
"lib/index.d.ts"
|
||||
],
|
||||
"strict": true
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"rules": {
|
||||
"unicorn/prefer-string-replace-all": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user