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

feat(compiler): support directive selectors with attributes containing $ #41567

Closed

Conversation

iRealNirmal
Copy link
Contributor

@iRealNirmal iRealNirmal commented Apr 11, 2021

Added support for $ in attribtue type directive. This feaure is covered as the part of ticket #41244.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Currently directive selector isn't working if it has $ character in it.

Issue Number: 41244

What is the new behavior?

As per the feature requirement now directive attribute selector is support character $

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR @iRealNirmal.

Could you please add a unit test similar to https://github.com/angular/angular/blob/master/packages/compiler/test/selector/selector_spec.ts#L116-L127, which demonstrates this fix.

Also, can you modify the commit message slightly. It should not mention the issue number in the commit header, but instead have a Fixes. Close or Resolves at the bottom of the commit body. Something like:

feat(compiler): Support directive selectors with attributes containing `$`

This commit adds support for `$` in when selecting attributes.

Resolves #41244.

@petebacondarwin petebacondarwin added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler feature Issue that requests a new feature target: minor This PR is targeted for the next minor release labels Apr 11, 2021
@ngbot ngbot bot modified the milestone: Backlog Apr 11, 2021
@iRealNirmal iRealNirmal force-pushed the selector/added-feature-41244 branch 2 times, most recently from 08e7204 to 9e01ab1 Compare April 11, 2021 15:38
@iRealNirmal
Copy link
Contributor Author

iRealNirmal commented Apr 11, 2021

Thanks for submitting this PR @iRealNirmal.

Could you please add a unit test similar to https://github.com/angular/angular/blob/master/packages/compiler/test/selector/selector_spec.ts#L116-L127, which demonstrates this fix.

Also, can you modify the commit message slightly. It should not mention the issue number in the commit header, but instead have a Fixes. Close or Resolves at the bottom of the commit body. Something like:

feat(compiler): Support directive selectors with attributes containing `$`

This commit adds support for `$` in when selecting attributes.

Resolves #41244.

Thanks @petebacondarwin. I have taken care for your both of comment.

But I am not sure why test_aio_preview failed. Will you be able to provide any insight here ?

@petebacondarwin
Copy link
Member

Thanks @iRealNirmal - the second commit could have been a "fixup" commit. You can read more about this here: https://github.com/angular/angular/blob/master/docs/FIXUP_COMMITS.md.

Also I made a mistake the first letter of the commit header should not be uppercase.

Could you either change the second commit to a fixup, or just squash both commits into one?

@pullapprove pullapprove bot requested a review from atscott April 11, 2021 17:34
@iRealNirmal iRealNirmal force-pushed the selector/added-feature-41244 branch 3 times, most recently from 0a0a800 to 0ed65cb Compare April 12, 2021 01:23
@iRealNirmal iRealNirmal changed the title feat(compiler-cli): Add support for $ in attribute - ticket - 41244 feat(compiler): support directive selectors with attributes containing $ Apr 12, 2021
@iRealNirmal
Copy link
Contributor Author

@petebacondarwin let me know in case anything else needs to be done in this PR.

@crisbeto
Copy link
Member

Are we sure that we want to support this? If the selector doesn't match an output name and we end up trying to add it to the DOM, the browser will throw an error. See:
Screenshot at Apr 12 09-42-15

@petebacondarwin
Copy link
Member

Are we sure that we want to support this? If the selector doesn't match an output name and we end up trying to add it to the DOM, the browser will throw an error. See:
Screenshot at Apr 12 09-42-15

@crisbeto - That seems like a perfectly reasonable error message for using an attribute incorrectly, no? Or am I missing something? If there is no such output on a directive/component, then the AOT compiler would complain before it got to runtime, no?

@crisbeto
Copy link
Member

It's possible that I'm missing some context as well, but wouldn't this also allow for any attribute containing $? E.g. having a <div foo$></div> in a template.

@crisbeto
Copy link
Member

I just double-checked it and we already allow <div foo$></div>, even though it results in a runtime error. Please ignore my previous comment.

@petebacondarwin
Copy link
Member

I just double-checked it and we already allow <div foo$></div>, even though it results in a runtime error. Please ignore my previous comment.

