Skip to content

Can't pass this to template in the runtime compiler #21096

@boris-petrov

Description

@boris-petrov

🐞 Describe the Bug

Check the repro.

🔬 Minimal Reproduction

import TemplateCompiler from '@ember/template-compiler/runtime';
...
  test('asd', async function (assert) {
    this.cls = 'asd';
    await render(TemplateCompiler.template('<div>{{this.cls}}</div>', { scope: () => ({ this: this }) }));
    assert.dom().hasText('asd');
  });

😕 Actual Behavior

SyntaxError: Unexpected token 'this'
    at new Function (<anonymous>)

🤔 Expected Behavior

No error.

🌍 Environment

  • Ember: 6.10.1
  • Ember-CLI: 6.10.2
  • Node.js/npm: v25.6.1
  • OS: Linux
  • Browser: Any

➕ Additional Context

The problem is on this line:

return new Function(...argNames, `return (${source})`)(...argValues);

Can't create a function with this as an argument name.

cc @NullVoxPopuli

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions