Skip to content

Commit 559562a

Browse files
Support linting the spec (#193)
1 parent 31565ff commit 559562a

File tree

3 files changed

+121
-51
lines changed

3 files changed

+121
-51
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"description": "The Source Map specification",
66
"scripts": {
77
"prebuild-only": "npm run clean && mkdir out && cp -R img out",
8-
"build-only": "ecmarkup --verbose --load-biblio @tc39/ecma262-biblio spec.emu out/index.html",
9-
"build": "npm run build-only",
8+
"build-only": "npm run ecmarkup -- --verbose --load-biblio @tc39/ecma262-biblio spec.emu out/index.html",
9+
"build-loose": "npm run build-only",
10+
"build": "npm run build-only -- --lint-spec",
1011
"clean": "rm -rf out",
12+
"ecmarkup": "node ./scripts/ecmarkup.js",
1113
"format": "emu-format --write spec.emu",
1214
"test": "exit 0",
1315
"watch": "npm run build-only -- --watch"

scripts/ecmarkup.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
function wrapWarnFunction(originalWarn) {
2+
return (err) => {
3+
if (
4+
err.message.includes("Completion Record") ||
5+
err.message.includes("an abrupt completion")
6+
) {
7+
// Ignore errors about completion records
8+
return;
9+
}
10+
11+
let match;
12+
if (match = /^could not find definition for (\w+)$/.exec(err.message)) {
13+
switch (match[1]) {
14+
// This is correctly <dfn>ed as a reference from an external
15+
// specification. However, ecmarkup only allows "calling" AOs and not
16+
// <dfn>ed terms.
17+
case "module_decode":
18+
// Ecmarkup mistakenly detects HTTP in "an HTTP(S) scheme" as an AO
19+
// call.
20+
case "HTTP":
21+
return;
22+
}
23+
}
24+
25+
originalWarn(err);
26+
};
27+
}
28+
29+
Object.defineProperty(Object.prototype, "warn", {
30+
enumerable: false,
31+
configurable: true,
32+
get: () => undefined,
33+
set(value) {
34+
// Trying to detect this object:
35+
// https://github.com/tc39/ecmarkup/blob/734baa009be2bdbab29c14a9e52ed3da1e26caa3/src/cli.ts#L104
36+
if (
37+
Object.hasOwn(this, "multipage") &&
38+
Object.hasOwn(this, "outfile") &&
39+
Object.hasOwn(this, "extraBiblios") &&
40+
Object.hasOwn(this, "lintSpec")
41+
) {
42+
value = wrapWarnFunction(value);
43+
}
44+
Object.defineProperty(this, "warn", {
45+
enumerable: true,
46+
configurable: true,
47+
writable: true,
48+
value,
49+
});
50+
},
51+
});
52+
53+
require("ecmarkup/bin/ecmarkup.js");

0 commit comments

Comments
 (0)