Updated the files.

This commit is contained in:
Batuhan Berk Başoğlu 2024-02-08 19:38:41 -05:00
parent 1553e6b971
commit 753967d4f5
23418 changed files with 3784666 additions and 0 deletions

View file

@ -0,0 +1,110 @@
/**
* @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
*/
/**
* An abstraction for getting information from an AST while being agnostic to the underlying AST
* implementation.
*/
export interface AstHost<TExpression> {
/**
* Get the name of the symbol represented by the given expression node, or `null` if it is not a
* symbol.
*/
getSymbolName(node: TExpression): string | null;
/**
* Return `true` if the given expression is a string literal, or false otherwise.
*/
isStringLiteral(node: TExpression): boolean;
/**
* Parse the string value from the given expression, or throw if it is not a string literal.
*/
parseStringLiteral(str: TExpression): string;
/**
* Return `true` if the given expression is a numeric literal, or false otherwise.
*/
isNumericLiteral(node: TExpression): boolean;
/**
* Parse the numeric value from the given expression, or throw if it is not a numeric literal.
*/
parseNumericLiteral(num: TExpression): number;
/**
* Return `true` if the given expression can be considered a boolean literal, or false otherwise.
*
* Note that this should also cover the special case of some minified code where `true` and
* `false` are replaced by `!0` and `!1` respectively.
*/
isBooleanLiteral(node: TExpression): boolean;
/**
* Parse the boolean value from the given expression, or throw if it is not a boolean literal.
*
* Note that this should also cover the special case of some minified code where `true` and
* `false` are replaced by `!0` and `!1` respectively.
*/
parseBooleanLiteral(bool: TExpression): boolean;
/**
* Returns `true` if the value corresponds to `null`.
*/
isNull(node: TExpression): boolean;
/**
* Return `true` if the given expression is an array literal, or false otherwise.
*/
isArrayLiteral(node: TExpression): boolean;
/**
* Parse an array of expressions from the given expression, or throw if it is not an array
* literal.
*/
parseArrayLiteral(array: TExpression): TExpression[];
/**
* Return `true` if the given expression is an object literal, or false otherwise.
*/
isObjectLiteral(node: TExpression): boolean;
/**
* Parse the given expression into a map of object property names to property expressions, or
* throw if it is not an object literal.
*/
parseObjectLiteral(obj: TExpression): Map<string, TExpression>;
/**
* Return `true` if the given expression is a function, or false otherwise.
*/
isFunctionExpression(node: TExpression): boolean;
/**
* Compute the "value" of a function expression by parsing its body for a single `return`
* statement, extracting the returned expression, or throw if it is not possible.
*/
parseReturnValue(fn: TExpression): TExpression;
/**
* Return true if the given expression is a call expression, or false otherwise.
*/
isCallExpression(node: TExpression): boolean;
/**
* Returns the expression that is called in the provided call expression, or throw if it is not
* a call expression.
*/
parseCallee(call: TExpression): TExpression;
/**
* Returns the argument expressions for the provided call expression, or throw if it is not
* a call expression.
*/
parseArguments(call: TExpression): TExpression[];
/**
* Compute the location range of the expression in the source file, to be used for source-mapping.
*/
getRange(node: TExpression): Range;
}
/**
* The location of the start and end of an expression in the original source file.
*/
export interface Range {
/** 0-based character position of the range start in the source file text. */
startPos: number;
/** 0-based line index of the range start in the source file text. */
startLine: number;
/** 0-based column position of the range start in the source file text. */
startCol: number;
/** 0-based character position of the range end in the source file text. */
endPos: number;
}

View file

@ -0,0 +1,203 @@
/**
* @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
*/
import * as o from '@angular/compiler';
import { AstHost, Range } from './ast_host';
/**
* Represents only those types in `T` that are object types.
*
* Note: Excluding `Array` types as we consider object literals are "objects"
* in the AST.
*/
type ObjectType<T> = T extends Array<any> ? never : T extends Record<string, any> ? T : never;
/**
* Represents the value type of an object literal.
*/
type ObjectValueType<T> = T extends Record<string, infer R> ? R : never;
/**
* Represents the value type of an array literal.
*/
type ArrayValueType<T> = T extends Array<infer R> ? R : never;
/**
* Ensures that `This` has its generic type `Actual` conform to the expected generic type in
* `Expected`, to disallow calling a method if the generic type does not conform.
*/
type ConformsTo<This, Actual, Expected> = Actual extends Expected ? This : never;
/**
* Represents only the string keys of type `T`.
*/
type PropertyKey<T> = keyof T & string;
/**
* This helper class wraps an object expression along with an `AstHost` object, exposing helper
* methods that make it easier to extract the properties of the object.
*
* The generic `T` is used as reference type of the expected structure that is represented by this
* object. It does not achieve full type-safety for the provided operations in correspondence with
* `T`; its main goal is to provide references to a documented type and ensure that the properties
* that are read from the object are present.
*
* Unfortunately, the generic types are unable to prevent reading an optional property from the
* object without first having called `has` to ensure that the property exists. This is one example
* of where full type-safety is not achieved.
*/
export declare class AstObject<T extends object, TExpression> {
readonly expression: TExpression;
private obj;
private host;
/**
* Create a new `AstObject` from the given `expression` and `host`.
*/
static parse<T extends object, TExpression>(expression: TExpression, host: AstHost<TExpression>): AstObject<T, TExpression>;
private constructor();
/**
* Returns true if the object has a property called `propertyName`.
*/
has(propertyName: PropertyKey<T>): boolean;
/**
* Returns the number value of the property called `propertyName`.
*
* Throws an error if there is no such property or the property is not a number.
*/
getNumber<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], number>, propertyName: K): number;
/**
* Returns the string value of the property called `propertyName`.
*
* Throws an error if there is no such property or the property is not a string.
*/
getString<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], string>, propertyName: K): string;
/**
* Returns the boolean value of the property called `propertyName`.
*
* Throws an error if there is no such property or the property is not a boolean.
*/
getBoolean<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], boolean>, propertyName: K): boolean;
/**
* Returns the nested `AstObject` parsed from the property called `propertyName`.
*
* Throws an error if there is no such property or the property is not an object.
*/
getObject<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], object>, propertyName: K): AstObject<ObjectType<T[K]>, TExpression>;
/**
* Returns an array of `AstValue` objects parsed from the property called `propertyName`.
*
* Throws an error if there is no such property or the property is not an array.
*/
getArray<K extends PropertyKey<T>>(this: ConformsTo<this, T[K], unknown[]>, propertyName: K): AstValue<ArrayValueType<T[K]>, TExpression>[];
/**
* Returns a `WrappedNodeExpr` object that wraps the expression at the property called
* `propertyName`.
*
* Throws an error if there is no such property.
*/
getOpaque(propertyName: PropertyKey<T>): o.WrappedNodeExpr<TExpression>;
/**
* Returns the raw `TExpression` value of the property called `propertyName`.
*
* Throws an error if there is no such property.
*/
getNode(propertyName: PropertyKey<T>): TExpression;
/**
* Returns an `AstValue` that wraps the value of the property called `propertyName`.
*
* Throws an error if there is no such property.
*/
getValue<K extends PropertyKey<T>>(propertyName: K): AstValue<T[K], TExpression>;
/**
* Converts the AstObject to a raw JavaScript object, mapping each property value (as an
* `AstValue`) to the generic type (`T`) via the `mapper` function.
*/
toLiteral<V>(mapper: (value: AstValue<ObjectValueType<T>, TExpression>, key: string) => V): Record<string, V>;
/**
* Converts the AstObject to a JavaScript Map, mapping each property value (as an
* `AstValue`) to the generic type (`T`) via the `mapper` function.
*/
toMap<V>(mapper: (value: AstValue<ObjectValueType<T>, TExpression>) => V): Map<string, V>;
private getRequiredProperty;
}
/**
* This helper class wraps an `expression`, exposing methods that use the `host` to give
* access to the underlying value of the wrapped expression.
*
* The generic `T` is used as reference type of the expected type that is represented by this value.
* It does not achieve full type-safety for the provided operations in correspondence with `T`; its
* main goal is to provide references to a documented type.
*/
export declare class AstValue<T, TExpression> {
readonly expression: TExpression;
private host;
/** Type brand that ensures that the `T` type is respected for assignability. */
ɵtypeBrand: T;
constructor(expression: TExpression, host: AstHost<TExpression>);
/**
* Get the name of the symbol represented by the given expression node, or `null` if it is not a
* symbol.
*/
getSymbolName(): string | null;
/**
* Is this value a number?
*/
isNumber(): boolean;
/**
* Parse the number from this value, or error if it is not a number.
*/
getNumber(this: ConformsTo<this, T, number>): number;
/**
* Is this value a string?
*/
isString(): boolean;
/**
* Parse the string from this value, or error if it is not a string.
*/
getString(this: ConformsTo<this, T, string>): string;
/**
* Is this value a boolean?
*/
isBoolean(): boolean;
/**
* Parse the boolean from this value, or error if it is not a boolean.
*/
getBoolean(this: ConformsTo<this, T, boolean>): boolean;
/**
* Is this value an object literal?
*/
isObject(): boolean;
/**
* Parse this value into an `AstObject`, or error if it is not an object literal.
*/
getObject(this: ConformsTo<this, T, object>): AstObject<ObjectType<T>, TExpression>;
/**
* Is this value an array literal?
*/
isArray(): boolean;
/** Whether the value is explicitly set to `null`. */
isNull(): boolean;
/**
* Parse this value into an array of `AstValue` objects, or error if it is not an array literal.
*/
getArray(this: ConformsTo<this, T, unknown[]>): AstValue<ArrayValueType<T>, TExpression>[];
/**
* Is this value a function expression?
*/
isFunction(): boolean;
/**
* Extract the return value as an `AstValue` from this value as a function expression, or error if
* it is not a function expression.
*/
getFunctionReturnValue<R>(this: ConformsTo<this, T, Function>): AstValue<R, TExpression>;
isCallExpression(): boolean;
getCallee(): AstValue<unknown, TExpression>;
getArguments(): AstValue<unknown, TExpression>[];
/**
* Return the `TExpression` of this value wrapped in a `WrappedNodeExpr`.
*/
getOpaque(): o.WrappedNodeExpr<TExpression>;
/**
* Get the range of the location of this value in the original source.
*/
getRange(): Range;
}
export {};

View file

@ -0,0 +1,38 @@
/**
* @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
*/
import ts from 'typescript';
import { AstHost, Range } from '../ast_host';
/**
* This implementation of `AstHost` is able to get information from TypeScript AST nodes.
*
* This host is not actually used at runtime in the current code.
*
* It is implemented here to ensure that the `AstHost` abstraction is not unfairly skewed towards
* the Babel implementation. It could also provide a basis for a 3rd TypeScript compiler plugin to
* do linking in the future.
*/
export declare class TypeScriptAstHost implements AstHost<ts.Expression> {
getSymbolName(node: ts.Expression): string | null;
isStringLiteral: typeof ts.isStringLiteral;
parseStringLiteral(str: ts.Expression): string;
isNull(node: ts.Expression): boolean;
isNumericLiteral: typeof ts.isNumericLiteral;
parseNumericLiteral(num: ts.Expression): number;
isBooleanLiteral(node: ts.Expression): boolean;
parseBooleanLiteral(bool: ts.Expression): boolean;
isArrayLiteral: typeof ts.isArrayLiteralExpression;
parseArrayLiteral(array: ts.Expression): ts.Expression[];
isObjectLiteral: typeof ts.isObjectLiteralExpression;
parseObjectLiteral(obj: ts.Expression): Map<string, ts.Expression>;
isFunctionExpression(node: ts.Expression): node is ts.FunctionExpression | ts.ArrowFunction;
parseReturnValue(fn: ts.Expression): ts.Expression;
isCallExpression: typeof ts.isCallExpression;
parseCallee(call: ts.Expression): ts.Expression;
parseArguments(call: ts.Expression): ts.Expression[];
getRange(node: ts.Expression): Range;
}

View file

@ -0,0 +1,4 @@
/**
* Assert that the given `node` is of the type guarded by the `predicate` function.
*/
export declare function assert<T, K extends T>(node: T, predicate: (node: T) => node is K, expected: string): asserts node is K;

View file

@ -0,0 +1,25 @@
/**
* @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
*/
/**
* An unrecoverable error during linking.
*/
export declare class FatalLinkerError extends Error {
node: unknown;
readonly type = "FatalLinkerError";
/**
* Create a new FatalLinkerError.
*
* @param node The AST node where the error occurred.
* @param message A description of the error.
*/
constructor(node: unknown, message: string);
}
/**
* Whether the given object `e` is a FatalLinkerError.
*/
export declare function isFatalLinkerError(e: any): e is FatalLinkerError;

View file

