@sentry/react 7.0.0-alpha.1 → 7.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +2 -3
  2. package/cjs/constants.js +12 -5
  3. package/cjs/constants.js.map +1 -1
  4. package/cjs/errorboundary.js +139 -112
  5. package/cjs/errorboundary.js.map +1 -1
  6. package/cjs/flags.js +7 -3
  7. package/cjs/flags.js.map +1 -1
  8. package/cjs/index.js +30 -21
  9. package/cjs/index.js.map +1 -1
  10. package/cjs/profiler.js +178 -147
  11. package/cjs/profiler.js.map +1 -1
  12. package/cjs/reactrouter.js +147 -100
  13. package/cjs/reactrouter.js.map +1 -1
  14. package/cjs/reactrouterv3.js +107 -83
  15. package/cjs/reactrouterv3.js.map +1 -1
  16. package/cjs/reactrouterv6.js +163 -0
  17. package/cjs/reactrouterv6.js.map +1 -0
  18. package/cjs/redux.js +51 -42
  19. package/cjs/redux.js.map +1 -1
  20. package/cjs/sdk.js +18 -15
  21. package/cjs/sdk.js.map +1 -1
  22. package/esm/constants.js +8 -4
  23. package/esm/constants.js.map +1 -1
  24. package/esm/errorboundary.js +124 -107
  25. package/esm/errorboundary.js.map +1 -1
  26. package/esm/flags.js +5 -2
  27. package/esm/flags.js.map +1 -1
  28. package/esm/index.js +8 -7
  29. package/esm/index.js.map +1 -1
  30. package/esm/profiler.js +161 -140
  31. package/esm/profiler.js.map +1 -1
  32. package/esm/reactrouter.js +133 -94
  33. package/esm/reactrouter.js.map +1 -1
  34. package/esm/reactrouterv3.js +103 -79
  35. package/esm/reactrouterv3.js.map +1 -1
  36. package/esm/reactrouterv6.js +153 -0
  37. package/esm/reactrouterv6.js.map +1 -0
  38. package/esm/redux.js +49 -41
  39. package/esm/redux.js.map +1 -1
  40. package/esm/sdk.js +17 -14
  41. package/esm/sdk.js.map +1 -1
  42. package/package.json +5 -5
  43. package/types/errorboundary.d.ts +1 -0
  44. package/types/errorboundary.d.ts.map +1 -1
  45. package/types/index.d.ts +1 -0
  46. package/types/index.d.ts.map +1 -1
  47. package/types/reactrouterv6.d.ts +27 -0
  48. package/types/reactrouterv6.d.ts.map +1 -0
  49. package/cjs/constants.d.ts +0 -4
  50. package/cjs/constants.d.ts.map +0 -1
  51. package/cjs/errorboundary.d.ts +0 -62
  52. package/cjs/errorboundary.d.ts.map +0 -1
  53. package/cjs/flags.d.ts +0 -3
  54. package/cjs/flags.d.ts.map +0 -1
  55. package/cjs/index.d.ts +0 -8
  56. package/cjs/index.d.ts.map +0 -1
  57. package/cjs/profiler.d.ts +0 -54
  58. package/cjs/profiler.d.ts.map +0 -1
  59. package/cjs/reactrouter.d.ts +0 -25
  60. package/cjs/reactrouter.d.ts.map +0 -1
  61. package/cjs/reactrouterv3.d.ts +0 -26
  62. package/cjs/reactrouterv3.d.ts.map +0 -1
  63. package/cjs/redux.d.ts +0 -33
  64. package/cjs/redux.d.ts.map +0 -1
  65. package/cjs/sdk.d.ts +0 -6
  66. package/cjs/sdk.d.ts.map +0 -1
  67. package/cjs/types.d.ts +0 -8
  68. package/cjs/types.d.ts.map +0 -1
  69. package/cjs/types.js +0 -2
  70. package/cjs/types.js.map +0 -1
  71. package/esm/constants.d.ts +0 -4
  72. package/esm/constants.d.ts.map +0 -1
  73. package/esm/errorboundary.d.ts +0 -62
  74. package/esm/errorboundary.d.ts.map +0 -1
  75. package/esm/flags.d.ts +0 -3
  76. package/esm/flags.d.ts.map +0 -1
  77. package/esm/index.d.ts +0 -8
  78. package/esm/index.d.ts.map +0 -1
  79. package/esm/profiler.d.ts +0 -54
  80. package/esm/profiler.d.ts.map +0 -1
  81. package/esm/reactrouter.d.ts +0 -25
  82. package/esm/reactrouter.d.ts.map +0 -1
  83. package/esm/reactrouterv3.d.ts +0 -26
  84. package/esm/reactrouterv3.d.ts.map +0 -1
  85. package/esm/redux.d.ts +0 -33
  86. package/esm/redux.d.ts.map +0 -1
  87. package/esm/sdk.d.ts +0 -6
  88. package/esm/sdk.d.ts.map +0 -1
  89. package/esm/types.d.ts +0 -8
  90. package/esm/types.d.ts.map +0 -1
  91. package/esm/types.js +0 -1
  92. package/esm/types.js.map +0 -1
