Skip to content

Commit 5064012

Browse files
mbenzenhoeferKeen Yee Liau
authored and
Keen Yee Liau
committed
fix(@schematics/angular): fix syntax error in main.ts after generating universal
Add missing curly brace for application boostrap wrapper and test Fixes #13392
1 parent 08d067a commit 5064012

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/schematics/angular/universal/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function wrapBootstrapCall(options: UniversalOptions): Rule {
134134
const triviaWidth = bootstrapCall.getLeadingTriviaWidth();
135135
const beforeText = `document.addEventListener('DOMContentLoaded', () => {\n`
136136
+ ' '.repeat(triviaWidth > 2 ? triviaWidth + 1 : triviaWidth);
137-
const afterText = `\n${triviaWidth > 2 ? ' '.repeat(triviaWidth - 1) : ''});`;
137+
const afterText = `\n${triviaWidth > 2 ? ' '.repeat(triviaWidth - 1) : ''}});`;
138138

139139
// in some cases we need to cater for a trailing semicolon such as;
140140
// bootstrap().catch(err => console.log(err));

packages/schematics/angular/universal/index_spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ describe('Universal Schematic', () => {
150150
const tree = schematicRunner.runSchematic('universal', defaultOptions, appTree);
151151
const filePath = '/projects/bar/src/main.ts';
152152
const contents = tree.readContent(filePath);
153-
expect(contents).toMatch(/document.addEventListener\('DOMContentLoaded', \(\) => {/);
153+
expect(contents)
154+
.toMatch(/document.addEventListener\('DOMContentLoaded', \(\) => {[\w\W]+;[\r\n]}\);/);
154155
});
155156

156-
it('should wrap the bootstrap decleration in a DOMContentLoaded event handler', () => {
157+
it('should wrap the bootstrap declaration in a DOMContentLoaded event handler', () => {
157158
const filePath = '/projects/bar/src/main.ts';
158159
appTree.overwrite(
159160
filePath,

0 commit comments

Comments
 (0)