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(compiler): don't throw when Symbol is used as DI token #13701

Merged
merged 1 commit into from
Mar 10, 2017

Conversation

DzmitryShylovich
Copy link
Contributor

@DzmitryShylovich DzmitryShylovich commented Dec 29, 2016

Closes #13314

@DzmitryShylovich DzmitryShylovich changed the title [WIP] fix(compiler): don't throw when Symbol is used as DI token Dec 29, 2016
@@ -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, '_');
Copy link
Contributor

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 ?

Copy link
Contributor Author

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?

Copy link
Contributor

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 vicb added area: core Issues related to the framework runtime action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Dec 29, 2016
@DzmitryShylovich
Copy link
Contributor Author

@vicb fixed

if (symbols.has(ref)) {
return symbols.get(ref);
}
const symbolStr = `${ref.toString().replace(/\(|\)/g, '_')}${symbolIndex++}`;
Copy link
Contributor

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'}]
Copy link
Contributor

Choose a reason for hiding this comment

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

and an override ?

@DzmitryShylovich
Copy link
Contributor Author

@vicb done

TestBed.configureTestingModule({
declarations: [CmpWithSymbol],
providers: [
{provide: SOME_SYMBOL, useValue: 'value'},
Copy link
Contributor

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'},

@DzmitryShylovich
Copy link
Contributor Author

@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>();
Copy link
Contributor

@vicb vicb Jan 3, 2017

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++}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

and symbolId

@DzmitryShylovich
Copy link
Contributor Author

@vicb done

@mhevery mhevery added action: merge The PR is ready for merge by the caretaker 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 Feb 10, 2017
@maxkoretskyi
Copy link

maxkoretskyi commented Feb 16, 2017

Is Symbol essentially a replacement for OpaqueToken ?

@DzmitryShylovich
Copy link
Contributor Author

nope

@maxkoretskyi
Copy link

maxkoretskyi commented Feb 16, 2017

It would be interesting to know what OpaqueToken can do that Symbol can't

@chuckjaz chuckjaz merged commit 8b5c6b2 into angular:master Mar 10, 2017
@DzmitryShylovich DzmitryShylovich deleted the gh/13314 branch March 10, 2017 23:28
SamVerschueren pushed a commit to SamVerschueren/angular that referenced this pull request Mar 18, 2017
mhevery added a commit to mhevery/angular that referenced this pull request Mar 20, 2017
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.
mhevery added a commit to mhevery/angular that referenced this pull request Mar 20, 2017
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
mhevery added a commit that referenced this pull request Mar 21, 2017
#13701)" (#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 #15183

PR Close #15319
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
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
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
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-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 11, 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 area: core Issues related to the framework runtime cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot create property '__anonymousType' on symbol
6 participants