Skip to content

XS Issue: Variables declared with let are treated as const #540

@MKGaru

Description

@MKGaru

version: 4ad0dde
Build environment: Windows
Target device: ESP32

Description
Should be possible to declare using const, but the let to be declared next will be treated as const.

Test case

function func(descriptors) {
  const obj = {}
  
  for (const [key, descriptor] of Object.entries(descriptors)) {
    const type =
      typeof descriptor.type == 'string'
        ? descriptor.type.toLowerCase()
      : typeof descriptor.type.name == 'string'
        ? descriptor.type.name.toLowerCase()
      : ''
    if ((type == 'digital')) {
      if (typeof descriptor.mode == 'string') {
        // It should be possible to declare using const, but the let to be declared next will be treated as const.
        const mode = descriptor.mode.toLowerCase()
        if (mode == 'output') descriptor.mode = 1
      }
      if (descriptor.mode == 1) {
        let value = descriptor.default || false
        //value = !value  // ERROR!! set value: const!
        
        Object.defineProperty(obj, key, {
          get() {
            return value
          },
          set(val) {
            value = val // ERROR!! set value: const!
          },
          enumerable: true,
        })
      }
    }
  }
  
  return obj
}

const obj = func({
  prop: {
    type: 'Digital',
    mode: 'Output',
  }
})

obj.prop = true

Sorry for not being able to provide the minimum test case

Behavior
Break: ?.prop: set value: const!

Steps to Reproduce

  1. Build and install the app using this build command: mcconfig -d -m -p esp32
  2. See error

Expected behavior
Can update value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed - please verifyIssue has been fixed. Please verify and close.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions