-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathjsonpath-shim.js
More file actions
29 lines (25 loc) · 1.05 KB
/
jsonpath-shim.js
File metadata and controls
29 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import * as lib from './original-jsonpath.js';
// 获取对象
// Rolldown/ESM interop 可能会把 export 放在 default 或 namespace
const JP = lib.JSONPath || lib.default?.JSONPath || lib.default;
// 确保全局挂载
if (typeof globalThis !== 'undefined') {
if (!globalThis.JSONPath) {
globalThis.JSONPath = {}; // 初始化容器
}
// min.js 的逻辑是 globalThis.JSONPath.JSONPath = F
// 如果 JP 是 F (构造函数)
if (typeof JP === 'function') {
globalThis.JSONPath.JSONPath = JP;
} else if (JP && JP.JSONPath) {
// 如果 JP 已经是 { JSONPath: F }
globalThis.JSONPath = JP;
}
// 如果 htmlParser.js 直接使用 JSONPath 变量而不是 globalThis.JSONPath
// 在 Bundle 环境下这是不可能的,除非它是全局变量。
// 但是在 Node 环境下,全局变量可以直接访问。
// 我们这里只能保证 globalThis.JSONPath 存在。
}
// 导出,虽然 htmlParser.js 没用到,但为了模块完整性
export { JP as JSONPath };
export default JP;