refactor(compiler-cli): rename `$ngDeclareDirective`/`$ngDeclareComponent` to use `ɵɵ` prefix (#39518)
For consistency with other generated code, the partial declaration functions are renamed to use the `ɵɵ` prefix which indicates that it is generated API. This commit also removes the declaration from the public API golden file, as it's not yet considered stable at this point. Once the linker is finalized will these declaration function be included into the golden file. PR Close #39518
This commit is contained in:
parent
87e9cd643b
commit
306a1307c7
|
@ -1,6 +1,3 @@
|
|||
/** @codeGenApi */
|
||||
export declare function $ngDeclareDirective(decl: unknown): unknown;
|
||||
|
||||
export declare interface AbstractType<T> extends Function {
|
||||
prototype: T;
|
||||
}
|
||||
|
|
|
@ -59,9 +59,9 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
transformSync(
|
||||
[
|
||||
'var core;',
|
||||
`$ngDeclareDirective({version: 1, ngImport: core, x: 1});`,
|
||||
`$ngDeclareComponent({version: 1, ngImport: core, foo: () => $ngDeclareDirective({version: 1, ngImport: core, x: 2})});`,
|
||||
`x.qux(() => $ngDeclareDirective({version: 1, ngImport: core, x: 3}));`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core, x: 1});`,
|
||||
`ɵɵngDeclareComponent({version: 1, ngImport: core, foo: () => ɵɵngDeclareDirective({version: 1, ngImport: core, x: 2})});`,
|
||||
`x.qux(() => ɵɵngDeclareDirective({version: 1, ngImport: core, x: 3}));`,
|
||||
'spread(...x);',
|
||||
].join('\n'),
|
||||
{
|
||||
|
@ -71,13 +71,13 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
});
|
||||
|
||||
expect(humanizeLinkerCalls(linkSpy.calls)).toEqual([
|
||||
['$ngDeclareDirective', '{version:1,ngImport:core,x:1}'],
|
||||
['ɵɵngDeclareDirective', '{version:1,ngImport:core,x:1}'],
|
||||
[
|
||||
'$ngDeclareComponent',
|
||||
'{version:1,ngImport:core,foo:()=>$ngDeclareDirective({version:1,ngImport:core,x:2})}'
|
||||
'ɵɵngDeclareComponent',
|
||||
'{version:1,ngImport:core,foo:()=>ɵɵngDeclareDirective({version:1,ngImport:core,x:2})}'
|
||||
],
|
||||
// Note we do not process `x:2` declaration since it is nested within another declaration
|
||||
['$ngDeclareDirective', '{version:1,ngImport:core,x:3}']
|
||||
['ɵɵngDeclareDirective', '{version:1,ngImport:core,x:3}']
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -89,8 +89,8 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
const result = transformSync(
|
||||
[
|
||||
'var core;',
|
||||
'$ngDeclareDirective({version: 1, ngImport: core});',
|
||||
'$ngDeclareDirective({version: 1, ngImport: core, foo: () => bar({})});',
|
||||
'ɵɵngDeclareDirective({version: 1, ngImport: core});',
|
||||
'ɵɵngDeclareDirective({version: 1, ngImport: core, foo: () => bar({})});',
|
||||
'x.qux();',
|
||||
'spread(...x);',
|
||||
].join('\n'),
|
||||
|
@ -109,9 +109,9 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
[
|
||||
'import * as core from \'some-module\';',
|
||||
'import {id} from \'other-module\';',
|
||||
`$ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`$ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`$ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
].join('\n'),
|
||||
{
|
||||
plugins: [createEs2015LinkerPlugin()],
|
||||
|
@ -130,9 +130,9 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
const result = transformSync(
|
||||
[
|
||||
'var core;',
|
||||
`$ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`$ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`$ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
].join('\n'),
|
||||
{
|
||||
plugins: [createEs2015LinkerPlugin()],
|
||||
|
@ -151,9 +151,9 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
spyOnLinkPartialDeclarationWithConstants(o.literal('REPLACEMENT'));
|
||||
const result = transformSync(
|
||||
[
|
||||
'function run(core) {', ` $ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` $ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` $ngDeclareDirective({version: 1, ngImport: core})`, '}'
|
||||
'function run(core) {', ` ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` ɵɵngDeclareDirective({version: 1, ngImport: core})`, '}'
|
||||
].join('\n'),
|
||||
{
|
||||
plugins: [createEs2015LinkerPlugin()],
|
||||
|
@ -172,9 +172,9 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
const result = transformSync(
|
||||
[
|
||||
'function run() {',
|
||||
` $ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` $ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` $ngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
` ɵɵngDeclareDirective({version: 1, ngImport: core})`,
|
||||
'}',
|
||||
].join('\n'),
|
||||
{
|
||||
|
@ -197,7 +197,7 @@ describe('createEs2015LinkerPlugin()', () => {
|
|||
spyOnLinkPartialDeclarationWithConstants(o.fn([], [], null, null, 'FOO'));
|
||||
const result = transformSync(
|
||||
[
|
||||
`$ngDeclareDirective({version: 1, ngImport: core}); FOO;`,
|
||||
`ɵɵngDeclareDirective({version: 1, ngImport: core}); FOO;`,
|
||||
].join('\n'),
|
||||
{
|
||||
plugins: [
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
* ```
|
||||
* function foo() {
|
||||
* function bar () {
|
||||
* $ngDeclareDirective({...});
|
||||
* ɵɵngDeclareDirective({...});
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* The `DeclarationScope` of the `$ngDeclareDirective()` call is the body of the `bar()` function.
|
||||
* The `DeclarationScope` of the `ɵɵngDeclareDirective()` call is the body of the `bar()` function.
|
||||
*
|
||||
* The `FileLinker` uses this object to identify the lexical scope of any constant statements that
|
||||
* might be generated by the linking process (i.e. where the `ConstantPool` lives for a set of
|
||||
|
|
|
@ -39,7 +39,7 @@ export class FileLinker<TConstantScope, TStatement, TExpression> {
|
|||
* definition and any shared constant statements.
|
||||
*
|
||||
* @param declarationFn the name of the function used to declare the partial declaration - e.g.
|
||||
* `$ngDeclareDirective`.
|
||||
* `ɵɵngDeclareDirective`.
|
||||
* @param args the arguments passed to the declaration function.
|
||||
* @param declarationScope the scope that contains this call to the declaration function.
|
||||
*/
|
||||
|
|
|
@ -13,7 +13,7 @@ import {AstObject} from '../../ast/ast_value';
|
|||
import {PartialLinker} from './partial_linker';
|
||||
|
||||
/**
|
||||
* A `PartialLinker` that is designed to process `$ngDeclareComponent()` call expressions.
|
||||
* A `PartialLinker` that is designed to process `ɵɵngDeclareComponent()` call expressions.
|
||||
*/
|
||||
export class PartialComponentLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
|
||||
linkPartialDeclaration(
|
||||
|
|
|
@ -15,7 +15,7 @@ import {FatalLinkerError} from '../../fatal_linker_error';
|
|||
import {PartialLinker} from './partial_linker';
|
||||
|
||||
/**
|
||||
* A `PartialLinker` that is designed to process `$ngDeclareDirective()` call expressions.
|
||||
* A `PartialLinker` that is designed to process `ɵɵngDeclareDirective()` call expressions.
|
||||
*/
|
||||
export class PartialDirectiveLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
|
||||
linkPartialDeclaration(
|
||||
|
|
|
@ -11,10 +11,10 @@ import {PartialLinker} from './partial_linker';
|
|||
|
||||
export class PartialLinkerSelector<TExpression> {
|
||||
private linkers: Record<string, Record<number, PartialLinker<TExpression>>> = {
|
||||
'$ngDeclareDirective': {
|
||||
'ɵɵngDeclareDirective': {
|
||||
1: new PartialDirectiveLinkerVersion1(),
|
||||
},
|
||||
'$ngDeclareComponent': {
|
||||
'ɵɵngDeclareComponent': {
|
||||
1: new PartialComponentLinkerVersion1(),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -25,8 +25,8 @@ describe('FileLinker', () => {
|
|||
describe('isPartialDeclaration()', () => {
|
||||
it('should return true if the callee is recognized', () => {
|
||||
const {fileLinker} = createFileLinker();
|
||||
expect(fileLinker.isPartialDeclaration('$ngDeclareDirective')).toBe(true);
|
||||
expect(fileLinker.isPartialDeclaration('$ngDeclareComponent')).toBe(true);
|
||||
expect(fileLinker.isPartialDeclaration('ɵɵngDeclareDirective')).toBe(true);
|
||||
expect(fileLinker.isPartialDeclaration('ɵɵngDeclareComponent')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if the callee is not recognized', () => {
|
||||
|
@ -58,7 +58,7 @@ describe('FileLinker', () => {
|
|||
]);
|
||||
expect(
|
||||
() => fileLinker.linkPartialDeclaration(
|
||||
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope()))
|
||||
'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope()))
|
||||
.toThrowError(`Expected property 'version' to be present.`);
|
||||
});
|
||||
|
||||
|
@ -70,7 +70,7 @@ describe('FileLinker', () => {
|
|||
]);
|
||||
expect(
|
||||
() => fileLinker.linkPartialDeclaration(
|
||||
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope()))
|
||||
'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope()))
|
||||
.toThrowError(`Expected property 'ngImport' to be present.`);
|
||||
});
|
||||
|
||||
|
@ -87,7 +87,7 @@ describe('FileLinker', () => {
|
|||
]);
|
||||
|
||||
const compilationResult = fileLinker.linkPartialDeclaration(
|
||||
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope());
|
||||
'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope());
|
||||
|
||||
expect(compilationResult).toEqual(factory.createLiteral('compilation result'));
|
||||
expect(compileSpy).toHaveBeenCalled();
|
||||
|
@ -108,7 +108,7 @@ describe('FileLinker', () => {
|
|||
]);
|
||||
|
||||
const replacement = fileLinker.linkPartialDeclaration(
|
||||
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope());
|
||||
'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope());
|
||||
expect(generate(replacement)).toEqual('"REPLACEMENT"');
|
||||
|
||||
const results = fileLinker.getConstantStatements();
|
||||
|
@ -131,7 +131,7 @@ describe('FileLinker', () => {
|
|||
]);
|
||||
|
||||
const replacement = fileLinker.linkPartialDeclaration(
|
||||
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope());
|
||||
'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope());
|
||||
expect(generate(replacement))
|
||||
.toEqual('function () { const _c0 = [1]; return "REPLACEMENT"; }()');
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ describe('PartialLinkerSelector', () => {
|
|||
it('should return true if there is at least one linker that matches the given function name',
|
||||
() => {
|
||||
const selector = new PartialLinkerSelector();
|
||||
expect(selector.supportsDeclaration('$ngDeclareDirective')).toBe(true);
|
||||
expect(selector.supportsDeclaration('$ngDeclareComponent')).toBe(true);
|
||||
expect(selector.supportsDeclaration('ɵɵngDeclareDirective')).toBe(true);
|
||||
expect(selector.supportsDeclaration('ɵɵngDeclareComponent')).toBe(true);
|
||||
expect(selector.supportsDeclaration('$foo')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
@ -24,9 +24,9 @@ describe('PartialLinkerSelector', () => {
|
|||
describe('getLinker()', () => {
|
||||
it('should return the linker that matches the name and version number', () => {
|
||||
const selector = new PartialLinkerSelector();
|
||||
expect(selector.getLinker('$ngDeclareDirective', 1))
|
||||
expect(selector.getLinker('ɵɵngDeclareDirective', 1))
|
||||
.toBeInstanceOf(PartialDirectiveLinkerVersion1);
|
||||
expect(selector.getLinker('$ngDeclareComponent', 1))
|
||||
expect(selector.getLinker('ɵɵngDeclareComponent', 1))
|
||||
.toBeInstanceOf(PartialComponentLinkerVersion1);
|
||||
});
|
||||
|
||||
|
@ -34,8 +34,8 @@ describe('PartialLinkerSelector', () => {
|
|||
const selector = new PartialLinkerSelector();
|
||||
expect(() => selector.getLinker('$foo', 1))
|
||||
.toThrowError('Unknown partial declaration function $foo.');
|
||||
expect(() => selector.getLinker('$ngDeclareDirective', 2))
|
||||
.toThrowError('Unsupported partial declaration version 2 for $ngDeclareDirective.');
|
||||
expect(() => selector.getLinker('ɵɵngDeclareDirective', 2))
|
||||
.toThrowError('Unsupported partial declaration version 2 for ɵɵngDeclareDirective.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -248,7 +248,7 @@ export class Identifiers {
|
|||
};
|
||||
|
||||
static defineDirective: o.ExternalReference = {name: 'ɵɵdefineDirective', moduleName: CORE};
|
||||
static declareDirective: o.ExternalReference = {name: '$ngDeclareDirective', moduleName: CORE};
|
||||
static declareDirective: o.ExternalReference = {name: 'ɵɵngDeclareDirective', moduleName: CORE};
|
||||
|
||||
static DirectiveDefWithMeta: o.ExternalReference = {
|
||||
name: 'ɵɵDirectiveDefWithMeta',
|
||||
|
|
|
@ -77,8 +77,6 @@ export {
|
|||
NG_PIPE_DEF as ɵNG_PIPE_DEF,
|
||||
} from './render3/fields';
|
||||
export {
|
||||
|
||||
$ngDeclareDirective,
|
||||
AttributeMarker as ɵAttributeMarker,
|
||||
ComponentDef as ɵComponentDef,
|
||||
ComponentFactory as ɵRender3ComponentFactory,
|
||||
|
@ -164,6 +162,7 @@ export {
|
|||
ɵɵnamespaceMathML,
|
||||
ɵɵnamespaceSVG,
|
||||
ɵɵnextContext,
|
||||
ɵɵngDeclareDirective,
|
||||
ɵɵNgOnChangesFeature,
|
||||
ɵɵpipe,
|
||||
ɵɵpipeBind1,
|
||||
|
|
|
@ -134,7 +134,7 @@ export {
|
|||
} from './interfaces/node';
|
||||
export {CssSelectorList, ProjectionSlots} from './interfaces/projection';
|
||||
export {
|
||||
$ngDeclareDirective,
|
||||
ɵɵngDeclareDirective,
|
||||
} from './jit/partial';
|
||||
export {
|
||||
setClassMetadata,
|
||||
|
|
|
@ -171,5 +171,5 @@ export const angularCoreEnv: {[name: string]: Function} =
|
|||
'ɵɵtrustConstantScript': sanitization.ɵɵtrustConstantScript,
|
||||
'ɵɵtrustConstantResourceUrl': sanitization.ɵɵtrustConstantResourceUrl,
|
||||
|
||||
'$ngDeclareDirective': partial.$ngDeclareDirective,
|
||||
'ɵɵngDeclareDirective': partial.ɵɵngDeclareDirective,
|
||||
}))();
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
*
|
||||
* @codeGenApi
|
||||
*/
|
||||
export function $ngDeclareDirective(decl: unknown): unknown {
|
||||
export function ɵɵngDeclareDirective(decl: unknown): unknown {
|
||||
throw new Error('Not yet implemented');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue