2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-09-27 20:12:25 -04:00
|
|
|
import {Component} from '@angular/core';
|
feat(upgrade): return a function (instead of array) from `downgradeInjectable()` (#14037)
This makes it more consistent with the dynamic version of `upgrade` and makes it
possible to share code between the dynamic and static versions.
This commit also refactors the file layout, moving common and dynamic-specific
files to `common/` and `dynamic/` directories respectively and renaming `aot/`
to `static/`.
Some private keys, used as AngularJS DI tokens, have also been renamed, but this
should not affect apps, since these keys are undocumented and not supposed to
be used externally.
BREAKING CHANGE:
Previously, `upgrade/static/downgradeInjectable` returned an array of the form:
```js
['dep1', 'dep2', ..., function factory(dep1, dep2, ...) { ... }]
```
Now it returns a function with an `$inject` property:
```js
factory.$inject = ['dep1', 'dep2', ...];
function factory(dep1, dep2, ...) { ... }
```
It shouldn't affect the behavior of apps, since both forms are equally suitable
to be used for registering AngularJS injectable services, but it is possible
that type-checking might fail or that current code breaks if it relies on the
returned value being an array.
2017-01-13 09:20:28 -05:00
|
|
|
import {getComponentInfo, parseFields} from '@angular/upgrade/src/dynamic/metadata';
|
2015-08-06 16:19:29 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('upgrade metadata', () => {
|
2015-10-01 16:14:59 -04:00
|
|
|
it('should extract component selector', () => {
|
2017-01-13 17:36:16 -05:00
|
|
|
expect(getComponentInfo(ElementNameComponent).selector).toBe('element-name-dashed');
|
2015-10-01 16:14:59 -04:00
|
|
|
});
|
2015-08-06 16:19:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
describe('errors', () => {
|
|
|
|
it('should throw on missing selector', () => {
|
2015-10-01 16:14:59 -04:00
|
|
|
expect(() => getComponentInfo(NoAnnotationComponent))
|
2016-06-22 17:58:57 -04:00
|
|
|
.toThrowError('No Directive annotation found on NoAnnotationComponent');
|
2015-08-06 16:19:29 -04:00
|
|
|
});
|
|
|
|
});
|
2015-10-01 16:14:59 -04:00
|
|
|
|
|
|
|
describe('parseFields', () => {
|
|
|
|
it('should process nulls', () => { expect(parseFields(null)).toEqual([]); });
|
|
|
|
|
|
|
|
it('should process values', () => {
|
2016-06-08 19:38:52 -04:00
|
|
|
expect(parseFields([' name ', ' prop : attr '])).toEqual([
|
2017-01-13 17:36:16 -05:00
|
|
|
jasmine.objectContaining({
|
2016-06-08 19:38:52 -04:00
|
|
|
prop: 'name',
|
|
|
|
attr: 'name',
|
|
|
|
bracketAttr: '[name]',
|
|
|
|
parenAttr: '(name)',
|
|
|
|
bracketParenAttr: '[(name)]',
|
|
|
|
onAttr: 'onName',
|
|
|
|
bindAttr: 'bindName',
|
|
|
|
bindonAttr: 'bindonName'
|
2017-01-13 17:36:16 -05:00
|
|
|
}),
|
|
|
|
jasmine.objectContaining({
|
2016-06-08 19:38:52 -04:00
|
|
|
prop: 'prop',
|
|
|
|
attr: 'attr',
|
|
|
|
bracketAttr: '[attr]',
|
|
|
|
parenAttr: '(attr)',
|
|
|
|
bracketParenAttr: '[(attr)]',
|
|
|
|
onAttr: 'onAttr',
|
|
|
|
bindAttr: 'bindAttr',
|
|
|
|
bindonAttr: 'bindonAttr'
|
2017-01-13 17:36:16 -05:00
|
|
|
})
|
2016-06-08 19:38:52 -04:00
|
|
|
]);
|
2015-10-01 16:14:59 -04:00
|
|
|
});
|
2016-07-21 20:12:00 -04:00
|
|
|
});
|
2015-08-06 16:19:29 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
@Component({selector: 'element-name-dashed', template: ``})
|
2015-08-06 16:19:29 -04:00
|
|
|
class ElementNameComponent {
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
@Component({selector: '[attr-name]', template: ``})
|
2015-08-06 16:19:29 -04:00
|
|
|
class AttributeNameComponent {
|
|
|
|
}
|
|
|
|
|
|
|
|
class NoAnnotationComponent {}
|