UNPKG

ng-router-loader

Version:

Webpack loader for `NgModule` lazy loading using the angular router

1 lines 4.7 kB
{"version":3,"file":"builtin_codegens.js","sourceRoot":"","sources":["../../src/builtin_codegens.ts"],"names":[],"mappings":";AAAA,IAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,IAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;AAClC,IAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAKhC,0BAA0B,IAAY,EAAE,MAAc;IACpD,MAAM,CAAC,YAAY,GAAG,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AACzD,CAAC;AAEY,QAAA,WAAW,GACtB,UAAC,IAAY,EAAE,MAAc,IAAK,OAAA,qCAAmC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,QAAK,EAAtE,CAAsE,CAAC;AAE9F,QAAA,aAAa,GAAkB,UAAC,IAAY,EAAE,MAAc,EAC5B,aAAkC,EAClC,eAAqC;IAChF,IAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrD,IAAM,gBAAgB,GAAG,eAAe,CAAC,SAAS,GAAG,QAAM,eAAe,CAAC,SAAS,MAAG,GAAG,EAAE,CAAC;IAE7F,IAAM,MAAM,GAAG;QACb,oEAAoE;QACpE,2CAA2C;QAC3C,iBAAe,aAAa,OAAI;QAChC,QAAM,gBAAgB,OAAI;QAC1B,KAAK;KACN,CAAC;IAEF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC,CAAC;AAEW,QAAA,aAAa,GAAkB,UAAC,IAAY,EAAE,MAAc,EAAE,IAAyB;IAClG,qBAAa,CAAC,YAAY,CAAC,EAAE,CAAC;IAC9B,IAAM,MAAM,GAAG;QACb,sDAAoD,IAAI,OAAI;QAC5D,8CAA4C,MAAM,eAAY;KAC/D,CAAC;IAEF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC,CAAC;AACF,qBAAa,CAAC,YAAY,CAAC,GAAG;IAC5B,OAAO,CAAC,IAAI,CAAC,mQAAmQ,CAAC,CAAC;IAClR,qBAAa,CAAC,YAAY,CAAC,GAAG,cAAO,CAAC,CAAC;AACzC,CAAC,CAAC;AAEW,QAAA,aAAa,GAAkB,UAAC,IAAY,EAAE,MAAc,EAAE,IAAyB;IAClG,IAAM,MAAM,GAAG;QACb,gDAA8C,IAAI,OAAI;QACtD,gDAA8C,MAAM,eAAY;KACjE,CAAC;IAEF,IAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrG,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;IAEjE,MAAM,CAAC,KAAK,CAAC;AACf,CAAC,CAAC;AAGW,QAAA,iBAAiB,GAAoD;IAChF,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAW,EAAE;IACtC,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,qBAAa,EAAE;IACjD,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,qBAAa,EAAE;IAChD,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,qBAAa,EAAE;CACjD,CAAC","sourcesContent":["const recast = require(\"recast\");\nconst n = recast.types.namedTypes;\nconst b = recast.types.builders;\n\nimport { LoaderCodeGen } from './Loader';\nimport { RouterLoaderOptions, RouteResourceOptions } from './options';\n\nfunction getRequireString(file: string, module: string): string {\n return 'require(\\'' + file + '\\')[\\'' + module + '\\']';\n}\n\nexport const syncCodeGen: LoaderCodeGen =\n (file: string, module: string) => `function syncCodeGen() { return ${getRequireString(file, module)}; }`;\n\nexport const ensureCodeGen: LoaderCodeGen = (file: string, module: string,\n loaderOptions: RouterLoaderOptions,\n resourceOptions: RouteResourceOptions) => {\n const requireString = getRequireString(file, module);\n const webpackChunkName = resourceOptions.chunkName ? `, '${resourceOptions.chunkName}'` : '';\n\n const result = [\n `function ensureCodeGen() { return new Promise(function (resolve) {`,\n ` require.ensure([], function (require) {`,\n ` resolve(${requireString});`,\n ` }${webpackChunkName});`,\n `})}`\n ];\n\n return result.join('');\n};\n\nexport const systemCodeGen: LoaderCodeGen = (file: string, module: string, opts: RouterLoaderOptions) => {\n systemCodeGen['deprecated']();\n const result = [\n `function systemCodeGen() { return System.import('${file}')`,\n `.then( function(module) { return module['${module}']; } ); }`\n ];\n\n return result.join('');\n};\nsystemCodeGen['deprecated'] = () => {\n console.warn('\\nDEPRECATED: ng-router-loader \"async-system\" loader use the System.import construct which is deprecated in webpack 2 and will be removed in webpack 3, please use the \"async-import\" instead. (https://github.com/webpack/webpack/releases/tag/v2.1.0-beta.28)\\n');\n systemCodeGen['deprecated'] = () => {};\n};\n\nexport const importCodeGen: LoaderCodeGen = (file: string, module: string, opts: RouterLoaderOptions) => {\n const result = [\n `function importCodeGen() { return import_('${file}')`,\n ` .then( function(module) { return module['${module}']; } ); }`\n ];\n\n const fnDec = recast.parse(result.join(''), { ecmaVersion: 5, sourceType: 'script'}).program.body[0];\n n.FunctionDeclaration.assert(fnDec);\n fnDec.body.body[0].argument.callee.object.callee.name = 'import';\n\n return fnDec;\n};\n\n\nexport const BUILT_IN_CODEGENS: Array<{ name: string, codeGen: LoaderCodeGen }> = [\n { name: 'sync', codeGen: syncCodeGen },\n { name: 'async-require', codeGen: ensureCodeGen },\n { name: 'async-import', codeGen: importCodeGen },\n { name: 'async-system', codeGen: systemCodeGen }\n];\n"]}