Skip to content

Commit 503c73c

Browse files
committed
@undefined -> undefined()
1 parent fc30131 commit 503c73c

File tree

8 files changed

+58
-56
lines changed

8 files changed

+58
-56
lines changed

src/Serilog.Expressions/Expressions/BuiltInProperty.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ static class BuiltInProperty
88
public const string Message = "m";
99
public const string MessageTemplate = "mt";
1010
public const string Properties = "p";
11-
12-
// Undocumented, simplifies a few scenarios; an `undefined()` may be better.
13-
public const string Undefined = "Undefined";
1411
}
1512
}

src/Serilog.Expressions/Expressions/Compilation/Linq/LinqExpressionCompiler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ protected override ExpressionBody Transform(AmbientPropertyExpression px)
120120
if (px.PropertyName == BuiltInProperty.Properties)
121121
return Splice(context => new StructureValue(context.Properties.Select(kvp => new LogEventProperty(kvp.Key, kvp.Value)), null));
122122

123-
// Also @Undefined
124123
return LX.Constant(null, typeof(LogEventPropertyValue));
125124
}
126125

src/Serilog.Expressions/Expressions/Compilation/Text/LikeSyntaxTransformer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cx.Constant is ScalarValue scalar &&
4949
}
5050

5151
SelfLog.WriteLine($"Serilog.Expressions: `like` requires a constant string argument; found ${like}.");
52-
return new AmbientPropertyExpression(BuiltInProperty.Undefined, true);
52+
return new CallExpression(false, Operators.OpUndefined);
5353
}
5454

5555
static string LikeToRegex(string like)

src/Serilog.Expressions/Expressions/Compilation/Text/TextMatchingTransformer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cx.Constant is ScalarValue scalar &&
4848
}
4949

5050
SelfLog.WriteLine($"Serilog.Expressions: `IndexOfMatch()` requires a constant string regular expression argument; found ${regex}.");
51-
return new AmbientPropertyExpression(BuiltInProperty.Undefined, true);
51+
return new CallExpression(false, Operators.OpUndefined);
5252
}
5353
}
5454
}

src/Serilog.Expressions/Expressions/Compilation/Variadics/VariadicCallRewriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ protected override Expression Transform(CallExpression lx)
1919
{
2020
var operands = lx.Operands
2121
.Select(Transform)
22-
.Concat(new[] {new AmbientPropertyExpression(BuiltInProperty.Undefined, true)})
22+
.Concat(new[] {new CallExpression(false, Operators.OpUndefined)})
2323
.ToArray();
2424
return new CallExpression(lx.IgnoreCase, lx.OperatorName, operands);
2525
}
2626

