ohos-router 1.1.3 → 1.1.5
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.
- package/package.json +1 -1
- package/router.ts +13 -17
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -217,21 +217,26 @@ export function pluginStart(node: HvigorNode, isExecute: boolean) {
|
|
|
217
217
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
|
|
221
220
|
let moduleSrcEntry: string
|
|
222
|
-
|
|
223
221
|
function moduleJson5JSONParse(moduleJson5Data: string) {
|
|
224
222
|
try {
|
|
225
223
|
let moduleJsonBean = JSON.parse(moduleJson5Data)
|
|
226
224
|
let module = moduleJsonBean.module
|
|
227
225
|
moduleSrcEntry = module.srcEntry
|
|
228
226
|
} catch (error) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
227
|
+
// 尝试修复常见的 JSON 错误
|
|
228
|
+
const repairedJson = moduleJson5Data
|
|
229
|
+
// 修复单引号
|
|
230
|
+
.replace(/'/g, '"')
|
|
231
|
+
// 修复未加引号的键名
|
|
232
|
+
.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)(\s*:)/g, '$1"$2"$3')
|
|
233
|
+
// 修复尾随逗号
|
|
234
|
+
.replace(/,\s*}/g, '}')
|
|
235
|
+
.replace(/,\s*]/g, ']')
|
|
236
|
+
// 修复注释(移除单行和多行注释)
|
|
237
|
+
.replace(/\/\/.*$/gm, '')
|
|
238
|
+
.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
239
|
+
moduleJson5JSONParse(repairedJson)
|
|
235
240
|
}
|
|
236
241
|
}
|
|
237
242
|
|
|
@@ -484,12 +489,3 @@ function replaceCharUsingSubstring(str: string, index: number, newChar: string)
|
|
|
484
489
|
}
|
|
485
490
|
return str.substring(0, index) + newChar + str.substring(index + 1);
|
|
486
491
|
}
|
|
487
|
-
|
|
488
|
-
function addPropertyToBeginning<T extends object, K extends string, V>(
|
|
489
|
-
obj: T,
|
|
490
|
-
key: K,
|
|
491
|
-
value: V
|
|
492
|
-
): T & { [P in K]: V } {
|
|
493
|
-
const newObj = {[key]: value, ...obj} as T & { [P in K]: V };
|
|
494
|
-
return newObj;
|
|
495
|
-
}
|