Skip to content

Instantly share code, notes, and snippets.

@phenomnomnominal
Created March 11, 2019 11:07
Show Gist options
  • Save phenomnomnominal/3ee7e8aa7a4985879f7a400779293d11 to your computer and use it in GitHub Desktop.
Save phenomnomnominal/3ee7e8aa7a4985879f7a400779293d11 to your computer and use it in GitHub Desktop.
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