From 306a1307c7be20764c9353a429030f9208775649 Mon Sep 17 00:00:00 2001 From: JoostK Date: Tue, 3 Nov 2020 21:33:57 +0100 Subject: [PATCH] =?UTF-8?q?refactor(compiler-cli):=20rename=20`$ngDeclareD?= =?UTF-8?q?irective`/`$ngDeclareComponent`=20to=20use=20`=C9=B5=C9=B5`=20p?= =?UTF-8?q?refix=20(#39518)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- goldens/public-api/core/core.d.ts | 3 -- .../babel/test/es2015_linker_plugin_spec.ts | 44 +++++++++---------- .../src/file_linker/declaration_scope.ts | 4 +- .../linker/src/file_linker/file_linker.ts | 2 +- .../partial_component_linker_1.ts | 2 +- .../partial_directive_linker_1.ts | 2 +- .../partial_linker_selector.ts | 4 +- .../test/file_linker/file_linker_spec.ts | 14 +++--- .../partial_linker_selector_spec.ts | 12 ++--- .../compiler/src/render3/r3_identifiers.ts | 2 +- .../core/src/core_render3_private_export.ts | 3 +- packages/core/src/render3/index.ts | 2 +- packages/core/src/render3/jit/environment.ts | 2 +- packages/core/src/render3/jit/partial.ts | 2 +- 14 files changed, 47 insertions(+), 51 deletions(-) diff --git a/goldens/public-api/core/core.d.ts b/goldens/public-api/core/core.d.ts index 728e56ac64..0bbed1ad02 100644 --- a/goldens/public-api/core/core.d.ts +++ b/goldens/public-api/core/core.d.ts @@ -1,6 +1,3 @@ -/** @codeGenApi */ -export declare function $ngDeclareDirective(decl: unknown): unknown; - export declare interface AbstractType extends Function { prototype: T; } diff --git a/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts b/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts index 1f492df846..556010a192 100644 --- a/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts +++ b/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts @@ -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: [ diff --git a/packages/compiler-cli/linker/src/file_linker/declaration_scope.ts b/packages/compiler-cli/linker/src/file_linker/declaration_scope.ts index a543bc3b87..320a269a26 100644 --- a/packages/compiler-cli/linker/src/file_linker/declaration_scope.ts +++ b/packages/compiler-cli/linker/src/file_linker/declaration_scope.ts @@ -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 diff --git a/packages/compiler-cli/linker/src/file_linker/file_linker.ts b/packages/compiler-cli/linker/src/file_linker/file_linker.ts index 936ef1ac59..ca575604f0 100644 --- a/packages/compiler-cli/linker/src/file_linker/file_linker.ts +++ b/packages/compiler-cli/linker/src/file_linker/file_linker.ts @@ -39,7 +39,7 @@ export class FileLinker { * 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. */ diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts index b32dda466d..bf0efbfc8e 100644 --- a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts @@ -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 implements PartialLinker { linkPartialDeclaration( diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts index bcd80f86cf..f89f38711a 100644 --- a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts @@ -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 implements PartialLinker { linkPartialDeclaration( diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_linker_selector.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_linker_selector.ts index f2490ba17b..ca98526274 100644 --- a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_linker_selector.ts +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_linker_selector.ts @@ -11,10 +11,10 @@ import {PartialLinker} from './partial_linker'; export class PartialLinkerSelector { private linkers: Record>> = { - '$ngDeclareDirective': { + 'ɵɵngDeclareDirective': { 1: new PartialDirectiveLinkerVersion1(), }, - '$ngDeclareComponent': { + 'ɵɵngDeclareComponent': { 1: new PartialComponentLinkerVersion1(), }, }; diff --git a/packages/compiler-cli/linker/test/file_linker/file_linker_spec.ts b/packages/compiler-cli/linker/test/file_linker/file_linker_spec.ts index 68eeee4ddf..583868992b 100644 --- a/packages/compiler-cli/linker/test/file_linker/file_linker_spec.ts +++ b/packages/compiler-cli/linker/test/file_linker/file_linker_spec.ts @@ -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"; }()'); diff --git a/packages/compiler-cli/linker/test/file_linker/partial_linkers/partial_linker_selector_spec.ts b/packages/compiler-cli/linker/test/file_linker/partial_linkers/partial_linker_selector_spec.ts index c04b92e2d9..46f584b2a2 100644 --- a/packages/compiler-cli/linker/test/file_linker/partial_linkers/partial_linker_selector_spec.ts +++ b/packages/compiler-cli/linker/test/file_linker/partial_linkers/partial_linker_selector_spec.ts @@ -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.'); }); }); }); diff --git a/packages/compiler/src/render3/r3_identifiers.ts b/packages/compiler/src/render3/r3_identifiers.ts index 9809447561..375f0fd4d0 100644 --- a/packages/compiler/src/render3/r3_identifiers.ts +++ b/packages/compiler/src/render3/r3_identifiers.ts @@ -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', diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index f061893474..6f12c1df9f 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -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, diff --git a/packages/core/src/render3/index.ts b/packages/core/src/render3/index.ts index cfdf8187d9..952c50d73c 100644 --- a/packages/core/src/render3/index.ts +++ b/packages/core/src/render3/index.ts @@ -134,7 +134,7 @@ export { } from './interfaces/node'; export {CssSelectorList, ProjectionSlots} from './interfaces/projection'; export { - $ngDeclareDirective, + ɵɵngDeclareDirective, } from './jit/partial'; export { setClassMetadata, diff --git a/packages/core/src/render3/jit/environment.ts b/packages/core/src/render3/jit/environment.ts index ce4bb0179f..6d4e4edd06 100644 --- a/packages/core/src/render3/jit/environment.ts +++ b/packages/core/src/render3/jit/environment.ts @@ -171,5 +171,5 @@ export const angularCoreEnv: {[name: string]: Function} = 'ɵɵtrustConstantScript': sanitization.ɵɵtrustConstantScript, 'ɵɵtrustConstantResourceUrl': sanitization.ɵɵtrustConstantResourceUrl, - '$ngDeclareDirective': partial.$ngDeclareDirective, + 'ɵɵngDeclareDirective': partial.ɵɵngDeclareDirective, }))(); diff --git a/packages/core/src/render3/jit/partial.ts b/packages/core/src/render3/jit/partial.ts index 9ba050fba6..133fe0c62b 100644 --- a/packages/core/src/render3/jit/partial.ts +++ b/packages/core/src/render3/jit/partial.ts @@ -11,6 +11,6 @@ * * @codeGenApi */ -export function $ngDeclareDirective(decl: unknown): unknown { +export function ɵɵngDeclareDirective(decl: unknown): unknown { throw new Error('Not yet implemented'); }