@@ -8,10 +8,10 @@ import {
8
8
VersionSyntax ,
9
9
BlockSyntax ,
10
10
SyntaxKind ,
11
- BaseValueSyntax ,
12
- StringValueSyntax ,
13
- StringArrayValueSyntax ,
14
- ObjectValueSyntax ,
11
+ BasePropertySyntax ,
12
+ StringPropertySyntax ,
13
+ ArrayPropertySyntax ,
14
+ ObjectPropertySyntax ,
15
15
} from "../parsing/syntax-nodes" ;
16
16
import {
17
17
BoundDocument ,
@@ -26,6 +26,8 @@ import {
26
26
BoundEnv ,
27
27
BoundSecrets ,
28
28
BoundUses ,
29
+ BoundStringValue ,
30
+ BoundObjectMember ,
29
31
} from "./bound-nodes" ;
30
32
import { TokenKind } from "../scanning/tokens" ;
31
33
import { MAXIMUM_SUPPORTED_VERSION } from "../util/constants" ;
@@ -92,15 +94,15 @@ export function bindDocument(root: DocumentSyntax, bag: DiagnosticBag): BoundDoc
92
94
if ( on ) {
93
95
bag . propertyAlreadyDefined ( property . key ) ;
94
96
} else {
95
- on = new BoundOn ( bindString ( property . value ) , property ) ;
97
+ on = new BoundOn ( bindString ( property ) , property ) ;
96
98
}
97
99
break ;
98
100
}
99
101
case TokenKind . ResolvesKeyword : {
100
102
if ( resolves ) {
101
103
bag . propertyAlreadyDefined ( property . key ) ;
102
104
} else {
103
- resolves = new BoundResolves ( bindStringOrArray ( property . value ) , property ) ;
105
+ resolves = new BoundResolves ( bindStringOrArray ( property ) , property ) ;
104
106
}
105
107
break ;
106
108
}
@@ -131,42 +133,42 @@ export function bindDocument(root: DocumentSyntax, bag: DiagnosticBag): BoundDoc
131
133
if ( uses ) {
132
134
bag . propertyAlreadyDefined ( property . key ) ;
133
135
} else {
134
- uses = new BoundUses ( bindString ( property . value ) , property ) ;
136
+ uses = new BoundUses ( bindString ( property ) , property ) ;
135
137
}
136
138
break ;
137
139
}
138
140
case TokenKind . NeedsKeyword : {
139
141
if ( needs ) {
140
142
bag . propertyAlreadyDefined ( property . key ) ;
141
143
} else {
142
- needs = new BoundNeeds ( bindStringOrArray ( property . value ) , property ) ;
144
+ needs = new BoundNeeds ( bindStringOrArray ( property ) , property ) ;
143
145
}
144
146
break ;
145
147
}
146
148
case TokenKind . RunsKeyword : {
147
149
if ( runs ) {
148
150
bag . propertyAlreadyDefined ( property . key ) ;
149
151
} else {
150
- runs = new BoundRuns ( bindStringOrArray ( property . value ) , property ) ;
152
+ runs = new BoundRuns ( bindStringOrArray ( property ) , property ) ;
151
153
}
152
154
break ;
153
155
}
154
156
case TokenKind . ArgsKeyword : {
155
157
if ( args ) {
156
158
bag . propertyAlreadyDefined ( property . key ) ;
157
159
} else {
158
- args = new BoundArgs ( bindStringOrArray ( property . value ) , property ) ;
160
+ args = new BoundArgs ( bindStringOrArray ( property ) , property ) ;
159
161
}
160
162
break ;
161
163
}
162
164
case TokenKind . EnvKeyword : {
163
165
if ( env ) {
164
166
bag . propertyAlreadyDefined ( property . key ) ;
165
167
} else {
166
- env = new BoundEnv ( bindObject ( property . value ) , property ) ;
167
- for ( const variable of env . variables . keys ( ) ) {
168
- if ( variable . startsWith ( "GITHUB_" ) ) {
169
- bag . reservedEnvironmentVariable ( property . key . range ) ;
168
+ env = new BoundEnv ( bindObject ( property ) , property ) ;
169
+ for ( const variable of env . variables ) {
170
+ if ( variable . name . startsWith ( "GITHUB_" ) ) {
171
+ bag . reservedEnvironmentVariable ( variable . syntax . name . range ) ;
170
172
}
171
173
}
172
174
}
@@ -176,7 +178,7 @@ export function bindDocument(root: DocumentSyntax, bag: DiagnosticBag): BoundDoc
176
178
if ( secrets ) {
177
179
bag . propertyAlreadyDefined ( property . key ) ;
178
180
} else {
179
- secrets = new BoundSecrets ( bindStringOrArray ( property . value ) , property ) ;
181
+ secrets = new BoundSecrets ( bindStringOrArray ( property ) , property ) ;
180
182
}
181
183
break ;
182
184
}
@@ -193,43 +195,55 @@ export function bindDocument(root: DocumentSyntax, bag: DiagnosticBag): BoundDoc
193
195
actions . push ( new BoundAction ( removeDoubleQuotes ( syntax . name . text ) , uses , needs , runs , args , env , secrets , syntax ) ) ;
194
196
}
195
197
196
- function bindString ( syntax : BaseValueSyntax | undefined ) : string {
198
+ function bindString ( syntax : BasePropertySyntax | undefined ) : BoundStringValue | undefined {
197
199
if ( ! syntax ) {
198
- return "" ;
200
+ return undefined ;
199
201
}
200
202
201
203
switch ( syntax . kind ) {
202
- case SyntaxKind . StringValue : {
203
- return removeDoubleQuotes ( ( syntax as StringValueSyntax ) . value . text ) ;
204
+ case SyntaxKind . StringProperty : {
205
+ const property = syntax as StringPropertySyntax ;
206
+ if ( property . value ) {
207
+ const value = removeDoubleQuotes ( property . value . text ) ;
208
+ return new BoundStringValue ( value , property . value ) ;
209
+ }
210
+ return undefined ;
204
211
}
205
- case SyntaxKind . StringArrayValue : {
206
- bag . valueIsNotString ( ( syntax as StringArrayValueSyntax ) . openBracket . range ) ;
207
- return "" ;
212
+ case SyntaxKind . ArrayProperty : {
213
+ bag . valueIsNotString ( syntax . key . range ) ;
214
+ return undefined ;
208
215
}
209
- case SyntaxKind . ObjectValue : {
210
- bag . valueIsNotString ( ( syntax as ObjectValueSyntax ) . openBracket . range ) ;
211
- return "" ;
216
+ case SyntaxKind . ObjectProperty : {
217
+ bag . valueIsNotString ( syntax . key . range ) ;
218
+ return undefined ;
212
219
}
213
220
default : {
214
221
throw new Error ( `Unexpected Syntax kind '${ syntax . kind } '` ) ;
215
222
}
216
223
}
217
224
}
218
225
219
- function bindStringOrArray ( syntax : BaseValueSyntax | undefined ) : ReadonlyArray < string > {
226
+ function bindStringOrArray ( syntax : BasePropertySyntax | undefined ) : ReadonlyArray < BoundStringValue > {
220
227
if ( ! syntax ) {
221
228
return [ ] ;
222
229
}
223
230
224
231
switch ( syntax . kind ) {
225
- case SyntaxKind . StringValue : {
226
- return [ removeDoubleQuotes ( ( syntax as StringValueSyntax ) . value . text ) ] ;
232
+ case SyntaxKind . StringProperty : {
233
+ const property = syntax as StringPropertySyntax ;
234
+ if ( property . value ) {
235
+ const value = removeDoubleQuotes ( property . value . text ) ;
236
+ return [ new BoundStringValue ( value , property . value ) ] ;
237
+ }
238
+ return [ ] ;
227
239
}
228
- case SyntaxKind . StringArrayValue : {
229
- return ( syntax as StringArrayValueSyntax ) . values . map ( v => removeDoubleQuotes ( v . value . text ) ) ;
240
+ case SyntaxKind . ArrayProperty : {
241
+ return ( syntax as ArrayPropertySyntax ) . items . map (
242
+ item => new BoundStringValue ( removeDoubleQuotes ( item . value . text ) , item . value ) ,
243
+ ) ;
230
244
}
231
- case SyntaxKind . ObjectValue : {
232
- bag . valueIsNotStringOrArray ( ( syntax as ObjectValueSyntax ) . openBracket . range ) ;
245
+ case SyntaxKind . ObjectProperty : {
246
+ bag . valueIsNotStringOrArray ( syntax . key . range ) ;
233
247
return [ ] ;
234
248
}
235
249
default : {
@@ -238,37 +252,29 @@ export function bindDocument(root: DocumentSyntax, bag: DiagnosticBag): BoundDoc
238
252
}
239
253
}
240
254
241
- function bindObject ( syntax : BaseValueSyntax | undefined ) : ReadonlyMap < string , string > {
242
- const map = new Map < string , string > ( ) ;
243
- if ( syntax ) {
244
- switch ( syntax . kind ) {
245
- case SyntaxKind . StringValue : {
246
- bag . valueIsNotAnObject ( ( syntax as StringValueSyntax ) . value . range ) ;
247
- break ;
248
- }
249
- case SyntaxKind . StringArrayValue : {
250
- bag . valueIsNotAnObject ( ( syntax as StringArrayValueSyntax ) . openBracket . range ) ;
251
- break ;
252
- }
253
- case SyntaxKind . ObjectValue : {
254
- ( syntax as ObjectValueSyntax ) . members . forEach ( variable => {
255
- const key = variable . name . text ;
256
- if ( map . has ( key ) ) {
257
- bag . duplicateKey ( key , variable . name . range ) ;
258
- } else {
259
- const value = removeDoubleQuotes ( variable . value . text ) ;
260
- map . set ( key , value ) ;
261
- }
262
- } ) ;
263
- break ;
264
- }
265
- default : {
266
- throw new Error ( `Unexpected Syntax kind '${ syntax . kind } '` ) ;
267
- }
268
- }
255
+ function bindObject ( syntax : BasePropertySyntax | undefined ) : ReadonlyArray < BoundObjectMember > {
256
+ if ( ! syntax ) {
257
+ return [ ] ;
269
258
}
270
259
271
- return map ;
260
+ switch ( syntax . kind ) {
261
+ case SyntaxKind . StringProperty : {
262
+ bag . valueIsNotAnObject ( syntax . key . range ) ;
263
+ return [ ] ;
264
+ }
265
+ case SyntaxKind . ArrayProperty : {
266
+ bag . valueIsNotAnObject ( syntax . key . range ) ;
267
+ return [ ] ;
268
+ }
269
+ case SyntaxKind . ObjectProperty : {
270
+ return ( syntax as ObjectPropertySyntax ) . members . map (
271
+ member => new BoundObjectMember ( member . name . text , removeDoubleQuotes ( member . value . text ) , member ) ,
272
+ ) ;
273
+ }
274
+ default : {
275
+ throw new Error ( `Unexpected Syntax kind '${ syntax . kind } '` ) ;
276
+ }
277
+ }
272
278
}
273
279
274
280
function removeDoubleQuotes ( value : string ) : string {
0 commit comments