@ -0,0 +1,44 @@
/**
* @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
*/
/**
* This interface represents the lexical scope of a partial declaration in the source code.
*
* For example, if you had the following code:
*
* ```
* function foo() {
* function bar () {
* ɵɵngDeclareDirective({...});
* }
* }
* ```
*
* The `DeclarationScope` of the `ɵɵngDeclareDirective()` call is the body of the `bar()` function.
*
* The `FileLinker` uses this object to identify the lexical scope of any constant statements that
* might be generated by the linking process (i.e. where the `ConstantPool` lives for a set of
* partial linkers).
*/
export interface DeclarationScope<TSharedConstantScope, TExpression> {
/**
* Get a `TSharedConstantScope` object that can be used to reference the lexical scope where any
* shared constant statements would be inserted.
*
* This object is generic because different AST implementations will need different
* `TConstantScope` types to be able to insert shared constant statements. For example in Babel
* this would be a `NodePath` object; in TS it would just be a `Node` object.
*
* If it is not possible to find such a shared scope, then constant statements will be wrapped up
* with their generated linked definition expression, in the form of an IIFE.
*
* @param expression the expression that points to the Angular core framework import.
* @returns a reference to a reference object for where the shared constant statements will be
* inserted, or `null` if it is not possible to have a shared scope.
*/
getConstantScopeRef(expression: TExpression): TSharedConstantScope | null;
}

View file

@ -0,0 +1,38 @@
/**
* @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
*/
import { ConstantPool } from '@angular/compiler';
import { AstFactory } from '../../../../src/ngtsc/translator';
import { LinkedDefinition } from '../partial_linkers/partial_linker';
import { Translator } from '../translator';
/**
* This class represents (from the point of view of the `FileLinker`) the scope in which
* statements and expressions related to a linked partial declaration will be emitted.
*
* It holds a copy of a `ConstantPool` that is used to capture any constant statements that need to
* be emitted in this context.
*
* This implementation will emit the definition and the constant statements separately.
*/
export declare class EmitScope<TStatement, TExpression> {
protected readonly ngImport: TExpression;
protected readonly translator: Translator<TStatement, TExpression>;
private readonly factory;
readonly constantPool: ConstantPool;
constructor(ngImport: TExpression, translator: Translator<TStatement, TExpression>, factory: AstFactory<TStatement, TExpression>);
/**
* Translate the given Output AST definition expression into a generic `TExpression`.
*
* Use a `LinkerImportGenerator` to handle any imports in the definition.
*/
translateDefinition(definition: LinkedDefinition): TExpression;
/**
* Return any constant statements that are shared between all uses of this `EmitScope`.
*/
getConstantStatements(): TStatement[];
private wrapInIifeWithStatements;
}

View file

@ -0,0 +1,28 @@
/**
* @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
*/
import { LinkedDefinition } from '../partial_linkers/partial_linker';
import { EmitScope } from './emit_scope';
/**
* This class is a specialization of the `EmitScope` class that is designed for the situation where
* there is no clear shared scope for constant statements. In this case they are bundled with the
* translated definition and will be emitted into an IIFE.
*/
export declare class LocalEmitScope<TStatement, TExpression> extends EmitScope<TStatement, TExpression> {
/**
* Translate the given Output AST definition expression into a generic `TExpression`.
*
* Merges the `ConstantPool` statements with the definition statements when generating the
* definition expression. This means that `ConstantPool` statements will be emitted into an IIFE.
*/
translateDefinition(definition: LinkedDefinition): TExpression;
/**
* It is not valid to call this method, since there will be no shared constant statements - they
* are already emitted in the IIFE alongside the translated definition.
*/
getConstantStatements(): TStatement[];
}

View file

@ -0,0 +1,39 @@
import { AbsoluteFsPath } from '../../../src/ngtsc/file_system';
import { DeclarationScope } from './declaration_scope';
import { LinkerEnvironment } from './linker_environment';
export declare const NO_STATEMENTS: Readonly<any[]>;
/**
* This class is responsible for linking all the partial declarations found in a single file.
*/
export declare class FileLinker<TConstantScope, TStatement, TExpression> {
private linkerEnvironment;
private linkerSelector;
private emitScopes;
constructor(linkerEnvironment: LinkerEnvironment<TStatement, TExpression>, sourceUrl: AbsoluteFsPath, code: string);
/**
* Return true if the given callee name matches a partial declaration that can be linked.
*/
isPartialDeclaration(calleeName: string): boolean;
/**
* Link the metadata extracted from the args of a call to a partial declaration function.
*
* The `declarationScope` is used to determine the scope and strategy of emission of the linked
* definition and any shared constant statements.
*
* @param declarationFn the name of the function used to declare the partial declaration - e.g.
* `ɵɵngDeclareDirective`.
* @param args the arguments passed to the declaration function, should be a single object that
* corresponds to the `R3DeclareDirectiveMetadata` or `R3DeclareComponentMetadata` interfaces.
* @param declarationScope the scope that contains this call to the declaration function.
*/
linkPartialDeclaration(declarationFn: string, args: TExpression[], declarationScope: DeclarationScope<TConstantScope, TExpression>): TExpression;
/**
* Return all the shared constant statements and their associated constant scope references, so
* that they can be inserted into the source code.
*/
getConstantStatements(): {
constantScope: TConstantScope;
statements: TStatement[];
}[];
private getEmitScope;
}