Thanks for checking

@petebacondarwin petebacondarwin added action: presubmit The PR is in need of a google3 presubmit and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Apr 12, 2021
@iRealNirmal iRealNirmal force-pushed the selector/added-feature-41244 branch 2 times, most recently from 0503d35 to 17515b4 Compare April 30, 2021 07:15
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Please make sure that the following tests pass:

    it('should detect attr names with escaped $', () => {
      let cssSelector = CssSelector.parse('[attrname\\$]')[0];
      expect(cssSelector.attrs).toEqual(['attrname$', '']);
      expect(cssSelector.toString()).toEqual('[attrname\\$]');

      cssSelector = CssSelector.parse('[\\$attrname]')[0];
      expect(cssSelector.attrs).toEqual(['$attrname', '']);
      expect(cssSelector.toString()).toEqual('[\\$attrname]');

      cssSelector = CssSelector.parse('[foo\\$bar]')[0];
      expect(cssSelector.attrs).toEqual(['foo$bar', '']);
      expect(cssSelector.toString()).toEqual('[foo\\$bar]');
    });

    it('should error on attr names with unescaped $', () => {
      expect(() => CssSelector.parse('[attrname$]'))
          .toThrowError(
              'Error in attribute selector "attrname$". Unescaped "$" is not supported. Please escape with "\\$".');
      expect(() => CssSelector.parse('[$attrname]'))
          .toThrowError(
              'Error in attribute selector "$attrname". Unescaped "$" is not supported. Please escape with "\\$".');
      expect(() => CssSelector.parse('[foo$bar]'))
          .toThrowError(
              'Error in attribute selector "foo$bar". Unescaped "$" is not supported. Please escape with "\\$".');
      expect(() => CssSelector.parse('[foo\\$bar$]'))
          .toThrowError(
              'Error in attribute selector "foo\\$bar$". Unescaped "$" is not supported. Please escape with "\\$".');
    });

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Great! I restarted the failing jobs - they are most likely flakes.
Just one update to the tests are needed.

packages/compiler/test/selector/selector_spec.ts Outdated Show resolved Hide resolved
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Awesome work. Thanks @iRealNirmal

@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels May 1, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this PR 👍

I've added a comment to expand internal docs (add JSDoc for newly added functions), so that there is context to simplify future maintenance of that code.

packages/compiler/src/selector.ts Show resolved Hide resolved
@AndrewKushnir
Copy link
Contributor

Presubmit.

@iRealNirmal iRealNirmal force-pushed the selector/added-feature-41244 branch from 2e92150 to b61b580 Compare May 4, 2021 10:57
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

A couple of tiny fixes to the docs.

packages/compiler/src/selector.ts Outdated Show resolved Hide resolved
packages/compiler/src/selector.ts Show resolved Hide resolved
packages/compiler/src/selector.ts Outdated Show resolved Hide resolved
packages/compiler/src/selector.ts Outdated Show resolved Hide resolved
…g `$`

This commit adds support for `$` in when selecting attributes.

Resolves angular#41244.

test(language-service): Add test to expose bug caused by source file change (angular#41500)

This commit adds a test to expose the bug caused by source file change in
between typecheck programs.

PR Close angular#41500
@iRealNirmal iRealNirmal force-pushed the selector/added-feature-41244 branch from b61b580 to 2c9ff71 Compare May 4, 2021 11:09
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM!

@petebacondarwin petebacondarwin dismissed alxhub’s stale review May 4, 2021 11:12

The requested changes have been made.

@petebacondarwin petebacondarwin removed the request for review from alxhub May 4, 2021 11:12
@petebacondarwin petebacondarwin 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 May 4, 2021
@AndrewKushnir
Copy link
Contributor

Presubmit #2.

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label May 4, 2021
@mhevery mhevery closed this in 1758d02 May 5, 2021
@iRealNirmal iRealNirmal deleted the selector/added-feature-41244 branch May 5, 2021 05:15
@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 Jun 5, 2021
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 area: compiler Issues related to `ngc`, Angular's template compiler cla: yes feature Issue that requests a new feature target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants