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:
JoostK 2020-11-03 21:33:57 +01:00 committed by Joey Perrott
parent 87e9cd643b
commit 306a1307c7
14 changed files with 47 additions and 51 deletions

View File

@ -1,6 +1,3 @@
/** @codeGenApi */
export declare function $ngDeclareDirective(decl: unknown): unknown;
export declare interface AbstractType<T> extends Function { export declare interface AbstractType<T> extends Function {
prototype: T; prototype: T;
} }

View File

@ -59,9 +59,9 @@ describe('createEs2015LinkerPlugin()', () => {
transformSync( transformSync(
[ [
'var core;', 'var core;',
`$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})});`,
`x.qux(() => $ngDeclareDirective({version: 1, ngImport: core, x: 3}));`, `x.qux(() => ɵɵngDeclareDirective({version: 1, ngImport: core, x: 3}));`,
'spread(...x);', 'spread(...x);',
].join('\n'), ].join('\n'),
{ {
@ -71,13 +71,13 @@ describe('createEs2015LinkerPlugin()', () => {
}); });
expect(humanizeLinkerCalls(linkSpy.calls)).toEqual([ expect(humanizeLinkerCalls(linkSpy.calls)).toEqual([
['$ngDeclareDirective', '{version:1,ngImport:core,x:1}'], ['ɵɵngDeclareDirective', '{version:1,ngImport:core,x:1}'],
[ [
'$ngDeclareComponent', 'ɵɵngDeclareComponent',
'{version:1,ngImport:core,foo:()=>$ngDeclareDirective({version:1,ngImport:core,x:2})}' '{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 // 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( const result = transformSync(
[ [
'var core;', 'var core;',
'$ngDeclareDirective({version: 1, ngImport: core});', 'ɵɵngDeclareDirective({version: 1, ngImport: core});',
'$ngDeclareDirective({version: 1, ngImport: core, foo: () => bar({})});', 'ɵɵngDeclareDirective({version: 1, ngImport: core, foo: () => bar({})});',
'x.qux();', 'x.qux();',
'spread(...x);', 'spread(...x);',
].join('\n'), ].join('\n'),
@ -109,9 +109,9 @@ describe('createEs2015LinkerPlugin()', () => {
[ [
'import * as core from \'some-module\';', 'import * as core from \'some-module\';',
'import {id} from \'other-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'), ].join('\n'),
{ {
plugins: [createEs2015LinkerPlugin()], plugins: [createEs2015LinkerPlugin()],
@ -130,9 +130,9 @@ describe('createEs2015LinkerPlugin()', () => {
const result = transformSync( const result = transformSync(
[ [
'var core;', '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'), ].join('\n'),
{ {
plugins: [createEs2015LinkerPlugin()], plugins: [createEs2015LinkerPlugin()],
@ -151,9 +151,9 @@ describe('createEs2015LinkerPlugin()', () => {
spyOnLinkPartialDeclarationWithConstants(o.literal('REPLACEMENT')); spyOnLinkPartialDeclarationWithConstants(o.literal('REPLACEMENT'));
const result = transformSync( const result = transformSync(
[ [
'function run(core) {', ` $ngDeclareDirective({version: 1, ngImport: core})`, 'function run(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'), ].join('\n'),
{ {
plugins: [createEs2015LinkerPlugin()], plugins: [createEs2015LinkerPlugin()],
@ -172,9 +172,9 @@ describe('createEs2015LinkerPlugin()', () => {
const result = transformSync( const result = transformSync(
[ [
'function run() {', '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'), ].join('\n'),
{ {
@ -197,7 +197,7 @@ describe('createEs2015LinkerPlugin()', () => {
spyOnLinkPartialDeclarationWithConstants(o.fn([], [], null, null, 'FOO')); spyOnLinkPartialDeclarationWithConstants(o.fn([], [], null, null, 'FOO'));
const result = transformSync( const result = transformSync(
[ [
`$ngDeclareDirective({version: 1, ngImport: core}); FOO;`, `ɵɵngDeclareDirective({version: 1, ngImport: core}); FOO;`,
].join('\n'), ].join('\n'),
{ {
plugins: [ plugins: [

View File

@ -14,12 +14,12 @@
* ``` * ```
* function foo() { * function foo() {
* function bar () { * 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 * 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 * might be generated by the linking process (i.e. where the `ConstantPool` lives for a set of

View File

@ -39,7 +39,7 @@ export class FileLinker<TConstantScope, TStatement, TExpression> {
* definition and any shared constant statements. * definition and any shared constant statements.
* *
* @param declarationFn the name of the function used to declare the partial declaration - e.g. * @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 args the arguments passed to the declaration function.
* @param declarationScope the scope that contains this call to the declaration function. * @param declarationScope the scope that contains this call to the declaration function.
*/ */

View File

@ -13,7 +13,7 @@ import {AstObject} from '../../ast/ast_value';
import {PartialLinker} from './partial_linker'; 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> { export class PartialComponentLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
linkPartialDeclaration( linkPartialDeclaration(

View File

@ -15,7 +15,7 @@ import {FatalLinkerError} from '../../fatal_linker_error';
import {PartialLinker} from './partial_linker'; 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> { export class PartialDirectiveLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
linkPartialDeclaration( linkPartialDeclaration(

View File

@ -11,10 +11,10 @@ import {PartialLinker} from './partial_linker';
export class PartialLinkerSelector<TExpression> { export class PartialLinkerSelector<TExpression> {
private linkers: Record<string, Record<number, PartialLinker<TExpression>>> = { private linkers: Record<string, Record<number, PartialLinker<TExpression>>> = {
'$ngDeclareDirective': { 'ɵɵngDeclareDirective': {
1: new PartialDirectiveLinkerVersion1(), 1: new PartialDirectiveLinkerVersion1(),
}, },
'$ngDeclareComponent': { 'ɵɵngDeclareComponent': {
1: new PartialComponentLinkerVersion1(), 1: new PartialComponentLinkerVersion1(),
}, },
}; };

View File

@ -25,8 +25,8 @@ describe('FileLinker', () => {
describe('isPartialDeclaration()', () => { describe('isPartialDeclaration()', () => {
it('should return true if the callee is recognized', () => { it('should return true if the callee is recognized', () => {
const {fileLinker} = createFileLinker(); const {fileLinker} = createFileLinker();
expect(fileLinker.isPartialDeclaration('$ngDeclareDirective')).toBe(true); expect(fileLinker.isPartialDeclaration('ɵɵngDeclareDirective')).toBe(true);
expect(fileLinker.isPartialDeclaration('$ngDeclareComponent')).toBe(true); expect(fileLinker.isPartialDeclaration('ɵɵngDeclareComponent')).toBe(true);
}); });
it('should return false if the callee is not recognized', () => { it('should return false if the callee is not recognized', () => {
@ -58,7 +58,7 @@ describe('FileLinker', () => {
]); ]);
expect( expect(
() => fileLinker.linkPartialDeclaration( () => fileLinker.linkPartialDeclaration(
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope())) 'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope()))
.toThrowError(`Expected property 'version' to be present.`); .toThrowError(`Expected property 'version' to be present.`);
}); });
@ -70,7 +70,7 @@ describe('FileLinker', () => {
]); ]);
expect( expect(
() => fileLinker.linkPartialDeclaration( () => fileLinker.linkPartialDeclaration(
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope())) 'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope()))
.toThrowError(`Expected property 'ngImport' to be present.`); .toThrowError(`Expected property 'ngImport' to be present.`);
}); });
@ -87,7 +87,7 @@ describe('FileLinker', () => {
]); ]);
const compilationResult = fileLinker.linkPartialDeclaration( const compilationResult = fileLinker.linkPartialDeclaration(
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope()); 'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope());
expect(compilationResult).toEqual(factory.createLiteral('compilation result')); expect(compilationResult).toEqual(factory.createLiteral('compilation result'));
expect(compileSpy).toHaveBeenCalled(); expect(compileSpy).toHaveBeenCalled();
@ -108,7 +108,7 @@ describe('FileLinker', () => {
]); ]);
const replacement = fileLinker.linkPartialDeclaration( const replacement = fileLinker.linkPartialDeclaration(
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope()); 'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope());
expect(generate(replacement)).toEqual('"REPLACEMENT"'); expect(generate(replacement)).toEqual('"REPLACEMENT"');
const results = fileLinker.getConstantStatements(); const results = fileLinker.getConstantStatements();
@ -131,7 +131,7 @@ describe('FileLinker', () => {
]); ]);
const replacement = fileLinker.linkPartialDeclaration( const replacement = fileLinker.linkPartialDeclaration(
'$ngDeclareDirective', [declarationArg], new MockDeclarationScope()); 'ɵɵngDeclareDirective', [declarationArg], new MockDeclarationScope());
expect(generate(replacement)) expect(generate(replacement))
.toEqual('function () { const _c0 = [1]; return "REPLACEMENT"; }()'); .toEqual('function () { const _c0 = [1]; return "REPLACEMENT"; }()');

View File

@ -15,8 +15,8 @@ describe('PartialLinkerSelector', () => {
it('should return true if there is at least one linker that matches the given function name', it('should return true if there is at least one linker that matches the given function name',
() => { () => {
const selector = new PartialLinkerSelector(); const selector = new PartialLinkerSelector();
expect(selector.supportsDeclaration('$ngDeclareDirective')).toBe(true); expect(selector.supportsDeclaration('ɵɵngDeclareDirective')).toBe(true);
expect(selector.supportsDeclaration('$ngDeclareComponent')).toBe(true); expect(selector.supportsDeclaration('ɵɵngDeclareComponent')).toBe(true);
expect(selector.supportsDeclaration('$foo')).toBe(false); expect(selector.supportsDeclaration('$foo')).toBe(false);
}); });
}); });
@ -24,9 +24,9 @@ describe('PartialLinkerSelector', () => {
describe('getLinker()', () => { describe('getLinker()', () => {
it('should return the linker that matches the name and version number', () => { it('should return the linker that matches the name and version number', () => {
const selector = new PartialLinkerSelector(); const selector = new PartialLinkerSelector();
expect(selector.getLinker('$ngDeclareDirective', 1)) expect(selector.getLinker('ɵɵngDeclareDirective', 1))
.toBeInstanceOf(PartialDirectiveLinkerVersion1); .toBeInstanceOf(PartialDirectiveLinkerVersion1);
expect(selector.getLinker('$ngDeclareComponent', 1)) expect(selector.getLinker('ɵɵngDeclareComponent', 1))
.toBeInstanceOf(PartialComponentLinkerVersion1); .toBeInstanceOf(PartialComponentLinkerVersion1);
}); });
@ -34,8 +34,8 @@ describe('PartialLinkerSelector', () => {
const selector = new PartialLinkerSelector(); const selector = new PartialLinkerSelector();
expect(() => selector.getLinker('$foo', 1)) expect(() => selector.getLinker('$foo', 1))
.toThrowError('Unknown partial declaration function $foo.'); .toThrowError('Unknown partial declaration function $foo.');
expect(() => selector.getLinker('$ngDeclareDirective', 2)) expect(() => selector.getLinker('ɵɵngDeclareDirective', 2))
.toThrowError('Unsupported partial declaration version 2 for $ngDeclareDirective.'); .toThrowError('Unsupported partial declaration version 2 for ɵɵngDeclareDirective.');
}); });
}); });
}); });

View File

@ -248,7 +248,7 @@ export class Identifiers {
}; };
static defineDirective: o.ExternalReference = {name: 'ɵɵdefineDirective', moduleName: CORE}; 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 = { static DirectiveDefWithMeta: o.ExternalReference = {
name: 'ɵɵDirectiveDefWithMeta', name: 'ɵɵDirectiveDefWithMeta',

View File

@ -77,8 +77,6 @@ export {
NG_PIPE_DEF as ɵNG_PIPE_DEF, NG_PIPE_DEF as ɵNG_PIPE_DEF,
} from './render3/fields'; } from './render3/fields';
export { export {
$ngDeclareDirective,
AttributeMarker as ɵAttributeMarker, AttributeMarker as ɵAttributeMarker,
ComponentDef as ɵComponentDef, ComponentDef as ɵComponentDef,
ComponentFactory as ɵRender3ComponentFactory, ComponentFactory as ɵRender3ComponentFactory,
@ -164,6 +162,7 @@ export {
ɵɵnamespaceMathML, ɵɵnamespaceMathML,
ɵɵnamespaceSVG, ɵɵnamespaceSVG,
ɵɵnextContext, ɵɵnextContext,
ɵɵngDeclareDirective,
ɵɵNgOnChangesFeature, ɵɵNgOnChangesFeature,
ɵɵpipe, ɵɵpipe,
ɵɵpipeBind1, ɵɵpipeBind1,

View File

@ -134,7 +134,7 @@ export {
} from './interfaces/node'; } from './interfaces/node';
export {CssSelectorList, ProjectionSlots} from './interfaces/projection'; export {CssSelectorList, ProjectionSlots} from './interfaces/projection';
export { export {
$ngDeclareDirective, ɵɵngDeclareDirective,
} from './jit/partial'; } from './jit/partial';
export { export {
setClassMetadata, setClassMetadata,

View File

@ -171,5 +171,5 @@ export const angularCoreEnv: {[name: string]: Function} =
'ɵɵtrustConstantScript': sanitization.ɵɵtrustConstantScript, 'ɵɵtrustConstantScript': sanitization.ɵɵtrustConstantScript,
'ɵɵtrustConstantResourceUrl': sanitization.ɵɵtrustConstantResourceUrl, 'ɵɵtrustConstantResourceUrl': sanitization.ɵɵtrustConstantResourceUrl,
'$ngDeclareDirective': partial.$ngDeclareDirective, 'ɵɵngDeclareDirective': partial.ɵɵngDeclareDirective,
}))(); }))();

View File

@ -11,6 +11,6 @@
* *
* @codeGenApi * @codeGenApi
*/ */
export function $ngDeclareDirective(decl: unknown): unknown { export function ɵɵngDeclareDirective(decl: unknown): unknown {
throw new Error('Not yet implemented'); throw new Error('Not yet implemented');
} }