@ecopages/react 0.2.1 → 0.3.1
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/README.md +179 -35
- package/package.json +78 -33
- package/src/app/client-only.js +10 -0
- package/src/app/dynamic.js +9 -0
- package/src/bundling/bootstrap-package-paths.d.ts +5 -0
- package/src/bundling/bootstrap-package-paths.js +5 -0
- package/src/bundling/bundle.d.ts +78 -0
- package/src/bundling/bundle.js +130 -0
- package/src/bundling/runtime-alias-map.d.ts +12 -0
- package/src/bundling/runtime-alias-map.js +110 -0
- package/src/bundling/runtime-bundle.d.ts +70 -0
- package/src/bundling/runtime-bundle.js +233 -0
- package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +1 -1
- package/src/bundling/runtime-interop-plugin.js +32 -0
- package/src/bundling/runtime-mode.d.ts +1 -0
- package/src/bundling/runtime-mode.js +10 -0
- package/src/bundling/runtime-modules.d.ts +21 -0
- package/src/bundling/runtime-modules.js +28 -0
- package/src/client-graph/ast-transform-eco-page.d.ts +10 -0
- package/src/client-graph/ast-transform-eco-page.js +71 -0
- package/src/client-graph/ast-transform-import-edits.d.ts +13 -0
- package/src/client-graph/ast-transform-import-edits.js +75 -0
- package/src/client-graph/ast-transform-walk-imports.d.ts +20 -0
- package/src/client-graph/ast-transform-walk-imports.js +105 -0
- package/src/client-graph/ast-transform.d.ts +12 -0
- package/src/client-graph/ast-transform.js +91 -0
- package/src/client-graph/ast-walk.d.ts +10 -0
- package/src/client-graph/ast-walk.js +26 -0
- package/src/client-graph/boundary-plugin-read-file-inline.d.ts +7 -0
- package/src/client-graph/boundary-plugin-read-file-inline.js +43 -0
- package/src/client-graph/boundary-plugin-transform.d.ts +16 -0
- package/src/client-graph/boundary-plugin-transform.js +31 -0
- package/src/client-graph/boundary-plugin.d.ts +23 -0
- package/src/client-graph/boundary-plugin.js +177 -0
- package/src/client-graph/component-config-traversal.d.ts +36 -0
- package/src/client-graph/component-config-traversal.js +77 -0
- package/src/{utils → client-graph}/declared-modules.d.ts +1 -1
- package/src/client-graph/declared-modules.js +69 -0
- package/src/client-graph/module-classification.d.ts +3 -0
- package/src/client-graph/module-classification.js +43 -0
- package/src/client-graph/reachability-analyzer.d.ts +26 -0
- package/src/client-graph/reachability-analyzer.js +55 -0
- package/src/client-graph/reachability-client-roots.d.ts +8 -0
- package/src/client-graph/reachability-client-roots.js +59 -0
- package/src/client-graph/reachability-export-names.d.ts +5 -0
- package/src/client-graph/reachability-export-names.js +34 -0
- package/src/client-graph/reachability-fallback-roots.d.ts +3 -0
- package/src/client-graph/reachability-fallback-roots.js +71 -0
- package/src/client-graph/reachability-preload.d.ts +10 -0
- package/src/client-graph/reachability-preload.js +30 -0
- package/src/client-graph/reachability-top-level-index.d.ts +14 -0
- package/src/client-graph/reachability-top-level-index.js +93 -0
- package/src/client-graph/reachability-traverse.d.ts +7 -0
- package/src/client-graph/reachability-traverse.js +201 -0
- package/src/client-graph/specifier-classification.d.ts +74 -0
- package/src/client-graph/specifier-classification.js +191 -0
- package/src/content/collection-component-cache.d.ts +25 -0
- package/src/content/collection-component-cache.js +62 -0
- package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +7 -14
- package/src/contracts/router-adapter.js +6 -0
- package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
- package/src/dev-transform/react-dev-transform-contributor.js +22 -0
- package/src/hmr/hmr-strategy-process.d.ts +34 -0
- package/src/hmr/hmr-strategy-process.js +83 -0
- package/src/hmr/hmr-strategy.d.ts +67 -0
- package/src/hmr/hmr-strategy.js +306 -0
- package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +6 -2
- package/src/hmr/page-metadata-cache.js +44 -0
- package/src/hmr/react-hmr-dev-transform-plugins.d.ts +22 -0
- package/src/hmr/react-hmr-dev-transform-plugins.js +19 -0
- package/src/hydration/bootstrap-imports.d.ts +25 -0
- package/src/hydration/bootstrap-imports.js +33 -0
- package/src/hydration/browser/island-hydration.d.ts +81 -0
- package/src/hydration/browser/island-hydration.js +247 -0
- package/src/hydration/browser/page-hydration-hmr.d.ts +11 -0
- package/src/hydration/browser/page-hydration-hmr.js +56 -0
- package/src/hydration/browser/page-hydration-module.d.ts +8 -0
- package/src/hydration/browser/page-hydration-module.js +17 -0
- package/src/hydration/browser/page-hydration.d.ts +54 -0
- package/src/hydration/browser/page-hydration.js +177 -0
- package/src/hydration/compiled-page-hydration-options.d.ts +20 -0
- package/src/hydration/compiled-page-hydration-options.js +1 -0
- package/src/hydration/hydration-asset.d.ts +128 -0
- package/src/hydration/hydration-asset.js +388 -0
- package/src/hydration/hydration-page-entry-source.d.ts +5 -0
- package/src/hydration/hydration-page-entry-source.js +87 -0
- package/src/hydration/hydration-script-compiler.d.ts +47 -0
- package/src/hydration/hydration-script-compiler.js +213 -0
- package/src/hydration/page-data-manifest.d.ts +58 -0
- package/src/hydration/page-data-manifest.js +97 -0
- package/src/hydration/page-data-reader.d.ts +17 -0
- package/src/hydration/page-data-reader.js +31 -0
- package/src/hydration/page-payload.d.ts +68 -0
- package/src/hydration/page-payload.js +106 -0
- package/src/hydration/serialize-page-data-script.d.ts +27 -0
- package/src/hydration/serialize-page-data-script.js +30 -0
- package/src/mdx/mdx-config-dependency.d.ts +37 -0
- package/src/mdx/mdx-config-dependency.js +107 -0
- package/src/mdx/mdx-loader-plugin.d.ts +8 -0
- package/src/mdx/mdx-loader-plugin.js +11 -0
- package/src/page/page-module.d.ts +46 -0
- package/src/page/page-module.js +74 -0
- package/src/plugin/react.constants.d.ts +1 -0
- package/src/plugin/react.constants.js +1 -0
- package/src/plugin/react.plugin.d.ts +71 -0
- package/src/plugin/react.plugin.js +210 -0
- package/src/plugin/react.types.d.ts +106 -0
- package/src/plugin/react.types.js +1 -0
- package/src/render/component-ownership.d.ts +49 -0
- package/src/render/component-ownership.js +47 -0
- package/src/render/component-ssr.d.ts +59 -0
- package/src/render/component-ssr.js +76 -0
- package/src/render/eco-embed.d.ts +11 -0
- package/src/render/eco-embed.js +9 -0
- package/src/render/errors.d.ts +16 -0
- package/src/render/errors.js +23 -0
- package/src/render/html-boundary.js +59 -0
- package/src/render/layout-compose.d.ts +66 -0
- package/src/render/layout-compose.js +134 -0
- package/src/render/react-renderer.d.ts +114 -0
- package/src/render/react-renderer.js +490 -0
- package/src/render/react-runtime.d.ts +13 -0
- package/src/render/react-runtime.js +26 -0
- package/src/render/unified-layout-composition.d.ts +22 -0
- package/src/render/unified-layout-composition.js +31 -0
- package/src/runtime/use-sync-external-store-with-selector.d.ts +3 -0
- package/src/runtime/use-sync-external-store-with-selector.js +54 -0
- package/CHANGELOG.md +0 -29
- package/src/react-hmr-strategy.d.ts +0 -148
- package/src/react-hmr-strategy.js +0 -313
- package/src/react-renderer.d.ts +0 -213
- package/src/react-renderer.js +0 -654
- package/src/react.plugin.d.ts +0 -147
- package/src/react.plugin.js +0 -146
- package/src/router-adapter.js +0 -0
- package/src/services/react-bundle.service.d.ts +0 -47
- package/src/services/react-bundle.service.js +0 -93
- package/src/services/react-hmr-page-metadata-cache.js +0 -35
- package/src/services/react-hydration-asset.service.d.ts +0 -76
- package/src/services/react-hydration-asset.service.js +0 -210
- package/src/services/react-page-module.service.d.ts +0 -83
- package/src/services/react-page-module.service.js +0 -162
- package/src/services/react-runtime-bundle.service.d.ts +0 -40
- package/src/services/react-runtime-bundle.service.js +0 -130
- package/src/utils/client-graph-boundary-plugin.d.ts +0 -43
- package/src/utils/client-graph-boundary-plugin.js +0 -494
- package/src/utils/client-only.js +0 -19
- package/src/utils/declared-modules.js +0 -59
- package/src/utils/dynamic.js +0 -12
- package/src/utils/hmr-scripts.d.ts +0 -18
- package/src/utils/hmr-scripts.js +0 -31
- package/src/utils/html-boundary.js +0 -55
- package/src/utils/hydration-scripts.d.ts +0 -86
- package/src/utils/hydration-scripts.js +0 -285
- package/src/utils/reachability-analyzer.d.ts +0 -66
- package/src/utils/reachability-analyzer.js +0 -339
- package/src/utils/react-dom-runtime-interop-plugin.js +0 -29
- package/src/utils/react-mdx-loader-plugin.d.ts +0 -3
- package/src/utils/react-mdx-loader-plugin.js +0 -45
- package/src/utils/react-runtime-specifier-map.d.ts +0 -6
- package/src/utils/react-runtime-specifier-map.js +0 -37
- package/src/utils/use-sync-external-store-shim-plugin.d.ts +0 -5
- package/src/utils/use-sync-external-store-shim-plugin.js +0 -41
- /package/src/{utils → app}/client-only.d.ts +0 -0
- /package/src/{utils → app}/dynamic.d.ts +0 -0
- /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
- /package/src/{utils → render}/html-boundary.d.ts +0 -0
|
@@ -1,494 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { dirname, extname, resolve } from "node:path";
|
|
3
|
-
import { parseSync } from "oxc-parser";
|
|
4
|
-
import { analyzeReachability } from "./reachability-analyzer.js";
|
|
5
|
-
const SOURCE_FILE_FILTER = /\.(tsx?|jsx?)$/;
|
|
6
|
-
const SERVER_ONLY_ECO_PAGE_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
7
|
-
"cache",
|
|
8
|
-
"middleware",
|
|
9
|
-
"requires",
|
|
10
|
-
"metadata",
|
|
11
|
-
"staticProps",
|
|
12
|
-
"staticPaths"
|
|
13
|
-
]);
|
|
14
|
-
function isBareSpecifier(specifier) {
|
|
15
|
-
if (specifier.startsWith(".")) return false;
|
|
16
|
-
if (specifier.startsWith("/")) return false;
|
|
17
|
-
if (specifier.includes("://")) return false;
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
function isProjectAliasSpecifier(specifier) {
|
|
21
|
-
return specifier.startsWith("@/") || specifier.startsWith("~/") || specifier.startsWith("ecopages:");
|
|
22
|
-
}
|
|
23
|
-
function isServerOnlySpecifier(specifier) {
|
|
24
|
-
if (specifier.startsWith("node:")) return true;
|
|
25
|
-
return /(?:^|[/])[^/]+\.server(?:$|\.)/.test(specifier);
|
|
26
|
-
}
|
|
27
|
-
function toModuleBaseSpecifier(specifier) {
|
|
28
|
-
if (!isBareSpecifier(specifier) || specifier.startsWith("node:")) {
|
|
29
|
-
return specifier;
|
|
30
|
-
}
|
|
31
|
-
if (specifier.startsWith("@")) {
|
|
32
|
-
const [scope, name2] = specifier.split("/");
|
|
33
|
-
if (!scope || !name2) return specifier;
|
|
34
|
-
return `${scope}/${name2}`;
|
|
35
|
-
}
|
|
36
|
-
const [name] = specifier.split("/");
|
|
37
|
-
return name ?? specifier;
|
|
38
|
-
}
|
|
39
|
-
function parseDeclaredModules(moduleDeclarations) {
|
|
40
|
-
const map = /* @__PURE__ */ new Map();
|
|
41
|
-
for (const declaration of moduleDeclarations ?? []) {
|
|
42
|
-
const source = declaration.trim();
|
|
43
|
-
if (source.length === 0) continue;
|
|
44
|
-
const openBraceIndex = source.indexOf("{");
|
|
45
|
-
if (openBraceIndex < 0) {
|
|
46
|
-
map.set(toModuleBaseSpecifier(source), "*");
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const closeBraceIndex = source.indexOf("}", openBraceIndex);
|
|
50
|
-
const rawPkg = source.slice(0, openBraceIndex).trim();
|
|
51
|
-
if (rawPkg.length === 0) continue;
|
|
52
|
-
const pkg = toModuleBaseSpecifier(rawPkg);
|
|
53
|
-
const namedImportsStr = closeBraceIndex > openBraceIndex ? source.slice(openBraceIndex + 1, closeBraceIndex) : source.slice(openBraceIndex + 1);
|
|
54
|
-
const namedImports = namedImportsStr.split(",").map((s) => s.trim()).filter(Boolean);
|
|
55
|
-
const existing = map.get(pkg);
|
|
56
|
-
if (existing === "*") continue;
|
|
57
|
-
if (!existing) {
|
|
58
|
-
if (namedImports.length === 0) {
|
|
59
|
-
map.set(pkg, "*");
|
|
60
|
-
} else {
|
|
61
|
-
map.set(pkg, new Set(namedImports));
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
for (const name of namedImports) {
|
|
65
|
-
existing.add(name);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return map;
|
|
70
|
-
}
|
|
71
|
-
function mergeDeclaredModulesMap(a, b) {
|
|
72
|
-
const result = new Map(a);
|
|
73
|
-
for (const [pkg, imports] of b.entries()) {
|
|
74
|
-
const existing = result.get(pkg);
|
|
75
|
-
if (existing === "*") continue;
|
|
76
|
-
if (imports === "*") {
|
|
77
|
-
result.set(pkg, "*");
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (!existing) {
|
|
81
|
-
result.set(pkg, imports);
|
|
82
|
-
} else {
|
|
83
|
-
for (const name of imports) {
|
|
84
|
-
existing.add(name);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
function parserLanguageForFile(filename) {
|
|
91
|
-
const extension = extname(filename).toLowerCase();
|
|
92
|
-
if (extension === ".tsx") return "tsx";
|
|
93
|
-
if (extension === ".ts") return "ts";
|
|
94
|
-
if (extension === ".jsx") return "jsx";
|
|
95
|
-
return "js";
|
|
96
|
-
}
|
|
97
|
-
function getObjectPropertyKeyName(node) {
|
|
98
|
-
if (!node) return void 0;
|
|
99
|
-
if (node.type === "Identifier") return node.name;
|
|
100
|
-
if (node.type === "StringLiteral" || node.type === "Literal") {
|
|
101
|
-
return typeof node.value === "string" ? node.value : void 0;
|
|
102
|
-
}
|
|
103
|
-
return void 0;
|
|
104
|
-
}
|
|
105
|
-
function stripServerOnlyEcoPageOptions(source, program) {
|
|
106
|
-
const edits = [];
|
|
107
|
-
function walk(node) {
|
|
108
|
-
if (!node || typeof node !== "object") return;
|
|
109
|
-
if (Array.isArray(node)) {
|
|
110
|
-
for (const child of node) walk(child);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (node.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.type === "Identifier" && node.callee.object.name === "eco" && node.callee.property?.type === "Identifier" && node.callee.property.name === "page" && node.arguments?.[0]?.type === "ObjectExpression") {
|
|
114
|
-
const objectExpression = node.arguments[0];
|
|
115
|
-
const keptProperties = [];
|
|
116
|
-
let removedProperty = false;
|
|
117
|
-
for (const property of objectExpression.properties ?? []) {
|
|
118
|
-
if (property?.type === "Property") {
|
|
119
|
-
const keyName = getObjectPropertyKeyName(property.key);
|
|
120
|
-
if (keyName && SERVER_ONLY_ECO_PAGE_OPTION_KEYS.has(keyName)) {
|
|
121
|
-
removedProperty = true;
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
keptProperties.push(source.slice(property.start, property.end));
|
|
126
|
-
}
|
|
127
|
-
if (removedProperty) {
|
|
128
|
-
const replacement = keptProperties.length > 0 ? `{ ${keptProperties.join(", ")} }` : "{}";
|
|
129
|
-
edits.push({
|
|
130
|
-
start: objectExpression.start,
|
|
131
|
-
end: objectExpression.end,
|
|
132
|
-
replacement
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
for (const key in node) {
|
|
137
|
-
if (key !== "type" && key !== "start" && key !== "end") {
|
|
138
|
-
walk(node[key]);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
walk(program);
|
|
143
|
-
if (edits.length === 0) {
|
|
144
|
-
return { transformed: source, modified: false };
|
|
145
|
-
}
|
|
146
|
-
edits.sort((a, b) => b.start - a.start);
|
|
147
|
-
let transformed = source;
|
|
148
|
-
for (const edit of edits) {
|
|
149
|
-
transformed = transformed.slice(0, edit.start) + edit.replacement + transformed.slice(edit.end);
|
|
150
|
-
}
|
|
151
|
-
return { transformed, modified: true };
|
|
152
|
-
}
|
|
153
|
-
function normalizeRequestedExportsKey(pathname) {
|
|
154
|
-
let normalized = pathname.replace(/\\/g, "/");
|
|
155
|
-
normalized = normalized.replace(/\.(tsx?|jsx?)$/i, "");
|
|
156
|
-
if (normalized.endsWith("/index")) {
|
|
157
|
-
normalized = normalized.slice(0, -"/index".length);
|
|
158
|
-
}
|
|
159
|
-
return normalized;
|
|
160
|
-
}
|
|
161
|
-
function resolveRequestedExportsKey(importer, specifier) {
|
|
162
|
-
if (isBareSpecifier(specifier) || isProjectAliasSpecifier(specifier)) {
|
|
163
|
-
return void 0;
|
|
164
|
-
}
|
|
165
|
-
const resolved = specifier.startsWith("/") ? specifier : resolve(dirname(importer), specifier);
|
|
166
|
-
return normalizeRequestedExportsKey(resolved);
|
|
167
|
-
}
|
|
168
|
-
function mergeRequestedExportRules(registry, moduleKey, rules) {
|
|
169
|
-
const existing = registry.get(moduleKey);
|
|
170
|
-
if (existing === "*") return;
|
|
171
|
-
if (rules === "*") {
|
|
172
|
-
registry.set(moduleKey, "*");
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (!existing) {
|
|
176
|
-
registry.set(moduleKey, new Set(rules));
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
for (const rule of rules) {
|
|
180
|
-
existing.add(rule);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function transformModuleImports(source, filename, globallyAllowed, requestedExports) {
|
|
184
|
-
let result;
|
|
185
|
-
try {
|
|
186
|
-
result = parseSync(filename, source, {
|
|
187
|
-
sourceType: "module",
|
|
188
|
-
lang: parserLanguageForFile(filename)
|
|
189
|
-
});
|
|
190
|
-
} catch {
|
|
191
|
-
return { transformed: source, modified: false };
|
|
192
|
-
}
|
|
193
|
-
const { program } = result;
|
|
194
|
-
const localDeclared = [];
|
|
195
|
-
function walk(node) {
|
|
196
|
-
if (!node || typeof node !== "object") return;
|
|
197
|
-
if (Array.isArray(node)) {
|
|
198
|
-
for (const child of node) walk(child);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (node.type === "Property" && node.key?.name === "modules" && node.value?.type === "ArrayExpression") {
|
|
202
|
-
for (const el of node.value.elements) {
|
|
203
|
-
if ((el.type === "StringLiteral" || el.type === "Literal") && typeof el.value === "string") {
|
|
204
|
-
localDeclared.push(el.value);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
for (const key in node) {
|
|
209
|
-
if (key !== "type" && key !== "start" && key !== "end") {
|
|
210
|
-
walk(node[key]);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
walk(program);
|
|
215
|
-
const locallyAllowed = parseDeclaredModules(localDeclared);
|
|
216
|
-
const allowedMap = mergeDeclaredModulesMap(globallyAllowed, locallyAllowed);
|
|
217
|
-
const explicitRequestedExports = requestedExports.get(normalizeRequestedExportsKey(filename));
|
|
218
|
-
const reachability = analyzeReachability(source, filename, program, explicitRequestedExports);
|
|
219
|
-
for (const statement of program.body) {
|
|
220
|
-
if (statement.type === "ImportDeclaration") {
|
|
221
|
-
const reachableRules = reachability.reachableImports.get(statement.source.value);
|
|
222
|
-
const requestedModuleKey = resolveRequestedExportsKey(filename, statement.source.value);
|
|
223
|
-
if (!requestedModuleKey || !reachableRules) continue;
|
|
224
|
-
mergeRequestedExportRules(requestedExports, requestedModuleKey, reachableRules);
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (statement.type === "ExportNamedDeclaration" && statement.source) {
|
|
228
|
-
const reachableRules = reachability.reachableImports.get(statement.source.value);
|
|
229
|
-
const requestedModuleKey = resolveRequestedExportsKey(filename, statement.source.value);
|
|
230
|
-
if (!requestedModuleKey || !reachableRules) continue;
|
|
231
|
-
mergeRequestedExportRules(requestedExports, requestedModuleKey, reachableRules);
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
if (statement.type === "ExportAllDeclaration" && statement.source) {
|
|
235
|
-
const reachableRules = reachability.reachableImports.get(statement.source.value);
|
|
236
|
-
const requestedModuleKey = resolveRequestedExportsKey(filename, statement.source.value);
|
|
237
|
-
if (!requestedModuleKey || !reachableRules) continue;
|
|
238
|
-
mergeRequestedExportRules(requestedExports, requestedModuleKey, reachableRules);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const edits = [];
|
|
242
|
-
function processSpecifier(specifier) {
|
|
243
|
-
const moduleBase = toModuleBaseSpecifier(specifier);
|
|
244
|
-
const explicitRules = allowedMap.get(moduleBase);
|
|
245
|
-
if (isServerOnlySpecifier(specifier)) {
|
|
246
|
-
if (explicitRules) {
|
|
247
|
-
return { allowed: true, rules: explicitRules };
|
|
248
|
-
}
|
|
249
|
-
return { allowed: false };
|
|
250
|
-
}
|
|
251
|
-
if (isProjectAliasSpecifier(specifier)) return { allowed: true, rules: explicitRules ?? "*" };
|
|
252
|
-
if (!isBareSpecifier(specifier)) return { allowed: true, rules: explicitRules ?? "*" };
|
|
253
|
-
return { allowed: true, rules: explicitRules ?? "*" };
|
|
254
|
-
}
|
|
255
|
-
function walkImports(node) {
|
|
256
|
-
if (!node || typeof node !== "object") return;
|
|
257
|
-
if (Array.isArray(node)) {
|
|
258
|
-
for (const child of node) walkImports(child);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
if (node.type === "ImportDeclaration") {
|
|
262
|
-
const specifier = node.source.value;
|
|
263
|
-
const reachableRules = reachability.reachableImports.get(specifier);
|
|
264
|
-
const { allowed, rules } = processSpecifier(specifier);
|
|
265
|
-
if (!allowed) {
|
|
266
|
-
if (reachableRules && !reachability.isFallbackRoots) {
|
|
267
|
-
throw new Error(
|
|
268
|
-
`[Ecopages Client Reachability] Forbidden client import '${specifier}' at ${filename}:${node.start}. This import is explicitly reachable from the React render function.`
|
|
269
|
-
);
|
|
270
|
-
} else {
|
|
271
|
-
edits.push({ start: node.start, end: node.end, replacement: "" });
|
|
272
|
-
}
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
if (rules instanceof Set && node.specifiers && node.specifiers.length > 0) {
|
|
276
|
-
let keptSpecifierCount = 0;
|
|
277
|
-
let defaultImportLocal;
|
|
278
|
-
let namespaceImportLocal;
|
|
279
|
-
const namedImportNodes = [];
|
|
280
|
-
for (const spec of node.specifiers) {
|
|
281
|
-
if (spec.type === "ImportSpecifier") {
|
|
282
|
-
const importedName = spec.imported.type === "Identifier" ? spec.imported.name : spec.imported.value;
|
|
283
|
-
if (rules.has(importedName)) {
|
|
284
|
-
keptSpecifierCount += 1;
|
|
285
|
-
const localName = spec.local?.name;
|
|
286
|
-
if (localName && localName !== importedName) {
|
|
287
|
-
namedImportNodes.push(`${importedName} as ${localName}`);
|
|
288
|
-
} else {
|
|
289
|
-
namedImportNodes.push(importedName);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
} else if (spec.type === "ImportDefaultSpecifier") {
|
|
293
|
-
if (rules.has("default")) {
|
|
294
|
-
keptSpecifierCount += 1;
|
|
295
|
-
defaultImportLocal = spec.local.name;
|
|
296
|
-
}
|
|
297
|
-
} else if (spec.type === "ImportNamespaceSpecifier") {
|
|
298
|
-
if (rules.has("*")) {
|
|
299
|
-
keptSpecifierCount += 1;
|
|
300
|
-
namespaceImportLocal = spec.local.name;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
if (keptSpecifierCount === 0) {
|
|
305
|
-
edits.push({ start: node.start, end: node.end, replacement: "" });
|
|
306
|
-
} else if (keptSpecifierCount < node.specifiers.length) {
|
|
307
|
-
let newDeclaration = "";
|
|
308
|
-
if (defaultImportLocal && namespaceImportLocal) {
|
|
309
|
-
newDeclaration = `import ${defaultImportLocal}, * as ${namespaceImportLocal} from '${specifier}';`;
|
|
310
|
-
} else if (namespaceImportLocal) {
|
|
311
|
-
newDeclaration = `import * as ${namespaceImportLocal} from '${specifier}';`;
|
|
312
|
-
} else if (defaultImportLocal && namedImportNodes.length > 0) {
|
|
313
|
-
newDeclaration = `import ${defaultImportLocal}, { ${namedImportNodes.join(", ")} } from '${specifier}';`;
|
|
314
|
-
} else if (defaultImportLocal) {
|
|
315
|
-
newDeclaration = `import ${defaultImportLocal} from '${specifier}';`;
|
|
316
|
-
} else {
|
|
317
|
-
newDeclaration = `import { ${namedImportNodes.join(", ")} } from '${specifier}';`;
|
|
318
|
-
}
|
|
319
|
-
edits.push({ start: node.start, end: node.end, replacement: newDeclaration });
|
|
320
|
-
}
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (!reachableRules && (!node.specifiers || node.specifiers.length === 0)) {
|
|
324
|
-
edits.push({ start: node.start, end: node.end, replacement: "" });
|
|
325
|
-
}
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
if (node.type === "ExportNamedDeclaration" && node.source) {
|
|
329
|
-
const specifier = node.source.value;
|
|
330
|
-
const { allowed } = processSpecifier(specifier);
|
|
331
|
-
if (!allowed) {
|
|
332
|
-
const reachableRules = reachability.reachableImports.get(specifier);
|
|
333
|
-
if (reachableRules && !reachability.isFallbackRoots) {
|
|
334
|
-
throw new Error(
|
|
335
|
-
`[Ecopages Client Reachability] Forbidden client export from '${specifier}' at ${filename}:${node.start}. This export is explicitly reachable from the React render function.`
|
|
336
|
-
);
|
|
337
|
-
} else {
|
|
338
|
-
edits.push({ start: node.start, end: node.end, replacement: "" });
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (node.type === "ExportAllDeclaration" && node.source) {
|
|
344
|
-
const specifier = node.source.value;
|
|
345
|
-
const { allowed } = processSpecifier(specifier);
|
|
346
|
-
if (!allowed) {
|
|
347
|
-
const reachableRules = reachability.reachableImports.get(specifier);
|
|
348
|
-
if (reachableRules && !reachability.isFallbackRoots) {
|
|
349
|
-
throw new Error(
|
|
350
|
-
`[Ecopages Client Reachability] Forbidden client export * from '${specifier}' at ${filename}:${node.start}. This export is explicitly reachable from the React render function.`
|
|
351
|
-
);
|
|
352
|
-
} else {
|
|
353
|
-
edits.push({ start: node.start, end: node.end, replacement: "" });
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
if (node.type === "ImportExpression" && node.source?.value) {
|
|
359
|
-
const specifier = node.source.value;
|
|
360
|
-
const { allowed } = processSpecifier(specifier);
|
|
361
|
-
const reachableRules = reachability.reachableImports.get(specifier);
|
|
362
|
-
if (!reachableRules) {
|
|
363
|
-
if (!allowed) {
|
|
364
|
-
edits.push({ start: node.start, end: node.end, replacement: "Promise.resolve({})" });
|
|
365
|
-
}
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
if (!allowed) {
|
|
369
|
-
if (!reachability.isFallbackRoots) {
|
|
370
|
-
throw new Error(
|
|
371
|
-
`[Ecopages Client Reachability] Forbidden dynamic import('${specifier}') at ${filename}:${node.start}. This import is explicitly reachable from the React render function.`
|
|
372
|
-
);
|
|
373
|
-
} else {
|
|
374
|
-
edits.push({ start: node.start, end: node.end, replacement: "Promise.resolve({})" });
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "require") {
|
|
380
|
-
const arg = node.arguments?.[0];
|
|
381
|
-
if (arg && (arg.type === "StringLiteral" || arg.type === "Literal") && typeof arg.value === "string") {
|
|
382
|
-
const specifier = arg.value;
|
|
383
|
-
const { allowed } = processSpecifier(specifier);
|
|
384
|
-
const reachableRules = reachability.reachableImports.get(specifier);
|
|
385
|
-
if (!reachableRules) {
|
|
386
|
-
if (!allowed) {
|
|
387
|
-
edits.push({ start: node.start, end: node.end, replacement: "({})" });
|
|
388
|
-
}
|
|
389
|
-
} else if (!allowed) {
|
|
390
|
-
if (!reachability.isFallbackRoots) {
|
|
391
|
-
throw new Error(
|
|
392
|
-
`[Ecopages Client Reachability] Forbidden require('${specifier}') at ${filename}:${node.start}. This import is explicitly reachable from the React render function.`
|
|
393
|
-
);
|
|
394
|
-
} else {
|
|
395
|
-
edits.push({ start: node.start, end: node.end, replacement: "({})" });
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
for (const key in node) {
|
|
401
|
-
if (key !== "type" && key !== "start" && key !== "end") {
|
|
402
|
-
walkImports(node[key]);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
walkImports(program);
|
|
407
|
-
if (edits.length === 0) {
|
|
408
|
-
return stripServerOnlyEcoPageOptions(source, program);
|
|
409
|
-
}
|
|
410
|
-
edits.sort((a, b) => b.start - a.start);
|
|
411
|
-
let transformed = source;
|
|
412
|
-
for (const edit of edits) {
|
|
413
|
-
transformed = transformed.slice(0, edit.start) + edit.replacement + transformed.slice(edit.end);
|
|
414
|
-
}
|
|
415
|
-
let reparsedResult;
|
|
416
|
-
try {
|
|
417
|
-
reparsedResult = parseSync(filename, transformed, {
|
|
418
|
-
sourceType: "module",
|
|
419
|
-
lang: parserLanguageForFile(filename)
|
|
420
|
-
});
|
|
421
|
-
} catch {
|
|
422
|
-
return { transformed, modified: true };
|
|
423
|
-
}
|
|
424
|
-
const strippedPageOptions = stripServerOnlyEcoPageOptions(transformed, reparsedResult.program);
|
|
425
|
-
if (strippedPageOptions.modified) {
|
|
426
|
-
return strippedPageOptions;
|
|
427
|
-
}
|
|
428
|
-
return { transformed, modified: true };
|
|
429
|
-
}
|
|
430
|
-
function createClientGraphBoundaryPlugin(options) {
|
|
431
|
-
return {
|
|
432
|
-
name: "ecopages-client-graph-boundary",
|
|
433
|
-
setup(build) {
|
|
434
|
-
const absWorkingDir = options?.absWorkingDir ?? process.cwd();
|
|
435
|
-
const globallyDeclaredSources = parseDeclaredModules(options?.declaredModules);
|
|
436
|
-
const requestedExports = /* @__PURE__ */ new Map();
|
|
437
|
-
for (const alwaysAllow of options?.alwaysAllowSpecifiers ?? []) {
|
|
438
|
-
globallyDeclaredSources.set(toModuleBaseSpecifier(alwaysAllow), "*");
|
|
439
|
-
}
|
|
440
|
-
build.onLoad({ filter: SOURCE_FILE_FILTER }, (args) => {
|
|
441
|
-
let source;
|
|
442
|
-
try {
|
|
443
|
-
source = readFileSync(args.path, "utf-8");
|
|
444
|
-
} catch {
|
|
445
|
-
return void 0;
|
|
446
|
-
}
|
|
447
|
-
let transformed = source;
|
|
448
|
-
let modified = false;
|
|
449
|
-
if (source.includes("readFileSync")) {
|
|
450
|
-
const readFileTransformed = transformed.replace(
|
|
451
|
-
/\bfs\.readFileSync\s*\(\s*path\.resolve\s*\(\s*(['"`])([^'"`\n]+)\1\s*\)\s*,\s*['"`]utf-?8['"`]\s*\)/g,
|
|
452
|
-
(_match, _q, relPath) => {
|
|
453
|
-
modified = true;
|
|
454
|
-
try {
|
|
455
|
-
const sourceDir = dirname(args.path);
|
|
456
|
-
const srcDirIndex = args.path.lastIndexOf("/src/");
|
|
457
|
-
const inferredProjectRoot = srcDirIndex >= 0 ? args.path.slice(0, srcDirIndex) : void 0;
|
|
458
|
-
const candidates = [
|
|
459
|
-
resolve(absWorkingDir, relPath),
|
|
460
|
-
resolve(process.cwd(), relPath),
|
|
461
|
-
resolve(sourceDir, relPath),
|
|
462
|
-
...inferredProjectRoot ? [resolve(inferredProjectRoot, relPath)] : []
|
|
463
|
-
];
|
|
464
|
-
const absolutePath = candidates.find((candidate) => existsSync(candidate));
|
|
465
|
-
if (!absolutePath) return '""';
|
|
466
|
-
const content = readFileSync(absolutePath, "utf-8");
|
|
467
|
-
return JSON.stringify(content);
|
|
468
|
-
} catch {
|
|
469
|
-
return '""';
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
);
|
|
473
|
-
transformed = readFileTransformed;
|
|
474
|
-
}
|
|
475
|
-
const { transformed: oxcTransformed, modified: importsModified } = transformModuleImports(
|
|
476
|
-
transformed,
|
|
477
|
-
args.path,
|
|
478
|
-
globallyDeclaredSources,
|
|
479
|
-
requestedExports
|
|
480
|
-
);
|
|
481
|
-
if (importsModified) {
|
|
482
|
-
modified = true;
|
|
483
|
-
transformed = oxcTransformed;
|
|
484
|
-
}
|
|
485
|
-
if (!modified) return void 0;
|
|
486
|
-
const ext = extname(args.path).slice(1);
|
|
487
|
-
return { contents: transformed, loader: ext, resolveDir: dirname(args.path) };
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
export {
|
|
493
|
-
createClientGraphBoundaryPlugin
|
|
494
|
-
};
|
package/src/utils/client-only.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
const useIsClient = () => {
|
|
3
|
-
const [isClient, setIsClient] = useState(false);
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
setIsClient(true);
|
|
6
|
-
}, []);
|
|
7
|
-
return isClient;
|
|
8
|
-
};
|
|
9
|
-
const ClientOnly = ({ children, fallback = null }) => {
|
|
10
|
-
const isClient = useIsClient();
|
|
11
|
-
if (!isClient) {
|
|
12
|
-
return fallback;
|
|
13
|
-
}
|
|
14
|
-
return children;
|
|
15
|
-
};
|
|
16
|
-
export {
|
|
17
|
-
ClientOnly,
|
|
18
|
-
useIsClient
|
|
19
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
function parseDeclaredModuleSource(value) {
|
|
2
|
-
const source = value.trim();
|
|
3
|
-
if (source.length === 0) return void 0;
|
|
4
|
-
const openBraceIndex = source.indexOf("{");
|
|
5
|
-
if (openBraceIndex < 0) return source;
|
|
6
|
-
const from = source.slice(0, openBraceIndex).trim();
|
|
7
|
-
return from.length > 0 ? from : void 0;
|
|
8
|
-
}
|
|
9
|
-
function normalizeDeclaredModuleSources(modules) {
|
|
10
|
-
const seen = /* @__PURE__ */ new Set();
|
|
11
|
-
for (const declaration of modules ?? []) {
|
|
12
|
-
const from = parseDeclaredModuleSource(declaration);
|
|
13
|
-
if (from) {
|
|
14
|
-
seen.add(from);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return Array.from(seen);
|
|
18
|
-
}
|
|
19
|
-
function collectDeclaredModulesInConfig(config, visited = /* @__PURE__ */ new Set()) {
|
|
20
|
-
if (!config || visited.has(config)) {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
visited.add(config);
|
|
24
|
-
const declarations = normalizeDeclaredModuleSources(config.dependencies?.modules);
|
|
25
|
-
if (config.layout?.config) {
|
|
26
|
-
declarations.push(...collectDeclaredModulesInConfig(config.layout.config, visited));
|
|
27
|
-
}
|
|
28
|
-
for (const component of config.dependencies?.components ?? []) {
|
|
29
|
-
if (component.config) {
|
|
30
|
-
declarations.push(...collectDeclaredModulesInConfig(component.config, visited));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return declarations;
|
|
34
|
-
}
|
|
35
|
-
function collectPageDeclaredModulesFromModule(pageModule) {
|
|
36
|
-
const declarations = [
|
|
37
|
-
...collectDeclaredModulesInConfig(pageModule.default?.config),
|
|
38
|
-
...collectDeclaredModulesInConfig(pageModule.config)
|
|
39
|
-
];
|
|
40
|
-
return Array.from(new Set(declarations));
|
|
41
|
-
}
|
|
42
|
-
async function collectPageDeclaredModules(pagePath) {
|
|
43
|
-
try {
|
|
44
|
-
const pageModule = await import(
|
|
45
|
-
/* @vite-ignore */
|
|
46
|
-
pagePath
|
|
47
|
-
);
|
|
48
|
-
return collectPageDeclaredModulesFromModule(pageModule);
|
|
49
|
-
} catch {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export {
|
|
54
|
-
collectDeclaredModulesInConfig,
|
|
55
|
-
collectPageDeclaredModules,
|
|
56
|
-
collectPageDeclaredModulesFromModule,
|
|
57
|
-
normalizeDeclaredModuleSources,
|
|
58
|
-
parseDeclaredModuleSource
|
|
59
|
-
};
|
package/src/utils/dynamic.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { lazy } from "react";
|
|
2
|
-
const NullComponent = () => null;
|
|
3
|
-
function dynamic(importFn, options = {}) {
|
|
4
|
-
const { ssr = false } = options;
|
|
5
|
-
if (ssr || typeof window !== "undefined") {
|
|
6
|
-
return lazy(importFn);
|
|
7
|
-
}
|
|
8
|
-
return NullComponent;
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
dynamic
|
|
12
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HMR script utilities for React components.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Checks if code has already been processed with HMR marker.
|
|
7
|
-
* @param code - The bundled code to check
|
|
8
|
-
* @returns True if the code already contains the HMR marker
|
|
9
|
-
*/
|
|
10
|
-
export declare function hasHmrMarker(code: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Injects HMR acceptance handler into bundled code.
|
|
13
|
-
* When a module with React exports changes, it triggers a full invalidation
|
|
14
|
-
* to ensure the parent module re-imports and re-renders with the updated component.
|
|
15
|
-
* @param code - The bundled code to wrap
|
|
16
|
-
* @returns Code with HMR handler injected
|
|
17
|
-
*/
|
|
18
|
-
export declare function injectHmrHandler(code: string): string;
|
package/src/utils/hmr-scripts.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const HMR_MARKER = "/* [ecopages] react-hmr */";
|
|
2
|
-
function hasHmrMarker(code) {
|
|
3
|
-
return code.includes(HMR_MARKER);
|
|
4
|
-
}
|
|
5
|
-
function injectHmrHandler(code) {
|
|
6
|
-
return `${HMR_MARKER}
|
|
7
|
-
${code}
|
|
8
|
-
if (import.meta.hot) {
|
|
9
|
-
import.meta.hot.accept((newModule) => {
|
|
10
|
-
if (newModule) {
|
|
11
|
-
const exports = Object.keys(newModule);
|
|
12
|
-
const hasReactExport = exports.some(key => {
|
|
13
|
-
const value = newModule[key];
|
|
14
|
-
return value && (
|
|
15
|
-
typeof value === 'function' ||
|
|
16
|
-
(typeof value === 'object' && value.$$typeof)
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
if (hasReactExport) {
|
|
21
|
-
import.meta.hot.invalidate();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
`;
|
|
27
|
-
}
|
|
28
|
-
export {
|
|
29
|
-
hasHmrMarker,
|
|
30
|
-
injectHmrHandler
|
|
31
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const VOID_TAGS = /* @__PURE__ */ new Set([
|
|
2
|
-
"area",
|
|
3
|
-
"base",
|
|
4
|
-
"br",
|
|
5
|
-
"col",
|
|
6
|
-
"embed",
|
|
7
|
-
"hr",
|
|
8
|
-
"img",
|
|
9
|
-
"input",
|
|
10
|
-
"link",
|
|
11
|
-
"meta",
|
|
12
|
-
"param",
|
|
13
|
-
"source",
|
|
14
|
-
"track",
|
|
15
|
-
"wbr"
|
|
16
|
-
]);
|
|
17
|
-
function hasSingleRootElement(html) {
|
|
18
|
-
const firstTagMatch = html.match(/^\s*<([a-zA-Z][a-zA-Z0-9:-]*)\b[^>]*>/);
|
|
19
|
-
if (!firstTagMatch) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
const firstTag = firstTagMatch[1].toLowerCase();
|
|
23
|
-
const firstTagText = firstTagMatch[0];
|
|
24
|
-
const firstTagStart = firstTagMatch.index ?? 0;
|
|
25
|
-
const firstTagEnd = firstTagStart + firstTagText.length;
|
|
26
|
-
const isSelfClosing = /\/\s*>$/.test(firstTagText);
|
|
27
|
-
if (isSelfClosing || VOID_TAGS.has(firstTag)) {
|
|
28
|
-
return html.slice(firstTagEnd).trim().length === 0;
|
|
29
|
-
}
|
|
30
|
-
const tokenRegex = /<\/?([a-zA-Z][a-zA-Z0-9:-]*)\b[^>]*>/g;
|
|
31
|
-
tokenRegex.lastIndex = firstTagEnd;
|
|
32
|
-
let depth = 1;
|
|
33
|
-
for (let token = tokenRegex.exec(html); token; token = tokenRegex.exec(html)) {
|
|
34
|
-
const tagText = token[0];
|
|
35
|
-
const tagName = token[1].toLowerCase();
|
|
36
|
-
const isClosing = tagText.startsWith("</");
|
|
37
|
-
const tokenSelfClosing = /\/\s*>$/.test(tagText);
|
|
38
|
-
if (VOID_TAGS.has(tagName) || tokenSelfClosing) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (isClosing) {
|
|
42
|
-
depth--;
|
|
43
|
-
if (depth === 0) {
|
|
44
|
-
const afterRoot = html.slice(token.index + token[0].length).trim();
|
|
45
|
-
return afterRoot.length === 0;
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
depth++;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
export {
|
|
54
|
-
hasSingleRootElement
|
|
55
|
-
};
|