mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(core): Don't generate standalone: true for definitions (#58238)
The runtime default is now `standalone: true`. `ɵɵdefineComponent`, `ɵɵdefineDirective` and `ɵɵdefinePipe` now set `standalone` as `true` by default in the definitions. PR Close #58238
This commit is contained in:
parent
18ddf0de76
commit
a10f7cfbc2
6 changed files with 17 additions and 11 deletions
|
|
@ -15,7 +15,7 @@
|
|||
"uncompressed": {
|
||||
"main": 108611,
|
||||
"polyfills": 34169,
|
||||
"lazy.routes": 388
|
||||
"lazy.routes": 368
|
||||
}
|
||||
},
|
||||
"forms": {
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
"uncompressed": {
|
||||
"main": 11497,
|
||||
"polyfills": 33807,
|
||||
"defer.component": 371
|
||||
"defer.component": 351
|
||||
}
|
||||
},
|
||||
"platform-server-hydration/browser": {
|
||||
|
|
|
|||
|
|
@ -60,9 +60,8 @@ export function compilePipeFromMetadata(metadata: R3PipeMetadata): R3CompiledExp
|
|||
// e.g. `pure: true`
|
||||
definitionMapValues.push({key: 'pure', value: o.literal(metadata.pure), quoted: false});
|
||||
|
||||
// TODO: standalone as default value (invert the condition)
|
||||
if (metadata.isStandalone) {
|
||||
definitionMapValues.push({key: 'standalone', value: o.literal(true), quoted: false});
|
||||
if (metadata.isStandalone === false) {
|
||||
definitionMapValues.push({key: 'standalone', value: o.literal(false), quoted: false});
|
||||
}
|
||||
|
||||
const expression = o
|
||||
|
|
|
|||
|
|
@ -93,8 +93,8 @@ function baseDirectiveFields(
|
|||
definitionMap.set('exportAs', o.literalArr(meta.exportAs.map((e) => o.literal(e))));
|
||||
}
|
||||
|
||||
if (meta.isStandalone) {
|
||||
definitionMap.set('standalone', o.literal(true));
|
||||
if (meta.isStandalone === false) {
|
||||
definitionMap.set('standalone', o.literal(false));
|
||||
}
|
||||
if (meta.isSignal) {
|
||||
definitionMap.set('signals', o.literal(true));
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import {InputFlags} from './interfaces/input_flags';
|
|||
import type {TAttributes, TConstantsOrFactory} from './interfaces/node';
|
||||
import {CssSelectorList} from './interfaces/projection';
|
||||
import {stringifyCSSSelectorList} from './node_selector_matcher';
|
||||
import {NG_STANDALONE_DEFAULT_VALUE} from './standalone-default-value';
|
||||
|
||||
/**
|
||||
* Map of inputs for a given directive/component.
|
||||
|
|
@ -603,7 +604,7 @@ export function ɵɵdefinePipe<T>(pipeDef: {
|
|||
name: pipeDef.name,
|
||||
factory: null,
|
||||
pure: pipeDef.pure !== false,
|
||||
standalone: pipeDef.standalone === true,
|
||||
standalone: pipeDef.standalone ?? NG_STANDALONE_DEFAULT_VALUE,
|
||||
onDestroy: pipeDef.type.prototype.ngOnDestroy || null,
|
||||
};
|
||||
}
|
||||
|
|
@ -636,7 +637,6 @@ export function getPipeDef<T>(type: any): PipeDef<T> | null {
|
|||
*/
|
||||
export function isStandalone(type: Type<unknown>): boolean {
|
||||
const def = getComponentDef(type) || getDirectiveDef(type) || getPipeDef(type);
|
||||
// TODO: standalone as default value (invert the condition)
|
||||
return def !== null ? def.standalone : false;
|
||||
}
|
||||
|
||||
|
|
@ -665,8 +665,7 @@ function getNgDirectiveDef<T>(directiveDefinition: DirectiveDefinition<T>): Dire
|
|||
inputTransforms: null,
|
||||
inputConfig: directiveDefinition.inputs || EMPTY_OBJ,
|
||||
exportAs: directiveDefinition.exportAs || null,
|
||||
// TODO: standalone as default value (invert the condition)
|
||||
standalone: directiveDefinition.standalone === true,
|
||||
standalone: directiveDefinition.standalone ?? NG_STANDALONE_DEFAULT_VALUE,
|
||||
signals: directiveDefinition.signals === true,
|
||||
selectors: directiveDefinition.selectors || EMPTY_ARRAY,
|
||||
viewQuery: directiveDefinition.viewQuery || null,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ describe('CopyDefinitionFeature', () => {
|
|||
static override ɵcmp = defineComponent({
|
||||
type: ChildComponent,
|
||||
selectors: [['some-cmp']],
|
||||
standalone: false,
|
||||
features: [InheritDefinitionFeature, CopyDefinitionFeature],
|
||||
decls: 0,
|
||||
vars: 0,
|
||||
|
|
|
|||
|
|
@ -922,6 +922,13 @@ describe('standalone components, directives, and pipes', () => {
|
|||
|
||||
describe('isStandalone()', () => {
|
||||
it('should return `true` if component is standalone', () => {
|
||||
@Component({selector: 'standalone-cmp'})
|
||||
class StandaloneCmp {}
|
||||
|
||||
expect(isStandalone(StandaloneCmp)).toBeTrue();
|
||||
});
|
||||
|
||||
it('should return `true` if component is standalone (with `standalone:true`)', () => {
|
||||
@Component({selector: 'standalone-cmp', standalone: true})
|
||||
class StandaloneCmp {}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue