Skip to content

Commit

Permalink
Merge pull request #272 from TroyAlford/task/better-bun-setup
Browse files Browse the repository at this point in the history
task/better bun setup
  • Loading branch information
TroyAlford authored Sep 16, 2024
2 parents 9313a7c + ecccad7 commit 2edd35e
Show file tree
Hide file tree
Showing 9 changed files with 2,756 additions and 187 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bun 1.1.27
25 changes: 25 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"tasks": [
{
"command": "asdf install && bun install",
"group": {
"isDefault": true,
"kind": "build"
},
"isBackground": true,
"label": "Setup Project",
"presentation": {
"echo": false,
"focus": false,
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [],
"runOptions": {
"runOn": "folderOpen"
},
"type": "shell"
}
],
"version": "2.0.0"
}
Binary file modified bun.lockb
Binary file not shown.
5 changes: 4 additions & 1 deletion bunfig.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[install.lockfile]
print = "yarn"

[test]
preload = ["./test/happydom.ts"]
preload = ["./test/happydom.ts"]
226 changes: 66 additions & 160 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,162 +1,68 @@
{
"author": "Troy Alford",
"bugs": "https://github.com/TroyAlford/react-jsx-parser/issues",
"description": "A React component which can parse JSX and output rendered React Components",
"files": [
"dist/"
],
"keywords": [
"react",
"jsx"
],
"license": "MIT",
"main": "dist/react-jsx-parser.min.js",
"types": "dist/index.d.ts",
"name": "react-jsx-parser",
"repository": "TroyAlford/react-jsx-parser",
"version": "2.0.0",
"dependencies": {
"acorn": "^8.12.1",
"acorn-jsx": "^5.3.2",
"browserslist": "^4.23.1",
"core-js": "^3.37.1"
},
"devDependencies": {
"@happy-dom/global-registrator": "^14.12.3",
"@types/acorn": "^4.0.6",
"@types/bun": "^1.1.6",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"basis": "TroyAlford/basis",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-react": "^7.34.3",
"mkdirp": "^3.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"source-map-explorer": "^2.5.3",
"typescript": "^5.5.3"
},
"optionalDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0"
},
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
},
"scripts": {
"build": "bun build:types && bun build:code",
"build:code": "bun build --target=browser --outfile=./dist/react-jsx-parser.min.js ./source/index.ts",
"build:types": "bun run tsc -p ./tsconfig.json -d --emitDeclarationOnly",
"develop": "NODE_ENV=production concurrently -n build,ts,demo -c green,cyan,yellow \"bun build:code --watch\" \"bun build:types --watch\" \"bun serve\"",
"lint": "bun eslint --ext .js,.ts,.tsx source/",
"postinstall": "npx patch-package",
"prebuild": "mkdirp ./dist && rm -rf ./dist/*",
"serve": "bun serve --port=8080 --open",
"sourcemap": "bun build && source-map-explorer ./dist/es5/react-jsx-parser.min.js",
"test": "bun lint && bun test"
},
"contributors": [
{
"name": "akucheruk-vareger",
"url": "https://github.com/akucheruk-vareger"
},
{
"name": "Alexander Sakhaev",
"url": "https://github.com/alsakhaev"
},
{
"name": "Anatolii Kucheruk",
"url": "https://github.com/anatollix"
},
{
"name": "Arunoda Susiripala",
"url": "https://github.com/arunoda"
},
{
"name": "chunminglu",
"url": "https://github.com/chunminglu"
},
{
"name": "Daniel Lee",
"url": "https://github.com/dan-lee"
},
{
"name": "Jean-Louis Dinh",
"url": "https://github.com/jldinh"
},
{
"name": "Jeff Wells",
"url": "https://github.com/jeffmwells"
},
{
"name": "Joe Duncan",
"url": "https://github.com/joeduncan"
},
{
"name": "Jonathan R Wickens",
"url": "https://github.com/jwickens"
},
{
"name": "Kevin Ho",
"url": "https://github.com/hokevins"
},
{
"name": "Kim Jeker",
"url": "https://github.com/kije"
},
{
"name": "Knut Sveidqvist",
"url": "https://github.com/knsv"
},
{
"name": "Levi Schuck",
"url": "https://github.com/LeviSchuck"
},
{
"name": "Lukas Klein",
"url": "https://github.com/lukasklein"
},
{
"name": "Mathieu Jouhet",
"url": "https://github.com/daformat"
},
{
"name": "Matthias Geisler",
"url": "https://github.com/BitPogo"
},
{
"name": "Moritz Schwörer",
"url": "https://github.com/mosch"
},
{
"name": "Pranab Gupta",
"url": "https://github.com/Pranab16"
},
{
"name": "Sandro",
"url": "https://github.com/saendu"
},
{
"name": "Tim Kindberg",
"url": "https://github.com/timkindberg"
},
{
"name": "Tim Suchanek",
"url": "https://github.com/timsuchanek"
},
{
"name": "Tomasz Kopacki",
"url": "https://github.com/tk-o"
},
{
"name": "tschicke-brown",
"url": "https://github.com/tschicke-brown"
}
]
"author": "Troy Alford",
"bugs": "https://github.com/TroyAlford/react-jsx-parser/issues",
"contributors": [
"See https://github.com/TroyAlford/react-jsx-parser/graphs/contributors"
],
"dependencies": {
"acorn": "^8.12.1",
"acorn-jsx": "^5.3.2"
},
"description": "A React component which can parse JSX and output rendered React Components",
"devDependencies": {
"@happy-dom/global-registrator": "^14.12.3",
"@types/acorn": "^4.0.6",
"@types/bun": "^1.1.6",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"basis": "TroyAlford/basis",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-react": "^7.34.3",
"mkdirp": "^3.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.3"
},
"engines": {
"bun": "^1.1.27"
},
"files": [
"dist/"
],
"keywords": [
"react",
"jsx"
],
"license": "MIT",
"main": "dist/react-jsx-parser.min.js",
"name": "react-jsx-parser",
"optionalDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0"
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
},
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
},
"repository": "TroyAlford/react-jsx-parser",
"scripts": {
"build": "bun build:types && bun build:code",
"build:code": "bun build --target=browser --outfile=./dist/react-jsx-parser.min.js ./source/index.ts",
"build:types": "bun run tsc -p ./tsconfig.json -d --emitDeclarationOnly",
"develop": "NODE_ENV=production concurrently -n build,ts,demo -c green,cyan,yellow \"bun build:code --watch\" \"bun build:types --watch\" \"bun serve\"",
"lint": "bun eslint --ext .js,.ts,.tsx source/",
"prebuild": "mkdirp ./dist && rm -rf ./dist/*",
"serve": "bun serve --port=8080 --open",
"test": "bun lint && bun test"
},
"types": "dist/index.d.ts",
"version": "2.0.0-beta.0"
}
24 changes: 12 additions & 12 deletions patches/acorn-jsx+5.3.2.patch → patches/[email protected]
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
diff --git a/node_modules/acorn-jsx/index.js b/node_modules/acorn-jsx/index.js
index 004e080..aed0558 100644
--- a/node_modules/acorn-jsx/index.js
+++ b/node_modules/acorn-jsx/index.js
diff --git a/index.js b/index.js
index 004e0809024006335916314d605090629b73575f..210963e8c8befc89f8bfb6565bb77e9e16e6e0da 100644
--- a/index.js
+++ b/index.js
@@ -75,7 +75,8 @@ module.exports = function(options) {
return function(Parser) {
return plugin({
allowNamespaces: options.allowNamespaces !== false,
- allowNamespacedObjects: !!options.allowNamespacedObjects
+ allowNamespacedObjects: !!options.allowNamespacedObjects,
+ autoCloseVoidElements: !!options.autoCloseVoidElements,
+ autoCloseVoidElements: !!options.autoCloseVoidElements
}, Parser);
};
};
@@ -356,6 +357,13 @@ function plugin(options, Parser) {
node.attributes.push(this.jsx_parseAttribute());
node.selfClosing = this.eat(tt.slash);
this.expect(tok.jsxTagEnd);
+ const VOID_ELEMENTS = [
+ 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
+ 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'
+ ]
+ if (options.autoCloseVoidElements && nodeName && VOID_ELEMENTS.includes(nodeName.name)) {
+ node.selfClosing = true;
+ }
+ const VOID_ELEMENTS = [
+ 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
+ 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'
+ ];
+ if (options.autoCloseVoidElements && nodeName && VOID_ELEMENTS.includes(nodeName.name)) {
+ node.selfClosing = true;
+ }
return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
}

