-
Notifications
You must be signed in to change notification settings - Fork 459
Run TypeScript scripts directly #2322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ed04a63
28a3736
68fd231
c5bf24d
bea54ae
f565c8f
988f6e6
9d5fb55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import * as Browser from "./types.js"; | ||
| import * as Browser from "./types.ts"; | ||
| import { | ||
| mapToArray, | ||
| distinct, | ||
|
|
@@ -10,15 +10,11 @@ import { | |
| baseTypeConversionMap, | ||
| assertUnique, | ||
| arrayBufferViewTypes, | ||
| } from "./helpers.js"; | ||
| import { collectLegacyNamespaceTypes } from "./legacy-namespace.js"; | ||
| } from "./helpers.ts"; | ||
| import { collectLegacyNamespaceTypes } from "./legacy-namespace.ts"; | ||
|
|
||
| /// Decide which members of a function to emit | ||
| enum EmitScope { | ||
| StaticOnly, | ||
| InstanceOnly, | ||
| All, | ||
| } | ||
| type EmitScope = "StaticOnly" | "InstanceOnly" | "All"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just use an as const object and the keyof typeof trick
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmmmmmmmmmmmmmmm..................... I kinda prefer this way as it's simpler and it's what we do in web APIs 🤔 |
||
|
|
||
| const tsKeywords = new Set(["default", "delete", "continue"]); | ||
| const extendConflictsBaseTypes: Record< | ||
|
|
@@ -38,9 +34,7 @@ const namespacesAsInterfaces = ["console"]; | |
| // Used to decide if a member should be emitted given its static property and | ||
| // the intended scope level. | ||
| function matchScope(scope: EmitScope, x: { static?: boolean }) { | ||
| return ( | ||
| scope === EmitScope.All || (scope === EmitScope.StaticOnly) === !!x.static | ||
| ); | ||
| return scope === "All" || (scope === "StaticOnly") === !!x.static; | ||
| } | ||
|
|
||
| /// Parameter cannot be named "default" in JavaScript/Typescript so we need to rename it. | ||
|
|
@@ -900,7 +894,7 @@ export function emitWebIdl( | |
| if ( | ||
| p.name === "name" && | ||
| i.name === "Window" && | ||
| emitScope === EmitScope.InstanceOnly && | ||
| emitScope === "InstanceOnly" && | ||
| prefix === "declare var " | ||
| ) { | ||
| printer.printLine("/** @deprecated */"); | ||
|
|
@@ -1114,7 +1108,7 @@ export function emitWebIdl( | |
| .sort(compareName) | ||
| .forEach((m) => emitMethod(prefix, m, conflictedMembers)); | ||
| } | ||
| if (i.anonymousMethods && emitScope === EmitScope.InstanceOnly) { | ||
| if (i.anonymousMethods && emitScope === "InstanceOnly") { | ||
| const stringifier = i.anonymousMethods.method.find((m) => m.stringifier); | ||
| if (stringifier) { | ||
| printer.printLine("toString(): string;"); | ||
|
|
@@ -1163,15 +1157,15 @@ export function emitWebIdl( | |
| ? "declare function " | ||
| : ""; | ||
| emitMethods(methodPrefix, emitScope, i, conflictedMembers); | ||
| if (emitScope === EmitScope.InstanceOnly) { | ||
| if (emitScope === "InstanceOnly") { | ||
| emitIteratorForEach(i); | ||
| } | ||
| } | ||
|
|
||
| /// Emit all members of every interfaces at the root level. | ||
| /// Called only once on the global polluter object | ||
| function emitAllMembers(i: Browser.Interface) { | ||
| emitMembers(/*prefix*/ "declare var ", EmitScope.InstanceOnly, i); | ||
| emitMembers(/*prefix*/ "declare var ", "InstanceOnly", i); | ||
|
|
||
| for (const relatedIName of iNameToIDependList[i.name]) { | ||
| const i = allInterfacesMap[relatedIName]; | ||
|
|
@@ -1275,7 +1269,7 @@ export function emitWebIdl( | |
| emitConstants(parent); | ||
| } | ||
| } | ||
| emitMembers(/*prefix*/ "", EmitScope.StaticOnly, i); | ||
| emitMembers(/*prefix*/ "", "StaticOnly", i); | ||
|
|
||
| printer.decreaseIndent(); | ||
| printer.printLine("};"); | ||
|
|
@@ -1493,10 +1487,10 @@ export function emitWebIdl( | |
| emitInterfaceDeclaration(i); | ||
| printer.increaseIndent(); | ||
|
|
||
| emitMembers(/*prefix*/ "", EmitScope.InstanceOnly, i); | ||
| emitMembers(/*prefix*/ "", "InstanceOnly", i); | ||
| emitConstants(i); | ||
| emitEventHandlers(/*prefix*/ "", i); | ||
| emitIndexers(EmitScope.InstanceOnly, i); | ||
| emitIndexers("InstanceOnly", i); | ||
|
|
||
| printer.decreaseIndent(); | ||
| printer.printLine("}"); | ||
|
|
@@ -1556,8 +1550,8 @@ export function emitWebIdl( | |
| namespace.nested.typedefs.sort(compareName).forEach(emitTypeDef); | ||
| } | ||
|
|
||
| emitProperties("var ", EmitScope.InstanceOnly, namespace); | ||
| emitMethods("function ", EmitScope.InstanceOnly, namespace, new Set()); | ||
| emitProperties("var ", "InstanceOnly", namespace); | ||
| emitMethods("function ", "InstanceOnly", namespace, new Set()); | ||
|
|
||
| printer.decreaseIndent(); | ||
| printer.printLine("}"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "es2022", | ||
| "module": "nodenext", | ||
| "moduleResolution": "nodenext", | ||
| "outDir": "./lib", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "sourceMap": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "resolveJsonModule": true | ||
| }, | ||
| "include": [ | ||
| "./src" | ||
| ] | ||
| "compilerOptions": { | ||
| "target": "es2022", | ||
| "module": "nodenext", | ||
| "moduleResolution": "nodenext", | ||
| "outDir": "./lib", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "sourceMap": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "resolveJsonModule": true, | ||
| "allowImportingTsExtensions": true, | ||
| "noEmit": true, | ||
| }, | ||
| "include": ["./src"], | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really just move these to src tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't properly review this at the moment but should be able to do so in a few days
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not strictly needed here and can happen separately IMO