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

Fix component script param parse if its a function #5565

Closed
wants to merge 1 commit into from

Conversation

xQwexx
Copy link
Contributor

@xQwexx xQwexx commented Dec 18, 2023

I tried to add script param for a component but it was having an error

const script = ()=>{
  const el: HTMLDivElement = this as any;
  console.log(el.id)
  // this is bound to the component element
  console.log('the element', this);
};

because it was converted to:

ƒ () {
    var el = _this;
    console.log(el.id);
    // this is bound to the component element
    console.log('the element', _this);
}

@artf
Copy link
Member

artf commented Dec 23, 2023

I think there is more of an issue with the compiler as you're using this and an array function (so the bundler tries to keep this context for you).
I'd simply avoid using array functions with component scripts as the context is never the same and that might bring similar issues.
Anyway, replacing blindly replaceAll('_this', 'this') will never be a solid fix as you risk replacing something unintentionally (considering in JS you can do a lot of dynamic stuff)

@artf artf closed this Dec 23, 2023
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

Successfully merging this pull request may close these issues.

2 participants