Skip to content

Commit 172e44b

Browse files
Revert "fix(compiler-cli): capture metadata for undecorated fields (#63904)" (#63952)
This reverts commit 4c091ab. PR Close #63952
1 parent 150ed2b commit 172e44b

File tree

16 files changed

+29
-419
lines changed

16 files changed

+29
-419
lines changed

packages/compiler-cli/src/ngtsc/annotations/common/src/metadata.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ import {
3030

3131
import {valueReferenceToExpression, wrapFunctionExpressionsInParens} from './util';
3232

33-
/** Function that extracts metadata from an undercorated class member. */
34-
export type UndecoratedMetadataExtractor = (member: ClassMember) => LiteralArrayExpr | null;
35-
3633
/**
3734
* Given a class declaration, generate a call to `setClassMetadata` with the Angular metadata
3835
* present on the class or its member fields. An ngDevMode guard is used to allow the call to be
@@ -47,7 +44,6 @@ export function extractClassMetadata(
4744
isCore: boolean,
4845
annotateForClosureCompiler?: boolean,
4946
angularDecoratorTransform: (dec: Decorator) => Decorator = (dec) => dec,
50-
undecoratedMetadataExtractor: UndecoratedMetadataExtractor = () => null,
5147
): R3ClassMetadata | null {
5248
if (!reflection.isClass(clazz)) {
5349
return null;
@@ -102,12 +98,10 @@ export function extractClassMetadata(
10298
let duplicateDecoratedMembers: ClassMember[] | null = null;
10399

104100
for (const member of classMembers) {
105-
const shouldQuoteName = member.nameNode !== null && ts.isStringLiteralLike(member.nameNode);
106-
107101
if (member.decorators !== null && member.decorators.length > 0) {
108102
decoratedMembers.push({
109103
key: member.name,
110-
quoted: shouldQuoteName,
104+
quoted: false,
111105
value: decoratedClassMemberToMetadata(member.decorators!, isCore),
112106
});
113107

@@ -117,16 +111,6 @@ export function extractClassMetadata(
117111
} else {
118112
seenMemberNames.add(member.name);
119113
}
120-
} else {
121-
const undecoratedMetadata = undecoratedMetadataExtractor(member);
122-
123-
if (undecoratedMetadata !== null) {
124-
decoratedMembers.push({
125-
key: member.name,
126-
quoted: shouldQuoteName,
127-
value: undecoratedMetadata,
128-
});
129-
}
130114
}
131115
}
132116

packages/compiler-cli/src/ngtsc/annotations/common/test/metadata_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ runInEachFileSystem(() => {
108108
}
109109
`);
110110
expect(res).toContain(
111-
`{ "has-dashes-in-name": [{ type: Input }], noDashesInName: [{ type: Input }] })`,
111+
`{ 'has-dashes-in-name': [{ type: Input }], noDashesInName: [{ type: Input }] })`,
112112
);
113113
});
114114

packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,12 @@ import {
155155
ResourceLoader,
156156
toFactoryMetadata,
157157
tryUnwrapForwardRef,
158-
UndecoratedMetadataExtractor,
159158
validateHostDirectives,
160159
wrapFunctionExpressionsInParens,
161160
} from '../../common';
162161
import {
163162
extractDirectiveMetadata,
164163
extractHostBindingResources,
165-
getDirectiveUndecoratedMetadataExtractor,
166164
parseDirectiveStyles,
167165
} from '../../directive';
168166
import {createModuleWithProvidersResolver, NgModuleSymbol} from '../../ng_module';
@@ -293,11 +291,6 @@ export class ComponentDecoratorHandler
293291
preserveSignificantWhitespace: this.i18nPreserveSignificantWhitespace,
294292
};
295293

296-
this.undecoratedMetadataExtractor = getDirectiveUndecoratedMetadataExtractor(
297-
reflector,
298-
importTracker,
299-
);
300-
301294
// Dependencies can't be deferred during HMR, because the HMR update module can't have
302295
// dynamic imports and its dependencies need to be passed in directly. If dependencies
303296
// are deferred, their imports will be deleted so we may lose the reference to them.
@@ -306,7 +299,6 @@ export class ComponentDecoratorHandler
306299

307300
private literalCache = new Map<Decorator, ts.ObjectLiteralExpression>();
308301
private elementSchemaRegistry = new DomElementSchemaRegistry();
309-
private readonly undecoratedMetadataExtractor: UndecoratedMetadataExtractor;
310302

311303
/**
312304
* During the asynchronous preanalyze phase, it's necessary to parse the template to extract
@@ -979,7 +971,6 @@ export class ComponentDecoratorHandler
979971
this.isCore,
980972
this.annotateForClosureCompiler,
981973
(dec) => transformDecoratorResources(dec, component, styles, template),
982-
this.undecoratedMetadataExtractor,
983974
)
984975
: null,
985976
classDebugInfo: extractClassDebugInfo(

packages/compiler-cli/src/ngtsc/annotations/directive/src/handler.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,10 @@ import {
7474
ReferencesRegistry,
7575
resolveProvidersRequiringFactory,
7676
toFactoryMetadata,
77-
UndecoratedMetadataExtractor,
7877
validateHostDirectives,
7978
} from '../../common';
8079

81-
import {
82-
extractDirectiveMetadata,
83-
extractHostBindingResources,
84-
getDirectiveUndecoratedMetadataExtractor,
85-
HostBindingNodes,
86-
} from './shared';
80+
import {extractDirectiveMetadata, extractHostBindingResources, HostBindingNodes} from './shared';
8781
import {DirectiveSymbol} from './symbol';
8882
import {JitDeclarationRegistry} from '../../common/src/jit_declaration_registry';
8983
import {
@@ -160,16 +154,10 @@ export class DirectiveDecoratorHandler
160154
private readonly usePoisonedData: boolean,
161155
private readonly typeCheckHostBindings: boolean,
162156
private readonly emitDeclarationOnly: boolean,
163-
) {
164-
this.undecoratedMetadataExtractor = getDirectiveUndecoratedMetadataExtractor(
165-
reflector,
166-
importTracker,
167-
);
168-
}
157+
) {}
169158

170159
readonly precedence = HandlerPrecedence.PRIMARY;
171160
readonly name = 'DirectiveDecoratorHandler';
172-
private readonly undecoratedMetadataExtractor: UndecoratedMetadataExtractor;
173161

174162
detect(
175163
node: ClassDeclaration,
@@ -252,14 +240,7 @@ export class DirectiveDecoratorHandler
252240
hostDirectives: directiveResult.hostDirectives,
253241
rawHostDirectives: directiveResult.rawHostDirectives,
254242
classMetadata: this.includeClassMetadata
255-
? extractClassMetadata(
256-
node,
257-
this.reflector,
258-
this.isCore,
259-
this.annotateForClosureCompiler,
260-
undefined,
261-
this.undecoratedMetadataExtractor,
262-
)
243+
? extractClassMetadata(node, this.reflector, this.isCore, this.annotateForClosureCompiler)
263244
: null,
264245
baseClass: readBaseClass(node, this.reflector, this.evaluator),
265246
typeCheckMeta: extractDirectiveTypeCheckMeta(node, directiveResult.inputs, this.reflector),

packages/compiler-cli/src/ngtsc/annotations/directive/src/shared.ts

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
ExternalReference,
1515
ForwardRefHandling,
1616
getSafePropertyAccessString,
17-
LiteralArrayExpr,
18-
literalMap,
1917
MaybeForwardRefExpression,
2018
ParsedHostBindings,
2119
ParseError,
@@ -26,10 +24,7 @@ import {
2624
R3QueryMetadata,
2725
R3Reference,
2826
verifyHostBindings,
29-
R3Identifiers,
30-
ArrowFunctionExpr,
3127
WrappedNodeExpr,
32-
literal,
3328
} from '@angular/compiler';
3429
import ts from 'typescript';
3530

@@ -81,7 +76,6 @@ import {
8176
ReferencesRegistry,
8277
toR3Reference,
8378
tryUnwrapForwardRef,
84-
UndecoratedMetadataExtractor,
8579
unwrapConstructorDependencies,
8680
unwrapExpression,
8781
validateConstructorDependencies,
@@ -861,140 +855,6 @@ export function parseFieldStringArrayValue(
861855
return value;
862856
}
863857

864-
/**
865-
* Returns a function that can be used to extract data for the `setClassMetadata`
866-
* calls from undecorated directive class members.
867-
*/
868-
export function getDirectiveUndecoratedMetadataExtractor(
869-
reflector: ReflectionHost,
870-
importTracker: ImportedSymbolsTracker,
871-
): UndecoratedMetadataExtractor {
872-
return (member: ClassMember): LiteralArrayExpr | null => {
873-
const input = tryParseSignalInputMapping(member, reflector, importTracker);
874-
if (input !== null) {
875-
return getDecoratorMetaArray([
876-
[new ExternalExpr(R3Identifiers.inputDecorator), memberMetadataFromSignalInput(input)],
877-
]);
878-
}
879-
880-
const output = tryParseInitializerBasedOutput(member, reflector, importTracker);
881-
if (output !== null) {
882-
return getDecoratorMetaArray([
883-
[
884-
new ExternalExpr(R3Identifiers.outputDecorator),
885-
memberMetadataFromInitializerOutput(output.metadata),
886-
],
887-
]);
888-
}
889-
890-
const model = tryParseSignalModelMapping(member, reflector, importTracker);
891-
if (model !== null) {
892-
return getDecoratorMetaArray([
893-
[
894-
new ExternalExpr(R3Identifiers.inputDecorator),
895-
memberMetadataFromSignalInput(model.input),
896-
],
897-
[
898-
new ExternalExpr(R3Identifiers.outputDecorator),
899-
memberMetadataFromInitializerOutput(model.output),
900-
],
901-
]);
902-
}
903-
904-
const query = tryParseSignalQueryFromInitializer(member, reflector, importTracker);
905-
if (query !== null) {
906-
let identifier: ExternalReference;
907-
if (query.name === 'viewChild') {
908-
identifier = R3Identifiers.viewChildDecorator;
909-
} else if (query.name === 'viewChildren') {
910-
identifier = R3Identifiers.viewChildrenDecorator;
911-
} else if (query.name === 'contentChild') {
912-
identifier = R3Identifiers.contentChildDecorator;
913-
} else if (query.name === 'contentChildren') {
914-
identifier = R3Identifiers.contentChildrenDecorator;
915-
} else {
916-
return null;
917-
}
918-
919-
return getDecoratorMetaArray([
920-
[new ExternalExpr(identifier), memberMetadataFromSignalQuery(query.call)],
921-
]);
922-
}
923-
924-
return null;
925-
};
926-
}
927-
928-
function getDecoratorMetaArray(
929-
decorators: [type: ExternalExpr, args: LiteralArrayExpr][],
930-
): LiteralArrayExpr {
931-
return new LiteralArrayExpr(
932-
decorators.map(([type, args]) =>
933-
literalMap([
934-
{key: 'type', value: type, quoted: false},
935-
{key: 'args', value: args, quoted: false},
936-
]),
937-
),
938-
);
939-
}
940-
941-
function memberMetadataFromSignalInput(input: InputMapping): LiteralArrayExpr {
942-
// Note that for signal inputs the transform is captured in the signal
943-
// initializer so we don't need to capture it here.
944-
return new LiteralArrayExpr([
945-
literalMap([
946-
{
947-
key: 'isSignal',
948-
value: literal(true),
949-
quoted: false,
950-
},
951-
{
952-
key: 'alias',
953-
value: literal(input.bindingPropertyName),
954-
quoted: false,
955-
},
956-
{
957-
key: 'required',
958-
value: literal(input.required),
959-
quoted: false,
960-
},
961-
]),
962-
]);
963-
}
964-
965-
function memberMetadataFromInitializerOutput(output: InputOrOutput): LiteralArrayExpr {
966-
return new LiteralArrayExpr([literal(output.bindingPropertyName)]);
967-
}
968-
969-
function memberMetadataFromSignalQuery(call: ts.CallExpression): LiteralArrayExpr {
970-
const firstArg = call.arguments[0];
971-
const firstArgMeta =
972-
ts.isStringLiteralLike(firstArg) || ts.isCallExpression(firstArg)
973-
? new WrappedNodeExpr(firstArg)
974-
: // If the first argument is a class reference, we need to wrap it in a `forwardRef`
975-
// because the reference might occur after the current class. This wouldn't be flagged
976-
// on the query initializer, because it executes after the class is initialized, whereas
977-
// `setClassMetadata` runs immediately.
978-
new ExternalExpr(R3Identifiers.forwardRef).callFn([
979-
new ArrowFunctionExpr([], new WrappedNodeExpr(firstArg)),
980-
]);
981-
982-
const entries: Expression[] = [
983-
// We use wrapped nodes here, because the output AST doesn't support spread assignments.
984-
firstArgMeta,
985-
new WrappedNodeExpr(
986-
ts.factory.createObjectLiteralExpression([
987-
...(call.arguments.length > 1
988-
? [ts.factory.createSpreadAssignment(call.arguments[1])]
989-
: []),
990-
ts.factory.createPropertyAssignment('isSignal', ts.factory.createTrue()),
991-
]),
992-
),
993-
];
994-
995-
return new LiteralArrayExpr(entries);
996-
}
997-
998858
function isStringArrayOrDie(value: any, name: string, node: ts.Expression): value is string[] {
999859
if (!Array.isArray(value)) {
1000860
return false;

packages/compiler-cli/test/compliance/test_cases/model_inputs/GOLDEN_PARTIAL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TestDir.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "0.0.
1414
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestDir, decorators: [{
1515
type: Directive,
1616
args: [{}]
17-
}], propDecorators: { counter: [{ type: i0.Input, args: [{ isSignal: true, alias: "counter", required: false }] }, { type: i0.Output, args: ["counterChange"] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }, { type: i0.Output, args: ["nameChange"] }] } });
17+
}] });
1818

