-
Notifications
You must be signed in to change notification settings - Fork 442
Detect added json items for static interfaces #52
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,9 +88,19 @@ module JsonItems = | |
t.Kind.ToLower() = kind.ToString() && | ||
(t.Flavor.IsNone || t.Flavor.Value = flavor.ToString() || flavor = All)) | ||
|
||
let getOverriddenItems kind flavor = getItems overriddenItems kind flavor | ||
let getAddedItems kind flavor = getItems addedItems kind flavor | ||
let getRemovedItems kind flavor = getItems removedItems kind flavor | ||
let getOverriddenItems kind flavor = | ||
getItems overriddenItems kind flavor | ||
let getAddedItems kind flavor = | ||
getItems addedItems kind flavor | ||
let getRemovedItems kind flavor = | ||
getItems removedItems kind flavor | ||
|
||
let getAddedItemsByInterfaceName kind flavor iName = | ||
getItems addedItems kind flavor |> Array.filter (matchInterface iName) | ||
let getOverriddenItemsByInterfaceName kind flavor iName = | ||
getItems overriddenItems kind flavor |> Array.filter (matchInterface iName) | ||
let getRemovedItemsByInterfaceName kind flavor iName = | ||
getItems removedItems kind flavor |> Array.filter (matchInterface iName) | ||
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. why not use the pre-composed versions you just added? eg instead of |
||
|
||
module Comments = | ||
type CommentType = JsonProvider<"inputfiles/comments.json"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,17 +465,33 @@ let EmitStaticInterface flavor (i:Browser.Interface) = | |
// Some types are static types with non-static members. For example, | ||
// NodeFilter is a static method itself, however it has an "acceptNode" method | ||
// that expects the user to implement. | ||
let hasNonStaticMember = | ||
match i.Methods with | ||
| Some ms -> ms.Methods |> Array.exists (fun m -> m.Static.IsNone) | ||
| _ -> false | ||
let hasNonStaticMember = | ||
let hasNonStaticMethod = | ||
match JsonItems.getAddedItemsByInterfaceName ItemKind.Method flavor i.Name with | ||
| [||] -> | ||
match i.Methods with | ||
| Some ms -> ms.Methods |> Array.exists (fun m -> m.Static.IsNone) | ||
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. why don't you have to also check 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. The original idea was the there is no static property, the only thing similar may be a static constant, which should be added as |
||
| _ -> false | ||
| addedMs -> addedMs |> Array.exists (fun m -> m.Static.IsNone || m.Static.Value = false) | ||
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. In the added methods case, don't you also need to check the non-overridden methods in |
||
let hasProperty = | ||
if i.Properties.IsSome then true | ||
else | ||
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.
|
||
JsonItems.getAddedItemsByInterfaceName ItemKind.Property flavor i.Name |> Array.isEmpty |> not | ||
hasNonStaticMethod || hasProperty | ||
|
||
let emitAddedConstructor () = | ||
match JsonItems.getAddedItemsByInterfaceName ItemKind.Constructor flavor i.Name with | ||
| [||] -> () | ||
| ctors -> | ||
Pt.printl "prototype: %s;" i.Name | ||
ctors |> Array.iter (fun ctor -> ctor.Signatures |> Array.iter (Pt.printl "%s;")) | ||
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. You can save a couple lines and some visual noise by getting rid of the match: let ctors = JsonItems....
if not <| Array.isEmpty ctors then Pt.printl ...
ctors |> Array.iter ... |
||
|
||
// For static types with non-static members, we put the non-static members into an | ||
// interface, and put the static members into the object literal type of 'declare var' | ||
// For static types with only static members, we put everything in the interface. | ||
// Because in the two cases the interface contains different things, it might be easier to | ||
// read to seperate them into two functions. | ||
let emitStaticInterfaceWithNonStaticMembers () = | ||
let emitStaticInterfaceWithNonStaticMembers () = | ||
Pt.resetIndent() | ||
EmitInterfaceDeclaration i | ||
Pt.increaseIndent() | ||
|
@@ -492,6 +508,7 @@ let EmitStaticInterface flavor (i:Browser.Interface) = | |
Pt.increaseIndent() | ||
EmitConstants i | ||
EmitMembers flavor prefix EmitScope.StaticOnly i | ||
emitAddedConstructor () | ||
Pt.decreaseIndent() | ||
Pt.printl "}" | ||
Pt.printl "" | ||
|
@@ -506,7 +523,7 @@ let EmitStaticInterface flavor (i:Browser.Interface) = | |
EmitConstants i | ||
EmitEventHandlers prefix i | ||
EmitIndexers EmitScope.StaticOnly i | ||
|
||
emitAddedConstructor () | ||
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. when does a pure static interface have a constructor? 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. This happens when the spec wrongly marked an interface as pure static, and a constructor is added in the json files. For example microsoft/TypeScript#2583 |
||
Pt.decreaseIndent() | ||
Pt.printl "}" | ||
Pt.printl "declare var %s: %s;" i.Name i.Name | ||
|
@@ -616,4 +633,4 @@ let EmitDomWeb () = | |
|
||
let EmitDomWorker () = | ||
ignoreDOMTypes <- true | ||
EmitTheWholeThing Flavor.Worker GlobalVars.tsWorkerOutput | ||
EmitTheWholeThing Flavor.Worker GlobalVars.tsWorkerOutput |
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.
why not let these be the point-free versions, eg
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.
Good point!