@forgewp/compiler 0.4.3 → 0.4.4
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 +59 -0
- package/bin/add.js +20 -14
- package/bin/cli.js +145 -70
- package/bin/doctor.js +21 -12
- package/bin/export.js +69 -20
- package/bin/fresh.js +5 -0
- package/bin/i18n-extract.js +3 -10
- package/bin/i18n-translate.js +15 -24
- package/bin/make-block.js +13 -0
- package/bin/make-editable.js +166 -0
- package/bin/make-form.js +131 -0
- package/bin/make-loop.js +40 -43
- package/bin/make-mail.js +27 -0
- package/bin/make-post-type.js +57 -29
- package/bin/make-sandbox.js +62 -11
- package/bin/make-section.js +221 -0
- package/bin/make-shell.js +375 -0
- package/bin/repair.js +14 -26
- package/bin/seed.js +119 -0
- package/bin/sync-routes.js +107 -85
- package/lib/adapters/html-adapter.js +5 -0
- package/lib/adapters/stub-adapter.js +4 -0
- package/lib/add-component.js +153 -92
- package/lib/asset-loader.js +313 -3
- package/lib/assets/asset-graph.js +432 -0
- package/lib/assets/asset-pipeline.js +125 -0
- package/lib/assets/diagnostics-report.js +345 -0
- package/lib/assets/external-fetcher.js +173 -0
- package/lib/assets/font-orchestrator.js +348 -0
- package/lib/assets/font-usage-scanner.js +242 -0
- package/lib/assets/image-optimizer.js +229 -0
- package/lib/assets/index.js +51 -0
- package/lib/assets/preload-generator.js +70 -0
- package/lib/assets/public-url.js +153 -0
- package/lib/block-authoring-help.js +11 -0
- package/lib/blocks/ast-parser.js +67 -0
- package/lib/blocks/discover-blocks.js +146 -0
- package/lib/blocks/editor-scope.js +733 -0
- package/lib/blocks/editor-transpiler.js +1229 -0
- package/lib/blocks/index.js +2838 -0
- package/lib/blocks/php-transpiler.js +4928 -0
- package/lib/blocks/scanner.js +1487 -0
- package/lib/blocks/shared-utils.js +290 -0
- package/lib/blocks/source-sanitize.js +1449 -0
- package/lib/blueprints.js +31 -91
- package/lib/build-assets.js +38 -33
- package/lib/collect-page-template-routes.js +102 -0
- package/lib/collect-static-routes.js +175 -0
- package/lib/diagnostics.js +58 -33
- package/lib/export-theme.js +84 -5
- package/lib/extract-template-content.js +90 -0
- package/lib/forms-preview.js +42 -0
- package/lib/functions/cpt-routing.js +69 -0
- package/lib/functions/forms.js +2461 -0
- package/lib/functions/hydration-enqueuer.js +400 -0
- package/lib/functions/index.js +1623 -0
- package/lib/functions/load-menus.js +112 -0
- package/lib/functions/load-translations.js +148 -0
- package/lib/functions/rest-endpoints.js +2923 -0
- package/lib/functions/routing.js +765 -0
- package/lib/functions/seed-mock-data.js +392 -0
- package/lib/functions/seed-products.js +481 -0
- package/lib/functions/settings-page.js +273 -0
- package/lib/functions/theme-setup.js +494 -0
- package/lib/generate-theme.js +1916 -339
- package/lib/hydration/editable-schemas.js +332 -0
- package/lib/hydration/enter-hidden-initial.js +65 -0
- package/lib/hydration/form-schemas.js +227 -0
- package/lib/hydration/index.js +12 -0
- package/lib/hydration/is-interactive.js +951 -0
- package/lib/hydration/island-split.js +1231 -0
- package/lib/hydration/islands-scanner.js +599 -0
- package/lib/hydration/resolve-island-chunk.js +103 -0
- package/lib/hydration/resolve-island-component.js +52 -0
- package/lib/hydration/rollup-inputs.js +81 -0
- package/lib/hydration/root-class-extractor.js +220 -0
- package/lib/hydration/scan-app-providers.js +154 -0
- package/lib/hydration/static-lint.js +382 -0
- package/lib/hydration/transform.js +257 -0
- package/lib/hydration/uses-block-area.js +49 -0
- package/lib/hydration/utils.js +119 -0
- package/lib/i18n/translation-cache.js +141 -0
- package/lib/icon-registry.js +72 -0
- package/lib/index.d.ts +287 -8
- package/lib/index.js +2 -1
- package/lib/load-config.js +338 -242
- package/lib/mail-templates.js +37 -0
- package/lib/markup-processor.js +388 -102
- package/lib/node-runtime.js +7 -0
- package/lib/page-config-plugin.js +64 -20
- package/lib/php-builders.js +383 -44
- package/lib/react-adapter.js +983 -235
- package/lib/registration-metadata.js +11 -0
- package/lib/render-theme.mts +1410 -616
- package/lib/route-layout.js +76 -0
- package/lib/template-discovery.js +58 -0
- package/lib/theme-compatibility.js +32 -0
- package/lib/validate-export.js +2 -2
- package/lib/validate.js +27 -5
- package/lib/virtual-plugin.js +319 -0
- package/lib/walkthrough.md +26 -0
- package/package.json +16 -5
- package/templates/auth/cms/email-logs.json +9 -0
- package/templates/auth/cms/menus.json +11 -0
- package/templates/auth/cms/mock-data.json +123 -0
- package/templates/auth/cms/roles.json +7 -0
- package/templates/auth/cms/sessions.json +1 -0
- package/templates/auth/cms/site-settings.json +28 -0
- package/templates/auth/cms/translations.json +4 -0
- package/templates/auth/cms/users.json +46 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +10 -2
- package/templates/auth/components/login-form-wrapper.tsx +118 -21
- package/templates/auth/components/reset-password-form-wrapper.tsx +10 -2
- package/templates/auth/components/signup-form-wrapper.tsx +2 -2
- package/templates/auth/components/verify-email-view-wrapper.tsx +5 -5
- package/templates/auth/pages/DashboardPage.tsx +1 -4
- package/templates/auth/pages/ForgotPasswordPage.tsx +1 -4
- package/templates/auth/pages/LoginPage.tsx +1 -4
- package/templates/auth/pages/ResetPasswordPage.tsx +1 -4
- package/templates/auth/pages/SignUpPage.tsx +1 -4
- package/templates/auth/pages/VerifyEmailPage.tsx +1 -4
- package/templates/auth/ui/button.tsx +57 -0
- package/templates/auth/ui/card.tsx +76 -0
- package/templates/auth/ui/field.tsx +242 -0
- package/templates/auth/ui/input.tsx +22 -0
- package/templates/auth/ui/label.tsx +24 -0
- package/templates/auth/ui/separator.tsx +31 -0
- package/templates/menus.json +12 -10
- package/templates/users.json +8 -4
- package/templates/wordpress.tsx +690 -245
- package/lib/block-compiler.js +0 -552
- package/lib/functions-builder.js +0 -2970
- package/lib/hydration-scanner.js +0 -833
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { readFileSync, existsSync, writeFileSync, rmSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
|
|
8
|
+
export const _svgHtmlCache = new Map();
|
|
9
|
+
const fallbackRequire = createRequire(import.meta.url);
|
|
10
|
+
|
|
11
|
+
function loadIconPackageSync(packageName, themeRoot) {
|
|
12
|
+
globalThis._forgewp_icon_packages = globalThis._forgewp_icon_packages || {};
|
|
13
|
+
if (globalThis._forgewp_icon_packages[packageName]) {
|
|
14
|
+
return globalThis._forgewp_icon_packages[packageName];
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const pkgJsonFile = themeRoot ? path.join(themeRoot, 'package.json') : null;
|
|
18
|
+
const projectRequire = pkgJsonFile && existsSync(pkgJsonFile) ? createRequire(pkgJsonFile) : fallbackRequire;
|
|
19
|
+
const resolveMod = (id) => {
|
|
20
|
+
try { return projectRequire(id); } catch (_) { return fallbackRequire(id); }
|
|
21
|
+
};
|
|
22
|
+
if (!globalThis._forgewp_icon_packages['react']) {
|
|
23
|
+
globalThis._forgewp_icon_packages['react'] = resolveMod('react');
|
|
24
|
+
}
|
|
25
|
+
if (!globalThis._forgewp_icon_packages['react-dom/server']) {
|
|
26
|
+
const rdMod = resolveMod('react-dom/server');
|
|
27
|
+
const renderToStaticMarkup = rdMod.renderToStaticMarkup || rdMod.default?.renderToStaticMarkup;
|
|
28
|
+
globalThis._forgewp_icon_packages['react-dom/server'] = { renderToStaticMarkup };
|
|
29
|
+
}
|
|
30
|
+
let pkgJsonPath;
|
|
31
|
+
try { pkgJsonPath = projectRequire.resolve(`${packageName}/package.json`); }
|
|
32
|
+
catch (_) { pkgJsonPath = fallbackRequire.resolve(`${packageName}/package.json`); }
|
|
33
|
+
const pkgDir = path.dirname(pkgJsonPath);
|
|
34
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
35
|
+
const exp = pkgJson.exports?.['.'];
|
|
36
|
+
const cjsRel =
|
|
37
|
+
(typeof exp?.require === 'string' ? exp.require : exp?.require?.default) ||
|
|
38
|
+
(typeof exp?.node === 'string' ? exp.node : exp?.node?.default) ||
|
|
39
|
+
(!pkgJson.type || pkgJson.type === 'commonjs' ? pkgJson.main : null);
|
|
40
|
+
if (cjsRel) {
|
|
41
|
+
const cjsPath = path.resolve(pkgDir, cjsRel);
|
|
42
|
+
if (existsSync(cjsPath)) {
|
|
43
|
+
const mod = { exports: {} };
|
|
44
|
+
const fn = new Function('exports', 'require', 'module', '__filename', '__dirname', readFileSync(cjsPath, 'utf8'));
|
|
45
|
+
const localReq = createRequire(cjsPath);
|
|
46
|
+
fn(mod.exports, (id) => { try { return localReq(id); } catch (_) { return resolveMod(id); } }, mod, cjsPath, path.dirname(cjsPath));
|
|
47
|
+
globalThis._forgewp_icon_packages[packageName] = mod.exports;
|
|
48
|
+
return mod.exports;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch (_) {}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function warmupIconCache(themeRoot) {
|
|
56
|
+
try {
|
|
57
|
+
const pkgJsonPath = path.join(themeRoot, 'package.json');
|
|
58
|
+
if (!existsSync(pkgJsonPath)) return;
|
|
59
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
|
|
60
|
+
const deps = { ...pkgJson.dependencies, ...pkgJson.devDependencies };
|
|
61
|
+
|
|
62
|
+
const srcDir = path.join(themeRoot, 'src');
|
|
63
|
+
const discoveredPackages = new Set();
|
|
64
|
+
|
|
65
|
+
// Recursively scan src directory to find external package imports with PascalCase elements
|
|
66
|
+
function scanDir(dir) {
|
|
67
|
+
if (!existsSync(dir)) return;
|
|
68
|
+
const entries = readdirSync(dir);
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const fullPath = path.join(dir, entry);
|
|
71
|
+
const stat = statSync(fullPath);
|
|
72
|
+
if (stat.isDirectory()) {
|
|
73
|
+
scanDir(fullPath);
|
|
74
|
+
} else if (stat.isFile() && /\.(tsx|jsx|ts|js)$/.test(entry)) {
|
|
75
|
+
try {
|
|
76
|
+
const content = readFileSync(fullPath, 'utf8');
|
|
77
|
+
const importRx = /import\s+(?:type\s+)?(?:\{([^}]+)\}|([A-Za-z0-9_$]+))\s+from\s+['"]([^'"]+)['"]/g;
|
|
78
|
+
let match;
|
|
79
|
+
while ((match = importRx.exec(content)) !== null) {
|
|
80
|
+
const namedImports = match[1];
|
|
81
|
+
const defaultImport = match[2];
|
|
82
|
+
const fromPkg = match[3];
|
|
83
|
+
|
|
84
|
+
if (fromPkg.startsWith('.') || fromPkg.startsWith('@/') || fromPkg.startsWith('react') || fromPkg.startsWith('next')) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let hasPascalCase = false;
|
|
89
|
+
if (namedImports) {
|
|
90
|
+
for (const name of namedImports.split(',')) {
|
|
91
|
+
const n = name.replace(/\s+as\s+\S+/, '').trim();
|
|
92
|
+
if (n && /^[A-Z]/.test(n)) {
|
|
93
|
+
hasPascalCase = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else if (defaultImport && /^[A-Z]/.test(defaultImport)) {
|
|
98
|
+
hasPascalCase = true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (hasPascalCase && deps[fromPkg]) {
|
|
102
|
+
discoveredPackages.add(fromPkg);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch (_) {}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
scanDir(srcDir);
|
|
110
|
+
|
|
111
|
+
const iconPackages = Array.from(discoveredPackages);
|
|
112
|
+
|
|
113
|
+
if (iconPackages.length === 0) return;
|
|
114
|
+
|
|
115
|
+
const projectRequire = createRequire(pkgJsonPath);
|
|
116
|
+
|
|
117
|
+
// Pre-import React and React DOM Server
|
|
118
|
+
const reactEntry = projectRequire.resolve('react');
|
|
119
|
+
const rdEntry = projectRequire.resolve('react-dom/server');
|
|
120
|
+
const React = (await import(pathToFileURL(reactEntry).href)).default || (await import(pathToFileURL(reactEntry).href));
|
|
121
|
+
const rdMod = await import(pathToFileURL(rdEntry).href);
|
|
122
|
+
const renderToStaticMarkup = rdMod.renderToStaticMarkup || rdMod.default?.renderToStaticMarkup;
|
|
123
|
+
|
|
124
|
+
globalThis._forgewp_icon_packages = globalThis._forgewp_icon_packages || {};
|
|
125
|
+
globalThis._forgewp_icon_packages['react'] = React;
|
|
126
|
+
globalThis._forgewp_icon_packages['react-dom/server'] = { renderToStaticMarkup };
|
|
127
|
+
|
|
128
|
+
for (const pkgName of iconPackages) {
|
|
129
|
+
if (loadIconPackageSync(pkgName, themeRoot)) continue;
|
|
130
|
+
try {
|
|
131
|
+
const pkgJsonPath = projectRequire.resolve(`${pkgName}/package.json`);
|
|
132
|
+
const pkgDir = path.dirname(pkgJsonPath);
|
|
133
|
+
const resolvedPkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
|
|
134
|
+
const esmRelEntry = resolvedPkgJson.module || resolvedPkgJson.exports?.['.']?.import || resolvedPkgJson.main;
|
|
135
|
+
const pkgEntry = path.resolve(pkgDir, esmRelEntry);
|
|
136
|
+
|
|
137
|
+
const pkg = await import(pathToFileURL(pkgEntry).href);
|
|
138
|
+
globalThis._forgewp_icon_packages[pkgName] = pkg;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
// Quietly fail for non-esm/non-icon libraries to avoid console noise
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.warn('[ForgeWP Compiler] Failed to warmup icon cache:', e.message);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
export function resolvePackageEsmEntry(packageName, themeRoot) {
|
|
151
|
+
const pr = createRequire(path.join(themeRoot, 'package.json'));
|
|
152
|
+
const pkgJsonPath = pr.resolve(`${packageName}/package.json`);
|
|
153
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
154
|
+
const entry = pkgJson.module || pkgJson.exports?.['.']?.import || pkgJson.main;
|
|
155
|
+
return pr.resolve(`${packageName}/${entry}`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Dynamically resolves an icon component to an SVG string by spawning a tiny
|
|
160
|
+
* ESM child process that uses pathToFileURL + dynamic import + renderToStaticMarkup.
|
|
161
|
+
*/
|
|
162
|
+
export function resolveIconToSvgHtml(componentName, packageName, themeRoot, classNameStr) {
|
|
163
|
+
const cacheKey = `${packageName}::${componentName}::${classNameStr}`;
|
|
164
|
+
if (_svgHtmlCache.has(cacheKey)) return _svgHtmlCache.get(cacheKey);
|
|
165
|
+
|
|
166
|
+
// 1. Try to render from in-process cache (warming synchronously via CJS entry when available)
|
|
167
|
+
loadIconPackageSync(packageName, themeRoot);
|
|
168
|
+
if (globalThis._forgewp_icon_packages && globalThis._forgewp_icon_packages[packageName]) {
|
|
169
|
+
const pkg = globalThis._forgewp_icon_packages[packageName];
|
|
170
|
+
const React = globalThis._forgewp_icon_packages['react'];
|
|
171
|
+
const rd = globalThis._forgewp_icon_packages['react-dom/server'];
|
|
172
|
+
|
|
173
|
+
if (pkg && React && rd) {
|
|
174
|
+
const Icon = pkg[componentName];
|
|
175
|
+
if (Icon) {
|
|
176
|
+
const FinalIcon = (typeof Icon === 'function') ? Icon : (Icon && (Icon.$$typeof || Icon.render) ? Icon : (Icon && Icon.default ? Icon.default : null));
|
|
177
|
+
if (FinalIcon) {
|
|
178
|
+
try {
|
|
179
|
+
const html = rd.renderToStaticMarkup(React.createElement(FinalIcon, { className: classNameStr || '' }));
|
|
180
|
+
if (html && html.startsWith('<svg')) {
|
|
181
|
+
_svgHtmlCache.set(cacheKey, html);
|
|
182
|
+
return html;
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.warn(`[ForgeWP Compiler] Cache render failed for ${componentName}:`, e.message);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
const projectRequire = createRequire(path.join(themeRoot, 'package.json'));
|
|
195
|
+
|
|
196
|
+
// Resolve absolute ESM entry for the icon package
|
|
197
|
+
const pkgJsonPath = projectRequire.resolve(`${packageName}/package.json`);
|
|
198
|
+
const pkgDir = path.dirname(pkgJsonPath);
|
|
199
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
200
|
+
const esmRelEntry = pkgJson.module || pkgJson.exports?.['.']?.import || pkgJson.main;
|
|
201
|
+
const pkgEntry = path.resolve(pkgDir, esmRelEntry);
|
|
202
|
+
|
|
203
|
+
// React and react-dom/server can use their default resolution
|
|
204
|
+
const reactEntry = projectRequire.resolve('react');
|
|
205
|
+
const rdEntry = projectRequire.resolve('react-dom/server');
|
|
206
|
+
|
|
207
|
+
const lines = [
|
|
208
|
+
`import { pathToFileURL } from 'url';`,
|
|
209
|
+
`const React = (await import(pathToFileURL(${JSON.stringify(reactEntry)}).href)).default;`,
|
|
210
|
+
`const rdMod = await import(pathToFileURL(${JSON.stringify(rdEntry)}).href);`,
|
|
211
|
+
`const renderToStaticMarkup = rdMod.renderToStaticMarkup || rdMod.default?.renderToStaticMarkup;`,
|
|
212
|
+
`const pkg = await import(pathToFileURL(${JSON.stringify(pkgEntry)}).href);`,
|
|
213
|
+
`const Icon = pkg[${JSON.stringify(componentName)}];`,
|
|
214
|
+
`const FinalIcon = (typeof Icon === 'function') ? Icon : (Icon && (Icon.$$typeof || Icon.render) ? Icon : (Icon && Icon.default ? Icon.default : null));`,
|
|
215
|
+
`if (!FinalIcon) { process.stdout.write(''); process.exit(0); }`,
|
|
216
|
+
`const html = renderToStaticMarkup(React.createElement(FinalIcon, { className: ${JSON.stringify(classNameStr || '')} }));`,
|
|
217
|
+
`process.stdout.write(html);`,
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
const tmpFile = path.join(tmpdir(), `_forgewp_icon_${Date.now()}.mjs`);
|
|
221
|
+
writeFileSync(tmpFile, lines.join('\n'), 'utf8');
|
|
222
|
+
|
|
223
|
+
let svgHtml = '';
|
|
224
|
+
try {
|
|
225
|
+
svgHtml = execSync(`node ${JSON.stringify(tmpFile)}`, {
|
|
226
|
+
encoding: 'utf8',
|
|
227
|
+
timeout: 10000,
|
|
228
|
+
}).trim();
|
|
229
|
+
} finally {
|
|
230
|
+
try { rmSync(tmpFile); } catch (_) {}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!svgHtml || !svgHtml.startsWith('<svg')) {
|
|
234
|
+
_svgHtmlCache.set(cacheKey, null);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_svgHtmlCache.set(cacheKey, svgHtml);
|
|
239
|
+
return svgHtml;
|
|
240
|
+
} catch (_) {
|
|
241
|
+
_svgHtmlCache.set(cacheKey, null);
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function findHtmlTagEnd(code, startPos) {
|
|
247
|
+
let depth = 0;
|
|
248
|
+
let braceDepth = 0;
|
|
249
|
+
let inQuote = false;
|
|
250
|
+
let quoteChar = '';
|
|
251
|
+
let insidePhp = false;
|
|
252
|
+
let pos = startPos;
|
|
253
|
+
while (pos < code.length) {
|
|
254
|
+
const c = code[pos];
|
|
255
|
+
|
|
256
|
+
if (insidePhp) {
|
|
257
|
+
if (code.substring(pos, pos + 2) === '?>') {
|
|
258
|
+
insidePhp = false;
|
|
259
|
+
pos += 2;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
} else if (code.substring(pos, pos + 5) === '<?php') {
|
|
263
|
+
insidePhp = true;
|
|
264
|
+
pos += 5;
|
|
265
|
+
continue;
|
|
266
|
+
} else if (inQuote) {
|
|
267
|
+
if (c === quoteChar) {
|
|
268
|
+
inQuote = false;
|
|
269
|
+
}
|
|
270
|
+
} else if (c === '"' || c === "'" || c === '`') {
|
|
271
|
+
inQuote = true;
|
|
272
|
+
quoteChar = c;
|
|
273
|
+
} else if (c === '{') {
|
|
274
|
+
braceDepth++;
|
|
275
|
+
} else if (c === '}') {
|
|
276
|
+
if (braceDepth > 0) braceDepth--;
|
|
277
|
+
} else if (braceDepth === 0) {
|
|
278
|
+
if (c === '<') {
|
|
279
|
+
depth++;
|
|
280
|
+
} else if (c === '>') {
|
|
281
|
+
depth--;
|
|
282
|
+
if (depth === 0) {
|
|
283
|
+
return pos;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
pos++;
|
|
288
|
+
}
|
|
289
|
+
return -1;
|
|
290
|
+
}
|