From d17602f31d5e879a0124dae28df3573327912708 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 26 Sep 2018 17:28:30 +0100 Subject: [PATCH] refactor(ivy): rename and move ngcc `Parsed...` to `Decorated...` (#26082) PR Close #26082 --- .../compiler-cli/src/ngcc/src/analyzer.ts | 12 +++---- .../decorated_class.ts} | 6 ++-- .../parsed_file.ts => host/decorated_file.ts} | 12 +++---- .../src/ngcc/src/parsing/esm2015_parser.ts | 12 +++---- .../src/ngcc/src/parsing/esm5_parser.ts | 12 +++---- .../src/ngcc/src/parsing/file_parser.ts | 4 +-- .../src/ngcc/test/analyzer_spec.ts | 32 ++++++++++--------- 7 files changed, 45 insertions(+), 45 deletions(-) rename packages/compiler-cli/src/ngcc/src/{parsing/parsed_class.ts => host/decorated_class.ts} (85%) rename packages/compiler-cli/src/ngcc/src/{parsing/parsed_file.ts => host/decorated_file.ts} (50%) diff --git a/packages/compiler-cli/src/ngcc/src/analyzer.ts b/packages/compiler-cli/src/ngcc/src/analyzer.ts index 5993c5b019..b28b8e325d 100644 --- a/packages/compiler-cli/src/ngcc/src/analyzer.ts +++ b/packages/compiler-cli/src/ngcc/src/analyzer.ts @@ -13,11 +13,11 @@ import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHa import {CompileResult, DecoratorHandler} from '../../ngtsc/transform'; import {NgccReflectionHost} from './host/ngcc_host'; -import {ParsedClass} from './parsing/parsed_class'; -import {ParsedFile} from './parsing/parsed_file'; +import {DecoratedClass} from './host/decorated_class'; +import {DecoratedFile} from './host/decorated_file'; import {isDefined} from './utils'; -export interface AnalyzedClass extends ParsedClass { +export interface AnalyzedClass extends DecoratedClass { handler: DecoratorHandler; analysis: any; diagnostics?: ts.Diagnostic[]; @@ -61,11 +61,11 @@ export class Analyzer { private rootDirs: string[], private isCore: boolean) {} /** - * Analyize a parsed file to generate the information about decorated classes that + * Analyze a decorated file to generate the information about decorated classes that * should be converted to use ivy definitions. * @param file The file to be analysed for decorated classes. */ - analyzeFile(file: ParsedFile): AnalyzedFile { + analyzeFile(file: DecoratedFile): AnalyzedFile { const constantPool = new ConstantPool(); const analyzedClasses = file.decoratedClasses.map(clazz => this.analyzeClass(constantPool, clazz)) @@ -77,7 +77,7 @@ export class Analyzer { }; } - protected analyzeClass(pool: ConstantPool, clazz: ParsedClass): AnalyzedClass|undefined { + protected analyzeClass(pool: ConstantPool, clazz: DecoratedClass): AnalyzedClass|undefined { const matchingHandlers = this.handlers .map(handler => ({ handler, diff --git a/packages/compiler-cli/src/ngcc/src/parsing/parsed_class.ts b/packages/compiler-cli/src/ngcc/src/host/decorated_class.ts similarity index 85% rename from packages/compiler-cli/src/ngcc/src/parsing/parsed_class.ts rename to packages/compiler-cli/src/ngcc/src/host/decorated_class.ts index c6cad7457d..46cd4c8a19 100644 --- a/packages/compiler-cli/src/ngcc/src/parsing/parsed_class.ts +++ b/packages/compiler-cli/src/ngcc/src/host/decorated_class.ts @@ -11,11 +11,11 @@ import {Decorator} from '../../../ngtsc/host'; /** * A simple container that holds the details of a decorated class that has been - * parsed out of a package. + * found in a `DecoratedFile`. */ -export class ParsedClass { +export class DecoratedClass { /** - * Initialize a `DecoratedClass` that was found by parsing a package. + * Initialize a `DecoratedClass` that was found in a `DecoratedFile`. * @param name The name of the class that has been found. This is mostly used * for informational purposes. * @param declaration The TypeScript AST node where this class is declared diff --git a/packages/compiler-cli/src/ngcc/src/parsing/parsed_file.ts b/packages/compiler-cli/src/ngcc/src/host/decorated_file.ts similarity index 50% rename from packages/compiler-cli/src/ngcc/src/parsing/parsed_file.ts rename to packages/compiler-cli/src/ngcc/src/host/decorated_file.ts index 117c460082..0d42307ab0 100644 --- a/packages/compiler-cli/src/ngcc/src/parsing/parsed_file.ts +++ b/packages/compiler-cli/src/ngcc/src/host/decorated_file.ts @@ -7,17 +7,15 @@ */ import * as ts from 'typescript'; -import {ParsedClass} from './parsed_class'; +import {DecoratedClass} from './decorated_class'; /** - * Information about a source file that has been parsed to - * extract all the decorated exported classes. + * Information about a source file that contains decorated exported classes. */ -export class ParsedFile { +export class DecoratedFile { /** - * The decorated exported classes that have been parsed out - * from the file. + * The decorated exported classes that have been found in the file. */ - public decoratedClasses: ParsedClass[] = []; + public decoratedClasses: DecoratedClass[] = []; constructor(public sourceFile: ts.SourceFile) {} } diff --git a/packages/compiler-cli/src/ngcc/src/parsing/esm2015_parser.ts b/packages/compiler-cli/src/ngcc/src/parsing/esm2015_parser.ts index 32fbcd344f..499f8103a1 100644 --- a/packages/compiler-cli/src/ngcc/src/parsing/esm2015_parser.ts +++ b/packages/compiler-cli/src/ngcc/src/parsing/esm2015_parser.ts @@ -9,20 +9,20 @@ import * as ts from 'typescript'; import {NgccReflectionHost} from '../host/ngcc_host'; +import {DecoratedClass} from '../host/decorated_class'; +import {DecoratedFile} from '../host/decorated_file'; import {getOriginalSymbol, isDefined} from '../utils'; import {FileParser} from './file_parser'; -import {ParsedClass} from './parsed_class'; -import {ParsedFile} from './parsed_file'; export class Esm2015FileParser implements FileParser { checker = this.program.getTypeChecker(); constructor(protected program: ts.Program, protected host: NgccReflectionHost) {} - parseFile(file: ts.SourceFile): ParsedFile[] { + parseFile(file: ts.SourceFile): DecoratedFile[] { const moduleSymbol = this.checker.getSymbolAtLocation(file); - const map = new Map(); + const map = new Map(); if (moduleSymbol) { const exportedSymbols = this.checker.getExportsOfModule(moduleSymbol).map(getOriginalSymbol(this.checker)); @@ -38,7 +38,7 @@ export class Esm2015FileParser implements FileParser { undefined; const decorators = this.host.getDecoratorsOfDeclaration(declaration); return decorators && isDefined(name) ? - new ParsedClass(name, declaration, decorators) : + new DecoratedClass(name, declaration, decorators) : undefined; } return undefined; @@ -48,7 +48,7 @@ export class Esm2015FileParser implements FileParser { decoratedClasses.forEach(clazz => { const file = clazz.declaration.getSourceFile(); if (!map.has(file)) { - map.set(file, new ParsedFile(file)); + map.set(file, new DecoratedFile(file)); } map.get(file) !.decoratedClasses.push(clazz); }); diff --git a/packages/compiler-cli/src/ngcc/src/parsing/esm5_parser.ts b/packages/compiler-cli/src/ngcc/src/parsing/esm5_parser.ts index e4c91de628..599c93b14a 100644 --- a/packages/compiler-cli/src/ngcc/src/parsing/esm5_parser.ts +++ b/packages/compiler-cli/src/ngcc/src/parsing/esm5_parser.ts @@ -9,11 +9,11 @@ import * as ts from 'typescript'; import {NgccReflectionHost} from '../host/ngcc_host'; +import {DecoratedClass} from '../host/decorated_class'; +import {DecoratedFile} from '../host/decorated_file'; import {getNameText, getOriginalSymbol, isDefined} from '../utils'; import {FileParser} from './file_parser'; -import {ParsedClass} from './parsed_class'; -import {ParsedFile} from './parsed_file'; @@ -27,13 +27,13 @@ export class Esm5FileParser implements FileParser { constructor(protected program: ts.Program, protected host: NgccReflectionHost) {} - parseFile(file: ts.SourceFile): ParsedFile[] { + parseFile(file: ts.SourceFile): DecoratedFile[] { const moduleSymbol = this.checker.getSymbolAtLocation(file); - const map = new Map(); + const map = new Map(); const getParsedClass = (declaration: ts.VariableDeclaration) => { const decorators = this.host.getDecoratorsOfDeclaration(declaration); if (decorators) { - return new ParsedClass(getNameText(declaration.name), declaration, decorators); + return new DecoratedClass(getNameText(declaration.name), declaration, decorators); } }; @@ -49,7 +49,7 @@ export class Esm5FileParser implements FileParser { decoratedClasses.forEach(clazz => { const file = clazz.declaration.getSourceFile(); if (!map.has(file)) { - map.set(file, new ParsedFile(file)); + map.set(file, new DecoratedFile(file)); } map.get(file) !.decoratedClasses.push(clazz); }); diff --git a/packages/compiler-cli/src/ngcc/src/parsing/file_parser.ts b/packages/compiler-cli/src/ngcc/src/parsing/file_parser.ts index 4b73263629..cf2f5147c6 100644 --- a/packages/compiler-cli/src/ngcc/src/parsing/file_parser.ts +++ b/packages/compiler-cli/src/ngcc/src/parsing/file_parser.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ import * as ts from 'typescript'; -import {ParsedFile} from './parsed_file'; +import {DecoratedFile} from '../host/decorated_file'; /** * Classes that implement this interface can parse a file in a package to @@ -31,5 +31,5 @@ export interface FileParser { * @param file The the entry point file for identifying classes to process. * @returns A `ParsedFiles` collection that holds the decorated classes and import information. */ - parseFile(file: ts.SourceFile): ParsedFile[]; + parseFile(file: ts.SourceFile): DecoratedFile[]; } diff --git a/packages/compiler-cli/src/ngcc/test/analyzer_spec.ts b/packages/compiler-cli/src/ngcc/test/analyzer_spec.ts index 994e402104..35d054763d 100644 --- a/packages/compiler-cli/src/ngcc/test/analyzer_spec.ts +++ b/packages/compiler-cli/src/ngcc/test/analyzer_spec.ts @@ -10,8 +10,8 @@ import {Decorator} from '../../ngtsc/host'; import {DecoratorHandler} from '../../ngtsc/transform'; import {AnalyzedFile, Analyzer} from '../src/analyzer'; import {Fesm2015ReflectionHost} from '../src/host/fesm2015_host'; -import {ParsedClass} from '../src/parsing/parsed_class'; -import {ParsedFile} from '../src/parsing/parsed_file'; +import {DecoratedClass} from '../src/host/decorated_class'; +import {DecoratedFile} from '../src/host/decorated_file'; import {getDeclaration, makeProgram} from './helpers/utils'; const TEST_PROGRAM = { @@ -49,23 +49,25 @@ function createTestHandler() { } function createParsedFile(program: ts.Program) { - const file = new ParsedFile(program.getSourceFile('test.js') !); + const file = new DecoratedFile(program.getSourceFile('test.js') !); const componentClass = getDeclaration(program, 'test.js', 'MyComponent', ts.isClassDeclaration); - file.decoratedClasses.push(new ParsedClass('MyComponent', {} as any, [{ - name: 'Component', - import: {from: '@angular/core', name: 'Component'}, - node: null as any, - args: null - }])); + file.decoratedClasses.push( + new DecoratedClass('MyComponent', {} as any, [{ + name: 'Component', + import: {from: '@angular/core', name: 'Component'}, + node: null as any, + args: null + }])); const serviceClass = getDeclaration(program, 'test.js', 'MyService', ts.isClassDeclaration); - file.decoratedClasses.push(new ParsedClass('MyService', {} as any, [{ - name: 'Injectable', - import: {from: '@angular/core', name: 'Injectable'}, - node: null as any, - args: null - }])); + file.decoratedClasses.push( + new DecoratedClass('MyService', {} as any, [{ + name: 'Injectable', + import: {from: '@angular/core', name: 'Injectable'}, + node: null as any, + args: null + }])); return file; }