View file

@ -0,0 +1,18 @@
/**
* @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
*/
import { AbsoluteFsPath } from '../../../src/ngtsc/file_system';
import { SourceFile, SourceFileLoader } from '../../../src/ngtsc/sourcemaps';
/**
* A function that will return a `SourceFile` object (or null) for the current file being linked.
*/
export type GetSourceFileFn = () => SourceFile | null;
/**
* Create a `GetSourceFileFn` that will return the `SourceFile` being linked or `null`, if not
* available.
*/
export declare function createGetSourceFile(sourceUrl: AbsoluteFsPath, code: string, loader: SourceFileLoader | null): GetSourceFileFn;

View file

@ -0,0 +1,25 @@
/**
* @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
*/
import { ReadonlyFileSystem } from '../../../src/ngtsc/file_system';
import { Logger } from '../../../src/ngtsc/logging';
import { SourceFileLoader } from '../../../src/ngtsc/sourcemaps';
import { AstFactory } from '../../../src/ngtsc/translator';
import { AstHost } from '../ast/ast_host';
import { LinkerOptions } from './linker_options';
import { Translator } from './translator';
export declare class LinkerEnvironment<TStatement, TExpression> {
readonly fileSystem: ReadonlyFileSystem;
readonly logger: Logger;
readonly host: AstHost<TExpression>;
readonly factory: AstFactory<TStatement, TExpression>;
readonly options: LinkerOptions;
readonly translator: Translator<TStatement, TExpression>;
readonly sourceFileLoader: SourceFileLoader | null;
private constructor();
static create<TStatement, TExpression>(fileSystem: ReadonlyFileSystem, logger: Logger, host: AstHost<TExpression>, factory: AstFactory<TStatement, TExpression>, options: Partial<LinkerOptions>): LinkerEnvironment<TStatement, TExpression>;
}

View file

@ -0,0 +1,41 @@
/**
* @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
*/
/**
* Options to configure the linking behavior.
*/
export interface LinkerOptions {
/**
* Whether to use source-mapping to compute the original source for external templates.
* The default is `true`.
*/
sourceMapping: boolean;
/**
* This option tells the linker to generate information used by a downstream JIT compiler.
*
* Specifically, in JIT mode, NgModule definitions must describe the `declarations`, `imports`,
* `exports`, etc, which are otherwise not needed.
*/
linkerJitMode: boolean;
/**
* How to handle a situation where a partial declaration matches none of the supported
* partial-linker versions.
*
* - `error` - the version mismatch is a fatal error.
* - `warn` - a warning is sent to the logger but the most recent partial-linker
* will attempt to process the declaration anyway.
* - `ignore` - the most recent partial-linker will, silently, attempt to process
* the declaration.
*
* The default is `error`.
*/
unknownDeclarationVersionHandling: 'ignore' | 'warn' | 'error';
}
/**
* The default linker options to use if properties are not provided.
*/
export declare const DEFAULT_LINKER_OPTIONS: LinkerOptions;

View file

@ -0,0 +1,23 @@
/**
* @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
*/
/**
* Determines if the provided source file may need to be processed by the linker, i.e. whether it
* potentially contains any declarations. If true is returned, then the source file should be
* processed by the linker as it may contain declarations that need to be fully compiled. If false
* is returned, parsing and processing of the source file can safely be skipped to improve
* performance.
*
* This function may return true even for source files that don't actually contain any declarations
* that need to be compiled.
*
* @param path the absolute path of the source file for which to determine whether linking may be
* needed.
* @param source the source file content as a string.
* @returns whether the source file may contain declarations that need to be linked.
*/
export declare function needsLinking(path: string, source: string): boolean;

View file

