-
Notifications
You must be signed in to change notification settings - Fork 26.6k
fix(compiler): don't throw when Symbol is used as DI token #13701
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
Conversation
@@ -90,6 +90,9 @@ export function identifierName(compileIdentifier: CompileIdentifierMetadata): st | |||
if (ref instanceof StaticSymbol) { | |||
return ref.name; | |||
} | |||
if (typeof ref === 'symbol') { | |||
return ref.toString().replace(/\(|\)/g, '_'); |
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.
But Symbol("foo") !== Symbol("foo")
- we should probably use a (Weak)Map
?
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.
But Symbol("foo") !== Symbol("foo")
we can add a counter to ensure uniqueness
${ref.toString().replace(/\(|\)/g, '_')}${counter++}
use a (Weak)Map ?
what will be the key?
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.
we can add a counter to ensure uniqueness
Then you could not override the token, no ? (same Symbol will generate 2 different IDs)
what will be the key?
the Symbol instance ?
@vicb fixed |
if (symbols.has(ref)) { | ||
return symbols.get(ref); | ||
} | ||
const symbolStr = `${ref.toString().replace(/\(|\)/g, '_')}${symbolIndex++}`; |
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.
could you make it _symbol_${_sanitizeIdentifier(ref.toString())}_${symbolIndex++}
|
||
TestBed.configureTestingModule({ | ||
declarations: [CmpWithSymbol], | ||
providers: [{provide: SOME_SYMBOL, useValue: 'value'}] |
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.
and an override ?
@vicb done |
TestBed.configureTestingModule({ | ||
declarations: [CmpWithSymbol], | ||
providers: [ | ||
{provide: SOME_SYMBOL, useValue: 'value'}, |
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.
{provide: SOME_SYMBOL, useValue: 'value'},
{provide: SOME_SYMBOL, useValue: 'override'},
@vicb comment is addressed |
@@ -81,6 +81,8 @@ function _sanitizeIdentifier(name: string): string { | |||
} | |||
|
|||
let _anonymousTypeIndex = 0; | |||
let symbolIndex = 0; | |||
const symbols = new Map<Symbol, string>(); |
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.
please rename to symbolIds
if (symbols.has(ref)) { | ||
return symbols.get(ref); | ||
} | ||
const symbolStr = `_symbol_${_sanitizeIdentifier(ref.toString())}_${symbolIndex++}`; |
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.
and symbolId
@vicb done |
Is Symbol essentially a replacement for OpaqueToken ? |
nope |
It would be interesting to know what OpaqueToken can do that Symbol can't |
angular#13701)" This reverts commit 8b5c6b2. This feature is not compatible with the `Injector.get` which now only takes `Type` or `InjectableToken`. `Symbol` is not a valid type. Closes angular#15183
angular#13701)" (angular#15319) This reverts commit 8b5c6b2. This feature is not compatible with the `Injector.get` which now only takes `Type` or `InjectableToken`. `Symbol` is not a valid type. Closes angular#15183 PR Close angular#15319
angular#13701)" (angular#15319) This reverts commit 8b5c6b2. This feature is not compatible with the `Injector.get` which now only takes `Type` or `InjectableToken`. `Symbol` is not a valid type. Closes angular#15183 PR Close angular#15319
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #13314