Add Web IDL base types + Encoding Standard from their specs#405
Add Web IDL base types + Encoding Standard from their specs#405mhegazy merged 15 commits intomicrosoft:masterfrom
Conversation
| @@ -0,0 +1,23 @@ | |||
| dictionary TextDecoderOptions { | |||
There was a problem hiding this comment.
where is the idl file comming from?
There was a problem hiding this comment.
nevermind. found the link :)
src/fetcher.ts
Outdated
| } | ||
|
|
||
| async function fetchIDLs() { | ||
| const file = fs.readFileSync(`${__dirname}/../inputfiles/idlSources.json`, { encoding: "utf-8" }); |
There was a problem hiding this comment.
nit: i would use path.combine here.
There was a problem hiding this comment.
or consider using require to get it and avoid JSON.parse
| async function fetchIDL(source: IDLSource) { | ||
| const response = await fetch(source.url); | ||
| const dom = new JSDOM(await response.text()); | ||
| const elements = Array.from(dom.window.document.querySelectorAll("pre.idl:not(.extract),code.idl-code")); |
There was a problem hiding this comment.
totally random, and not related to this change; it would be super cool if in the future we can extract the description from the widl file and put it as a comment on the declaration..
src/widlprocess.ts
Outdated
| throw new Error("Unsupported IDL type structure"); | ||
| } | ||
|
|
||
| function createEmptyBrowserWebidl(): Browser.WebIdl { |
There was a problem hiding this comment.
we have this function already in index.ts, i would move it helpers and reuse it.
src/widlprocess.ts
Outdated
| export function convert(text: string) { | ||
| const rootTypes = webidl2.parse(text); | ||
| const partialInterfaces: Browser.Interface[] = []; | ||
| const browser = createEmptyBrowserWebidl(); |
There was a problem hiding this comment.
nit, browser might not be the best name, consider changing it to webidl
mhegazy
left a comment
There was a problem hiding this comment.
A few comments, and the build seems to be failing on a few errors as well.
src/widlprocess.ts
Outdated
| return { | ||
| name: operation.name!, | ||
| signature: [{ | ||
| ...convertIdlType(operation.idlType!), |
There was a problem hiding this comment.
should we throe if idlType is not defined?
0cb7327 to
afcc4a1
Compare
src/test.ts
Outdated
| function compileGeneratedFile(file: string) { | ||
| try { | ||
| child_process.execSync(`node ${tscPath} --strict --lib es5 --noEmit ${path.join(outputFolder, file)}`); | ||
| child_process.execSync(`node ${tscPath} --strict --lib es5 --skipLibCheck --noEmit ${path.join(outputFolder, file)}`); |
There was a problem hiding this comment.
why? we want to make sure we are generating valid declaration file.. that is the whole point of the test.
There was a problem hiding this comment.
This breaks @types/jsdom which depends on DOM types. I think we are still testing the input library file, this just turns off checks for JavaScript types.
Edit: @types/jsdom only breaks when checking worker types, as it lacks DOM.
There was a problem hiding this comment.
Then Add ‘—types’ to exclude all @types packages.
There was a problem hiding this comment.
Good idea, but how can I pass empty string to --types? --types [], --types "", or --types "''" don't work.
There was a problem hiding this comment.
just --types..
--strict --lib es5 --types --noEmit
|
thanks! |
The new json type file tends to flatten typedefs, is it a requirement?