Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/@ngtools/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const NormalModule = require('webpack/lib/NormalModule');


function _getContentOfKeyLiteral(source: ts.SourceFile, node: ts.Node): string {
if (node.kind == ts.SyntaxKind.Identifier) {
if (!node) {
return null;
} else if (node.kind == ts.SyntaxKind.Identifier) {
return (node as ts.Identifier).text;
} else if (node.kind == ts.SyntaxKind.StringLiteral) {
return (node as ts.StringLiteral).text;
Expand Down Expand Up @@ -241,11 +243,16 @@ function _removeModuleId(refactor: TypeScriptFileRefactor) {

refactor.findAstNodes(sourceFile, ts.SyntaxKind.ObjectLiteralExpression, true)
// Get all their property assignments.
.filter((node: ts.ObjectLiteralExpression) =>
node.properties.some(prop => _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId'))
.filter((node: ts.ObjectLiteralExpression) => {
return node.properties.some(prop => {
return prop.kind == ts.SyntaxKind.PropertyAssignment
&& _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId';
});
})
.forEach((node: ts.ObjectLiteralExpression) => {
const moduleIdProp = node.properties.filter((prop: ts.ObjectLiteralElement, idx: number) => {
return _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId';
return prop.kind == ts.SyntaxKind.PropertyAssignment
&& _getContentOfKeyLiteral(sourceFile, prop.name) == 'moduleId';
})[0];
// get the trailing comma
const moduleIdCommaProp = moduleIdProp.parent.getChildAt(1).getChildren()[1];
Expand Down