@ -0,0 +1,20 @@
/**
* @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
*/
import { ConstantPool, R3ClassMetadata, R3DeclareClassMetadata, R3PartialDeclaration } from '@angular/compiler';
import { AstObject } from '../../ast/ast_value';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareClassMetadata()` call expressions.
*/
export declare class PartialClassMetadataLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>): LinkedDefinition;
}
/**
* Derives the `R3ClassMetadata` structure from the AST object.
*/
export declare function toR3ClassMetadata<TExpression>(metaObj: AstObject<R3DeclareClassMetadata, TExpression>): R3ClassMetadata;

View file

@ -0,0 +1,34 @@
/**
* @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
*/
import { ConstantPool, R3PartialDeclaration } from '@angular/compiler';
import { AbsoluteFsPath } from '../../../../src/ngtsc/file_system';
import { AstObject } from '../../ast/ast_value';
import { GetSourceFileFn } from '../get_source_file';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareComponent()` call expressions.
*/
export declare class PartialComponentLinkerVersion1<TStatement, TExpression> implements PartialLinker<TExpression> {
private readonly getSourceFile;
private sourceUrl;
private code;
constructor(getSourceFile: GetSourceFileFn, sourceUrl: AbsoluteFsPath, code: string);
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>, version: string): LinkedDefinition;
/**
* This function derives the `R3ComponentMetadata` from the provided AST object.
*/
private toR3ComponentMeta;
/**
* Update the range to remove the start and end chars, which should be quotes around the template.
*/
private getTemplateInfo;
private tryExternalTemplate;
private templateFromPartialCode;
private createR3DeferredMetadata;
private resolveDeferTriggers;
}

View file

@ -0,0 +1,26 @@
/**
* @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
*/
import { ConstantPool, ParseSourceSpan, R3DeclareDirectiveMetadata, R3DirectiveMetadata, R3PartialDeclaration } from '@angular/compiler';
import { AbsoluteFsPath } from '../../../../src/ngtsc/file_system';
import { Range } from '../../ast/ast_host';
import { AstObject } from '../../ast/ast_value';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareDirective()` call expressions.
*/
export declare class PartialDirectiveLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
private sourceUrl;
private code;
constructor(sourceUrl: AbsoluteFsPath, code: string);
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>): LinkedDefinition;
}
/**
* Derives the `R3DirectiveMetadata` structure from the AST object.
*/
export declare function toR3DirectiveMeta<TExpression>(metaObj: AstObject<R3DeclareDirectiveMetadata, TExpression>, code: string, sourceUrl: AbsoluteFsPath): R3DirectiveMetadata;
export declare function createSourceSpan(range: Range, code: string, sourceUrl: string): ParseSourceSpan;

View file

@ -0,0 +1,20 @@
/**
* @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
*/
import { ConstantPool, R3DeclareFactoryMetadata, R3FactoryMetadata, R3PartialDeclaration } from '@angular/compiler';
import { AstObject } from '../../ast/ast_value';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareFactory()` call expressions.
*/
export declare class PartialFactoryLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>): LinkedDefinition;
}
/**
* Derives the `R3FactoryMetadata` structure from the AST object.
*/
export declare function toR3FactoryMeta<TExpression>(metaObj: AstObject<R3DeclareFactoryMetadata, TExpression>): R3FactoryMetadata;

View file

@ -0,0 +1,20 @@
/**
* @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
*/
import { ConstantPool, R3DeclareInjectableMetadata, R3InjectableMetadata, R3PartialDeclaration } from '@angular/compiler';
import { AstObject } from '../../ast/ast_value';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareInjectable()` call expressions.
*/
export declare class PartialInjectableLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>): LinkedDefinition;
}
/**
* Derives the `R3InjectableMetadata` structure from the AST object.
*/
export declare function toR3InjectableMeta<TExpression>(metaObj: AstObject<R3DeclareInjectableMetadata, TExpression>): R3InjectableMetadata;

View file

@ -0,0 +1,20 @@
/**
* @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
*/
import { ConstantPool, R3DeclareInjectorMetadata, R3InjectorMetadata, R3PartialDeclaration } from '@angular/compiler';
import { AstObject } from '../../ast/ast_value';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareInjector()` call expressions.
*/
export declare class PartialInjectorLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>): LinkedDefinition;
}
/**
* Derives the `R3InjectorMetadata` structure from the AST object.
*/
export declare function toR3InjectorMeta<TExpression>(metaObj: AstObject<R3DeclareInjectorMetadata, TExpression>): R3InjectorMetadata;

View file

@ -0,0 +1,28 @@
/**
* @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
*/
import { ConstantPool, outputAst as o, R3PartialDeclaration } from '@angular/compiler';
import { AstObject } from '../../ast/ast_value';
/**
* A definition generated by a `PartialLinker`, ready to emit.
*/
export interface LinkedDefinition {
expression: o.Expression;
statements: o.Statement[];
}
/**
* An interface for classes that can link partial declarations into full definitions.
*/
export interface PartialLinker<TExpression> {
/**
* Link the partial declaration `metaObj` information to generate a full definition expression.
*
* @param metaObj An object that fits one of the `R3DeclareDirectiveMetadata` or
* `R3DeclareComponentMetadata` interfaces.
*/
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>, version: string): LinkedDefinition;
}