26 changes: 13 additions & 13 deletions source/components/JsxParser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ describe('JsxParser Component', () => {
test('allows no-whitespace-element named custom components to take whitespace', () => {
// eslint-disable-next-line react/prop-types
const tr = ({ children }) => <div className="tr">{children}</div>
const { node } = render(<JsxParser components={{ tr }} jsx={'<tr> <a href="/url">Text</a> </tr>'} />)
const { node } = render(<JsxParser components={{ tr }} jsx='<tr> <a href="/url">Text</a> </tr>' />)
expect(node.childNodes[0].nodeName).toEqual('DIV')
expect(node.childNodes[0].childNodes).toHaveLength(3)

Expand Down Expand Up @@ -694,7 +694,7 @@ describe('JsxParser Component', () => {
expect(instance.ParsedChildren[0].props.shouldBeFalse).toBe(false)
})
test('parses bound object values', () => {
const { instance } = render(<JsxParser components={{ Custom }} jsx={'<Custom obj={{ foo: "bar", bar: "foo" }} />'} />)
const { instance } = render(<JsxParser components={{ Custom }} jsx='<Custom obj={{ foo: "bar", bar: "foo" }} />' />)

expect(instance.ParsedChildren).toHaveLength(1)
expect(instance.ParsedChildren[0].props.obj).toEqual({ foo: 'bar', bar: 'foo' })
Expand Down Expand Up @@ -849,15 +849,15 @@ describe('JsxParser Component', () => {
expect(instance.ParsedChildren[0].props.testProp).toEqual(false)
})
test('can evaluate inequality comparison', () => {
const { instance } = render(<JsxParser jsx={'<span testProp={1 != "1"} />'} />)
const { instance } = render(<JsxParser jsx='<span testProp={1 != "1"} />' />)
expect(instance.ParsedChildren[0].props.testProp).toEqual(false)
})
test('can evaluate strict equality comparison', () => {
const { instance } = render(<JsxParser jsx="<span testProp={1 === 1} />" />)
expect(instance.ParsedChildren[0].props.testProp).toEqual(true)
})
test('can evaluate strict inequality comparison', () => {
const { instance } = render(<JsxParser jsx={'<span testProp={1 !== "1"} />'} />)
const { instance } = render(<JsxParser jsx='<span testProp={1 !== "1"} />' />)
expect(instance.ParsedChildren[0].props.testProp).toEqual(true)
})
test('can execute unary plus operations', () => {
Expand All @@ -871,27 +871,27 @@ describe('JsxParser Component', () => {
expect(instance.ParsedChildren[0].props.testProp).toEqual(-60)
})
test('can execute unary NOT operations', () => {
const { node, instance } = render(<JsxParser jsx={'<span testProp={!60}>{ !false && "Yes" }</span>'} />)
const { node, instance } = render(<JsxParser jsx='<span testProp={!60}>{ !false && "Yes" }</span>' />)
expect(node.childNodes[0].textContent).toEqual('Yes')
expect(instance.ParsedChildren[0].props.testProp).toEqual(false)
})
test('can evaluate > operator', () => {
const { node, instance } = render(<JsxParser jsx={'<span testProp={1 > 2}>{1 > 2 || "Nope"}</span>'} />)
const { node, instance } = render(<JsxParser jsx='<span testProp={1 > 2}>{1 > 2 || "Nope"}</span>' />)
expect(node.childNodes[0].textContent).toEqual('Nope')
expect(instance.ParsedChildren[0].props.testProp).toEqual(false)
})
test('can evaluate >= operator', () => {
const { node, instance } = render(<JsxParser jsx={'<span testProp={1 >= 2}>{1 >= 2 || "Nope"}</span>'} />)
const { node, instance } = render(<JsxParser jsx='<span testProp={1 >= 2}>{1 >= 2 || "Nope"}</span>' />)
expect(node.childNodes[0].textContent).toEqual('Nope')
expect(instance.ParsedChildren[0].props.testProp).toEqual(false)
})
test('can evaluate < operator', () => {
const { node, instance } = render(<JsxParser jsx={'<span testProp={1 < 2}>{2 < 1 || "Nope"}</span>'} />)
const { node, instance } = render(<JsxParser jsx='<span testProp={1 < 2}>{2 < 1 || "Nope"}</span>' />)
expect(node.childNodes[0].textContent).toEqual('Nope')
expect(instance.ParsedChildren[0].props.testProp).toEqual(true)
})
test('can evaluate <= operator', () => {
const { node, instance } = render(<JsxParser jsx={'<span testProp={1 <= 2}>{2 <= 1 || "Nope"}</span>'} />)
const { node, instance } = render(<JsxParser jsx='<span testProp={1 <= 2}>{2 <= 1 || "Nope"}</span>' />)
expect(node.childNodes[0].textContent).toEqual('Nope')
expect(instance.ParsedChildren[0].props.testProp).toEqual(true)
})
Expand Down Expand Up @@ -1062,7 +1062,7 @@ describe('JsxParser Component', () => {
test('void-element named custom components to take children', () => {
// eslint-disable-next-line react/prop-types
const link = ({ to, children }) => (<a href={to}>{children}</a>)
const { node } = render(<JsxParser components={{ link }} jsx={'<link to="/url">Text</link>'} />)
const { node } = render(<JsxParser components={{ link }} jsx='<link to="/url">Text</link>' />)
expect(node.childNodes[0].nodeName).toEqual('A')
expect(node.childNodes[0].textContent).toEqual('Text')
})
Expand Down Expand Up @@ -1103,9 +1103,9 @@ describe('JsxParser Component', () => {
test.skip('throws on non-simple literal and global object instance methods', () => {
// Some of these would normally fail silently, set `onError` forces throw for assertion purposes
expect(() => render(<JsxParser jsx="{ window.scrollTo() }" onError={e => { throw e }} />)).toThrow()
expect(() => render(<JsxParser jsx={'{ (() => { window.location = "badsite" })() }'} onError={e => { throw e }} />)).toThrow()
expect(() => render(<JsxParser jsx={'{ document.querySelector("body") }'} onError={e => { throw e }} />)).toThrow()
expect(() => render(<JsxParser jsx={'{ document.createElement("script") }'} onError={e => { throw e }} />)).toThrow()
expect(() => render(<JsxParser jsx='{ (() => { window.location = "badsite" })() }' onError={e => { throw e }} />)).toThrow()
expect(() => render(<JsxParser jsx='{ document.querySelector("body") }' onError={e => { throw e }} />)).toThrow()
expect(() => render(<JsxParser jsx='{ document.createElement("script") }' onError={e => { throw e }} />)).toThrow()
expect(() => render(<JsxParser jsx="{ [1, 2, 3].filter(num => num === 2) }" />)).toThrow()
expect(() => render(<JsxParser jsx="{ [1, 2, 3].map(num => num * 2) }" />)).toThrow()
expect(() => render(<JsxParser jsx="{ [1, 2, 3].reduce((a, b) => a + b) }" />)).toThrow()
Expand Down
Loading

0 comments on commit 2edd35e

Please sign in to comment.