-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from pedromdev/modifiers-v5
Properties Modifiers v5
- Loading branch information
Showing
8 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {getClassType, hasModifier, Reflective, Types} from "tsruntime"; | ||
|
||
class Cls { | ||
f!: string; | ||
protected g!: string; | ||
constructor() { | ||
} | ||
} | ||
|
||
@Reflective | ||
abstract class SubCls extends Cls { | ||
a!: string; | ||
public b!: string; | ||
protected c!: string; | ||
private d!: string; | ||
readonly e!: string; | ||
override f!: string; | ||
protected override readonly g!: string; | ||
abstract h: string; | ||
protected abstract i: string; | ||
public readonly j!: string; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
} | ||
|
||
function getProperty(name: string) { | ||
const type = getClassType(SubCls); | ||
return type.properties[name]; | ||
} | ||
|
||
function matchModifiers(propName: string, expected: Types.ModifierFlags[]) { | ||
for (const modifierFlag of expected) { | ||
expect({ | ||
name: propName, | ||
modifierFlag, | ||
hasModifier: hasModifier(getProperty(propName) as any as {modifiers: number}, modifierFlag) | ||
}).toEqual({ | ||
name: propName, | ||
modifierFlag, | ||
hasModifier: true | ||
}); | ||
} | ||
} | ||
|
||
describe("class properties modifiers", () => { | ||
it("matches modifiers", () => { | ||
matchModifiers("a", [Types.ModifierFlags.None]); | ||
matchModifiers("b", [Types.ModifierFlags.Public]); | ||
matchModifiers("c", [Types.ModifierFlags.Protected]); | ||
matchModifiers("d", [Types.ModifierFlags.Private]); | ||
matchModifiers("e", [Types.ModifierFlags.Readonly]); | ||
matchModifiers("f", [Types.ModifierFlags.Override]); | ||
matchModifiers("g", [Types.ModifierFlags.Protected, Types.ModifierFlags.Readonly, Types.ModifierFlags.Override]); | ||
matchModifiers("h", [Types.ModifierFlags.Abstract]); | ||
matchModifiers("i", [Types.ModifierFlags.Protected, Types.ModifierFlags.Abstract]); | ||
matchModifiers("j", [Types.ModifierFlags.Public, Types.ModifierFlags.Readonly]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ModifierFlags } from './publicTypes'; | ||
|
||
export const hasModifier = (type: { modifiers: number }, modifier: ModifierFlags) => { | ||
if (modifier === type.modifiers) { | ||
return true; | ||
} | ||
return !!(type.modifiers & modifier); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './reflect' | ||
export * from './classUtils' | ||
export * from './common' | ||
export * from './hasModifier' | ||
|
||
import * as Types from './publicTypes'; | ||
export {Types} | ||
export {Types} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters