Skip to content

Commit 8e69a25

Browse files
authored
perf(deps): remove html-entities dependency (#82)
1 parent 8cb0d2a commit 8e69a25

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

client/overlay/components/CompileErrorTrace.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
const ansiHTML = require('../../utils/ansi-html.js');
2-
const entities = require('html-entities');
32
const theme = require('../theme.js');
43
const utils = require('../utils.js');
54

65
ansiHTML.setColors(theme);
76

7+
/**
8+
* Escape text before passing it to `ansiHTML`, which injects HTML markup.
9+
* @param {string} value
10+
* @returns {string}
11+
*/
12+
function escapeHtml(value) {
13+
return value
14+
.replace(/&/g, '&')
15+
.replace(/</g, '&lt;')
16+
.replace(/>/g, '&gt;')
17+
.replace(/"/g, '&quot;')
18+
.replace(/'/g, '&#39;');
19+
}
20+
821
/**
922
* @typedef {Object} CompileErrorTraceProps
1023
* @property {string} errorMessage
@@ -32,15 +45,7 @@ function CompileErrorTrace(document, root, props) {
3245
}
3346

3447
const stackContainer = document.createElement('pre');
35-
stackContainer.innerHTML = entities.decode(
36-
ansiHTML(
37-
entities.encode(errorParts.join('\n'), {
38-
level: 'html5',
39-
mode: 'nonAscii',
40-
}),
41-
),
42-
{ level: 'html5' },
43-
);
48+
stackContainer.innerHTML = ansiHTML(escapeHtml(errorParts.join('\n')));
4449
stackContainer.style.fontFamily = [
4550
'"Operator Mono SSm"',
4651
'"Operator Mono"',

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
"typescript": "5.9.3"
5656
},
5757
"dependencies": {
58-
"error-stack-parser": "^2.1.4",
59-
"html-entities": "^2.6.0"
58+
"error-stack-parser": "^2.1.4"
6059
},
6160
"peerDependencies": {
6261
"react-refresh": ">=0.10.0 <1.0.0",

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)