Skip to content

Commit eca46c7

Browse files
cmdcolinclaude
andcommitted
fix: add non-null assertions for noUncheckedIndexedAccess compliance
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 0c6e986 commit eca46c7

6 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/Jexl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Jexl {
169169
* @param {string} operator The operator string to be removed
170170
*/
171171
removeOp(operator: string) {
172-
const elem = this._grammar.elements[operator]
172+
const elem = this._grammar.elements[operator]!
173173
if (elem.type === 'binaryOp' || elem.type === 'unaryOp') {
174174
Reflect.deleteProperty(this._grammar.elements, operator)
175175
}

src/Lexer.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ class Lexer {
8484
const tokens: Token[] = []
8585
let negate = false
8686
for (let i = 0; i < elements.length; i++) {
87-
if (this._isWhitespace(elements[i])) {
87+
if (this._isWhitespace(elements[i]!)) {
8888
if (tokens.length) {
89-
tokens[tokens.length - 1].raw += elements[i]
89+
tokens[tokens.length - 1]!.raw += elements[i]!
9090
}
9191
} else if (elements[i] === '-' && this._isNegative(tokens)) {
9292
negate = true
9393
} else {
9494
if (negate) {
95-
elements[i] = '-' + elements[i]
95+
elements[i] = '-' + elements[i]!
9696
negate = false
9797
}
98-
tokens.push(this._createToken(elements[i]))
98+
tokens.push(this._createToken(elements[i]!))
9999
}
100100
}
101101
// Catch a - at the end of the string. Let the parser handle that issue.
@@ -164,7 +164,7 @@ class Lexer {
164164
} else if (element === 'true' || element === 'false') {
165165
token.value = element === 'true'
166166
} else if (Object.hasOwn(this._grammar.elements, element)) {
167-
token.type = this._grammar.elements[element].type
167+
token.type = this._grammar.elements[element]!.type
168168
} else if (identRegex.exec(element)) {
169169
token.type = 'identifier'
170170
} else {
@@ -231,7 +231,7 @@ class Lexer {
231231
if (!tokens.length) {
232232
return true
233233
}
234-
return minusNegatesAfter.has(tokens[tokens.length - 1].type)
234+
return minusNegatesAfter.has(tokens[tokens.length - 1]!.type)
235235
}
236236

237237
/**
@@ -258,7 +258,7 @@ class Lexer {
258258
* @private
259259
*/
260260
_unquote(str: string) {
261-
const quote = str[0]
261+
const quote = str[0]!
262262
let escQuoteRegex = this._escQuoteRegexCache.get(quote)
263263
if (!escQuoteRegex) {
264264
escQuoteRegex = new RegExp('\\\\' + quote, 'g')
@@ -281,7 +281,7 @@ class Lexer {
281281
continue
282282
}
283283

284-
if (str[current] === '$' && str[current + 1] === '{') {
284+
if (str[current] === '$' && str[current + 1]! === '{') {
285285
if (current > staticStart) {
286286
parts.push({
287287
type: 'static',
@@ -294,14 +294,14 @@ class Lexer {
294294
current += 2
295295

296296
while (current < str.length && braceDepth > 0) {
297-
if (str[current] === '\\') {
297+
if (str[current]! === '\\') {
298298
current += 2
299299
continue
300300
}
301-
if (str[current] === '{') {
301+
if (str[current]! === '{') {
302302
braceDepth++
303303
}
304-
if (str[current] === '}') {
304+
if (str[current]! === '}') {
305305
braceDepth--
306306
}
307307
current++

src/evaluator/Evaluator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Evaluator {
4646
eval(ast: AstNode): JexlValue {
4747
type HandlerFn = (this: Evaluator, ast: AstNode) => JexlValue
4848
const handlerMap = handlers as unknown as Record<string, HandlerFn>
49-
return handlerMap[ast.type].call(this, ast)
49+
return handlerMap[ast.type]!.call(this, ast)
5050
}
5151

5252
/**

src/evaluator/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function BinaryExpression(
5656
this: Evaluator,
5757
ast: BinaryExpression
5858
): JexlValue {
59-
const grammarOp = this._grammar.elements[ast.operator]
59+
const grammarOp = this._grammar.elements[ast.operator]!
6060
if (grammarOp.type === 'binaryOp') {
6161
const binaryOp = grammarOp as BinaryOp
6262
if (binaryOp.evalOnDemand) {
@@ -238,7 +238,7 @@ export function UnaryExpression(
238238
ast: UnaryExpression
239239
): JexlValue {
240240
const right = this.eval(ast.right!)
241-
const elem = this._grammar.elements[ast.operator]
241+
const elem = this._grammar.elements[ast.operator]!
242242
if (elem.type === 'unaryOp') {
243243
return (elem as UnaryOp).eval(right)
244244
}

src/parser/Parser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Parser {
7272
if (this._state === 'complete') {
7373
throw new Error('Cannot add a new token to a completed Parser')
7474
}
75-
const state = states[this._state]
75+
const state = states[this._state]!
7676
const startExpr = this._exprStr
7777
this._exprStr += token.raw
7878
if (state.subHandler) {
@@ -91,9 +91,9 @@ class Parser {
9191
}
9292
}
9393
} else if (token.type === 'semicolon' && this._stopMap[token.type]) {
94-
return this._stopMap[token.type]
94+
return this._stopMap[token.type]!
9595
} else if (state.tokenTypes?.[token.type]) {
96-
const typeOpts = state.tokenTypes[token.type]
96+
const typeOpts = state.tokenTypes[token.type]!
9797
let handleFunc = (
9898
handlers as Record<
9999
string,
@@ -110,7 +110,7 @@ class Parser {
110110
this._state = typeOpts.toState
111111
}
112112
} else if (this._stopMap[token.type]) {
113-
return this._stopMap[token.type]
113+
return this._stopMap[token.type]!
114114
} else {
115115
throw new Error(
116116
`Token ${token.raw} (${token.type}) unexpected in expression: ${this._exprStr}`
@@ -138,7 +138,7 @@ class Parser {
138138
* the expression, indicating that the expression is incomplete
139139
*/
140140
complete() {
141-
if (this._cursor && !states[this._state].completable) {
141+
if (this._cursor && !states[this._state]!.completable) {
142142
throw new Error(`Unexpected end of expression: ${this._exprStr}`)
143143
}
144144
if (this._subParser) {
@@ -175,7 +175,7 @@ class Parser {
175175
* @private
176176
*/
177177
_endSubExpression() {
178-
states[this._state].subHandler!.call(this, this._subParser!.complete())
178+
states[this._state]!.subHandler!.call(this, this._subParser!.complete())
179179
this._subParser = undefined
180180
}
181181

@@ -232,12 +232,12 @@ class Parser {
232232
* @private
233233
*/
234234
_startSubExpression(exprStr?: string) {
235-
let endStates = states[this._state].endStates
235+
let endStates = states[this._state]!.endStates
236236
if (!endStates) {
237237
this._parentStop = true
238238
endStates = this._stopMap
239239
}
240-
if (states[this._state].completable && !endStates.semicolon) {
240+
if (states[this._state]!.completable && !endStates.semicolon) {
241241
endStates = { ...endStates, semicolon: '_semicolon' }
242242
}
243243
this._subParser = new Parser(this._grammar, this._lexer, exprStr, endStates)

src/parser/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function binaryOp(this: Parser, token: Token) {
7575
}
7676

7777
const tokenValue = token.value as string
78-
const grammarElem = this._grammar.elements[tokenValue]
78+
const grammarElem = this._grammar.elements[tokenValue]!
7979
const precedence =
8080
(grammarElem.type === 'binaryOp'
8181
? (grammarElem as BinaryOp).precedence
@@ -86,7 +86,7 @@ export function binaryOp(this: Parser, token: Token) {
8686
if (!parentExpr.operator) {
8787
break
8888
}
89-
const parentElem = this._grammar.elements[parentExpr.operator]
89+
const parentElem = this._grammar.elements[parentExpr.operator]!
9090
const parentPrecedence =
9191
parentElem.type === 'binaryOp' || parentElem.type === 'unaryOp'
9292
? (parentElem as BinaryOp).precedence

0 commit comments

Comments
 (0)