Skip to content

Commit

Permalink
readOnly for Property
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhrmanator committed Jul 18, 2024
1 parent 21571b3 commit 06bcf8e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Famix-TypeScript-Entities/FamixTypeScriptProperty.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ I represent a TypeScript class property.
| `isClassSide` | `Boolean` | false | Entity can be declared class side i.e. static|
| `isStub` | `Boolean` | false | Flag true if the entity attributes are incomplete, either because the entity is missing or not imported.|
| `name` | `String` | nil | Basic name of the entity, not full reference.|
| `readOnly` | `Boolean` | false | Properties may be prefixed with the readonly modifier. This prevents assignments to the field outside of the constructor.|
| `visibility` | `String` | nil | Visibility of the entity|
"
Expand All @@ -37,6 +38,9 @@ Class {
#superclass : #FamixTypeScriptStructuralEntity,
#traits : 'FamixTAttribute + FamixTCanBeClassSide + FamixTHasVisibility',
#classTraits : 'FamixTAttribute classTrait + FamixTCanBeClassSide classTrait + FamixTHasVisibility classTrait',
#instVars : [
'#readOnly => FMProperty defaultValue: false'
],
#category : #'Famix-TypeScript-Entities-Entities'
}

Expand All @@ -48,3 +52,18 @@ FamixTypeScriptProperty class >> annotation [
<generated>
^ self
]

{ #category : #accessing }
FamixTypeScriptProperty >> readOnly [

<FMProperty: #readOnly type: #Boolean defaultValue: false>
<generated>
<FMComment: 'Properties may be prefixed with the readonly modifier. This prevents assignments to the field outside of the constructor.'>
^ readOnly ifNil: [ readOnly := false ]
]

{ #category : #accessing }
FamixTypeScriptProperty >> readOnly: anObject [
<generated>
readOnly := anObject
]
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ FamixTypeScriptGenerator >> defineProperties [

(decorator property: #expression type: #String)
comment: 'Decorators use the form @expression, where expression must evaluate to a function that will be called at runtime with information about the decorated declaration'.
(property property: #readOnly type: #Boolean defaultValue: false)
comment: 'Properties may be prefixed with the readonly modifier. This prevents assignments to the field outside of the constructor.'
"The following are not need because of THasKind (?)"

"(method property: #isConstructor type: #Boolean defaultValue: false)
Expand Down
10 changes: 10 additions & 0 deletions src/Famix-TypeScript-Tests/FamixTypeScriptPropertyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Class {
#category : #'Famix-TypeScript-Tests-Entities'
}

{ #category : #tests }
FamixTypeScriptPropertyTest >> testPropertyReadonly [
| property |
property := FamixTypeScriptProperty new.
self deny: property readOnly.
property readOnly: true.
self assert: property readOnly.

]

{ #category : #tests }
FamixTypeScriptPropertyTest >> testPropertyVisibility [
| property |
Expand Down

0 comments on commit 06bcf8e

Please sign in to comment.