-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathrecheck.js
41 lines (36 loc) · 1.16 KB
/
recheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Lexer } from '../lib/marked.esm.js';
import { check } from 'recheck';
const { inline, block } = Lexer.rules;
function checkRegexp(obj, name) {
return Promise.all(Object.keys(obj).map(async(prop) => {
const item = obj[prop];
const itemName = `${name}.${prop}`;
let source = '';
let flags = '';
if (item instanceof RegExp) {
source = item.source;
flags = item.flags;
} else if (typeof item === 'string') {
source = item;
} else {
return checkRegexp(item, itemName);
}
const gfm = itemName.includes('.gfm.');
const pedantic = itemName.includes('.pedantic.');
const recheckObj = await check(source, flags);
if (recheckObj.status !== 'safe') {
console.log(`// ${itemName}: /${recheckObj.source}/${recheckObj.flags}`);
console.log(`// marked(${recheckObj.attack.pattern}, { pedantic: ${pedantic ? 'true' : 'false'}, gfm: ${gfm ? 'true' : 'false'} });`);
}
}));
}
console.log(`
import { marked } from '../lib/marked.esm.js';
const start = Date.now();
`);
await Promise.all([
checkRegexp(inline, 'inline'),
checkRegexp(block, 'block'),
]);
console.log(`
console.log(Date.now() - start);`);