@@ -1,119 +1,166 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- var tslib_1 = require("tslib");
3
- var utils_1 = require("@sentry/utils");
4
- var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
5
- var React = tslib_1.__importStar(require("react"));
6
- /* eslint-enable @typescript-eslint/no-explicit-any */
7
- var global = utils_1.getGlobalObject();
8
- var activeTransaction;
9
- function reactRouterV4Instrumentation(history, routes, matchPath) {
10
- return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
1
+ var {
2
+ _interopDefault,
3
+ _interopNamespace
4
+ } = require('@sentry/utils/cjs/buildPolyfills');
5
+
6
+ Object.defineProperty(exports, '__esModule', { value: true });
7
+
8
+ var utils = require('@sentry/utils');
9
+ var hoistNonReactStatics = require('hoist-non-react-statics');
10
+ var React = require('react');
11
+
12
+ var hoistNonReactStatics__default = /*#__PURE__*/_interopDefault(hoistNonReactStatics);
13
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
14
+
15
+ var _jsxFileName = "/home/runner/work/sentry-javascript/sentry-javascript/packages/react/src/reactrouter.tsx";
16
+
17
+ // We need to disable eslint no-explict-any because any is required for the
18
+ // react-router typings.
19
+
20
+ var global = utils.getGlobalObject();
21
+
22
+ let activeTransaction;
23
+
24
+ function reactRouterV4Instrumentation(
25
+ history,
26
+ routes,
27
+ matchPath,
28
+ ) {
29
+ return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
11
30
  }
12
- exports.reactRouterV4Instrumentation = reactRouterV4Instrumentation;
13
- function reactRouterV5Instrumentation(history, routes, matchPath) {
14
- return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
31
+
32
+ function reactRouterV5Instrumentation(
33
+ history,
34
+ routes,
35
+ matchPath,
36
+ ) {
37
+ return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
15
38
  }
16
- exports.reactRouterV5Instrumentation = reactRouterV5Instrumentation;
17
- function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
18
- if (allRoutes === void 0) { allRoutes = []; }
19
- function getInitPathName() {
20
- if (history && history.location) {
21
- return history.location.pathname;
22
- }
23
- if (global && global.location) {
24
- return global.location.pathname;
25
- }
26
- return undefined;
39
+
40
+ function createReactRouterInstrumentation(
41
+ history,
42
+ name,
43
+ allRoutes = [],
44
+ matchPath,
45
+ ) {
46
+ function getInitPathName() {
47
+ if (history && history.location) {
48
+ return history.location.pathname;
27
49
  }
28
- function getTransactionName(pathname) {
29
- if (allRoutes.length === 0 || !matchPath) {
30
- return pathname;
31
- }
32
- var branches = matchRoutes(allRoutes, pathname, matchPath);
33
- // eslint-disable-next-line @typescript-eslint/prefer-for-of
34
- for (var x = 0; x < branches.length; x++) {
35
- if (branches[x].match.isExact) {
36
- return branches[x].match.path;
37
- }
38
- }
39
- return pathname;
50
+
51
+ if (global && global.location) {
52
+ return global.location.pathname;
40
53
  }
41
- return function (customStartTransaction, startTransactionOnPageLoad, startTransactionOnLocationChange) {
42
- if (startTransactionOnPageLoad === void 0) { startTransactionOnPageLoad = true; }
43
- if (startTransactionOnLocationChange === void 0) { startTransactionOnLocationChange = true; }
44
- var initPathName = getInitPathName();
45
- if (startTransactionOnPageLoad && initPathName) {
46
- activeTransaction = customStartTransaction({
47
- name: getTransactionName(initPathName),
48
- op: 'pageload',
49
- tags: {
50
- 'routing.instrumentation': name,
51
- },
52
- });
53
- }
54
- if (startTransactionOnLocationChange && history.listen) {
55
- history.listen(function (location, action) {
56
- if (action && (action === 'PUSH' || action === 'POP')) {
57
- if (activeTransaction) {
58
- activeTransaction.finish();
59
- }
60
- var tags = {
61
- 'routing.instrumentation': name,
62
- };
63
- activeTransaction = customStartTransaction({
64
- name: getTransactionName(location.pathname),
65
- op: 'navigation',
66
- tags: tags,
67
- });
68
- }
69
- });
54
+
55
+ return undefined;
56
+ }
57
+
58
+ function getTransactionName(pathname) {
59
+ if (allRoutes.length === 0 || !matchPath) {
60
+ return pathname;
61
+ }
62
+
63
+ var branches = matchRoutes(allRoutes, pathname, matchPath);
64
+ for (let x = 0; x < branches.length; x++) {
65
+ if (branches[x].match.isExact) {
66
+ return branches[x].match.path;
67
+ }
68
+ }
69
+
70
+ return pathname;
71
+ }
72
+
73
+ return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true) => {
74
+ var initPathName = getInitPathName();
75
+ if (startTransactionOnPageLoad && initPathName) {
76
+ activeTransaction = customStartTransaction({
77
+ name: getTransactionName(initPathName),
78
+ op: 'pageload',
79
+ tags: {
80
+ 'routing.instrumentation': name,
81
+ },
82
+ });
83
+ }
84
+
85
+ if (startTransactionOnLocationChange && history.listen) {
86
+ history.listen((location, action) => {
87
+ if (action && (action === 'PUSH' || action === 'POP')) {
88
+ if (activeTransaction) {
89
+ activeTransaction.finish();
90
+ }
91
+ var tags = {
92
+ 'routing.instrumentation': name,
93
+ };
94
+
95
+ activeTransaction = customStartTransaction({
96
+ name: getTransactionName(location.pathname),
97
+ op: 'navigation',
98
+ tags,
99
+ });
70
100
  }
71
- };
101
+ });
102
+ }
103
+ };
72
104
  }
105
+
73
106
  /**
74
107
  * Matches a set of routes to a pathname
75
108
  * Based on implementation from
76
109
  */
77
- function matchRoutes(routes, pathname, matchPath, branch) {
78
- if (branch === void 0) { branch = []; }
79
- routes.some(function (route) {
80
- var match = route.path
81
- ? matchPath(pathname, route)
82
- : branch.length
83
- ? branch[branch.length - 1].match // use parent match
84
- : computeRootMatch(pathname); // use default "root" match
85
- if (match) {
86
- branch.push({ route: route, match: match });
87
- if (route.routes) {
88
- matchRoutes(route.routes, pathname, matchPath, branch);
89
- }
90
- }
91
- return !!match;
92
- });
93
- return branch;
110
+ function matchRoutes(
111
+ routes,
112
+ pathname,
113
+ matchPath,
114
+ branch = [],
115
+ ) {
116
+ routes.some(route => {
117
+ var match = route.path
118
+ ? matchPath(pathname, route)
119
+ : branch.length
120
+ ? branch[branch.length - 1].match // use parent match
121
+ : computeRootMatch(pathname); // use default "root" match
122
+
123
+ if (match) {
124
+ branch.push({ route, match });
125
+
126
+ if (route.routes) {
127
+ matchRoutes(route.routes, pathname, matchPath, branch);
128
+ }
129
+ }
130
+
131
+ return !!match;
132
+ });
133
+
134
+ return branch;
94
135
  }
136
+
95
137
  function computeRootMatch(pathname) {
96
- return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
138
+ return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
97
139
  }
98
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
140
+
99
141
  function withSentryRouting(Route) {
100
- var componentDisplayName = Route.displayName || Route.name;
101
- var WrappedRoute = function (props) {
102
- if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
103
- activeTransaction.setName(props.computedMatch.path);
104
- }
105
- // @ts-ignore Setting more specific React Component typing for `R` generic above
106
- // will break advanced type inference done by react router params:
107
- // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
108
- return React.createElement(Route, tslib_1.__assign({}, props));
109
- };
110
- WrappedRoute.displayName = "sentryRoute(" + componentDisplayName + ")";
111
- hoist_non_react_statics_1.default(WrappedRoute, Route);
142
+ var componentDisplayName = (Route ).displayName || (Route ).name;
143
+
144
+ var WrappedRoute = (props) => {
145
+ if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
146
+ activeTransaction.setName(props.computedMatch.path);
147
+ }
148
+
112
149
  // @ts-ignore Setting more specific React Component typing for `R` generic above
113
150
  // will break advanced type inference done by react router params:
114
151
  // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
115
- return WrappedRoute;
152
+ return React__namespace.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 163}} );
153
+ };
154
+
155
+ WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
156
+ hoistNonReactStatics__default(WrappedRoute, Route);
157
+ // @ts-ignore Setting more specific React Component typing for `R` generic above
158
+ // will break advanced type inference done by react router params:
159
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
160
+ return WrappedRoute;
116
161
  }
