From 9872fdb6e7350fb56deeb6acbbf07fe468699d8f Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 6 Dec 2021 15:10:27 +0000 Subject: [PATCH] Split tpyes/globals 2 --- src/build/emitter.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/build/emitter.ts b/src/build/emitter.ts index 12e129831..f326bb144 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -144,6 +144,8 @@ export function emitWebIdl( (i) => !!i.global ); + const globals: string[] = [] + const allNonCallbackInterfaces = getElements( webidl.interfaces, "interface" @@ -225,7 +227,9 @@ export function emitWebIdl( getParentsWithConstant ); - return iterator ? emitES6DomIterators() : emit(); + const body = iterator ? emitES6DomIterators() : emit(); + const footer = "\n" + globals.join("\n"); + return body + footer; function getTagNameToElementNameMap() { const htmlResult: Record = {}; @@ -1134,7 +1138,14 @@ export function emitWebIdl( if (i.deprecated) { printer.printLine(`/** @deprecated */`); } - printer.printLine(`${prefix}var ${i.name}: {`); + + if (prefix !== "") { + globals.push(`${prefix} var ${i.name}: ${i.name}Constructor`); + + printer.printLine(`${prefix} interface ${i.name}Constructor {`); + } else { + printer.printLine(`var ${i.name}: {`); + } printer.increaseIndent(); // TODO: To be more accurate, this should be `readonly prototype`