Skip to content

JS in variables causes errors #192

Description

@ildar170975

Checklist:

  • I updated to the latest version available
  • I cleared the cache of my browser

Release with the issue: 2.0.0-b1

Last working release (if known): 1.3.7-beta.1

Browser and Operating System:
Chrome 145.0.7632.160
Win10x64

Description of problem:

This code used to work in 1.3.7-beta.1:

      - type: custom:config-template-card
        variables:
          child: |
            const c = "Use Me";
            c;
          parent: |
            (passed_var) => {
              const p = "Please " +
                (passed_var ? passed_var : child);
              return p;
            }
        entities:
          - sun.sun
        card:
          type: entities
          entities:
            - entity: sun.sun
              name: ${parent('xxx')}
            - entity: sun.sun
              name: ${parent()}
Image

But it did not work in 1.3.6 & does not in the latest 2.0.0-b1.

Javascript errors shown in the web inspector (if applicable):

Error with 1.3.6:

Uncaught (in promise) ReferenceError: child is not defined
    at eval (eval at _evaluateTemplate (config-template-card.js?hacstag=172177543136:905:34), <anonymous>:3:32)
    at eval (eval at _evaluateTemplate (config-template-card.js?hacstag=172177543136:912:16), <anonymous>:3:1)
    at ConfigTemplateCard._evaluateTemplate (config-template-card.js?hacstag=172177543136:912:16)
    at config-template-card.js?hacstag=172177543136:860:40
    at Array.forEach (<anonymous>)
    at ConfigTemplateCard._evaluateConfig (config-template-card.js?hacstag=172177543136:849:32)
    at ConfigTemplateCard._evaluateArray (config-template-card.js?hacstag=172177543136:874:33)
    at config-template-card.js?hacstag=172177543136:854:40
    at Array.forEach (<anonymous>)
    at ConfigTemplateCard._evaluateConfig (config-template-card.js?hacstag=172177543136:849:32)

Error with 2.0.0-b1:

VM478375:3 Uncaught (in promise) SyntaxError: Unexpected token 'const'
    at new Function (<anonymous>)
    at h (config-template-card.js?hacstag=1721775432001:39:4725)
    at $t._evaluateTemplate (config-template-card.js?hacstag=1721775432001:39:5233)
    at config-template-card.js?hacstag=1721775432001:39:4260
    at Array.forEach (<anonymous>)
    at $t._evaluateConfig (config-template-card.js?hacstag=1721775432001:39:4075)
    at $t._evaluateArray (config-template-card.js?hacstag=1721775432001:39:4420)
    at config-template-card.js?hacstag=1721775432001:39:4145
    at Array.forEach (<anonymous>)
    at $t._evaluateConfig (config-template-card.js?hacstag=1721775432001:39:4075)

Additional information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions