This repository was archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
fix(compiler): Support camelCase property bindings #1462
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,12 @@ relaxFnArgs(Function fn) { | |
|
||
capitalize(String s) => s.substring(0, 1).toUpperCase() + s.substring(1); | ||
|
||
String camelCase(String s) { | ||
var part = s.split('-').map((s) => s.toLowerCase()); | ||
if (part.length <= 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: should be on one line or use {} |
||
return part.join(); | ||
return part.first + part.skip(1).map(capitalize).join(); | ||
} | ||
|
||
/// Returns whether or not the given identifier is a reserved word in Dart. | ||
bool isReservedWord(String identifier) => RESERVED_WORDS.contains(identifier); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
library utils_spec; | ||
|
||
import '_specs.dart'; | ||
import 'package:angular/utils.dart'; | ||
|
||
main() { | ||
describe('relaxFnApply', () { | ||
it('should work with 6 arguments', () { | ||
var sixArgs = [1, 1, 2, 3, 5, 8]; | ||
expect(relaxFnApply(() => "none", sixArgs)).toEqual("none"); | ||
expect(relaxFnApply((a) => a, sixArgs)).toEqual(1); | ||
expect(relaxFnApply((a, b) => a + b, sixArgs)).toEqual(2); | ||
expect(relaxFnApply((a, b, c) => a + b + c, sixArgs)).toEqual(4); | ||
expect(relaxFnApply((a, b, c, d) => a + b + c + d, sixArgs)).toEqual(7); | ||
expect(relaxFnApply((a, b, c, d, e) => a + b + c + d + e, sixArgs)).toEqual(12); | ||
}); | ||
|
||
it('should work with 0 arguments', () { | ||
var noArgs = []; | ||
expect(relaxFnApply(() => "none", noArgs)).toEqual("none"); | ||
expect(relaxFnApply(([a]) => a, noArgs)).toEqual(null); | ||
expect(relaxFnApply(([a, b]) => b, noArgs)).toEqual(null); | ||
expect(relaxFnApply(([a, b, c]) => c, noArgs)).toEqual(null); | ||
expect(relaxFnApply(([a, b, c, d]) => d, noArgs)).toEqual(null); | ||
expect(relaxFnApply(([a, b, c, d, e]) => e, noArgs)).toEqual(null); | ||
}); | ||
|
||
it('should fail with not enough arguments', () { | ||
expect(() { | ||
relaxFnApply((required, alsoRequired) => "happy", [1]); | ||
}).toThrowWith(message: 'Unknown function type, expecting 0 to 5 args.'); | ||
}); | ||
}); | ||
|
||
describe('camelCase', () { | ||
it('should ignore non camelCase', () { | ||
expect(camelCase('regular')).toEqual('regular'); | ||
}); | ||
|
||
it('should convert snake-case', () { | ||
expect(camelCase('snake-case')).toEqual('snakeCase'); | ||
}); | ||
|
||
it('should lowercase strings', () { | ||
expect(camelCase('Caps-first')).toEqual('capsFirst'); | ||
}); | ||
}); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
perf: only the first part need to be lowercased