Skip to content
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', {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure that 0.0.0-PLACEHOLDER is also considered to pass.

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
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ import * as i0 from "@angular/core";
export class AbstractDirective {
}
AbstractDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: AbstractDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
AbstractDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: AbstractDirective, ngImport: i0 });
AbstractDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: AbstractDirective, isStandalone: true, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: AbstractDirective, decorators: [{
type: Directive
}] });
Expand All @@ -170,7 +170,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
import * as i0 from "@angular/core";
export declare class AbstractDirective {
static ɵfac: i0.ɵɵFactoryDeclaration<AbstractDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<AbstractDirective, never, never, {}, {}, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<AbstractDirective, never, never, {}, {}, never, never, true, never>;
}

/****************************************************************************************************
Expand Down Expand Up @@ -456,7 +456,7 @@ var Comp = /** @class */ (function () {
function Comp() {
}
Comp.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: Comp, deps: [], target: i0.ɵɵFactoryTarget.Component });
Comp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: Comp, selector: "ng-component", providers: [{ provide: token, useExisting: Comp }], ngImport: i0, template: '', isInline: true });
Comp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: Comp, isStandalone: true, selector: "ng-component", providers: [{ provide: token, useExisting: Comp }], ngImport: i0, template: '', isInline: true });
Comp = __decorate([
Custom()
], Comp);
Expand All @@ -478,7 +478,7 @@ import * as i0 from "@angular/core";
export declare function Custom(): (target: any) => void;
export declare class Comp {
static ɵfac: i0.ɵɵFactoryDeclaration<Comp, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<Comp, "ng-component", never, {}, {}, never, never, false, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<Comp, "ng-component", never, {}, {}, never, never, true, never>;
}