2727
if (Operators.SameOperator(lx.OperatorName, Operators.OpCoalesce))
2828
{
2929
if (lx.Operands.Length == 0)
30-
return new AmbientPropertyExpression(BuiltInProperty.Undefined, true);
30+
return new CallExpression(false, Operators.OpUndefined);
3131
if (lx.Operands.Length == 1)
3232
return Transform(lx.Operands.Single());
3333
if (lx.Operands.Length > 2)

src/Serilog.Expressions/Expressions/Operators.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static class Operators
2929
public const string OpSubstring = "Substring";
3030
public const string OpTagOf = "TagOf";
3131
public const string OpTypeOf = "TypeOf";
32+
public const string OpUndefined = "Undefined";
3233

3334
public const string IntermediateOpLike = "_Internal_Like";
3435
public const string IntermediateOpNotLike = "_Internal_NotLike";

src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ internal static LogEventPropertyValue ScalarBoolean(bool value)
1717
{
1818
return value ? ConstantTrue : ConstantFalse;
1919
}
20+
21+
public static LogEventPropertyValue? Undefined()
22+
{
23+
return null;
24+
}
2025

2126
public static LogEventPropertyValue? _Internal_Add(LogEventPropertyValue? left, LogEventPropertyValue? right)
2227
{

test/Serilog.Expressions.Tests/Cases/expression-evaluation-cases.asv

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ false ⇶ false
1010
{a: 1, 'b c': 2} ⇶ {a: 1, 'b c': 2}
1111

1212
// Collections
13-
[5, undefined] ⇶ undefined
13+
[5, undefined()] ⇶ undefined()
1414

1515
// Strings
1616
'' ⇶ ''
@@ -34,22 +34,22 @@ false ⇶ false
3434
// Math
3535
1 + 1 ⇶ 2
3636
1 + 2 + 3 ⇶ 6
37-
'foo' + 1 ⇶ undefined
37+
'foo' + 1 ⇶ undefined()
3838
1 - 2 ⇶ -1
3939
-1 - -1 ⇶ 0
4040
3 - 2 ⇶ 1
41-
'foo' - - 1 ⇶ undefined
41+
'foo' - - 1 ⇶ undefined()
4242
1.0 + 2.0 ⇶ 3
4343
1 * 0 ⇶ 0
4444
12 * 12 ⇶ 144
4545
3 / 1 ⇶ 3
46-
3 / 0 ⇶ undefined
46+
3 / 0 ⇶ undefined()
4747
3 ^ 2 ⇶ 9
4848
0 ^ 1 ⇶ 0
4949
0 ^ 0 ⇶ 1
50-
0 % 0 ⇶ undefined
50+
0 % 0 ⇶ undefined()
5151
0 % 1 ⇶ 0
52-
1 % 0 ⇶ undefined
52+
1 % 0 ⇶ undefined()
5353
1 % 1 ⇶ 0
5454
5 % 2 ⇶ 1
5555
79228162514264337593543950334 + 1 ⇶ 79228162514264337593543950335
@@ -71,108 +71,108 @@ true and true ⇶ true
7171
true and null ⇶ false
7272
false and null ⇶ false
7373
null and null ⇶ false
74-
undefined and undefined ⇶ false
75-
undefined and true ⇶ false
76-
true and undefined ⇶ false
74+
undefined() and undefined() ⇶ false
75+
undefined() and true ⇶ false
76+
true and undefined() ⇶ false
7777
false or false ⇶ false
7878
true or false ⇶ true
7979
true or true ⇶ true
8080
false or true ⇶ true
8181
true or null ⇶ true
8282
null or true ⇶ true
83-
true or undefined ⇶ true
84-
undefined or true ⇶ true
85-
undefined or undefined ⇶ false
83+
true or undefined() ⇶ true
84+
undefined() or true ⇶ true
85+
undefined() or undefined() ⇶ false
8686
not true ⇶ false
8787
not false ⇶ true
88-
not undefined ⇶ true
88+
not undefined() ⇶ true
8989
not(true) ⇶ false
9090
not(false and false) ⇶ true
91-
not(undefined) ⇶ true
91+
not(undefined()) ⇶ true
9292
'not a bool' or true ⇶ true
9393

9494
// Coalesce
9595
coalesce(null, 1) ⇶ 1
96-
coalesce(undefined, 1) ⇶ 1
96+
coalesce(undefined(), 1) ⇶ 1
9797
coalesce(1, null) ⇶ 1
98-
coalesce(undefined, undefined) ⇶ undefined
98+
coalesce(undefined(), undefined()) ⇶ undefined()
9999
coalesce(null, null) ⇶ null
100100
coalesce(null, null, 3) ⇶ 3
101-
coalesce() ⇶ undefined
101+
coalesce() ⇶ undefined()
102102
coalesce(1) ⇶ 1
103103

104104
// Identifiers
105-
A ⇶ undefined
106-
_a ⇶ undefined
107-
a1 ⇶ undefined
105+
A ⇶ undefined()
106+
_a ⇶ undefined()
107+
a1 ⇶ undefined()
108108

109109
// EQ
110110
1 = 1 ⇶ true
111111
1 = 0 ⇶ false
112112
null = 0 ⇶ false
113113
null = null ⇶ true
114-
null = undefined ⇶ undefined
115-
undefined = undefined ⇶ undefined
114+
null = undefined() ⇶ undefined()
115+
undefined() = undefined() ⇶ undefined()
116116

117117
// NEQ
118118
1 <> 1 ⇶ false
119119
1 <> 0 ⇶ true
120120
null <> 0 ⇶ true
121121
null <> null ⇶ false
122-
undefined <> null ⇶ undefined
123-
undefined <> undefined ⇶ undefined
122+
undefined() <> null ⇶ undefined()
123+
undefined() <> undefined() ⇶ undefined()
124124

125125
// LT
126126
1 < 2 ⇶ true
127127
1 < 1 ⇶ false
128128
1 < 0 ⇶ false
129-
null < 0 ⇶ undefined
130-
null < null ⇶ undefined
131-
undefined < null ⇶ undefined
132-
undefined < undefined ⇶ undefined
129+
null < 0 ⇶ undefined()
130+
null < null ⇶ undefined()
131+
undefined() < null ⇶ undefined()
132+
undefined() < undefined() ⇶ undefined()
133133

134134
// LTE
135135
1 <= 2 ⇶ true
136136
1 <= 1 ⇶ true
137137
1 <= 0 ⇶ false
138-
null <= 0 ⇶ undefined
139-
null <= null ⇶ undefined
140-
undefined <= null ⇶ undefined
141-
undefined <= undefined ⇶ undefined
138+
null <= 0 ⇶ undefined()
139+
null <= null ⇶ undefined()
140+
undefined() <= null ⇶ undefined()
141+
undefined() <= undefined() ⇶ undefined()
142142

143143
// GT
144144
3 > 1 ⇶ true
145145
1 > 1 ⇶ false
146146
1 > 0 ⇶ true
147-
null > 0 ⇶ undefined
148-
null > null ⇶ undefined
149-
undefined > null ⇶ undefined
150-
undefined > undefined ⇶ undefined
147+
null > 0 ⇶ undefined()
148+
null > null ⇶ undefined()
149+
undefined() > null ⇶ undefined()
150+
undefined() > undefined() ⇶ undefined()
151151

152152
// GTE
153153
2 >= 1 ⇶ true
154154
1 >= 1 ⇶ true
155155
1 >= 0 ⇶ true
156156
-1 >= 0 ⇶ false
157-
null >= 0 ⇶ undefined
158-
null >= null ⇶ undefined
159-
undefined >= null ⇶ undefined
160-
undefined >= undefined ⇶ undefined
157+
null >= 0 ⇶ undefined()
158+
null >= null ⇶ undefined()
159+
undefined() >= null ⇶ undefined()
160+
undefined() >= undefined() ⇶ undefined()
161161

162162
// in/not in
163163
1 in [1, 2, 3] ⇶ true
164164
5 in [1, 2, 3] ⇶ false
165165
1 not in [1, 2, 3] ⇶ false
166166
5 not in [1, 2, 3] ⇶ true
167-
undefined in [1, 2, 3] ⇶ undefined
168-
undefined not in [1, 2, 3] ⇶ undefined
169-
1 in undefined ⇶ undefined
167+
undefined() in [1, 2, 3] ⇶ undefined()
168+
undefined() not in [1, 2, 3] ⇶ undefined()
169+
1 in undefined() ⇶ undefined()
170170
null in [1, null, 3] ⇶ true
171171

172172
// is null/is not null
173173
null is null ⇶ true
174174
null is not null ⇶ false
175-
undefined is null ⇶ true
175+
undefined() is null ⇶ true
176176

177177
// Property names and accessors
178178
[5, 6, 7][1] ⇶ 6
@@ -202,12 +202,12 @@ substring('abcd', 1) ⇶ 'bcd'
202202
if true then 1 else 2 ⇶ 1
203203
if 1 + 2 = 3 then 1 else 2 ⇶ 1
204204
if false then 1 else 2 ⇶ 2
205-
if undefined then 1 else 2 ⇶ 2
205+
if undefined() then 1 else 2 ⇶ 2
206206
if 'string' then 1 else 2 ⇶ 2
207207
if true then if false then 1 else 2 else 3 ⇶ 2
208208

209209
// Typeof
210-
typeof(undefined) ⇶ 'undefined'
210+
typeof(undefined()) ⇶ 'undefined'
211211
typeof('test') ⇶ 'System.String'
212212
typeof(10) ⇶ 'System.Decimal'
213213
typeof(true) ⇶ 'System.Boolean'
@@ -225,8 +225,8 @@ typeof({}) ⇶ 'object'
225225
'ὈΔΥΣΣΕΎΣ!' = 'ὀδυσσεύσ!' ci ⇶ true
226226
null = 0 ci ⇶ false
227227
null = null ci ⇶ true
228-
null = undefined ci ⇶ undefined
229-
undefined = undefined ci ⇶ undefined
228+
null = undefined() ci ⇶ undefined()
229+
undefined() = undefined() ci ⇶ undefined()
230230

231231
// Like
232232
'test' like 'test' ⇶ true

0 commit comments

Comments
 (0)