-
-
Notifications
You must be signed in to change notification settings - Fork 80
Remove generated/properties in favor of direct mixin #278
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
base: main
Are you sure you want to change the base?
Conversation
|
This is extremely exciting. Thank you for all your work to get us to this point. Now that I compare the generated code before and after, I see what a good idea this is. It is also great to remove the complicated codegen dependencies. However, I think we can go even further. The architecture in this PR does the following:
This approach is much better than the previous approach, which generated a lot of redundant code for the generic handlers. However, it does a lot of work at startup. We could do better by changing the build-time script to generate "use strict";
const backgroundImage = require("background-image");
const { getGenericPropertyDescriptor } = require("../utils/propertyDescriptors.js");
module.exports = {
// ...
"background-image": backgroundImage,
"backgroundImage": backgroundImage
// ...
"block-ellipsis": getGenericPropertyDescriptor("block-ellipsis"),
"blockEllipsis": getGenericPropertyDescriptor("block-ellipsis")
// ...
};Then, we do not need your new const propertyDescriptors = require("./generated/propertyDescriptors.js");
const propertyNames = require("./generated/allProperties.js");
// ...
if (!propertyNames.has(property)) {
// ...
Object.defineProperties(CSSStyleDeclaration.prototype, propertyDescriptors);What do you think? |
We only use camelize for scripts.
|
PR ready. |
|
Additional notes:
|
|
No, please use the proper term, "propertyDescriptors". See, e.g., https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#description . We should, as a lower-priority future to-do, fix the exports from the property handler files to be But, the hardest part of reviewing this PR was properly distinguishing the three things:
We should not use the term "handlers" for (2). Only for (3). |
32a91db to
e0c6d48
Compare
|
PR ready. |
domenic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great, just a few more tweaks.
| for (const property of styleDeclaration) { | ||
| descriptors.push(`"${property}": ${camel}.definition`); | ||
| } | ||
| } else if (camelCasedProperties.has(aliasCamel)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch is never hit (and never should be hit; we should always ensure the files are named after their canonical property names).
Delete it and delete all the stuff around aliasCamel and legacyAliasOf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I would like to maintain the current implementation.
As mentioned in the comment below, the conditions here are not met because we don't prepare a standard implementation.
Even after implementing webkit-foo standardization and not hit here, I would like to remove it at that time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this, sorry. This code is literally never executed. It is dead code. And it is new code. I would like to not commit new code that is never run to this repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
|
|
||
| const list = fs | ||
| .readdirSync(path.resolve(dirname, "../lib/properties")) | ||
| .map((file) => file.replace(/\.[cm]?js$/, "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if we were a bit more careful with file extensions:
- Don't get rid of them here. It's nicer if the generated
require()s contain file extensions. This works better in the future if we move to ESM, and is slightly faster today. - Don't be tolerant of
\.[cm]?js. Only accept\.js. If we change our file extensions in the future, we can change this script. Accepting different extensions now just lets the project be inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed \.[cm]?js, and added file extension like properties/foo.js in require().
| // autogenerated - ${dateTodayFormatted} | ||
| ${requires.sort().join("\n")} | ||
| const { getPropertyDescriptor } = require("../utils/propertyDescriptors"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const { getPropertyDescriptor } = require("../utils/propertyDescriptors"); | |
| const { getPropertyDescriptor } = require("../utils/propertyDescriptors.js"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
test/CSSStyleDeclaration.test.js
Outdated
| }); | ||
|
|
||
| it("has all functions", () => { | ||
| it("has all camelCase properties", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this into a smoke test instead of an exhaustive test. Just pick one property and test that its camelCase version is there manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
test/CSSStyleDeclaration.test.js
Outdated
| }); | ||
|
|
||
| it("has PascalCase for webkit prefixed properties", () => { | ||
| it("has PascalCase property for all webkit prefixed properties", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly just pick a single one that we know should have WebKit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
While writing up #279, I noticed something interesting we should probably fix in this PR. Previously, After this PR, Per my initial thoughts in #279, I think this is OK. We can have a breaking change that removes all properties not in the But, we should delete the dead code ASAP. I think doing it in this PR would be best. You should be able to quickly ask an AI to delete all files in If you think deleting these files loses valuable code, then we should stop to reconsider and discuss. But I think it will probably be fine. |
|
Also, sorry, some of my drafts from an earlier revision seem to have been kept in my latest review. I will go mark them all as resolved. |
This is tracked in #210. Some things have been standardized in I'm planning to address this before making the major bump. |
|
Let me a bit more clear on the requirements for this PR. Either:
OR
I prefer (2). But if you prefer (1), we need to do some work there too. |
I think these two things are not in conflict. |
I'm talking about things like It has been standardized, but renamed. |
I also prefer 2, but in a separate PR to address that issue. |
We should not include support for non-standardized aliases like
OK. So will you do 1 in this PR? |
Motivation
This PR refactors the property handling mechanism.
generated/properties.jsis a duplicate of the logic already present inproperties/*.js.By referencing
properties/*.jsdirectly from the newgenerated/propertyHandlers.js, we eliminate this redundancy and ensure a single source of truth for property definitions.Part of #255 (comment)
However, this PR does not include a fix for
CSSStyleDeclarationitself.Planning to address it in a separate PR.
Key Changes
scripts/generatePropertyHandlers.mjs, which generatesgenerated/propertyHandlers.jsthat directly references definitions inproperties/*.js../property.jsto manage property definitions dinamically.CSSStyleDeclarationto usepropertyDefinitionsand themixinProperties()function from./property.js.