Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable evaluate JavaScript in stache expression. #197

Closed
1 of 5 tasks
Lighttree opened this issue Nov 27, 2018 · 3 comments
Closed
1 of 5 tasks

Unable evaluate JavaScript in stache expression. #197

Lighttree opened this issue Nov 27, 2018 · 3 comments
Assignees

Comments

@Lighttree
Copy link

How often can you reproduce it?

  • Always
  • Sometimes
  • Rarely
  • Unable
  • I didn’t try

JavaScript statement inside {{expressions}} throws TypeError:

Uncaught TypeError: Invalid value used as weak map key
    at WeakMap.set (<anonymous>)
    at Object.addMutatedBy (ecosystem.mjs:12556)
    at callMutateWithRightArgs (ecosystem.mjs:17854)
    at ScopeKeyData.read (ecosystem.mjs:18058)
    at Observation.onBound (ecosystem.mjs:5498)
    at KeyTree.add (ecosystem.mjs:4681)
    at Observation.on (ecosystem.mjs:4956)
    at Object.onValue (ecosystem.mjs:1101)
    at ScopeKeyData.onBound (ecosystem.mjs:17940)
    at KeyTree.add (ecosystem.mjs:4681)

Steps to reproduce:

https://codepen.io/Lighttree/pen/eQjzwy?editors=1010

Expected results:

Before it was possible to evaluate JavaScript inside {{expressions}}.

Actual results:

Inline JavaScript evaluation doesn't work anymore.

Environment:

Software Version
can-stache version 4+
Browser Chrome
Operating system Windows
@Lighttree
Copy link
Author

Lighttree commented Nov 27, 2018

Seems like not all code fails. For example I had following:

ViewModel:

contextTitle: {
  value() {
    return this.context
      .split('_')
      .map(word => word.charAt(0).toUpperCase() + word.slice(1))
      .join(' ');
  }
}

Stache:

<h1>
    {{contextTitle.split(' ')[0]}} <span class="styled">{{contextTitle.split(' ')[1]}}</span>
</h1>

This case fails.

I found some workaround for my case that works:

ViewModel:

contextTitle: {
  value() {
    return this.context
      .split('_')
      .map(word => word.charAt(0).toUpperCase() + word.slice(1));
  }
}

Stache:

<h1>
    {{contextTitle[0]}} <span class="styled">{{contextTitle[1]}}</span>
</h1>

... some other place ...

<h2 class="headline2">
  {{ i18n('txt_my_events_lbl', event_type=contextTitle.join(' ')) }}
</h2>

@justinbmeyer
Copy link
Contributor

It was never possible to evaluate all JS expression types. However, these call expressions should work.

@justinbmeyer justinbmeyer self-assigned this Nov 27, 2018
@justinbmeyer
Copy link
Contributor

Given the error, I'm not sure this is a stache problem.

@justinbmeyer justinbmeyer transferred this issue from canjs/can-stache Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants