@@ -58,6 +58,17 @@ module ServerLess<Input I> {
58
58
result = mapping .lookup ( property ) .( YamlScalar ) .getValue ( )
59
59
}
60
60
61
+ /**
62
+ * Gets the looked up value if it exists or
63
+ * the empty string if it does not.
64
+ */
65
+ pragma [ inline]
66
+ private string lookupValueOrEmpty ( YamlMapping mapping , string property ) {
67
+ if exists ( mapping .lookup ( property ) )
68
+ then result = mapping .lookup ( property ) .( YamlScalar ) .getValue ( )
69
+ else result = ""
70
+ }
71
+
61
72
/**
62
73
* Gets a string where an ending "/." is simplified to "/" (if it exists).
63
74
*/
@@ -78,9 +89,13 @@ module ServerLess<Input I> {
78
89
79
90
/**
80
91
* Gets a string suitable as part of a file path.
92
+ *
93
+ * Maps the empty string to the empty string.
81
94
*/
82
95
bindingset [ base]
83
- private string normalise ( string base ) { result = removeLeadingDotSlash ( removeTrailingDot ( base ) ) }
96
+ private string normalizePath ( string base ) {
97
+ result = removeLeadingDotSlash ( removeTrailingDot ( base ) )
98
+ }
84
99
85
100
/**
86
101
* Holds if the `.yml` file `ymlFile` contains a serverless configuration from `framework` with
@@ -99,16 +114,8 @@ module ServerLess<Input I> {
99
114
exists ( YamlMapping properties | properties = resource .lookup ( "Properties" ) |
100
115
(
101
116
handler = lookupValue ( properties , "Handler" ) and
102
- (
103
- if exists ( properties .lookup ( "CodeUri" ) )
104
- then codeUri = normalise ( lookupValue ( properties , "CodeUri" ) )
105
- else codeUri = ""
106
- ) and
107
- (
108
- if exists ( properties .lookup ( "Runtime" ) )
109
- then runtime = lookupValue ( properties , "Runtime" )
110
- else runtime = ""
111
- )
117
+ codeUri = normalizePath ( lookupValueOrEmpty ( properties , "CodeUri" ) ) and
118
+ runtime = lookupValueOrEmpty ( properties , "Runtime" )
112
119
)
113
120
)
114
121
or
@@ -119,11 +126,7 @@ module ServerLess<Input I> {
119
126
not exists ( resource .getParentNode ( ) ) and
120
127
handler = lookupValue ( functions .getValue ( _) , "handler" ) and
121
128
codeUri = "" and
122
- (
123
- if exists ( functions .lookup ( "Runtime" ) )
124
- then runtime = lookupValue ( functions , "Runtime" )
125
- else runtime = ""
126
- )
129
+ runtime = lookupValueOrEmpty ( functions , "Runtime" )
127
130
)
128
131
)
129
132
}
0 commit comments