Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit a70fb3b

Browse files
committed
fix: create PropertyAssignment instead of string literal (Identifier) when modifying the NgModule - in some cases (e.g. when there is a decomposition in another NgModule property), the TypeScipt program is trying to read node.name.kind on each property causing an exception for Identifiers)
1 parent aba0313 commit a70fb3b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Diff for: transformers/ns-replace-lazy-loader.spec.ts

+37
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,43 @@ describe("@ngtools/webpack transformers", () => {
4343
AppModule);
4444
export { AppModule };`
4545
},
46+
{
47+
name: "should add providers and NgModuleFactoryLoader when providers is missing and decomposition is used",
48+
rawAppModule: `
49+
import { NgModule } from "@angular/core";
50+
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
51+
import { AppComponent } from "./app.component";
52+
53+
const declarationsArray = [AppComponent];
54+
@NgModule({
55+
bootstrap: [
56+
AppComponent
57+
],
58+
imports: [
59+
NativeScriptModule
60+
],
61+
declarations: [
62+
...declarationsArray
63+
]
64+
})
65+
export class AppModule { }
66+
`,
67+
transformedAppModule: `
68+
import * as tslib_1 from "tslib"; import { NgModule } from "@angular/core";
69+
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
70+
import { AppComponent } from "./app.component";
71+
${NgLazyLoaderCode}
72+
const declarationsArray = [AppComponent];
73+
let AppModule = class AppModule { };
74+
AppModule = tslib_1.__decorate([ NgModule({
75+
bootstrap: [ AppComponent ],
76+
imports: [ NativeScriptModule ],
77+
declarations: [ ...declarationsArray ],
78+
providers: [{ provide: nsNgCoreImport_Generated.NgModuleFactoryLoader, useClass: NSLazyModulesLoader_Generated }] })
79+
],
80+
AppModule);
81+
export { AppModule };`
82+
},
4683
{
4784
name: "should add NgModuleFactoryLoader when the providers array is empty",
4885
rawAppModule: `

Diff for: transformers/ns-replace-lazy-loader.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export function addArrayPropertyValueToNgModule(
9393

9494
// the target field is missing, we will insert it @NgModule({ otherProps })
9595
const lastConfigObjPropertyNode = ngModuleConfigObjectNode.properties[ngModuleConfigObjectNode.properties.length - 1];
96-
const newTargetPropertyNode = ts.createIdentifier(`${targetPropertyName}: [${newPropertyValue}]`);
96+
97+
const newTargetPropertyNode = ts.createPropertyAssignment(targetPropertyName, ts.createIdentifier(`[${newPropertyValue}]`));
9798

9899
return [
99100
new AddNodeOperation(sourceFile, lastConfigObjPropertyNode, undefined, newTargetPropertyNode),

0 commit comments

Comments
 (0)