-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate Ember object types in resolver
This commit adds assertions to ensure that some key object types are validated when they are resolved: * Routes * Components * Views * Services I did not add a validation for controller classes because the implementation for detection would need to be a little different and some of Ember's tests play fast (and loose) with with the types of things they try to pass off as controllers. For now I don't think this additional validation is worth adding given imminent demise of Controllers.
- Loading branch information
1 parent
37f4325
commit a876722
Showing
8 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,25 @@ | ||
/** | ||
@module ember | ||
@submodule ember-application | ||
*/ | ||
|
||
let VALIDATED_TYPES = { | ||
route: ['isRouteFactory', 'Ember.Route'], | ||
component: ['isComponentFactory', 'Ember.Component'], | ||
view: ['isViewFactory', 'Ember.View'], | ||
service: ['isServiceFactory', 'Ember.Service'] | ||
}; | ||
|
||
export default function validateType(resolvedType, parsedName) { | ||
let validationAttributes = VALIDATED_TYPES[parsedName.type]; | ||
|
||
if (!validationAttributes) { | ||
return; | ||
} | ||
|
||
let [factoryFlag, expectedType] = validationAttributes; | ||
|
||
Ember.assert(`Expected ${parsedName.fullName} to resolve to an ${expectedType} but instead it was ${resolvedType}.`, function() { | ||
return resolvedType[factoryFlag]; | ||
}); | ||
} |
This file contains 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 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 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 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 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 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