refactor(ivy): rename and move ngcc `Parsed...` to `Decorated...` (#26082)

PR Close #26082
This commit is contained in:
Pete Bacon Darwin 2018-09-26 17:28:30 +01:00 committed by Miško Hevery
parent 7d0e17530b
commit d17602f31d
7 changed files with 45 additions and 45 deletions

View File

@ -13,11 +13,11 @@ import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHa
import {CompileResult, DecoratorHandler} from '../../ngtsc/transform'; import {CompileResult, DecoratorHandler} from '../../ngtsc/transform';
import {NgccReflectionHost} from './host/ngcc_host'; import {NgccReflectionHost} from './host/ngcc_host';
import {ParsedClass} from './parsing/parsed_class'; import {DecoratedClass} from './host/decorated_class';
import {ParsedFile} from './parsing/parsed_file'; import {DecoratedFile} from './host/decorated_file';
import {isDefined} from './utils'; import {isDefined} from './utils';
export interface AnalyzedClass<A = any, M = any> extends ParsedClass { export interface AnalyzedClass<A = any, M = any> extends DecoratedClass {
handler: DecoratorHandler<A, M>; handler: DecoratorHandler<A, M>;
analysis: any; analysis: any;
diagnostics?: ts.Diagnostic[]; diagnostics?: ts.Diagnostic[];
@ -61,11 +61,11 @@ export class Analyzer {
private rootDirs: string[], private isCore: boolean) {} 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. * should be converted to use ivy definitions.
* @param file The file to be analysed for decorated classes. * @param file The file to be analysed for decorated classes.
*/ */
analyzeFile(file: ParsedFile): AnalyzedFile { analyzeFile(file: DecoratedFile): AnalyzedFile {
const constantPool = new ConstantPool(); const constantPool = new ConstantPool();
const analyzedClasses = const analyzedClasses =
file.decoratedClasses.map(clazz => this.analyzeClass(constantPool, clazz)) 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 const matchingHandlers = this.handlers
.map(handler => ({ .map(handler => ({
handler, handler,

View File

@ -11,11 +11,11 @@ import {Decorator} from '../../../ngtsc/host';
/** /**
* A simple container that holds the details of a decorated class that has been * 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 * @param name The name of the class that has been found. This is mostly used
* for informational purposes. * for informational purposes.
* @param declaration The TypeScript AST node where this class is declared * @param declaration The TypeScript AST node where this class is declared

View File

@ -7,17 +7,15 @@
*/ */
import * as ts from 'typescript'; 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 * Information about a source file that contains decorated exported classes.
* extract all the decorated exported classes.
*/ */
export class ParsedFile { export class DecoratedFile {
/** /**
* The decorated exported classes that have been parsed out * The decorated exported classes that have been found in the file.
* from the file.
*/ */
public decoratedClasses: ParsedClass[] = []; public decoratedClasses: DecoratedClass[] = [];
constructor(public sourceFile: ts.SourceFile) {} constructor(public sourceFile: ts.SourceFile) {}
} }

View File

@ -9,20 +9,20 @@
import * as ts from 'typescript'; import * as ts from 'typescript';
import {NgccReflectionHost} from '../host/ngcc_host'; import {NgccReflectionHost} from '../host/ngcc_host';
import {DecoratedClass} from '../host/decorated_class';
import {DecoratedFile} from '../host/decorated_file';
import {getOriginalSymbol, isDefined} from '../utils'; import {getOriginalSymbol, isDefined} from '../utils';
import {FileParser} from './file_parser'; import {FileParser} from './file_parser';
import {ParsedClass} from './parsed_class';
import {ParsedFile} from './parsed_file';
export class Esm2015FileParser implements FileParser { export class Esm2015FileParser implements FileParser {
checker = this.program.getTypeChecker(); checker = this.program.getTypeChecker();
constructor(protected program: ts.Program, protected host: NgccReflectionHost) {} 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 moduleSymbol = this.checker.getSymbolAtLocation(file);
const map = new Map<ts.SourceFile, ParsedFile>(); const map = new Map<ts.SourceFile, DecoratedFile>();
if (moduleSymbol) { if (moduleSymbol) {
const exportedSymbols = const exportedSymbols =
this.checker.getExportsOfModule(moduleSymbol).map(getOriginalSymbol(this.checker)); this.checker.getExportsOfModule(moduleSymbol).map(getOriginalSymbol(this.checker));
@ -38,7 +38,7 @@ export class Esm2015FileParser implements FileParser {
undefined; undefined;
const decorators = this.host.getDecoratorsOfDeclaration(declaration); const decorators = this.host.getDecoratorsOfDeclaration(declaration);
return decorators && isDefined(name) ? return decorators && isDefined(name) ?
new ParsedClass(name, declaration, decorators) : new DecoratedClass(name, declaration, decorators) :
undefined; undefined;
} }
return undefined; return undefined;
@ -48,7 +48,7 @@ export class Esm2015FileParser implements FileParser {
decoratedClasses.forEach(clazz => { decoratedClasses.forEach(clazz => {
const file = clazz.declaration.getSourceFile(); const file = clazz.declaration.getSourceFile();
if (!map.has(file)) { if (!map.has(file)) {
map.set(file, new ParsedFile(file)); map.set(file, new DecoratedFile(file));
} }
map.get(file) !.decoratedClasses.push(clazz); map.get(file) !.decoratedClasses.push(clazz);
}); });

View File

@ -9,11 +9,11 @@
import * as ts from 'typescript'; import * as ts from 'typescript';
import {NgccReflectionHost} from '../host/ngcc_host'; 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 {getNameText, getOriginalSymbol, isDefined} from '../utils';
import {FileParser} from './file_parser'; 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) {} 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 moduleSymbol = this.checker.getSymbolAtLocation(file);
const map = new Map<ts.SourceFile, ParsedFile>(); const map = new Map<ts.SourceFile, DecoratedFile>();
const getParsedClass = (declaration: ts.VariableDeclaration) => { const getParsedClass = (declaration: ts.VariableDeclaration) => {
const decorators = this.host.getDecoratorsOfDeclaration(declaration); const decorators = this.host.getDecoratorsOfDeclaration(declaration);
if (decorators) { 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 => { decoratedClasses.forEach(clazz => {
const file = clazz.declaration.getSourceFile(); const file = clazz.declaration.getSourceFile();
if (!map.has(file)) { if (!map.has(file)) {
map.set(file, new ParsedFile(file)); map.set(file, new DecoratedFile(file));
} }
map.get(file) !.decoratedClasses.push(clazz); map.get(file) !.decoratedClasses.push(clazz);
}); });

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import * as ts from 'typescript'; 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 * 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. * @param file The the entry point file for identifying classes to process.
* @returns A `ParsedFiles` collection that holds the decorated classes and import information. * @returns A `ParsedFiles` collection that holds the decorated classes and import information.
*/ */
parseFile(file: ts.SourceFile): ParsedFile[]; parseFile(file: ts.SourceFile): DecoratedFile[];
} }

View File

@ -10,8 +10,8 @@ import {Decorator} from '../../ngtsc/host';
import {DecoratorHandler} from '../../ngtsc/transform'; import {DecoratorHandler} from '../../ngtsc/transform';
import {AnalyzedFile, Analyzer} from '../src/analyzer'; import {AnalyzedFile, Analyzer} from '../src/analyzer';
import {Fesm2015ReflectionHost} from '../src/host/fesm2015_host'; import {Fesm2015ReflectionHost} from '../src/host/fesm2015_host';
import {ParsedClass} from '../src/parsing/parsed_class'; import {DecoratedClass} from '../src/host/decorated_class';
import {ParsedFile} from '../src/parsing/parsed_file'; import {DecoratedFile} from '../src/host/decorated_file';
import {getDeclaration, makeProgram} from './helpers/utils'; import {getDeclaration, makeProgram} from './helpers/utils';
const TEST_PROGRAM = { const TEST_PROGRAM = {
@ -49,10 +49,11 @@ function createTestHandler() {
} }
function createParsedFile(program: ts.Program) { 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); const componentClass = getDeclaration(program, 'test.js', 'MyComponent', ts.isClassDeclaration);
file.decoratedClasses.push(new ParsedClass('MyComponent', {} as any, [{ file.decoratedClasses.push(
new DecoratedClass('MyComponent', {} as any, [{
name: 'Component', name: 'Component',
import: {from: '@angular/core', name: 'Component'}, import: {from: '@angular/core', name: 'Component'},
node: null as any, node: null as any,
@ -60,7 +61,8 @@ function createParsedFile(program: ts.Program) {
}])); }]));
const serviceClass = getDeclaration(program, 'test.js', 'MyService', ts.isClassDeclaration); const serviceClass = getDeclaration(program, 'test.js', 'MyService', ts.isClassDeclaration);
file.decoratedClasses.push(new ParsedClass('MyService', {} as any, [{ file.decoratedClasses.push(
new DecoratedClass('MyService', {} as any, [{
name: 'Injectable', name: 'Injectable',
import: {from: '@angular/core', name: 'Injectable'}, import: {from: '@angular/core', name: 'Injectable'},
node: null as any, node: null as any,