Created
March 11, 2019 11:07
-
-
Save phenomnomnominal/3ee7e8aa7a4985879f7a400779293d11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Rule extends Rules.AbstractRule { | |
public apply(sourceFile: SourceFile): Array<RuleFailure> { | |
// ... | |
let fix = preferAsync === 'async' ? this._asyncReplacement(valueNode.text) : this._promiseReplacement(valueNode.text); | |
// ... | |
} | |
private _promiseReplacement (loadChildren: string): string { | |
const [path, moduleName] = this._getChunks(loadChildren); | |
return `() => import('${path}').then(m => m.${moduleName})`; | |
} | |
private _asyncReplacement (loadChildren: string): string { | |
const [path, moduleName] = this._getChunks(loadChildren); | |
return `async () => { | |
const { ${moduleName} } = await import('${path}'); | |
return ${moduleName}; | |
}`; | |
} | |
private _getChunks (loadChildren: string): Array<string> { | |
return loadChildren.split(LOAD_CHILDREN_SPLIT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment