UNPKG

3.88 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12exports.lint = void 0;
13const collect_nodes_1 = require("./collect-nodes");
14const collect_grammar_diagnostics_1 = require("./collect-grammar-diagnostics");
15const collect_spelling_diagnostics_1 = require("./collect-spelling-diagnostics");
16const collect_algorithm_diagnostics_1 = require("./collect-algorithm-diagnostics");
17const collect_header_diagnostics_1 = require("./collect-header-diagnostics");
18const collect_tag_diagnostics_1 = require("./collect-tag-diagnostics");
19/*
20Currently this checks
21- grammarkdown's built-in sanity checks
22- the productions in the definition of each early error and SDO are defined in the main grammar
23- those productions do not include `[no LineTerminator here]` restrictions or `[+flag]` gating
24- the algorithm linting rules imported above
25- headers of abstract operations have consistent spacing
26- certain common spelling errors
27
28There's more to do:
29https://github.com/tc39/ecmarkup/issues/173
30*/
31function lint(report, sourceText, spec, document) {
32 return __awaiter(this, void 0, void 0, function* () {
33 collect_spelling_diagnostics_1.collectSpellingDiagnostics(report, sourceText, spec.imports);
34 collect_tag_diagnostics_1.collectTagDiagnostics(report, spec, document);
35 const collection = collect_nodes_1.collectNodes(report, sourceText, spec, document);
36 if (!collection.success) {
37 return;
38 }
39 const { mainGrammar, headers, sdos, earlyErrors, algorithms } = collection;
40 const { grammar, oneOffGrammars } = yield collect_grammar_diagnostics_1.collectGrammarDiagnostics(report, spec, sourceText, mainGrammar, sdos, earlyErrors);
41 collect_algorithm_diagnostics_1.collectAlgorithmDiagnostics(report, spec, sourceText, algorithms);
42 collect_header_diagnostics_1.collectHeaderDiagnostics(report, headers);
43 // Stash intermediate results for later use
44 // This isn't actually necessary for linting, but we might as well avoid redoing work later when we can.
45 yield grammar.emit(undefined, (file, source) => {
46 const name = +file.split('.')[0];
47 const node = mainGrammar[name].element;
48 if ('grammarkdownOut' in node) {
49 throw new Error('unexpectedly regenerating grammarkdown output for node ' + name);
50 }
51 // @ts-ignore we are intentionally adding a property here
52 node.grammarkdownOut = source;
53 });
54 for (const { grammarEle, grammar } of oneOffGrammars) {
55 yield grammar.emit(undefined, (file, source) => {
56 if ('grammarkdownOut' in grammarEle) {
57 throw new Error('unexpectedly regenerating grammarkdown output');
58 }
59 // @ts-ignore we are intentionally adding a property here
60 grammarEle.grammarkdownOut = source;
61 });
62 }
63 for (const pair of algorithms) {
64 if ('tree' in pair) {
65 // @ts-ignore we are intentionally adding a property here
66 pair.element.ecmarkdownTree = pair.tree;
67 }
68 }
69 });
70}
71exports.lint = lint;