Skip to content

Commit 0e9bcdf

Browse files
committed
remove template literal check
1 parent e20ec7a commit 0e9bcdf

File tree

4 files changed

+10
-79
lines changed

4 files changed

+10
-79
lines changed

apps/sim/executor/utils/block-reference.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,17 @@ function getProperties(schema: unknown): Record<string, unknown> | undefined {
5353
: undefined
5454
}
5555

56-
function getFieldCaseInsensitive(
57-
obj: Record<string, unknown>,
58-
fieldName: string
59-
): unknown | undefined {
60-
if (fieldName in obj) {
61-
return obj[fieldName]
62-
}
63-
const lowerName = fieldName.toLowerCase()
64-
for (const key of Object.keys(obj)) {
65-
if (key.toLowerCase() === lowerName) {
66-
return obj[key]
67-
}
68-
}
69-
return undefined
70-
}
71-
7256
function lookupField(schema: unknown, fieldName: string): unknown | undefined {
7357
if (typeof schema !== 'object' || schema === null) return undefined
7458
const typed = schema as Record<string, unknown>
7559

76-
const direct = getFieldCaseInsensitive(typed, fieldName)
77-
if (direct !== undefined) {
78-
return direct
60+
if (fieldName in typed) {
61+
return typed[fieldName]
7962
}
8063

8164
const props = getProperties(schema)
82-
if (props) {
83-
return getFieldCaseInsensitive(props, fieldName)
65+
if (props && fieldName in props) {
66+
return props[fieldName]
8467
}
8568

8669
return undefined

apps/sim/executor/variables/resolver.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,7 @@ export class VariableResolver {
174174
return match
175175
}
176176

177-
const isInTemplateLiteral =
178-
blockType === BlockType.FUNCTION &&
179-
template.includes('${') &&
180-
template.includes('}') &&
181-
template.includes('`')
182-
183-
return this.blockResolver.formatValueForBlock(
184-
resolved,
185-
blockType,
186-
isInTemplateLiteral,
187-
language
188-
)
177+
return this.blockResolver.formatValueForBlock(resolved, blockType, language)
189178
} catch (error) {
190179
replacementError = error instanceof Error ? error : new Error(String(error))
191180
return match

apps/sim/executor/variables/resolvers/block.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,13 @@ export class BlockResolver implements Resolver {
159159
return this.nameToBlockId.get(normalizeName(name))
160160
}
161161

162-
public formatValueForBlock(
163-
value: any,
164-
blockType: string | undefined,
165-
isInTemplateLiteral = false,
166-
language?: string
167-
): string {
162+
public formatValueForBlock(value: any, blockType: string | undefined, language?: string): string {
168163
if (blockType === 'condition') {
169164
return this.stringifyForCondition(value)
170165
}
171166

172167
if (blockType === 'function') {
173-
return this.formatValueForCodeContext(value, isInTemplateLiteral, language)
168+
return this.formatValueForCodeContext(value, language)
174169
}
175170

176171
if (blockType === 'response') {
@@ -211,32 +206,9 @@ export class BlockResolver implements Resolver {
211206
return String(value)
212207
}
213208

214-
private formatValueForCodeContext(
215-
value: any,
216-
isInTemplateLiteral: boolean,
217-
language?: string
218-
): string {
209+
private formatValueForCodeContext(value: any, language?: string): string {
219210
const isPython = language === 'python'
220211

221-
if (isInTemplateLiteral) {
222-
if (typeof value === 'string') {
223-
return value
224-
}
225-
if (typeof value === 'object' && value !== null) {
226-
return JSON.stringify(value)
227-
}
228-
if (typeof value === 'boolean') {
229-
return isPython ? (value ? 'True' : 'False') : String(value)
230-
}
231-
if (value === undefined) {
232-
return isPython ? 'None' : 'undefined'
233-
}
234-
if (value === null) {
235-
return isPython ? 'None' : 'null'
236-
}
237-
return String(value)
238-
}
239-
240212
if (typeof value === 'string') {
241213
return JSON.stringify(value)
242214
}

apps/sim/executor/variables/resolvers/reference.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,6 @@ export interface Resolver {
2020
* navigatePath({a: {b: {c: 1}}}, ['a', 'b', 'c']) => 1
2121
* navigatePath({items: [{name: 'test'}]}, ['items', '0', 'name']) => 'test'
2222
*/
23-
function getPropertyCaseInsensitive(obj: Record<string, unknown>, key: string): unknown {
24-
if (key in obj) {
25-
return obj[key]
26-
}
27-
const lowerKey = key.toLowerCase()
28-
for (const k of Object.keys(obj)) {
29-
if (k.toLowerCase() === lowerKey) {
30-
return obj[k]
31-
}
32-
}
33-
return undefined
34-
}
35-
3623
export function navigatePath(obj: any, path: string[]): any {
3724
let current = obj
3825
for (const part of path) {
@@ -45,7 +32,7 @@ export function navigatePath(obj: any, path: string[]): any {
4532
const [, prop, bracketsPart] = arrayMatch
4633
current =
4734
typeof current === 'object' && current !== null
48-
? getPropertyCaseInsensitive(current, prop)
35+
? (current as Record<string, unknown>)[prop]
4936
: undefined
5037
if (current === undefined || current === null) {
5138
return undefined
@@ -67,7 +54,7 @@ export function navigatePath(obj: any, path: string[]): any {
6754
} else {
6855
current =
6956
typeof current === 'object' && current !== null
70-
? getPropertyCaseInsensitive(current, part)
57+
? (current as Record<string, unknown>)[part]
7158
: undefined
7259
}
7360
}

0 commit comments

Comments
 (0)