unplugin-jsx-string
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -1,5 +0,13 @@ | ||
export { transformJsxToString } from './core/convert.js'; | ||
import './core/utils.js'; | ||
import './core/options.js'; | ||
import * as magic_string from 'magic-string'; | ||
import { O as OptionsResolved } from './options-D9JXHjEn.js'; | ||
import '@babel/parser'; | ||
import '@rollup/pluginutils'; | ||
declare function transformJsxToString(code: string, { debug, plugins, id, }: Pick<OptionsResolved, 'debug' | 'plugins'> & { | ||
id?: string; | ||
}): { | ||
code: string; | ||
readonly map: magic_string.SourceMap; | ||
}; | ||
export { transformJsxToString }; |
405
dist/api.js
@@ -1,401 +0,6 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
import { | ||
transformJsxToString | ||
} from "./chunk-RYSW25F3.js"; | ||
export { | ||
transformJsxToString | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/api.ts | ||
var api_exports = {}; | ||
__export(api_exports, { | ||
transformJsxToString: () => transformJsxToString | ||
}); | ||
module.exports = __toCommonJS(api_exports); | ||
// src/core/convert.ts | ||
var import_parser = require("@babel/parser"); | ||
var import_estree_walker = require("estree-walker"); | ||
var import_entities = require("entities"); | ||
var import_magic_string = __toESM(require("magic-string")); | ||
var import_types = require("@babel/types"); | ||
// src/core/utils.ts | ||
var import_jsesc = __toESM(require("jsesc")); | ||
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g; | ||
function kebabCase(str) { | ||
return str.replaceAll(KEBAB_REGEX, (match) => { | ||
return `-${match.toLowerCase()}`; | ||
}); | ||
} | ||
var styleToString = (styles) => Object.entries(styles).map(([key, value]) => `${kebabCase(key)}:${value}`).join(";"); | ||
var RAW_RE = /__RAW_(.*?)_RAW/g; | ||
var escapeString = (str) => { | ||
const text = (0, import_jsesc.default)(str, { | ||
quotes: "backtick", | ||
wrap: true, | ||
es6: true | ||
}); | ||
return text.replaceAll(RAW_RE, "${$1}"); | ||
}; | ||
var isPrimitive = (val) => { | ||
if (typeof val === "object") | ||
return val === null; | ||
return typeof val !== "function"; | ||
}; | ||
var isPlainObject = (obj) => { | ||
return Object.prototype.toString.call(obj) === "[object Object]"; | ||
}; | ||
// src/core/convert.ts | ||
function extractJsx(code, plugins) { | ||
const ast = (0, import_parser.parse)(code, { | ||
sourceType: "module", | ||
plugins | ||
}); | ||
const nodes = []; | ||
(0, import_estree_walker.walk)(ast.program, { | ||
enter(node) { | ||
let arg; | ||
if ((0, import_types.isCallExpression)(node) && (0, import_types.isIdentifier)(node.callee, { name: "jsxToString" }) && (0, import_types.isJSX)(arg = node.arguments[0])) | ||
nodes.push([arg, node]); | ||
} | ||
}); | ||
return nodes; | ||
} | ||
function transformJsx(code, node) { | ||
return escapeString(toStringJsx(node)); | ||
function toStringJsx(node2) { | ||
return toStringExpression(resolveJsx(node2)); | ||
} | ||
function toStringExpression(expr) { | ||
if (expr instanceof RegExp) { | ||
return expr.toString(); | ||
} else if (typeof expr === "object") { | ||
return JSON.stringify(expr); | ||
} | ||
return String(expr); | ||
} | ||
function toStringJsxChildren(nodes) { | ||
return nodes.map((child) => toStringJsx(child)).join(""); | ||
} | ||
function toStringJsxText(node2) { | ||
const texts = node2.value.split("\n"); | ||
return texts.map((text, idx) => idx > 0 ? text.trim() : text).filter((line) => { | ||
if (line.trim().length === 0) | ||
return false; | ||
return true; | ||
}).join(" "); | ||
} | ||
function toStringJsxElement(node2) { | ||
if (node2.openingElement.selfClosing) { | ||
return toStringOpeningElement(node2.openingElement); | ||
} else { | ||
const children = toStringJsxChildren(node2.children); | ||
return `${toStringOpeningElement( | ||
node2.openingElement | ||
)}${children}</${toStringJsxName(node2.closingElement.name)}>`; | ||
} | ||
function toStringOpeningElement(node3) { | ||
let str = `<${toStringJsxName(node3.name)}`; | ||
const props = node3.attributes.map((attr) => { | ||
if (attr.type === "JSXAttribute") { | ||
return toStringJsxAttribute(attr); | ||
} else { | ||
return notSupported(node3); | ||
} | ||
}).filter((x) => x !== void 0); | ||
if (props.length > 0) { | ||
str += ` ${props.join(" ")}`; | ||
} | ||
str += node3.selfClosing ? "/>" : ">"; | ||
return str; | ||
} | ||
} | ||
function toStringJsxAttribute(node2) { | ||
let name = toStringJsxName(node2.name); | ||
if (name === "className") | ||
name = "class"; | ||
else if (name.startsWith("on")) | ||
name = name.toLowerCase(); | ||
let value; | ||
if (node2.value) { | ||
const rawValue = toStringJsxAttributeValue(node2.value, name); | ||
if (rawValue === null) { | ||
return void 0; | ||
} | ||
value = rawValue; | ||
} | ||
return `${name}${value !== void 0 ? `="${(0, import_entities.encode)(value)}"` : ""}`; | ||
} | ||
function toStringJsxAttributeValue(node2, key) { | ||
let value; | ||
if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isBooleanLiteral)(node2.expression)) { | ||
value = node2.expression.value ? void 0 : null; | ||
} else if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isFunction)(node2.expression)) { | ||
value = getSource(node2.expression.body); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
value = resolveJsx(node2); | ||
if (key === "style" && isPlainObject(value)) { | ||
value = styleToString(value); | ||
} else if (key === "class" && Array.isArray(value) && value.every((e) => isPrimitive(e))) | ||
value = value.join(" "); | ||
} else if ((0, import_types.isStringLiteral)(node2)) { | ||
value = node2.value; | ||
} | ||
if (value === void 0 || value === null) | ||
return value; | ||
return toStringExpression(value); | ||
} | ||
function toStringJsxName(node2) { | ||
if (node2.type === "JSXIdentifier") | ||
return node2.name; | ||
return notSupported(node2); | ||
} | ||
function resolveJsx(node2) { | ||
switch (node2.type) { | ||
case "JSXElement": | ||
return toStringJsxElement(node2); | ||
case "JSXFragment": | ||
return toStringJsxChildren(node2.children); | ||
case "JSXText": | ||
return toStringJsxText(node2); | ||
case "JSXEmptyExpression": | ||
return node2.innerComments?.map((comment) => `<!--${comment.value}-->`).join("") ?? ""; | ||
case "JSXExpressionContainer": { | ||
return resolveExpression(node2.expression); | ||
} | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveExpression(node2, parent) { | ||
if ((0, import_types.isLiteral)(node2)) { | ||
return resolveLiteral(node2); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
return resolveJsx(node2); | ||
} | ||
switch (node2.type) { | ||
case "ArrayExpression": | ||
return resolveArrayExpression(node2); | ||
case "ObjectExpression": | ||
return resolveObjectExpression(node2); | ||
case "BinaryExpression": | ||
case "LogicalExpression": | ||
return resolveBinary(node2); | ||
case "UnaryExpression": | ||
return resolveUnaryExpression(node2); | ||
case "ConditionalExpression": | ||
return resolveExpression(node2.test, node2) ? resolveExpression(node2.consequent, node2) : resolveExpression(node2.alternate, node2); | ||
case "SequenceExpression": { | ||
const expressions = node2.expressions.map( | ||
(expr) => resolveExpression(expr, node2) | ||
); | ||
return expressions.at(-1); | ||
} | ||
case "ParenthesizedExpression": | ||
case "TSNonNullExpression": | ||
case "TSAsExpression": | ||
case "TSTypeAssertion": | ||
case "TSInstantiationExpression": | ||
return resolveExpression(node2.expression, node2); | ||
case "CallExpression": | ||
return resolveCallExpression(node2, !parent); | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveCallExpression(node2, isTopLevel) { | ||
if (isTopLevel && node2.callee.type === "Identifier" && node2.callee.name === "jsxRaw") { | ||
return `__RAW_${getSource(node2.arguments[0])}_RAW`; | ||
} | ||
return notSupported(node2); | ||
} | ||
function resolveBinary(node2) { | ||
const left = resolveExpression(node2.left, node2); | ||
const right = resolveExpression(node2.right, node2); | ||
switch (node2.operator) { | ||
case "+": | ||
return left + right; | ||
case "-": | ||
return left - right; | ||
case "*": | ||
return left * right; | ||
case "/": | ||
return left / right; | ||
case "&&": | ||
return left && right; | ||
case "||": | ||
return left || right; | ||
case "??": | ||
return left ?? right; | ||
case "==": | ||
return left == right; | ||
case "!=": | ||
return left != right; | ||
case "===": | ||
return left === right; | ||
case "!==": | ||
return left !== right; | ||
case ">": | ||
return left > right; | ||
case ">=": | ||
return left >= right; | ||
case "<": | ||
return left < right; | ||
case "<=": | ||
return left <= right; | ||
case "%": | ||
return left % right; | ||
case "**": | ||
return left ** right; | ||
case "&": | ||
return left & right; | ||
case "|": | ||
return left | right; | ||
case "^": | ||
return left ^ right; | ||
case "<<": | ||
return left << right; | ||
case ">>": | ||
return left >> right; | ||
case ">>>": | ||
return left >>> right; | ||
case "in": | ||
return left in right; | ||
case "instanceof": | ||
return left instanceof right; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveUnaryExpression(node2) { | ||
const value = resolveExpression(node2.argument, node2); | ||
switch (node2.operator) { | ||
case "!": | ||
return !value; | ||
case "+": | ||
return +value; | ||
case "-": | ||
return -value; | ||
case "typeof": | ||
return typeof value; | ||
case "void": | ||
return void 0; | ||
case "~": | ||
return ~value; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveLiteral(node2) { | ||
switch (node2.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node2); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node2.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node2.pattern, node2.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node2.value; | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveArrayExpression(node2) { | ||
const items = []; | ||
for (const [i, element] of node2.elements.entries()) { | ||
if (element) | ||
items[i] = resolveExpression(element, node2); | ||
} | ||
return items; | ||
} | ||
function resolveObjectExpression(node2) { | ||
const obj = {}; | ||
for (const prop of node2.properties) { | ||
if (prop.type !== "ObjectProperty") | ||
return notSupported(prop); | ||
let key; | ||
if ((0, import_types.isIdentifier)(prop.key) && !prop.computed) { | ||
key = prop.key.name; | ||
} else { | ||
key = resolveExpression(prop.key, prop); | ||
} | ||
obj[key] = resolveExpression(prop.value, prop); | ||
} | ||
return obj; | ||
} | ||
function resolveTemplateLiteral(node2) { | ||
return node2.quasis.reduce((prev, curr, idx) => { | ||
if (node2.expressions[idx]) { | ||
return prev + curr.value.cooked + resolveExpression(node2.expressions[idx], node2); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
function getSource(node2) { | ||
return code.slice(node2.start, node2.end); | ||
} | ||
function notSupported(node2) { | ||
throw new Error(`not supported ${node2.type}: ${getSource(node2)}`); | ||
} | ||
} | ||
function transformJsxToString(code, { | ||
debug, | ||
plugins, | ||
id = "" | ||
}) { | ||
const s = new import_magic_string.default(code); | ||
if (id.endsWith(".tsx")) | ||
plugins.push("typescript"); | ||
const nodes = extractJsx(code, plugins); | ||
for (const [node, expr] of nodes) { | ||
let str; | ||
if (!debug) { | ||
str = transformJsx(code, node); | ||
} else { | ||
try { | ||
str = transformJsx(code, node); | ||
} catch (err) { | ||
str = `(() => { throw new Error(${escapeString(err.toString())}) })()`; | ||
} | ||
} | ||
s.overwrite(expr.start, expr.end, str); | ||
} | ||
return { | ||
code: s.toString(), | ||
get map() { | ||
return s.generateMap(); | ||
} | ||
}; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
transformJsxToString | ||
}); | ||
exports.default = module.exports; |
import * as unplugin from 'unplugin'; | ||
import { Options } from './core/options.js'; | ||
import { a as Options } from './options-D9JXHjEn.js'; | ||
import '@babel/parser'; | ||
import '@rollup/pluginutils'; | ||
declare const _default: (options: Options) => unplugin.EsbuildPlugin; | ||
declare const _default: (options?: Options | undefined) => unplugin.EsbuildPlugin; | ||
export { _default as default }; |
@@ -1,438 +0,10 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
import { | ||
index_default | ||
} from "./chunk-VHWXMNG4.js"; | ||
import "./chunk-RYSW25F3.js"; | ||
// src/esbuild.ts | ||
var esbuild_exports = {}; | ||
__export(esbuild_exports, { | ||
default: () => esbuild_default | ||
}); | ||
module.exports = __toCommonJS(esbuild_exports); | ||
// src/index.ts | ||
var import_unplugin = require("unplugin"); | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
// src/core/convert.ts | ||
var import_parser = require("@babel/parser"); | ||
var import_estree_walker = require("estree-walker"); | ||
var import_entities = require("entities"); | ||
var import_magic_string = __toESM(require("magic-string")); | ||
var import_types = require("@babel/types"); | ||
// src/core/utils.ts | ||
var import_jsesc = __toESM(require("jsesc")); | ||
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g; | ||
function kebabCase(str) { | ||
return str.replaceAll(KEBAB_REGEX, (match) => { | ||
return `-${match.toLowerCase()}`; | ||
}); | ||
} | ||
var styleToString = (styles) => Object.entries(styles).map(([key, value]) => `${kebabCase(key)}:${value}`).join(";"); | ||
var RAW_RE = /__RAW_(.*?)_RAW/g; | ||
var escapeString = (str) => { | ||
const text = (0, import_jsesc.default)(str, { | ||
quotes: "backtick", | ||
wrap: true, | ||
es6: true | ||
}); | ||
return text.replaceAll(RAW_RE, "${$1}"); | ||
var esbuild_default = index_default.esbuild; | ||
export { | ||
esbuild_default as default | ||
}; | ||
var isPrimitive = (val) => { | ||
if (typeof val === "object") | ||
return val === null; | ||
return typeof val !== "function"; | ||
}; | ||
var isPlainObject = (obj) => { | ||
return Object.prototype.toString.call(obj) === "[object Object]"; | ||
}; | ||
// src/core/convert.ts | ||
function extractJsx(code, plugins) { | ||
const ast = (0, import_parser.parse)(code, { | ||
sourceType: "module", | ||
plugins | ||
}); | ||
const nodes = []; | ||
(0, import_estree_walker.walk)(ast.program, { | ||
enter(node) { | ||
let arg; | ||
if ((0, import_types.isCallExpression)(node) && (0, import_types.isIdentifier)(node.callee, { name: "jsxToString" }) && (0, import_types.isJSX)(arg = node.arguments[0])) | ||
nodes.push([arg, node]); | ||
} | ||
}); | ||
return nodes; | ||
} | ||
function transformJsx(code, node) { | ||
return escapeString(toStringJsx(node)); | ||
function toStringJsx(node2) { | ||
return toStringExpression(resolveJsx(node2)); | ||
} | ||
function toStringExpression(expr) { | ||
if (expr instanceof RegExp) { | ||
return expr.toString(); | ||
} else if (typeof expr === "object") { | ||
return JSON.stringify(expr); | ||
} | ||
return String(expr); | ||
} | ||
function toStringJsxChildren(nodes) { | ||
return nodes.map((child) => toStringJsx(child)).join(""); | ||
} | ||
function toStringJsxText(node2) { | ||
const texts = node2.value.split("\n"); | ||
return texts.map((text, idx) => idx > 0 ? text.trim() : text).filter((line) => { | ||
if (line.trim().length === 0) | ||
return false; | ||
return true; | ||
}).join(" "); | ||
} | ||
function toStringJsxElement(node2) { | ||
if (node2.openingElement.selfClosing) { | ||
return toStringOpeningElement(node2.openingElement); | ||
} else { | ||
const children = toStringJsxChildren(node2.children); | ||
return `${toStringOpeningElement( | ||
node2.openingElement | ||
)}${children}</${toStringJsxName(node2.closingElement.name)}>`; | ||
} | ||
function toStringOpeningElement(node3) { | ||
let str = `<${toStringJsxName(node3.name)}`; | ||
const props = node3.attributes.map((attr) => { | ||
if (attr.type === "JSXAttribute") { | ||
return toStringJsxAttribute(attr); | ||
} else { | ||
return notSupported(node3); | ||
} | ||
}).filter((x) => x !== void 0); | ||
if (props.length > 0) { | ||
str += ` ${props.join(" ")}`; | ||
} | ||
str += node3.selfClosing ? "/>" : ">"; | ||
return str; | ||
} | ||
} | ||
function toStringJsxAttribute(node2) { | ||
let name = toStringJsxName(node2.name); | ||
if (name === "className") | ||
name = "class"; | ||
else if (name.startsWith("on")) | ||
name = name.toLowerCase(); | ||
let value; | ||
if (node2.value) { | ||
const rawValue = toStringJsxAttributeValue(node2.value, name); | ||
if (rawValue === null) { | ||
return void 0; | ||
} | ||
value = rawValue; | ||
} | ||
return `${name}${value !== void 0 ? `="${(0, import_entities.encode)(value)}"` : ""}`; | ||
} | ||
function toStringJsxAttributeValue(node2, key) { | ||
let value; | ||
if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isBooleanLiteral)(node2.expression)) { | ||
value = node2.expression.value ? void 0 : null; | ||
} else if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isFunction)(node2.expression)) { | ||
value = getSource(node2.expression.body); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
value = resolveJsx(node2); | ||
if (key === "style" && isPlainObject(value)) { | ||
value = styleToString(value); | ||
} else if (key === "class" && Array.isArray(value) && value.every((e) => isPrimitive(e))) | ||
value = value.join(" "); | ||
} else if ((0, import_types.isStringLiteral)(node2)) { | ||
value = node2.value; | ||
} | ||
if (value === void 0 || value === null) | ||
return value; | ||
return toStringExpression(value); | ||
} | ||
function toStringJsxName(node2) { | ||
if (node2.type === "JSXIdentifier") | ||
return node2.name; | ||
return notSupported(node2); | ||
} | ||
function resolveJsx(node2) { | ||
switch (node2.type) { | ||
case "JSXElement": | ||
return toStringJsxElement(node2); | ||
case "JSXFragment": | ||
return toStringJsxChildren(node2.children); | ||
case "JSXText": | ||
return toStringJsxText(node2); | ||
case "JSXEmptyExpression": | ||
return node2.innerComments?.map((comment) => `<!--${comment.value}-->`).join("") ?? ""; | ||
case "JSXExpressionContainer": { | ||
return resolveExpression(node2.expression); | ||
} | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveExpression(node2, parent) { | ||
if ((0, import_types.isLiteral)(node2)) { | ||
return resolveLiteral(node2); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
return resolveJsx(node2); | ||
} | ||
switch (node2.type) { | ||
case "ArrayExpression": | ||
return resolveArrayExpression(node2); | ||
case "ObjectExpression": | ||
return resolveObjectExpression(node2); | ||
case "BinaryExpression": | ||
case "LogicalExpression": | ||
return resolveBinary(node2); | ||
case "UnaryExpression": | ||
return resolveUnaryExpression(node2); | ||
case "ConditionalExpression": | ||
return resolveExpression(node2.test, node2) ? resolveExpression(node2.consequent, node2) : resolveExpression(node2.alternate, node2); | ||
case "SequenceExpression": { | ||
const expressions = node2.expressions.map( | ||
(expr) => resolveExpression(expr, node2) | ||
); | ||
return expressions.at(-1); | ||
} | ||
case "ParenthesizedExpression": | ||
case "TSNonNullExpression": | ||
case "TSAsExpression": | ||
case "TSTypeAssertion": | ||
case "TSInstantiationExpression": | ||
return resolveExpression(node2.expression, node2); | ||
case "CallExpression": | ||
return resolveCallExpression(node2, !parent); | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveCallExpression(node2, isTopLevel) { | ||
if (isTopLevel && node2.callee.type === "Identifier" && node2.callee.name === "jsxRaw") { | ||
return `__RAW_${getSource(node2.arguments[0])}_RAW`; | ||
} | ||
return notSupported(node2); | ||
} | ||
function resolveBinary(node2) { | ||
const left = resolveExpression(node2.left, node2); | ||
const right = resolveExpression(node2.right, node2); | ||
switch (node2.operator) { | ||
case "+": | ||
return left + right; | ||
case "-": | ||
return left - right; | ||
case "*": | ||
return left * right; | ||
case "/": | ||
return left / right; | ||
case "&&": | ||
return left && right; | ||
case "||": | ||
return left || right; | ||
case "??": | ||
return left ?? right; | ||
case "==": | ||
return left == right; | ||
case "!=": | ||
return left != right; | ||
case "===": | ||
return left === right; | ||
case "!==": | ||
return left !== right; | ||
case ">": | ||
return left > right; | ||
case ">=": | ||
return left >= right; | ||
case "<": | ||
return left < right; | ||
case "<=": | ||
return left <= right; | ||
case "%": | ||
return left % right; | ||
case "**": | ||
return left ** right; | ||
case "&": | ||
return left & right; | ||
case "|": | ||
return left | right; | ||
case "^": | ||
return left ^ right; | ||
case "<<": | ||
return left << right; | ||
case ">>": | ||
return left >> right; | ||
case ">>>": | ||
return left >>> right; | ||
case "in": | ||
return left in right; | ||
case "instanceof": | ||
return left instanceof right; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveUnaryExpression(node2) { | ||
const value = resolveExpression(node2.argument, node2); | ||
switch (node2.operator) { | ||
case "!": | ||
return !value; | ||
case "+": | ||
return +value; | ||
case "-": | ||
return -value; | ||
case "typeof": | ||
return typeof value; | ||
case "void": | ||
return void 0; | ||
case "~": | ||
return ~value; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveLiteral(node2) { | ||
switch (node2.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node2); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node2.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node2.pattern, node2.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node2.value; | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveArrayExpression(node2) { | ||
const items = []; | ||
for (const [i, element] of node2.elements.entries()) { | ||
if (element) | ||
items[i] = resolveExpression(element, node2); | ||
} | ||
return items; | ||
} | ||
function resolveObjectExpression(node2) { | ||
const obj = {}; | ||
for (const prop of node2.properties) { | ||
if (prop.type !== "ObjectProperty") | ||
return notSupported(prop); | ||
let key; | ||
if ((0, import_types.isIdentifier)(prop.key) && !prop.computed) { | ||
key = prop.key.name; | ||
} else { | ||
key = resolveExpression(prop.key, prop); | ||
} | ||
obj[key] = resolveExpression(prop.value, prop); | ||
} | ||
return obj; | ||
} | ||
function resolveTemplateLiteral(node2) { | ||
return node2.quasis.reduce((prev, curr, idx) => { | ||
if (node2.expressions[idx]) { | ||
return prev + curr.value.cooked + resolveExpression(node2.expressions[idx], node2); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
function getSource(node2) { | ||
return code.slice(node2.start, node2.end); | ||
} | ||
function notSupported(node2) { | ||
throw new Error(`not supported ${node2.type}: ${getSource(node2)}`); | ||
} | ||
} | ||
function transformJsxToString(code, { | ||
debug, | ||
plugins, | ||
id = "" | ||
}) { | ||
const s = new import_magic_string.default(code); | ||
if (id.endsWith(".tsx")) | ||
plugins.push("typescript"); | ||
const nodes = extractJsx(code, plugins); | ||
for (const [node, expr] of nodes) { | ||
let str; | ||
if (!debug) { | ||
str = transformJsx(code, node); | ||
} else { | ||
try { | ||
str = transformJsx(code, node); | ||
} catch (err) { | ||
str = `(() => { throw new Error(${escapeString(err.toString())}) })()`; | ||
} | ||
} | ||
s.overwrite(expr.start, expr.end, str); | ||
} | ||
return { | ||
code: s.toString(), | ||
get map() { | ||
return s.generateMap(); | ||
} | ||
}; | ||
} | ||
// src/core/options.ts | ||
function resolveOption(options) { | ||
return { | ||
include: options.include || [/\.[jt]sx$/], | ||
exclude: options.exclude || void 0, | ||
debug: options.debug ?? false, | ||
plugins: ["jsx"] | ||
}; | ||
} | ||
// src/index.ts | ||
var src_default = (0, import_unplugin.createUnplugin)((options = {}) => { | ||
const opt = resolveOption(options); | ||
const filter = (0, import_pluginutils.createFilter)(opt.include, opt.exclude); | ||
const name = "unplugin-jsx-string"; | ||
return { | ||
name, | ||
enforce: "pre", | ||
transformInclude(id) { | ||
return filter(id); | ||
}, | ||
transform(code, id) { | ||
try { | ||
return transformJsxToString(code, { | ||
...opt, | ||
id | ||
}); | ||
} catch (err) { | ||
this.error(`${name} ${err}`); | ||
} | ||
} | ||
}; | ||
}); | ||
// src/esbuild.ts | ||
var esbuild_default = src_default.esbuild; | ||
exports.default = module.exports; |
import * as unplugin from 'unplugin'; | ||
import { Options } from './core/options.js'; | ||
import { a as Options } from './options-D9JXHjEn.js'; | ||
import '@babel/parser'; | ||
@@ -10,4 +10,4 @@ import '@rollup/pluginutils'; | ||
} | ||
declare const _default: unplugin.UnpluginInstance<Options, boolean>; | ||
declare const _default: unplugin.UnpluginInstance<Options | undefined, false>; | ||
export { _default as default }; |
@@ -1,432 +0,7 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
import { | ||
index_default | ||
} from "./chunk-VHWXMNG4.js"; | ||
import "./chunk-RYSW25F3.js"; | ||
export { | ||
index_default as default | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
default: () => src_default | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var import_unplugin = require("unplugin"); | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
// src/core/convert.ts | ||
var import_parser = require("@babel/parser"); | ||
var import_estree_walker = require("estree-walker"); | ||
var import_entities = require("entities"); | ||
var import_magic_string = __toESM(require("magic-string")); | ||
var import_types = require("@babel/types"); | ||
// src/core/utils.ts | ||
var import_jsesc = __toESM(require("jsesc")); | ||
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g; | ||
function kebabCase(str) { | ||
return str.replaceAll(KEBAB_REGEX, (match) => { | ||
return `-${match.toLowerCase()}`; | ||
}); | ||
} | ||
var styleToString = (styles) => Object.entries(styles).map(([key, value]) => `${kebabCase(key)}:${value}`).join(";"); | ||
var RAW_RE = /__RAW_(.*?)_RAW/g; | ||
var escapeString = (str) => { | ||
const text = (0, import_jsesc.default)(str, { | ||
quotes: "backtick", | ||
wrap: true, | ||
es6: true | ||
}); | ||
return text.replaceAll(RAW_RE, "${$1}"); | ||
}; | ||
var isPrimitive = (val) => { | ||
if (typeof val === "object") | ||
return val === null; | ||
return typeof val !== "function"; | ||
}; | ||
var isPlainObject = (obj) => { | ||
return Object.prototype.toString.call(obj) === "[object Object]"; | ||
}; | ||
// src/core/convert.ts | ||
function extractJsx(code, plugins) { | ||
const ast = (0, import_parser.parse)(code, { | ||
sourceType: "module", | ||
plugins | ||
}); | ||
const nodes = []; | ||
(0, import_estree_walker.walk)(ast.program, { | ||
enter(node) { | ||
let arg; | ||
if ((0, import_types.isCallExpression)(node) && (0, import_types.isIdentifier)(node.callee, { name: "jsxToString" }) && (0, import_types.isJSX)(arg = node.arguments[0])) | ||
nodes.push([arg, node]); | ||
} | ||
}); | ||
return nodes; | ||
} | ||
function transformJsx(code, node) { | ||
return escapeString(toStringJsx(node)); | ||
function toStringJsx(node2) { | ||
return toStringExpression(resolveJsx(node2)); | ||
} | ||
function toStringExpression(expr) { | ||
if (expr instanceof RegExp) { | ||
return expr.toString(); | ||
} else if (typeof expr === "object") { | ||
return JSON.stringify(expr); | ||
} | ||
return String(expr); | ||
} | ||
function toStringJsxChildren(nodes) { | ||
return nodes.map((child) => toStringJsx(child)).join(""); | ||
} | ||
function toStringJsxText(node2) { | ||
const texts = node2.value.split("\n"); | ||
return texts.map((text, idx) => idx > 0 ? text.trim() : text).filter((line) => { | ||
if (line.trim().length === 0) | ||
return false; | ||
return true; | ||
}).join(" "); | ||
} | ||
function toStringJsxElement(node2) { | ||
if (node2.openingElement.selfClosing) { | ||
return toStringOpeningElement(node2.openingElement); | ||
} else { | ||
const children = toStringJsxChildren(node2.children); | ||
return `${toStringOpeningElement( | ||
node2.openingElement | ||
)}${children}</${toStringJsxName(node2.closingElement.name)}>`; | ||
} | ||
function toStringOpeningElement(node3) { | ||
let str = `<${toStringJsxName(node3.name)}`; | ||
const props = node3.attributes.map((attr) => { | ||
if (attr.type === "JSXAttribute") { | ||
return toStringJsxAttribute(attr); | ||
} else { | ||
return notSupported(node3); | ||
} | ||
}).filter((x) => x !== void 0); | ||
if (props.length > 0) { | ||
str += ` ${props.join(" ")}`; | ||
} | ||
str += node3.selfClosing ? "/>" : ">"; | ||
return str; | ||
} | ||
} | ||
function toStringJsxAttribute(node2) { | ||
let name = toStringJsxName(node2.name); | ||
if (name === "className") | ||
name = "class"; | ||
else if (name.startsWith("on")) | ||
name = name.toLowerCase(); | ||
let value; | ||
if (node2.value) { | ||
const rawValue = toStringJsxAttributeValue(node2.value, name); | ||
if (rawValue === null) { | ||
return void 0; | ||
} | ||
value = rawValue; | ||
} | ||
return `${name}${value !== void 0 ? `="${(0, import_entities.encode)(value)}"` : ""}`; | ||
} | ||
function toStringJsxAttributeValue(node2, key) { | ||
let value; | ||
if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isBooleanLiteral)(node2.expression)) { | ||
value = node2.expression.value ? void 0 : null; | ||
} else if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isFunction)(node2.expression)) { | ||
value = getSource(node2.expression.body); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
value = resolveJsx(node2); | ||
if (key === "style" && isPlainObject(value)) { | ||
value = styleToString(value); | ||
} else if (key === "class" && Array.isArray(value) && value.every((e) => isPrimitive(e))) | ||
value = value.join(" "); | ||
} else if ((0, import_types.isStringLiteral)(node2)) { | ||
value = node2.value; | ||
} | ||
if (value === void 0 || value === null) | ||
return value; | ||
return toStringExpression(value); | ||
} | ||
function toStringJsxName(node2) { | ||
if (node2.type === "JSXIdentifier") | ||
return node2.name; | ||
return notSupported(node2); | ||
} | ||
function resolveJsx(node2) { | ||
switch (node2.type) { | ||
case "JSXElement": | ||
return toStringJsxElement(node2); | ||
case "JSXFragment": | ||
return toStringJsxChildren(node2.children); | ||
case "JSXText": | ||
return toStringJsxText(node2); | ||
case "JSXEmptyExpression": | ||
return node2.innerComments?.map((comment) => `<!--${comment.value}-->`).join("") ?? ""; | ||
case "JSXExpressionContainer": { | ||
return resolveExpression(node2.expression); | ||
} | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveExpression(node2, parent) { | ||
if ((0, import_types.isLiteral)(node2)) { | ||
return resolveLiteral(node2); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
return resolveJsx(node2); | ||
} | ||
switch (node2.type) { | ||
case "ArrayExpression": | ||
return resolveArrayExpression(node2); | ||
case "ObjectExpression": | ||
return resolveObjectExpression(node2); | ||
case "BinaryExpression": | ||
case "LogicalExpression": | ||
return resolveBinary(node2); | ||
case "UnaryExpression": | ||
return resolveUnaryExpression(node2); | ||
case "ConditionalExpression": | ||
return resolveExpression(node2.test, node2) ? resolveExpression(node2.consequent, node2) : resolveExpression(node2.alternate, node2); | ||
case "SequenceExpression": { | ||
const expressions = node2.expressions.map( | ||
(expr) => resolveExpression(expr, node2) | ||
); | ||
return expressions.at(-1); | ||
} | ||
case "ParenthesizedExpression": | ||
case "TSNonNullExpression": | ||
case "TSAsExpression": | ||
case "TSTypeAssertion": | ||
case "TSInstantiationExpression": | ||
return resolveExpression(node2.expression, node2); | ||
case "CallExpression": | ||
return resolveCallExpression(node2, !parent); | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveCallExpression(node2, isTopLevel) { | ||
if (isTopLevel && node2.callee.type === "Identifier" && node2.callee.name === "jsxRaw") { | ||
return `__RAW_${getSource(node2.arguments[0])}_RAW`; | ||
} | ||
return notSupported(node2); | ||
} | ||
function resolveBinary(node2) { | ||
const left = resolveExpression(node2.left, node2); | ||
const right = resolveExpression(node2.right, node2); | ||
switch (node2.operator) { | ||
case "+": | ||
return left + right; | ||
case "-": | ||
return left - right; | ||
case "*": | ||
return left * right; | ||
case "/": | ||
return left / right; | ||
case "&&": | ||
return left && right; | ||
case "||": | ||
return left || right; | ||
case "??": | ||
return left ?? right; | ||
case "==": | ||
return left == right; | ||
case "!=": | ||
return left != right; | ||
case "===": | ||
return left === right; | ||
case "!==": | ||
return left !== right; | ||
case ">": | ||
return left > right; | ||
case ">=": | ||
return left >= right; | ||
case "<": | ||
return left < right; | ||
case "<=": | ||
return left <= right; | ||
case "%": | ||
return left % right; | ||
case "**": | ||
return left ** right; | ||
case "&": | ||
return left & right; | ||
case "|": | ||
return left | right; | ||
case "^": | ||
return left ^ right; | ||
case "<<": | ||
return left << right; | ||
case ">>": | ||
return left >> right; | ||
case ">>>": | ||
return left >>> right; | ||
case "in": | ||
return left in right; | ||
case "instanceof": | ||
return left instanceof right; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveUnaryExpression(node2) { | ||
const value = resolveExpression(node2.argument, node2); | ||
switch (node2.operator) { | ||
case "!": | ||
return !value; | ||
case "+": | ||
return +value; | ||
case "-": | ||
return -value; | ||
case "typeof": | ||
return typeof value; | ||
case "void": | ||
return void 0; | ||
case "~": | ||
return ~value; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveLiteral(node2) { | ||
switch (node2.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node2); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node2.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node2.pattern, node2.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node2.value; | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveArrayExpression(node2) { | ||
const items = []; | ||
for (const [i, element] of node2.elements.entries()) { | ||
if (element) | ||
items[i] = resolveExpression(element, node2); | ||
} | ||
return items; | ||
} | ||
function resolveObjectExpression(node2) { | ||
const obj = {}; | ||
for (const prop of node2.properties) { | ||
if (prop.type !== "ObjectProperty") | ||
return notSupported(prop); | ||
let key; | ||
if ((0, import_types.isIdentifier)(prop.key) && !prop.computed) { | ||
key = prop.key.name; | ||
} else { | ||
key = resolveExpression(prop.key, prop); | ||
} | ||
obj[key] = resolveExpression(prop.value, prop); | ||
} | ||
return obj; | ||
} | ||
function resolveTemplateLiteral(node2) { | ||
return node2.quasis.reduce((prev, curr, idx) => { | ||
if (node2.expressions[idx]) { | ||
return prev + curr.value.cooked + resolveExpression(node2.expressions[idx], node2); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
function getSource(node2) { | ||
return code.slice(node2.start, node2.end); | ||
} | ||
function notSupported(node2) { | ||
throw new Error(`not supported ${node2.type}: ${getSource(node2)}`); | ||
} | ||
} | ||
function transformJsxToString(code, { | ||
debug, | ||
plugins, | ||
id = "" | ||
}) { | ||
const s = new import_magic_string.default(code); | ||
if (id.endsWith(".tsx")) | ||
plugins.push("typescript"); | ||
const nodes = extractJsx(code, plugins); | ||
for (const [node, expr] of nodes) { | ||
let str; | ||
if (!debug) { | ||
str = transformJsx(code, node); | ||
} else { | ||
try { | ||
str = transformJsx(code, node); | ||
} catch (err) { | ||
str = `(() => { throw new Error(${escapeString(err.toString())}) })()`; | ||
} | ||
} | ||
s.overwrite(expr.start, expr.end, str); | ||
} | ||
return { | ||
code: s.toString(), | ||
get map() { | ||
return s.generateMap(); | ||
} | ||
}; | ||
} | ||
// src/core/options.ts | ||
function resolveOption(options) { | ||
return { | ||
include: options.include || [/\.[jt]sx$/], | ||
exclude: options.exclude || void 0, | ||
debug: options.debug ?? false, | ||
plugins: ["jsx"] | ||
}; | ||
} | ||
// src/index.ts | ||
var src_default = (0, import_unplugin.createUnplugin)((options = {}) => { | ||
const opt = resolveOption(options); | ||
const filter = (0, import_pluginutils.createFilter)(opt.include, opt.exclude); | ||
const name = "unplugin-jsx-string"; | ||
return { | ||
name, | ||
enforce: "pre", | ||
transformInclude(id) { | ||
return filter(id); | ||
}, | ||
transform(code, id) { | ||
try { | ||
return transformJsxToString(code, { | ||
...opt, | ||
id | ||
}); | ||
} catch (err) { | ||
this.error(`${name} ${err}`); | ||
} | ||
} | ||
}; | ||
}); |
import * as rollup from 'rollup'; | ||
import { Options } from './core/options.js'; | ||
import { a as Options } from './options-D9JXHjEn.js'; | ||
import '@babel/parser'; | ||
import '@rollup/pluginutils'; | ||
declare const _default: (options: Options) => rollup.Plugin | rollup.Plugin[]; | ||
declare const _default: (options?: Options | undefined) => rollup.Plugin<any>; | ||
export { _default as default }; |
@@ -1,438 +0,10 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
import { | ||
index_default | ||
} from "./chunk-VHWXMNG4.js"; | ||
import "./chunk-RYSW25F3.js"; | ||
// src/rollup.ts | ||
var rollup_exports = {}; | ||
__export(rollup_exports, { | ||
default: () => rollup_default | ||
}); | ||
module.exports = __toCommonJS(rollup_exports); | ||
// src/index.ts | ||
var import_unplugin = require("unplugin"); | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
// src/core/convert.ts | ||
var import_parser = require("@babel/parser"); | ||
var import_estree_walker = require("estree-walker"); | ||
var import_entities = require("entities"); | ||
var import_magic_string = __toESM(require("magic-string")); | ||
var import_types = require("@babel/types"); | ||
// src/core/utils.ts | ||
var import_jsesc = __toESM(require("jsesc")); | ||
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g; | ||
function kebabCase(str) { | ||
return str.replaceAll(KEBAB_REGEX, (match) => { | ||
return `-${match.toLowerCase()}`; | ||
}); | ||
} | ||
var styleToString = (styles) => Object.entries(styles).map(([key, value]) => `${kebabCase(key)}:${value}`).join(";"); | ||
var RAW_RE = /__RAW_(.*?)_RAW/g; | ||
var escapeString = (str) => { | ||
const text = (0, import_jsesc.default)(str, { | ||
quotes: "backtick", | ||
wrap: true, | ||
es6: true | ||
}); | ||
return text.replaceAll(RAW_RE, "${$1}"); | ||
var rollup_default = index_default.rollup; | ||
export { | ||
rollup_default as default | ||
}; | ||
var isPrimitive = (val) => { | ||
if (typeof val === "object") | ||
return val === null; | ||
return typeof val !== "function"; | ||
}; | ||
var isPlainObject = (obj) => { | ||
return Object.prototype.toString.call(obj) === "[object Object]"; | ||
}; | ||
// src/core/convert.ts | ||
function extractJsx(code, plugins) { | ||
const ast = (0, import_parser.parse)(code, { | ||
sourceType: "module", | ||
plugins | ||
}); | ||
const nodes = []; | ||
(0, import_estree_walker.walk)(ast.program, { | ||
enter(node) { | ||
let arg; | ||
if ((0, import_types.isCallExpression)(node) && (0, import_types.isIdentifier)(node.callee, { name: "jsxToString" }) && (0, import_types.isJSX)(arg = node.arguments[0])) | ||
nodes.push([arg, node]); | ||
} | ||
}); | ||
return nodes; | ||
} | ||
function transformJsx(code, node) { | ||
return escapeString(toStringJsx(node)); | ||
function toStringJsx(node2) { | ||
return toStringExpression(resolveJsx(node2)); | ||
} | ||
function toStringExpression(expr) { | ||
if (expr instanceof RegExp) { | ||
return expr.toString(); | ||
} else if (typeof expr === "object") { | ||
return JSON.stringify(expr); | ||
} | ||
return String(expr); | ||
} | ||
function toStringJsxChildren(nodes) { | ||
return nodes.map((child) => toStringJsx(child)).join(""); | ||
} | ||
function toStringJsxText(node2) { | ||
const texts = node2.value.split("\n"); | ||
return texts.map((text, idx) => idx > 0 ? text.trim() : text).filter((line) => { | ||
if (line.trim().length === 0) | ||
return false; | ||
return true; | ||
}).join(" "); | ||
} | ||
function toStringJsxElement(node2) { | ||
if (node2.openingElement.selfClosing) { | ||
return toStringOpeningElement(node2.openingElement); | ||
} else { | ||
const children = toStringJsxChildren(node2.children); | ||
return `${toStringOpeningElement( | ||
node2.openingElement | ||
)}${children}</${toStringJsxName(node2.closingElement.name)}>`; | ||
} | ||
function toStringOpeningElement(node3) { | ||
let str = `<${toStringJsxName(node3.name)}`; | ||
const props = node3.attributes.map((attr) => { | ||
if (attr.type === "JSXAttribute") { | ||
return toStringJsxAttribute(attr); | ||
} else { | ||
return notSupported(node3); | ||
} | ||
}).filter((x) => x !== void 0); | ||
if (props.length > 0) { | ||
str += ` ${props.join(" ")}`; | ||
} | ||
str += node3.selfClosing ? "/>" : ">"; | ||
return str; | ||
} | ||
} | ||
function toStringJsxAttribute(node2) { | ||
let name = toStringJsxName(node2.name); | ||
if (name === "className") | ||
name = "class"; | ||
else if (name.startsWith("on")) | ||
name = name.toLowerCase(); | ||
let value; | ||
if (node2.value) { | ||
const rawValue = toStringJsxAttributeValue(node2.value, name); | ||
if (rawValue === null) { | ||
return void 0; | ||
} | ||
value = rawValue; | ||
} | ||
return `${name}${value !== void 0 ? `="${(0, import_entities.encode)(value)}"` : ""}`; | ||
} | ||
function toStringJsxAttributeValue(node2, key) { | ||
let value; | ||
if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isBooleanLiteral)(node2.expression)) { | ||
value = node2.expression.value ? void 0 : null; | ||
} else if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isFunction)(node2.expression)) { | ||
value = getSource(node2.expression.body); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
value = resolveJsx(node2); | ||
if (key === "style" && isPlainObject(value)) { | ||
value = styleToString(value); | ||
} else if (key === "class" && Array.isArray(value) && value.every((e) => isPrimitive(e))) | ||
value = value.join(" "); | ||
} else if ((0, import_types.isStringLiteral)(node2)) { | ||
value = node2.value; | ||
} | ||
if (value === void 0 || value === null) | ||
return value; | ||
return toStringExpression(value); | ||
} | ||
function toStringJsxName(node2) { | ||
if (node2.type === "JSXIdentifier") | ||
return node2.name; | ||
return notSupported(node2); | ||
} | ||
function resolveJsx(node2) { | ||
switch (node2.type) { | ||
case "JSXElement": | ||
return toStringJsxElement(node2); | ||
case "JSXFragment": | ||
return toStringJsxChildren(node2.children); | ||
case "JSXText": | ||
return toStringJsxText(node2); | ||
case "JSXEmptyExpression": | ||
return node2.innerComments?.map((comment) => `<!--${comment.value}-->`).join("") ?? ""; | ||
case "JSXExpressionContainer": { | ||
return resolveExpression(node2.expression); | ||
} | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveExpression(node2, parent) { | ||
if ((0, import_types.isLiteral)(node2)) { | ||
return resolveLiteral(node2); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
return resolveJsx(node2); | ||
} | ||
switch (node2.type) { | ||
case "ArrayExpression": | ||
return resolveArrayExpression(node2); | ||
case "ObjectExpression": | ||
return resolveObjectExpression(node2); | ||
case "BinaryExpression": | ||
case "LogicalExpression": | ||
return resolveBinary(node2); | ||
case "UnaryExpression": | ||
return resolveUnaryExpression(node2); | ||
case "ConditionalExpression": | ||
return resolveExpression(node2.test, node2) ? resolveExpression(node2.consequent, node2) : resolveExpression(node2.alternate, node2); | ||
case "SequenceExpression": { | ||
const expressions = node2.expressions.map( | ||
(expr) => resolveExpression(expr, node2) | ||
); | ||
return expressions.at(-1); | ||
} | ||
case "ParenthesizedExpression": | ||
case "TSNonNullExpression": | ||
case "TSAsExpression": | ||
case "TSTypeAssertion": | ||
case "TSInstantiationExpression": | ||
return resolveExpression(node2.expression, node2); | ||
case "CallExpression": | ||
return resolveCallExpression(node2, !parent); | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveCallExpression(node2, isTopLevel) { | ||
if (isTopLevel && node2.callee.type === "Identifier" && node2.callee.name === "jsxRaw") { | ||
return `__RAW_${getSource(node2.arguments[0])}_RAW`; | ||
} | ||
return notSupported(node2); | ||
} | ||
function resolveBinary(node2) { | ||
const left = resolveExpression(node2.left, node2); | ||
const right = resolveExpression(node2.right, node2); | ||
switch (node2.operator) { | ||
case "+": | ||
return left + right; | ||
case "-": | ||
return left - right; | ||
case "*": | ||
return left * right; | ||
case "/": | ||
return left / right; | ||
case "&&": | ||
return left && right; | ||
case "||": | ||
return left || right; | ||
case "??": | ||
return left ?? right; | ||
case "==": | ||
return left == right; | ||
case "!=": | ||
return left != right; | ||
case "===": | ||
return left === right; | ||
case "!==": | ||
return left !== right; | ||
case ">": | ||
return left > right; | ||
case ">=": | ||
return left >= right; | ||
case "<": | ||
return left < right; | ||
case "<=": | ||
return left <= right; | ||
case "%": | ||
return left % right; | ||
case "**": | ||
return left ** right; | ||
case "&": | ||
return left & right; | ||
case "|": | ||
return left | right; | ||
case "^": | ||
return left ^ right; | ||
case "<<": | ||
return left << right; | ||
case ">>": | ||
return left >> right; | ||
case ">>>": | ||
return left >>> right; | ||
case "in": | ||
return left in right; | ||
case "instanceof": | ||
return left instanceof right; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveUnaryExpression(node2) { | ||
const value = resolveExpression(node2.argument, node2); | ||
switch (node2.operator) { | ||
case "!": | ||
return !value; | ||
case "+": | ||
return +value; | ||
case "-": | ||
return -value; | ||
case "typeof": | ||
return typeof value; | ||
case "void": | ||
return void 0; | ||
case "~": | ||
return ~value; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveLiteral(node2) { | ||
switch (node2.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node2); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node2.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node2.pattern, node2.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node2.value; | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveArrayExpression(node2) { | ||
const items = []; | ||
for (const [i, element] of node2.elements.entries()) { | ||
if (element) | ||
items[i] = resolveExpression(element, node2); | ||
} | ||
return items; | ||
} | ||
function resolveObjectExpression(node2) { | ||
const obj = {}; | ||
for (const prop of node2.properties) { | ||
if (prop.type !== "ObjectProperty") | ||
return notSupported(prop); | ||
let key; | ||
if ((0, import_types.isIdentifier)(prop.key) && !prop.computed) { | ||
key = prop.key.name; | ||
} else { | ||
key = resolveExpression(prop.key, prop); | ||
} | ||
obj[key] = resolveExpression(prop.value, prop); | ||
} | ||
return obj; | ||
} | ||
function resolveTemplateLiteral(node2) { | ||
return node2.quasis.reduce((prev, curr, idx) => { | ||
if (node2.expressions[idx]) { | ||
return prev + curr.value.cooked + resolveExpression(node2.expressions[idx], node2); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
function getSource(node2) { | ||
return code.slice(node2.start, node2.end); | ||
} | ||
function notSupported(node2) { | ||
throw new Error(`not supported ${node2.type}: ${getSource(node2)}`); | ||
} | ||
} | ||
function transformJsxToString(code, { | ||
debug, | ||
plugins, | ||
id = "" | ||
}) { | ||
const s = new import_magic_string.default(code); | ||
if (id.endsWith(".tsx")) | ||
plugins.push("typescript"); | ||
const nodes = extractJsx(code, plugins); | ||
for (const [node, expr] of nodes) { | ||
let str; | ||
if (!debug) { | ||
str = transformJsx(code, node); | ||
} else { | ||
try { | ||
str = transformJsx(code, node); | ||
} catch (err) { | ||
str = `(() => { throw new Error(${escapeString(err.toString())}) })()`; | ||
} | ||
} | ||
s.overwrite(expr.start, expr.end, str); | ||
} | ||
return { | ||
code: s.toString(), | ||
get map() { | ||
return s.generateMap(); | ||
} | ||
}; | ||
} | ||
// src/core/options.ts | ||
function resolveOption(options) { | ||
return { | ||
include: options.include || [/\.[jt]sx$/], | ||
exclude: options.exclude || void 0, | ||
debug: options.debug ?? false, | ||
plugins: ["jsx"] | ||
}; | ||
} | ||
// src/index.ts | ||
var src_default = (0, import_unplugin.createUnplugin)((options = {}) => { | ||
const opt = resolveOption(options); | ||
const filter = (0, import_pluginutils.createFilter)(opt.include, opt.exclude); | ||
const name = "unplugin-jsx-string"; | ||
return { | ||
name, | ||
enforce: "pre", | ||
transformInclude(id) { | ||
return filter(id); | ||
}, | ||
transform(code, id) { | ||
try { | ||
return transformJsxToString(code, { | ||
...opt, | ||
id | ||
}); | ||
} catch (err) { | ||
this.error(`${name} ${err}`); | ||
} | ||
} | ||
}; | ||
}); | ||
// src/rollup.ts | ||
var rollup_default = src_default.rollup; | ||
exports.default = module.exports; |
import * as vite from 'vite'; | ||
import { Options } from './core/options.js'; | ||
import { a as Options } from './options-D9JXHjEn.js'; | ||
import '@babel/parser'; | ||
import '@rollup/pluginutils'; | ||
declare const _default: (options: Options) => vite.Plugin | vite.Plugin[]; | ||
declare const _default: (options?: Options | undefined) => vite.Plugin<any>; | ||
export { _default as default }; |
442
dist/vite.js
@@ -1,438 +0,10 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
import { | ||
index_default | ||
} from "./chunk-VHWXMNG4.js"; | ||
import "./chunk-RYSW25F3.js"; | ||
// src/vite.ts | ||
var vite_exports = {}; | ||
__export(vite_exports, { | ||
default: () => vite_default | ||
}); | ||
module.exports = __toCommonJS(vite_exports); | ||
// src/index.ts | ||
var import_unplugin = require("unplugin"); | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
// src/core/convert.ts | ||
var import_parser = require("@babel/parser"); | ||
var import_estree_walker = require("estree-walker"); | ||
var import_entities = require("entities"); | ||
var import_magic_string = __toESM(require("magic-string")); | ||
var import_types = require("@babel/types"); | ||
// src/core/utils.ts | ||
var import_jsesc = __toESM(require("jsesc")); | ||
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g; | ||
function kebabCase(str) { | ||
return str.replaceAll(KEBAB_REGEX, (match) => { | ||
return `-${match.toLowerCase()}`; | ||
}); | ||
} | ||
var styleToString = (styles) => Object.entries(styles).map(([key, value]) => `${kebabCase(key)}:${value}`).join(";"); | ||
var RAW_RE = /__RAW_(.*?)_RAW/g; | ||
var escapeString = (str) => { | ||
const text = (0, import_jsesc.default)(str, { | ||
quotes: "backtick", | ||
wrap: true, | ||
es6: true | ||
}); | ||
return text.replaceAll(RAW_RE, "${$1}"); | ||
var vite_default = index_default.vite; | ||
export { | ||
vite_default as default | ||
}; | ||
var isPrimitive = (val) => { | ||
if (typeof val === "object") | ||
return val === null; | ||
return typeof val !== "function"; | ||
}; | ||
var isPlainObject = (obj) => { | ||
return Object.prototype.toString.call(obj) === "[object Object]"; | ||
}; | ||
// src/core/convert.ts | ||
function extractJsx(code, plugins) { | ||
const ast = (0, import_parser.parse)(code, { | ||
sourceType: "module", | ||
plugins | ||
}); | ||
const nodes = []; | ||
(0, import_estree_walker.walk)(ast.program, { | ||
enter(node) { | ||
let arg; | ||
if ((0, import_types.isCallExpression)(node) && (0, import_types.isIdentifier)(node.callee, { name: "jsxToString" }) && (0, import_types.isJSX)(arg = node.arguments[0])) | ||
nodes.push([arg, node]); | ||
} | ||
}); | ||
return nodes; | ||
} | ||
function transformJsx(code, node) { | ||
return escapeString(toStringJsx(node)); | ||
function toStringJsx(node2) { | ||
return toStringExpression(resolveJsx(node2)); | ||
} | ||
function toStringExpression(expr) { | ||
if (expr instanceof RegExp) { | ||
return expr.toString(); | ||
} else if (typeof expr === "object") { | ||
return JSON.stringify(expr); | ||
} | ||
return String(expr); | ||
} | ||
function toStringJsxChildren(nodes) { | ||
return nodes.map((child) => toStringJsx(child)).join(""); | ||
} | ||
function toStringJsxText(node2) { | ||
const texts = node2.value.split("\n"); | ||
return texts.map((text, idx) => idx > 0 ? text.trim() : text).filter((line) => { | ||
if (line.trim().length === 0) | ||
return false; | ||
return true; | ||
}).join(" "); | ||
} | ||
function toStringJsxElement(node2) { | ||
if (node2.openingElement.selfClosing) { | ||
return toStringOpeningElement(node2.openingElement); | ||
} else { | ||
const children = toStringJsxChildren(node2.children); | ||
return `${toStringOpeningElement( | ||
node2.openingElement | ||
)}${children}</${toStringJsxName(node2.closingElement.name)}>`; | ||
} | ||
function toStringOpeningElement(node3) { | ||
let str = `<${toStringJsxName(node3.name)}`; | ||
const props = node3.attributes.map((attr) => { | ||
if (attr.type === "JSXAttribute") { | ||
return toStringJsxAttribute(attr); | ||
} else { | ||
return notSupported(node3); | ||
} | ||
}).filter((x) => x !== void 0); | ||
if (props.length > 0) { | ||
str += ` ${props.join(" ")}`; | ||
} | ||
str += node3.selfClosing ? "/>" : ">"; | ||
return str; | ||
} | ||
} | ||
function toStringJsxAttribute(node2) { | ||
let name = toStringJsxName(node2.name); | ||
if (name === "className") | ||
name = "class"; | ||
else if (name.startsWith("on")) | ||
name = name.toLowerCase(); | ||
let value; | ||
if (node2.value) { | ||
const rawValue = toStringJsxAttributeValue(node2.value, name); | ||
if (rawValue === null) { | ||
return void 0; | ||
} | ||
value = rawValue; | ||
} | ||
return `${name}${value !== void 0 ? `="${(0, import_entities.encode)(value)}"` : ""}`; | ||
} | ||
function toStringJsxAttributeValue(node2, key) { | ||
let value; | ||
if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isBooleanLiteral)(node2.expression)) { | ||
value = node2.expression.value ? void 0 : null; | ||
} else if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isFunction)(node2.expression)) { | ||
value = getSource(node2.expression.body); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
value = resolveJsx(node2); | ||
if (key === "style" && isPlainObject(value)) { | ||
value = styleToString(value); | ||
} else if (key === "class" && Array.isArray(value) && value.every((e) => isPrimitive(e))) | ||
value = value.join(" "); | ||
} else if ((0, import_types.isStringLiteral)(node2)) { | ||
value = node2.value; | ||
} | ||
if (value === void 0 || value === null) | ||
return value; | ||
return toStringExpression(value); | ||
} | ||
function toStringJsxName(node2) { | ||
if (node2.type === "JSXIdentifier") | ||
return node2.name; | ||
return notSupported(node2); | ||
} | ||
function resolveJsx(node2) { | ||
switch (node2.type) { | ||
case "JSXElement": | ||
return toStringJsxElement(node2); | ||
case "JSXFragment": | ||
return toStringJsxChildren(node2.children); | ||
case "JSXText": | ||
return toStringJsxText(node2); | ||
case "JSXEmptyExpression": | ||
return node2.innerComments?.map((comment) => `<!--${comment.value}-->`).join("") ?? ""; | ||
case "JSXExpressionContainer": { | ||
return resolveExpression(node2.expression); | ||
} | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveExpression(node2, parent) { | ||
if ((0, import_types.isLiteral)(node2)) { | ||
return resolveLiteral(node2); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
return resolveJsx(node2); | ||
} | ||
switch (node2.type) { | ||
case "ArrayExpression": | ||
return resolveArrayExpression(node2); | ||
case "ObjectExpression": | ||
return resolveObjectExpression(node2); | ||
case "BinaryExpression": | ||
case "LogicalExpression": | ||
return resolveBinary(node2); | ||
case "UnaryExpression": | ||
return resolveUnaryExpression(node2); | ||
case "ConditionalExpression": | ||
return resolveExpression(node2.test, node2) ? resolveExpression(node2.consequent, node2) : resolveExpression(node2.alternate, node2); | ||
case "SequenceExpression": { | ||
const expressions = node2.expressions.map( | ||
(expr) => resolveExpression(expr, node2) | ||
); | ||
return expressions.at(-1); | ||
} | ||
case "ParenthesizedExpression": | ||
case "TSNonNullExpression": | ||
case "TSAsExpression": | ||
case "TSTypeAssertion": | ||
case "TSInstantiationExpression": | ||
return resolveExpression(node2.expression, node2); | ||
case "CallExpression": | ||
return resolveCallExpression(node2, !parent); | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveCallExpression(node2, isTopLevel) { | ||
if (isTopLevel && node2.callee.type === "Identifier" && node2.callee.name === "jsxRaw") { | ||
return `__RAW_${getSource(node2.arguments[0])}_RAW`; | ||
} | ||
return notSupported(node2); | ||
} | ||
function resolveBinary(node2) { | ||
const left = resolveExpression(node2.left, node2); | ||
const right = resolveExpression(node2.right, node2); | ||
switch (node2.operator) { | ||
case "+": | ||
return left + right; | ||
case "-": | ||
return left - right; | ||
case "*": | ||
return left * right; | ||
case "/": | ||
return left / right; | ||
case "&&": | ||
return left && right; | ||
case "||": | ||
return left || right; | ||
case "??": | ||
return left ?? right; | ||
case "==": | ||
return left == right; | ||
case "!=": | ||
return left != right; | ||
case "===": | ||
return left === right; | ||
case "!==": | ||
return left !== right; | ||
case ">": | ||
return left > right; | ||
case ">=": | ||
return left >= right; | ||
case "<": | ||
return left < right; | ||
case "<=": | ||
return left <= right; | ||
case "%": | ||
return left % right; | ||
case "**": | ||
return left ** right; | ||
case "&": | ||
return left & right; | ||
case "|": | ||
return left | right; | ||
case "^": | ||
return left ^ right; | ||
case "<<": | ||
return left << right; | ||
case ">>": | ||
return left >> right; | ||
case ">>>": | ||
return left >>> right; | ||
case "in": | ||
return left in right; | ||
case "instanceof": | ||
return left instanceof right; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveUnaryExpression(node2) { | ||
const value = resolveExpression(node2.argument, node2); | ||
switch (node2.operator) { | ||
case "!": | ||
return !value; | ||
case "+": | ||
return +value; | ||
case "-": | ||
return -value; | ||
case "typeof": | ||
return typeof value; | ||
case "void": | ||
return void 0; | ||
case "~": | ||
return ~value; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveLiteral(node2) { | ||
switch (node2.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node2); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node2.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node2.pattern, node2.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node2.value; | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveArrayExpression(node2) { | ||
const items = []; | ||
for (const [i, element] of node2.elements.entries()) { | ||
if (element) | ||
items[i] = resolveExpression(element, node2); | ||
} | ||
return items; | ||
} | ||
function resolveObjectExpression(node2) { | ||
const obj = {}; | ||
for (const prop of node2.properties) { | ||
if (prop.type !== "ObjectProperty") | ||
return notSupported(prop); | ||
let key; | ||
if ((0, import_types.isIdentifier)(prop.key) && !prop.computed) { | ||
key = prop.key.name; | ||
} else { | ||
key = resolveExpression(prop.key, prop); | ||
} | ||
obj[key] = resolveExpression(prop.value, prop); | ||
} | ||
return obj; | ||
} | ||
function resolveTemplateLiteral(node2) { | ||
return node2.quasis.reduce((prev, curr, idx) => { | ||
if (node2.expressions[idx]) { | ||
return prev + curr.value.cooked + resolveExpression(node2.expressions[idx], node2); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
function getSource(node2) { | ||
return code.slice(node2.start, node2.end); | ||
} | ||
function notSupported(node2) { | ||
throw new Error(`not supported ${node2.type}: ${getSource(node2)}`); | ||
} | ||
} | ||
function transformJsxToString(code, { | ||
debug, | ||
plugins, | ||
id = "" | ||
}) { | ||
const s = new import_magic_string.default(code); | ||
if (id.endsWith(".tsx")) | ||
plugins.push("typescript"); | ||
const nodes = extractJsx(code, plugins); | ||
for (const [node, expr] of nodes) { | ||
let str; | ||
if (!debug) { | ||
str = transformJsx(code, node); | ||
} else { | ||
try { | ||
str = transformJsx(code, node); | ||
} catch (err) { | ||
str = `(() => { throw new Error(${escapeString(err.toString())}) })()`; | ||
} | ||
} | ||
s.overwrite(expr.start, expr.end, str); | ||
} | ||
return { | ||
code: s.toString(), | ||
get map() { | ||
return s.generateMap(); | ||
} | ||
}; | ||
} | ||
// src/core/options.ts | ||
function resolveOption(options) { | ||
return { | ||
include: options.include || [/\.[jt]sx$/], | ||
exclude: options.exclude || void 0, | ||
debug: options.debug ?? false, | ||
plugins: ["jsx"] | ||
}; | ||
} | ||
// src/index.ts | ||
var src_default = (0, import_unplugin.createUnplugin)((options = {}) => { | ||
const opt = resolveOption(options); | ||
const filter = (0, import_pluginutils.createFilter)(opt.include, opt.exclude); | ||
const name = "unplugin-jsx-string"; | ||
return { | ||
name, | ||
enforce: "pre", | ||
transformInclude(id) { | ||
return filter(id); | ||
}, | ||
transform(code, id) { | ||
try { | ||
return transformJsxToString(code, { | ||
...opt, | ||
id | ||
}); | ||
} catch (err) { | ||
this.error(`${name} ${err}`); | ||
} | ||
} | ||
}; | ||
}); | ||
// src/vite.ts | ||
var vite_default = src_default.vite; | ||
exports.default = module.exports; |
@@ -1,7 +0,7 @@ | ||
import { Options } from './core/options.js'; | ||
import { a as Options } from './options-D9JXHjEn.js'; | ||
import '@babel/parser'; | ||
import '@rollup/pluginutils'; | ||
declare const _default: (options: Options) => WebpackPluginInstance; | ||
declare const _default: (options?: Options | undefined) => WebpackPluginInstance; | ||
export { _default as default }; |
@@ -1,438 +0,10 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
import { | ||
index_default | ||
} from "./chunk-VHWXMNG4.js"; | ||
import "./chunk-RYSW25F3.js"; | ||
// src/webpack.ts | ||
var webpack_exports = {}; | ||
__export(webpack_exports, { | ||
default: () => webpack_default | ||
}); | ||
module.exports = __toCommonJS(webpack_exports); | ||
// src/index.ts | ||
var import_unplugin = require("unplugin"); | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
// src/core/convert.ts | ||
var import_parser = require("@babel/parser"); | ||
var import_estree_walker = require("estree-walker"); | ||
var import_entities = require("entities"); | ||
var import_magic_string = __toESM(require("magic-string")); | ||
var import_types = require("@babel/types"); | ||
// src/core/utils.ts | ||
var import_jsesc = __toESM(require("jsesc")); | ||
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g; | ||
function kebabCase(str) { | ||
return str.replaceAll(KEBAB_REGEX, (match) => { | ||
return `-${match.toLowerCase()}`; | ||
}); | ||
} | ||
var styleToString = (styles) => Object.entries(styles).map(([key, value]) => `${kebabCase(key)}:${value}`).join(";"); | ||
var RAW_RE = /__RAW_(.*?)_RAW/g; | ||
var escapeString = (str) => { | ||
const text = (0, import_jsesc.default)(str, { | ||
quotes: "backtick", | ||
wrap: true, | ||
es6: true | ||
}); | ||
return text.replaceAll(RAW_RE, "${$1}"); | ||
var webpack_default = index_default.webpack; | ||
export { | ||
webpack_default as default | ||
}; | ||
var isPrimitive = (val) => { | ||
if (typeof val === "object") | ||
return val === null; | ||
return typeof val !== "function"; | ||
}; | ||
var isPlainObject = (obj) => { | ||
return Object.prototype.toString.call(obj) === "[object Object]"; | ||
}; | ||
// src/core/convert.ts | ||
function extractJsx(code, plugins) { | ||
const ast = (0, import_parser.parse)(code, { | ||
sourceType: "module", | ||
plugins | ||
}); | ||
const nodes = []; | ||
(0, import_estree_walker.walk)(ast.program, { | ||
enter(node) { | ||
let arg; | ||
if ((0, import_types.isCallExpression)(node) && (0, import_types.isIdentifier)(node.callee, { name: "jsxToString" }) && (0, import_types.isJSX)(arg = node.arguments[0])) | ||
nodes.push([arg, node]); | ||
} | ||
}); | ||
return nodes; | ||
} | ||
function transformJsx(code, node) { | ||
return escapeString(toStringJsx(node)); | ||
function toStringJsx(node2) { | ||
return toStringExpression(resolveJsx(node2)); | ||
} | ||
function toStringExpression(expr) { | ||
if (expr instanceof RegExp) { | ||
return expr.toString(); | ||
} else if (typeof expr === "object") { | ||
return JSON.stringify(expr); | ||
} | ||
return String(expr); | ||
} | ||
function toStringJsxChildren(nodes) { | ||
return nodes.map((child) => toStringJsx(child)).join(""); | ||
} | ||
function toStringJsxText(node2) { | ||
const texts = node2.value.split("\n"); | ||
return texts.map((text, idx) => idx > 0 ? text.trim() : text).filter((line) => { | ||
if (line.trim().length === 0) | ||
return false; | ||
return true; | ||
}).join(" "); | ||
} | ||
function toStringJsxElement(node2) { | ||
if (node2.openingElement.selfClosing) { | ||
return toStringOpeningElement(node2.openingElement); | ||
} else { | ||
const children = toStringJsxChildren(node2.children); | ||
return `${toStringOpeningElement( | ||
node2.openingElement | ||
)}${children}</${toStringJsxName(node2.closingElement.name)}>`; | ||
} | ||
function toStringOpeningElement(node3) { | ||
let str = `<${toStringJsxName(node3.name)}`; | ||
const props = node3.attributes.map((attr) => { | ||
if (attr.type === "JSXAttribute") { | ||
return toStringJsxAttribute(attr); | ||
} else { | ||
return notSupported(node3); | ||
} | ||
}).filter((x) => x !== void 0); | ||
if (props.length > 0) { | ||
str += ` ${props.join(" ")}`; | ||
} | ||
str += node3.selfClosing ? "/>" : ">"; | ||
return str; | ||
} | ||
} | ||
function toStringJsxAttribute(node2) { | ||
let name = toStringJsxName(node2.name); | ||
if (name === "className") | ||
name = "class"; | ||
else if (name.startsWith("on")) | ||
name = name.toLowerCase(); | ||
let value; | ||
if (node2.value) { | ||
const rawValue = toStringJsxAttributeValue(node2.value, name); | ||
if (rawValue === null) { | ||
return void 0; | ||
} | ||
value = rawValue; | ||
} | ||
return `${name}${value !== void 0 ? `="${(0, import_entities.encode)(value)}"` : ""}`; | ||
} | ||
function toStringJsxAttributeValue(node2, key) { | ||
let value; | ||
if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isBooleanLiteral)(node2.expression)) { | ||
value = node2.expression.value ? void 0 : null; | ||
} else if ((0, import_types.isJSXExpressionContainer)(node2) && (0, import_types.isFunction)(node2.expression)) { | ||
value = getSource(node2.expression.body); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
value = resolveJsx(node2); | ||
if (key === "style" && isPlainObject(value)) { | ||
value = styleToString(value); | ||
} else if (key === "class" && Array.isArray(value) && value.every((e) => isPrimitive(e))) | ||
value = value.join(" "); | ||
} else if ((0, import_types.isStringLiteral)(node2)) { | ||
value = node2.value; | ||
} | ||
if (value === void 0 || value === null) | ||
return value; | ||
return toStringExpression(value); | ||
} | ||
function toStringJsxName(node2) { | ||
if (node2.type === "JSXIdentifier") | ||
return node2.name; | ||
return notSupported(node2); | ||
} | ||
function resolveJsx(node2) { | ||
switch (node2.type) { | ||
case "JSXElement": | ||
return toStringJsxElement(node2); | ||
case "JSXFragment": | ||
return toStringJsxChildren(node2.children); | ||
case "JSXText": | ||
return toStringJsxText(node2); | ||
case "JSXEmptyExpression": | ||
return node2.innerComments?.map((comment) => `<!--${comment.value}-->`).join("") ?? ""; | ||
case "JSXExpressionContainer": { | ||
return resolveExpression(node2.expression); | ||
} | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveExpression(node2, parent) { | ||
if ((0, import_types.isLiteral)(node2)) { | ||
return resolveLiteral(node2); | ||
} else if ((0, import_types.isJSX)(node2)) { | ||
return resolveJsx(node2); | ||
} | ||
switch (node2.type) { | ||
case "ArrayExpression": | ||
return resolveArrayExpression(node2); | ||
case "ObjectExpression": | ||
return resolveObjectExpression(node2); | ||
case "BinaryExpression": | ||
case "LogicalExpression": | ||
return resolveBinary(node2); | ||
case "UnaryExpression": | ||
return resolveUnaryExpression(node2); | ||
case "ConditionalExpression": | ||
return resolveExpression(node2.test, node2) ? resolveExpression(node2.consequent, node2) : resolveExpression(node2.alternate, node2); | ||
case "SequenceExpression": { | ||
const expressions = node2.expressions.map( | ||
(expr) => resolveExpression(expr, node2) | ||
); | ||
return expressions.at(-1); | ||
} | ||
case "ParenthesizedExpression": | ||
case "TSNonNullExpression": | ||
case "TSAsExpression": | ||
case "TSTypeAssertion": | ||
case "TSInstantiationExpression": | ||
return resolveExpression(node2.expression, node2); | ||
case "CallExpression": | ||
return resolveCallExpression(node2, !parent); | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveCallExpression(node2, isTopLevel) { | ||
if (isTopLevel && node2.callee.type === "Identifier" && node2.callee.name === "jsxRaw") { | ||
return `__RAW_${getSource(node2.arguments[0])}_RAW`; | ||
} | ||
return notSupported(node2); | ||
} | ||
function resolveBinary(node2) { | ||
const left = resolveExpression(node2.left, node2); | ||
const right = resolveExpression(node2.right, node2); | ||
switch (node2.operator) { | ||
case "+": | ||
return left + right; | ||
case "-": | ||
return left - right; | ||
case "*": | ||
return left * right; | ||
case "/": | ||
return left / right; | ||
case "&&": | ||
return left && right; | ||
case "||": | ||
return left || right; | ||
case "??": | ||
return left ?? right; | ||
case "==": | ||
return left == right; | ||
case "!=": | ||
return left != right; | ||
case "===": | ||
return left === right; | ||
case "!==": | ||
return left !== right; | ||
case ">": | ||
return left > right; | ||
case ">=": | ||
return left >= right; | ||
case "<": | ||
return left < right; | ||
case "<=": | ||
return left <= right; | ||
case "%": | ||
return left % right; | ||
case "**": | ||
return left ** right; | ||
case "&": | ||
return left & right; | ||
case "|": | ||
return left | right; | ||
case "^": | ||
return left ^ right; | ||
case "<<": | ||
return left << right; | ||
case ">>": | ||
return left >> right; | ||
case ">>>": | ||
return left >>> right; | ||
case "in": | ||
return left in right; | ||
case "instanceof": | ||
return left instanceof right; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveUnaryExpression(node2) { | ||
const value = resolveExpression(node2.argument, node2); | ||
switch (node2.operator) { | ||
case "!": | ||
return !value; | ||
case "+": | ||
return +value; | ||
case "-": | ||
return -value; | ||
case "typeof": | ||
return typeof value; | ||
case "void": | ||
return void 0; | ||
case "~": | ||
return ~value; | ||
default: | ||
notSupported(node2); | ||
} | ||
} | ||
function resolveLiteral(node2) { | ||
switch (node2.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node2); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node2.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node2.pattern, node2.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node2.value; | ||
default: | ||
return notSupported(node2); | ||
} | ||
} | ||
function resolveArrayExpression(node2) { | ||
const items = []; | ||
for (const [i, element] of node2.elements.entries()) { | ||
if (element) | ||
items[i] = resolveExpression(element, node2); | ||
} | ||
return items; | ||
} | ||
function resolveObjectExpression(node2) { | ||
const obj = {}; | ||
for (const prop of node2.properties) { | ||
if (prop.type !== "ObjectProperty") | ||
return notSupported(prop); | ||
let key; | ||
if ((0, import_types.isIdentifier)(prop.key) && !prop.computed) { | ||
key = prop.key.name; | ||
} else { | ||
key = resolveExpression(prop.key, prop); | ||
} | ||
obj[key] = resolveExpression(prop.value, prop); | ||
} | ||
return obj; | ||
} | ||
function resolveTemplateLiteral(node2) { | ||
return node2.quasis.reduce((prev, curr, idx) => { | ||
if (node2.expressions[idx]) { | ||
return prev + curr.value.cooked + resolveExpression(node2.expressions[idx], node2); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
function getSource(node2) { | ||
return code.slice(node2.start, node2.end); | ||
} | ||
function notSupported(node2) { | ||
throw new Error(`not supported ${node2.type}: ${getSource(node2)}`); | ||
} | ||
} | ||
function transformJsxToString(code, { | ||
debug, | ||
plugins, | ||
id = "" | ||
}) { | ||
const s = new import_magic_string.default(code); | ||
if (id.endsWith(".tsx")) | ||
plugins.push("typescript"); | ||
const nodes = extractJsx(code, plugins); | ||
for (const [node, expr] of nodes) { | ||
let str; | ||
if (!debug) { | ||
str = transformJsx(code, node); | ||
} else { | ||
try { | ||
str = transformJsx(code, node); | ||
} catch (err) { | ||
str = `(() => { throw new Error(${escapeString(err.toString())}) })()`; | ||
} | ||
} | ||
s.overwrite(expr.start, expr.end, str); | ||
} | ||
return { | ||
code: s.toString(), | ||
get map() { | ||
return s.generateMap(); | ||
} | ||
}; | ||
} | ||
// src/core/options.ts | ||
function resolveOption(options) { | ||
return { | ||
include: options.include || [/\.[jt]sx$/], | ||
exclude: options.exclude || void 0, | ||
debug: options.debug ?? false, | ||
plugins: ["jsx"] | ||
}; | ||
} | ||
// src/index.ts | ||
var src_default = (0, import_unplugin.createUnplugin)((options = {}) => { | ||
const opt = resolveOption(options); | ||
const filter = (0, import_pluginutils.createFilter)(opt.include, opt.exclude); | ||
const name = "unplugin-jsx-string"; | ||
return { | ||
name, | ||
enforce: "pre", | ||
transformInclude(id) { | ||
return filter(id); | ||
}, | ||
transform(code, id) { | ||
try { | ||
return transformJsxToString(code, { | ||
...opt, | ||
id | ||
}); | ||
} catch (err) { | ||
this.error(`${name} ${err}`); | ||
} | ||
} | ||
}; | ||
}); | ||
// src/webpack.ts | ||
var webpack_default = src_default.webpack; | ||
exports.default = module.exports; |
110
package.json
{ | ||
"name": "unplugin-jsx-string", | ||
"version": "0.7.1", | ||
"packageManager": "pnpm@8.6.11", | ||
"version": "0.8.0", | ||
"description": "Converts JSX to HTML strings at compile time.", | ||
"type": "module", | ||
"keywords": [ | ||
@@ -16,9 +16,9 @@ "unplugin", | ||
"license": "MIT", | ||
"homepage": "https://github.com/sxzz/unplugin-jsx-string#readme", | ||
"homepage": "https://github.com/unplugin/unplugin-jsx-string#readme", | ||
"bugs": { | ||
"url": "https://github.com/sxzz/unplugin-jsx-string/issues" | ||
"url": "https://github.com/unplugin/unplugin-jsx-string/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sxzz/unplugin-jsx-string.git" | ||
"url": "git+https://github.com/unplugin/unplugin-jsx-string.git" | ||
}, | ||
@@ -30,52 +30,28 @@ "author": "三咲智子 <sxzz@sxzz.moe>", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": { | ||
"require": "./dist/index.d.ts", | ||
"import": "./dist/index.d.mts" | ||
}, | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
}, | ||
"./vite": { | ||
"types": { | ||
"require": "./dist/vite.d.ts", | ||
"import": "./dist/vite.d.mts" | ||
}, | ||
"require": "./dist/vite.js", | ||
"import": "./dist/vite.mjs" | ||
"require": "./dist/vite.cjs", | ||
"import": "./dist/vite.js" | ||
}, | ||
"./webpack": { | ||
"types": { | ||
"require": "./dist/webpack.d.ts", | ||
"import": "./dist/webpack.d.mts" | ||
}, | ||
"require": "./dist/webpack.js", | ||
"import": "./dist/webpack.mjs" | ||
"require": "./dist/webpack.cjs", | ||
"import": "./dist/webpack.js" | ||
}, | ||
"./rollup": { | ||
"types": { | ||
"require": "./dist/rollup.d.ts", | ||
"import": "./dist/rollup.d.mts" | ||
}, | ||
"require": "./dist/rollup.js", | ||
"import": "./dist/rollup.mjs" | ||
"require": "./dist/rollup.cjs", | ||
"import": "./dist/rollup.js" | ||
}, | ||
"./esbuild": { | ||
"types": { | ||
"require": "./dist/esbuild.d.ts", | ||
"import": "./dist/esbuild.d.mts" | ||
}, | ||
"require": "./dist/esbuild.js", | ||
"import": "./dist/esbuild.mjs" | ||
"require": "./dist/esbuild.cjs", | ||
"import": "./dist/esbuild.js" | ||
}, | ||
"./api": { | ||
"types": { | ||
"require": "./dist/api.d.ts", | ||
"import": "./dist/api.d.mts" | ||
}, | ||
"require": "./dist/api.js", | ||
"import": "./dist/api.mjs" | ||
"require": "./dist/api.cjs", | ||
"import": "./dist/api.js" | ||
}, | ||
@@ -96,32 +72,30 @@ "./*": "./*" | ||
"dependencies": { | ||
"@babel/parser": "^7.22.7", | ||
"@babel/types": "^7.22.5", | ||
"@rollup/pluginutils": "^5.0.2", | ||
"entities": "^4.5.0", | ||
"@babel/parser": "^7.26.5", | ||
"@babel/types": "^7.26.5", | ||
"@rollup/pluginutils": "^5.1.4", | ||
"entities": "^6.0.0", | ||
"estree-walker": "^3.0.3", | ||
"jsesc": "^3.0.2", | ||
"magic-string": "^0.30.2", | ||
"unplugin": "^1.4.0" | ||
"jsesc": "^3.1.0", | ||
"magic-string": "^0.30.17", | ||
"unplugin": "^2.1.2" | ||
}, | ||
"devDependencies": { | ||
"@sxzz/eslint-config": "^3.3.2", | ||
"@sxzz/prettier-config": "^1.0.4", | ||
"@types/benchmark": "^2.1.2", | ||
"@types/jsesc": "^3.0.1", | ||
"@types/node": "^20.4.5", | ||
"@types/react": "^18.2.18", | ||
"@sxzz/eslint-config": "^4.6.0", | ||
"@sxzz/prettier-config": "^2.0.2", | ||
"@types/benchmark": "^2.1.5", | ||
"@types/jsesc": "^3.0.3", | ||
"@types/node": "^22.10.5", | ||
"@types/react": "^19.0.6", | ||
"benchmark": "^2.1.4", | ||
"bumpp": "^9.1.1", | ||
"eslint": "^8.46.0", | ||
"eslint-define-config": "^1.22.0", | ||
"fast-glob": "^3.3.1", | ||
"prettier": "^3.0.0", | ||
"tsup": "^7.1.0", | ||
"tsx": "^3.12.7", | ||
"typescript": "^5.1.6", | ||
"vite": "^4.4.8", | ||
"vitest": "^0.33.0" | ||
"bumpp": "^9.10.0", | ||
"eslint": "^9.18.0", | ||
"prettier": "^3.4.2", | ||
"tsup": "^8.3.5", | ||
"tsx": "^4.19.2", | ||
"typescript": "^5.7.3", | ||
"vite": "^6.0.7", | ||
"vitest": "^2.1.8" | ||
}, | ||
"engines": { | ||
"node": ">=16.14.0" | ||
"node": ">=18.12.0" | ||
}, | ||
@@ -132,8 +106,8 @@ "prettier": "@sxzz/prettier-config", | ||
"lint:fix": "pnpm run lint --fix", | ||
"build": "tsup && tsx scripts/postbuild.mts", | ||
"build": "tsup", | ||
"dev": "pnpm run -C playground dev", | ||
"test": "vitest", | ||
"release": "bumpp && pnpm publish", | ||
"benchmark": "node benchmark/index.mjs" | ||
"benchmark": "node benchmark/index.js" | ||
} | ||
} |
# unplugin-jsx-string [](https://npmjs.com/package/unplugin-jsx-string) | ||
[](https://github.com/sxzz/unplugin-jsx-string/actions/workflows/unit-test.yml) | ||
[](https://github.com/unplugin/unplugin-jsx-string/actions/workflows/unit-test.yml) | ||
@@ -5,0 +5,0 @@ Converts JSX to HTML strings at compile time. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15
Yes
38836
33
961
1
+ Addedentities@6.0.0(transitive)
+ Addedunplugin@2.2.0(transitive)
- Removedentities@4.5.0(transitive)
- Removedunplugin@1.16.1(transitive)
Updated@babel/parser@^7.26.5
Updated@babel/types@^7.26.5
Updated@rollup/pluginutils@^5.1.4
Updatedentities@^6.0.0
Updatedjsesc@^3.1.0
Updatedmagic-string@^0.30.17
Updatedunplugin@^2.1.2