refactor(compiler-cli): ngcc - remove unnecessary `sourcePath` parameters (#29643)

The `Transformer` and `Renderer` classes do not
actually need a `sourcePath` value as by the time
they are doing their work we are only working directly
with full absolute paths.

PR Close #29643
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:47:56 +01:00 committed by Andrew Kushnir
parent 1195dabb84
commit 78b5bd5174
8 changed files with 12 additions and 18 deletions

View File

@ -73,7 +73,7 @@ export function mainNgcc({basePath, targetEntryPointPath,
propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES,
compileAllFormats = true, createNewEntryPointFormats = false,
logger = new ConsoleLogger(LogLevel.info)}: NgccOptions): void {
const transformer = new Transformer(logger, basePath);
const transformer = new Transformer(logger);
const host = new DependencyHost();
const resolver = new DependencyResolver(logger, host);
const finder = new EntryPointFinder(logger, resolver);

View File

@ -46,7 +46,7 @@ import {EntryPointBundle} from './entry_point_bundle';
* - Some formats may contain multiple "modules" in a single file.
*/
export class Transformer {
constructor(private logger: Logger, private sourcePath: string) {}
constructor(private logger: Logger) {}
/**
* Transform the source (and typings) files of a bundle.
@ -85,9 +85,9 @@ export class Transformer {
getRenderer(host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle): Renderer {
switch (bundle.format) {
case 'esm2015':
return new EsmRenderer(this.logger, host, isCore, bundle, this.sourcePath);
return new EsmRenderer(this.logger, host, isCore, bundle);
case 'esm5':
return new Esm5Renderer(this.logger, host, isCore, bundle, this.sourcePath);
return new Esm5Renderer(this.logger, host, isCore, bundle);
default:
throw new Error(`Renderer for "${bundle.format}" not yet implemented.`);
}

View File

@ -15,10 +15,8 @@ import {EntryPointBundle} from '../packages/entry_point_bundle';
import {Logger} from '../logging/logger';
export class Esm5Renderer extends EsmRenderer {
constructor(
logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle,
sourcePath: string) {
super(logger, host, isCore, bundle, sourcePath);
constructor(logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
super(logger, host, isCore, bundle);
}
/**

View File

@ -17,10 +17,8 @@ import {isDtsPath} from '../../../src/ngtsc/util/src/typescript';
import {Logger} from '../logging/logger';
export class EsmRenderer extends Renderer {
constructor(
logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle,
sourcePath: string) {
super(logger, host, isCore, bundle, sourcePath);
constructor(logger: Logger, host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
super(logger, host, isCore, bundle);
}
/**

View File

@ -82,7 +82,7 @@ export const RedundantDecoratorMap = Map;
export abstract class Renderer {
constructor(
protected logger: Logger, protected host: NgccReflectionHost, protected isCore: boolean,
protected bundle: EntryPointBundle, protected sourcePath: string) {}
protected bundle: EntryPointBundle) {}
renderProgram(
decorationAnalyses: DecorationAnalyses, switchMarkerAnalyses: SwitchMarkerAnalyses,

View File

@ -19,7 +19,6 @@ import {MockLogger} from '../helpers/mock_logger';
function setup(file: {name: string, contents: string}) {
const logger = new MockLogger();
const dir = dirname(file.name);
const bundle = makeTestEntryPointBundle('es2015', 'esm2015', false, [file]) !;
const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm2015ReflectionHost(logger, false, typeChecker);
@ -30,7 +29,7 @@ function setup(file: {name: string, contents: string}) {
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
.analyzeProgram();
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program);
const renderer = new EsmRenderer(logger, host, false, bundle, dir);
const renderer = new EsmRenderer(logger, host, false, bundle);
return {
host,
program: bundle.src.program,

View File

@ -19,7 +19,6 @@ import {MockLogger} from '../helpers/mock_logger';
function setup(file: {name: string, contents: string}) {
const logger = new MockLogger();
const dir = dirname(file.name);
const bundle = makeTestEntryPointBundle('module', 'esm5', false, [file]);
const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm5ReflectionHost(logger, false, typeChecker);
@ -30,7 +29,7 @@ function setup(file: {name: string, contents: string}) {
referencesRegistry, [AbsoluteFsPath.fromUnchecked('/')], false)
.analyzeProgram();
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program);
const renderer = new Esm5Renderer(logger, host, false, bundle, dir);
const renderer = new Esm5Renderer(logger, host, false, bundle);
return {
host,
program: bundle.src.program,

View File

@ -24,7 +24,7 @@ import {MockLogger} from '../helpers/mock_logger';
class TestRenderer extends Renderer {
constructor(
logger: Logger, host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
super(logger, host, isCore, bundle, '/src');
super(logger, host, isCore, bundle);
}
addImports(
output: MagicString, imports: {specifier: string, qualifier: string}[], sf: ts.SourceFile) {