remove template literal check

This commit is contained in:
Vikhyath Mondreti
2026-01-26 01:10:30 -08:00
parent e20ec7ae3c
commit 0e9bcdf1b2
4 changed files with 10 additions and 79 deletions

View File

@@ -53,34 +53,17 @@ function getProperties(schema: unknown): Record<string, unknown> | undefined {
: undefined
}
function getFieldCaseInsensitive(
obj: Record<string, unknown>,
fieldName: string
): unknown | undefined {
if (fieldName in obj) {
return obj[fieldName]
}
const lowerName = fieldName.toLowerCase()
for (const key of Object.keys(obj)) {
if (key.toLowerCase() === lowerName) {
return obj[key]
}
}
return undefined
}
function lookupField(schema: unknown, fieldName: string): unknown | undefined {
if (typeof schema !== 'object' || schema === null) return undefined
const typed = schema as Record<string, unknown>
const direct = getFieldCaseInsensitive(typed, fieldName)
if (direct !== undefined) {
return direct
if (fieldName in typed) {
return typed[fieldName]
}
const props = getProperties(schema)
if (props) {
return getFieldCaseInsensitive(props, fieldName)
if (props && fieldName in props) {
return props[fieldName]
}
return undefined

View File

@@ -174,18 +174,7 @@ export class VariableResolver {
return match
}
const isInTemplateLiteral =
blockType === BlockType.FUNCTION &&
template.includes('${') &&
template.includes('}') &&
template.includes('`')
return this.blockResolver.formatValueForBlock(
resolved,
blockType,
isInTemplateLiteral,
language
)
return this.blockResolver.formatValueForBlock(resolved, blockType, language)
} catch (error) {
replacementError = error instanceof Error ? error : new Error(String(error))
return match

View File

@@ -159,18 +159,13 @@ export class BlockResolver implements Resolver {
return this.nameToBlockId.get(normalizeName(name))
}
public formatValueForBlock(
value: any,
blockType: string | undefined,
isInTemplateLiteral = false,
language?: string
): string {
public formatValueForBlock(value: any, blockType: string | undefined, language?: string): string {
if (blockType === 'condition') {
return this.stringifyForCondition(value)
}
if (blockType === 'function') {
return this.formatValueForCodeContext(value, isInTemplateLiteral, language)
return this.formatValueForCodeContext(value, language)
}
if (blockType === 'response') {
@@ -211,32 +206,9 @@ export class BlockResolver implements Resolver {
return String(value)
}
private formatValueForCodeContext(
value: any,
isInTemplateLiteral: boolean,
language?: string
): string {
private formatValueForCodeContext(value: any, language?: string): string {
const isPython = language === 'python'
if (isInTemplateLiteral) {
if (typeof value === 'string') {
return value
}
if (typeof value === 'object' && value !== null) {
return JSON.stringify(value)
}
if (typeof value === 'boolean') {
return isPython ? (value ? 'True' : 'False') : String(value)
}
if (value === undefined) {
return isPython ? 'None' : 'undefined'
}
if (value === null) {
return isPython ? 'None' : 'null'
}
return String(value)
}
if (typeof value === 'string') {
return JSON.stringify(value)
}

View File

@@ -20,19 +20,6 @@ export interface Resolver {
* navigatePath({a: {b: {c: 1}}}, ['a', 'b', 'c']) => 1
* navigatePath({items: [{name: 'test'}]}, ['items', '0', 'name']) => 'test'
*/
function getPropertyCaseInsensitive(obj: Record<string, unknown>, key: string): unknown {
if (key in obj) {
return obj[key]
}
const lowerKey = key.toLowerCase()
for (const k of Object.keys(obj)) {
if (k.toLowerCase() === lowerKey) {
return obj[k]
}
}
return undefined
}
export function navigatePath(obj: any, path: string[]): any {
let current = obj
for (const part of path) {
@@ -45,7 +32,7 @@ export function navigatePath(obj: any, path: string[]): any {
const [, prop, bracketsPart] = arrayMatch
current =
typeof current === 'object' && current !== null
? getPropertyCaseInsensitive(current, prop)
? (current as Record<string, unknown>)[prop]
: undefined
if (current === undefined || current === null) {
return undefined
@@ -67,7 +54,7 @@ export function navigatePath(obj: any, path: string[]): any {
} else {
current =
typeof current === 'object' && current !== null
? getPropertyCaseInsensitive(current, part)
? (current as Record<string, unknown>)[part]
: undefined
}
}