/****************************************************************************************************
Expand Down Expand Up @@ -665,7 +665,7 @@ import * as i0 from "@angular/core";
export class Main {
}
Main.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: Main, deps: [], target: i0.ɵɵFactoryTarget.Component });
Main.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: Main, selector: "ng-component", ngImport: i0, template: 'Hello Angular!', isInline: true });
Main.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: Main, isStandalone: true, selector: "ng-component", ngImport: i0, template: 'Hello Angular!', isInline: true });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: Main, decorators: [{
type: Component,
args: [{
Expand All @@ -690,7 +690,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
import * as i0 from "@angular/core";
export declare class Main {
static ɵfac: i0.ɵɵFactoryDeclaration<Main, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<Main, "ng-component", never, {}, {}, never, never, false, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<Main, "ng-component", never, {}, {}, never, never, true, never>;
}
export declare class MainStandalone {
static ɵfac: i0.ɵɵFactoryDeclaration<MainStandalone, never>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AbstractDirective.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
type: AbstractDirective
type: AbstractDirective,
standalone: true
});
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export class MyApp {
}
}
MyApp.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyApp, deps: [], target: i0.ɵɵFactoryTarget.Component });
MyApp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: MyApp, selector: "ng-component", ngImport: i0, template: `
MyApp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: MyApp, isStandalone: true, selector: "ng-component", ngImport: i0, template: `
{{message}}
@defer (
hydrate when isVisible() || isReady;
Expand Down Expand Up @@ -603,7 +603,7 @@ export declare class MyApp {
isReady: boolean;
isVisible(): boolean;
static ɵfac: i0.ɵɵFactoryDeclaration<MyApp, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<MyApp, "ng-component", never, {}, {}, never, never, false, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<MyApp, "ng-component", never, {}, {}, never, never, true, never>;
}

/****************************************************************************************************
Expand All @@ -617,7 +617,7 @@ export class MyApp {
}
}
MyApp.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyApp, deps: [], target: i0.ɵɵFactoryTarget.Component });
MyApp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: MyApp, selector: "ng-component", ngImport: i0, template: `
MyApp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "0.0.0-PLACEHOLDER", type: MyApp, isStandalone: true, selector: "ng-component", ngImport: i0, template: `
@defer (when isReady; hydrate on timer(1337); prefetch on viewport) {
Hello
} @placeholder {
Expand All @@ -644,7 +644,7 @@ import * as i0 from "@angular/core";
export declare class MyApp {
isReady: boolean;
static ɵfac: i0.ɵɵFactoryDeclaration<MyApp, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<MyApp, "ng-component", never, {}, {}, never, never, false, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<MyApp, "ng-component", never, {}, {}, never, never, true, never>;
}

/****************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export class MyComponent {
}
}
MyComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
MyComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyComponent, host: { listeners: { "click": "click($event.target)" } }, ngImport: i0 });
MyComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", type: MyComponent, isStandalone: true, host: { listeners: { "click": "click($event.target)" } }, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyComponent, decorators: [{
type: Directive
}], propDecorators: { click: [{
Expand All @@ -459,7 +459,7 @@ import * as i0 from "@angular/core";
export declare class MyComponent {
click(target: any): void;
static ɵfac: i0.ɵɵFactoryDeclaration<MyComponent, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<MyComponent, never, never, {}, {}, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<MyComponent, never, never, {}, {}, never, never, true, never>;
}

/****************************************************************************************************
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-cli/test/ngtsc/authoring_models_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ runInEachFileSystem(() => {
expect(dts).toContain(
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, ' +
'{ "value": { "alias": "value"; "required": false; "isSignal": true; }; }, ' +
'{ "value": "valueChange"; }, never, never, false, never>;',
'{ "value": "valueChange"; }, never, never, true, never>;',
);
});

Expand All @@ -72,7 +72,7 @@ runInEachFileSystem(() => {
expect(dts).toContain(
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, ' +
'{ "value": { "alias": "alias"; "required": false; "isSignal": true; }; }, ' +
'{ "value": "aliasChange"; }, never, never, false, never>;',
'{ "value": "aliasChange"; }, never, never, true, never>;',
);
});

Expand All @@ -98,7 +98,7 @@ runInEachFileSystem(() => {
expect(dts).toContain(
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, ' +
'{ "value": { "alias": "value"; "required": true; "isSignal": true; }; }, ' +
'{ "value": "valueChange"; }, never, never, false, never>;',
'{ "value": "valueChange"; }, never, never, true, never>;',
);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ runInEachFileSystem((os: string) => {

const dtsContents = env.getContents('test.d.ts');
expect(dtsContents).toContain(
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, {}, {}, never, never, false, never>',
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, {}, {}, never, never, true, never>',
);
expect(dtsContents).toContain('static ɵfac: i0.ɵɵFactoryDeclaration<TestDir, never>');
});
Expand Down Expand Up @@ -1401,11 +1401,11 @@ runInEachFileSystem((os: string) => {

const jsContents = env.getContents('test.js');
expect(jsContents).toContain(
'i0.ɵɵdefineDirective({ type: TestBase, inputs: { input: "input" } });',
'i0.ɵɵdefineDirective({ type: TestBase, inputs: { input: "input" }, standalone: true });',
);

const dtsContents = env.getContents('test.d.ts');
const expectedDirectiveDeclaration = `static ɵdir: i0.ɵɵDirectiveDeclaration<TestBase, never, never, { "input": { "alias": "input"; "required": false; }; }, {}, never, never, false, never>;`;
const expectedDirectiveDeclaration = `static ɵdir: i0.ɵɵDirectiveDeclaration<TestBase, never, never, { "input": { "alias": "input"; "required": false; }; }, {}, never, never, true, never>;`;
expect(dtsContents).toContain(expectedDirectiveDeclaration);
});

Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/src/compiler_facade_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export type LegacyInputPartialMapping =
export interface R3DeclareDirectiveFacade {
selector?: string;
type: Type;
version: string;
inputs?: {
[fieldName: string]:
| {
Expand Down Expand Up @@ -390,6 +391,7 @@ export interface R3DeclareNgModuleFacade {

export interface R3DeclarePipeFacade {
type: Type;
version: string;
name: string;
pure?: boolean;
isStandalone?: boolean;
Expand Down
Loading