1919
/****************************************************************************************************
2020
* PARTIAL FILE: model_directive_definition.d.ts
@@ -45,7 +45,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
4545
args: [{
4646
template: 'Works',
4747
}]
48-
}], propDecorators: { counter: [{ type: i0.Input, args: [{ isSignal: true, alias: "counter", required: false }] }, { type: i0.Output, args: ["counterChange"] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }, { type: i0.Output, args: ["nameChange"] }] } });
48+
}] });
4949

5050
/****************************************************************************************************
5151
* PARTIAL FILE: model_component_definition.d.ts
@@ -80,7 +80,7 @@ TestDir.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "0.0.
8080
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestDir, decorators: [{
8181
type: Directive,
8282
args: [{}]
83-
}], propDecorators: { counter: [{ type: i0.Input, args: [{ isSignal: true, alias: "counter", required: false }] }, { type: i0.Output, args: ["counterChange"] }], modelWithAlias: [{ type: i0.Input, args: [{ isSignal: true, alias: "alias", required: false }] }, { type: i0.Output, args: ["aliasChange"] }], decoratorInput: [{
83+
}], propDecorators: { decoratorInput: [{
8484
type: Input
8585
}], decoratorInputWithAlias: [{
8686
type: Input,

packages/compiler-cli/test/compliance/test_cases/output_function/GOLDEN_PARTIAL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TestDir.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.
1818
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: TestDir, decorators: [{
1919
type: Directive,
2020
args: [{}]
21-
}], propDecorators: { a: [{ type: i0.Output, args: ["a"] }], b: [{ type: i0.Output, args: ["b"] }], c: [{ type: i0.Output, args: ["cPublic"] }], d: [{ type: i0.Output, args: ["d"] }], e: [{ type: i0.Output, args: ["e"] }] } });
21+
}] });
2222

2323
/****************************************************************************************************
2424
* PARTIAL FILE: output_in_directive.d.ts
@@ -56,7 +56,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
5656
args: [{
5757
template: 'Works',
5858
}]
59-
}], propDecorators: { a: [{ type: i0.Output, args: ["a"] }], b: [{ type: i0.Output, args: ["b"] }], c: [{ type: i0.Output, args: ["cPublic"] }], d: [{ type: i0.Output, args: ["d"] }], e: [{ type: i0.Output, args: ["e"] }] } });
59+
}] });
6060

6161
/****************************************************************************************************
6262
* PARTIAL FILE: output_in_component.d.ts
@@ -97,7 +97,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
9797
args: [{
9898
standalone: true,
9999
}]
100-
}], propDecorators: { click1: [{ type: i0.Output, args: ["click1"] }], click2: [{ type: i0.Output, args: ["click2"] }], click3: [{ type: i0.Output, args: ["click3"] }], _bla: [{ type: i0.Output, args: ["decoratorPublicName"] }], _bla2: [{ type: i0.Output, args: ["decoratorPublicName2"] }], clickDecorator1: [{
100+
}], propDecorators: { clickDecorator1: [{
101101
type: Output
102102
}], clickDecorator2: [{
103103
type: Output

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_bindings/host_bindings/GOLDEN_PARTIAL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
795795
selector: '[hostBindingDir]',
796796
standalone: false
797797
}]
798-
}], propDecorators: { "is-a": [{
798+
}], propDecorators: { 'is-a': [{
799799
type: HostBinding,
800800
args: ['class.a']
801-
}], "is-\"b\"": [{
801+
}], 'is-"b"': [{
802802
type: HostBinding,
803803
args: ['class.b']
804-
}], "\"is-c\"": [{
804+
}], '"is-c"': [{
805805
type: HostBinding,
806806
args: ['class.c']
807807
}] } });

0 commit comments

Comments
 (0)