style(ngcc): reformat of ngcc after clang update (#36447)
PR Close #36447
This commit is contained in:

committed by
Kara Erickson

parent
bfa55162de
commit
74b7a8eaf5
@ -9,7 +9,7 @@ import * as ts from 'typescript';
|
||||
|
||||
import {FatalDiagnosticError, makeDiagnostic} from '../../../src/ngtsc/diagnostics';
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassDeclaration, Decorator} from '../../../src/ngtsc/reflection';
|
||||
import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../src/ngtsc/transform';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
@ -21,7 +21,7 @@ import {Migration, MigrationHost} from '../../src/migrations/migration';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
type DecoratorHandlerWithResolve = DecoratorHandler<unknown, unknown, unknown>& {
|
||||
type DecoratorHandlerWithResolve = DecoratorHandler<unknown, unknown, unknown>&{
|
||||
resolve: NonNullable<DecoratorHandler<unknown, unknown, unknown>['resolve']>;
|
||||
};
|
||||
|
||||
@ -29,7 +29,9 @@ runInEachFileSystem(() => {
|
||||
describe('DecorationAnalyzer', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
beforeEach(() => { _ = absoluteFrom; });
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
});
|
||||
|
||||
describe('analyzeProgram()', () => {
|
||||
let logs: string[];
|
||||
@ -50,8 +52,8 @@ runInEachFileSystem(() => {
|
||||
]);
|
||||
// Only detect the Component and Directive decorators
|
||||
handler.detect.and.callFake(
|
||||
(node: ts.Declaration, decorators: Decorator[] | null): DetectResult<unknown>|
|
||||
undefined => {
|
||||
(node: ts.Declaration, decorators: Decorator[]|null): DetectResult<unknown>|
|
||||
undefined => {
|
||||
const className = (node as any).name.text;
|
||||
if (decorators === null) {
|
||||
logs.push(`detect: ${className} (no decorators)`);
|
||||
@ -94,17 +96,17 @@ runInEachFileSystem(() => {
|
||||
// The "test" compilation result is just the name of the decorator being compiled
|
||||
// (suffixed with `(compiled)`)
|
||||
handler.compile.and.callFake((decl: ts.Declaration, analysis: any) => {
|
||||
logs.push(
|
||||
`compile: ${(decl as any).name.text}@${analysis.decoratorName} (resolved: ${analysis.resolved})`);
|
||||
logs.push(`compile: ${(decl as any).name.text}@${analysis.decoratorName} (resolved: ${
|
||||
analysis.resolved})`);
|
||||
return `@${analysis.decoratorName} (compiled)`;
|
||||
});
|
||||
return handler;
|
||||
};
|
||||
|
||||
function setUpAnalyzer(
|
||||
testFiles: TestFile[],
|
||||
options: {analyzeError: boolean,
|
||||
resolveError: boolean} = {analyzeError: false, resolveError: false}) {
|
||||
function setUpAnalyzer(testFiles: TestFile[], options: {
|
||||
analyzeError: boolean,
|
||||
resolveError: boolean
|
||||
} = {analyzeError: false, resolveError: false}) {
|
||||
logs = [];
|
||||
loadTestFiles(testFiles);
|
||||
loadFakeCore(getFileSystem());
|
||||
@ -173,9 +175,9 @@ runInEachFileSystem(() => {
|
||||
|
||||
it('should return an object containing a reference to the original source file', () => {
|
||||
const testFile = getSourceFileOrError(program, _('/node_modules/test-package/test.js'));
|
||||
expect(result.get(testFile) !.sourceFile).toBe(testFile);
|
||||
expect(result.get(testFile)!.sourceFile).toBe(testFile);
|
||||
const otherFile = getSourceFileOrError(program, _('/node_modules/test-package/other.js'));
|
||||
expect(result.get(otherFile) !.sourceFile).toBe(otherFile);
|
||||
expect(result.get(otherFile)!.sourceFile).toBe(otherFile);
|
||||
});
|
||||
|
||||
it('should call detect on the decorator handlers with each class from the parsed file',
|
||||
@ -192,20 +194,23 @@ runInEachFileSystem(() => {
|
||||
|
||||
it('should return an object containing the classes that were analyzed', () => {
|
||||
const file1 = getSourceFileOrError(program, _('/node_modules/test-package/test.js'));
|
||||
const compiledFile1 = result.get(file1) !;
|
||||
const compiledFile1 = result.get(file1)!;
|
||||
expect(compiledFile1.compiledClasses.length).toEqual(2);
|
||||
expect(compiledFile1.compiledClasses[0]).toEqual(jasmine.objectContaining({
|
||||
name: 'MyComponent', compilation: ['@Component (compiled)'],
|
||||
name: 'MyComponent',
|
||||
compilation: ['@Component (compiled)'],
|
||||
} as unknown as CompiledClass));
|
||||
expect(compiledFile1.compiledClasses[1]).toEqual(jasmine.objectContaining({
|
||||
name: 'MyDirective', compilation: ['@Directive (compiled)'],
|
||||
name: 'MyDirective',
|
||||
compilation: ['@Directive (compiled)'],
|
||||
} as unknown as CompiledClass));
|
||||
|
||||
const file2 = getSourceFileOrError(program, _('/node_modules/test-package/other.js'));
|
||||
const compiledFile2 = result.get(file2) !;
|
||||
const compiledFile2 = result.get(file2)!;
|
||||
expect(compiledFile2.compiledClasses.length).toEqual(1);
|
||||
expect(compiledFile2.compiledClasses[0]).toEqual(jasmine.objectContaining({
|
||||
name: 'MyOtherComponent', compilation: ['@Component (compiled)'],
|
||||
name: 'MyOtherComponent',
|
||||
compilation: ['@Component (compiled)'],
|
||||
} as unknown as CompiledClass));
|
||||
});
|
||||
|
||||
@ -284,18 +289,18 @@ runInEachFileSystem(() => {
|
||||
() => {
|
||||
const file =
|
||||
getSourceFileOrError(program, _('/node_modules/test-package/component.js'));
|
||||
const analysis = result.get(file) !;
|
||||
const analysis = result.get(file)!;
|
||||
expect(analysis).toBeDefined();
|
||||
const ImportedComponent =
|
||||
analysis.compiledClasses.find(f => f.name === 'ImportedComponent') !;
|
||||
analysis.compiledClasses.find(f => f.name === 'ImportedComponent')!;
|
||||
expect(ImportedComponent).toBeDefined();
|
||||
});
|
||||
|
||||
it('should analyze an internally defined component, which is not exported at all', () => {
|
||||
const file = getSourceFileOrError(program, _('/node_modules/test-package/entrypoint.js'));
|
||||
const analysis = result.get(file) !;
|
||||
const analysis = result.get(file)!;
|
||||
expect(analysis).toBeDefined();
|
||||
const LocalComponent = analysis.compiledClasses.find(f => f.name === 'LocalComponent') !;
|
||||
const LocalComponent = analysis.compiledClasses.find(f => f.name === 'LocalComponent')!;
|
||||
expect(LocalComponent).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -341,7 +346,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
it('should ignore classes from an externally imported file', () => {
|
||||
const file = program.getSourceFile(_('/node_modules/other/component.js')) !;
|
||||
const file = program.getSourceFile(_('/node_modules/other/component.js'))!;
|
||||
expect(result.has(file)).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -427,11 +432,15 @@ runInEachFileSystem(() => {
|
||||
name = 'FakeDecoratorHandler';
|
||||
precedence = HandlerPrecedence.PRIMARY;
|
||||
|
||||
detect(): undefined { throw new Error('detect should not have been called'); }
|
||||
detect(): undefined {
|
||||
throw new Error('detect should not have been called');
|
||||
}
|
||||
analyze(): AnalysisOutput<unknown> {
|
||||
throw new Error('analyze should not have been called');
|
||||
}
|
||||
compile(): CompileResult { throw new Error('compile should not have been called'); }
|
||||
compile(): CompileResult {
|
||||
throw new Error('compile should not have been called');
|
||||
}
|
||||
}
|
||||
|
||||
const analyzer = setUpAnalyzer([{
|
||||
|
@ -62,7 +62,7 @@ runInEachFileSystem(() => {
|
||||
const {host, compiler} = createMigrationHost({entryPoint, handlers: [handler]});
|
||||
host.injectSyntheticDecorator(mockClazz, injectedDecorator);
|
||||
|
||||
const record = compiler.recordFor(mockClazz) !;
|
||||
const record = compiler.recordFor(mockClazz)!;
|
||||
expect(record).toBeDefined();
|
||||
expect(record.traits.length).toBe(1);
|
||||
expect(record.traits[0].detected.decorator).toBe(injectedDecorator);
|
||||
@ -77,7 +77,7 @@ runInEachFileSystem(() => {
|
||||
const decorator = createComponentDecorator(mockClazz, {selector: 'comp', exportAs: null});
|
||||
host.injectSyntheticDecorator(mockClazz, decorator);
|
||||
|
||||
const record = compiler.recordFor(mockClazz) !;
|
||||
const record = compiler.recordFor(mockClazz)!;
|
||||
const migratedTrait = record.traits[0];
|
||||
if (migratedTrait.state !== TraitState.ERRORED) {
|
||||
return fail('Expected migrated class trait to be in an error state');
|
||||
@ -120,7 +120,7 @@ runInEachFileSystem(() => {
|
||||
|
||||
host.injectSyntheticDecorator(myClass, injectedDecorator);
|
||||
|
||||
const decorators = host.getAllDecorators(myClass) !;
|
||||
const decorators = host.getAllDecorators(myClass)!;
|
||||
expect(decorators.length).toBe(2);
|
||||
expect(decorators[0].name).toBe('Directive');
|
||||
expect(decorators[1].name).toBe('InjectedDecorator');
|
||||
@ -183,9 +183,13 @@ class DetectDecoratorHandler implements DecoratorHandler<unknown, unknown, unkno
|
||||
return {trigger: node, decorator, metadata: {}};
|
||||
}
|
||||
|
||||
analyze(node: ClassDeclaration): AnalysisOutput<unknown> { return {}; }
|
||||
analyze(node: ClassDeclaration): AnalysisOutput<unknown> {
|
||||
return {};
|
||||
}
|
||||
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] { return []; }
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
class DiagnosticProducingHandler implements DecoratorHandler<unknown, unknown, unknown> {
|
||||
@ -201,5 +205,7 @@ class DiagnosticProducingHandler implements DecoratorHandler<unknown, unknown, u
|
||||
return {diagnostics: [makeDiagnostic(9999, node, 'test diagnostic')]};
|
||||
}
|
||||
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] { return []; }
|
||||
compile(node: ClassDeclaration): CompileResult|CompileResult[] {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFrom, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {ModuleWithProvidersAnalyses, ModuleWithProvidersAnalyzer} from '../../src/analysis/module_with_providers_analyzer';
|
||||
@ -333,7 +333,7 @@ runInEachFileSystem(() => {
|
||||
'test-package', 'esm2015', false, getRootFiles(TEST_PROGRAM),
|
||||
getRootFiles(TEST_DTS_PROGRAM));
|
||||
program = bundle.src.program;
|
||||
dtsProgram = bundle.dts !;
|
||||
dtsProgram = bundle.dts!;
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src, dtsProgram);
|
||||
referencesRegistry = new NgccReferencesRegistry(host);
|
||||
|
||||
@ -367,8 +367,8 @@ runInEachFileSystem(() => {
|
||||
const libraryModuleDeclaration = getDeclaration(
|
||||
program, absoluteFrom('/node_modules/some-library/index.d.ts'), 'LibraryModule',
|
||||
ts.isClassDeclaration);
|
||||
expect(declarations.has(externalModuleDeclaration.name !)).toBe(true);
|
||||
expect(declarations.has(libraryModuleDeclaration.name !)).toBe(false);
|
||||
expect(declarations.has(externalModuleDeclaration.name!)).toBe(true);
|
||||
expect(declarations.has(libraryModuleDeclaration.name!)).toBe(false);
|
||||
});
|
||||
|
||||
it('should find declarations that have implicit return types', () => {
|
||||
@ -414,13 +414,12 @@ runInEachFileSystem(() => {
|
||||
analyses: ModuleWithProvidersAnalyses, fileName: AbsoluteFsPath) {
|
||||
const file = getSourceFileOrError(dtsProgram.program, fileName);
|
||||
const analysis = analyses.get(file);
|
||||
return analysis ?
|
||||
analysis.map(
|
||||
info =>
|
||||
[info.declaration.name !.getText(),
|
||||
(info.ngModule.node as ts.ClassDeclaration).name !.getText(),
|
||||
info.ngModule.viaModule]) :
|
||||
[];
|
||||
return analysis ? analysis.map(
|
||||
info =>
|
||||
[info.declaration.name!.getText(),
|
||||
(info.ngModule.node as ts.ClassDeclaration).name!.getText(),
|
||||
info.ngModule.viaModule]) :
|
||||
[];
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -536,7 +535,7 @@ runInEachFileSystem(() => {
|
||||
'test-package', 'esm2015', false, getRootFiles(TEST_PROGRAM),
|
||||
getRootFiles(TEST_DTS_PROGRAM));
|
||||
const program = bundle.src.program;
|
||||
const dtsProgram = bundle.dts !;
|
||||
const dtsProgram = bundle.dts!;
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle.src, dtsProgram);
|
||||
const referencesRegistry = new NgccReferencesRegistry(host);
|
||||
|
||||
@ -558,9 +557,9 @@ runInEachFileSystem(() => {
|
||||
const libraryModuleDeclaration = getDeclaration(
|
||||
program, absoluteFrom('/node_modules/some-library/index.d.ts'), 'LibraryModule',
|
||||
ts.isClassDeclaration);
|
||||
expect(declarations.has(explicitInternalModuleDeclaration.name !)).toBe(true);
|
||||
expect(declarations.has(externalModuleDeclaration.name !)).toBe(true);
|
||||
expect(declarations.has(libraryModuleDeclaration.name !)).toBe(false);
|
||||
expect(declarations.has(explicitInternalModuleDeclaration.name!)).toBe(true);
|
||||
expect(declarations.has(externalModuleDeclaration.name!)).toBe(true);
|
||||
expect(declarations.has(libraryModuleDeclaration.name!)).toBe(false);
|
||||
});
|
||||
|
||||
it('should track references even when typings have already been processed', () => {
|
||||
@ -586,9 +585,9 @@ runInEachFileSystem(() => {
|
||||
const libraryModuleDeclaration = getDeclaration(
|
||||
program, absoluteFrom('/node_modules/some-library/index.d.ts'), 'LibraryModule',
|
||||
ts.isClassDeclaration);
|
||||
expect(declarations.has(explicitInternalModuleDeclaration.name !)).toBe(true);
|
||||
expect(declarations.has(externalModuleDeclaration.name !)).toBe(true);
|
||||
expect(declarations.has(libraryModuleDeclaration.name !)).toBe(false);
|
||||
expect(declarations.has(explicitInternalModuleDeclaration.name!)).toBe(true);
|
||||
expect(declarations.has(externalModuleDeclaration.name!)).toBe(true);
|
||||
expect(declarations.has(libraryModuleDeclaration.name!)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -91,7 +91,7 @@ runInEachFileSystem(() => {
|
||||
|
||||
const record = compiler.recordFor(mockClazz);
|
||||
expect(record).toBeDefined();
|
||||
expect(record !.traits.length).toBe(1);
|
||||
expect(record!.traits.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should add a new trait to an existing class record', () => {
|
||||
@ -118,11 +118,11 @@ runInEachFileSystem(() => {
|
||||
compiler.analyzeFile(entryPoint.src.file);
|
||||
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
|
||||
|
||||
const record = compiler.recordFor(myClass) !;
|
||||
const record = compiler.recordFor(myClass)!;
|
||||
expect(record).toBeDefined();
|
||||
expect(record.traits.length).toBe(2);
|
||||
expect(record.traits[0].detected.decorator !.name).toBe('Directive');
|
||||
expect(record.traits[1].detected.decorator !.name).toBe('InjectedDecorator');
|
||||
expect(record.traits[0].detected.decorator!.name).toBe('Directive');
|
||||
expect(record.traits[1].detected.decorator!.name).toBe('InjectedDecorator');
|
||||
});
|
||||
|
||||
it('should not add a weak handler when a primary handler already exists', () => {
|
||||
@ -150,10 +150,10 @@ runInEachFileSystem(() => {
|
||||
|
||||
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
|
||||
|
||||
const record = compiler.recordFor(myClass) !;
|
||||
const record = compiler.recordFor(myClass)!;
|
||||
expect(record).toBeDefined();
|
||||
expect(record.traits.length).toBe(1);
|
||||
expect(record.traits[0].detected.decorator !.name).toBe('Directive');
|
||||
expect(record.traits[0].detected.decorator!.name).toBe('Directive');
|
||||
});
|
||||
|
||||
it('should replace an existing weak handler when injecting a primary handler', () => {
|
||||
@ -181,10 +181,10 @@ runInEachFileSystem(() => {
|
||||
|
||||
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
|
||||
|
||||
const record = compiler.recordFor(myClass) !;
|
||||
const record = compiler.recordFor(myClass)!;
|
||||
expect(record).toBeDefined();
|
||||
expect(record.traits.length).toBe(1);
|
||||
expect(record.traits[0].detected.decorator !.name).toBe('InjectedDecorator');
|
||||
expect(record.traits[0].detected.decorator!.name).toBe('InjectedDecorator');
|
||||
});
|
||||
|
||||
it('should produce an error when a primary handler is added when a primary handler is already present',
|
||||
@ -214,12 +214,11 @@ runInEachFileSystem(() => {
|
||||
|
||||
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
|
||||
|
||||
const record = compiler.recordFor(myClass) !;
|
||||
const record = compiler.recordFor(myClass)!;
|
||||
expect(record).toBeDefined();
|
||||
expect(record.metaDiagnostics).toBeDefined();
|
||||
expect(record.metaDiagnostics !.length).toBe(1);
|
||||
expect(record.metaDiagnostics ![0].code)
|
||||
.toBe(ngErrorCode(ErrorCode.DECORATOR_COLLISION));
|
||||
expect(record.metaDiagnostics!.length).toBe(1);
|
||||
expect(record.metaDiagnostics![0].code).toBe(ngErrorCode(ErrorCode.DECORATOR_COLLISION));
|
||||
expect(record.traits.length).toBe(0);
|
||||
});
|
||||
|
||||
@ -233,7 +232,7 @@ runInEachFileSystem(() => {
|
||||
const decorator = createComponentDecorator(mockClazz, {selector: 'comp', exportAs: null});
|
||||
compiler.injectSyntheticDecorator(mockClazz, decorator);
|
||||
|
||||
const record = compiler.recordFor(mockClazz) !;
|
||||
const record = compiler.recordFor(mockClazz)!;
|
||||
const migratedTrait = record.traits[0];
|
||||
if (migratedTrait.state !== TraitState.ERRORED) {
|
||||
return fail('Expected migrated class trait to be in an error state');
|
||||
@ -286,13 +285,12 @@ runInEachFileSystem(() => {
|
||||
|
||||
compiler.injectSyntheticDecorator(myClass, injectedDecorator);
|
||||
|
||||
const decorators = compiler.getAllDecorators(myClass) !;
|
||||
const decorators = compiler.getAllDecorators(myClass)!;
|
||||
expect(decorators.length).toBe(2);
|
||||
expect(decorators[0].name).toBe('Directive');
|
||||
expect(decorators[1].name).toBe('InjectedDecorator');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@ -302,7 +300,7 @@ class TestHandler implements DecoratorHandler<unknown, unknown, unknown> {
|
||||
precedence = HandlerPrecedence.PRIMARY;
|
||||
|
||||
detect(node: ClassDeclaration, decorators: Decorator[]|null): DetectResult<unknown>|undefined {
|
||||
this.log.push(`${this.name}:detect:${node.name.text}:${decorators !.map(d => d.name)}`);
|
||||
this.log.push(`${this.name}:detect:${node.name.text}:${decorators!.map(d => d.name)}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {Reference} from '../../../src/ngtsc/imports';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers/src/mock_file_loading';
|
||||
@ -192,6 +192,6 @@ runInEachFileSystem(() => {
|
||||
program: ts.Program, registry: NgccReferencesRegistry, fileName: AbsoluteFsPath,
|
||||
componentName: string) {
|
||||
const declaration = getDeclaration(program, fileName, componentName, ts.isClassDeclaration);
|
||||
registry.add(null !, new Reference(declaration));
|
||||
registry.add(null!, new Reference(declaration));
|
||||
}
|
||||
});
|
||||
|
@ -8,7 +8,7 @@
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {Reference} from '../../../src/ngtsc/imports';
|
||||
import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator';
|
||||
import {TypeScriptReflectionHost} from '../../../src/ngtsc/reflection';
|
||||
@ -44,19 +44,19 @@ runInEachFileSystem(() => {
|
||||
getDeclaration(program, indexPath, 'someFunction', ts.isFunctionDeclaration);
|
||||
const someVariableDecl =
|
||||
getDeclaration(program, indexPath, 'someVariable', ts.isVariableDeclaration);
|
||||
const testArrayExpression = testArrayDeclaration.initializer !;
|
||||
const testArrayExpression = testArrayDeclaration.initializer!;
|
||||
|
||||
const reflectionHost = new TypeScriptReflectionHost(checker);
|
||||
const evaluator = new PartialEvaluator(reflectionHost, checker, /* dependencyTracker */ null);
|
||||
const registry = new NgccReferencesRegistry(reflectionHost);
|
||||
|
||||
const references = (evaluator.evaluate(testArrayExpression) as any[]).filter(isReference);
|
||||
registry.add(null !, ...references);
|
||||
registry.add(null!, ...references);
|
||||
|
||||
const map = registry.getDeclarationMap();
|
||||
expect(map.size).toEqual(2);
|
||||
expect(map.get(someClassDecl.name !) !.node).toBe(someClassDecl);
|
||||
expect(map.get(someFunctionDecl.name !) !.node).toBe(someFunctionDecl);
|
||||
expect(map.get(someClassDecl.name!)!.node).toBe(someClassDecl);
|
||||
expect(map.get(someFunctionDecl.name!)!.node).toBe(someFunctionDecl);
|
||||
expect(map.has(someVariableDecl.name as ts.Identifier)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {absoluteFrom, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
@ -15,7 +15,6 @@ import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('SwitchMarkerAnalyzer', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let TEST_PROGRAM: TestFile[];
|
||||
|
||||
@ -87,14 +86,14 @@ runInEachFileSystem(() => {
|
||||
expect(analysis.has(entrypoint)).toBe(false);
|
||||
expect(analysis.has(a)).toBe(false);
|
||||
expect(analysis.has(b)).toBe(true);
|
||||
expect(analysis.get(b) !.sourceFile).toBe(b);
|
||||
expect(analysis.get(b) !.declarations.map(decl => decl.getText())).toEqual([
|
||||
expect(analysis.get(b)!.sourceFile).toBe(b);
|
||||
expect(analysis.get(b)!.declarations.map(decl => decl.getText())).toEqual([
|
||||
'factoryB = factory__PRE_R3__'
|
||||
]);
|
||||
|
||||
expect(analysis.has(c)).toBe(true);
|
||||
expect(analysis.get(c) !.sourceFile).toBe(c);
|
||||
expect(analysis.get(c) !.declarations.map(decl => decl.getText())).toEqual([
|
||||
expect(analysis.get(c)!.sourceFile).toBe(c);
|
||||
expect(analysis.get(c)!.declarations.map(decl => decl.getText())).toEqual([
|
||||
'factoryC = factory__PRE_R3__',
|
||||
'factoryD = factory__PRE_R3__',
|
||||
]);
|
||||
|
@ -387,7 +387,7 @@ runInEachFileSystem(() => {
|
||||
reExportsWithoutRequire?: string[];
|
||||
}
|
||||
|
||||
function commonJs(importsPerType: ImportsPerType | string[], exportNames: string[] = []): string {
|
||||
function commonJs(importsPerType: ImportsPerType|string[], exportNames: string[] = []): string {
|
||||
if (Array.isArray(importsPerType)) {
|
||||
importsPerType = {varDeclaration: importsPerType};
|
||||
}
|
||||
@ -414,8 +414,9 @@ runInEachFileSystem(() => {
|
||||
} = importsPerType;
|
||||
|
||||
// var foo = require('...');
|
||||
importsOfTypeVarDeclaration.forEach(
|
||||
p => { importStatements.push(`var ${pathToVarName(p)} = require('${p}');`); });
|
||||
importsOfTypeVarDeclaration.forEach(p => {
|
||||
importStatements.push(`var ${pathToVarName(p)} = require('${p}');`);
|
||||
});
|
||||
|
||||
// var foo = require('...'), bar = require('...');
|
||||
importsOfTypeVarDeclarations.forEach(pp => {
|
||||
@ -424,8 +425,9 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
// exports.foo = require('...');
|
||||
importsOfTypePropAssignment.forEach(
|
||||
p => { importStatements.push(`exports.${pathToVarName(p)} = require('${p}');`); });
|
||||
importsOfTypePropAssignment.forEach(p => {
|
||||
importStatements.push(`exports.${pathToVarName(p)} = require('${p}');`);
|
||||
});
|
||||
|
||||
// module.exports = {foo: require('...')};
|
||||
const propAssignments =
|
||||
@ -434,15 +436,19 @@ runInEachFileSystem(() => {
|
||||
importStatements.push(`module.exports = {${propAssignments}\n};`);
|
||||
|
||||
// require('...');
|
||||
importsOfTypeForSideEffects.forEach(p => { importStatements.push(`require('${p}');`); });
|
||||
importsOfTypeForSideEffects.forEach(p => {
|
||||
importStatements.push(`require('${p}');`);
|
||||
});
|
||||
|
||||
// __export(require('...'));
|
||||
importsOfTypeReExportsWithEmittedHelper.forEach(
|
||||
p => { importStatements.push(`__export(require('${p}'));`); });
|
||||
importsOfTypeReExportsWithEmittedHelper.forEach(p => {
|
||||
importStatements.push(`__export(require('${p}'));`);
|
||||
});
|
||||
|
||||
// tslib_1.__exportStar(require('...'), exports);
|
||||
importsOfTypeReExportsWithImportedHelper.forEach(
|
||||
p => { importStatements.push(`tslib_1.__exportStar(require('${p}'), exports);`); });
|
||||
importsOfTypeReExportsWithImportedHelper.forEach(p => {
|
||||
importStatements.push(`tslib_1.__exportStar(require('${p}'), exports);`);
|
||||
});
|
||||
|
||||
// var foo = require('...');
|
||||
// __export(foo);
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {DepGraph} from 'dependency-graph';
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem, relativeFrom} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, relativeFrom} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {DependencyInfo} from '../../src/dependencies/dependency_host';
|
||||
import {DependencyResolver, SortedEntryPointsInfo} from '../../src/dependencies/dependency_resolver';
|
||||
@ -254,7 +254,8 @@ runInEachFileSystem(() => {
|
||||
const result = resolver.sortEntryPointsByDependency([first]);
|
||||
expect(result.entryPoints).toEqual([first]);
|
||||
expect(logger.logs.warn).toEqual([[
|
||||
`Entry point 'first' contains deep imports into '${_('/deep/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
`Entry point 'first' contains deep imports into '${
|
||||
_('/deep/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
]]);
|
||||
});
|
||||
|
||||
@ -292,14 +293,14 @@ runInEachFileSystem(() => {
|
||||
const result = resolver.sortEntryPointsByDependency([testEntryPoint]);
|
||||
expect(result.entryPoints).toEqual([testEntryPoint]);
|
||||
expect(logger.logs.warn).toEqual([[
|
||||
`Entry point 'test-package' contains deep imports into '${_('/project/node_modules/deeper/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
`Entry point 'test-package' contains deep imports into '${
|
||||
_('/project/node_modules/deeper/one')}'. This is probably not a problem, but may cause the compilation of entry points to be out of order.`
|
||||
]]);
|
||||
|
||||
});
|
||||
|
||||
it('should error if the entry point does not have a suitable format', () => {
|
||||
expect(() => resolver.sortEntryPointsByDependency([
|
||||
{ path: '/first', packageJson: {}, compiledByAngular: true } as EntryPoint
|
||||
{path: '/first', packageJson: {}, compiledByAngular: true} as EntryPoint
|
||||
])).toThrowError(`There is no appropriate source code format in '/first' entry-point.`);
|
||||
});
|
||||
|
||||
@ -307,7 +308,8 @@ runInEachFileSystem(() => {
|
||||
resolver = new DependencyResolver(fs, new MockLogger(), config, {esm2015: host}, host);
|
||||
expect(() => resolver.sortEntryPointsByDependency([first]))
|
||||
.toThrowError(
|
||||
`Could not find a suitable format for computing dependencies of entry-point: '${first.path}'.`);
|
||||
`Could not find a suitable format for computing dependencies of entry-point: '${
|
||||
first.path}'.`);
|
||||
});
|
||||
|
||||
it('should capture any dependencies that were ignored', () => {
|
||||
@ -462,7 +464,7 @@ runInEachFileSystem(() => {
|
||||
deps[entryPointPath].missing.forEach(
|
||||
dep => missing.add(fs.isRooted(dep) ? absoluteFrom(dep) : relativeFrom(dep)));
|
||||
if (deps[entryPointPath].deepImports) {
|
||||
deps[entryPointPath].deepImports !.forEach(dep => deepImports.add(dep));
|
||||
deps[entryPointPath].deepImports!.forEach(dep => deepImports.add(dep));
|
||||
}
|
||||
return {dependencies, missing, deepImports};
|
||||
};
|
||||
|
@ -14,7 +14,6 @@ import {createDependencyInfo} from '../../src/dependencies/dependency_host';
|
||||
import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
||||
describe('DtsDependencyHost', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
let host: DtsDependencyHost;
|
||||
|
@ -16,7 +16,6 @@ import {EsmDependencyHost, hasImportOrReexportStatements, isStringImportOrReexpo
|
||||
import {ModuleResolver} from '../../src/dependencies/module_resolver';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
||||
describe('EsmDependencyHost', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
let host: EsmDependencyHost;
|
||||
|
@ -251,8 +251,10 @@ runInEachFileSystem(() => {
|
||||
exportNames.map(e => ` exports.${e.replace(/.+\./, '')} = ${e};`).join('\n');
|
||||
return `
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports${commonJsRequires}) :
|
||||
typeof define === 'function' && define.amd ? define('${moduleName}', ['exports'${amdDeps}], factory) :
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports${
|
||||
commonJsRequires}) :
|
||||
typeof define === 'function' && define.amd ? define('${moduleName}', ['exports'${
|
||||
amdDeps}], factory) :
|
||||
(factory(global.${moduleName}${globalParams}));
|
||||
}(this, (function (exports${params}) { 'use strict';
|
||||
${exportStatements}
|
||||
|
@ -5,8 +5,8 @@
|
||||
* 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, FileSystem, absoluteFrom, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DependencyResolver} from '../../src/dependencies/dependency_resolver';
|
||||
import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||
|
@ -5,8 +5,8 @@
|
||||
* 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, FileSystem, absoluteFrom, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, relative} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DependencyResolver} from '../../src/dependencies/dependency_resolver';
|
||||
import {DtsDependencyHost} from '../../src/dependencies/dts_dependency_host';
|
||||
@ -365,7 +365,6 @@ runInEachFileSystem(() => {
|
||||
basePath: AbsoluteFsPath, entryPoints: EntryPoint[]): [string, string][] {
|
||||
return entryPoints.map(x => [relative(basePath, x.package), relative(basePath, x.path)]);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
describe('targetNeedsProcessingOrCleaning()', () => {
|
||||
|
@ -132,9 +132,12 @@ runInEachFileSystem(() => {
|
||||
fs.resolve(projectDirectory, 'dist-1'),
|
||||
]);
|
||||
expect(logger.logs.warn).toEqual([
|
||||
[`The basePath "${fs.resolve(projectDirectory, 'sub-folder/dist-2')}" computed from baseUrl "${projectDirectory}" and path mapping "sub-folder/dist-2" does not exist in the file-system.\n` +
|
||||
[`The basePath "${
|
||||
fs.resolve(projectDirectory, 'sub-folder/dist-2')}" computed from baseUrl "${
|
||||
projectDirectory}" and path mapping "sub-folder/dist-2" does not exist in the file-system.\n` +
|
||||
`It will not be scanned for entry-points.`],
|
||||
[`The basePath "${fs.resolve(projectDirectory, 'libs')}" computed from baseUrl "${projectDirectory}" and path mapping "libs/*" does not exist in the file-system.\n` +
|
||||
[`The basePath "${fs.resolve(projectDirectory, 'libs')}" computed from baseUrl "${
|
||||
projectDirectory}" and path mapping "libs/*" does not exist in the file-system.\n` +
|
||||
`It will not be scanned for entry-points.`],
|
||||
]);
|
||||
});
|
||||
|
@ -51,7 +51,7 @@ describe('ClusterExecutor', () => {
|
||||
describe('(on cluster master)', () => {
|
||||
beforeEach(() => runAsClusterMaster(true));
|
||||
|
||||
it('should log debug info about the executor', async() => {
|
||||
it('should log debug info about the executor', async () => {
|
||||
const anyFn: () => any = () => undefined;
|
||||
await executor.execute(anyFn, anyFn);
|
||||
|
||||
@ -60,7 +60,7 @@ describe('ClusterExecutor', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should delegate to `ClusterMaster#run()`', async() => {
|
||||
it('should delegate to `ClusterMaster#run()`', async () => {
|
||||
const analyzeEntryPointsSpy = jasmine.createSpy('analyzeEntryPoints');
|
||||
const createCompilerFnSpy = jasmine.createSpy('createCompilerFn');
|
||||
|
||||
@ -75,13 +75,13 @@ describe('ClusterExecutor', () => {
|
||||
});
|
||||
|
||||
it('should call LockFile.write() and LockFile.remove() if master runner completes successfully',
|
||||
async() => {
|
||||
async () => {
|
||||
const anyFn: () => any = () => undefined;
|
||||
await executor.execute(anyFn, anyFn);
|
||||
expect(lockFileLog).toEqual(['write()', 'remove()']);
|
||||
});
|
||||
|
||||
it('should call LockFile.write() and LockFile.remove() if master runner fails', async() => {
|
||||
it('should call LockFile.write() and LockFile.remove() if master runner fails', async () => {
|
||||
const anyFn: () => any = () => undefined;
|
||||
masterRunSpy.and.returnValue(Promise.reject(new Error('master runner error')));
|
||||
let error = '';
|
||||
@ -94,7 +94,7 @@ describe('ClusterExecutor', () => {
|
||||
expect(lockFileLog).toEqual(['write()', 'remove()']);
|
||||
});
|
||||
|
||||
it('should not call master runner if LockFile.write() fails', async() => {
|
||||
it('should not call master runner if LockFile.write() fails', async () => {
|
||||
const anyFn: () => any = () => undefined;
|
||||
spyOn(mockLockFile, 'write').and.callFake(() => {
|
||||
lockFileLog.push('write()');
|
||||
@ -114,7 +114,7 @@ describe('ClusterExecutor', () => {
|
||||
expect(masterRunSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should fail if LockFile.remove() fails', async() => {
|
||||
it('should fail if LockFile.remove() fails', async () => {
|
||||
const anyFn: () => any = () => undefined;
|
||||
spyOn(mockLockFile, 'remove').and.callFake(() => {
|
||||
lockFileLog.push('remove()');
|
||||
@ -139,14 +139,14 @@ describe('ClusterExecutor', () => {
|
||||
describe('(on cluster worker)', () => {
|
||||
beforeEach(() => runAsClusterMaster(false));
|
||||
|
||||
it('should not log debug info about the executor', async() => {
|
||||
it('should not log debug info about the executor', async () => {
|
||||
const anyFn: () => any = () => undefined;
|
||||
await executor.execute(anyFn, anyFn);
|
||||
|
||||
expect(mockLogger.logs.debug).toEqual([]);
|
||||
});
|
||||
|
||||
it('should delegate to `ClusterWorker#run()`', async() => {
|
||||
it('should delegate to `ClusterWorker#run()`', async () => {
|
||||
const analyzeEntryPointsSpy = jasmine.createSpy('analyzeEntryPoints');
|
||||
const createCompilerFnSpy = jasmine.createSpy('createCompilerFn');
|
||||
|
||||
@ -160,7 +160,7 @@ describe('ClusterExecutor', () => {
|
||||
expect(createCompilerFnSpy).toHaveBeenCalledWith(jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('should not call LockFile.write() or LockFile.remove()', async() => {
|
||||
it('should not call LockFile.write() or LockFile.remove()', async () => {
|
||||
const anyFn: () => any = () => undefined;
|
||||
await executor.execute(anyFn, anyFn);
|
||||
expect(lockFileLog).toEqual([]);
|
||||
|
@ -39,8 +39,9 @@ runInEachFileSystem(() => {
|
||||
isMaster => describe(`(on cluster ${isMaster ? 'master' : 'worker'})`, () => {
|
||||
beforeEach(() => runAsClusterMaster(isMaster));
|
||||
|
||||
it('should return a `PackageJsonUpdate` instance',
|
||||
() => { expect(updater.createUpdate()).toEqual(jasmine.any(PackageJsonUpdate)); });
|
||||
it('should return a `PackageJsonUpdate` instance', () => {
|
||||
expect(updater.createUpdate()).toEqual(jasmine.any(PackageJsonUpdate));
|
||||
});
|
||||
|
||||
it('should wire up the `PackageJsonUpdate` with its `writeChanges()` method', () => {
|
||||
const writeChangesSpy = spyOn(updater, 'writeChanges');
|
||||
|
@ -60,11 +60,9 @@ describe('ClusterWorker', () => {
|
||||
|
||||
onTaskCompleted(null as any, TaskProcessingOutcome.Processed, null);
|
||||
expect(processSendSpy).toHaveBeenCalledTimes(1);
|
||||
expect(processSendSpy).toHaveBeenCalledWith({
|
||||
type: 'task-completed',
|
||||
outcome: TaskProcessingOutcome.Processed,
|
||||
message: null
|
||||
});
|
||||
expect(processSendSpy)
|
||||
.toHaveBeenCalledWith(
|
||||
{type: 'task-completed', outcome: TaskProcessingOutcome.Processed, message: null});
|
||||
|
||||
processSendSpy.calls.reset();
|
||||
|
||||
@ -137,7 +135,9 @@ describe('ClusterWorker', () => {
|
||||
} as unknown as Task;
|
||||
|
||||
let err: string|Error;
|
||||
compileFnSpy.and.callFake(() => { throw err; });
|
||||
compileFnSpy.and.callFake(() => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
worker.run();
|
||||
|
||||
|
@ -14,8 +14,8 @@ import {EntryPoint} from '../../src/packages/entry_point';
|
||||
*
|
||||
* NOTE 1: The first task for each entry-point generates typings (which is similar to what happens
|
||||
* in the actual code).
|
||||
* NOTE 2: The `computeTaskDependencies()` implementation relies on the fact that tasks are sorted in such
|
||||
* a way that a task can only depend upon earlier tasks (i.e. dependencies always come
|
||||
* NOTE 2: The `computeTaskDependencies()` implementation relies on the fact that tasks are sorted
|
||||
* in such a way that a task can only depend upon earlier tasks (i.e. dependencies always come
|
||||
* before dependents in the list of tasks).
|
||||
* To preserve this attribute, you need to ensure that entry-points will only depend on
|
||||
* entry-points with a lower index. Take this into account when defining `entryPointDeps`.
|
||||
@ -52,7 +52,7 @@ export function createTasksAndGraph(
|
||||
graph.addNode(entryPoint.path);
|
||||
|
||||
for (let tIdx = 0; tIdx < tasksPerEntryPointCount; tIdx++) {
|
||||
tasks.push({ entryPoint, formatProperty: `prop-${tIdx}`, processDts: tIdx === 0 } as Task);
|
||||
tasks.push({entryPoint, formatProperty: `prop-${tIdx}`, processDts: tIdx === 0} as Task);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,13 @@ describe('SingleProcessExecutor', () => {
|
||||
executor = new SingleProcessExecutorSync(mockLogger, locker, createTaskCompletedCallback);
|
||||
});
|
||||
|
||||
const noTasks = () => ({ allTasksCompleted: true, getNextTask: () => null } as TaskQueue);
|
||||
const noTasks = () => ({allTasksCompleted: true, getNextTask: () => null} as TaskQueue);
|
||||
const oneTask = () => {
|
||||
let tasksCount = 1;
|
||||
return <TaskQueue>{
|
||||
get allTasksCompleted() { return tasksCount === 0; },
|
||||
get allTasksCompleted() {
|
||||
return tasksCount === 0;
|
||||
},
|
||||
getNextTask() {
|
||||
tasksCount--;
|
||||
return {};
|
||||
@ -55,7 +57,9 @@ describe('SingleProcessExecutor', () => {
|
||||
});
|
||||
|
||||
it('should call LockFile.write() and LockFile.remove() if `analyzeEntryPoints` fails', () => {
|
||||
const errorFn: () => never = () => { throw new Error('analyze error'); };
|
||||
const errorFn: () => never = () => {
|
||||
throw new Error('analyze error');
|
||||
};
|
||||
const createCompileFn: () => any = () => undefined;
|
||||
let error: string = '';
|
||||
try {
|
||||
@ -68,7 +72,9 @@ describe('SingleProcessExecutor', () => {
|
||||
});
|
||||
|
||||
it('should call LockFile.write() and LockFile.remove() if `createCompileFn` fails', () => {
|
||||
const createErrorCompileFn: () => any = () => { throw new Error('compile error'); };
|
||||
const createErrorCompileFn: () => any = () => {
|
||||
throw new Error('compile error');
|
||||
};
|
||||
let error: string = '';
|
||||
try {
|
||||
executor.execute(oneTask, createErrorCompileFn);
|
||||
@ -85,7 +91,9 @@ describe('SingleProcessExecutor', () => {
|
||||
throw new Error('LockFile.write() error');
|
||||
});
|
||||
|
||||
const analyzeFn: () => any = () => { lockFileLog.push('analyzeFn'); };
|
||||
const analyzeFn: () => any = () => {
|
||||
lockFileLog.push('analyzeFn');
|
||||
};
|
||||
const anyFn: () => any = () => undefined;
|
||||
executor = new SingleProcessExecutorSync(mockLogger, locker, createTaskCompletedCallback);
|
||||
let error = '';
|
||||
|
@ -77,9 +77,9 @@ describe('ParallelTaskQueue', () => {
|
||||
it('should be `true`, when there are no unprocess or in-progress tasks', () => {
|
||||
const {queue} = createQueue(3);
|
||||
|
||||
const task1 = queue.getNextTask() !;
|
||||
const task2 = queue.getNextTask() !;
|
||||
const task3 = queue.getNextTask() !;
|
||||
const task1 = queue.getNextTask()!;
|
||||
const task2 = queue.getNextTask()!;
|
||||
const task3 = queue.getNextTask()!;
|
||||
expect(queue.allTasksCompleted).toBe(false);
|
||||
|
||||
queue.markTaskCompleted(task1);
|
||||
@ -266,8 +266,8 @@ describe('ParallelTaskQueue', () => {
|
||||
it('should mark a task as completed', () => {
|
||||
const {queue} = createQueue(2);
|
||||
|
||||
const task1 = queue.getNextTask() !;
|
||||
const task2 = queue.getNextTask() !;
|
||||
const task1 = queue.getNextTask()!;
|
||||
const task2 = queue.getNextTask()!;
|
||||
expect(queue.allTasksCompleted).toBe(false);
|
||||
|
||||
queue.markTaskCompleted(task1);
|
||||
@ -327,7 +327,7 @@ describe('ParallelTaskQueue', () => {
|
||||
|
||||
processNextTask(queue2);
|
||||
processNextTask(queue2);
|
||||
const task = queue2.getNextTask() !;
|
||||
const task = queue2.getNextTask()!;
|
||||
|
||||
expect(queue2.toString()).toContain(' All tasks completed: false\n');
|
||||
|
||||
@ -344,7 +344,7 @@ describe('ParallelTaskQueue', () => {
|
||||
' - {entryPoint: entry-point-1, formatProperty: prop-0, processDts: true}\n' +
|
||||
' - {entryPoint: entry-point-2, formatProperty: prop-0, processDts: true}\n');
|
||||
|
||||
const task1 = queue.getNextTask() !;
|
||||
const task1 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' Unprocessed tasks (2): \n' +
|
||||
@ -352,7 +352,7 @@ describe('ParallelTaskQueue', () => {
|
||||
' - {entryPoint: entry-point-2, formatProperty: prop-0, processDts: true}\n');
|
||||
|
||||
queue.markTaskCompleted(task1);
|
||||
const task2 = queue.getNextTask() !;
|
||||
const task2 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' Unprocessed tasks (1): \n' +
|
||||
@ -367,14 +367,14 @@ describe('ParallelTaskQueue', () => {
|
||||
const {queue} = createQueue(3);
|
||||
expect(queue.toString()).toContain(' In-progress tasks (0): \n');
|
||||
|
||||
const task1 = queue.getNextTask() !;
|
||||
const task1 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' In-progress tasks (1): \n' +
|
||||
' - {entryPoint: entry-point-0, formatProperty: prop-0, processDts: true}\n');
|
||||
|
||||
queue.markTaskCompleted(task1);
|
||||
const task2 = queue.getNextTask() !;
|
||||
const task2 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' In-progress tasks (1): \n' +
|
||||
|
@ -30,12 +30,10 @@ describe('SerialTaskQueue', () => {
|
||||
const tasks: PartiallyOrderedTasks = [] as any;
|
||||
const graph = new DepGraph<EntryPoint>();
|
||||
for (let i = 0; i < taskCount; i++) {
|
||||
const entryPoint = {
|
||||
name: `entry-point-${i}`,
|
||||
path: `/path/to/entry/point/${i}`
|
||||
} as EntryPoint;
|
||||
const entryPoint = {name: `entry-point-${i}`, path: `/path/to/entry/point/${i}`} as
|
||||
EntryPoint;
|
||||
tasks.push(
|
||||
{ entryPoint: entryPoint, formatProperty: `prop-${i}`, processDts: i % 2 === 0 } as Task);
|
||||
{entryPoint: entryPoint, formatProperty: `prop-${i}`, processDts: i % 2 === 0} as Task);
|
||||
graph.addNode(entryPoint.path);
|
||||
}
|
||||
const dependencies = computeTaskDependencies(tasks, graph);
|
||||
@ -140,7 +138,7 @@ describe('SerialTaskQueue', () => {
|
||||
describe('markTaskCompleted()', () => {
|
||||
it('should mark a task as completed, so that the next task can be picked', () => {
|
||||
const {queue} = createQueue(3);
|
||||
const task = queue.getNextTask() !;
|
||||
const task = queue.getNextTask()!;
|
||||
|
||||
expect(() => queue.getNextTask()).toThrow();
|
||||
|
||||
@ -174,7 +172,7 @@ describe('SerialTaskQueue', () => {
|
||||
|
||||
processNextTask(queue2);
|
||||
processNextTask(queue2);
|
||||
const task = queue2.getNextTask() !;
|
||||
const task = queue2.getNextTask()!;
|
||||
|
||||
expect(queue2.toString()).toContain(' All tasks completed: false\n');
|
||||
|
||||
@ -191,7 +189,7 @@ describe('SerialTaskQueue', () => {
|
||||
' - {entryPoint: entry-point-1, formatProperty: prop-1, processDts: false}\n' +
|
||||
' - {entryPoint: entry-point-2, formatProperty: prop-2, processDts: true}\n');
|
||||
|
||||
const task1 = queue.getNextTask() !;
|
||||
const task1 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' Unprocessed tasks (2): \n' +
|
||||
@ -199,7 +197,7 @@ describe('SerialTaskQueue', () => {
|
||||
' - {entryPoint: entry-point-2, formatProperty: prop-2, processDts: true}\n');
|
||||
|
||||
queue.markTaskCompleted(task1);
|
||||
const task2 = queue.getNextTask() !;
|
||||
const task2 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' Unprocessed tasks (1): \n' +
|
||||
@ -214,14 +212,14 @@ describe('SerialTaskQueue', () => {
|
||||
const {queue} = createQueue(3);
|
||||
expect(queue.toString()).toContain(' In-progress tasks (0): ');
|
||||
|
||||
const task1 = queue.getNextTask() !;
|
||||
const task1 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' In-progress tasks (1): \n' +
|
||||
' - {entryPoint: entry-point-0, formatProperty: prop-0, processDts: true}');
|
||||
|
||||
queue.markTaskCompleted(task1);
|
||||
const task2 = queue.getNextTask() !;
|
||||
const task2 = queue.getNextTask()!;
|
||||
expect(queue.toString())
|
||||
.toContain(
|
||||
' In-progress tasks (1): \n' +
|
||||
@ -253,7 +251,7 @@ describe('SerialTaskQueue', () => {
|
||||
' In-progress tasks (0): ');
|
||||
|
||||
processNextTask(queue2);
|
||||
const task = queue2.getNextTask() !;
|
||||
const task = queue2.getNextTask()!;
|
||||
expect(queue2.toString())
|
||||
.toBe(
|
||||
'SerialTaskQueue\n' +
|
||||
|
@ -15,10 +15,14 @@ export class MockLockFile implements LockFile {
|
||||
constructor(
|
||||
fs: FileSystem, private log: string[] = [], public path = fs.resolve('/lockfile'),
|
||||
private pid = '1234') {}
|
||||
write() { this.log.push('write()'); }
|
||||
write() {
|
||||
this.log.push('write()');
|
||||
}
|
||||
read(): string {
|
||||
this.log.push('read()');
|
||||
return this.pid;
|
||||
}
|
||||
remove() { this.log.push('remove()'); }
|
||||
remove() {
|
||||
this.log.push('remove()');
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {LogLevel, Logger} from '../../src/logging/logger';
|
||||
import {Logger, LogLevel} from '../../src/logging/logger';
|
||||
|
||||
export class MockLogger implements Logger {
|
||||
constructor(public level = LogLevel.info) {}
|
||||
@ -17,8 +17,16 @@ export class MockLogger implements Logger {
|
||||
warn: [],
|
||||
error: [],
|
||||
};
|
||||
debug(...args: string[]) { this.logs.debug.push(args); }
|
||||
info(...args: string[]) { this.logs.info.push(args); }
|
||||
warn(...args: string[]) { this.logs.warn.push(args); }
|
||||
error(...args: string[]) { this.logs.error.push(args); }
|
||||
debug(...args: string[]) {
|
||||
this.logs.debug.push(args);
|
||||
}
|
||||
info(...args: string[]) {
|
||||
this.logs.info.push(args);
|
||||
}
|
||||
warn(...args: string[]) {
|
||||
this.logs.warn.push(args);
|
||||
}
|
||||
error(...args: string[]) {
|
||||
this.logs.error.push(args);
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, NgtscCompilerHost, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, getFileSystem, NgtscCompilerHost} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {BundleProgram, makeBundleProgram} from '../../src/packages/bundle_program';
|
||||
import {NgccEntryPointConfig} from '../../src/packages/configuration';
|
||||
@ -49,7 +49,12 @@ export function makeTestEntryPointBundle(
|
||||
return {
|
||||
entryPoint,
|
||||
format,
|
||||
rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore, enableI18nLegacyMessageIdFormat
|
||||
rootDirs: [absoluteFrom('/')],
|
||||
src,
|
||||
dts,
|
||||
isCore,
|
||||
isFlatCore,
|
||||
enableI18nLegacyMessageIdFormat
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
@ -90,15 +90,15 @@ exports.AliasedDirective$1 = AliasedDirective$1;
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('core.Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('core.Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -111,15 +111,15 @@ exports.AliasedDirective$1 = AliasedDirective$1;
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, TOPLEVEL_DECORATORS_FILE.name, 'AliasedDirective$1',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('core.Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('core.Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
|
@ -9,7 +9,7 @@
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, Import, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles, loadTsLib} from '../../../test/helpers';
|
||||
@ -168,16 +168,16 @@ runInEachFileSystem(() => {
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -189,16 +189,16 @@ runInEachFileSystem(() => {
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -210,16 +210,16 @@ runInEachFileSystem(() => {
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: './directives'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -234,15 +234,15 @@ runInEachFileSystem(() => {
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const input1 = members.find(member => member.name === 'input1') !;
|
||||
const input1 = members.find(member => member.name === 'input1')!;
|
||||
expect(input1.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input1.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
|
||||
const input2 = members.find(member => member.name === 'input2') !;
|
||||
const input2 = members.find(member => member.name === 'input2')!;
|
||||
expect(input2.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input2.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
});
|
||||
|
||||
it('should find decorated members on a class when mixing `ctorParameters` and `__decorate`',
|
||||
@ -254,10 +254,10 @@ runInEachFileSystem(() => {
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const input1 = members.find(member => member.name === 'input1') !;
|
||||
const input1 = members.find(member => member.name === 'input1')!;
|
||||
expect(input1.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input1.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
});
|
||||
|
||||
it('should find non decorated properties on a class', () => {
|
||||
@ -268,11 +268,11 @@ runInEachFileSystem(() => {
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const instanceProperty = members.find(member => member.name === 'instanceProperty') !;
|
||||
const instanceProperty = members.find(member => member.name === 'instanceProperty')!;
|
||||
expect(instanceProperty.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(instanceProperty.isStatic).toEqual(false);
|
||||
expect(ts.isBinaryExpression(instanceProperty.implementation !)).toEqual(true);
|
||||
expect(instanceProperty.value !.getText()).toEqual(`'instance'`);
|
||||
expect(ts.isBinaryExpression(instanceProperty.implementation!)).toEqual(true);
|
||||
expect(instanceProperty.value!.getText()).toEqual(`'instance'`);
|
||||
});
|
||||
|
||||
it('should find static methods on a class', () => {
|
||||
@ -283,10 +283,10 @@ runInEachFileSystem(() => {
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const staticMethod = members.find(member => member.name === 'staticMethod') !;
|
||||
const staticMethod = members.find(member => member.name === 'staticMethod')!;
|
||||
expect(staticMethod.kind).toEqual(ClassMemberKind.Method);
|
||||
expect(staticMethod.isStatic).toEqual(true);
|
||||
expect(ts.isMethodDeclaration(staticMethod.implementation !)).toEqual(true);
|
||||
expect(ts.isMethodDeclaration(staticMethod.implementation!)).toEqual(true);
|
||||
});
|
||||
|
||||
it('should find static properties on a class', () => {
|
||||
@ -297,11 +297,11 @@ runInEachFileSystem(() => {
|
||||
isNamedVariableDeclaration);
|
||||
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
const staticProperty = members.find(member => member.name === 'staticProperty') !;
|
||||
const staticProperty = members.find(member => member.name === 'staticProperty')!;
|
||||
expect(staticProperty.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(staticProperty.isStatic).toEqual(true);
|
||||
expect(ts.isPropertyAccessExpression(staticProperty.implementation !)).toEqual(true);
|
||||
expect(staticProperty.value !.getText()).toEqual(`'static'`);
|
||||
expect(ts.isPropertyAccessExpression(staticProperty.implementation!)).toEqual(true);
|
||||
expect(staticProperty.value!.getText()).toEqual(`'static'`);
|
||||
});
|
||||
|
||||
it('should find static properties on a class that has an intermediate variable assignment',
|
||||
@ -313,11 +313,11 @@ runInEachFileSystem(() => {
|
||||
isNamedVariableDeclaration);
|
||||
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
const staticProperty = members.find(member => member.name === 'staticProperty') !;
|
||||
const staticProperty = members.find(member => member.name === 'staticProperty')!;
|
||||
expect(staticProperty.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(staticProperty.isStatic).toEqual(true);
|
||||
expect(ts.isPropertyAccessExpression(staticProperty.implementation !)).toEqual(true);
|
||||
expect(staticProperty.value !.getText()).toEqual(`'static'`);
|
||||
expect(ts.isPropertyAccessExpression(staticProperty.implementation!)).toEqual(true);
|
||||
expect(staticProperty.value!.getText()).toEqual(`'static'`);
|
||||
});
|
||||
|
||||
it('should support decorators being used inside @angular/core', () => {
|
||||
@ -329,10 +329,10 @@ runInEachFileSystem(() => {
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const input1 = members.find(member => member.name === 'input1') !;
|
||||
const input1 = members.find(member => member.name === 'input1')!;
|
||||
expect(input1.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input1.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -346,10 +346,10 @@ runInEachFileSystem(() => {
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
||||
expect(parameters).toBeDefined();
|
||||
expect(parameters !.map(parameter => parameter.name)).toEqual([
|
||||
expect(parameters!.map(parameter => parameter.name)).toEqual([
|
||||
'_viewContainer', '_template', 'injected'
|
||||
]);
|
||||
expectTypeValueReferencesForParameters(parameters !, [
|
||||
expectTypeValueReferencesForParameters(parameters!, [
|
||||
'ViewContainerRef',
|
||||
'TemplateRef',
|
||||
'String',
|
||||
@ -366,20 +366,20 @@ runInEachFileSystem(() => {
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
||||
expect(parameters).toBeDefined();
|
||||
expect(parameters !.map(parameter => parameter.name)).toEqual([
|
||||
expect(parameters!.map(parameter => parameter.name)).toEqual([
|
||||
'_viewContainer', '_template', 'injected'
|
||||
]);
|
||||
expectTypeValueReferencesForParameters(parameters !, [
|
||||
expectTypeValueReferencesForParameters(parameters!, [
|
||||
'ViewContainerRef',
|
||||
'TemplateRef',
|
||||
null,
|
||||
]);
|
||||
|
||||
const decorators = parameters ![2].decorators !;
|
||||
const decorators = parameters![2].decorators!;
|
||||
expect(decorators.length).toEqual(1);
|
||||
expect(decorators[0].name).toBe('Inject');
|
||||
expect(decorators[0].import !.from).toBe('@angular/core');
|
||||
expect(decorators[0].import !.name).toBe('Inject');
|
||||
expect(decorators[0].import!.from).toBe('@angular/core');
|
||||
expect(decorators[0].import!.name).toBe('Inject');
|
||||
});
|
||||
});
|
||||
|
||||
@ -390,8 +390,8 @@ runInEachFileSystem(() => {
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
||||
const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{
|
||||
const ctrDecorators = host.getConstructorParameters(classNode)!;
|
||||
const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference! as {
|
||||
local: true,
|
||||
expression: ts.Identifier,
|
||||
defaultImportStatement: null,
|
||||
@ -401,8 +401,8 @@ runInEachFileSystem(() => {
|
||||
bundle.program, _('/some_directive.js'), 'ViewContainerRef', ts.isClassDeclaration);
|
||||
const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef);
|
||||
expect(actualDeclaration).not.toBe(null);
|
||||
expect(actualDeclaration !.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration !.viaModule).toBe(null);
|
||||
expect(actualDeclaration!.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration!.viaModule).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the declaration of an externally defined identifier', () => {
|
||||
@ -411,8 +411,8 @@ runInEachFileSystem(() => {
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decoratorNode = classDecorators[0].node !;
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const decoratorNode = classDecorators[0].node!;
|
||||
const identifierOfDirective =
|
||||
ts.isCallExpression(decoratorNode) && ts.isIdentifier(decoratorNode.expression) ?
|
||||
decoratorNode.expression :
|
||||
@ -421,10 +421,10 @@ runInEachFileSystem(() => {
|
||||
const expectedDeclarationNode = getDeclaration(
|
||||
bundle.program, _('/node_modules/@angular/core/index.d.ts'), 'Directive',
|
||||
isNamedVariableDeclaration);
|
||||
const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !);
|
||||
const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective!);
|
||||
expect(actualDeclaration).not.toBe(null);
|
||||
expect(actualDeclaration !.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration !.viaModule).toBe('@angular/core');
|
||||
expect(actualDeclaration!.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration!.viaModule).toBe('@angular/core');
|
||||
});
|
||||
});
|
||||
|
||||
@ -435,13 +435,13 @@ runInEachFileSystem(() => {
|
||||
const ngModuleRef = findVariableDeclaration(
|
||||
getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'HttpClientXsrfModule_1');
|
||||
|
||||
const value = host.getVariableValue(ngModuleRef !);
|
||||
const value = host.getVariableValue(ngModuleRef!);
|
||||
expect(value).not.toBe(null);
|
||||
if (!value || !ts.isClassExpression(value)) {
|
||||
throw new Error(
|
||||
`Expected value to be a class expression: ${value && value.getText()}.`);
|
||||
}
|
||||
expect(value.name !.text).toBe('HttpClientXsrfModule');
|
||||
expect(value.name!.text).toBe('HttpClientXsrfModule');
|
||||
});
|
||||
|
||||
it('should return null if the variable has no assignment', () => {
|
||||
@ -449,7 +449,7 @@ runInEachFileSystem(() => {
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const missingValue = findVariableDeclaration(
|
||||
getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'missingValue');
|
||||
const value = host.getVariableValue(missingValue !);
|
||||
const value = host.getVariableValue(missingValue!);
|
||||
expect(value).toBe(null);
|
||||
});
|
||||
|
||||
@ -458,7 +458,7 @@ runInEachFileSystem(() => {
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const nonDecoratedVar = findVariableDeclaration(
|
||||
getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'nonDecoratedVar');
|
||||
const value = host.getVariableValue(nonDecoratedVar !);
|
||||
const value = host.getVariableValue(nonDecoratedVar!);
|
||||
expect(value).toBe(null);
|
||||
});
|
||||
});
|
||||
@ -468,7 +468,7 @@ runInEachFileSystem(() => {
|
||||
const bundle = makeTestBundleProgram(_('/ngmodule.js'));
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, bundle);
|
||||
const classSymbol =
|
||||
host.findClassSymbols(bundle.program.getSourceFile(_('/ngmodule.js')) !)[0];
|
||||
host.findClassSymbols(bundle.program.getSourceFile(_('/ngmodule.js'))!)[0];
|
||||
const endOfClass = host.getEndOfClass(classSymbol);
|
||||
expect(endOfClass.getText())
|
||||
.toMatch(
|
||||
@ -479,7 +479,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
function findVariableDeclaration(
|
||||
node: ts.Node | undefined, variableName: string): ts.VariableDeclaration|undefined {
|
||||
node: ts.Node|undefined, variableName: string): ts.VariableDeclaration|undefined {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, isNamedFunctionDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadFakeCore, loadTestFiles, loadTsLib} from '../../../test/helpers';
|
||||
@ -227,19 +227,18 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it('should find the decorators on a minified class', () => {
|
||||
@ -248,19 +247,18 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_minified_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it('should find the decorators on an aliased class', () => {
|
||||
@ -269,16 +267,16 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_aliased_directive.js'), 'AliasedDirective$1',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -290,16 +288,16 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive_ctor_parameters.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -311,16 +309,16 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/node_modules/@angular/core/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: './directives'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -333,13 +331,12 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_minified_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const innerNode =
|
||||
getIifeBody(classNode) !.statements.find(isNamedFunctionDeclaration) !;
|
||||
const innerNode = getIifeBody(classNode)!.statements.find(isNamedFunctionDeclaration)!;
|
||||
const classSymbol = host.getClassSymbol(classNode);
|
||||
|
||||
expect(classSymbol).toBeDefined();
|
||||
expect(classSymbol !.declaration.valueDeclaration).toBe(classNode);
|
||||
expect(classSymbol !.implementation.valueDeclaration).toBe(innerNode);
|
||||
expect(classSymbol!.declaration.valueDeclaration).toBe(classNode);
|
||||
expect(classSymbol!.implementation.valueDeclaration).toBe(innerNode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -352,15 +349,15 @@ export { AliasedDirective$1 };
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const input1 = members.find(member => member.name === 'input1') !;
|
||||
const input1 = members.find(member => member.name === 'input1')!;
|
||||
expect(input1.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input1.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
|
||||
const input2 = members.find(member => member.name === 'input2') !;
|
||||
const input2 = members.find(member => member.name === 'input2')!;
|
||||
expect(input2.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input2.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
});
|
||||
|
||||
it('should find decorated members on a class when mixing `ctorParameters` and `__decorate`',
|
||||
@ -372,10 +369,10 @@ export { AliasedDirective$1 };
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const input1 = members.find(member => member.name === 'input1') !;
|
||||
const input1 = members.find(member => member.name === 'input1')!;
|
||||
expect(input1.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input1.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
});
|
||||
|
||||
it('should find non decorated properties on a class', () => {
|
||||
@ -386,11 +383,11 @@ export { AliasedDirective$1 };
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const instanceProperty = members.find(member => member.name === 'instanceProperty') !;
|
||||
const instanceProperty = members.find(member => member.name === 'instanceProperty')!;
|
||||
expect(instanceProperty.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(instanceProperty.isStatic).toEqual(false);
|
||||
expect(ts.isBinaryExpression(instanceProperty.implementation !)).toEqual(true);
|
||||
expect(instanceProperty.value !.getText()).toEqual(`'instance'`);
|
||||
expect(ts.isBinaryExpression(instanceProperty.implementation!)).toEqual(true);
|
||||
expect(instanceProperty.value!.getText()).toEqual(`'instance'`);
|
||||
});
|
||||
|
||||
it('should find static methods on a class', () => {
|
||||
@ -401,10 +398,10 @@ export { AliasedDirective$1 };
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const staticMethod = members.find(member => member.name === 'staticMethod') !;
|
||||
const staticMethod = members.find(member => member.name === 'staticMethod')!;
|
||||
expect(staticMethod.kind).toEqual(ClassMemberKind.Method);
|
||||
expect(staticMethod.isStatic).toEqual(true);
|
||||
expect(ts.isFunctionExpression(staticMethod.implementation !)).toEqual(true);
|
||||
expect(ts.isFunctionExpression(staticMethod.implementation!)).toEqual(true);
|
||||
});
|
||||
|
||||
it('should find static properties on a class', () => {
|
||||
@ -415,11 +412,11 @@ export { AliasedDirective$1 };
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const staticProperty = members.find(member => member.name === 'staticProperty') !;
|
||||
const staticProperty = members.find(member => member.name === 'staticProperty')!;
|
||||
expect(staticProperty.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(staticProperty.isStatic).toEqual(true);
|
||||
expect(ts.isPropertyAccessExpression(staticProperty.implementation !)).toEqual(true);
|
||||
expect(staticProperty.value !.getText()).toEqual(`'static'`);
|
||||
expect(ts.isPropertyAccessExpression(staticProperty.implementation!)).toEqual(true);
|
||||
expect(staticProperty.value!.getText()).toEqual(`'static'`);
|
||||
});
|
||||
|
||||
it('should support decorators being used inside @angular/core', () => {
|
||||
@ -431,10 +428,10 @@ export { AliasedDirective$1 };
|
||||
isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const input1 = members.find(member => member.name === 'input1') !;
|
||||
const input1 = members.find(member => member.name === 'input1')!;
|
||||
expect(input1.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input1.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
});
|
||||
});
|
||||
describe('getConstructorParameters', () => {
|
||||
@ -447,10 +444,10 @@ export { AliasedDirective$1 };
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
||||
expect(parameters).toBeDefined();
|
||||
expect(parameters !.map(parameter => parameter.name)).toEqual([
|
||||
expect(parameters!.map(parameter => parameter.name)).toEqual([
|
||||
'_viewContainer', '_template', 'injected'
|
||||
]);
|
||||
expectTypeValueReferencesForParameters(parameters !, [
|
||||
expectTypeValueReferencesForParameters(parameters!, [
|
||||
'ViewContainerRef',
|
||||
'TemplateRef',
|
||||
'String',
|
||||
@ -467,10 +464,10 @@ export { AliasedDirective$1 };
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
||||
expect(parameters).toBeDefined();
|
||||
expect(parameters !.map(parameter => parameter.name)).toEqual([
|
||||
expect(parameters!.map(parameter => parameter.name)).toEqual([
|
||||
'_viewContainer', '_template', 'injected'
|
||||
]);
|
||||
expectTypeValueReferencesForParameters(parameters !, [
|
||||
expectTypeValueReferencesForParameters(parameters!, [
|
||||
'ViewContainerRef',
|
||||
'TemplateRef',
|
||||
null,
|
||||
@ -485,7 +482,7 @@ export { AliasedDirective$1 };
|
||||
bundle.program, _('/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
const decorators = parameters ![2].decorators !;
|
||||
const decorators = parameters![2].decorators!;
|
||||
|
||||
expect(decorators.length).toEqual(1);
|
||||
expect(decorators[0].import).toEqual({name: 'Inject', from: '@angular/core'});
|
||||
@ -522,7 +519,7 @@ export { AliasedDirective$1 };
|
||||
const ngModuleDecorators = ngModuleClasses.map(s => host.getDecoratorsOfSymbol(s));
|
||||
|
||||
expect(ngModuleClasses.length).toEqual(1);
|
||||
expect(ngModuleDecorators[0] !.map(d => d.name)).toEqual(['NgModule']);
|
||||
expect(ngModuleDecorators[0]!.map(d => d.name)).toEqual(['NgModule']);
|
||||
|
||||
const someDirectiveFile = getSourceFileOrError(bundle.program, _('/some_directive.js'));
|
||||
const someDirectiveClasses = host.findClassSymbols(someDirectiveFile);
|
||||
@ -532,7 +529,7 @@ export { AliasedDirective$1 };
|
||||
expect(someDirectiveDecorators.length).toEqual(3);
|
||||
expect(someDirectiveDecorators[0]).toBe(null);
|
||||
expect(someDirectiveDecorators[1]).toBe(null);
|
||||
expect(someDirectiveDecorators[2] !.map(d => d.name)).toEqual(['Directive']);
|
||||
expect(someDirectiveDecorators[2]!.map(d => d.name)).toEqual(['Directive']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -543,8 +540,8 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const ctrDecorators = host.getConstructorParameters(classNode) !;
|
||||
const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference !as{
|
||||
const ctrDecorators = host.getConstructorParameters(classNode)!;
|
||||
const identifierOfViewContainerRef = (ctrDecorators[0].typeValueReference! as {
|
||||
local: true,
|
||||
expression: ts.Identifier,
|
||||
defaultImportStatement: null,
|
||||
@ -555,8 +552,8 @@ export { AliasedDirective$1 };
|
||||
isNamedVariableDeclaration);
|
||||
const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfViewContainerRef);
|
||||
expect(actualDeclaration).not.toBe(null);
|
||||
expect(actualDeclaration !.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration !.viaModule).toBe(null);
|
||||
expect(actualDeclaration!.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration!.viaModule).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the declaration of an externally defined identifier', () => {
|
||||
@ -565,8 +562,8 @@ export { AliasedDirective$1 };
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, _('/some_directive.js'), 'SomeDirective',
|
||||
isNamedVariableDeclaration);
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decoratorNode = classDecorators[0].node !;
|
||||
const classDecorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
const decoratorNode = classDecorators[0].node!;
|
||||
|
||||
const identifierOfDirective =
|
||||
ts.isCallExpression(decoratorNode) && ts.isIdentifier(decoratorNode.expression) ?
|
||||
@ -576,10 +573,10 @@ export { AliasedDirective$1 };
|
||||
const expectedDeclarationNode = getDeclaration(
|
||||
bundle.program, _('/node_modules/@angular/core/index.d.ts'), 'Directive',
|
||||
isNamedVariableDeclaration);
|
||||
const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective !);
|
||||
const actualDeclaration = host.getDeclarationOfIdentifier(identifierOfDirective!);
|
||||
expect(actualDeclaration).not.toBe(null);
|
||||
expect(actualDeclaration !.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration !.viaModule).toBe('@angular/core');
|
||||
expect(actualDeclaration!.node).toBe(expectedDeclarationNode);
|
||||
expect(actualDeclaration!.viaModule).toBe('@angular/core');
|
||||
});
|
||||
|
||||
it('should find the "actual" declaration of an aliased variable identifier', () => {
|
||||
@ -589,9 +586,9 @@ export { AliasedDirective$1 };
|
||||
getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'HttpClientXsrfModule_1',
|
||||
isNgModulePropertyAssignment);
|
||||
|
||||
const declaration = host.getDeclarationOfIdentifier(ngModuleRef !);
|
||||
const declaration = host.getDeclarationOfIdentifier(ngModuleRef!);
|
||||
expect(declaration).not.toBe(null);
|
||||
expect(declaration !.node !.getText()).toContain('function HttpClientXsrfModule()');
|
||||
expect(declaration!.node!.getText()).toContain('function HttpClientXsrfModule()');
|
||||
});
|
||||
});
|
||||
describe('getVariableValue', () => {
|
||||
@ -601,7 +598,7 @@ export { AliasedDirective$1 };
|
||||
const ngModuleRef = findVariableDeclaration(
|
||||
getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'HttpClientXsrfModule_1');
|
||||
|
||||
const value = host.getVariableValue(ngModuleRef !);
|
||||
const value = host.getVariableValue(ngModuleRef!);
|
||||
expect(value).not.toBe(null);
|
||||
if (!value || !ts.isFunctionDeclaration(value.parent)) {
|
||||
throw new Error(
|
||||
@ -615,7 +612,7 @@ export { AliasedDirective$1 };
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const missingValue = findVariableDeclaration(
|
||||
getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'missingValue');
|
||||
const value = host.getVariableValue(missingValue !);
|
||||
const value = host.getVariableValue(missingValue!);
|
||||
expect(value).toBe(null);
|
||||
});
|
||||
|
||||
@ -624,7 +621,7 @@ export { AliasedDirective$1 };
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const nonDecoratedVar = findVariableDeclaration(
|
||||
getSourceFileOrError(bundle.program, _('/ngmodule.js')), 'nonDecoratedVar');
|
||||
const value = host.getVariableValue(nonDecoratedVar !);
|
||||
const value = host.getVariableValue(nonDecoratedVar!);
|
||||
expect(value).toBe(null);
|
||||
});
|
||||
});
|
||||
@ -634,7 +631,7 @@ export { AliasedDirective$1 };
|
||||
const bundle = makeTestBundleProgram(_('/ngmodule.js'));
|
||||
const host = new Esm5ReflectionHost(new MockLogger(), false, bundle);
|
||||
const classSymbol =
|
||||
host.findClassSymbols(bundle.program.getSourceFile(_('/ngmodule.js')) !)[0];
|
||||
host.findClassSymbols(bundle.program.getSourceFile(_('/ngmodule.js'))!)[0];
|
||||
const endOfClass = host.getEndOfClass(classSymbol);
|
||||
expect(endOfClass.getText())
|
||||
.toMatch(
|
||||
@ -644,7 +641,7 @@ export { AliasedDirective$1 };
|
||||
});
|
||||
|
||||
function findVariableDeclaration(
|
||||
node: ts.Node | undefined, variableName: string): ts.VariableDeclaration|undefined {
|
||||
node: ts.Node|undefined, variableName: string): ts.VariableDeclaration|undefined {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@ -656,7 +653,7 @@ export { AliasedDirective$1 };
|
||||
});
|
||||
|
||||
function findIdentifier(
|
||||
node: ts.Node | undefined, identifierName: string,
|
||||
node: ts.Node|undefined, identifierName: string,
|
||||
requireFn: (node: ts.Identifier) => boolean): ts.Identifier|undefined {
|
||||
if (!node) {
|
||||
return undefined;
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {ClassMemberKind, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
@ -81,16 +81,16 @@ runInEachFileSystem(() => {
|
||||
const host = new UmdReflectionHost(new MockLogger(), false, bundle);
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('core.Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('core.Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -102,16 +102,16 @@ runInEachFileSystem(() => {
|
||||
const classNode = getDeclaration(
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'AliasedDirective$1',
|
||||
isNamedVariableDeclaration);
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode) !;
|
||||
const decorators = host.getDecoratorsOfDeclaration(classNode)!;
|
||||
|
||||
expect(decorators).toBeDefined();
|
||||
expect(decorators.length).toEqual(1);
|
||||
|
||||
const decorator = decorators[0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier !.getText()).toEqual('core.Directive');
|
||||
expect(decorator.identifier!.getText()).toEqual('core.Directive');
|
||||
expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'});
|
||||
expect(decorator.args !.map(arg => arg.getText())).toEqual([
|
||||
expect(decorator.args!.map(arg => arg.getText())).toEqual([
|
||||
'{ selector: \'[someDirective]\' }',
|
||||
]);
|
||||
});
|
||||
@ -126,15 +126,15 @@ runInEachFileSystem(() => {
|
||||
bundle.program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', isNamedVariableDeclaration);
|
||||
const members = host.getMembersOfClass(classNode);
|
||||
|
||||
const input1 = members.find(member => member.name === 'input1') !;
|
||||
const input1 = members.find(member => member.name === 'input1')!;
|
||||
expect(input1.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input1.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
|
||||
const input2 = members.find(member => member.name === 'input2') !;
|
||||
const input2 = members.find(member => member.name === 'input2')!;
|
||||
expect(input2.kind).toEqual(ClassMemberKind.Property);
|
||||
expect(input2.isStatic).toEqual(false);
|
||||
expect(input1.decorators !.map(d => d.name)).toEqual(['Input']);
|
||||
expect(input1.decorators!.map(d => d.name)).toEqual(['Input']);
|
||||
});
|
||||
|
||||
describe('getConstructorParameters', () => {
|
||||
@ -148,10 +148,10 @@ runInEachFileSystem(() => {
|
||||
const parameters = host.getConstructorParameters(classNode);
|
||||
|
||||
expect(parameters).toBeDefined();
|
||||
expect(parameters !.map(parameter => parameter.name)).toEqual([
|
||||
expect(parameters!.map(parameter => parameter.name)).toEqual([
|
||||
'_viewContainer', '_template', 'injected'
|
||||
]);
|
||||
expectTypeValueReferencesForParameters(parameters !, [
|
||||
expectTypeValueReferencesForParameters(parameters!, [
|
||||
'ViewContainerRef',
|
||||
'TemplateRef',
|
||||
null,
|
||||
|
@ -14,9 +14,8 @@ import {CtorParameter} from '../../../src/ngtsc/reflection';
|
||||
* names.
|
||||
*/
|
||||
export function expectTypeValueReferencesForParameters(
|
||||
parameters: CtorParameter[], expectedParams: (string | null)[],
|
||||
fromModule: string | null = null) {
|
||||
parameters !.forEach((param, idx) => {
|
||||
parameters: CtorParameter[], expectedParams: (string|null)[], fromModule: string|null = null) {
|
||||
parameters!.forEach((param, idx) => {
|
||||
const expected = expectedParams[idx];
|
||||
if (expected !== null) {
|
||||
if (param.typeValueReference === null) {
|
||||
@ -32,7 +31,7 @@ export function expectTypeValueReferencesForParameters(
|
||||
expect(param.typeValueReference.expression.text).toEqual(expected);
|
||||
}
|
||||
} else if (param.typeValueReference !== null) {
|
||||
expect(param.typeValueReference.moduleName).toBe(fromModule !);
|
||||
expect(param.typeValueReference.moduleName).toBe(fromModule!);
|
||||
expect(param.typeValueReference.name).toBe(expected);
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,9 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as os from 'os';
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem, join} from '../../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem, TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, join} from '../../../src/ngtsc/file_system';
|
||||
import {Folder, MockFileSystem, runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadStandardTestFiles, loadTestFiles} from '../../../test/helpers';
|
||||
import {getLockFilePath} from '../../src/locking/lock_file';
|
||||
import {mainNgcc} from '../../src/main';
|
||||
@ -19,6 +20,7 @@ import {EntryPointManifestFile} from '../../src/packages/entry_point_manifest';
|
||||
import {Transformer} from '../../src/packages/transformer';
|
||||
import {DirectPackageJsonUpdater, PackageJsonUpdater} from '../../src/writing/package_json_updater';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
|
||||
import {compileIntoApf, compileIntoFlatEs5Package} from './util';
|
||||
|
||||
const testFiles = loadStandardTestFiles({fakeCore: false, rxjs: true});
|
||||
@ -145,7 +147,8 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
['esm5', 'esm2015'].forEach(target => {
|
||||
it(`should be able to process spread operator inside objects for ${target} format (imported helpers)`,
|
||||
it(`should be able to process spread operator inside objects for ${
|
||||
target} format (imported helpers)`,
|
||||
() => {
|
||||
compileIntoApf(
|
||||
'test-package', {
|
||||
@ -184,7 +187,8 @@ runInEachFileSystem(() => {
|
||||
expect(jsContents).toContain('ngcc0.ɵɵclassProp("a", true)("b", true)("c", false)');
|
||||
});
|
||||
|
||||
it(`should be able to process emitted spread operator inside objects for ${target} format (emitted helpers)`,
|
||||
it(`should be able to process emitted spread operator inside objects for ${
|
||||
target} format (emitted helpers)`,
|
||||
() => {
|
||||
compileIntoApf(
|
||||
'test-package', {
|
||||
@ -326,7 +330,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
const before = fs.readFile(_(`/node_modules/test-package/index.js`));
|
||||
const originalProp = /ɵprov[^;]+/.exec(before) ![0];
|
||||
const originalProp = /ɵprov[^;]+/.exec(before)![0];
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: 'test-package',
|
||||
@ -496,7 +500,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
describe('in async mode', () => {
|
||||
it('should run ngcc without errors for fesm2015', async() => {
|
||||
it('should run ngcc without errors for fesm2015', async () => {
|
||||
const promise = mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['fesm2015'],
|
||||
@ -507,7 +511,7 @@ runInEachFileSystem(() => {
|
||||
await promise;
|
||||
});
|
||||
|
||||
it('should reject, if some of the entry-points are unprocessable', async() => {
|
||||
it('should reject, if some of the entry-points are unprocessable', async () => {
|
||||
const createEntryPoint = (name: string, prop: EntryPointJsonProperty): TestFile[] => {
|
||||
return [
|
||||
{
|
||||
@ -541,7 +545,7 @@ runInEachFileSystem(() => {
|
||||
` - ${_('/dist/unprocessable-3')}`)));
|
||||
});
|
||||
|
||||
it('should reject, if an error happens during processing', async() => {
|
||||
it('should reject, if an error happens during processing', async () => {
|
||||
spyOn(Transformer.prototype, 'transform').and.throwError('Test error.');
|
||||
|
||||
const promise = mainNgcc({
|
||||
@ -651,7 +655,8 @@ runInEachFileSystem(() => {
|
||||
markPropertiesAsProcessed('@angular/common/http/testing', SUPPORTED_FORMAT_PROPERTIES);
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing', logger,
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.debug).toContain([
|
||||
'The target entry-point has already been processed'
|
||||
@ -665,7 +670,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
propertiesToConsider: ['fesm2015', 'esm5', 'esm2015'], logger,
|
||||
propertiesToConsider: ['fesm2015', 'esm5', 'esm2015'],
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.debug).not.toContain([
|
||||
'The target entry-point has already been processed'
|
||||
@ -682,7 +688,8 @@ runInEachFileSystem(() => {
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
propertiesToConsider: ['esm5', 'esm2015'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).not.toContain([
|
||||
@ -699,7 +706,8 @@ runInEachFileSystem(() => {
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
// Simulate a property that does not exist on the package.json and will be ignored.
|
||||
propertiesToConsider: ['missing', 'esm2015', 'esm5'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).toContain([
|
||||
@ -717,7 +725,8 @@ runInEachFileSystem(() => {
|
||||
targetEntryPointPath: '@angular/common/http/testing',
|
||||
// Simulate a property that does not exist on the package.json and will be ignored.
|
||||
propertiesToConsider: ['missing', 'esm2015', 'esm5'],
|
||||
compileAllFormats: false, logger,
|
||||
compileAllFormats: false,
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logger.logs.debug).toContain([
|
||||
@ -752,7 +761,7 @@ runInEachFileSystem(() => {
|
||||
|
||||
// Now hack the files to look like it was processed by an outdated version of ngcc
|
||||
const packageJson = loadPackage('test-package', _('/node_modules'));
|
||||
packageJson.__processed_by_ivy_ngcc__ !.typings = '8.0.0';
|
||||
packageJson.__processed_by_ivy_ngcc__!.typings = '8.0.0';
|
||||
packageJson.main_ivy_ngcc = '__ivy_ngcc__/main.js';
|
||||
fs.writeFile(_('/node_modules/test-package/package.json'), JSON.stringify(packageJson));
|
||||
fs.writeFile(_('/node_modules/test-package/x.js'), 'processed content');
|
||||
@ -838,7 +847,8 @@ runInEachFileSystem(() => {
|
||||
// `fesm2015` and `es2015` map to the same file: `./fesm2015/common.js`
|
||||
mainNgcc({
|
||||
basePath: '/node_modules/@angular/common',
|
||||
propertiesToConsider: ['fesm2015'], logger,
|
||||
propertiesToConsider: ['fesm2015'],
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logs).not.toContain(['Skipping @angular/common : es2015 (already compiled).']);
|
||||
@ -851,7 +861,8 @@ runInEachFileSystem(() => {
|
||||
// Now, compiling `es2015` should be a no-op.
|
||||
mainNgcc({
|
||||
basePath: '/node_modules/@angular/common',
|
||||
propertiesToConsider: ['es2015'], logger,
|
||||
propertiesToConsider: ['es2015'],
|
||||
logger,
|
||||
});
|
||||
|
||||
expect(logs).toContain(['Skipping @angular/common : es2015 (already compiled).']);
|
||||
@ -997,21 +1008,21 @@ runInEachFileSystem(() => {
|
||||
expectNotToHaveProp(pkg, 'esm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm2015_ivy_ngcc');
|
||||
expectNotToHaveProp(pkg, 'fesm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__ !, 'fesm2015');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__!, 'fesm2015');
|
||||
|
||||
// Process `fesm5` and update `package.json`.
|
||||
pkg = processFormatAndUpdatePackageJson('fesm5');
|
||||
expectNotToHaveProp(pkg, 'esm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm2015_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__ !, 'fesm5');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__!, 'fesm5');
|
||||
|
||||
// Process `esm5` and update `package.json`.
|
||||
pkg = processFormatAndUpdatePackageJson('esm5');
|
||||
expectToHaveProp(pkg, 'esm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm2015_ivy_ngcc');
|
||||
expectToHaveProp(pkg, 'fesm5_ivy_ngcc');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__ !, 'esm5');
|
||||
expectToHaveProp(pkg.__processed_by_ivy_ngcc__!, 'esm5');
|
||||
|
||||
// Ensure the properties are in deterministic order (regardless of processing order).
|
||||
const pkgKeys = stringifyKeys(pkg);
|
||||
@ -1026,7 +1037,7 @@ runInEachFileSystem(() => {
|
||||
// For example:
|
||||
// - `fesm2015` <=> `es2015`
|
||||
// - `fesm5` <=> `module`
|
||||
expect(stringifyKeys(pkg.__processed_by_ivy_ngcc__ !))
|
||||
expect(stringifyKeys(pkg.__processed_by_ivy_ngcc__!))
|
||||
.toBe('|es2015|esm5|fesm2015|fesm5|module|typings|');
|
||||
|
||||
// Helpers
|
||||
@ -1034,7 +1045,8 @@ runInEachFileSystem(() => {
|
||||
expect(obj.hasOwnProperty(prop))
|
||||
.toBe(
|
||||
false,
|
||||
`Expected object not to have property '${prop}': ${JSON.stringify(obj, null, 2)}`);
|
||||
`Expected object not to have property '${prop}': ${
|
||||
JSON.stringify(obj, null, 2)}`);
|
||||
}
|
||||
|
||||
function expectToHaveProp(obj: object, prop: string) {
|
||||
@ -1053,7 +1065,9 @@ runInEachFileSystem(() => {
|
||||
return loadPackage('@angular/core');
|
||||
}
|
||||
|
||||
function stringifyKeys(obj: object) { return `|${Object.keys(obj).join('|')}|`; }
|
||||
function stringifyKeys(obj: object) {
|
||||
return `|${Object.keys(obj).join('|')}|`;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -1206,7 +1220,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['es2015'],
|
||||
errorOnFailedEntryPoint: false, logger,
|
||||
errorOnFailedEntryPoint: false,
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.error.length).toEqual(1);
|
||||
const message = logger.logs.error[0][0];
|
||||
@ -1236,7 +1251,8 @@ runInEachFileSystem(() => {
|
||||
const logger = new MockLogger();
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['esm2015'], logger,
|
||||
propertiesToConsider: ['esm2015'],
|
||||
logger,
|
||||
});
|
||||
expect(logger.logs.info).toContain(['Compiling @angular/common/http : esm2015 as esm2015']);
|
||||
});
|
||||
@ -1281,7 +1297,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/dist',
|
||||
propertiesToConsider: ['es2015'],
|
||||
tsConfigPath: _('/tsconfig.app.json'), logger
|
||||
tsConfigPath: _('/tsconfig.app.json'),
|
||||
logger
|
||||
});
|
||||
expect(loadPackage('local-package', _('/dist')).__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
@ -1316,7 +1333,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
propertiesToConsider: ['es2015'],
|
||||
pathMappings: {paths: {'*': ['dist/*']}, baseUrl: '/'}, logger
|
||||
pathMappings: {paths: {'*': ['dist/*']}, baseUrl: '/'},
|
||||
logger
|
||||
});
|
||||
expect(loadPackage('@angular/core').__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
@ -1356,7 +1374,8 @@ runInEachFileSystem(() => {
|
||||
mainNgcc({
|
||||
basePath: '/dist',
|
||||
propertiesToConsider: ['es2015'],
|
||||
tsConfigPath: null, logger,
|
||||
tsConfigPath: null,
|
||||
logger,
|
||||
});
|
||||
expect(loadPackage('local-package', _('/dist')).__processed_by_ivy_ngcc__).toEqual({
|
||||
es2015: '0.0.0-PLACEHOLDER',
|
||||
@ -1821,7 +1840,7 @@ runInEachFileSystem(() => {
|
||||
expect(jsContents).toContain('exports.ɵngExportɵFooModuleɵFoo = ɵngcc1.Foo;');
|
||||
expect(dtsContents)
|
||||
.toContain(`export {Foo as ɵngExportɵFooModuleɵFoo} from './directive';`);
|
||||
expect(dtsContents.match(/ɵngExportɵFooModuleɵFoo/g) !.length).toBe(1);
|
||||
expect(dtsContents.match(/ɵngExportɵFooModuleɵFoo/g)!.length).toBe(1);
|
||||
expect(dtsContents).not.toContain(`ɵngExportɵFooModuleɵLocalDir`);
|
||||
});
|
||||
});
|
||||
|
@ -234,11 +234,21 @@ class MockCompilerHost implements ts.CompilerHost {
|
||||
this.fs.writeFile(this.fs.resolve(fileName), data);
|
||||
}
|
||||
|
||||
getCurrentDirectory(): string { return this.fs.pwd(); }
|
||||
getCanonicalFileName(fileName: string): string { return fileName; }
|
||||
useCaseSensitiveFileNames(): boolean { return true; }
|
||||
getNewLine(): string { return '\n'; }
|
||||
fileExists(fileName: string): boolean { return this.fs.exists(this.fs.resolve(fileName)); }
|
||||
getCurrentDirectory(): string {
|
||||
return this.fs.pwd();
|
||||
}
|
||||
getCanonicalFileName(fileName: string): string {
|
||||
return fileName;
|
||||
}
|
||||
useCaseSensitiveFileNames(): boolean {
|
||||
return true;
|
||||
}
|
||||
getNewLine(): string {
|
||||
return '\n';
|
||||
}
|
||||
fileExists(fileName: string): boolean {
|
||||
return this.fs.exists(this.fs.resolve(fileName));
|
||||
}
|
||||
readFile(fileName: string): string|undefined {
|
||||
const abs = this.fs.resolve(fileName);
|
||||
return this.fs.exists(abs) ? this.fs.readFile(abs) : undefined;
|
||||
|
@ -14,13 +14,13 @@ import {MockLogger} from '../helpers/mock_logger';
|
||||
runInEachFileSystem(() => {
|
||||
describe('AsyncLocker', () => {
|
||||
describe('lock()', () => {
|
||||
it('should guard the `fn()` with calls to `write()` and `remove()`', async() => {
|
||||
it('should guard the `fn()` with calls to `write()` and `remove()`', async () => {
|
||||
const fs = getFileSystem();
|
||||
const log: string[] = [];
|
||||
const lockFile = new MockLockFile(fs, log);
|
||||
const locker = new AsyncLocker(lockFile, new MockLogger(), 100, 10);
|
||||
|
||||
await locker.lock(async() => {
|
||||
await locker.lock(async () => {
|
||||
log.push('fn() - before');
|
||||
// This promise forces node to do a tick in this function, ensuring that we are truly
|
||||
// testing an async scenario.
|
||||
@ -31,7 +31,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
it('should guard the `fn()` with calls to `write()` and `remove()`, even if it throws',
|
||||
async() => {
|
||||
async () => {
|
||||
let error: string = '';
|
||||
const fs = getFileSystem();
|
||||
const log: string[] = [];
|
||||
@ -39,7 +39,7 @@ runInEachFileSystem(() => {
|
||||
const locker = new AsyncLocker(lockFile, new MockLogger(), 100, 10);
|
||||
|
||||
try {
|
||||
await locker.lock(async() => {
|
||||
await locker.lock(async () => {
|
||||
log.push('fn()');
|
||||
throw new Error('ERROR');
|
||||
});
|
||||
@ -50,7 +50,7 @@ runInEachFileSystem(() => {
|
||||
expect(log).toEqual(['write()', 'fn()', 'remove()']);
|
||||
});
|
||||
|
||||
it('should retry if another process is locking', async() => {
|
||||
it('should retry if another process is locking', async () => {
|
||||
const fs = getFileSystem();
|
||||
const log: string[] = [];
|
||||
const lockFile = new MockLockFile(fs, log);
|
||||
@ -69,7 +69,7 @@ runInEachFileSystem(() => {
|
||||
return lockFileContents;
|
||||
});
|
||||
|
||||
const promise = locker.lock(async() => log.push('fn()'));
|
||||
const promise = locker.lock(async () => log.push('fn()'));
|
||||
// The lock is now waiting on the lock-file becoming free, so no `fn()` in the log.
|
||||
expect(log).toEqual(['write()', 'read() => 188']);
|
||||
expect(logger.logs.info).toEqual([[
|
||||
@ -83,7 +83,7 @@ runInEachFileSystem(() => {
|
||||
expect(log).toEqual(['write()', 'read() => 188', 'write()', 'fn()', 'remove()']);
|
||||
});
|
||||
|
||||
it('should extend the retry timeout if the other process locking the file changes', async() => {
|
||||
it('should extend the retry timeout if the other process locking the file changes', async () => {
|
||||
const fs = getFileSystem();
|
||||
const log: string[] = [];
|
||||
const lockFile = new MockLockFile(fs, log);
|
||||
@ -102,7 +102,7 @@ runInEachFileSystem(() => {
|
||||
return lockFileContents;
|
||||
});
|
||||
|
||||
const promise = locker.lock(async() => log.push('fn()'));
|
||||
const promise = locker.lock(async () => log.push('fn()'));
|
||||
// The lock is now waiting on the lock-file becoming free, so no `fn()` in the log.
|
||||
expect(log).toEqual(['write()', 'read() => 188']);
|
||||
expect(logger.logs.info).toEqual([[
|
||||
@ -132,7 +132,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
it('should error if another process does not release the lock-file before this times out',
|
||||
async() => {
|
||||
async () => {
|
||||
const fs = getFileSystem();
|
||||
const log: string[] = [];
|
||||
const lockFile = new MockLockFile(fs, log);
|
||||
@ -151,7 +151,7 @@ runInEachFileSystem(() => {
|
||||
return lockFileContents;
|
||||
});
|
||||
|
||||
const promise = locker.lock(async() => log.push('fn()'));
|
||||
const promise = locker.lock(async () => log.push('fn()'));
|
||||
|
||||
// The lock is now waiting on the lock-file becoming free, so no `fn()` in the log.
|
||||
expect(log).toEqual(['write()', 'read() => 188']);
|
||||
@ -159,10 +159,11 @@ runInEachFileSystem(() => {
|
||||
let error: Error;
|
||||
await promise.catch(e => error = e);
|
||||
expect(log).toEqual(['write()', 'read() => 188', 'write()', 'read() => 188']);
|
||||
expect(error !.message)
|
||||
expect(error!.message)
|
||||
.toEqual(
|
||||
`Timed out waiting 0.2s for another ngcc process, with id 188, to complete.\n` +
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${lockFile.path}.)`);
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${
|
||||
lockFile.path}.)`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ runInEachFileSystem(() => {
|
||||
class LockFileUnderTest extends LockFileWithChildProcess {
|
||||
// Note that log is initialized in the `createUnlocker()` function that is called from
|
||||
// super(), so we can't initialize it here.
|
||||
log !: string[];
|
||||
log!: string[];
|
||||
constructor(fs: FileSystem) {
|
||||
super(fs, new MockLogger());
|
||||
fs.ensureDir(fs.dirname(this.path));
|
||||
@ -47,7 +47,11 @@ runInEachFileSystem(() => {
|
||||
const log = this.log;
|
||||
// Normally this would fork a child process and return it.
|
||||
// But we don't want to do that in these tests.
|
||||
return <any>{disconnect() { log.push('unlocker.disconnect()'); }};
|
||||
return <any>{
|
||||
disconnect() {
|
||||
log.push('unlocker.disconnect()');
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* 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, FileSystem, absoluteFrom, getFileSystem} from '../../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../../src/ngtsc/file_system/testing';
|
||||
import {removeLockFile} from '../../../src/locking/lock_file_with_child_process/util';
|
||||
import {MockLogger} from '../../helpers/mock_logger';
|
||||
@ -24,8 +24,9 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
describe('removeLockFile()', () => {
|
||||
it('should do nothing if there is no file to remove',
|
||||
() => { removeLockFile(fs, logger, absoluteFrom('/lockfile/path'), '1234'); });
|
||||
it('should do nothing if there is no file to remove', () => {
|
||||
removeLockFile(fs, logger, absoluteFrom('/lockfile/path'), '1234');
|
||||
});
|
||||
|
||||
it('should do nothing if the pid does not match', () => {
|
||||
fs.writeFile(lockFilePath, '888');
|
||||
|
@ -50,7 +50,9 @@ runInEachFileSystem(() => {
|
||||
const lockFile = new MockLockFile(fs, log);
|
||||
const locker = new SyncLocker(lockFile);
|
||||
|
||||
spyOn(lockFile, 'write').and.callFake(() => { throw {code: 'EEXIST'}; });
|
||||
spyOn(lockFile, 'write').and.callFake(() => {
|
||||
throw {code: 'EEXIST'};
|
||||
});
|
||||
spyOn(lockFile, 'read').and.returnValue('188');
|
||||
|
||||
expect(() => locker.lock(() => {}))
|
||||
@ -58,7 +60,8 @@ runInEachFileSystem(() => {
|
||||
`ngcc is already running at process with id 188.\n` +
|
||||
`If you are running multiple builds in parallel then you should pre-process your node_modules via the command line ngcc tool before starting the builds;\n` +
|
||||
`See https://v9.angular.io/guide/ivy#speeding-up-ngcc-compilation.\n` +
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${lockFile.path}.)`);
|
||||
`(If you are sure no ngcc process is running then you should delete the lock-file at ${
|
||||
lockFile.path}.)`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -7,14 +7,14 @@
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {absoluteFrom, AbsoluteFsPath, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {DecorationAnalyses} from '../../src/analysis/types';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {MissingInjectableMigration, getAngularCoreDecoratorName} from '../../src/migrations/missing_injectable_migration';
|
||||
import {getAngularCoreDecoratorName, MissingInjectableMigration} from '../../src/migrations/missing_injectable_migration';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
@ -58,7 +58,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceA')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceB')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceC')).toBe(false);
|
||||
@ -66,7 +66,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
function runTests(
|
||||
type: 'NgModule' | 'Directive' | 'Component', propName: 'providers' | 'viewProviders') {
|
||||
type: 'NgModule'|'Directive'|'Component', propName: 'providers'|'viewProviders') {
|
||||
const args = type === 'Component' ? 'template: "", ' : '';
|
||||
|
||||
it(`should migrate type provider in ${type}`, () => {
|
||||
@ -85,7 +85,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'OtherService')).toBe(false);
|
||||
});
|
||||
@ -106,12 +106,12 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'OtherService')).toBe(false);
|
||||
});
|
||||
|
||||
it(`should migrate object literal provider with forwardRef in ${type}`, async() => {
|
||||
it(`should migrate object literal provider with forwardRef in ${type}`, async () => {
|
||||
const {program, analysis} = setUpAndAnalyzeProgram([{
|
||||
name: INDEX_FILENAME,
|
||||
contents: `
|
||||
@ -121,12 +121,13 @@ runInEachFileSystem(() => {
|
||||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: forwardRef(() => MyService) }]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: forwardRef(() => MyService) }]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(true);
|
||||
});
|
||||
|
||||
@ -140,12 +141,13 @@ runInEachFileSystem(() => {
|
||||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: MyService, useValue: null }]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: MyService, useValue: null }]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(false);
|
||||
});
|
||||
|
||||
@ -159,12 +161,13 @@ runInEachFileSystem(() => {
|
||||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: MyService, useFactory: () => null }]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: MyService, useFactory: () => null }]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(false);
|
||||
});
|
||||
|
||||
@ -189,7 +192,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyToken')).toBe(false);
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyTokenAlias')).toBe(false);
|
||||
@ -206,12 +209,13 @@ runInEachFileSystem(() => {
|
||||
|
||||
export class TestClass {}
|
||||
TestClass.decorators = [
|
||||
{ type: ${type}, args: [{${args}${propName}: [{provide: MyToken, useClass: MyService}]}] }
|
||||
{ type: ${type}, args: [{${args}${
|
||||
propName}: [{provide: MyToken, useClass: MyService}]}] }
|
||||
];
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyToken')).toBe(false);
|
||||
});
|
||||
@ -234,7 +238,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(getInjectableDecorators(index, analysis, 'MyService').length).toBe(1);
|
||||
});
|
||||
|
||||
@ -256,7 +260,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(false);
|
||||
});
|
||||
|
||||
@ -278,7 +282,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(false);
|
||||
});
|
||||
|
||||
@ -300,7 +304,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(false);
|
||||
});
|
||||
|
||||
@ -320,7 +324,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceA')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceB')).toBe(true);
|
||||
});
|
||||
@ -348,7 +352,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceA')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceB')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceC')).toBe(true);
|
||||
@ -381,7 +385,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceA')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceB')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceC')).toBe(true);
|
||||
@ -407,7 +411,7 @@ runInEachFileSystem(() => {
|
||||
`
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceA')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceB')).toBe(true);
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceC')).toBe(false);
|
||||
@ -434,7 +438,7 @@ runInEachFileSystem(() => {
|
||||
`
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(getInjectableDecorators(index, analysis, 'ServiceA').length).toBe(1);
|
||||
expect(getInjectableDecorators(index, analysis, 'ServiceB').length).toBe(1);
|
||||
});
|
||||
@ -454,7 +458,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'ServiceA')).toBe(false);
|
||||
});
|
||||
|
||||
@ -481,7 +485,7 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
]);
|
||||
|
||||
const index = program.getSourceFile(SERVICE_FILENAME) !;
|
||||
const index = program.getSourceFile(SERVICE_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(true);
|
||||
});
|
||||
|
||||
@ -508,7 +512,7 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
]);
|
||||
|
||||
const index = program.getSourceFile(SERVICE_FILENAME) !;
|
||||
const index = program.getSourceFile(SERVICE_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(false);
|
||||
});
|
||||
|
||||
@ -527,7 +531,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(true);
|
||||
});
|
||||
|
||||
@ -546,7 +550,7 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
}]);
|
||||
|
||||
const index = program.getSourceFile(INDEX_FILENAME) !;
|
||||
const index = program.getSourceFile(INDEX_FILENAME)!;
|
||||
expect(hasInjectableDecorator(index, analysis, 'MyService')).toBe(false);
|
||||
});
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
import {AbsoluteFsPath, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
|
||||
import {absoluteFrom, AbsoluteFsPath, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
@ -34,7 +35,7 @@ runInEachFileSystem(() => {
|
||||
`
|
||||
}]);
|
||||
expect(errors).toEqual([]);
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME) !);
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME)!);
|
||||
expect(file).toBeUndefined();
|
||||
});
|
||||
|
||||
@ -56,7 +57,7 @@ runInEachFileSystem(() => {
|
||||
`
|
||||
}]);
|
||||
expect(errors).toEqual([]);
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME) !) !;
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME)!)!;
|
||||
expect(file.compiledClasses.find(c => c.name === 'DerivedClass')).toBeDefined();
|
||||
expect(file.compiledClasses.find(c => c.name === 'BaseClass')).toBeUndefined();
|
||||
});
|
||||
@ -81,15 +82,15 @@ runInEachFileSystem(() => {
|
||||
`
|
||||
}]);
|
||||
expect(errors).toEqual([]);
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME) !) !;
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME)!)!;
|
||||
expect(file.compiledClasses.find(c => c.name === 'DerivedClass')).toBeDefined();
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass') !;
|
||||
expect(baseClass.decorators !.length).toEqual(1);
|
||||
const decorator = baseClass.decorators ![0];
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass')!;
|
||||
expect(baseClass.decorators!.length).toEqual(1);
|
||||
const decorator = baseClass.decorators![0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier).toBeNull('The decorator must be synthesized');
|
||||
expect(decorator.import).toEqual({from: '@angular/core', name: 'Directive'});
|
||||
expect(decorator.args !.length).toEqual(0);
|
||||
expect(decorator.args!.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should not add a decorator to a base class that is already decorated', () => {
|
||||
@ -114,11 +115,11 @@ runInEachFileSystem(() => {
|
||||
`
|
||||
}]);
|
||||
expect(errors).toEqual([]);
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME) !) !;
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME)!)!;
|
||||
expect(file.compiledClasses.find(c => c.name === 'DerivedClass')).toBeDefined();
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass') !;
|
||||
expect(baseClass.decorators !.length).toEqual(1);
|
||||
const decorator = baseClass.decorators ![0];
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass')!;
|
||||
expect(baseClass.decorators!.length).toEqual(1);
|
||||
const decorator = baseClass.decorators![0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier).not.toBeNull('The decorator must not be synthesized');
|
||||
});
|
||||
@ -145,25 +146,25 @@ runInEachFileSystem(() => {
|
||||
`
|
||||
}]);
|
||||
expect(errors).toEqual([]);
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME) !) !;
|
||||
const file = analysis.get(program.getSourceFile(INDEX_FILENAME)!)!;
|
||||
expect(file.compiledClasses.find(c => c.name === 'DerivedClass')).toBeDefined();
|
||||
expect(file.compiledClasses.find(c => c.name === 'RealBaseClass')).toBeUndefined();
|
||||
|
||||
const intermediateClass = file.compiledClasses.find(c => c.name === 'IntermediateClass') !;
|
||||
expect(intermediateClass.decorators !.length).toEqual(1);
|
||||
const intermediateDecorator = intermediateClass.decorators ![0];
|
||||
const intermediateClass = file.compiledClasses.find(c => c.name === 'IntermediateClass')!;
|
||||
expect(intermediateClass.decorators!.length).toEqual(1);
|
||||
const intermediateDecorator = intermediateClass.decorators![0];
|
||||
expect(intermediateDecorator.name).toEqual('Directive');
|
||||
expect(intermediateDecorator.identifier).toBeNull('The decorator must be synthesized');
|
||||
expect(intermediateDecorator.import).toEqual({from: '@angular/core', name: 'Directive'});
|
||||
expect(intermediateDecorator.args !.length).toEqual(0);
|
||||
expect(intermediateDecorator.args!.length).toEqual(0);
|
||||
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass') !;
|
||||
expect(baseClass.decorators !.length).toEqual(1);
|
||||
const baseDecorator = baseClass.decorators ![0];
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass')!;
|
||||
expect(baseClass.decorators!.length).toEqual(1);
|
||||
const baseDecorator = baseClass.decorators![0];
|
||||
expect(baseDecorator.name).toEqual('Directive');
|
||||
expect(baseDecorator.identifier).toBeNull('The decorator must be synthesized');
|
||||
expect(baseDecorator.import).toEqual({from: '@angular/core', name: 'Directive'});
|
||||
expect(baseDecorator.args !.length).toEqual(0);
|
||||
expect(baseDecorator.args!.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should handle the base class being in a different file (same package) as the derived class',
|
||||
@ -195,14 +196,14 @@ runInEachFileSystem(() => {
|
||||
}
|
||||
]);
|
||||
expect(errors).toEqual([]);
|
||||
const file = analysis.get(program.getSourceFile(BASE_FILENAME) !) !;
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass') !;
|
||||
expect(baseClass.decorators !.length).toEqual(1);
|
||||
const decorator = baseClass.decorators ![0];
|
||||
const file = analysis.get(program.getSourceFile(BASE_FILENAME)!)!;
|
||||
const baseClass = file.compiledClasses.find(c => c.name === 'BaseClass')!;
|
||||
expect(baseClass.decorators!.length).toEqual(1);
|
||||
const decorator = baseClass.decorators![0];
|
||||
expect(decorator.name).toEqual('Directive');
|
||||
expect(decorator.identifier).toBeNull('The decorator must be synthesized');
|
||||
expect(decorator.import).toEqual({from: '@angular/core', name: 'Directive'});
|
||||
expect(decorator.args !.length).toEqual(0);
|
||||
expect(decorator.args!.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should skip the base class if it is in a different package from the derived class', () => {
|
||||
|
@ -8,7 +8,7 @@
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NGCC_VERSION, cleanPackageJson, hasBeenProcessed, markAsProcessed, needsCleaning} from '../../src/packages/build_marker';
|
||||
import {cleanPackageJson, hasBeenProcessed, markAsProcessed, needsCleaning, NGCC_VERSION} from '../../src/packages/build_marker';
|
||||
import {EntryPointPackageJson} from '../../src/packages/entry_point';
|
||||
import {DirectPackageJsonUpdater} from '../../src/writing/package_json_updater';
|
||||
|
||||
@ -192,8 +192,9 @@ runInEachFileSystem(() => {
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
it('should return false if no markers exist',
|
||||
() => { expect(hasBeenProcessed({name: 'test'}, 'module')).toBe(false); });
|
||||
it('should return false if no markers exist', () => {
|
||||
expect(hasBeenProcessed({name: 'test'}, 'module')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('needsCleaning()', () => {
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
import {createHash} from 'crypto';
|
||||
|
||||
import {FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DEFAULT_NGCC_CONFIG, NgccConfiguration} from '../../src/packages/configuration';
|
||||
@ -27,8 +27,8 @@ runInEachFileSystem(() => {
|
||||
it('should error if a project level config file is badly formatted', () => {
|
||||
loadTestFiles([{name: _Abs('/project-1/ngcc.config.js'), contents: `bad js code`}]);
|
||||
expect(() => new NgccConfiguration(fs, _Abs('/project-1')))
|
||||
.toThrowError(
|
||||
`Invalid project configuration file at "${_Abs('/project-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
.toThrowError(`Invalid project configuration file at "${
|
||||
_Abs('/project-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -50,8 +50,8 @@ runInEachFileSystem(() => {
|
||||
};`
|
||||
}]);
|
||||
const project1Conf = new NgccConfiguration(fs, project1);
|
||||
const expectedProject1Config =
|
||||
`{"packages":{"${project1Package1}":[{"entryPoints":{"${project1Package1EntryPoint1}":{}},"versionRange":"*"}]}}`;
|
||||
const expectedProject1Config = `{"packages":{"${project1Package1}":[{"entryPoints":{"${
|
||||
project1Package1EntryPoint1}":{}},"versionRange":"*"}]}}`;
|
||||
expect(project1Conf.hash)
|
||||
.toEqual(createHash('md5').update(expectedProject1Config).digest('hex'));
|
||||
|
||||
@ -71,8 +71,8 @@ runInEachFileSystem(() => {
|
||||
};`
|
||||
}]);
|
||||
const project2Conf = new NgccConfiguration(fs, project2);
|
||||
const expectedProject2Config =
|
||||
`{"packages":{"${project2Package1}":[{"entryPoints":{"${project2Package1EntryPoint1}":{"ignore":true}},"versionRange":"*"}]}}`;
|
||||
const expectedProject2Config = `{"packages":{"${project2Package1}":[{"entryPoints":{"${
|
||||
project2Package1EntryPoint1}":{"ignore":true}},"versionRange":"*"}]}}`;
|
||||
expect(project2Conf.hash)
|
||||
.toEqual(createHash('md5').update(expectedProject2Config).digest('hex'));
|
||||
});
|
||||
@ -136,8 +136,9 @@ runInEachFileSystem(() => {
|
||||
}]);
|
||||
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
|
||||
expect(() => configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0'))
|
||||
.toThrowError(
|
||||
`Invalid package configuration file at "${_Abs('/project-1/node_modules/package-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
.toThrowError(`Invalid package configuration file at "${
|
||||
_Abs(
|
||||
'/project-1/node_modules/package-1/ngcc.config.js')}": Unexpected identifier`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -243,7 +244,7 @@ runInEachFileSystem(() => {
|
||||
]);
|
||||
|
||||
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
|
||||
const getConfig = (packageName: string, version: string | null) =>
|
||||
const getConfig = (packageName: string, version: string|null) =>
|
||||
configuration.getConfig(_Abs(`/project-1/node_modules/${packageName}`), version);
|
||||
|
||||
// Default version range: *
|
||||
@ -343,7 +344,6 @@ runInEachFileSystem(() => {
|
||||
versionRange: '*',
|
||||
entryPoints: {[_Abs('/project-1/node_modules/@angular/common')]: {}}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should override package level config with project level config per package', () => {
|
||||
@ -412,8 +412,7 @@ runInEachFileSystem(() => {
|
||||
configuration.getConfig(_Abs('/project-1/node_modules/package-1'), '1.0.0');
|
||||
expect(config).toEqual({
|
||||
versionRange: '*',
|
||||
entryPoints:
|
||||
{[_Abs('/project-1/node_modules/package-1/default-level-entry-point')]: {}}
|
||||
entryPoints: {[_Abs('/project-1/node_modules/package-1/default-level-entry-point')]: {}}
|
||||
});
|
||||
});
|
||||
|
||||
@ -427,8 +426,7 @@ runInEachFileSystem(() => {
|
||||
// merge entry-points.
|
||||
expect(config).toEqual({
|
||||
versionRange: '1.0.0',
|
||||
entryPoints:
|
||||
{[_Abs('/project-1/node_modules/package-1/package-level-entry-point')]: {}}
|
||||
entryPoints: {[_Abs('/project-1/node_modules/package-1/package-level-entry-point')]: {}}
|
||||
});
|
||||
});
|
||||
|
||||
@ -465,8 +463,7 @@ runInEachFileSystem(() => {
|
||||
// merge entry-points.
|
||||
expect(config).toEqual({
|
||||
versionRange: '*',
|
||||
entryPoints:
|
||||
{[_Abs('/project-1/node_modules/package-1/project-level-entry-point')]: {}}
|
||||
entryPoints: {[_Abs('/project-1/node_modules/package-1/project-level-entry-point')]: {}}
|
||||
});
|
||||
});
|
||||
|
||||
@ -490,7 +487,7 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
|
||||
const getConfig = (packageName: string, version: string | null) =>
|
||||
const getConfig = (packageName: string, version: string|null) =>
|
||||
configuration.getConfig(_Abs(`/project-1/node_modules/${packageName}`), version);
|
||||
|
||||
// Default version range: *
|
||||
|
@ -13,7 +13,6 @@ import {makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('entry point bundle', () => {
|
||||
|
||||
function setupMockFileSystem(): void {
|
||||
const _ = absoluteFrom;
|
||||
loadTestFiles([
|
||||
@ -196,7 +195,7 @@ runInEachFileSystem(() => {
|
||||
'/node_modules/other/index.d.ts',
|
||||
].map(p => absoluteFrom(p).toString())));
|
||||
|
||||
expect(esm5bundle.dts !.program.getSourceFiles().map(sf => sf.fileName))
|
||||
expect(esm5bundle.dts!.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.toEqual(jasmine.arrayWithExactContents([
|
||||
// All modules in the dts program should be declaration files
|
||||
'/node_modules/test/index.d.ts',
|
||||
@ -231,7 +230,7 @@ runInEachFileSystem(() => {
|
||||
/* pathMappings */ undefined, /* mirrorDtsFromSrc */ true);
|
||||
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.toContain(absoluteFrom('/node_modules/test/internal.js'));
|
||||
expect(esm5bundle.dts !.program.getSourceFiles().map(sf => sf.fileName))
|
||||
expect(esm5bundle.dts!.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.toContain(absoluteFrom('/node_modules/test/internal.d.ts'));
|
||||
});
|
||||
|
||||
@ -253,7 +252,7 @@ runInEachFileSystem(() => {
|
||||
/* pathMappings */ undefined, /* mirrorDtsFromSrc */ true);
|
||||
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.toContain(absoluteFrom('/node_modules/internal/esm2015/src/internal.js'));
|
||||
expect(esm5bundle.dts !.program.getSourceFiles().map(sf => sf.fileName))
|
||||
expect(esm5bundle.dts!.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.toContain(absoluteFrom('/node_modules/internal/src/internal.d.ts'));
|
||||
});
|
||||
|
||||
@ -275,7 +274,7 @@ runInEachFileSystem(() => {
|
||||
/* pathMappings */ undefined, /* mirrorDtsFromSrc */ false);
|
||||
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.toContain(absoluteFrom('/node_modules/test/internal.js'));
|
||||
expect(esm5bundle.dts !.program.getSourceFiles().map(sf => sf.fileName))
|
||||
expect(esm5bundle.dts!.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.not.toContain(absoluteFrom('/node_modules/test/internal.d.ts'));
|
||||
});
|
||||
});
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
import {createHash} from 'crypto';
|
||||
|
||||
import {FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NGCC_VERSION} from '../../src/packages/build_marker';
|
||||
@ -135,13 +135,15 @@ runInEachFileSystem(() => {
|
||||
_Abs('/project/node_modules/__ngcc_entry_points__.json'), JSON.stringify(manifestFile));
|
||||
const entryPoints = manifest.readEntryPointsUsingManifest(_Abs('/project/node_modules'));
|
||||
expect(entryPoints).toEqual([{
|
||||
name: 'some_package/valid_entry_point', packageJson: jasmine.any(Object),
|
||||
package: _Abs('/project/node_modules/some_package'),
|
||||
path: _Abs('/project/node_modules/some_package/valid_entry_point'),
|
||||
typings: _Abs(
|
||||
'/project/node_modules/some_package/valid_entry_point/valid_entry_point.d.ts'),
|
||||
compiledByAngular: true, ignoreMissingDependencies: false,
|
||||
generateDeepReexports: false,
|
||||
name: 'some_package/valid_entry_point',
|
||||
packageJson: jasmine.any(Object),
|
||||
package: _Abs('/project/node_modules/some_package'),
|
||||
path: _Abs('/project/node_modules/some_package/valid_entry_point'),
|
||||
typings:
|
||||
_Abs('/project/node_modules/some_package/valid_entry_point/valid_entry_point.d.ts'),
|
||||
compiledByAngular: true,
|
||||
ignoreMissingDependencies: false,
|
||||
generateDeepReexports: false,
|
||||
} as any]);
|
||||
});
|
||||
|
||||
|
@ -6,11 +6,11 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||
import {EntryPoint, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat, getEntryPointInfo} from '../../src/packages/entry_point';
|
||||
import {EntryPoint, getEntryPointFormat, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, SUPPORTED_FORMAT_PROPERTIES} from '../../src/packages/entry_point';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
@ -69,8 +69,7 @@ runInEachFileSystem(() => {
|
||||
]);
|
||||
const config = new NgccConfiguration(fs, _('/project'));
|
||||
spyOn(config, 'getConfig').and.returnValue({
|
||||
entryPoints:
|
||||
{[_('/project/node_modules/some_package/valid_entry_point')]: {ignore: true}}
|
||||
entryPoints: {[_('/project/node_modules/some_package/valid_entry_point')]: {ignore: true}}
|
||||
});
|
||||
const entryPoint = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
@ -102,8 +101,9 @@ runInEachFileSystem(() => {
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
_('/project/node_modules/some_package/valid_entry_point'));
|
||||
const overriddenPackageJson = {
|
||||
...loadPackageJson(fs, '/project/node_modules/some_package/valid_entry_point'),
|
||||
...override};
|
||||
...loadPackageJson(fs, '/project/node_modules/some_package/valid_entry_point'),
|
||||
...override
|
||||
};
|
||||
expect(entryPoint).toEqual({
|
||||
name: 'some_package/valid_entry_point',
|
||||
package: SOME_PACKAGE,
|
||||
@ -145,8 +145,7 @@ runInEachFileSystem(() => {
|
||||
const override =
|
||||
JSON.parse(createPackageJson('missing_package_json', {excludes: ['name']}));
|
||||
spyOn(config, 'getConfig').and.returnValue({
|
||||
entryPoints:
|
||||
{[_('/project/node_modules/some_package/missing_package_json')]: {override}}
|
||||
entryPoints: {[_('/project/node_modules/some_package/missing_package_json')]: {override}}
|
||||
});
|
||||
const entryPoint = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
@ -211,37 +210,38 @@ runInEachFileSystem(() => {
|
||||
// Let's give 'module' a specific path, otherwise compute it based on the property.
|
||||
const typingsPath = prop === 'module' ? 'index' : `${prop}/missing_typings`;
|
||||
|
||||
it(`should return an object if it can guess the typings path from the "${prop}" field`, () => {
|
||||
loadTestFiles([
|
||||
{
|
||||
name: _('/project/node_modules/some_package/missing_typings/package.json'),
|
||||
contents: createPackageJson('missing_typings', {excludes: ['typings']}),
|
||||
},
|
||||
{
|
||||
name: _(
|
||||
`/project/node_modules/some_package/missing_typings/${typingsPath}.metadata.json`),
|
||||
contents: 'some meta data',
|
||||
},
|
||||
{
|
||||
name: _(`/project/node_modules/some_package/missing_typings/${typingsPath}.d.ts`),
|
||||
contents: '// some typings file',
|
||||
},
|
||||
]);
|
||||
const config = new NgccConfiguration(fs, _('/project'));
|
||||
const entryPoint = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
_('/project/node_modules/some_package/missing_typings'));
|
||||
expect(entryPoint).toEqual({
|
||||
name: 'some_package/missing_typings',
|
||||
package: SOME_PACKAGE,
|
||||
path: _('/project/node_modules/some_package/missing_typings'),
|
||||
typings: _(`/project/node_modules/some_package/missing_typings/${typingsPath}.d.ts`),
|
||||
packageJson: loadPackageJson(fs, '/project/node_modules/some_package/missing_typings'),
|
||||
compiledByAngular: true,
|
||||
ignoreMissingDependencies: false,
|
||||
generateDeepReexports: false,
|
||||
});
|
||||
});
|
||||
it(`should return an object if it can guess the typings path from the "${prop}" field`,
|
||||
() => {
|
||||
loadTestFiles([
|
||||
{
|
||||
name: _('/project/node_modules/some_package/missing_typings/package.json'),
|
||||
contents: createPackageJson('missing_typings', {excludes: ['typings']}),
|
||||
},
|
||||
{
|
||||
name: _(`/project/node_modules/some_package/missing_typings/${
|
||||
typingsPath}.metadata.json`),
|
||||
contents: 'some meta data',
|
||||
},
|
||||
{
|
||||
name: _(`/project/node_modules/some_package/missing_typings/${typingsPath}.d.ts`),
|
||||
contents: '// some typings file',
|
||||
},
|
||||
]);
|
||||
const config = new NgccConfiguration(fs, _('/project'));
|
||||
const entryPoint = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), SOME_PACKAGE,
|
||||
_('/project/node_modules/some_package/missing_typings'));
|
||||
expect(entryPoint).toEqual({
|
||||
name: 'some_package/missing_typings',
|
||||
package: SOME_PACKAGE,
|
||||
path: _('/project/node_modules/some_package/missing_typings'),
|
||||
typings: _(`/project/node_modules/some_package/missing_typings/${typingsPath}.d.ts`),
|
||||
packageJson: loadPackageJson(fs, '/project/node_modules/some_package/missing_typings'),
|
||||
compiledByAngular: true,
|
||||
ignoreMissingDependencies: false,
|
||||
generateDeepReexports: false,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('should return an object with `compiledByAngular` set to false if there is no metadata.json file next to the typing file',
|
||||
@ -401,23 +401,29 @@ runInEachFileSystem(() => {
|
||||
entryPoint = result;
|
||||
});
|
||||
|
||||
it('should return `esm2015` format for `fesm2015` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'fesm2015')).toBe('esm2015'); });
|
||||
it('should return `esm2015` format for `fesm2015` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'fesm2015')).toBe('esm2015');
|
||||
});
|
||||
|
||||
it('should return `esm5` format for `fesm5` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'fesm5')).toBe('esm5'); });
|
||||
it('should return `esm5` format for `fesm5` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'fesm5')).toBe('esm5');
|
||||
});
|
||||
|
||||
it('should return `esm2015` format for `es2015` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'es2015')).toBe('esm2015'); });
|
||||
it('should return `esm2015` format for `es2015` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'es2015')).toBe('esm2015');
|
||||
});
|
||||
|
||||
it('should return `esm2015` format for `esm2015` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'esm2015')).toBe('esm2015'); });
|
||||
it('should return `esm2015` format for `esm2015` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'esm2015')).toBe('esm2015');
|
||||
});
|
||||
|
||||
it('should return `esm5` format for `esm5` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'esm5')).toBe('esm5'); });
|
||||
it('should return `esm5` format for `esm5` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'esm5')).toBe('esm5');
|
||||
});
|
||||
|
||||
it('should return `esm5` format for `module` property',
|
||||
() => { expect(getEntryPointFormat(fs, entryPoint, 'module')).toBe('esm5'); });
|
||||
it('should return `esm5` format for `module` property', () => {
|
||||
expect(getEntryPointFormat(fs, entryPoint, 'module')).toBe('esm5');
|
||||
});
|
||||
|
||||
it('should return `umd` for `main` if the file contains a UMD wrapper function', () => {
|
||||
loadTestFiles([{
|
||||
|
@ -8,19 +8,20 @@
|
||||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, absoluteFromSourceFile, AbsoluteFsPath, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {AbsoluteFsPath, getFileSystem, getSourceFileOrError, absoluteFrom, absoluteFromSourceFile} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {CommonJsReflectionHost} from '../../src/host/commonjs_host';
|
||||
import {CommonJsRenderingFormatter} from '../../src/rendering/commonjs_rendering_formatter';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('CommonJsRenderingFormatter', () => {
|
||||
@ -273,7 +274,7 @@ var A = (function() {`);
|
||||
const file = getSourceFileOrError(program, _('/node_modules/test-package/some/file.js'));
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
renderer.rewriteSwitchableDeclarations(
|
||||
output, file, switchMarkerAnalyses.get(sourceFile) !.declarations);
|
||||
output, file, switchMarkerAnalyses.get(sourceFile)!.declarations);
|
||||
expect(output.toString())
|
||||
.not.toContain(`var compileNgModuleFactory = compileNgModuleFactory__PRE_R3__;`);
|
||||
expect(output.toString())
|
||||
@ -295,7 +296,7 @@ var A = (function() {`);
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString()).toContain(`
|
||||
A.prototype.ngDoCheck = function() {
|
||||
@ -314,15 +315,16 @@ SOME DEFINITION TEXT
|
||||
program, absoluteFromSourceFile(sourceFile), 'NoIife', ts.isFunctionDeclaration);
|
||||
const mockNoIifeClass: any = {declaration: noIifeDeclaration, name: 'NoIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockNoIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class declaration is not inside an IIFE: NoIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
.toThrowError(`Compiled class declaration is not inside an IIFE: NoIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
|
||||
const badIifeDeclaration = getDeclaration(
|
||||
program, absoluteFromSourceFile(sourceFile), 'BadIife', ts.isVariableDeclaration);
|
||||
const mockBadIifeClass: any = {declaration: badIifeDeclaration, name: 'BadIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockBadIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -347,8 +349,8 @@ SOME DEFINITION TEXT
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(program);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
expect(output.toString())
|
||||
.toContain(
|
||||
@ -364,8 +366,8 @@ SOME DEFINITION TEXT
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(program);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITIONS');
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
const definitionsPosition = output.toString().indexOf('SOME DEFINITIONS');
|
||||
@ -377,16 +379,15 @@ SOME DEFINITION TEXT
|
||||
});
|
||||
|
||||
describe('removeDecorators', () => {
|
||||
|
||||
it('should delete the decorator (and following comma) that was matched in the analysis',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.not.toContain(`{ type: core.Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -404,10 +405,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.toContain(`{ type: core.Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -425,10 +426,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString())
|
||||
@ -441,7 +442,6 @@ SOME DEFINITION TEXT
|
||||
.toContain(`function C() {}\nSOME DEFINITION TEXT\n return C;`);
|
||||
expect(output.toString()).not.toContain(`C.decorators`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('[__decorate declarations]', () => {
|
||||
@ -450,10 +450,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).not.toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -467,10 +467,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -485,10 +485,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
|
@ -7,21 +7,22 @@
|
||||
*/
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {Reexport} from '../../../src/ngtsc/imports';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {Import, ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ModuleWithProvidersAnalyzer, ModuleWithProvidersInfo} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {PrivateDeclarationsAnalyzer, ExportInfo} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ExportInfo, PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {RenderingFormatter, RedundantDecoratorMap} from '../../src/rendering/rendering_formatter';
|
||||
import {DtsRenderer} from '../../src/rendering/dts_renderer';
|
||||
import {RedundantDecoratorMap, RenderingFormatter} from '../../src/rendering/rendering_formatter';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle, getRootFiles} from '../helpers/utils';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
class TestRenderingFormatter implements RenderingFormatter {
|
||||
addImports(output: MagicString, imports: Import[], sf: ts.SourceFile) {
|
||||
@ -53,7 +54,9 @@ class TestRenderingFormatter implements RenderingFormatter {
|
||||
importManager: ImportManager): void {
|
||||
output.prepend('\n// ADD MODUlE WITH PROVIDERS PARAMS\n');
|
||||
}
|
||||
printStatement(): string { return 'IGNORED'; }
|
||||
printStatement(): string {
|
||||
return 'IGNORED';
|
||||
}
|
||||
}
|
||||
|
||||
function createTestRenderer(
|
||||
@ -92,12 +95,14 @@ function createTestRenderer(
|
||||
|
||||
const renderer = new DtsRenderer(testFormatter, fs, logger, host, bundle);
|
||||
|
||||
return {renderer,
|
||||
testFormatter,
|
||||
decorationAnalyses,
|
||||
moduleWithProvidersAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
bundle};
|
||||
return {
|
||||
renderer,
|
||||
testFormatter,
|
||||
decorationAnalyses,
|
||||
moduleWithProvidersAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
bundle
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
@ -120,35 +125,44 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
it('should render extract types into typings files', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||
|
||||
const typingsFile =
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts')) !;
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts'))!;
|
||||
expect(typingsFile.contents)
|
||||
.toContain(
|
||||
'foo(x: number): number;\n static ɵfac: ɵngcc0.ɵɵFactoryDef<A, never>;\n static ɵdir: ɵngcc0.ɵɵDirectiveDefWithMeta');
|
||||
});
|
||||
|
||||
it('should render imports into typings files', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||
|
||||
const typingsFile =
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts')) !;
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts'))!;
|
||||
expect(typingsFile.contents).toContain(`\n// ADD IMPORTS\n`);
|
||||
});
|
||||
|
||||
it('should render exports into typings files', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
|
||||
// Add a mock export to trigger export rendering
|
||||
privateDeclarationsAnalyses.push({
|
||||
@ -161,20 +175,23 @@ runInEachFileSystem(() => {
|
||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||
|
||||
const typingsFile =
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts')) !;
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts'))!;
|
||||
expect(typingsFile.contents).toContain(`\n// ADD EXPORTS\n`);
|
||||
});
|
||||
|
||||
it('should render ModuleWithProviders type params', () => {
|
||||
const {renderer, decorationAnalyses, privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses} =
|
||||
createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
moduleWithProvidersAnalyses
|
||||
} = createTestRenderer('test-package', [INPUT_PROGRAM], [INPUT_DTS_PROGRAM]);
|
||||
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||
|
||||
const typingsFile =
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts')) !;
|
||||
result.find(f => f.path === _('/node_modules/test-package/typings/file.d.ts'))!;
|
||||
expect(typingsFile.contents).toContain(`\n// ADD MODUlE WITH PROVIDERS PARAMS\n`);
|
||||
});
|
||||
});
|
||||
|
@ -8,20 +8,21 @@
|
||||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, absoluteFromSourceFile, AbsoluteFsPath, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {AbsoluteFsPath, absoluteFrom, absoluteFromSourceFile, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {IMPORT_PREFIX} from '../../src/constants';
|
||||
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
||||
import {Esm5RenderingFormatter} from '../../src/rendering/esm5_rendering_formatter';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
function setup(file: {name: AbsoluteFsPath, contents: string}) {
|
||||
loadTestFiles([file]);
|
||||
@ -39,13 +40,16 @@ function setup(file: {name: AbsoluteFsPath, contents: string}) {
|
||||
return {
|
||||
host,
|
||||
program: bundle.src.program,
|
||||
sourceFile: bundle.src.file, renderer, decorationAnalyses, switchMarkerAnalyses, importManager
|
||||
sourceFile: bundle.src.file,
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
importManager
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('Esm5RenderingFormatter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let PROGRAM: TestFile;
|
||||
let PROGRAM_DECORATE_HELPER: TestFile;
|
||||
@ -276,7 +280,7 @@ var A = (function() {`);
|
||||
const file = getSourceFileOrError(program, _('/node_modules/test-package/some/file.js'));
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
renderer.rewriteSwitchableDeclarations(
|
||||
output, file, switchMarkerAnalyses.get(sourceFile) !.declarations);
|
||||
output, file, switchMarkerAnalyses.get(sourceFile)!.declarations);
|
||||
expect(output.toString())
|
||||
.not.toContain(`var compileNgModuleFactory = compileNgModuleFactory__PRE_R3__;`);
|
||||
expect(output.toString())
|
||||
@ -298,7 +302,7 @@ var A = (function() {`);
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString()).toContain(`
|
||||
A.prototype.ngDoCheck = function() {
|
||||
@ -317,15 +321,16 @@ SOME DEFINITION TEXT
|
||||
program, absoluteFromSourceFile(sourceFile), 'NoIife', ts.isFunctionDeclaration);
|
||||
const mockNoIifeClass: any = {declaration: noIifeDeclaration, name: 'NoIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockNoIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class declaration is not inside an IIFE: NoIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
.toThrowError(`Compiled class declaration is not inside an IIFE: NoIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
|
||||
const badIifeDeclaration = getDeclaration(
|
||||
program, absoluteFromSourceFile(sourceFile), 'BadIife', ts.isVariableDeclaration);
|
||||
const mockBadIifeClass: any = {declaration: badIifeDeclaration, name: 'BadIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockBadIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -350,8 +355,8 @@ SOME DEFINITION TEXT
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(program);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
expect(output.toString())
|
||||
.toContain(
|
||||
@ -367,8 +372,8 @@ SOME DEFINITION TEXT
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(program);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITIONS');
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
const definitionsPosition = output.toString().indexOf('SOME DEFINITIONS');
|
||||
@ -381,16 +386,15 @@ SOME DEFINITION TEXT
|
||||
|
||||
|
||||
describe('removeDecorators', () => {
|
||||
|
||||
it('should delete the decorator (and following comma) that was matched in the analysis',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.not.toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -406,10 +410,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
|
||||
expect(output.toString()).toContain(`{ type: OtherA }`);
|
||||
@ -425,10 +429,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString()).toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -447,10 +451,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).not.toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -464,10 +468,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -481,10 +485,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -500,10 +504,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'E') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'E')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).not.toContain(`Directive({ selector: '[e]' })`);
|
||||
expect(output.toString()).not.toContain(`E = tslib_1.__decorate([`);
|
||||
@ -515,10 +519,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'F') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'F')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).not.toContain(`Directive({ selector: '[f]' })`);
|
||||
expect(output.toString()).not.toContain(`F = tslib_1.__decorate([`);
|
||||
|
@ -8,20 +8,21 @@
|
||||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
|
||||
import {absoluteFrom, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {loadTestFiles, loadFakeCore} from '../../../test/helpers';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadFakeCore, loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {ModuleWithProvidersAnalyzer} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {IMPORT_PREFIX} from '../../src/constants';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {EsmRenderingFormatter} from '../../src/rendering/esm_rendering_formatter';
|
||||
import {makeTestEntryPointBundle, getRootFiles} from '../helpers/utils';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {ModuleWithProvidersAnalyzer} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
function setup(files: TestFile[], dtsFiles?: TestFile[]) {
|
||||
const fs = getFileSystem();
|
||||
@ -32,7 +33,7 @@ function setup(files: TestFile[], dtsFiles?: TestFile[]) {
|
||||
}
|
||||
const logger = new MockLogger();
|
||||
const bundle = makeTestEntryPointBundle(
|
||||
'test-package', 'esm2015', false, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles)) !;
|
||||
'test-package', 'esm2015', false, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles))!;
|
||||
const host = new Esm2015ReflectionHost(logger, false, bundle.src, bundle.dts);
|
||||
const referencesRegistry = new NgccReferencesRegistry(host);
|
||||
const decorationAnalyses =
|
||||
@ -45,13 +46,16 @@ function setup(files: TestFile[], dtsFiles?: TestFile[]) {
|
||||
host,
|
||||
bundle,
|
||||
program: bundle.src.program,
|
||||
sourceFile: bundle.src.file, renderer, decorationAnalyses, switchMarkerAnalyses, importManager,
|
||||
sourceFile: bundle.src.file,
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
importManager,
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('EsmRenderingFormatter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let PROGRAM: TestFile;
|
||||
|
||||
@ -195,7 +199,7 @@ export class A {`);
|
||||
const file = getSourceFileOrError(program, _('/node_modules/test-package/some/file.js'));
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
renderer.rewriteSwitchableDeclarations(
|
||||
output, file, switchMarkerAnalyses.get(sourceFile) !.declarations);
|
||||
output, file, switchMarkerAnalyses.get(sourceFile)!.declarations);
|
||||
expect(output.toString())
|
||||
.not.toContain(`let compileNgModuleFactory = compileNgModuleFactory__PRE_R3__;`);
|
||||
expect(output.toString())
|
||||
@ -216,7 +220,7 @@ export class A {`);
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup([PROGRAM]);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString()).toContain(`
|
||||
export class A {}
|
||||
@ -230,7 +234,7 @@ A.decorators = [
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup([PROGRAM]);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString()).toContain(`
|
||||
let C = C_1 = class C {};
|
||||
@ -259,8 +263,8 @@ C.decorators = [
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup([program]);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
expect(output.toString())
|
||||
.toContain(
|
||||
@ -275,8 +279,8 @@ C.decorators = [
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup([program]);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITIONS');
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
const definitionsPosition = output.toString().indexOf('SOME DEFINITIONS');
|
||||
@ -294,10 +298,10 @@ C.decorators = [
|
||||
const {decorationAnalyses, sourceFile, renderer} = setup([PROGRAM]);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.not.toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -315,10 +319,10 @@ C.decorators = [
|
||||
const {decorationAnalyses, sourceFile, renderer} = setup([PROGRAM]);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -343,10 +347,10 @@ A.decorators = [
|
||||
const {decorationAnalyses, sourceFile, renderer} = setup([file]);
|
||||
const output = new MagicString(text);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
// The decorator should have been removed correctly.
|
||||
expect(output.toString()).toContain('A.decorators = [ { type: OtherA }');
|
||||
@ -358,10 +362,10 @@ A.decorators = [
|
||||
const {decorationAnalyses, sourceFile, renderer} = setup([PROGRAM]);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -424,10 +428,10 @@ export { D };
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup([PROGRAM_DECORATE_HELPER]);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).not.toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -441,10 +445,10 @@ export { D };
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup([PROGRAM_DECORATE_HELPER]);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -459,10 +463,10 @@ export { D };
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup([PROGRAM_DECORATE_HELPER]);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -573,8 +577,8 @@ export { D };
|
||||
new ModuleWithProvidersAnalyzer(host, referencesRegistry, true)
|
||||
.analyzeProgram(bundle.src.program);
|
||||
const typingsFile = getSourceFileOrError(
|
||||
bundle.dts !.program, _('/node_modules/test-package/typings/index.d.ts'));
|
||||
const moduleWithProvidersInfo = moduleWithProvidersAnalyses.get(typingsFile) !;
|
||||
bundle.dts!.program, _('/node_modules/test-package/typings/index.d.ts'));
|
||||
const moduleWithProvidersInfo = moduleWithProvidersAnalyses.get(typingsFile)!;
|
||||
|
||||
const output = new MagicString(MODULE_WITH_PROVIDERS_DTS_PROGRAM[0].contents);
|
||||
const importManager = new ImportManager(new NoopImportRewriter(), 'i');
|
||||
@ -610,8 +614,8 @@ export { D };
|
||||
new ModuleWithProvidersAnalyzer(host, referencesRegistry, true)
|
||||
.analyzeProgram(bundle.src.program);
|
||||
const typingsFile = getSourceFileOrError(
|
||||
bundle.dts !.program, _('/node_modules/test-package/typings/module.d.ts'));
|
||||
const moduleWithProvidersInfo = moduleWithProvidersAnalyses.get(typingsFile) !;
|
||||
bundle.dts!.program, _('/node_modules/test-package/typings/module.d.ts'));
|
||||
const moduleWithProvidersInfo = moduleWithProvidersAnalyses.get(typingsFile)!;
|
||||
|
||||
const output = new MagicString(MODULE_WITH_PROVIDERS_DTS_PROGRAM[1].contents);
|
||||
const importManager = new ImportManager(new NoopImportRewriter(), 'i');
|
||||
|
@ -6,27 +6,28 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {Statement} from '@angular/compiler';
|
||||
import {SourceMapMappings, encode} from 'sourcemap-codec';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {fromObject, generateMapFileComment, SourceMapConverter} from 'convert-source-map';
|
||||
import MagicString from 'magic-string';
|
||||
import {encode, SourceMapMappings} from 'sourcemap-codec';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NOOP_DEFAULT_IMPORT_RECORDER, Reexport} from '../../../src/ngtsc/imports';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {Import, ImportManager, translateStatement} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ModuleWithProvidersInfo} from '../../src/analysis/module_with_providers_analyzer';
|
||||
import {PrivateDeclarationsAnalyzer, ExportInfo} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {ExportInfo, PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {CompiledClass} from '../../src/analysis/types';
|
||||
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
||||
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
|
||||
import {Renderer} from '../../src/rendering/renderer';
|
||||
import {RedundantDecoratorMap, RenderingFormatter} from '../../src/rendering/rendering_formatter';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {RenderingFormatter, RedundantDecoratorMap} from '../../src/rendering/rendering_formatter';
|
||||
import {makeTestEntryPointBundle, getRootFiles} from '../helpers/utils';
|
||||
import {getRootFiles, makeTestEntryPointBundle} from '../helpers/utils';
|
||||
|
||||
class TestRenderingFormatter implements RenderingFormatter {
|
||||
private printer = ts.createPrinter({newLine: ts.NewLineKind.LineFeed});
|
||||
@ -106,12 +107,14 @@ function createTestRenderer(
|
||||
|
||||
const renderer = new Renderer(host, testFormatter, fs, logger, bundle);
|
||||
|
||||
return {renderer,
|
||||
testFormatter,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
bundle};
|
||||
return {
|
||||
renderer,
|
||||
testFormatter,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
bundle
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
@ -227,8 +230,13 @@ runInEachFileSystem(() => {
|
||||
|
||||
|
||||
it('should render as JavaScript', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [COMPONENT_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [COMPONENT_PROGRAM]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
@ -253,8 +261,13 @@ A.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, v
|
||||
describe('calling RenderingFormatter methods', () => {
|
||||
it('should call addImports with the source code and info about the core Angular library.',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const result = renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addImportsSpy = testFormatter.addImports as jasmine.Spy;
|
||||
@ -266,8 +279,13 @@ A.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], decls: 1, v
|
||||
|
||||
it('should call addDefinitions with the source code, the analyzed class and the rendered definitions.',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
@ -284,8 +302,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
|
||||
it('should call addAdjacentStatements with the source code, the analyzed class and the rendered statements',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
@ -303,8 +326,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
|
||||
it('should call removeDecorators with the source code, a map of class decorators that have been analyzed',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const removeDecoratorsSpy = testFormatter.removeDecorators as jasmine.Spy;
|
||||
@ -326,8 +354,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
});
|
||||
|
||||
it('should render definitions as static fields', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
@ -337,8 +370,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
});
|
||||
|
||||
it('should render adjacent statements', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [NGMODULE_PROGRAM]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
@ -347,8 +385,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
});
|
||||
|
||||
it('should render directives using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
@ -379,8 +422,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
});
|
||||
|
||||
it('should render injectables using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
@ -411,8 +459,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
});
|
||||
|
||||
it('should render ng-modules using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
@ -448,8 +501,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
});
|
||||
|
||||
it('should render pipes using the inner class name if different from outer', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} =
|
||||
createTestRenderer(
|
||||
'test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
@ -479,9 +537,13 @@ A.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });`
|
||||
});
|
||||
|
||||
it('should render classes without decorators if class fields are decorated', () => {
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} =
|
||||
createTestRenderer('test-package', [{
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [{
|
||||
name: _('/node_modules/test-package/src/file.js'),
|
||||
contents: `
|
||||
import { Directive, ViewChild } from '@angular/core';
|
||||
@ -514,8 +576,13 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
||||
|
||||
it('should call renderImports after other abstract methods', () => {
|
||||
// This allows the other methods to add additional imports if necessary
|
||||
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const {
|
||||
renderer,
|
||||
decorationAnalyses,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('test-package', [JS_CONTENT]);
|
||||
const addExportsSpy = testFormatter.addExports as jasmine.Spy;
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
@ -537,8 +604,12 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
||||
name: JS_CONTENT.name,
|
||||
contents: JS_CONTENT.contents + '\n' + JS_CONTENT_MAP.toComment()
|
||||
}];
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses} = createTestRenderer('test-package', sourceFiles);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses
|
||||
} = createTestRenderer('test-package', sourceFiles);
|
||||
const [sourceFile, mapFile] = renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js'));
|
||||
@ -555,9 +626,12 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
||||
}];
|
||||
const mappingFiles: TestFile[] =
|
||||
[{name: _(JS_CONTENT.name + '.map'), contents: JS_CONTENT_MAP.toJSON()}];
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses} =
|
||||
createTestRenderer('test-package', sourceFiles, undefined, mappingFiles);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses
|
||||
} = createTestRenderer('test-package', sourceFiles, undefined, mappingFiles);
|
||||
const [sourceFile, mapFile] = renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
expect(sourceFile.path).toEqual(_('/node_modules/test-package/src/file.js'));
|
||||
@ -582,8 +656,13 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
||||
contents: `export const NgModule = () => null;`
|
||||
};
|
||||
// The package name of `@angular/core` indicates that we are compiling the core library.
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('@angular/core', [CORE_FILE, R3_SYMBOLS_FILE]);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('@angular/core', [CORE_FILE, R3_SYMBOLS_FILE]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
@ -602,8 +681,13 @@ UndecoratedBase.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: UndecoratedBase, vie
|
||||
export class MyModule {}\nMyModule.decorators = [\n { type: NgModule, args: [] }\n];\n`
|
||||
};
|
||||
|
||||
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||
testFormatter} = createTestRenderer('@angular/core', [CORE_FILE]);
|
||||
const {
|
||||
decorationAnalyses,
|
||||
renderer,
|
||||
switchMarkerAnalyses,
|
||||
privateDeclarationsAnalyses,
|
||||
testFormatter
|
||||
} = createTestRenderer('@angular/core', [CORE_FILE]);
|
||||
renderer.renderProgram(
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addAdjacentStatementsSpy = testFormatter.addAdjacentStatements as jasmine.Spy;
|
||||
|
@ -8,16 +8,17 @@
|
||||
import {DeclareVarStmt, LiteralExpr, StmtModifier} from '@angular/compiler';
|
||||
import MagicString from 'magic-string';
|
||||
import * as ts from 'typescript';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
|
||||
import {absoluteFrom, absoluteFromSourceFile, getFileSystem, getSourceFileOrError} from '../../../src/ngtsc/file_system';
|
||||
import {TestFile, runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing';
|
||||
import {NoopImportRewriter} from '../../../src/ngtsc/imports';
|
||||
import {getDeclaration} from '../../../src/ngtsc/testing';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
||||
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
||||
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
||||
import {UmdReflectionHost} from '../../src/host/umd_host';
|
||||
import {ImportManager} from '../../../src/ngtsc/translator';
|
||||
import {UmdRenderingFormatter} from '../../src/rendering/umd_rendering_formatter';
|
||||
import {MockLogger} from '../helpers/mock_logger';
|
||||
import {makeTestEntryPointBundle} from '../helpers/utils';
|
||||
@ -40,14 +41,15 @@ function setup(file: TestFile) {
|
||||
decorationAnalyses,
|
||||
host,
|
||||
importManager,
|
||||
program: src.program, renderer,
|
||||
sourceFile: src.file, switchMarkerAnalyses
|
||||
program: src.program,
|
||||
renderer,
|
||||
sourceFile: src.file,
|
||||
switchMarkerAnalyses
|
||||
};
|
||||
}
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('UmdRenderingFormatter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let PROGRAM: TestFile;
|
||||
let PROGRAM_DECORATE_HELPER: TestFile;
|
||||
@ -438,7 +440,7 @@ var A = (function() {`);
|
||||
const file = getSourceFileOrError(program, _('/node_modules/test-package/some/file.js'));
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
renderer.rewriteSwitchableDeclarations(
|
||||
output, file, switchMarkerAnalyses.get(sourceFile) !.declarations);
|
||||
output, file, switchMarkerAnalyses.get(sourceFile)!.declarations);
|
||||
expect(output.toString())
|
||||
.not.toContain(`var compileNgModuleFactory = compileNgModuleFactory__PRE_R3__;`);
|
||||
expect(output.toString())
|
||||
@ -460,7 +462,7 @@ var A = (function() {`);
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString()).toContain(`
|
||||
A.prototype.ngDoCheck = function() {
|
||||
@ -479,15 +481,16 @@ SOME DEFINITION TEXT
|
||||
program, absoluteFromSourceFile(sourceFile), 'NoIife', ts.isFunctionDeclaration);
|
||||
const mockNoIifeClass: any = {declaration: noIifeDeclaration, name: 'NoIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockNoIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class declaration is not inside an IIFE: NoIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
.toThrowError(`Compiled class declaration is not inside an IIFE: NoIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
|
||||
const badIifeDeclaration = getDeclaration(
|
||||
program, absoluteFromSourceFile(sourceFile), 'BadIife', ts.isVariableDeclaration);
|
||||
const mockBadIifeClass: any = {declaration: badIifeDeclaration, name: 'BadIife'};
|
||||
expect(() => renderer.addDefinitions(output, mockBadIifeClass, 'SOME DEFINITION TEXT'))
|
||||
.toThrowError(
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${_('/node_modules/test-package/some/file.js')}`);
|
||||
`Compiled class wrapper IIFE does not have a return statement: BadIife in ${
|
||||
_('/node_modules/test-package/some/file.js')}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -518,8 +521,8 @@ SOME DEFINITION TEXT
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(program);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
expect(output.toString())
|
||||
.toContain(
|
||||
@ -535,8 +538,8 @@ SOME DEFINITION TEXT
|
||||
const program = {name: _('/node_modules/test-package/some/file.js'), contents};
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(program);
|
||||
const output = new MagicString(contents);
|
||||
const compiledClass = decorationAnalyses.get(sourceFile) !.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective') !;
|
||||
const compiledClass = decorationAnalyses.get(sourceFile)!.compiledClasses.find(
|
||||
c => c.name === 'SomeDirective')!;
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITIONS');
|
||||
renderer.addAdjacentStatements(output, compiledClass, 'SOME STATEMENTS');
|
||||
const definitionsPosition = output.toString().indexOf('SOME DEFINITIONS');
|
||||
@ -548,16 +551,15 @@ SOME DEFINITION TEXT
|
||||
});
|
||||
|
||||
describe('removeDecorators', () => {
|
||||
|
||||
it('should delete the decorator (and following comma) that was matched in the analysis',
|
||||
() => {
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.not.toContain(`{ type: core.Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -575,10 +577,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString())
|
||||
.toContain(`{ type: core.Directive, args: [{ selector: '[a]' }] },`);
|
||||
@ -596,10 +598,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM);
|
||||
const output = new MagicString(PROGRAM.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators ![0];
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators![0];
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
renderer.addDefinitions(output, compiledClass, 'SOME DEFINITION TEXT');
|
||||
expect(output.toString())
|
||||
@ -610,7 +612,6 @@ SOME DEFINITION TEXT
|
||||
expect(output.toString()).toContain(`{ type: OtherB }`);
|
||||
expect(output.toString()).not.toContain(`C.decorators`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('[__decorate declarations]', () => {
|
||||
@ -619,10 +620,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'A') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'A')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).not.toContain(`core.Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -636,10 +637,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'B')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`core.Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
@ -654,10 +655,10 @@ SOME DEFINITION TEXT
|
||||
const {renderer, decorationAnalyses, sourceFile} = setup(PROGRAM_DECORATE_HELPER);
|
||||
const output = new MagicString(PROGRAM_DECORATE_HELPER.contents);
|
||||
const compiledClass =
|
||||
decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'C') !;
|
||||
const decorator = compiledClass.decorators !.find(d => d.name === 'Directive') !;
|
||||
decorationAnalyses.get(sourceFile)!.compiledClasses.find(c => c.name === 'C')!;
|
||||
const decorator = compiledClass.decorators!.find(d => d.name === 'Directive')!;
|
||||
const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
|
||||
decoratorsToRemove.set(decorator.node !.parent !, [decorator.node !]);
|
||||
decoratorsToRemove.set(decorator.node!.parent!, [decorator.node!]);
|
||||
renderer.removeDecorators(output, decoratorsToRemove);
|
||||
expect(output.toString()).toContain(`core.Directive({ selector: '[a]' }),`);
|
||||
expect(output.toString()).toContain(`OtherA()`);
|
||||
|
@ -5,7 +5,7 @@
|
||||
* 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 {FileSystem, absoluteFrom, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||
import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||
import {fromObject} from 'convert-source-map';
|
||||
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
@ -75,7 +75,8 @@ runInEachFileSystem(() => {
|
||||
const encodedSourceMap = Buffer.from(JSON.stringify(sourceMap)).toString('base64');
|
||||
const sourceFile = registry.loadSourceFile(
|
||||
_('/foo/src/index.js'),
|
||||
`some inline content\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${encodedSourceMap}`);
|
||||
`some inline content\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${
|
||||
encodedSourceMap}`);
|
||||
if (sourceFile === null) {
|
||||
return fail('Expected source file to be defined');
|
||||
}
|
||||
@ -139,26 +140,26 @@ runInEachFileSystem(() => {
|
||||
|
||||
expect(sourceFile.sources.length).toEqual(3);
|
||||
|
||||
expect(sourceFile.sources[0] !.contents).toEqual('x content');
|
||||
expect(sourceFile.sources[0] !.sourcePath).toEqual(_('/foo/src/x.js'));
|
||||
expect(sourceFile.sources[0] !.rawMap).toEqual(null);
|
||||
expect(sourceFile.sources[0] !.sources).toEqual([]);
|
||||
expect(sourceFile.sources[0]!.contents).toEqual('x content');
|
||||
expect(sourceFile.sources[0]!.sourcePath).toEqual(_('/foo/src/x.js'));
|
||||
expect(sourceFile.sources[0]!.rawMap).toEqual(null);
|
||||
expect(sourceFile.sources[0]!.sources).toEqual([]);
|
||||
|
||||
|
||||
expect(sourceFile.sources[1] !.contents).toEqual('y content');
|
||||
expect(sourceFile.sources[1] !.sourcePath).toEqual(_('/foo/src/y.js'));
|
||||
expect(sourceFile.sources[1] !.rawMap).toEqual(ySourceMap);
|
||||
expect(sourceFile.sources[1]!.contents).toEqual('y content');
|
||||
expect(sourceFile.sources[1]!.sourcePath).toEqual(_('/foo/src/y.js'));
|
||||
expect(sourceFile.sources[1]!.rawMap).toEqual(ySourceMap);
|
||||
|
||||
expect(sourceFile.sources[1] !.sources.length).toEqual(1);
|
||||
expect(sourceFile.sources[1] !.sources[0] !.contents).toEqual('a content');
|
||||
expect(sourceFile.sources[1] !.sources[0] !.sourcePath).toEqual(_('/foo/src/a.js'));
|
||||
expect(sourceFile.sources[1] !.sources[0] !.rawMap).toEqual(null);
|
||||
expect(sourceFile.sources[1] !.sources[0] !.sources).toEqual([]);
|
||||
expect(sourceFile.sources[1]!.sources.length).toEqual(1);
|
||||
expect(sourceFile.sources[1]!.sources[0]!.contents).toEqual('a content');
|
||||
expect(sourceFile.sources[1]!.sources[0]!.sourcePath).toEqual(_('/foo/src/a.js'));
|
||||
expect(sourceFile.sources[1]!.sources[0]!.rawMap).toEqual(null);
|
||||
expect(sourceFile.sources[1]!.sources[0]!.sources).toEqual([]);
|
||||
|
||||
expect(sourceFile.sources[2] !.contents).toEqual('z content');
|
||||
expect(sourceFile.sources[2] !.sourcePath).toEqual(_('/foo/src/z.js'));
|
||||
expect(sourceFile.sources[2] !.rawMap).toEqual(null);
|
||||
expect(sourceFile.sources[2] !.sources).toEqual([]);
|
||||
expect(sourceFile.sources[2]!.contents).toEqual('z content');
|
||||
expect(sourceFile.sources[2]!.sourcePath).toEqual(_('/foo/src/z.js'));
|
||||
expect(sourceFile.sources[2]!.rawMap).toEqual(null);
|
||||
expect(sourceFile.sources[2]!.sources).toEqual([]);
|
||||
});
|
||||
|
||||
it('should handle a missing source file referenced from a source-map', () => {
|
||||
@ -186,22 +187,25 @@ runInEachFileSystem(() => {
|
||||
|
||||
const aPath = _('/foo/src/a.js');
|
||||
fs.writeFile(
|
||||
aPath, 'a content\n' +
|
||||
aPath,
|
||||
'a content\n' +
|
||||
fromObject(createRawSourceMap({file: 'a.js', sources: ['b.js']})).toComment());
|
||||
|
||||
const bPath = _('/foo/src/b.js');
|
||||
fs.writeFile(
|
||||
bPath, 'b content\n' +
|
||||
bPath,
|
||||
'b content\n' +
|
||||
fromObject(createRawSourceMap({file: 'b.js', sources: ['c.js']})).toComment());
|
||||
|
||||
const cPath = _('/foo/src/c.js');
|
||||
fs.writeFile(
|
||||
cPath, 'c content\n' +
|
||||
cPath,
|
||||
'c content\n' +
|
||||
fromObject(createRawSourceMap({file: 'c.js', sources: ['a.js']})).toComment());
|
||||
|
||||
expect(() => registry.loadSourceFile(aPath))
|
||||
.toThrowError(
|
||||
`Circular source file mapping dependency: ${aPath} -> ${bPath} -> ${cPath} -> ${aPath}`);
|
||||
.toThrowError(`Circular source file mapping dependency: ${aPath} -> ${bPath} -> ${
|
||||
cPath} -> ${aPath}`);
|
||||
});
|
||||
|
||||
it('should not fail if there is a cyclic dependency in filenames of inline sources', () => {
|
||||
@ -209,7 +213,8 @@ runInEachFileSystem(() => {
|
||||
|
||||
const aPath = _('/foo/src/a.js');
|
||||
fs.writeFile(
|
||||
aPath, 'a content\n' +
|
||||
aPath,
|
||||
'a content\n' +
|
||||
fromObject(createRawSourceMap({file: 'a.js', sources: ['b.js']})).toComment());
|
||||
|
||||
const bPath = _('/foo/src/b.js');
|
||||
@ -238,6 +243,7 @@ function createRawSourceMap(custom: Partial<RawSourceMap>): RawSourceMap {
|
||||
'sources': [],
|
||||
'sourcesContent': [],
|
||||
'names': [],
|
||||
'mappings': '', ...custom
|
||||
'mappings': '',
|
||||
...custom
|
||||
};
|
||||
}
|
@ -11,13 +11,15 @@ import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {RawSourceMap} from '../../src/sourcemaps/raw_source_map';
|
||||
import {SegmentMarker} from '../../src/sourcemaps/segment_marker';
|
||||
import {Mapping, SourceFile, computeStartOfLinePositions, ensureOriginalSegmentLinks, extractOriginalSegments, findLastMappingIndexBefore, parseMappings} from '../../src/sourcemaps/source_file';
|
||||
import {computeStartOfLinePositions, ensureOriginalSegmentLinks, extractOriginalSegments, findLastMappingIndexBefore, Mapping, parseMappings, SourceFile} from '../../src/sourcemaps/source_file';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('SourceFile and utilities', () => {
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
beforeEach(() => { _ = absoluteFrom; });
|
||||
beforeEach(() => {
|
||||
_ = absoluteFrom;
|
||||
});
|
||||
|
||||
describe('parseMappings()', () => {
|
||||
it('should be an empty array for source files with no source map', () => {
|
||||
@ -118,7 +120,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 35, position: 35, next: undefined};
|
||||
const index = findLastMappingIndexBefore(mappings, marker, /* exclusive */ false, 0);
|
||||
@ -133,7 +135,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 35, position: 35, next: undefined};
|
||||
const index = findLastMappingIndexBefore(mappings, marker, /* exclusive */ false, 0);
|
||||
@ -147,7 +149,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 60, position: 60, next: undefined};
|
||||
|
||||
@ -162,7 +164,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 5, position: 5, next: undefined};
|
||||
|
||||
@ -180,7 +182,7 @@ runInEachFileSystem(() => {
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
const index = findLastMappingIndexBefore(mappings, marker3, /* exclusive */ false, 0);
|
||||
expect(index).toEqual(2);
|
||||
});
|
||||
@ -194,7 +196,7 @@ runInEachFileSystem(() => {
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
const index = findLastMappingIndexBefore(mappings, marker3, /* exclusive */ false, 0);
|
||||
expect(index).toEqual(3);
|
||||
});
|
||||
@ -209,7 +211,7 @@ runInEachFileSystem(() => {
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
const index = findLastMappingIndexBefore(mappings, marker3, /* exclusive */ true, 0);
|
||||
expect(index).toEqual(1);
|
||||
});
|
||||
@ -223,7 +225,7 @@ runInEachFileSystem(() => {
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
const index = findLastMappingIndexBefore(mappings, marker3, /* exclusive */ false, 0);
|
||||
expect(index).toEqual(3);
|
||||
});
|
||||
@ -238,7 +240,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 35, position: 35, next: undefined};
|
||||
const index = findLastMappingIndexBefore(mappings, marker, /* exclusive */ false, 1);
|
||||
@ -253,7 +255,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 30, position: 30, next: undefined};
|
||||
const index = findLastMappingIndexBefore(mappings, marker, /* exclusive */ false, 2);
|
||||
@ -268,7 +270,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 30, position: 30, next: undefined};
|
||||
const index = findLastMappingIndexBefore(mappings, marker, /* exclusive */ false, 3);
|
||||
@ -282,7 +284,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 25, position: 25, next: undefined};
|
||||
|
||||
@ -298,7 +300,7 @@ runInEachFileSystem(() => {
|
||||
const marker2: SegmentMarker = {line: 0, column: 20, position: 20, next: marker3};
|
||||
const marker1: SegmentMarker = {line: 0, column: 10, position: 10, next: marker2};
|
||||
const mappings: Mapping[] = [marker1, marker2, marker3, marker4, marker5].map(
|
||||
marker => ({ generatedSegment: marker } as Mapping));
|
||||
marker => ({generatedSegment: marker} as Mapping));
|
||||
|
||||
const marker: SegmentMarker = {line: 0, column: 30, position: 30, next: undefined};
|
||||
|
||||
|
@ -126,7 +126,7 @@ describe('getTsHelperFnFromDeclaration()', () => {
|
||||
const classDecl =
|
||||
ts.createClassDeclaration(undefined, undefined, '__assign', undefined, undefined, []);
|
||||
|
||||
expect(classDecl.name !.text).toBe('__assign');
|
||||
expect(classDecl.name!.text).toBe('__assign');
|
||||
expect(getTsHelperFnFromDeclaration(classDecl)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
@ -5,7 +5,7 @@
|
||||
* 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, FileSystem, PathSegment, absoluteFrom, getFileSystem} from '../../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, PathSegment} from '../../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../../src/ngtsc/file_system/testing';
|
||||
import {EntryPointPackageJson} from '../../../src/packages/entry_point';
|
||||
import {BackupFileCleaner, NgccDirectoryCleaner, PackageJsonCleaner} from '../../../src/writing/cleaning/cleaning_strategies';
|
||||
@ -21,9 +21,10 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
describe('PackageJsonCleaner', () => {
|
||||
|
||||
let packageJsonPath: AbsoluteFsPath;
|
||||
beforeEach(() => { packageJsonPath = _abs('/node_modules/pkg/package.json'); });
|
||||
beforeEach(() => {
|
||||
packageJsonPath = _abs('/node_modules/pkg/package.json');
|
||||
});
|
||||
|
||||
describe('canClean()', () => {
|
||||
it('should return true if the basename is package.json', () => {
|
||||
@ -150,7 +151,6 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
describe('canClean()', () => {
|
||||
|
||||
it('should return true if the file name ends in .__ivy_ngcc_bak and the processed file exists',
|
||||
() => {
|
||||
const strategy = new BackupFileCleaner(fs);
|
||||
@ -192,7 +192,9 @@ runInEachFileSystem(() => {
|
||||
|
||||
describe('NgccDirectoryCleaner', () => {
|
||||
let ivyDirectory: AbsoluteFsPath;
|
||||
beforeEach(() => { ivyDirectory = _abs('/node_modules/pkg/__ivy_ngcc__'); });
|
||||
beforeEach(() => {
|
||||
ivyDirectory = _abs('/node_modules/pkg/__ivy_ngcc__');
|
||||
});
|
||||
|
||||
describe('canClean()', () => {
|
||||
it('should return true if the path is a directory and is called __ivy_ngcc__', () => {
|
||||
|
@ -5,7 +5,7 @@
|
||||
* 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, FileSystem, PathSegment, absoluteFrom, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, PathSegment} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||
|
||||
import {runInEachFileSystem} from '../../../../src/ngtsc/file_system/testing';
|
||||
import {CleaningStrategy} from '../../../src/writing/cleaning/cleaning_strategies';
|
||||
|
@ -14,7 +14,6 @@ import {MockLogger} from '../helpers/mock_logger';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('InPlaceFileWriter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
beforeEach(() => {
|
||||
@ -79,8 +78,8 @@ runInEachFileSystem(() => {
|
||||
() => fileWriter.writeBundle(
|
||||
{} as EntryPointBundle,
|
||||
[{path: absoluteBackupPath, contents: 'MODIFIED BACKED UP'}]))
|
||||
.toThrowError(
|
||||
`Tried to overwrite ${absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.`);
|
||||
.toThrowError(`Tried to overwrite ${
|
||||
absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.`);
|
||||
});
|
||||
|
||||
it('should log an error, and skip writing the file, if the backup file already exists and errorOnFailedEntryPoint is false',
|
||||
@ -95,7 +94,9 @@ runInEachFileSystem(() => {
|
||||
expect(fs.readFile(absoluteBackupPath)).toEqual('ORIGINAL ALREADY BACKED UP');
|
||||
expect(fs.readFile(_(absoluteBackupPath + '.__ivy_ngcc_bak'))).toEqual('BACKED UP');
|
||||
expect(logger.logs.error).toEqual([[
|
||||
`Tried to write ${absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file but it already exists so not writing, nor backing up, ${absoluteBackupPath}.\n` +
|
||||
`Tried to write ${
|
||||
absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file but it already exists so not writing, nor backing up, ${
|
||||
absoluteBackupPath}.\n` +
|
||||
`This error may be because two or more entry-points overlap and ngcc has been asked to process some files more than once.\n` +
|
||||
`You should check other entry-points in this package and set up a config to ignore any that you are not using.`
|
||||
]]);
|
||||
|
@ -5,11 +5,11 @@
|
||||
* 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 {FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {NgccConfiguration} from '../../src/packages/configuration';
|
||||
import {EntryPoint, EntryPointFormat, EntryPointJsonProperty, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT, getEntryPointInfo} from '../../src/packages/entry_point';
|
||||
import {EntryPoint, EntryPointFormat, EntryPointJsonProperty, getEntryPointInfo, INCOMPATIBLE_ENTRY_POINT, NO_ENTRY_POINT} from '../../src/packages/entry_point';
|
||||
import {EntryPointBundle, makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
||||
import {FileWriter} from '../../src/writing/file_writer';
|
||||
import {NewEntryPointFileWriter} from '../../src/writing/new_entry_point_file_writer';
|
||||
@ -19,7 +19,6 @@ import {loadPackageJson} from '../packages/entry_point_spec';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('NewEntryPointFileWriter', () => {
|
||||
|
||||
let _: typeof absoluteFrom;
|
||||
let fs: FileSystem;
|
||||
let fileWriter: FileWriter;
|
||||
@ -107,7 +106,7 @@ runInEachFileSystem(() => {
|
||||
fs, logger, /* errorOnFailedEntryPoint */ true, new DirectPackageJsonUpdater(fs));
|
||||
const config = new NgccConfiguration(fs, _('/'));
|
||||
const result = getEntryPointInfo(
|
||||
fs, config, logger, _('/node_modules/test'), _('/node_modules/test')) !;
|
||||
fs, config, logger, _('/node_modules/test'), _('/node_modules/test'))!;
|
||||
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
|
||||
return fail(`Expected an entry point but got ${result}`);
|
||||
}
|
||||
@ -247,7 +246,7 @@ runInEachFileSystem(() => {
|
||||
fs, logger, /* errorOnFailedEntryPoint */ true, new DirectPackageJsonUpdater(fs));
|
||||
const config = new NgccConfiguration(fs, _('/'));
|
||||
const result = getEntryPointInfo(
|
||||
fs, config, logger, _('/node_modules/test'), _('/node_modules/test/a')) !;
|
||||
fs, config, logger, _('/node_modules/test'), _('/node_modules/test/a'))!;
|
||||
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
|
||||
return fail(`Expected an entry point but got ${result}`);
|
||||
}
|
||||
@ -376,7 +375,7 @@ runInEachFileSystem(() => {
|
||||
fs, logger, /* errorOnFailedEntryPoint */ true, new DirectPackageJsonUpdater(fs));
|
||||
const config = new NgccConfiguration(fs, _('/'));
|
||||
const result = getEntryPointInfo(
|
||||
fs, config, new MockLogger(), _('/node_modules/test'), _('/node_modules/test/b')) !;
|
||||
fs, config, new MockLogger(), _('/node_modules/test'), _('/node_modules/test/b'))!;
|
||||
if (result === NO_ENTRY_POINT || result === INCOMPATIBLE_ENTRY_POINT) {
|
||||
return fail(`Expected an entry point but got ${result}`);
|
||||
}
|
||||
@ -501,6 +500,6 @@ runInEachFileSystem(() => {
|
||||
fs: FileSystem, entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty,
|
||||
format: EntryPointFormat): EntryPointBundle {
|
||||
return makeEntryPointBundle(
|
||||
fs, entryPoint, entryPoint.packageJson[formatProperty] !, false, format, true);
|
||||
fs, entryPoint, entryPoint.packageJson[formatProperty]!, false, format, true);
|
||||
}
|
||||
});
|
||||
|
@ -5,7 +5,7 @@
|
||||
* 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, FileSystem, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {JsonObject} from '../../src/packages/entry_point';
|
||||
|
Reference in New Issue
Block a user