Add lexical scope and redefining variables in functions (#3015)
* Fix to allow variable shadowing inside functions * Implement closures * Fix KCL test code to not reference future tag definition * Remove tag declarator from function parameters This is an example where the scoping change revealed a subtle issue with TagDeclarators. You cannot bind a new tag using a function parameter. The issue is that evaluating a TagDeclarator like $foo binds an identifier to its corresponding TagIdentifier, but returns the TagDeclarator. If you have a TagDeclarator passed in as a parameter to a function, you can never get its corresponding TagIdentifier. This seems like a case where TagDeclarator evaluation needs to be revisited, especially now that we have scoped tags. * Fix to query return, functions, and tag declarator AST nodes correctly
This commit is contained in:
@ -82,8 +82,7 @@ export const MemoryPane = () => {
|
||||
|
||||
export const processMemory = (programMemory: ProgramMemory) => {
|
||||
const processedMemory: any = {}
|
||||
Object.keys(programMemory?.root || {}).forEach((key) => {
|
||||
const val = programMemory.root[key]
|
||||
for (const [key, val] of programMemory?.visibleEntries()) {
|
||||
if (typeof val.value !== 'function') {
|
||||
if (val.type === 'SketchGroup') {
|
||||
processedMemory[key] = val.value.map(({ __geoMeta, ...rest }: Path) => {
|
||||
@ -103,6 +102,6 @@ export const processMemory = (programMemory: ProgramMemory) => {
|
||||
} else if (key !== 'log') {
|
||||
processedMemory[key] = '__function__'
|
||||
}
|
||||
})
|
||||
}
|
||||
return processedMemory
|
||||
}
|
||||
|
Reference in New Issue
Block a user