View file

@ -0,0 +1,80 @@
/**
* @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
*/
import semver from 'semver';
import { AbsoluteFsPath } from '../../../../src/ngtsc/file_system';
import { Logger } from '../../../../src/ngtsc/logging';
import { LinkerEnvironment } from '../linker_environment';
import { PartialLinker } from './partial_linker';
export declare const ɵɵngDeclareDirective = "\u0275\u0275ngDeclareDirective";
export declare const ɵɵngDeclareClassMetadata = "\u0275\u0275ngDeclareClassMetadata";
export declare const ɵɵngDeclareComponent = "\u0275\u0275ngDeclareComponent";
export declare const ɵɵngDeclareFactory = "\u0275\u0275ngDeclareFactory";
export declare const ɵɵngDeclareInjectable = "\u0275\u0275ngDeclareInjectable";
export declare const ɵɵngDeclareInjector = "\u0275\u0275ngDeclareInjector";
export declare const ɵɵngDeclareNgModule = "\u0275\u0275ngDeclareNgModule";
export declare const ɵɵngDeclarePipe = "\u0275\u0275ngDeclarePipe";
export declare const declarationFunctions: string[];
export interface LinkerRange<TExpression> {
range: semver.Range;
linker: PartialLinker<TExpression>;
}
/**
* Create a mapping between partial-declaration call name and collections of partial-linkers.
*
* Each collection of partial-linkers will contain a version range that will be matched against the
* `minVersion` of the partial-declaration. (Additionally, a partial-linker may modify its behaviour
* internally based on the `version` property of the declaration.)
*
* Versions should be sorted in ascending order. The most recent partial-linker will be used as the
* fallback linker if none of the other version ranges match. For example:
*
* ```
* {range: getRange('<=', '13.0.0'), linker PartialDirectiveLinkerVersion2(...) },
* {range: getRange('<=', '13.1.0'), linker PartialDirectiveLinkerVersion3(...) },
* {range: getRange('<=', '14.0.0'), linker PartialDirectiveLinkerVersion4(...) },
* {range: LATEST_VERSION_RANGE, linker: new PartialDirectiveLinkerVersion1(...)},
* ```
*
* If the `LATEST_VERSION_RANGE` is `<=15.0.0` then the fallback linker would be
* `PartialDirectiveLinkerVersion1` for any version greater than `15.0.0`.
*
* When there is a change to a declaration interface that requires a new partial-linker, the
* `minVersion` of the partial-declaration should be updated, the new linker implementation should
* be added to the end of the collection, and the version of the previous linker should be updated.
*/
export declare function createLinkerMap<TStatement, TExpression>(environment: LinkerEnvironment<TStatement, TExpression>, sourceUrl: AbsoluteFsPath, code: string): Map<string, LinkerRange<TExpression>[]>;
/**
* A helper that selects the appropriate `PartialLinker` for a given declaration.
*
* The selection is made from a database of linker instances, chosen if their given semver range
* satisfies the `minVersion` of the partial declaration to be linked.
*
* Note that the ranges are checked in order, and the first matching range will be selected. So
* ranges should be most restrictive first. In practice, since ranges are always `<=X.Y.Z` this
* means that ranges should be in ascending order.
*
* Note that any "pre-release" versions are stripped from ranges. Therefore if a `minVersion` is
* `11.1.0-next.1` then this would match `11.1.0-next.2` and also `12.0.0-next.1`. (This is
* different to standard semver range checking, where pre-release versions do not cross full version
* boundaries.)
*/
export declare class PartialLinkerSelector<TExpression> {
private readonly linkers;
private readonly logger;
private readonly unknownDeclarationVersionHandling;
constructor(linkers: Map<string, LinkerRange<TExpression>[]>, logger: Logger, unknownDeclarationVersionHandling: 'ignore' | 'warn' | 'error');
/**
* Returns true if there are `PartialLinker` classes that can handle functions with this name.
*/
supportsDeclaration(functionName: string): boolean;
/**
* Returns the `PartialLinker` that can handle functions with the given name and version.
* Throws an error if there is none.
*/
getLinker(functionName: string, minVersion: string, version: string): PartialLinker<TExpression>;
}

View file

