mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(compiler): remove unused code and exports
Removes unused code and exports that are no longer referenced anywhere
in the compiler codebase.
(cherry picked from commit 337053ef1a)
This commit is contained in:
committed by
Jessica Janiuk
parent
832ff2aff3
commit
3478df716e
@@ -79,7 +79,6 @@ class FixupExpression extends o.Expression {
|
||||
export class ConstantPool {
|
||||
statements: o.Statement[] = [];
|
||||
private literals = new Map<string, FixupExpression>();
|
||||
private literalFactories = new Map<string, o.Expression>();
|
||||
private sharedConstants = new Map<string, o.Expression>();
|
||||
|
||||
/**
|
||||
@@ -90,8 +89,6 @@ export class ConstantPool {
|
||||
*/
|
||||
private _claimedNames = new Map<string, number>();
|
||||
|
||||
private nextNameIndex = 0;
|
||||
|
||||
constructor(private readonly isClosureCompilerEnabled: boolean = false) {}
|
||||
|
||||
getConstLiteral(literal: o.Expression, forceShared?: boolean): o.Expression {
|
||||
|
||||
@@ -16,10 +16,6 @@ export type MapEntry = {
|
||||
|
||||
export type MapLiteral = MapEntry[];
|
||||
|
||||
export function mapEntry(key: string, value: o.Expression): MapEntry {
|
||||
return {key, value, quoted: false};
|
||||
}
|
||||
|
||||
export function mapLiteral(
|
||||
obj: {[key: string]: o.Expression},
|
||||
quoted: boolean = false,
|
||||
|
||||
@@ -79,7 +79,7 @@ export function compileDeclareComponentFromMetadata(
|
||||
/**
|
||||
* Gathers the declaration fields for a component into a `DefinitionMap`.
|
||||
*/
|
||||
export function createComponentDefinitionMap(
|
||||
function createComponentDefinitionMap(
|
||||
meta: R3ComponentMetadata<R3TemplateDependencyMetadata>,
|
||||
template: ParsedTemplate,
|
||||
templateInfo: DeclareComponentTemplateInfo,
|
||||
|
||||
@@ -40,7 +40,7 @@ export function compileDeclareInjectableFromMetadata(
|
||||
/**
|
||||
* Gathers the declaration fields for a Injectable into a `DefinitionMap`.
|
||||
*/
|
||||
export function createInjectableDefinitionMap(
|
||||
function createInjectableDefinitionMap(
|
||||
meta: R3InjectableMetadata,
|
||||
): DefinitionMap<R3DeclareInjectableMetadata> {
|
||||
const definitionMap = new DefinitionMap<R3DeclareInjectableMetadata>();
|
||||
|
||||
@@ -37,9 +37,7 @@ export function compileDeclarePipeFromMetadata(meta: R3PipeMetadata): R3Compiled
|
||||
/**
|
||||
* Gathers the declaration fields for a Pipe into a `DefinitionMap`.
|
||||
*/
|
||||
export function createPipeDefinitionMap(
|
||||
meta: R3PipeMetadata,
|
||||
): DefinitionMap<R3DeclarePipeMetadata> {
|
||||
function createPipeDefinitionMap(meta: R3PipeMetadata): DefinitionMap<R3DeclarePipeMetadata> {
|
||||
const definitionMap = new DefinitionMap<R3DeclarePipeMetadata>();
|
||||
|
||||
definitionMap.set('minVersion', o.literal(MINIMUM_PARTIAL_LINKER_VERSION));
|
||||
|
||||
@@ -37,7 +37,7 @@ export function compileDeclareServiceFromMetadata(meta: R3ServiceMetadata): R3Co
|
||||
/**
|
||||
* Gathers the declaration fields for a Service into a `DefinitionMap`.
|
||||
*/
|
||||
export function createServiceDefinitionMap(
|
||||
function createServiceDefinitionMap(
|
||||
meta: R3ServiceMetadata,
|
||||
): DefinitionMap<R3DeclareServiceMetadata> {
|
||||
const definitionMap = new DefinitionMap<R3DeclareServiceMetadata>();
|
||||
|
||||
@@ -45,24 +45,11 @@ export interface R3CompiledExpression {
|
||||
statements: o.Statement[];
|
||||
}
|
||||
|
||||
const LEGACY_ANIMATE_SYMBOL_PREFIX = '@';
|
||||
export function prepareSyntheticPropertyName(name: string) {
|
||||
return `${LEGACY_ANIMATE_SYMBOL_PREFIX}${name}`;
|
||||
}
|
||||
|
||||
export function prepareSyntheticListenerName(name: string, phase: string) {
|
||||
return `${LEGACY_ANIMATE_SYMBOL_PREFIX}${name}.${phase}`;
|
||||
}
|
||||
|
||||
export function getSafePropertyAccessString(accessor: string, name: string): string {
|
||||
const escapedName = escapeIdentifier(name, false);
|
||||
return escapedName !== name ? `${accessor}[${escapedName}]` : `${accessor}.${name}`;
|
||||
}
|
||||
|
||||
export function prepareSyntheticListenerFunctionName(name: string, phase: string) {
|
||||
return `animation_${name}_${phase}`;
|
||||
}
|
||||
|
||||
export function jitOnlyGuardedExpression(expr: o.Expression): o.Expression {
|
||||
return guardedExpression('ngJitMode', expr);
|
||||
}
|
||||
@@ -71,7 +58,7 @@ export function devOnlyGuardedExpression(expr: o.Expression): o.Expression {
|
||||
return guardedExpression('ngDevMode', expr);
|
||||
}
|
||||
|
||||
export function guardedExpression(guard: string, expr: o.Expression): o.Expression {
|
||||
function guardedExpression(guard: string, expr: o.Expression): o.Expression {
|
||||
const guardExpr = new o.ExternalExpr({name: guard, moduleName: null});
|
||||
const guardNotDefined = new o.BinaryOperatorExpr(
|
||||
o.BinaryOperator.Identical,
|
||||
|
||||
@@ -64,10 +64,7 @@ function toQueryFlags(query: R3QueryMetadata): number {
|
||||
);
|
||||
}
|
||||
|
||||
export function getQueryPredicate(
|
||||
query: R3QueryMetadata,
|
||||
constantPool: ConstantPool,
|
||||
): o.Expression {
|
||||
function getQueryPredicate(query: R3QueryMetadata, constantPool: ConstantPool): o.Expression {
|
||||
if (Array.isArray(query.predicate)) {
|
||||
let predicate: o.Expression[] = [];
|
||||
query.predicate.forEach((selector: string): void => {
|
||||
|
||||
@@ -44,12 +44,6 @@ export function temporaryAllocator(
|
||||
};
|
||||
}
|
||||
|
||||
export function invalid<T>(this: t.Visitor, arg: o.Expression | o.Statement | t.Node): never {
|
||||
throw new Error(
|
||||
`Invalid state: Visitor ${this.constructor.name} doesn't handle ${arg.constructor.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function asLiteral(value: any): o.Expression {
|
||||
if (Array.isArray(value)) {
|
||||
return o.literalArr(value.map(asLiteral));
|
||||
|
||||
@@ -73,7 +73,7 @@ export function isIrExpression(expr: o.Expression): expr is Expression {
|
||||
/**
|
||||
* Base type used for all logical IR expressions.
|
||||
*/
|
||||
export abstract class ExpressionBase extends o.Expression {
|
||||
abstract class ExpressionBase extends o.Expression {
|
||||
abstract readonly kind: ExpressionKind;
|
||||
|
||||
constructor(sourceSpan: ParseSourceSpan | null = null) {
|
||||
|
||||
@@ -54,7 +54,7 @@ export function namespaceForKey(namespacePrefixKey: string | null): ir.Namespace
|
||||
return NAMESPACES.get(namespacePrefixKey) ?? ir.Namespace.HTML;
|
||||
}
|
||||
|
||||
export function keyForNamespace(namespace: ir.Namespace): string | null {
|
||||
function keyForNamespace(namespace: ir.Namespace): string | null {
|
||||
const NAMESPACES = new Map([
|
||||
['svg', ir.Namespace.SVG],
|
||||
['math', ir.Namespace.Math],
|
||||
|
||||
@@ -48,7 +48,7 @@ export function isI18nRootNode(meta?: i18n.I18nMeta): meta is i18n.Message {
|
||||
return meta instanceof i18n.Message;
|
||||
}
|
||||
|
||||
export function isSingleI18nIcu(meta?: i18n.I18nMeta): meta is i18n.I18nMeta & {nodes: [i18n.Icu]} {
|
||||
function isSingleI18nIcu(meta?: i18n.I18nMeta): meta is i18n.I18nMeta & {nodes: [i18n.Icu]} {
|
||||
return isI18nRootNode(meta) && meta.nodes.length === 1 && meta.nodes[0] instanceof i18n.Icu;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ function calcHostBindingSecurityContexts(
|
||||
|
||||
// TODO: We should refactor the parser to use the same types and structures for host bindings as
|
||||
// with ordinary components. This would allow us to share a lot more ingestion code.
|
||||
export function ingestDomProperty(
|
||||
function ingestDomProperty(
|
||||
job: HostBindingCompilationJob,
|
||||
property: e.ParsedProperty,
|
||||
bindingKind: ir.BindingKind,
|
||||
@@ -220,7 +220,7 @@ export function ingestDomProperty(
|
||||
);
|
||||
}
|
||||
|
||||
export function ingestHostAttribute(
|
||||
function ingestHostAttribute(
|
||||
job: HostBindingCompilationJob,
|
||||
name: string,
|
||||
value: o.Expression,
|
||||
@@ -244,7 +244,7 @@ export function ingestHostAttribute(
|
||||
job.root.update.push(attrBinding);
|
||||
}
|
||||
|
||||
export function ingestHostEvent(job: HostBindingCompilationJob, event: e.ParsedEvent) {
|
||||
function ingestHostEvent(job: HostBindingCompilationJob, event: e.ParsedEvent) {
|
||||
let eventBinding: ir.CreateOp;
|
||||
if (event.type === e.ParsedEventType.Animation) {
|
||||
eventBinding = ir.createAnimationListenerOp(
|
||||
|
||||
@@ -29,7 +29,7 @@ const NG_I18N_CLOSURE_MODE = 'ngI18nClosureMode';
|
||||
const TRANSLATION_VAR_PREFIX = 'i18n_';
|
||||
|
||||
/** Prefix of ICU expressions for post processing */
|
||||
export const I18N_ICU_MAPPING_PREFIX = 'I18N_EXP_';
|
||||
const I18N_ICU_MAPPING_PREFIX = 'I18N_EXP_';
|
||||
|
||||
/**
|
||||
* The escape sequence used for message param values.
|
||||
@@ -45,7 +45,7 @@ const CLOSURE_TRANSLATION_VAR_PREFIX = 'MSG_';
|
||||
* @param extra Additional local prefix that should be injected into translation var name
|
||||
* @returns Complete translation const prefix
|
||||
*/
|
||||
export function getTranslationConstPrefix(extra: string): string {
|
||||
function getTranslationConstPrefix(extra: string): string {
|
||||
return `${CLOSURE_TRANSLATION_VAR_PREFIX}${extra}`.toUpperCase();
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export function getTranslationConstPrefix(extra: string): string {
|
||||
* Generate AST to declare a variable. E.g. `var I18N_1;`.
|
||||
* @param variable the name of the variable to declare.
|
||||
*/
|
||||
export function declareI18nVariable(variable: o.ReadVarExpr): o.Statement {
|
||||
function declareI18nVariable(variable: o.ReadVarExpr): o.Statement {
|
||||
return new o.DeclareVarStmt(
|
||||
variable.name!,
|
||||
undefined,
|
||||
|
||||
@@ -20,7 +20,7 @@ import {ExpressionIdentifier} from '../comments';
|
||||
* A `TcbOp` which constructs an instance of a directive. For generic directives, generic
|
||||
* parameters are set to `any` type.
|
||||
*/
|
||||
export abstract class TcbDirectiveTypeOpBase extends TcbOp {
|
||||
abstract class TcbDirectiveTypeOpBase extends TcbOp {
|
||||
constructor(
|
||||
protected tcb: Context,
|
||||
protected scope: Scope,
|
||||
|
||||
@@ -34,7 +34,7 @@ const enum EventParamType {
|
||||
* `ts.Expression`, with special handling of the `$event` variable that can be used within event
|
||||
* bindings.
|
||||
*/
|
||||
export function tcbEventHandlerExpression(ast: AST, tcb: Context, scope: Scope): TcbExpr {
|
||||
function tcbEventHandlerExpression(ast: AST, tcb: Context, scope: Scope): TcbExpr {
|
||||
const translator = new TcbEventHandlerTranslator(tcb, scope);
|
||||
return translator.translate(ast);
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ export function expandBoundAttributesForField(
|
||||
return boundInputs;
|
||||
}
|
||||
|
||||
export function isFieldDirective(meta: TcbDirectiveMetadata): boolean {
|
||||
function isFieldDirective(meta: TcbDirectiveMetadata): boolean {
|
||||
if (meta.name !== 'FormField') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -34,10 +34,6 @@ export function noUndefined<T>(val: T | undefined): T {
|
||||
return val === undefined ? null! : val;
|
||||
}
|
||||
|
||||
export function error(msg: string): never {
|
||||
throw new Error(`Internal Error: ${msg}`);
|
||||
}
|
||||
|
||||
// Escape characters that have a special meaning in Regular Expressions
|
||||
export function escapeRegExp(s: string): string {
|
||||
return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
|
||||
|
||||
Reference in New Issue
Block a user