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

fix: the Lazy transformer is not crashing the TypeScript program anymore #959

Merged
merged 2 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions transformers/ns-replace-lazy-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,43 @@ describe("@ngtools/webpack transformers", () => {
AppModule);
export { AppModule };`
},
{
name: "should add providers and NgModuleFactoryLoader when providers is missing and decomposition is used",
rawAppModule: `
import { NgModule } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AppComponent } from "./app.component";

const declarationsArray = [AppComponent];
@NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule
],
declarations: [
...declarationsArray
]
})
export class AppModule { }
`,
transformedAppModule: `
import * as tslib_1 from "tslib"; import { NgModule } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AppComponent } from "./app.component";
${NgLazyLoaderCode}
const declarationsArray = [AppComponent];
let AppModule = class AppModule { };
AppModule = tslib_1.__decorate([ NgModule({
bootstrap: [ AppComponent ],
imports: [ NativeScriptModule ],
declarations: [ ...declarationsArray ],
providers: [{ provide: nsNgCoreImport_Generated.NgModuleFactoryLoader, useClass: NSLazyModulesLoader_Generated }] })
],
AppModule);
export { AppModule };`
},
{
name: "should add NgModuleFactoryLoader when the providers array is empty",
rawAppModule: `
Expand Down
3 changes: 2 additions & 1 deletion transformers/ns-replace-lazy-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export function addArrayPropertyValueToNgModule(

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

const newTargetPropertyNode = ts.createPropertyAssignment(targetPropertyName, ts.createIdentifier(`[${newPropertyValue}]`));

return [
new AddNodeOperation(sourceFile, lastConfigObjPropertyNode, undefined, newTargetPropertyNode),
Expand Down