|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import * as coreMode from '#core/mode'; |
18 | | -import {parseQueryString} from '#core/types/string/url'; |
| 18 | +import {getHashParams} from '#core/types/string/url'; |
19 | 19 |
|
20 | 20 | /** |
21 | 21 | * @typedef {{ |
22 | 22 | * localDev: boolean, |
23 | 23 | * development: boolean, |
24 | 24 | * test: boolean, |
25 | | - * log: (string|undefined), |
26 | 25 | * rtvVersion: string, |
27 | 26 | * runtime: (null|string|undefined), |
28 | 27 | * a4aId: (null|string|undefined), |
@@ -57,24 +56,19 @@ export function getMode(opt_win) { |
57 | 56 | * @return {!ModeDef} |
58 | 57 | */ |
59 | 58 | function getMode_(win) { |
60 | | - const hashQuery = parseQueryString( |
61 | | - // location.originalHash is set by the viewer when it removes the fragment |
62 | | - // from the URL. |
63 | | - win.location['originalHash'] || win.location.hash |
64 | | - ); |
| 59 | + const hashParams = getHashParams(win); |
65 | 60 |
|
66 | 61 | // The `minified`, `test` and `localDev` properties are replaced |
67 | 62 | // as boolean literals when we run `amp dist` without the `--fortesting` |
68 | 63 | // flags. This improved DCE on the production file we deploy as the code |
69 | 64 | // paths for localhost/testing/development are eliminated. |
70 | 65 | return { |
71 | 66 | localDev: coreMode.isLocalDev(win), |
72 | | - development: isModeDevelopment(win), |
| 67 | + development: isModeDevelopment(win, hashParams), |
73 | 68 | esm: IS_ESM, |
74 | 69 | // amp-geo override |
75 | | - geoOverride: hashQuery['amp-geo'], |
| 70 | + geoOverride: hashParams['amp-geo'], |
76 | 71 | test: coreMode.isTest(win), |
77 | | - log: parseInt(hashQuery['log'], 10), |
78 | 72 | rtvVersion: getRtvVersion(win), |
79 | 73 | }; |
80 | 74 | } |
@@ -104,17 +98,13 @@ function getRtvVersion(win) { |
104 | 98 | * bypassed via #validate=0. |
105 | 99 | * Note that AMP_DEV_MODE flag is used for testing purposes. |
106 | 100 | * @param {!Window} win |
| 101 | + * @param {!JsonObject=} opt_hashParams |
107 | 102 | * @return {boolean} |
108 | 103 | */ |
109 | | -export function isModeDevelopment(win) { |
110 | | - const hashQuery = parseQueryString( |
111 | | - win.location['originalHash'] || win.location.hash |
112 | | - ); |
113 | | - return !!( |
114 | | - ['1', 'actions', 'amp', 'amp4ads', 'amp4email'].includes( |
115 | | - hashQuery['development'] |
116 | | - ) || win.AMP_DEV_MODE |
117 | | - ); |
| 104 | +export function isModeDevelopment(win, opt_hashParams) { |
| 105 | + const devModes = ['1', 'actions', 'amp', 'amp4ads', 'amp4email']; |
| 106 | + const devParam = opt_hashParams || getHashParams(win); |
| 107 | + return devModes.includes(devParam['development']) || !!win.AMP_DEV_MODE; |
118 | 108 | } |
119 | 109 |
|
120 | 110 | /** |
|
0 commit comments