Skip to content

Commit

Permalink
fix(@schematics/angular): fix syntax error in main.ts after generatin…
Browse files Browse the repository at this point in the history
…g universal

Add missing curly brace for application boostrap wrapper and test
Fixes #13392
  • Loading branch information
mbenzenhoefer authored and kyliau committed Jan 11, 2019
1 parent 270e1dc commit 5ca3523
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/schematics/angular/universal/index.ts
Expand Up @@ -134,7 +134,7 @@ function wrapBootstrapCall(options: UniversalOptions): Rule {
const triviaWidth = bootstrapCall.getLeadingTriviaWidth();
const beforeText = `document.addEventListener('DOMContentLoaded', () => {\n`
+ ' '.repeat(triviaWidth > 2 ? triviaWidth + 1 : triviaWidth);
const afterText = `\n${triviaWidth > 2 ? ' '.repeat(triviaWidth - 1) : ''});`;
const afterText = `\n${triviaWidth > 2 ? ' '.repeat(triviaWidth - 1) : ''}});`;

// in some cases we need to cater for a trailing semicolon such as;
// bootstrap().catch(err => console.log(err));
Expand Down
5 changes: 3 additions & 2 deletions packages/schematics/angular/universal/index_spec.ts
Expand Up @@ -150,10 +150,11 @@ describe('Universal Schematic', () => {
const tree = schematicRunner.runSchematic('universal', defaultOptions, appTree);
const filePath = '/projects/bar/src/main.ts';
const contents = tree.readContent(filePath);
expect(contents).toMatch(/document.addEventListener\('DOMContentLoaded', \(\) => {/);
expect(contents)
.toMatch(/document.addEventListener\('DOMContentLoaded', \(\) => {[\w\W]+;[\r\n]}\);/);
});

it('should wrap the bootstrap decleration in a DOMContentLoaded event handler', () => {
it('should wrap the bootstrap declaration in a DOMContentLoaded event handler', () => {
const filePath = '/projects/bar/src/main.ts';
appTree.overwrite(
filePath,
Expand Down

0 comments on commit 5ca3523

Please sign in to comment.