Skip to content

Commit 9de22cf

Browse files
committed
Merge pull request #86 from Microsoft/readonly
Add "readonly" modifier for property and constants
2 parents e67cbb7 + bb869dc commit 9de22cf

File tree

5 files changed

+2660
-2654
lines changed

5 files changed

+2660
-2654
lines changed

TS.fsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ let rec DomTypeToTsType (objDomType: string) =
7979
else "any"
8080

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

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

9090
// Emit the constants added in the json files
9191

@@ -212,7 +212,11 @@ let EmitEnums () =
212212

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

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

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

0 commit comments

Comments
 (0)