Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(compiler-cli): Adapt the compiler to use standalone by default. #58169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
2 changes: 1 addition & 1 deletion goldens/public-api/upgrade/static/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
// (undocumented)
ngOnInit(): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<UpgradeComponent, never, never, {}, {}, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<UpgradeComponent, never, never, {}, {}, never, never, true, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<UpgradeComponent, never>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression>
}

return {
...toR3DirectiveMeta(metaObj, this.code, this.sourceUrl),
...toR3DirectiveMeta(metaObj, this.code, this.sourceUrl, version),
viewProviders: metaObj.has('viewProviders') ? metaObj.getOpaque('viewProviders') : null,
template: {
nodes: template.nodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {AstObject, AstValue} from '../../ast/ast_value';
import {FatalLinkerError} from '../../fatal_linker_error';

import {LinkedDefinition, PartialLinker} from './partial_linker';
import {extractForwardRef, wrapReference} from './util';
import {extractForwardRef, getDefaultStandaloneValue, wrapReference} from './util';

/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareDirective()` call expressions.
Expand All @@ -46,8 +46,9 @@ export class PartialDirectiveLinkerVersion1<TExpression> implements PartialLinke
linkPartialDeclaration(
constantPool: ConstantPool,
metaObj: AstObject<R3PartialDeclaration, TExpression>,
version: string,
): LinkedDefinition {
const meta = toR3DirectiveMeta(metaObj, this.code, this.sourceUrl);
const meta = toR3DirectiveMeta(metaObj, this.code, this.sourceUrl, version);
return compileDirectiveFromMetadata(meta, constantPool, makeBindingParser());
}
}
Expand All @@ -59,6 +60,7 @@ export function toR3DirectiveMeta<TExpression>(
metaObj: AstObject<R3DeclareDirectiveMetadata, TExpression>,
code: string,
sourceUrl: AbsoluteFsPath,
version: string,
): R3DirectiveMetadata {
const typeExpr = metaObj.getValue('type');
const typeName = typeExpr.getSymbolName();
Expand Down Expand Up @@ -96,7 +98,9 @@ export function toR3DirectiveMeta<TExpression>(
},
name: typeName,
usesInheritance: metaObj.has('usesInheritance') ? metaObj.getBoolean('usesInheritance') : false,
isStandalone: metaObj.has('isStandalone') ? metaObj.getBoolean('isStandalone') : false,
isStandalone: metaObj.has('isStandalone')
? metaObj.getBoolean('isStandalone')
: getDefaultStandaloneValue(version),
isSignal: metaObj.has('isSignal') ? metaObj.getBoolean('isSignal') : false,
hostDirectives: metaObj.has('hostDirectives')
? toHostDirectivesMetadata(metaObj.getValue('hostDirectives'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {AstObject} from '../../ast/ast_value';
import {FatalLinkerError} from '../../fatal_linker_error';

import {LinkedDefinition, PartialLinker} from './partial_linker';
import {wrapReference} from './util';
import {getDefaultStandaloneValue, wrapReference} from './util';

/**
* A `PartialLinker` that is designed to process `ɵɵngDeclarePipe()` call expressions.
Expand All @@ -29,8 +29,9 @@ export class PartialPipeLinkerVersion1<TExpression> implements PartialLinker<TEx
linkPartialDeclaration(
constantPool: ConstantPool,
metaObj: AstObject<R3PartialDeclaration, TExpression>,
version: string,
): LinkedDefinition {
const meta = toR3PipeMeta(metaObj);
const meta = toR3PipeMeta(metaObj, version);
return compilePipeFromMetadata(meta);
}
}
Expand All @@ -40,6 +41,7 @@ export class PartialPipeLinkerVersion1<TExpression> implements PartialLinker<TEx
*/
export function toR3PipeMeta<TExpression>(
metaObj: AstObject<R3DeclarePipeMetadata, TExpression>,
version: string,
): R3PipeMetadata {
const typeExpr = metaObj.getValue('type');
const typeName = typeExpr.getSymbolName();
Expand All @@ -51,7 +53,9 @@ export function toR3PipeMeta<TExpression>(
}

const pure = metaObj.has('pure') ? metaObj.getBoolean('pure') : true;
const isStandalone = metaObj.has('isStandalone') ? metaObj.getBoolean('isStandalone') : false;
const isStandalone = metaObj.has('isStandalone')
? metaObj.getBoolean('isStandalone')
: getDefaultStandaloneValue(version);

return {
name: typeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {

import {AstObject, AstValue} from '../../ast/ast_value';
import {FatalLinkerError} from '../../fatal_linker_error';
import semver from 'semver';

export const PLACEHOLDER_VERSION = '0.0.0-PLACEHOLDER';

Expand Down Expand Up @@ -113,3 +114,11 @@ export function extractForwardRef<TExpression>(
ForwardRefHandling.Unwrapped,
);
}

const STANDALONE_IS_DEFAULT_RANGE = new semver.Range(`>= 19.0.0 || ${PLACEHOLDER_VERSION}`, {
includePrerelease: true,
});

export function getDefaultStandaloneValue(version: string): boolean {
return STANDALONE_IS_DEFAULT_RANGE.test(version);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
* 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;
export const NG_STANDALONE_DEFAULT_VALUE = true;
2 changes: 2 additions & 0 deletions packages/compiler-cli/src/ngtsc/metadata/src/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class DtsMetadataReader implements MetadataReader {
const ngContentSelectors =
def.type.typeArguments.length > 6 ? readStringArrayType(def.type.typeArguments[6]) : null;

// Note: the default value is still `false` here, because only legacy .d.ts files written before
// we had so many arguments use this default.
const isStandalone =
def.type.typeArguments.length > 7 && (readBooleanType(def.type.typeArguments[7]) ?? false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
export class ComponentWithExternalResource {
}
ComponentWithExternalResource.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: ComponentWithExternalResource, deps: [], target: i0.ɵɵFactoryTarget.Component });
ComponentWithExternalResource.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: ComponentWithExternalResource, selector: "test-cmp", ngImport: i0, template: "<span>Test template</span>\n" });
ComponentWithExternalResource.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: ComponentWithExternalResource, isStandalone: true, selector: "test-cmp", ngImport: i0, template: "<span>Test template</span>\n" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: ComponentWithExternalResource, decorators: [{
type: Component,
args: [{ selector: 'test-cmp', template: "<span>Test template</span>\n" }]
Expand All @@ -78,7 +78,7 @@ export declare class RootInjectable {
}
export declare class ComponentWithExternalResource {
static ɵfac: i0.ɵɵFactoryDeclaration<ComponentWithExternalResource, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<ComponentWithExternalResource, "test-cmp", never, {}, {}, never, never, false, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<ComponentWithExternalResource, "test-cmp", never, {}, {}, never, never, true, never>;
}

/****************************************************************************************************
Expand Down Expand Up @@ -119,7 +119,7 @@ import * as i0 from "@angular/core";
export class MyDir {
}
MyDir.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyDir, deps: [], target: i0.ɵɵFactoryTarget.Directive });
MyDir.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyDir, inputs: { foo: "foo", bar: ["baz", "bar"], mixed: "mixed" }, outputs: { mixed: "mixed" }, ngImport: i0 });
MyDir.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyDir, isStandalone: true, inputs: { foo: "foo", bar: ["baz", "bar"], mixed: "mixed" }, outputs: { mixed: "mixed" }, ngImport: i0 });
__decorate([
CustomPropDecorator(),
__metadata("design:type", String)
Expand Down Expand Up @@ -152,7 +152,7 @@ export declare class MyDir {
mixed: string;
none: string;
static ɵfac: i0.ɵɵFactoryDeclaration<MyDir, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<MyDir, never, never, { "foo": { "alias": "foo"; "required": false; }; "bar": { "alias": "baz"; "required": false; }; "mixed": { "alias": "mixed"; "required": false; }; }, { "mixed": "mixed"; }, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<MyDir, never, never, { "foo": { "alias": "foo"; "required": false; }; "bar": { "alias": "baz"; "required": false; }; "mixed": { "alias": "mixed"; "required": false; }; }, { "mixed": "mixed"; }, never, never, true, never>;
}

/****************************************************************************************************
Expand Down
Loading