2018-07-16 05:23:37 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* 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 * as fs from 'fs';
|
|
|
|
import MagicString from 'magic-string';
|
2018-11-25 16:40:25 -05:00
|
|
|
import * as ts from 'typescript';
|
2018-07-16 05:23:37 -04:00
|
|
|
import {fromObject, generateMapFileComment} from 'convert-source-map';
|
2018-10-16 03:56:54 -04:00
|
|
|
import {CompiledClass, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
|
2018-11-13 09:40:54 -05:00
|
|
|
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
|
2018-11-25 17:07:51 -05:00
|
|
|
import {PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
|
2018-10-04 07:19:11 -04:00
|
|
|
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';
|
2018-10-10 09:17:32 -04:00
|
|
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
2018-11-18 15:37:30 -05:00
|
|
|
import {RedundantDecoratorMap, Renderer} from '../../src/rendering/renderer';
|
2018-11-25 16:40:25 -05:00
|
|
|
import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
|
|
|
|
import {makeTestEntryPointBundle} from '../helpers/utils';
|
2018-07-16 05:23:37 -04:00
|
|
|
|
|
|
|
class TestRenderer extends Renderer {
|
2018-11-25 16:40:25 -05:00
|
|
|
constructor(host: Esm2015ReflectionHost, isCore: boolean, bundle: EntryPointBundle) {
|
|
|
|
super(host, isCore, bundle, '/src', '/dist');
|
2018-11-11 13:16:04 -05:00
|
|
|
}
|
2018-07-16 05:23:37 -04:00
|
|
|
addImports(output: MagicString, imports: {name: string, as: string}[]) {
|
|
|
|
output.prepend('\n// ADD IMPORTS\n');
|
|
|
|
}
|
2018-11-25 17:07:51 -05:00
|
|
|
addExports(output: MagicString, baseEntryPointPath: string, exports: {
|
|
|
|
identifier: string,
|
|
|
|
from: string
|
|
|
|
}[]) {
|
|
|
|
output.prepend('\n// ADD EXPORTS\n');
|
|
|
|
}
|
2018-06-27 11:41:11 -04:00
|
|
|
addConstants(output: MagicString, constants: string, file: ts.SourceFile): void {
|
|
|
|
output.prepend('\n// ADD CONSTANTS\n');
|
|
|
|
}
|
2018-10-16 03:56:54 -04:00
|
|
|
addDefinitions(output: MagicString, compiledClass: CompiledClass, definitions: string) {
|
2018-07-16 05:23:37 -04:00
|
|
|
output.prepend('\n// ADD DEFINITIONS\n');
|
|
|
|
}
|
2018-11-18 15:37:30 -05:00
|
|
|
removeDecorators(output: MagicString, decoratorsToRemove: RedundantDecoratorMap) {
|
2018-07-16 05:23:37 -04:00
|
|
|
output.prepend('\n// REMOVE DECORATORS\n');
|
|
|
|
}
|
2018-08-17 02:50:45 -04:00
|
|
|
rewriteSwitchableDeclarations(output: MagicString, sourceFile: ts.SourceFile): void {
|
|
|
|
output.prepend('\n// REWRITTEN DECLARATIONS\n');
|
|
|
|
}
|
2018-07-16 05:23:37 -04:00
|
|
|
}
|
|
|
|
|
2018-11-11 13:16:04 -05:00
|
|
|
function createTestRenderer(
|
2018-11-25 16:40:25 -05:00
|
|
|
packageName: string, files: {name: string, contents: string}[],
|
|
|
|
dtsFile?: {name: string, contents: string}) {
|
|
|
|
const isCore = packageName === '@angular/core';
|
|
|
|
const bundle = makeTestEntryPointBundle('esm2015', files, dtsFile && [dtsFile]);
|
|
|
|
const typeChecker = bundle.src.program.getTypeChecker();
|
|
|
|
const host = new Esm2015ReflectionHost(isCore, typeChecker, bundle.dts);
|
2018-11-13 09:40:54 -05:00
|
|
|
const referencesRegistry = new NgccReferencesRegistry(host);
|
2018-10-04 07:19:11 -04:00
|
|
|
const decorationAnalyses =
|
2018-11-25 16:40:25 -05:00
|
|
|
new DecorationAnalyzer(typeChecker, host, referencesRegistry, bundle.rootDirs, isCore)
|
|
|
|
.analyzeProgram(bundle.src.program);
|
|
|
|
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(bundle.src.program);
|
2018-11-25 17:07:51 -05:00
|
|
|
const privateDeclarationsAnalyses =
|
|
|
|
new PrivateDeclarationsAnalyzer(host, referencesRegistry).analyzeProgram(bundle.src.program);
|
2018-11-25 16:40:25 -05:00
|
|
|
const renderer = new TestRenderer(host, isCore, bundle);
|
2018-07-16 05:23:37 -04:00
|
|
|
spyOn(renderer, 'addImports').and.callThrough();
|
|
|
|
spyOn(renderer, 'addDefinitions').and.callThrough();
|
|
|
|
spyOn(renderer, 'removeDecorators').and.callThrough();
|
2018-09-28 09:57:50 -04:00
|
|
|
|
2018-11-25 17:07:51 -05:00
|
|
|
return {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses};
|
2018-07-16 05:23:37 -04:00
|
|
|
}
|
|
|
|
|
2018-09-28 09:57:50 -04:00
|
|
|
|
2018-07-16 05:23:37 -04:00
|
|
|
describe('Renderer', () => {
|
|
|
|
const INPUT_PROGRAM = {
|
2018-10-04 07:19:11 -04:00
|
|
|
name: '/src/file.js',
|
2018-07-16 05:23:37 -04:00
|
|
|
contents:
|
|
|
|
`import { Directive } from '@angular/core';\nexport class A {\n foo(x) {\n return x;\n }\n}\nA.decorators = [\n { type: Directive, args: [{ selector: '[a]' }] }\n];\n`
|
|
|
|
};
|
2018-11-25 16:40:25 -05:00
|
|
|
const INPUT_DTS_PROGRAM = {
|
|
|
|
name: '/typings/file.d.ts',
|
|
|
|
contents: `export declare class A {\nfoo(x: number): number;\n}\n`
|
|
|
|
};
|
2018-10-04 07:19:11 -04:00
|
|
|
|
2018-12-10 11:34:56 -05:00
|
|
|
const COMPONENT_PROGRAM = {
|
|
|
|
name: '/src/component.js',
|
|
|
|
contents:
|
|
|
|
`import { Component } from '@angular/core';\nexport class A {}\nA.decorators = [\n { type: Component, args: [{ selector: 'a', template: '{{ person!.name }}' }] }\n];\n`
|
|
|
|
};
|
|
|
|
|
2018-07-16 05:23:37 -04:00
|
|
|
const INPUT_PROGRAM_MAP = fromObject({
|
|
|
|
'version': 3,
|
2018-10-04 07:19:11 -04:00
|
|
|
'file': '/src/file.js',
|
2018-07-16 05:23:37 -04:00
|
|
|
'sourceRoot': '',
|
2018-10-04 07:19:11 -04:00
|
|
|
'sources': ['/src/file.ts'],
|
2018-07-16 05:23:37 -04:00
|
|
|
'names': [],
|
|
|
|
'mappings':
|
|
|
|
'AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,MAAM;IACF,GAAG,CAAC,CAAS;QACT,OAAO,CAAC,CAAC;IACb,CAAC;;AACM,YAAU,GAAG;IAChB,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE;CACnD,CAAC',
|
2018-10-04 07:19:11 -04:00
|
|
|
'sourcesContent': [INPUT_PROGRAM.contents]
|
2018-07-16 05:23:37 -04:00
|
|
|
});
|
2018-10-04 07:19:11 -04:00
|
|
|
|
2018-07-16 05:23:37 -04:00
|
|
|
const RENDERED_CONTENTS =
|
2018-11-18 15:37:30 -05:00
|
|
|
`\n// ADD EXPORTS\n\n// ADD IMPORTS\n\n// ADD CONSTANTS\n\n// ADD DEFINITIONS\n\n// REMOVE DECORATORS\n` +
|
2018-06-27 11:41:11 -04:00
|
|
|
INPUT_PROGRAM.contents;
|
2018-10-04 07:19:11 -04:00
|
|
|
|
2018-07-16 05:23:37 -04:00
|
|
|
const OUTPUT_PROGRAM_MAP = fromObject({
|
|
|
|
'version': 3,
|
2018-10-04 07:19:11 -04:00
|
|
|
'file': '/dist/file.js',
|
|
|
|
'sources': ['/src/file.js'],
|
|
|
|
'sourcesContent': [INPUT_PROGRAM.contents],
|
2018-07-16 05:23:37 -04:00
|
|
|
'names': [],
|
2018-11-25 17:07:51 -05:00
|
|
|
'mappings': ';;;;;;;;;;AAAA;;;;;;;;;'
|
2018-07-16 05:23:37 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const MERGED_OUTPUT_PROGRAM_MAP = fromObject({
|
|
|
|
'version': 3,
|
2018-10-04 07:19:11 -04:00
|
|
|
'sources': ['/src/file.ts'],
|
2018-07-16 05:23:37 -04:00
|
|
|
'names': [],
|
2018-11-25 17:07:51 -05:00
|
|
|
'mappings': ';;;;;;;;;;AAAA',
|
2018-10-04 07:19:11 -04:00
|
|
|
'file': '/dist/file.js',
|
|
|
|
'sourcesContent': [INPUT_PROGRAM.contents]
|
2018-07-16 05:23:37 -04:00
|
|
|
});
|
|
|
|
|
2018-10-04 07:19:11 -04:00
|
|
|
describe('renderProgram()', () => {
|
2018-07-16 05:23:37 -04:00
|
|
|
it('should render the modified contents; and a new map file, if the original provided no map file.',
|
|
|
|
() => {
|
2018-11-25 17:07:51 -05:00
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
2018-11-25 16:40:25 -05:00
|
|
|
createTestRenderer('test-package', [INPUT_PROGRAM]);
|
2018-11-25 17:07:51 -05:00
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-10-04 07:19:11 -04:00
|
|
|
expect(result[0].path).toEqual('/dist/file.js');
|
|
|
|
expect(result[0].contents)
|
|
|
|
.toEqual(RENDERED_CONTENTS + '\n' + generateMapFileComment('/dist/file.js.map'));
|
|
|
|
expect(result[1].path).toEqual('/dist/file.js.map');
|
|
|
|
expect(result[1].contents).toEqual(OUTPUT_PROGRAM_MAP.toJSON());
|
2018-07-16 05:23:37 -04:00
|
|
|
});
|
|
|
|
|
2018-12-10 11:34:56 -05:00
|
|
|
|
|
|
|
it('should render as JavaScript', () => {
|
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
|
|
|
createTestRenderer('test-package', [COMPONENT_PROGRAM]);
|
|
|
|
renderer.renderProgram(decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
|
|
|
const addDefinitionsSpy = renderer.addDefinitions as jasmine.Spy;
|
|
|
|
expect(addDefinitionsSpy.calls.first().args[2])
|
|
|
|
.toEqual(`/*@__PURE__*/ ɵngcc0.ɵsetClassMetadata(A, [{
|
|
|
|
type: Component,
|
|
|
|
args: [{ selector: 'a', template: '{{ person!.name }}' }]
|
|
|
|
}], null, null);
|
|
|
|
A.ngComponentDef = ɵngcc0.ɵdefineComponent({ type: A, selectors: [["a"]], factory: function A_Factory(t) { return new (t || A)(); }, consts: 1, vars: 1, template: function A_Template(rf, ctx) { if (rf & 1) {
|
|
|
|
ɵngcc0.ɵtext(0);
|
|
|
|
} if (rf & 2) {
|
|
|
|
ɵngcc0.ɵtextBinding(0, ɵngcc0.ɵinterpolation1("", ctx.person.name, ""));
|
|
|
|
} }, encapsulation: 2 });`);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
describe('calling abstract methods', () => {
|
|
|
|
it('should call addImports with the source code and info about the core Angular library.',
|
|
|
|
() => {
|
2018-11-25 17:07:51 -05:00
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
2018-11-25 16:40:25 -05:00
|
|
|
createTestRenderer('test-package', [INPUT_PROGRAM]);
|
2018-11-25 17:07:51 -05:00
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-25 16:40:25 -05:00
|
|
|
const addImportsSpy = renderer.addImports as jasmine.Spy;
|
|
|
|
expect(addImportsSpy.calls.first().args[0].toString()).toEqual(RENDERED_CONTENTS);
|
|
|
|
expect(addImportsSpy.calls.first().args[1]).toEqual([
|
|
|
|
{name: '@angular/core', as: 'ɵngcc0'}
|
|
|
|
]);
|
|
|
|
});
|
2018-07-16 05:23:37 -04:00
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
it('should call addDefinitions with the source code, the analyzed class and the rendered definitions.',
|
|
|
|
() => {
|
2018-11-25 17:07:51 -05:00
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
2018-11-25 16:40:25 -05:00
|
|
|
createTestRenderer('test-package', [INPUT_PROGRAM]);
|
2018-11-25 17:07:51 -05:00
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-25 16:40:25 -05:00
|
|
|
const addDefinitionsSpy = renderer.addDefinitions as jasmine.Spy;
|
|
|
|
expect(addDefinitionsSpy.calls.first().args[0].toString()).toEqual(RENDERED_CONTENTS);
|
|
|
|
expect(addDefinitionsSpy.calls.first().args[1]).toEqual(jasmine.objectContaining({
|
|
|
|
name: 'A',
|
|
|
|
decorators: [jasmine.objectContaining({name: 'Directive'})],
|
|
|
|
}));
|
|
|
|
expect(addDefinitionsSpy.calls.first().args[2])
|
|
|
|
.toEqual(`/*@__PURE__*/ ɵngcc0.ɵsetClassMetadata(A, [{
|
2018-10-30 14:19:10 -04:00
|
|
|
type: Directive,
|
|
|
|
args: [{ selector: '[a]' }]
|
|
|
|
}], null, { foo: [] });
|
|
|
|
A.ngDirectiveDef = ɵngcc0.ɵdefineDirective({ type: A, selectors: [["", "a", ""]], factory: function A_Factory(t) { return new (t || A)(); } });`);
|
2018-11-25 16:40:25 -05:00
|
|
|
});
|
2018-07-16 05:23:37 -04:00
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
it('should call removeDecorators with the source code, a map of class decorators that have been analyzed',
|
|
|
|
() => {
|
2018-11-25 17:07:51 -05:00
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
2018-11-25 16:40:25 -05:00
|
|
|
createTestRenderer('test-package', [INPUT_PROGRAM]);
|
2018-11-25 17:07:51 -05:00
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-25 16:40:25 -05:00
|
|
|
const removeDecoratorsSpy = renderer.removeDecorators as jasmine.Spy;
|
|
|
|
expect(removeDecoratorsSpy.calls.first().args[0].toString()).toEqual(RENDERED_CONTENTS);
|
2018-07-16 05:23:37 -04:00
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
// Each map key is the TS node of the decorator container
|
|
|
|
// Each map value is an array of TS nodes that are the decorators to remove
|
|
|
|
const map = removeDecoratorsSpy.calls.first().args[1] as Map<ts.Node, ts.Node[]>;
|
|
|
|
const keys = Array.from(map.keys());
|
|
|
|
expect(keys.length).toEqual(1);
|
|
|
|
expect(keys[0].getText())
|
|
|
|
.toEqual(`[\n { type: Directive, args: [{ selector: '[a]' }] }\n]`);
|
|
|
|
const values = Array.from(map.values());
|
|
|
|
expect(values.length).toEqual(1);
|
|
|
|
expect(values[0].length).toEqual(1);
|
|
|
|
expect(values[0][0].getText())
|
|
|
|
.toEqual(`{ type: Directive, args: [{ selector: '[a]' }] }`);
|
|
|
|
});
|
|
|
|
});
|
2018-07-16 05:23:37 -04:00
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
describe('source map merging', () => {
|
|
|
|
it('should merge any inline source map from the original file and write the output as an inline source map',
|
|
|
|
() => {
|
2018-11-25 17:07:51 -05:00
|
|
|
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
|
|
|
createTestRenderer(
|
|
|
|
'test-package', [{
|
|
|
|
...INPUT_PROGRAM,
|
|
|
|
contents: INPUT_PROGRAM.contents + '\n' + INPUT_PROGRAM_MAP.toComment()
|
|
|
|
}]);
|
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-25 16:40:25 -05:00
|
|
|
expect(result[0].path).toEqual('/dist/file.js');
|
|
|
|
expect(result[0].contents)
|
|
|
|
.toEqual(RENDERED_CONTENTS + '\n' + MERGED_OUTPUT_PROGRAM_MAP.toComment());
|
|
|
|
expect(result[1]).toBeUndefined();
|
|
|
|
});
|
2018-11-11 13:16:04 -05:00
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
it('should merge any external source map from the original file and write the output to an external source map',
|
|
|
|
() => {
|
|
|
|
// Mock out reading the map file from disk
|
|
|
|
spyOn(fs, 'readFileSync').and.returnValue(INPUT_PROGRAM_MAP.toJSON());
|
2018-11-25 17:07:51 -05:00
|
|
|
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
|
|
|
createTestRenderer(
|
|
|
|
'test-package', [{
|
|
|
|
...INPUT_PROGRAM,
|
|
|
|
contents: INPUT_PROGRAM.contents + '\n//# sourceMappingURL=file.js.map'
|
|
|
|
}]);
|
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-25 16:40:25 -05:00
|
|
|
expect(result[0].path).toEqual('/dist/file.js');
|
|
|
|
expect(result[0].contents)
|
|
|
|
.toEqual(RENDERED_CONTENTS + '\n' + generateMapFileComment('/dist/file.js.map'));
|
|
|
|
expect(result[1].path).toEqual('/dist/file.js.map');
|
|
|
|
expect(result[1].contents).toEqual(MERGED_OUTPUT_PROGRAM_MAP.toJSON());
|
|
|
|
});
|
|
|
|
});
|
2018-11-11 13:16:04 -05:00
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
describe('@angular/core support', () => {
|
2018-11-11 13:16:04 -05:00
|
|
|
it('should render relative imports in ESM bundles', () => {
|
|
|
|
const CORE_FILE = {
|
|
|
|
name: '/src/core.js',
|
|
|
|
contents:
|
|
|
|
`import { NgModule } from './ng_module';\nexport class MyModule {}\nMyModule.decorators = [\n { type: NgModule, args: [] }\n];\n`
|
|
|
|
};
|
2018-11-25 16:40:25 -05:00
|
|
|
const R3_SYMBOLS_FILE = {
|
|
|
|
// r3_symbols in the file name indicates that this is the path to rewrite core imports to
|
|
|
|
name: '/src/r3_symbols.js',
|
|
|
|
contents: `export const NgModule = () => null;`
|
|
|
|
};
|
|
|
|
// The package name of `@angular/core` indicates that we are compiling the core library.
|
|
|
|
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
|
|
|
createTestRenderer('@angular/core', [CORE_FILE, R3_SYMBOLS_FILE]);
|
|
|
|
renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-11 13:16:04 -05:00
|
|
|
const addDefinitionsSpy = renderer.addDefinitions as jasmine.Spy;
|
|
|
|
expect(addDefinitionsSpy.calls.first().args[2])
|
|
|
|
.toContain(`/*@__PURE__*/ ɵngcc0.setClassMetadata(`);
|
|
|
|
const addImportsSpy = renderer.addImports as jasmine.Spy;
|
|
|
|
expect(addImportsSpy.calls.first().args[1]).toEqual([{name: './r3_symbols', as: 'ɵngcc0'}]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render no imports in FESM bundles', () => {
|
|
|
|
const CORE_FILE = {
|
|
|
|
name: '/src/core.js',
|
|
|
|
contents: `export const NgModule = () => null;
|
|
|
|
export class MyModule {}\nMyModule.decorators = [\n { type: NgModule, args: [] }\n];\n`
|
|
|
|
};
|
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
const {decorationAnalyses, renderer, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
|
|
|
createTestRenderer('@angular/core', [CORE_FILE]);
|
|
|
|
renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-11 13:16:04 -05:00
|
|
|
const addDefinitionsSpy = renderer.addDefinitions as jasmine.Spy;
|
|
|
|
expect(addDefinitionsSpy.calls.first().args[2])
|
|
|
|
.toContain(`/*@__PURE__*/ setClassMetadata(`);
|
|
|
|
const addImportsSpy = renderer.addImports as jasmine.Spy;
|
|
|
|
expect(addImportsSpy.calls.first().args[1]).toEqual([]);
|
|
|
|
});
|
2018-11-25 16:40:25 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('rendering typings', () => {
|
|
|
|
it('should render extract types into typings files', () => {
|
2018-11-25 17:07:51 -05:00
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
2018-11-25 16:40:25 -05:00
|
|
|
createTestRenderer('test-package', [INPUT_PROGRAM], INPUT_DTS_PROGRAM);
|
2018-11-25 17:07:51 -05:00
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-11 13:16:04 -05:00
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
const typingsFile = result.find(f => f.path === '/typings/file.d.ts') !;
|
|
|
|
expect(typingsFile.contents)
|
|
|
|
.toContain(
|
|
|
|
'foo(x: number): number;\n static ngDirectiveDef: ɵngcc0.ɵDirectiveDefWithMeta');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render imports into typings files', () => {
|
2018-11-25 17:07:51 -05:00
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
2018-11-25 16:40:25 -05:00
|
|
|
createTestRenderer('test-package', [INPUT_PROGRAM], INPUT_DTS_PROGRAM);
|
2018-11-25 17:07:51 -05:00
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
2018-11-25 16:40:25 -05:00
|
|
|
|
|
|
|
const typingsFile = result.find(f => f.path === '/typings/file.d.ts') !;
|
|
|
|
expect(typingsFile.contents).toContain(`// ADD IMPORTS\nexport declare class A`);
|
|
|
|
});
|
2018-11-25 17:07:51 -05:00
|
|
|
|
|
|
|
it('should render exports into typings files', () => {
|
|
|
|
const {renderer, decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses} =
|
|
|
|
createTestRenderer('test-package', [INPUT_PROGRAM], INPUT_DTS_PROGRAM);
|
|
|
|
|
|
|
|
// Add a mock export to trigger export rendering
|
|
|
|
privateDeclarationsAnalyses.push(
|
|
|
|
{identifier: 'ComponentB', from: '/src/file.js', dtsFrom: '/typings/b.d.ts'});
|
|
|
|
|
|
|
|
const result = renderer.renderProgram(
|
|
|
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
|
|
|
|
|
|
|
const typingsFile = result.find(f => f.path === '/typings/file.d.ts') !;
|
|
|
|
expect(typingsFile.contents)
|
|
|
|
.toContain(`// ADD EXPORTS\n\n// ADD IMPORTS\nexport declare class A`);
|
|
|
|
});
|
2018-11-11 13:16:04 -05:00
|
|
|
});
|
2018-07-16 05:23:37 -04:00
|
|
|
});
|
2018-07-27 15:36:54 -04:00
|
|
|
});
|