162
+
163
+ exports.reactRouterV4Instrumentation = reactRouterV4Instrumentation;
164
+ exports.reactRouterV5Instrumentation = reactRouterV5Instrumentation;
117
165
  exports.withSentryRouting = withSentryRouting;
118
- /* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
119
- //# sourceMappingURL=reactrouter.js.map
166
+ //# sourceMappingURL=reactrouter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactrouter.js","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":";;AACA,uCAAgD;AAChD,4FAA2D;AAC3D,mDAA+B;AAuB/B,sDAAsD;AAEtD,IAAM,MAAM,GAAG,uBAAe,EAAU,CAAC;AAEzC,IAAI,iBAA0C,CAAC;AAE/C,SAAgB,4BAA4B,CAC1C,OAAsB,EACtB,MAAsB,EACtB,SAAqB;IAErB,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACzF,CAAC;AAND,oEAMC;AAED,SAAgB,4BAA4B,CAC1C,OAAsB,EACtB,MAAsB,EACtB,SAAqB;IAErB,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACzF,CAAC;AAND,oEAMC;AAED,SAAS,gCAAgC,CACvC,OAAsB,EACtB,IAAY,EACZ,SAA6B,EAC7B,SAAqB;IADrB,0BAAA,EAAA,cAA6B;IAG7B,SAAS,eAAe;QACt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AAC;AAED,SAAS,gBAAgB,CAAC,QAAgB;IACxC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,KAAK,GAAG,EAAE,CAAC;AACxE,CAAC;AAED,mGAAmG;AACnG,SAAgB,iBAAiB,CAAkE,KAAQ;IACzG,IAAM,oBAAoB,GAAI,KAAa,CAAC,WAAW,IAAK,KAAa,CAAC,IAAI,CAAC;IAE/E,IAAM,YAAY,GAAgB,UAAC,KAAQ;QACzC,IAAI,iBAAiB,IAAI,KAAK,IAAI,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE;YACpF,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;SACrD;QAED,gFAAgF;QAChF,kEAAkE;QAClE,2IAA2I;QAC3I,OAAO,oBAAC,KAAK,uBAAK,KAAK,EAAI,CAAC;IAC9B,CAAC,CAAC;IAEF,YAAY,CAAC,WAAW,GAAG,iBAAe,oBAAoB,MAAG,CAAC;IAClE,iCAAoB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC1C,gFAAgF;IAChF,kEAAkE;IAClE,2IAA2I;IAC3I,OAAO,YAAY,CAAC;AACtB,CAAC;AApBD,8CAoBC;AACD,kGAAkG","sourcesContent":["import { Transaction } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\n/* eslint-disable @typescript-eslint/no-explicit-any */\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean };\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>;\n\nexport type RouteConfig = {\n [propName: string]: any;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nconst global = getGlobalObject<Window>();\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (global && global.location) {\n return global.location.pathname;\n }\n\n return undefined;\n }\n\n function getTransactionName(pathname: string): string {\n if (allRoutes.length === 0 || !matchPath) {\n return pathname;\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return branches[x].match.path;\n }\n }\n\n return pathname;\n }\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: getTransactionName(initPathName),\n op: 'pageload',\n tags: {\n 'routing.instrumentation': name,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags = {\n 'routing.instrumentation': name,\n };\n\n activeTransaction = customStartTransaction({\n name: getTransactionName(location.pathname),\n op: 'navigation',\n tags,\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path);\n }\n\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"]}
1
+ {"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { Transaction } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\n/* eslint-disable @typescript-eslint/no-explicit-any */\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean };\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>;\n\nexport type RouteConfig = {\n [propName: string]: any;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nconst global = getGlobalObject<Window>();\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (global && global.location) {\n return global.location.pathname;\n }\n\n return undefined;\n }\n\n function getTransactionName(pathname: string): string {\n if (allRoutes.length === 0 || !matchPath) {\n return pathname;\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return branches[x].match.path;\n }\n }\n\n return pathname;\n }\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: getTransactionName(initPathName),\n op: 'pageload',\n tags: {\n 'routing.instrumentation': name,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags = {\n 'routing.instrumentation': name,\n };\n\n activeTransaction = customStartTransaction({\n name: getTransactionName(location.pathname),\n op: 'navigation',\n tags,\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path);\n }\n\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;AAOA;AACA;;AAoBA;;AAEA;;;;;;AAMA;;AAEA;;;;;;AAMA;;AAEA;;AAEA;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA;;AAEA;;;;AAIA;;;;;AAKA;;;;;;;;;;;;;;;;;;;;AAoBA;;AAEA;;AAEA;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;"}
@@ -1,6 +1,12 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- var utils_1 = require("@sentry/utils");
3
- var global = utils_1.getGlobalObject();
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var utils = require('@sentry/utils');
4
+
5
+ // Many of the types below had to be mocked out to prevent typescript issues
6
+ // these types are required for correct functionality.
7
+
8
+ var global = utils.getGlobalObject();
9
+
4
10
  /**
5
11
  * Creates routing instrumentation for React Router v3
6
12
  * Works for React Router >= 3.2.0 and < 4.0.0
@@ -9,97 +15,115 @@ var global = utils_1.getGlobalObject();
9
15
  * @param routes a list of all routes, should be
10
16
  * @param match `Router.match` utility
11
17
  */
12
- function reactRouterV3Instrumentation(history, routes, match) {
13
- return function (startTransaction, startTransactionOnPageLoad, startTransactionOnLocationChange) {
14
- if (startTransactionOnPageLoad === void 0) { startTransactionOnPageLoad = true; }
15
- if (startTransactionOnLocationChange === void 0) { startTransactionOnLocationChange = true; }
16
- var activeTransaction;
17
- var prevName;
18
- // Have to use global.location because history.location might not be defined.
19
- if (startTransactionOnPageLoad && global && global.location) {
20
- normalizeTransactionName(routes, global.location, match, function (localName) {
21
- prevName = localName;
22
- activeTransaction = startTransaction({
23
- name: prevName,
24
- op: 'pageload',
25
- tags: {
26
- 'routing.instrumentation': 'react-router-v3',
27
- },
28
- });
29
- });
30
- }
31
- if (startTransactionOnLocationChange && history.listen) {
32
- history.listen(function (location) {
33
- if (location.action === 'PUSH' || location.action === 'POP') {
34
- if (activeTransaction) {
35
- activeTransaction.finish();
36
- }
37
- var tags_1 = {
38
- 'routing.instrumentation': 'react-router-v3',
39
- };
40
- if (prevName) {
41
- tags_1.from = prevName;
42
- }
43
- normalizeTransactionName(routes, location, match, function (localName) {
44
- prevName = localName;
45
- activeTransaction = startTransaction({
46
- name: prevName,
47
- op: 'navigation',
48
- tags: tags_1,
49
- });
50
- });
51
- }
18
+ function reactRouterV3Instrumentation(
19
+ history,
20
+ routes,
21
+ match,
22
+ ) {
23
+ return (
24
+ startTransaction,
25
+ startTransactionOnPageLoad = true,
26
+ startTransactionOnLocationChange = true,
27
+ ) => {
28
+ let activeTransaction;
29
+ let prevName;
30
+
31
+ // Have to use global.location because history.location might not be defined.
32
+ if (startTransactionOnPageLoad && global && global.location) {
33
+ normalizeTransactionName(routes, global.location , match, (localName) => {
34
+ prevName = localName;
35
+ activeTransaction = startTransaction({
36
+ name: prevName,
37
+ op: 'pageload',
38
+ tags: {
39
+ 'routing.instrumentation': 'react-router-v3',
40
+ },
41
+ });
42
+ });
43
+ }
44
+
45
+ if (startTransactionOnLocationChange && history.listen) {
46
+ history.listen(location => {
47
+ if (location.action === 'PUSH' || location.action === 'POP') {
48
+ if (activeTransaction) {
49
+ activeTransaction.finish();
50
+ }
51
+ var tags = {
52
+ 'routing.instrumentation': 'react-router-v3',
53
+ };
54
+ if (prevName) {
55
+ tags.from = prevName;
56
+ }
57
+ normalizeTransactionName(routes, location, match, (localName) => {
58
+ prevName = localName;
59
+ activeTransaction = startTransaction({
60
+ name: prevName,
61
+ op: 'navigation',
62
+ tags,
52
63
  });
64
+ });
53
65
  }
54
- };
66
+ });
67
+ }
68
+ };
55
69
  }
56
- exports.reactRouterV3Instrumentation = reactRouterV3Instrumentation;
70
+
57
71
  /**
58
72
  * Normalize transaction names using `Router.match`
59
73
  */
60
- function normalizeTransactionName(appRoutes, location, match, callback) {
61
- var name = location.pathname;
62
- match({
63
- location: location,
64
- routes: appRoutes,
65
- }, function (error, _redirectLocation, renderProps) {
66
- if (error || !renderProps) {
67
- return callback(name);
68
- }
69
- var routePath = getRouteStringFromRoutes(renderProps.routes || []);
70
- if (routePath.length === 0 || routePath === '/*') {
71
- return callback(name);
72
- }
73
- name = routePath;
74
+ function normalizeTransactionName(
75
+ appRoutes,
76
+ location,
77
+ match,
78
+ callback,
79
+ ) {
80
+ let name = location.pathname;
81
+ match(
82
+ {
83
+ location,
84
+ routes: appRoutes,
85
+ },
86
+ (error, _redirectLocation, renderProps) => {
87
+ if (error || !renderProps) {
88
+ return callback(name);
89
+ }
90
+
91
+ var routePath = getRouteStringFromRoutes(renderProps.routes || []);
92
+ if (routePath.length === 0 || routePath === '/*') {
74
93
  return callback(name);
75
- });
94
+ }
95
+
96
+ name = routePath;
97
+ return callback(name);
98
+ },
99
+ );
76
100
  }
101
+
77
102
  /**
78
103
  * Generate route name from array of routes
79
104
  */
80
105
  function getRouteStringFromRoutes(routes) {
81
- if (!Array.isArray(routes) || routes.length === 0) {
82
- return '';
106
+ if (!Array.isArray(routes) || routes.length === 0) {
107
+ return '';
108
+ }
109
+
110
+ var routesWithPaths = routes.filter((route) => !!route.path);
111
+
112
+ let index = -1;
113
+ for (let x = routesWithPaths.length - 1; x >= 0; x--) {
114
+ var route = routesWithPaths[x];
115
+ if (route.path && route.path.startsWith('/')) {
116
+ index = x;
117
+ break;
83
118
  }
84
- var routesWithPaths = routes.filter(function (route) { return !!route.path; });
85
- var index = -1;
86
- for (var x = routesWithPaths.length - 1; x >= 0; x--) {
87
- var route = routesWithPaths[x];
88
- if (route.path && route.path.startsWith('/')) {
89
- index = x;
90
- break;
91
- }
92
- }
93
- return routesWithPaths
94
- .slice(index)
95
- .filter(function (_a) {
96
- var path = _a.path;
97
- return !!path;
98
- })
99
- .map(function (_a) {
100
- var path = _a.path;
101
- return path;
102
- })
103
- .join('');
119
+ }
120
+
121
+ return routesWithPaths
122
+ .slice(index)
123
+ .filter(({ path }) => !!path)
124
+ .map(({ path }) => path)
125
+ .join('');
104
126
  }
105
- //# sourceMappingURL=reactrouterv3.js.map
127
+
128
+ exports.reactRouterV3Instrumentation = reactRouterV3Instrumentation;
129
+ //# sourceMappingURL=reactrouterv3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactrouterv3.js","sourceRoot":"","sources":["../../src/reactrouterv3.ts"],"names":[],"mappings":";AACA,uCAAgD;AAoBhD,IAAM,MAAM,GAAG,uBAAe,EAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,SAAgB,4BAA4B,CAC1C,OAAkB,EAClB,MAAe,EACf,KAAY;IAEZ,OAAO,UACL,gBAA0E,EAC1E,0BAA0C,EAC1C,gCAAgD;QADhD,2CAAA,EAAA,iCAA0C;QAC1C,iDAAA,EAAA,uCAAgD;QAEhD,IAAI,iBAA0C,CAAC;QAC/C,IAAI,QAA4B,CAAC;QAEjC,6EAA6E;QAC7E,IAAI,0BAA0B,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC3D,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,QAA+B,EAAE,KAAK,EAAE,UAAC,SAAiB;gBAChG,QAAQ,GAAG,SAAS,CAAC;gBACrB,iBAAiB,GAAG,gBAAgB,CAAC;oBACnC,IAAI,EAAE,QAAQ;oBACd,EAAE,EAAE,UAAU;oBACd,IAAI,EAAE;wBACJ,yBAAyB,EAAE,iBAAiB;qBA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,KAAK,CAAC,IAAI,SAAS,KAAK,IAAI,EAAE;YAChD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;SACvB;QAED,IAAI,GAAG,SAAS,CAAC;QACjB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,MAAe;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACjD,OAAO,EAAE,CAAC;KACX;IAED,IAAM,eAAe,GAAY,MAAM,CAAC,MAAM,CAAC,UAAC,KAAY,IAAK,OAAA,CAAC,CAAC,KAAK,CAAC,IAAI,EAAZ,CAAY,CAAC,CAAC;IAE/E,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QACpD,IAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC5C,KAAK,GAAG,CAAC,CAAC;YACV,MAAM;SACP;KACF;IAED,OAAO,eAAe;SACnB,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,UAAC,EAAQ;YAAN,cAAI;QAAO,OAAA,CAAC,CAAC,IAAI;IAAN,CAAM,CAAC;SAC5B,GAAG,CAAC,UAAC,EAAQ;YAAN,cAAI;QAAO,OAAA,IAAI;IAAJ,CAAI,CAAC;SACvB,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name);\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"]}
1
+ {"version":3,"file":"reactrouterv3.js","sources":["../../src/reactrouterv3.ts"],"sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name);\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"],"names":[],"mappings":";;;;AAKA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;"}