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

add function for safely setting properties #2748

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

break-stuff
Copy link

@break-stuff break-stuff commented Nov 8, 2023

What I did

  1. Added a function to safely error when the spread operator tries to set "getter-only" properties

Copy link

changeset-bot bot commented Nov 8, 2023

🦋 Changeset detected

Latest commit: bc626e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@open-wc/lit-helpers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Nov 8, 2023

CLA assistant check
All committers have signed the CLA.

Comment on lines +19 to +21
"setup": "npm run setup:ts-configs && npm run setup:patch && npm run setup:playwright && npm run setup:postinstall",
"setup:patch": "npx patch-package",
"setup:playwright": "npx playwright install",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason Playwright changed their package to no longer install the browser instances with their package and now they need to be manually installed. This includes it as part of the setup. I can remove it, but nevs will need to run npx playwright install after each installation to ensure the browser instances are in sync the Playwright version.

Comment on lines +252 to +256
} else {
console.warn(
`Could not set property "${name}" on ${element.tagName} because it has no "setter".`,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to do something like https://github.com/thepassle/app-tools/tree/master/env so that console warnings can be trimmed from the final deployment in a production environment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! I was thinking the same thing, but wasn't sure if there was already a mechanism in place for this.

}

function hasSetter(element: Element, name: string) {
return !!Object.getOwnPropertyDescriptor(element.constructor.prototype, name)?.set;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@@ -45,6 +50,7 @@ describe('spread', () => {
number,
'.array': array,
'.object': object,
'.validity': undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the actual expectation associated with this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this being set, it should not crash the application, but I can't get the tests to run for some reason. Are you able to for the lit helpers? They didn't seem to be set up at all.

@jamiejojo
Copy link

jamiejojo commented Dec 27, 2023 via email

@break-stuff
Copy link
Author

Was this comment meant for something else?

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.

None yet

4 participants