From c948cf6406902261c73e9ba91d9b6651bfae9ef1 Mon Sep 17 00:00:00 2001 From: irustm Date: Sat, 16 Oct 2021 19:48:30 +0300 Subject: [PATCH] added guess dist folder --- .../guess/packages/common/interfaces.js | 12 + .../guess/packages/common/interfaces.js.map | 1 + .../guess-parser/src/angular/index.js | 5 + .../guess-parser/src/angular/index.js.map | 1 + .../guess-parser/src/angular/modules.js | 243 ++++++++++++++++++ .../guess-parser/src/angular/modules.js.map | 1 + .../guess-parser/src/angular/route-parser.js | 95 +++++++ .../src/angular/route-parser.js.map | 1 + .../guess-parser/src/angular/routes.js | 144 +++++++++++ .../guess-parser/src/angular/routes.js.map | 1 + 10 files changed, 504 insertions(+) create mode 100644 guess-dist/guess/packages/common/interfaces.js create mode 100644 guess-dist/guess/packages/common/interfaces.js.map create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/index.js create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/index.js.map create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/modules.js create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/modules.js.map create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/route-parser.js create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/route-parser.js.map create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/routes.js create mode 100644 guess-dist/guess/packages/guess-parser/src/angular/routes.js.map diff --git a/guess-dist/guess/packages/common/interfaces.js b/guess-dist/guess/packages/common/interfaces.js new file mode 100644 index 0000000..790a45d --- /dev/null +++ b/guess-dist/guess/packages/common/interfaces.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ProjectType = void 0; +var ProjectType; +(function (ProjectType) { + ProjectType["AngularCLI"] = "angular-cli"; + ProjectType["CreateReactApp"] = "create-react-app"; + ProjectType["PreactCLI"] = "preact-cli"; + ProjectType["Gatsby"] = "gatsby"; + ProjectType["CreateReactAppTypeScript"] = "create-react-app-typescript"; +})(ProjectType = exports.ProjectType || (exports.ProjectType = {})); +//# sourceMappingURL=interfaces.js.map \ No newline at end of file diff --git a/guess-dist/guess/packages/common/interfaces.js.map b/guess-dist/guess/packages/common/interfaces.js.map new file mode 100644 index 0000000..28ac8b2 --- /dev/null +++ b/guess-dist/guess/packages/common/interfaces.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../guess/packages/common/interfaces.ts"],"names":[],"mappings":";;;AAgCA,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,yCAA0B,CAAA;IAC1B,kDAAmC,CAAA;IACnC,uCAAwB,CAAA;IACxB,gCAAiB,CAAA;IACjB,uEAAwD,CAAA;AAC1D,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB"} \ No newline at end of file diff --git a/guess-dist/guess/packages/guess-parser/src/angular/index.js b/guess-dist/guess/packages/guess-parser/src/angular/index.js new file mode 100644 index 0000000..a070881 --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/index.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tslib_1 = require("tslib"); +tslib_1.__exportStar(require("./route-parser"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/guess-dist/guess/packages/guess-parser/src/angular/index.js.map b/guess-dist/guess/packages/guess-parser/src/angular/index.js.map new file mode 100644 index 0000000..6b628e3 --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../guess/packages/guess-parser/src/angular/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B"} \ No newline at end of file diff --git a/guess-dist/guess/packages/guess-parser/src/angular/modules.js b/guess-dist/guess/packages/guess-parser/src/angular/modules.js new file mode 100644 index 0000000..7ca1457 --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/modules.js @@ -0,0 +1,243 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getLazyEntryPoints = exports.getModuleEntryPoint = exports.cleanModuleCache = exports.getModulePathFromRoute = exports.findMainModule = exports.collectRoutingModules = exports.findRootModule = exports.findRootModules = void 0; +const ts = require("typescript"); +const path_1 = require("path"); +const fs_1 = require("fs"); +const routes_1 = require("./routes"); +exports.findRootModules = (registry) => { + const roots = getRootModules(registry); + roots.length > 1 && console.log("Root Modules:", roots.length); + return roots; +}; +exports.findRootModule = (registry) => { + const roots = getRootModules(registry); + if (roots.length > 1) { + throw new Error('Multiple root routing modules found ' + roots.join(', ')); + } + return roots[0]; +}; +function getRootModules(registry) { + const childModules = new Set(); + const traverseRoute = (route) => { + if (route.module) { + childModules.add(route.module); + } + route.children.forEach(traverseRoute); + }; + const allModulePaths = Object.keys(registry); + allModulePaths.forEach(path => { + const declaration = registry[path]; + // It's possible if the declaration does not exist + // See https://github.com/guess-js/guess/issues/311 + if (declaration) { + declaration.eagerRoutes.forEach(traverseRoute); + declaration.lazyRoutes.forEach(traverseRoute); + } + }); + return allModulePaths.filter(m => !childModules.has(m)); +} +exports.collectRoutingModules = (rootFile, registry, result, parentFilePath = rootFile, currentRoutePath = '', existing = new Set()) => { + const declaration = registry[rootFile]; + // It's possible if the declaration does not exist + // See https://github.com/guess-js/guess/issues/311 + if (!declaration) { + return; + } + const process = (r, routePath = currentRoutePath) => { + if (r.module) { + // tslint:disable-next-line: no-use-before-declare + return processLazyRoute(r, routePath); + } + // tslint:disable-next-line: no-use-before-declare + return processRoute(r, routePath); + }; + const processRoute = (r, routePath = currentRoutePath) => { + const path = (routePath + '/' + r.path).replace(/\/$/, ''); + r.children.forEach(route => process(route, path)); + if (!existing.has(path)) { + const routingModule = { + path, + lazy: parentFilePath !== rootFile && r.redirectTo === undefined, + modulePath: rootFile, + parentModulePath: parentFilePath, + }; + if (r.redirectTo !== undefined) { + routingModule.redirectTo = r.redirectTo; + } + result.push(routingModule); + existing.add(path); + } + }; + const processLazyRoute = (r, routePath = currentRoutePath) => { + const path = (routePath + '/' + r.path).replace(/\/$/, ''); + r.children.forEach(route => process(route, path)); + exports.collectRoutingModules(r.module, registry, result, rootFile, path); + }; + declaration.eagerRoutes.forEach(r => processRoute(r)); + declaration.lazyRoutes.forEach(r => processLazyRoute(r)); +}; +exports.findMainModule = (program) => { + const tryFindMainModule = (n, sf) => { + if (n.kind === ts.SyntaxKind.Identifier && + n.text === 'bootstrapModule') { + const propAccess = n.parent; + if (!propAccess || + propAccess.kind !== ts.SyntaxKind.PropertyAccessExpression) { + return null; + } + const tempExpr = propAccess.parent; + if (!tempExpr || tempExpr.kind !== ts.SyntaxKind.CallExpression) { + return null; + } + const expr = tempExpr; + const module = expr.arguments[0]; + const tc = program.getTypeChecker(); + const symbol = tc.getTypeAtLocation(module).getSymbol(); + if (!symbol) { + return null; + } + const decl = symbol.getDeclarations(); + if (!decl) { + return null; + } + return path_1.resolve(decl[0].getSourceFile().fileName); + } + let mainPath = null; + n.forEachChild(c => { + if (mainPath) { + return mainPath; + } + mainPath = tryFindMainModule(c, sf); + }); + return mainPath; + }; + return program.getSourceFiles().reduce((a, sf) => { + if (a) { + return a; + } + let mainPath = null; + sf.forEachChild(n => { + if (mainPath) { + return; + } + mainPath = tryFindMainModule(n, sf); + }); + return mainPath; + }, null); +}; +const isImportDeclaration = (node) => { + return node.kind === ts.SyntaxKind.ImportDeclaration; +}; +const isReExportDeclaration = (node) => { + return (node.kind === ts.SyntaxKind.ExportDeclaration && node.exportClause === undefined); +}; +const normalizeFilePath = (path) => { + return path_1.join(...path.split(/\//).map((part, index) => (part === '' && index === 0) ? path_1.sep : part)); +}; +exports.getModulePathFromRoute = (parentPath, loadChildren, program, host) => { + const childModule = loadChildren.split('#')[0]; + const { resolvedModule } = ts.resolveModuleName(childModule, parentPath, program.getCompilerOptions(), host); + if (resolvedModule) { + return normalizeFilePath(resolvedModule.resolvedFileName); + } + const childModuleFile = childModule + '.ts'; + const parentSegments = path_1.dirname(parentPath).split(path_1.sep); + const childSegments = childModuleFile.split('/'); + const max = Math.min(parentSegments.length, childSegments.length); + let maxCommon = 0; + for (let i = 1; i < max; i += 1) { + for (let j = 0; j < i; j += 1) { + let common = 0; + if (parentSegments[parentSegments.length - 1 - j] === childSegments[j]) { + common++; + maxCommon = Math.max(maxCommon, common); + } + else { + // breaking here + common = 0; + j = i; + } + } + } + const path = path_1.join(path_1.dirname(parentPath), childModuleFile + .split('/') + .slice(maxCommon, childSegments.length) + .join('/')); + // This early failure provides better error message compared to the + // generic "Multiple root routing modules" error. + if (!fs_1.existsSync(path)) { + throw new Error(`The relative path "${loadChildren}" to "${parentPath}" cannot be resolved to a module`); + } + return path; +}; +const imports = (parent, child, program, host, importCache, visited = {}) => { + if (importCache[parent] && importCache[parent][child] !== undefined) { + return importCache[parent][child]; + } + importCache[parent] = importCache[parent] || {}; + const sf = program.getSourceFile(parent); + if (!sf) { + importCache[parent][child] = false; + return false; + } + if (visited[parent]) { + importCache[parent][child] = false; + return false; + } + visited[parent] = true; + let found = false; + sf.forEachChild(n => { + if (found) { + return; + } + if (!isImportDeclaration(n) && !isReExportDeclaration(n)) { + return; + } + const path = n.moduleSpecifier.text; + const { resolvedModule } = ts.resolveModuleName(path, parent, program.getCompilerOptions(), host); + if (resolvedModule === undefined) { + return; + } + const fullPath = normalizeFilePath(resolvedModule.resolvedFileName); + if (fullPath === child) { + found = true; + } + // We don't want to dig into node_modules to find an entry point. + if (!found && fs_1.existsSync(fullPath) && !fullPath.includes('node_modules')) { + found = imports(fullPath, child, program, host, importCache, visited); + } + }); + importCache[parent][child] = found; + return found; +}; +let cache = {}; +exports.cleanModuleCache = () => (cache = {}); +// This can potentially break if there's a lazy module +// that is not only loaded lazily but also imported +// inside of a parent module. +// +// For example, `app.module.ts` lazily loads `bar.module.ts` +// in the same time `app.module.ts` imports `bar.module.ts` +// this way the module entry point will be `app.module.ts`. +exports.getModuleEntryPoint = (path, entryPoints, program, host) => { + const parents = [...entryPoints].filter(e => imports(e, path, program, host, cache)); + // If no parents, this could be the root module + if (parents.length === 0) { + return path; + } + if (parents.length > 1) { + throw new Error(`Module ${path} belongs to more than one module: ${parents.join(', ')}`); + } + return parents[0]; +}; +exports.getLazyEntryPoints = (node, program, host) => { + const value = routes_1.readLoadChildren(node, program.getTypeChecker()); + if (!value) { + return null; + } + const parent = path_1.resolve(node.getSourceFile().fileName); + const module = exports.getModulePathFromRoute(parent, value, program, host); + return module; +}; +//# sourceMappingURL=modules.js.map \ No newline at end of file diff --git a/guess-dist/guess/packages/guess-parser/src/angular/modules.js.map b/guess-dist/guess/packages/guess-parser/src/angular/modules.js.map new file mode 100644 index 0000000..659cfbf --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/modules.js.map @@ -0,0 +1 @@ +{"version":3,"file":"modules.js","sourceRoot":"","sources":["../../../../../../guess/packages/guess-parser/src/angular/modules.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,+BAAmD;AACnD,2BAAgC;AAChC,qCAA8D;AAajD,QAAA,eAAe,GAAG,CAAC,QAAkB,EAAY,EAAE;IAC9D,MAAM,KAAK,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEvC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC9D,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEW,QAAA,cAAc,GAAG,CAAC,QAAkB,EAAU,EAAE;IAC3D,MAAM,KAAK,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEvC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;KAC5E;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC;AAEF,SAAS,cAAc,CAAC,QAAkB;IACxC,MAAM,YAAY,GAAG,IAAI,GA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-dist/guess/packages/guess-parser/src/angular/route-parser.js b/guess-dist/guess/packages/guess-parser/src/angular/route-parser.js new file mode 100644 index 0000000..73bb4ec --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/route-parser.js @@ -0,0 +1,95 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseRoutes = void 0; +const ts = require("typescript"); +const fs_1 = require("fs"); +const path_1 = require("path"); +const modules_1 = require("./modules"); +const routes_1 = require("./routes"); +const defaultOptions = { + redirects: false, +}; +const normalizeOptions = (options) => (Object.assign(Object.assign({}, defaultOptions), options)); +exports.parseRoutes = (tsconfig, exclude = [], inputOptions = {}) => { + const options = normalizeOptions(inputOptions); + modules_1.cleanModuleCache(); + const parseConfigHost = { + fileExists: fs_1.existsSync, + readDirectory: ts.sys.readDirectory, + readFile: file => fs_1.readFileSync(file, 'utf8'), + useCaseSensitiveFileNames: true + }; + const config = ts.readConfigFile(tsconfig, path => fs_1.readFileSync(path).toString()); + const parsed = ts.parseJsonConfigFileContent(config.config, parseConfigHost, path_1.resolve(path_1.dirname(tsconfig)), { + noEmit: true + }); + const host = ts.createCompilerHost(parsed.options, true); + const program = ts.createProgram(parsed.fileNames, parsed.options, host); + const typeChecker = program.getTypeChecker(); + const toAbsolute = (file) => file.startsWith('/') || file.startsWith(process.cwd()) ? file : path_1.join(process.cwd(), file); + const excludeFiles = new Set(exclude.map(toAbsolute)); + const visitTopLevelRoutes = (s, callback, n) => { + if (excludeFiles.has(path_1.resolve(s.fileName))) { + return; + } + if (!n) { + return; + } + if (routes_1.isRoute(n, typeChecker, options.redirects)) { + callback(n); + } + else { + n.forEachChild(visitTopLevelRoutes.bind(null, s, callback)); + } + }; + const mainPath = modules_1.findMainModule(program); + if (!mainPath) { + throw new Error('Cannot find the main application module'); + } + const entryPoints = new Set([mainPath]); + const collectEntryPoints = (n) => { + const path = modules_1.getLazyEntryPoints(n, program, host); + if (!path) { + const childrenArray = routes_1.readChildren(n); + if (childrenArray) { + childrenArray.forEach(collectEntryPoints); + } + return; + } + entryPoints.add(path); + }; + program.getSourceFiles().map(s => { + s.forEachChild(visitTopLevelRoutes.bind(null, s, collectEntryPoints)); + }); + const registry = {}; + program.getSourceFiles().map(s => { + s.forEachChild(visitTopLevelRoutes.bind(null, s, (n) => { + const path = path_1.resolve(n.getSourceFile().fileName); + const route = routes_1.getRoute(n, entryPoints, program, host); + if (!route) { + return; + } + const modulePath = modules_1.getModuleEntryPoint(path, entryPoints, program, host); + const current = registry[modulePath] || { + lazyRoutes: [], + eagerRoutes: [] + }; + if (route.module) { + current.lazyRoutes.push(route); + } + else { + current.eagerRoutes.push(route); + } + registry[modulePath] = current; + })); + }); + const result = []; + if (Object.keys(registry).length > 0) { + const roots = modules_1.findRootModules(registry); + for (const root of roots) { + modules_1.collectRoutingModules(root, registry, result); + } + } + return result; +}; +//# sourceMappingURL=route-parser.js.map \ No newline at end of file diff --git a/guess-dist/guess/packages/guess-parser/src/angular/route-parser.js.map b/guess-dist/guess/packages/guess-parser/src/angular/route-parser.js.map new file mode 100644 index 0000000..08d520a --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/route-parser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"route-parser.js","sourceRoot":"","sources":["../../../../../../guess/packages/guess-parser/src/angular/route-parser.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,2BAA8C;AAC9C,+BAA8C;AAC9C,uCAQmB;AACnB,qCAAsE;AAMtE,MAAM,cAAc,GAAY;IAC9B,SAAS,EAAE,KAAK;CACjB,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,OAAyB,EAAE,EAAE,CAAC,iCACnD,cAAc,GACd,OAAO,EACV,CAAC;AAEU,QAAA,WAAW,GAAG,CACzB,QAAgB,EAChB,UAAoB,EAAE,EACtB,eAAiC,EAAE,EAClB,EAAE;IAEnB,MAAM,OAAO,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC/C,0BAAgB,EAAE,CA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/guess-dist/guess/packages/guess-parser/src/angular/routes.js b/guess-dist/guess/packages/guess-parser/src/angular/routes.js new file mode 100644 index 0000000..9393d64 --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/routes.js @@ -0,0 +1,144 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isRoute = exports.getRoute = exports.readChildren = exports.readLoadChildren = void 0; +const ts = require("typescript"); +const ts_evaluator_1 = require("ts-evaluator"); +const modules_1 = require("./modules"); +const path_1 = require("path"); +const getObjectProp = (node, prop) => { + const vals = node.properties.values(); + for (const val of vals) { + if (val.kind !== ts.SyntaxKind.PropertyAssignment) { + continue; + } + const value = val; + if (value.name.kind !== ts.SyntaxKind.Identifier) { + continue; + } + const name = value.name.text; + if (name === prop) { + return value.initializer; + } + } + return null; +}; +exports.readLoadChildren = (node, typeChecker) => { + const expr = getObjectProp(node, 'loadChildren'); + if (!expr) { + return null; + } + if (expr.kind === ts.SyntaxKind.StringLiteral) { + return expr.text; + } + let result = null; + const visitor = (n) => { + if (n.kind === ts.SyntaxKind.ImportKeyword) { + const parent = n.parent; + const arg = parent.arguments[0]; + const res = ts_evaluator_1.evaluate({ + node: arg, + typeChecker: typeChecker + }); + if (res.success) { + result = res.value; + } + } + if (result) { + return; + } + n.forEachChild(visitor); + }; + expr.forEachChild(visitor); + // Fallback to when loadChildren looks like: + // loadChildren: 'foo' + '/' + 'bar' + if (!result) { + const res = ts_evaluator_1.evaluate({ + node: expr, + typeChecker: typeChecker + }); + if (res.success) { + result = res.value; + } + } + return result; +}; +const readPath = (node, typeChecker) => { + const expr = getObjectProp(node, 'path'); + if (!expr) { + return null; + } + const val = ts_evaluator_1.evaluate({ + node: expr, + typeChecker + }); + if (val.success) { + return val.value; + } + return null; +}; +const readRedirect = (node, typeChecker) => { + const expr = getObjectProp(node, 'redirectTo'); + if (!expr) { + return null; + } + const val = ts_evaluator_1.evaluate({ + node: expr, + typeChecker + }); + if (val.success) { + return val.value; + } + return null; +}; +exports.readChildren = (node) => { + const expr = getObjectProp(node, 'children'); + if (!expr) { + return null; + } + return expr.elements; +}; +exports.getRoute = (node, entryPoints, program, host) => { + const path = readPath(node, program.getTypeChecker()); + if (path === null) { + return null; + } + const childrenArray = exports.readChildren(node); + let children = []; + if (childrenArray) { + children = childrenArray + .map(c => { + if (c.kind !== ts.SyntaxKind.ObjectLiteralExpression) { + return null; + } + return exports.getRoute(c, entryPoints, program, host); + }) + .filter(e => e !== null); + } + const route = { path, children }; + const redirectTo = readRedirect(node, program.getTypeChecker()); + if (redirectTo) { + route.redirectTo = redirectTo; + } + const loadChildren = exports.readLoadChildren(node, program.getTypeChecker()); + if (loadChildren) { + const parent = modules_1.getModuleEntryPoint(path_1.resolve(node.getSourceFile().fileName), entryPoints, program, host); + const module = modules_1.getModulePathFromRoute(parent, loadChildren, program, host); + return Object.assign(Object.assign({}, route), { module }); + } + return route; +}; +exports.isRoute = (n, typeChecker, redirects) => { + if (n.kind !== ts.SyntaxKind.ObjectLiteralExpression || + !n.parent || + n.parent.kind !== ts.SyntaxKind.ArrayLiteralExpression) { + return false; + } + const objLiteral = n; + const path = readPath(objLiteral, typeChecker) !== null; + const redirectTo = redirects && readRedirect(objLiteral, typeChecker) !== null; + const children = !!exports.readChildren(objLiteral); + const loadChildren = !!exports.readLoadChildren(objLiteral, typeChecker); + const component = !!getObjectProp(objLiteral, 'component'); + return (path && children) || (path && component) || (path && loadChildren) || (path && redirectTo); +}; +//# sourceMappingURL=routes.js.map \ No newline at end of file diff --git a/guess-dist/guess/packages/guess-parser/src/angular/routes.js.map b/guess-dist/guess/packages/guess-parser/src/angular/routes.js.map new file mode 100644 index 0000000..c695b93 --- /dev/null +++ b/guess-dist/guess/packages/guess-parser/src/angular/routes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../../../../guess/packages/guess-parser/src/angular/routes.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,+CAAwC;AACxC,uCAAwE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