Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor(core): Setup constant for standalone default value
This commit is part of the migration to standalone by default and sets up 2 files with a default value for standalone. They are still `false` in this case to land the change into G3 first. The switch to `true` will be executed in a follow-up PR.
  • Loading branch information
JeanMeche committed Oct 14, 2024
commit a2dfee5772fddaf000fcfef5bee8cca2901d4c51
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
* Copyright Google LLC 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
*/

/**
* A constant defining the default value for the standalone attribute in Directive and Pipes decorators.
* Extracted to a separate file to facilitate G3 patches.
*/
export const NG_STANDALONE_DEFAULT_VALUE = false;
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {tryParseSignalInputMapping} from './input_function';
import {tryParseSignalModelMapping} from './model_function';
import {tryParseInitializerBasedOutput} from './output_function';
import {tryParseSignalQueryFromInitializer} from './query_functions';
import {NG_STANDALONE_DEFAULT_VALUE} from '../../common/src/standalone-default-value';

const EMPTY_OBJECT: {[key: string]: string} = {};

Expand Down Expand Up @@ -335,7 +336,7 @@ export function extractDirectiveMetadata(
dep.token.value.name === 'TemplateRef',
);

let isStandalone = false;
let isStandalone = NG_STANDALONE_DEFAULT_VALUE;
if (directive.has('standalone')) {
const expr = directive.get('standalone')!;
const resolved = evaluator.evaluate(expr);
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
unwrapExpression,
wrapTypeReference,
} from '../common';
import {NG_STANDALONE_DEFAULT_VALUE} from '../common/src/standalone-default-value';

export interface PipeHandlerData {
meta: R3PipeMetadata;
Expand Down Expand Up @@ -176,7 +177,7 @@ export class PipeDecoratorHandler
pure = pureValue;
}

let isStandalone = false;
let isStandalone = NG_STANDALONE_DEFAULT_VALUE;
if (pipe.has('standalone')) {
const expr = pipe.get('standalone')!;
const resolved = this.evaluator.evaluate(expr);
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/core_render3_private_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,4 @@ export {
} from './render3/deps_tracker/deps_tracker';
export {generateStandaloneInDeclarationsError as ɵgenerateStandaloneInDeclarationsError} from './render3/jit/module';
export {getAsyncClassMetadataFn as ɵgetAsyncClassMetadataFn} from './render3/metadata';
export {NG_STANDALONE_DEFAULT_VALUE as ɵNG_STANDALONE_DEFAULT_VALUE} from './render3/standalone-default-value';
4 changes: 3 additions & 1 deletion packages/core/src/render3/jit/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
patchComponentDefWithScope,
transitiveScopesFor,
} from './module';
import {NG_STANDALONE_DEFAULT_VALUE} from '../standalone-default-value';
import {isComponent, verifyStandaloneImport} from './util';

/**
Expand Down Expand Up @@ -452,7 +453,8 @@ export function directiveMetadata(type: Type<any>, metadata: Directive): R3Direc
exportAs: extractExportAs(metadata.exportAs),
providers: metadata.providers || null,
viewQueries: extractQueriesMetadata(type, propMetadata, isViewQuery),
isStandalone: !!metadata.standalone,
isStandalone:
metadata.standalone === undefined ? NG_STANDALONE_DEFAULT_VALUE : !!metadata.standalone,
isSignal: !!metadata.signals,
hostDirectives:
metadata.hostDirectives?.map((directive) =>
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/render3/jit/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {Pipe} from '../../metadata/directives';
import {NG_FACTORY_DEF, NG_PIPE_DEF} from '../fields';

import {angularCoreEnv} from './environment';
import {NG_STANDALONE_DEFAULT_VALUE} from '../standalone-default-value';

export function compilePipe(type: Type<any>, meta: Pipe): void {
let ngPipeDef: any = null;
Expand Down Expand Up @@ -73,6 +74,6 @@ function getPipeMetadata(type: Type<any>, meta: Pipe): R3PipeMetadataFacade {
name: type.name,
pipeName: meta.name,
pure: meta.pure !== undefined ? meta.pure : true,
isStandalone: !!meta.standalone,
isStandalone: meta.standalone === undefined ? NG_STANDALONE_DEFAULT_VALUE : !!meta.standalone,
};
}
13 changes: 13 additions & 0 deletions packages/core/src/render3/standalone-default-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
* Copyright Google LLC 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
*/

/**
* A constant defining the default value for the standalone attribute in Directive and Pipes decorators.
* Extracted to a separate file to facilitate G3 patches.
*/
export const NG_STANDALONE_DEFAULT_VALUE = false;
3 changes: 3 additions & 0 deletions packages/core/test/bundling/defer/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,9 @@
{
"name": "init_skip_hydration"
},
{
"name": "init_standalone_default_value"
},
{
"name": "init_standalone_feature"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/testing/src/test_bed_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
ɵɵInjectableDeclaration as InjectableDeclaration,
NgZone,
ErrorHandler,
ɵNG_STANDALONE_DEFAULT_VALUE as NG_STANDALONE_DEFAULT_VALUE,
} from '@angular/core';

import {ComponentDef, ComponentType} from '../../src/render3';
Expand Down Expand Up @@ -102,7 +103,7 @@ function assertNoStandaloneComponents(
types.forEach((type) => {
if (!getAsyncClassMetadataFn(type)) {
const component = resolver.resolve(type);
if (component && component.standalone) {
if (component && (component.standalone ?? NG_STANDALONE_DEFAULT_VALUE)) {
throw new Error(ɵgenerateStandaloneInDeclarationsError(type, location));
}
}
Expand Down