@ -0,0 +1,31 @@
/**
* @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
*/
import { ConstantPool, R3DeclareNgModuleMetadata, R3NgModuleMetadata, R3PartialDeclaration } from '@angular/compiler';
import { AstObject } from '../../ast/ast_value';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclareNgModule()` call expressions.
*/
export declare class PartialNgModuleLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
/**
* If true then emit the additional declarations, imports, exports, etc in the NgModule
* definition. These are only used by JIT compilation.
*/
private emitInline;
constructor(
/**
* If true then emit the additional declarations, imports, exports, etc in the NgModule
* definition. These are only used by JIT compilation.
*/
emitInline: boolean);
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>): LinkedDefinition;
}
/**
* Derives the `R3NgModuleMetadata` structure from the AST object.
*/
export declare function toR3NgModuleMeta<TExpression>(metaObj: AstObject<R3DeclareNgModuleMetadata, TExpression>, supportJit: boolean): R3NgModuleMetadata;

View file

@ -0,0 +1,21 @@
/**
* @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
*/
import { ConstantPool, R3DeclarePipeMetadata, R3PartialDeclaration, R3PipeMetadata } from '@angular/compiler';
import { AstObject } from '../../ast/ast_value';
import { LinkedDefinition, PartialLinker } from './partial_linker';
/**
* A `PartialLinker` that is designed to process `ɵɵngDeclarePipe()` call expressions.
*/
export declare class PartialPipeLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
constructor();
linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3PartialDeclaration, TExpression>): LinkedDefinition;
}
/**
* Derives the `R3PipeMetadata` structure from the AST object.
*/
export declare function toR3PipeMeta<TExpression>(metaObj: AstObject<R3DeclarePipeMetadata, TExpression>): R3PipeMetadata;

View file

@ -0,0 +1,30 @@
/**
* @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
*/
import { MaybeForwardRefExpression, outputAst as o, R3DeclareDependencyMetadata, R3DependencyMetadata, R3Reference } from '@angular/compiler';
import { AstObject, AstValue } from '../../ast/ast_value';
export declare const PLACEHOLDER_VERSION = "17.1.3";
export declare function wrapReference<TExpression>(wrapped: o.WrappedNodeExpr<TExpression>): R3Reference;
/**
* Parses the value of an enum from the AST value's symbol name.
*/
export declare function parseEnum<TExpression, TEnum>(value: AstValue<unknown, TExpression>, Enum: TEnum): TEnum[keyof TEnum];
/**
* Parse a dependency structure from an AST object.
*/
export declare function getDependency<TExpression>(depObj: AstObject<R3DeclareDependencyMetadata, TExpression>): R3DependencyMetadata;
/**
* Return an `R3ProviderExpression` that represents either the extracted type reference expression
* from a `forwardRef` function call, or the type itself.
*
* For example, the expression `forwardRef(function() { return FooDir; })` returns `FooDir`. Note
* that this expression is required to be wrapped in a closure, as otherwise the forward reference
* would be resolved before initialization.
*
* If there is no forwardRef call expression then we just return the opaque type.
*/
export declare function extractForwardRef<TExpression>(expr: AstValue<unknown, TExpression>): MaybeForwardRefExpression<o.WrappedNodeExpr<TExpression>>;

View file

@ -0,0 +1,25 @@
/**
* @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
*/
import * as o from '@angular/compiler';
import { AstFactory, ImportGenerator, TranslatorOptions } from '../../../src/ngtsc/translator';
/**
* Generic translator helper class, which exposes methods for translating expressions and
* statements.
*/
export declare class Translator<TStatement, TExpression> {
private factory;
constructor(factory: AstFactory<TStatement, TExpression>);
/**
* Translate the given output AST in the context of an expression.
*/
translateExpression(expression: o.Expression, imports: ImportGenerator<TExpression>, options?: TranslatorOptions<TExpression>): TExpression;
/**
* Translate the given output AST in the context of a statement.
*/
translateStatement(statement: o.Statement, imports: ImportGenerator<TExpression>, options?: TranslatorOptions<TExpression>): TStatement;
}

View file

@ -0,0 +1,23 @@
/**
* @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
*/
import { ImportGenerator, NamedImport } from '../../src/ngtsc/translator';
/**
* A class that is used to generate imports when translating from Angular Output AST to an AST to
* render, such as Babel.
*
* Note that, in the linker, there can only be imports from `@angular/core` and that these imports
* must be achieved by property access on an `ng` namespace identifier, which is passed in via the
* constructor.
*/
export declare class LinkerImportGenerator<TExpression> implements ImportGenerator<TExpression> {
private ngImport;
constructor(ngImport: TExpression);
generateNamespaceImport(moduleName: string): TExpression;
generateNamedImport(moduleName: string, originalSymbol: string): NamedImport<TExpression>;
private assertModuleName;
}