Skip to content

Add "readonly" modifier for property and constants #86

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

Merged
merged 2 commits into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions TS.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ let rec DomTypeToTsType (objDomType: string) =
else "any"

let EmitConstants (i: Browser.Interface) =
let emitConstantFromJson (c: ItemsType.Root) = Pt.printl "%s: %s;" c.Name.Value c.Type.Value
let emitConstantFromJson (c: ItemsType.Root) = Pt.printl "readonly %s: %s;" c.Name.Value c.Type.Value

let emitConstant (c: Browser.Constant) =
if Option.isNone (findRemovedItem c.Name ItemKind.Constant i.Name) then
match findOverriddenItem c.Name ItemKind.Constant i.Name with
| Some c' -> emitConstantFromJson c'
| None -> Pt.printl "%s: %s;" c.Name (DomTypeToTsType c.Type)
| None -> Pt.printl "readonly %s: %s;" c.Name (DomTypeToTsType c.Type)

// Emit the constants added in the json files

Expand Down Expand Up @@ -212,7 +212,11 @@ let EmitEnums () =

let EmitProperties flavor prefix (emitScope: EmitScope) (i: Browser.Interface)=
let emitPropertyFromJson (p: ItemsType.Root) =
Pt.printl "%s%s: %s;" prefix p.Name.Value p.Type.Value
let readOnlyModifier =
match p.Readonly with
| Some(true) -> "readonly "
| _ -> ""
Pt.printl "%s%s%s: %s;" prefix readOnlyModifier p.Name.Value p.Type.Value

let emitProperty (p: Browser.Property) =
match GetCommentForProperty i.Name p.Name with
Expand All @@ -227,7 +231,8 @@ let EmitProperties flavor prefix (emitScope: EmitScope) (i: Browser.Interface)=
match p.Type with
| "EventHandler" -> String.Format("(ev: {0}) => any", ehNameToEType.[p.Name])
| _ -> DomTypeToTsType p.Type
Pt.printl "%s%s: %s;" prefix p.Name pType
let readOnlyModifier = if p.ReadOnly.IsSome && prefix = "" then "readonly " else ""
Pt.printl "%s%s%s: %s;" prefix readOnlyModifier p.Name pType

// Note: the schema file shows the property doesn't have "static" attribute,
// therefore all properties are emited for the instance type.
Expand Down
Loading