Async import only once

This commit is contained in:
Christof Marti 2021-06-04 21:42:23 +02:00
parent ff9dd60caf
commit 63e5b8058a

View file

@ -59,6 +59,7 @@ export class ExtensionLinter {
private readmeQ = new Set<TextDocument>();
private timer: NodeJS.Timer | undefined;
private markdownIt: MarkdownItType.MarkdownIt | undefined;
private parse5: typeof import('parse5') | undefined;
constructor() {
this.disposables.push(
@ -202,8 +203,10 @@ export class ExtensionLinter {
let svgStart: Diagnostic;
for (const tnp of tokensAndPositions) {
if (tnp.token.type === 'text' && tnp.token.content) {
const parse5 = await import('parse5');
const parser = new parse5.SAXParser({ locationInfo: true });
if (!this.parse5) {
this.parse5 = await import('parse5');
}
const parser = new this.parse5.SAXParser({ locationInfo: true });
parser.on('startTag', (name, attrs, _selfClosing, location) => {
if (name === 'img') {
const src = attrs.find(a => a.name === 'src');