Skip to content

Commit 277f712

Browse files
committed
Docs: document E044 and E045
Also, make sure BEL, BS, and DEL show up on the web page for E045.
1 parent 341c68d commit 277f712

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

docs/errors/E044.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# E044: unexpected characters in number literal
2+
3+
```config-for-examples
4+
{
5+
"globals": {
6+
"pi": true
7+
}
8+
}
9+
```
10+
11+
Letters are allowed in number literals in certain situations, such as in
12+
`123n`, `1e6`, and `0xff`. It is an error to include other letters or letters in
13+
the wrong spot:
14+
15+
let gazillion = 10000000000000000000000000N;
16+
let pi = 3.14l;
17+
let tau = 2pi;
18+
19+
To fix this error, use the correct letter or remove the extraneous letter:
20+
21+
let gazillion = 10000000000000000000000000n;
22+
let pi = 3.14;
23+
24+
Alternatively, use the `*` operator to multiply a variable by a number:
25+
26+
let tau = 2*pi;

docs/errors/E045.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# E045: unexpected control character
2+
3+
JavaScript treats some Unicode control characters, such as newlines, tabs, and
4+
form feeds, as whitespace. Most other control characters are now allowed outside
5+
string literals and template literals:
6+
7+
 
8+
9+
To fix this error, delete the extra control characters, or put them inside a
10+
comment:
11+
12+
/*
13+
 
14+
*/

website/public/errors/index.ejs.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,33 @@
4747
text-decoration: none;
4848
}
4949

50-
.unicode-bom:before {
51-
content: "BOM";
50+
.unicode-bom:before,
51+
.unicode-bel:before,
52+
.unicode-bs:before,
53+
.unicode-del:before {
5254
background-color: #edbf66;
5355
border: 1px solid red;
5456
border-radius: 5px;
5557
padding: 1px 3px;
5658
}
59+
.unicode-bom:before {
60+
content: "BOM";
61+
}
62+
.unicode-bel:before {
63+
content: "BEL";
64+
}
65+
.unicode-bs:before {
66+
content: "BS";
67+
}
68+
.unicode-del:before {
69+
content: "DEL";
70+
}
5771

5872
@media (prefers-color-scheme: dark) {
59-
.unicode-bom:before {
73+
.unicode-bom:before,
74+
.unicode-bel:before,
75+
.unicode-bs:before,
76+
.unicode-del:before {
6077
background-color: #884444;
6178
}
6279
}

website/src/error-documentation.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ markdownParser.renderer.rules = {
7676
);
7777
}
7878

79+
codeHTML = wrapASCIIControlCharacters(codeHTML);
80+
7981
env.codeBlockIndex += 1;
8082
return `<figure><pre><code>${codeHTML}</code></pre></figure>`;
8183
},
@@ -306,6 +308,18 @@ export async function loadErrorDocumentationFilesAsync(rootPath) {
306308

307309
export class ProblemsError extends Error {}
308310

311+
function wrapASCIIControlCharacters(html) {
312+
let CONTROL_CHARACTER_TO_CSS_CLASS = {
313+
"\u0007": "unicode-bel",
314+
"\u0008": "unicode-bs",
315+
"\u007f": "unicode-del",
316+
};
317+
return html.replace(/[\u0007\u0008\u007f]/g, (controlCharacter) => {
318+
let cssClass = CONTROL_CHARACTER_TO_CSS_CLASS[controlCharacter];
319+
return `<span class='${cssClass}'>${controlCharacter}</span>`;
320+
});
321+
}
322+
309323
// quick-lint-js finds bugs in JavaScript programs.
310324
// Copyright (C) 2020 Matthew "strager" Glazar
311325
//

website/test/test-error-documentation.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ wasn't that neat?
172172
);
173173
});
174174

175+
it("html wraps weird control characters", () => {
176+
let doc = ErrorDocumentation.parseString(
177+
"file.md",
178+
"code:\n\n```\n" + "BEL:\u0007\n" + "BS:\u0008\n" + "DEL:\u007f\n" + "```"
179+
);
180+
let html = doc.toHTML();
181+
expect(html).toContain("BEL:<span class='unicode-bel'>\u0007</span>");
182+
expect(html).toContain("BS:<span class='unicode-bs'>\u0008</span>");
183+
expect(html).toContain("DEL:<span class='unicode-del'>\u007f</span>");
184+
});
185+
175186
it("many possibilities of html code has bom", () => {
176187
const possibilities = [
177188
"<mark>\u{feff}hello</mark>",

0 commit comments

Comments
 (0)