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

fix(ngcc): do not output duplicate ɵprov properties #34085

Closed

Conversation

@petebacondarwin
Copy link
Member

petebacondarwin commented Nov 27, 2019

Previously, the Angular AOT compiler would always add a
ɵprov to injectables. But in ngcc this resulted in duplicate ɵprov
properties since published libraries already have this property.

Now in ngtsc, trying to add a duplicate ɵprov property is an error,
while in ngcc the additional property is silently not added.

// FW-1750

@petebacondarwin petebacondarwin requested review from angular/fw-compiler as code owners Nov 27, 2019
@ngbot ngbot bot added this to the needsTriage milestone Nov 27, 2019
@googlebot googlebot added the cla: yes label Nov 27, 2019
@petebacondarwin petebacondarwin force-pushed the petebacondarwin:ngcc-repeated-prov branch 2 times, most recently from 4cb2e28 to aea73e4 Nov 27, 2019
@petebacondarwin petebacondarwin requested a review from angular/fw-size-tracking as a code owner Nov 27, 2019
Copy link
Member

IgorMinar left a comment

A few nits but overall lgtm. Thank you

/**
* An injectable already has a `ɵprov` property.
*/
INJECTABLE_DUPLICAGE_PROV = 9001

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Nov 27, 2019

Member

DUPLICATE_INJECTABLE_PROV?

This comment has been minimized.

Copy link
@petebacondarwin

petebacondarwin Nov 27, 2019

Author Member

I'll fix the typo... :-)

I was following the "sort of" convention in this file of putting the "scope" e.g. INJECTABLE at the start of the error code. For example:

  DECORATOR_ARG_NOT_LITERAL = 1001,
  DECORATOR_ARITY_WRONG = 1002,
  DECORATOR_NOT_CALLED = 1003,
  DECORATOR_ON_ANONYMOUS_CLASS = 1004,
  DECORATOR_UNEXPECTED = 1005,
  ...
  NGMODULE_INVALID_DECLARATION = 6001,
  NGMODULE_INVALID_IMPORT = 6002,
  NGMODULE_INVALID_EXPORT = 6003,
  ...

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Nov 27, 2019

Member

ok. sgtm

function countOccurrences(haystack: string, needle: string): number {
const regex = new RegExp(needle, 'g');
let count = 0;
while (regex.exec(haystack)) {

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Nov 27, 2019

Member

How does this work? You are not mutating the haystack so how do you exit the loop?

This comment has been minimized.

Copy link
@petebacondarwin

petebacondarwin Nov 27, 2019

Author Member

Each time you execute the regex it starts from the previous position.

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Nov 27, 2019

Member

it does?!?!? so it stores the state? how did I not know this! thanks

This comment has been minimized.

Copy link
@gkalpak

gkalpak Nov 28, 2019

Member

I am late to the party, but here are some fun facts:

  • There is a (kind of) bug in RegExp#exec(), so that you can get stuck in an infinite loop when the RegExp accepts zero-length matches. E.g.
    const re = /\d*/g;
    while (re.exec('1a2b')) console.log('Infinite loop \\o/');
    To avoid it, you need to manually do re.lastIndex += 1 on zero-length matches.
  • Other methods are not susceptible to this issue. So, using haystack.match(needle) would avoid this pitfall (and be sorter 😉).

This comment has been minimized.

Copy link
@petebacondarwin

petebacondarwin Nov 28, 2019

Author Member

String.match() is what I was looking for!

@petebacondarwin petebacondarwin force-pushed the petebacondarwin:ngcc-repeated-prov branch from aea73e4 to 10d1d10 Nov 27, 2019
Previously, the Angular AOT compiler would always add a
`ɵprov` to injectables. But in ngcc this resulted in duplicate `ɵprov`
properties since published libraries already have this property.

Now in ngtsc, trying to add a duplicate `ɵprov` property is an error,
while in ngcc the additional property is silently not added.

// FW-1750
@petebacondarwin petebacondarwin force-pushed the petebacondarwin:ngcc-repeated-prov branch from 10d1d10 to fad3834 Nov 27, 2019
Copy link
Member

IgorMinar left a comment

merge-assistance: global approval

@IgorMinar

This comment has been minimized.

Copy link
Member

IgorMinar commented Nov 27, 2019

mhevery added a commit that referenced this pull request Nov 27, 2019
Previously, the Angular AOT compiler would always add a
`ɵprov` to injectables. But in ngcc this resulted in duplicate `ɵprov`
properties since published libraries already have this property.

Now in ngtsc, trying to add a duplicate `ɵprov` property is an error,
while in ngcc the additional property is silently not added.

// FW-1750

PR Close #34085
@mhevery mhevery closed this in 2fb9b7f Nov 27, 2019
@petebacondarwin petebacondarwin deleted the petebacondarwin:ngcc-repeated-prov branch Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.