fix(ngcc): insert definitions after statement (#34677)

If a class was defined as a class expression
in a variable declaration, the definitions
were being inserted before the statment's
final semi-colon.

Now the insertion point will be after the
full statement.

Fixes #34648

PR Close #34677
This commit is contained in:
Pete Bacon Darwin
2020-01-08 15:03:30 +00:00
committed by Alex Rickabaugh
parent 66a1db7c6d
commit f2952403dd
2 changed files with 31 additions and 3 deletions

View File

@ -74,10 +74,12 @@ B.decorators = [
{ type: OtherB },
{ type: Directive, args: [{ selector: '[b]' }] }
];
export class C {}
var C_1;
let C = C_1 = class C {};
C.decorators = [
{ type: Directive, args: [{ selector: '[c]' }] },
];
export C;
let compileNgModuleFactory = compileNgModuleFactory__PRE_R3__;
let badlyFormattedVariable = __PRE_R3__badlyFormattedVariable;
@ -222,6 +224,20 @@ SOME DEFINITION TEXT
A.decorators = [
`);
});
it('should insert the definitions after the variable declaration of class expressions',
() => {
const {renderer, decorationAnalyses, sourceFile} = setup([PROGRAM]);
const output = new MagicString(PROGRAM.contents);
const compiledClass =
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 {};
SOME DEFINITION TEXT
C.decorators = [
`);
});
});
describe('addAdjacentStatements', () => {