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

Animations: CSS calc/var polyfill parser #9287

Merged
merged 3 commits into from May 17, 2017
Merged

Conversation

dvoytenko
Copy link
Contributor

Partial for #9129.

This PR is only concerned with grammar and parser. Evaluations will be added in the follow-up PRs.

set = nodeOrSet;
} else {
set = new CssConcatNode();
set.array_.push(nodeOrSet);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: pass this as a constructor argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

set.array_.push(nodeOrSet);
}
if (otherNodeOrSet instanceof CssConcatNode) {
set.array_.concat(otherNodeOrSet.array_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: implement this as a instance method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to avoid construction and state leaking into public methods of AST nodes. I'd rather it all be fully compressed to this module only and preserve full obfuscation of these details on compiler level.

super();
/** @const @private {string} */
this.name_ = endsWith(name, '(') ?
name.substring(0, name.length - 1) : name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: name.slice(0, -1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* A CSS `calc()` expression: `calc(100px)`, `calc(80vw - 30em)`, etc.
* See https://drafts.csswg.org/css-values-3/#calc-notation.
*/
export class CssCalcNode extends CssNode {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this just a CssFuncNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically no. calc() and var() are expressions - they resolve in actual values. While translate(), rotate() and such are actual CSS functions. The formats within are very different, e.g. + and - are only possible in calc() and no , args. Implementation-wise they will also differ a lot with calc() and var() actually resolving to final values, e.g. 100px.

/**
* A CSS `calc()` product expression: `100px * 2`, `80vw / 2`, etc.
*/
export class CssCalcProductNode extends CssNode {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can we join this with the above and call them CssCalcBinaryNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could and may still do so later. But implementation-wise per spec they are super different. So not sure if I'll win anything if I do at this time.

Y [Yy]
Z [Zz]

num [+-]?[0-9]+(\.[0-9]+)?([eE][+\-]?[0-9]+)?|[+-]?"."[0-9]+([eE][+\-]?[0-9]+)?
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the "." be \.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. These and all others actually come directly from CSS spec (https://www.w3.org/TR/CSS22/grammar.html) and such.

{num}{M}{S} return 'TIME_MS'
{num}{S} return 'TIME_S'

{num}"%" return 'PERCENTAGE'
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Alignment is off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Z [Zz]

num [+-]?[0-9]+(\.[0-9]+)?([eE][+\-]?[0-9]+)?|[+-]?"."[0-9]+([eE][+\-]?[0-9]+)?
hex [a-fA-F0-9]+
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make this stricter? [a-fA-F0-9]{3}|[a-fA-F0-9]{6}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CSS spec is super relaxed about colors for some reason. So, i'd rather keep.

constructor(name, args) {
super();
/** @const @private {string} */
this.name_ = endsWith(name, '(') ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we parse out the (?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@dvoytenko
Copy link
Contributor Author

PTAL

@dvoytenko dvoytenko requested a review from aghassemi May 15, 2017 18:26
set = new CssConcatNode([nodeOrSet]);
}
if (otherNodeOrSet instanceof CssConcatNode) {
set.array_.concat(otherNodeOrSet.array_);
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be reassigned to set.array_

also concat works with non-array single values, so two cases could be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! Fixed and added tests for this as well.

expect(parsePseudo('10s')).to.equal('TME<10 S>');
});

it('should parse url', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe validator has special rules for valid values of url, need to apply the same rules, either at parse or eval time (being being passed through)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. We simply need to control that this is not a http URL.

@dvoytenko
Copy link
Contributor Author

@aghassemi thanks! ptal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants