Skip to content

Commit 8b3e300

Browse files
authored
fix(@ngtools/webpack): fix error with object spread (angular#4642)
The loader throws an exception when an object spread is used. This fixes it. Fixes angular#4600
1 parent b1790e6 commit 8b3e300

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/@ngtools/webpack/src/loader.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const NormalModule = require('webpack/lib/NormalModule');
99

1010

1111
function _getContentOfKeyLiteral(source: ts.SourceFile, node: ts.Node): string {
12-
if (node.kind == ts.SyntaxKind.Identifier) {
12+
if (!node) {
13+
return null;
14+
} else if (node.kind == ts.SyntaxKind.Identifier) {
1315
return (node as ts.Identifier).text;
1416
} else if (node.kind == ts.SyntaxKind.StringLiteral) {
1517
return (node as ts.StringLiteral).text;
@@ -241,11 +243,16 @@ function _removeModuleId(refactor: TypeScriptFileRefactor) {
241243

242244
refactor.findAstNodes(sourceFile, ts.SyntaxKind.ObjectLiteralExpression, true)
243245
// Get all their property assignments.
244-
.filter((node: ts.ObjectLiteralExpression) =>
245-
node.properties.some(prop => _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId'))
246+
.filter((node: ts.ObjectLiteralExpression) => {
247+
return node.properties.some(prop => {
248+
return prop.kind == ts.SyntaxKind.PropertyAssignment
249+
&& _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId';
250+
});
251+
})
246252
.forEach((node: ts.ObjectLiteralExpression) => {
247253
const moduleIdProp = node.properties.filter((prop: ts.ObjectLiteralElement, idx: number) => {
248-
return _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId';
254+
return prop.kind == ts.SyntaxKind.PropertyAssignment
255+
&& _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId';
249256
})[0];
250257
// get the trailing comma
251258
const moduleIdCommaProp = moduleIdProp.parent.getChildAt(1).getChildren()[1];

0 commit comments

Comments
 (0)