Skip to content

Commit

Permalink
Enhanced Member Expression Check (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Mar 27, 2023
1 parent 89564f1 commit ff2a63c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.26.4",
"version": "0.26.5",
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export namespace TypeCompiler {
// Polices
// -------------------------------------------------------------------
function IsExactOptionalProperty(value: string, key: string, expression: string) {
return TypeSystem.ExactOptionalPropertyTypes ? `('${key}' in ${value} ? ${expression} : true)` : `(${value}.${key} !== undefined ? ${expression} : true)`
return TypeSystem.ExactOptionalPropertyTypes ? `('${key}' in ${value} ? ${expression} : true)` : `(${MemberExpression.Encode(value, key)} !== undefined ? ${expression} : true)`
}
function IsObjectCheck(value: string): string {
return !TypeSystem.AllowArrayObjects ? `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}))` : `(typeof ${value} === 'object' && ${value} !== null)`
Expand Down
12 changes: 8 additions & 4 deletions test/runtime/compiler/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,20 @@ describe('type/compiler/Object', () => {
'0-leading': Type.Literal(2),
'$-leading': Type.Literal(3),
'!@#$%^&*(': Type.Literal(4),
'node-mirror:release': Type.Literal(5), // issue: 353
"a'a": Type.Literal(6),
'node-mirror:release:0': Type.Literal(5), // issue: 353
'node-mirror:release:1': Type.Optional(Type.Literal(6)), // issue: 356
'node-mirror:release:2': Type.Union([Type.Literal(7), Type.Undefined()]), // key known
"a'a": Type.Literal(8),
})
Ok(T, {
'with-hyphen': 1,
'0-leading': 2,
'$-leading': 3,
'!@#$%^&*(': 4,
'node-mirror:release': 5,
"a'a": 6,
'node-mirror:release:0': 5,
'node-mirror:release:1': 6,
'node-mirror:release:2': 7,
"a'a": 8,
})
})
it('Should validate schema additional properties of string', () => {
Expand Down

0 comments on commit ff2a63c

Please sign in to comment.