-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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(compiler): don't throw when Symbol is used as DI token #13701
Conversation
ee4ba8b
to
df2c0d2
Compare
df2c0d2
to
3c26161
Compare
@@ -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 ?
aa0955b
to
29d21e4
Compare
@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 |
139b1b9
to
1575a13
Compare
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'},
1575a13
to
a6449a6
Compare
@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
a6449a6
to
0061388
Compare
@vicb done |
Is Symbol essentially a replacement for OpaqueToken ? |
nope |
It would be interesting to know what OpaqueToken can do that Symbol can't |
0061388
to
630278a
Compare
630278a
to
d76fad7
Compare
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.
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