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

refactor(ivy): flatten css selectors #23074

Closed
wants to merge 4 commits into from
Closed

Conversation

kara
Copy link
Contributor

@kara kara commented Mar 29, 2018

This PR flattens the CSS selectors generated for directives and components. This should help directives to generate less code, and will make selectors generally friendlier to work with.

Simple selector:
selector: 'div'

Parsed (before):

selector: [[['div'], null]]

Parsed (after):

selectors: [['div']]

Complex selector:
selector: 'div.foo[title=title]:not([bar]):not(.baz), [test]'

Parsed (before):

selector:  [
  [['div', 'title', 'title', 'class', 'foo'], [[ '', 'bar', '' ], ['', 'class', 'baz']]] , 
  [['', 'test', ''], null] 
]

Parsed (after, with flags written out for clarity):

selectors: [
   [ 'div', 'title', 'title',  SelectorFlags.CLASS, 'foo', 
      SelectorFlags.NOT|SelectorFlags.ATTRIBUTE, 'bar', 
      SelectorFlags.NOT|SelectorFlags.CLASS, 'baz'], 
   ['', 'test', '']
]

Because SelectorFlags is a const enum, the real output will be a number (see below):

Parsed (after, actual):

selectors: [
   [ 'div', 'title', 'title',  8, 'foo', 3, 'bar', 9, 'baz'], 
   ['', 'test', '']
]

Notes:

  • I also changed selector to selectors in DirectiveDef because I think it clarifies that it is a list of selectors for the directive, as opposed to one selector.

First commit: updates runtime
Second commit: updates compiler

@kara kara added action: review The PR is still awaiting reviews from at least one requested reviewer refactoring Issue that involves refactoring or code-cleanup comp: ivy target: major This PR is targeted for the next major release labels Mar 30, 2018
@kara kara requested a review from mhevery March 30, 2018 01:13
*/
export type SimpleCssSelector = string[];
export type CssSelector = (string | number)[];
Copy link
Contributor

@mhevery mhevery Mar 30, 2018

Choose a reason for hiding this comment

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

I think this should be number => SelectorFlags?

@kara
Copy link
Contributor Author

kara commented Mar 30, 2018

presubmit

@kara kara added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 30, 2018
@alxhub alxhub closed this in 6e5fb99 Mar 30, 2018
alxhub pushed a commit that referenced this pull request Mar 30, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes refactoring Issue that involves refactoring or code-cleanup target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants