@opengsd/gsd-core 1.15.0 → 1.16.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.opencode/plugins/gsd-core.js +85 -5
- package/agents/gsd-code-fixer.compact.md +1 -1
- package/agents/gsd-code-fixer.md +1 -1
- package/agents/gsd-code-reviewer.compact.md +5 -3
- package/agents/gsd-code-reviewer.md +8 -6
- package/agents/gsd-debug-session-manager.compact.md +1 -1
- package/agents/gsd-debug-session-manager.md +1 -1
- package/agents/gsd-debugger.md +2 -2
- package/agents/gsd-eval-auditor.compact.md +1 -1
- package/agents/gsd-eval-auditor.md +1 -1
- package/agents/gsd-executor.md +4 -4
- package/agents/gsd-intel-updater.compact.md +1 -1
- package/agents/gsd-intel-updater.md +1 -1
- package/agents/gsd-mempalace-curator.md +2 -2
- package/agents/gsd-phase-researcher.md +1 -1
- package/agents/gsd-plan-checker.md +7 -2
- package/agents/gsd-planner.md +3 -3
- package/agents/gsd-project-researcher.compact.md +1 -1
- package/agents/gsd-project-researcher.md +1 -1
- package/agents/gsd-research-synthesizer.compact.md +1 -1
- package/agents/gsd-research-synthesizer.md +1 -1
- package/agents/gsd-ui-auditor.compact.md +21 -30
- package/agents/gsd-ui-auditor.md +42 -51
- package/agents/gsd-ui-researcher.compact.md +1 -1
- package/agents/gsd-ui-researcher.md +1 -1
- package/agents/gsd-verifier.md +31 -9
- package/bin/install.js +126 -196
- package/commands/gsd/add-tests.md +6 -1
- package/commands/gsd/ai-integration-phase.md +6 -1
- package/commands/gsd/audit-fix.md +5 -0
- package/commands/gsd/audit-milestone.md +6 -1
- package/commands/gsd/autonomous.md +5 -0
- package/commands/gsd/capture.md +8 -4
- package/commands/gsd/code-review.md +7 -2
- package/commands/gsd/complete-milestone.md +4 -0
- package/commands/gsd/config.md +7 -3
- package/commands/gsd/debug.md +11 -7
- package/commands/gsd/discuss-phase.md +7 -3
- package/commands/gsd/docs-update.md +12 -7
- package/commands/gsd/eval-review.md +6 -1
- package/commands/gsd/execute-phase.md +12 -7
- package/commands/gsd/extract-learnings.md +5 -0
- package/commands/gsd/fast.md +4 -0
- package/commands/gsd/forensics.md +5 -1
- package/commands/gsd/graphify.md +10 -6
- package/commands/gsd/health.md +5 -0
- package/commands/gsd/help.md +7 -2
- package/commands/gsd/import.md +7 -3
- package/commands/gsd/inbox.md +5 -0
- package/commands/gsd/ingest-docs.md +5 -1
- package/commands/gsd/manager.md +6 -1
- package/commands/gsd/map-codebase.md +7 -3
- package/commands/gsd/mempalace-capture.md +5 -1
- package/commands/gsd/mempalace-recall.md +5 -1
- package/commands/gsd/milestone-summary.md +5 -1
- package/commands/gsd/mvp-phase.md +8 -3
- package/commands/gsd/new-milestone.md +6 -1
- package/commands/gsd/new-project.md +5 -0
- package/commands/gsd/next.md +6 -1
- package/commands/gsd/ns-context.md +4 -0
- package/commands/gsd/ns-ideate.md +4 -0
- package/commands/gsd/ns-manage.md +4 -0
- package/commands/gsd/ns-project.md +4 -0
- package/commands/gsd/ns-review.md +4 -0
- package/commands/gsd/ns-workflow.md +4 -0
- package/commands/gsd/onboard.md +6 -1
- package/commands/gsd/pause-work.md +5 -1
- package/commands/gsd/phase.md +8 -4
- package/commands/gsd/plan-phase.md +6 -1
- package/commands/gsd/plan-review-convergence.md +5 -1
- package/commands/gsd/pr-branch.md +4 -0
- package/commands/gsd/profile-user.md +5 -1
- package/commands/gsd/progress.md +6 -1
- package/commands/gsd/quick-batch.md +20 -8
- package/commands/gsd/quick.md +12 -7
- package/commands/gsd/review.md +5 -1
- package/commands/gsd/secure-phase.md +6 -1
- package/commands/gsd/ship.md +5 -0
- package/commands/gsd/sketch.md +7 -2
- package/commands/gsd/spec-phase.md +5 -1
- package/commands/gsd/spike.md +8 -3
- package/commands/gsd/surface.md +5 -1
- package/commands/gsd/thread.md +4 -0
- package/commands/gsd/ui-phase.md +6 -1
- package/commands/gsd/ui-review.md +6 -1
- package/commands/gsd/ultraplan-phase.md +5 -1
- package/commands/gsd/undo.md +5 -1
- package/commands/gsd/update.md +6 -2
- package/commands/gsd/validate-phase.md +6 -1
- package/commands/gsd/verify-work.md +6 -1
- package/commands/gsd/workspace.md +7 -3
- package/gsd-core/bin/gsd-tools.cjs +142 -56
- package/gsd-core/bin/lib/active-workstream-store.cjs +15 -0
- package/gsd-core/bin/lib/agent-install-check.cjs +4 -1
- package/gsd-core/bin/lib/audit.cjs +78 -44
- package/gsd-core/bin/lib/broken-windows.cjs +13 -13
- package/gsd-core/bin/lib/capability-activation.cjs +9 -4
- package/gsd-core/bin/lib/capability-registry.cjs +183 -103
- package/gsd-core/bin/lib/capability-validator.cjs +16 -0
- package/gsd-core/bin/lib/check-auto-mode.cjs +35 -0
- package/gsd-core/bin/lib/check-command-router.cjs +164 -1712
- package/gsd-core/bin/lib/cjs-command-router-adapter.cjs +13 -2
- package/gsd-core/bin/lib/cli-exit.cjs +12 -0
- package/gsd-core/bin/lib/codex-agent-toml.cjs +11 -8
- package/gsd-core/bin/lib/command-aliases.cjs +7 -0
- package/gsd-core/bin/lib/command-routing-hub.cjs +48 -1
- package/gsd-core/bin/lib/commands.cjs +173 -170
- package/gsd-core/bin/lib/complexity-trigger.cjs +8 -7
- package/gsd-core/bin/lib/config.cjs +43 -12
- package/gsd-core/bin/lib/core-utils.cjs +6 -1
- package/gsd-core/bin/lib/coverage.cjs +4 -8
- package/gsd-core/bin/lib/decision-coverage-support.cjs +259 -0
- package/gsd-core/bin/lib/drift.cjs +177 -42
- package/gsd-core/bin/lib/frontmatter-fence.cjs +90 -0
- package/gsd-core/bin/lib/frontmatter-splice.cjs +494 -0
- package/gsd-core/bin/lib/frontmatter.cjs +413 -234
- package/gsd-core/bin/lib/gap-checker.cjs +72 -29
- package/gsd-core/bin/lib/gate-api-coverage-verify-pre.cjs +381 -0
- package/gsd-core/bin/lib/gate-args.cjs +53 -0
- package/gsd-core/bin/lib/gate-codebase-drift.cjs +285 -0
- package/gsd-core/bin/lib/gate-config.cjs +46 -0
- package/gsd-core/bin/lib/gate-context-drift.cjs +141 -0
- package/gsd-core/bin/lib/gate-decision-coverage-plan.cjs +169 -0
- package/gsd-core/bin/lib/gate-decision-coverage-verify.cjs +126 -0
- package/gsd-core/bin/lib/gate-evaluation-scope.cjs +555 -0
- package/gsd-core/bin/lib/gate-evidence.cjs +138 -0
- package/gsd-core/bin/lib/gate-exit.cjs +27 -0
- package/gsd-core/bin/lib/gate-gap-analysis-plan-post.cjs +61 -0
- package/gsd-core/bin/lib/gate-phase-context.cjs +170 -0
- package/gsd-core/bin/lib/gate-predicate-evaluator.cjs +1 -1
- package/gsd-core/bin/lib/gate-predicate.cjs +165 -0
- package/gsd-core/bin/lib/gate-prohibition-enforcement.cjs +94 -0
- package/gsd-core/bin/lib/gate-schema-drift.cjs +165 -0
- package/gsd-core/bin/lib/gate-tdd-red-evidence.cjs +100 -0
- package/gsd-core/bin/lib/gate-tdd-review-checkpoint.cjs +182 -0
- package/gsd-core/bin/lib/gate-ui-plan.cjs +86 -0
- package/gsd-core/bin/lib/gate-ui-safety.cjs +80 -0
- package/gsd-core/bin/lib/gate-verdict.cjs +64 -0
- package/gsd-core/bin/lib/gate-verify-command-paths.cjs +78 -0
- package/gsd-core/bin/lib/gate-verify-failure-directions.cjs +41 -0
- package/gsd-core/bin/lib/health-diagnostic-rules/phase-structure.cjs +43 -47
- package/gsd-core/bin/lib/health-diagnostic.cjs +45 -8
- package/gsd-core/bin/lib/init.cjs +162 -96
- package/gsd-core/bin/lib/install-engine.cjs +19 -35
- package/gsd-core/bin/lib/install-profiles.cjs +7 -4
- package/gsd-core/bin/lib/io.cjs +122 -3
- package/gsd-core/bin/lib/loop-resolver.cjs +95 -0
- package/gsd-core/bin/lib/markdown-sectionizer.cjs +75 -1
- package/gsd-core/bin/lib/milestone.cjs +19 -1
- package/gsd-core/bin/lib/model-resolver.cjs +18 -18
- package/gsd-core/bin/lib/observability/event.cjs +1 -1
- package/gsd-core/bin/lib/observability/logger.cjs +46 -1
- package/gsd-core/bin/lib/pattern.cjs +10 -0
- package/gsd-core/bin/lib/phase-command-router.cjs +11 -4
- package/gsd-core/bin/lib/phase-estimation.cjs +5 -4
- package/gsd-core/bin/lib/phase-id.cjs +1 -1
- package/gsd-core/bin/lib/phase-lifecycle.cjs +9 -2
- package/gsd-core/bin/lib/phase-status.cjs +360 -0
- package/gsd-core/bin/lib/phase.cjs +280 -80
- package/gsd-core/bin/lib/plan-document.cjs +93 -19
- package/gsd-core/bin/lib/plan-drift-guard.cjs +5 -0
- package/gsd-core/bin/lib/planning-document.cjs +273 -40
- package/gsd-core/bin/lib/planning-inspect.cjs +42 -8
- package/gsd-core/bin/lib/planning-snapshot.cjs +18 -0
- package/gsd-core/bin/lib/planning-workspace.cjs +76 -53
- package/gsd-core/bin/lib/pristine-baseline.cjs +10 -0
- package/gsd-core/bin/lib/profile-output.cjs +6 -3
- package/gsd-core/bin/lib/prohibition-enforcement.cjs +0 -55
- package/gsd-core/bin/lib/quick-batch-command-router.cjs +35 -9
- package/gsd-core/bin/lib/quick-batch-dispatch.cjs +11 -8
- package/gsd-core/bin/lib/real-home-guard.cjs +9 -1
- package/gsd-core/bin/lib/report-parser.cjs +269 -0
- package/gsd-core/bin/lib/roadmap-command-router.cjs +13 -15
- package/gsd-core/bin/lib/roadmap-parser.cjs +82 -15
- package/gsd-core/bin/lib/roadmap-upgrade.cjs +127 -65
- package/gsd-core/bin/lib/roadmap.cjs +169 -72
- package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +91 -157
- package/gsd-core/bin/lib/runtime-artifact-install-plan.cjs +2 -1
- package/gsd-core/bin/lib/runtime-artifact-layout.cjs +57 -1
- package/gsd-core/bin/lib/runtime-homes.cjs +13 -10
- package/gsd-core/bin/lib/runtime-hooks-surface.cjs +307 -591
- package/gsd-core/bin/lib/runtime-name-policy.cjs +142 -27
- package/gsd-core/bin/lib/runtime-slash.cjs +47 -30
- package/gsd-core/bin/lib/shell-command-projection.cjs +37 -2
- package/gsd-core/bin/lib/smart-entry.cjs +19 -3
- package/gsd-core/bin/lib/stale-bake-guard.cjs +32 -48
- package/gsd-core/bin/lib/state-contract.cjs +15 -18
- package/gsd-core/bin/lib/state-document.cjs +100 -22
- package/gsd-core/bin/lib/state.cjs +214 -105
- package/gsd-core/bin/lib/surface.cjs +2 -1
- package/gsd-core/bin/lib/tdd-red-evidence.cjs +48 -152
- package/gsd-core/bin/lib/uat-predicate.cjs +313 -35
- package/gsd-core/bin/lib/uat.cjs +424 -7
- package/gsd-core/bin/lib/ui-frontend-evidence.cjs +94 -58
- package/gsd-core/bin/lib/vendor/README.md +31 -9
- package/gsd-core/bin/lib/vendor/saxes.cjs +1934 -0
- package/gsd-core/bin/lib/vendor/saxes.cjs.LICENSE.txt +92 -0
- package/gsd-core/bin/lib/vendor/tap-parser.cjs +8927 -0
- package/gsd-core/bin/lib/vendor/tap-parser.cjs.LICENSE.txt +152 -0
- package/gsd-core/bin/lib/verification-command-router.cjs +2 -1
- package/gsd-core/bin/lib/verification.cjs +1165 -314
- package/gsd-core/bin/lib/verify-command-router.cjs +18 -7
- package/gsd-core/bin/lib/verify.cjs +286 -567
- package/gsd-core/bin/lib/workstream-inventory-builder.cjs +14 -6
- package/gsd-core/bin/lib/workstream-inventory.cjs +31 -21
- package/gsd-core/bin/lib/workstream-name-policy.cjs +31 -1
- package/gsd-core/bin/lib/workstream.cjs +11 -2
- package/gsd-core/bin/shared/config-defaults.manifest.json +5 -0
- package/gsd-core/bin/shared/config-schema.manifest.json +4 -0
- package/gsd-core/references/autonomous-smart-discuss.md +2 -1
- package/gsd-core/references/autonomous-ui-design-contract.md +3 -3
- package/gsd-core/references/execute-mvp-tdd.md +5 -10
- package/gsd-core/references/execute-phase-between-wave-reset.md +3 -0
- package/gsd-core/references/execute-phase-response-language.md +1 -1
- package/gsd-core/references/gsd-run-resolver.md +1 -1
- package/gsd-core/references/loop-hook-dispatch.md +7 -1
- package/gsd-core/references/offer-next.md +1 -1
- package/gsd-core/references/planning-config.md +1 -1
- package/gsd-core/references/spidr-splitting.md +1 -1
- package/gsd-core/references/tdd.md +10 -4
- package/gsd-core/references/verifier-phase-gates.md +5 -2
- package/gsd-core/references/verify-mvp-mode.md +2 -2
- package/gsd-core/references/workstream-flag.md +33 -3
- package/gsd-core/templates/README.md +1 -1
- package/gsd-core/templates/UAT.md +17 -1
- package/gsd-core/templates/config.json +2 -11
- package/gsd-core/templates/verification-report.md +1 -1
- package/gsd-core/workflows/_runtime-launcher.snippet.sh +1 -1
- package/gsd-core/workflows/add-backlog.md +1 -1
- package/gsd-core/workflows/add-phase.md +8 -7
- package/gsd-core/workflows/add-tests.md +3 -2
- package/gsd-core/workflows/add-todo.md +4 -3
- package/gsd-core/workflows/ai-integration-phase.md +3 -2
- package/gsd-core/workflows/audit-fix.md +1 -1
- package/gsd-core/workflows/audit-milestone.md +4 -3
- package/gsd-core/workflows/audit-uat.md +1 -1
- package/gsd-core/workflows/autonomous.md +28 -18
- package/gsd-core/workflows/check-todos.md +6 -5
- package/gsd-core/workflows/cleanup.md +1 -1
- package/gsd-core/workflows/code-review/steps/structural-pre-pass.md +20 -13
- package/gsd-core/workflows/code-review-fix.md +5 -4
- package/gsd-core/workflows/code-review.md +84 -90
- package/gsd-core/workflows/complete-milestone/detail/elaboration.md +4 -3
- package/gsd-core/workflows/complete-milestone.md +12 -7
- package/gsd-core/workflows/debug.md +30 -5
- package/gsd-core/workflows/diagnose-issues.md +3 -2
- package/gsd-core/workflows/discuss-phase/modes/advisor.md +1 -1
- package/gsd-core/workflows/discuss-phase/modes/chain.md +1 -1
- package/gsd-core/workflows/discuss-phase-assumptions.md +4 -3
- package/gsd-core/workflows/discuss-phase.md +4 -3
- package/gsd-core/workflows/do.md +1 -1
- package/gsd-core/workflows/docs-update.md +4 -3
- package/gsd-core/workflows/edit-phase.md +4 -3
- package/gsd-core/workflows/eval-review.md +5 -3
- package/gsd-core/workflows/execute-phase/detail/elaboration.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/code-review-disposition.md +4 -2
- package/gsd-core/workflows/execute-phase/steps/codebase-drift-gate.md +15 -4
- package/gsd-core/workflows/execute-phase/steps/completion-reconciliation.md +10 -7
- package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/gap-closure-artifacts.md +3 -1
- package/gsd-core/workflows/execute-phase/steps/partial-wave.md +2 -2
- package/gsd-core/workflows/execute-phase/steps/per-plan-executor-routing.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/post-merge-gate.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/protected-branch.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/regression-gate-run.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/regression-gate.md +2 -0
- package/gsd-core/workflows/execute-phase/steps/tdd-applicability-resolution.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/verify-phase-goal.md +187 -0
- package/gsd-core/workflows/execute-phase/steps/wave-post-gate-hooks.md +2 -3
- package/gsd-core/workflows/execute-phase.md +78 -170
- package/gsd-core/workflows/execute-plan.md +13 -19
- package/gsd-core/workflows/explore.md +2 -2
- package/gsd-core/workflows/extract-learnings.md +3 -2
- package/gsd-core/workflows/fast.md +1 -1
- package/gsd-core/workflows/forensics.md +1 -1
- package/gsd-core/workflows/graduation.md +1 -1
- package/gsd-core/workflows/health.md +2 -1
- package/gsd-core/workflows/import.md +3 -2
- package/gsd-core/workflows/inbox.md +1 -1
- package/gsd-core/workflows/ingest-docs.md +1 -1
- package/gsd-core/workflows/insert-phase.md +4 -3
- package/gsd-core/workflows/list-seeds.md +1 -1
- package/gsd-core/workflows/list-workspaces.md +1 -1
- package/gsd-core/workflows/manager.md +5 -3
- package/gsd-core/workflows/map-codebase.md +4 -3
- package/gsd-core/workflows/milestone-summary.md +3 -2
- package/gsd-core/workflows/mvp-phase.md +14 -14
- package/gsd-core/workflows/new-milestone.md +10 -10
- package/gsd-core/workflows/new-project/steps/auto-mode-config.md +1 -1
- package/gsd-core/workflows/new-project.md +1 -1
- package/gsd-core/workflows/new-workspace.md +1 -1
- package/gsd-core/workflows/next.md +1 -1
- package/gsd-core/workflows/pause-work.md +2 -2
- package/gsd-core/workflows/plan-phase/detail/elaboration.md +1 -1
- package/gsd-core/workflows/plan-phase/steps/chunked-planning-mode.md +1 -1
- package/gsd-core/workflows/plan-phase/steps/closed-phase-gate.md +1 -1
- package/gsd-core/workflows/plan-phase/steps/prd-express-path.md +1 -1
- package/gsd-core/workflows/plan-phase/steps/stall-detection-helpers.md +1 -1
- package/gsd-core/workflows/plan-phase.md +27 -18
- package/gsd-core/workflows/plan-review-convergence.md +1 -1
- package/gsd-core/workflows/plant-seed.md +1 -1
- package/gsd-core/workflows/pr-branch.md +1 -1
- package/gsd-core/workflows/profile-user.md +1 -1
- package/gsd-core/workflows/progress.md +19 -49
- package/gsd-core/workflows/quick/steps/plan-checker-loop.md +4 -2
- package/gsd-core/workflows/quick/steps/quick-verification.md +4 -4
- package/gsd-core/workflows/quick/steps/worktree-pre-dispatch-commit.md +30 -11
- package/gsd-core/workflows/quick-batch/steps/batch-init.md +1 -1
- package/gsd-core/workflows/quick-batch/steps/completion.md +1 -1
- package/gsd-core/workflows/quick-batch/steps/merge-wave.md +1 -1
- package/gsd-core/workflows/quick-batch/steps/planner-wave.md +1 -1
- package/gsd-core/workflows/quick-batch/steps/research-phase.md +1 -1
- package/gsd-core/workflows/quick-batch/steps/resume-mode.md +1 -1
- package/gsd-core/workflows/quick-batch/steps/verification-wave.md +9 -3
- package/gsd-core/workflows/quick-batch/steps/worktree-dispatch.md +1 -1
- package/gsd-core/workflows/quick-batch.md +15 -10
- package/gsd-core/workflows/quick.md +42 -31
- package/gsd-core/workflows/remove-phase.md +3 -2
- package/gsd-core/workflows/remove-workspace.md +1 -1
- package/gsd-core/workflows/resume-project.md +3 -2
- package/gsd-core/workflows/review.md +3 -2
- package/gsd-core/workflows/scan.md +3 -2
- package/gsd-core/workflows/secure-phase.md +11 -12
- package/gsd-core/workflows/settings-advanced.md +1 -1
- package/gsd-core/workflows/settings-integrations.md +1 -1
- package/gsd-core/workflows/settings.md +1 -1
- package/gsd-core/workflows/ship.md +12 -12
- package/gsd-core/workflows/sketch-wrap-up.md +1 -1
- package/gsd-core/workflows/sketch.md +1 -1
- package/gsd-core/workflows/smart-entry.md +1 -1
- package/gsd-core/workflows/spec-phase.md +1 -1
- package/gsd-core/workflows/spike-wrap-up.md +1 -1
- package/gsd-core/workflows/spike.md +1 -1
- package/gsd-core/workflows/stats.md +1 -1
- package/gsd-core/workflows/sync-skills.md +1 -1
- package/gsd-core/workflows/thread.md +2 -2
- package/gsd-core/workflows/transition.md +13 -23
- package/gsd-core/workflows/ui-phase.md +5 -4
- package/gsd-core/workflows/ui-review.md +4 -3
- package/gsd-core/workflows/ultraplan-phase.md +3 -2
- package/gsd-core/workflows/undo.md +1 -1
- package/gsd-core/workflows/validate-phase.md +10 -12
- package/gsd-core/workflows/verify-work/detail/elaboration.md +43 -3
- package/gsd-core/workflows/verify-work/steps/automated-ui-verification.md +1 -1
- package/gsd-core/workflows/verify-work/steps/mvp-uat-framing.md +5 -3
- package/gsd-core/workflows/verify-work.md +68 -59
- package/hooks/dist/gsd-agent-isolation-guard.js +8 -0
- package/hooks/dist/gsd-check-update-worker.js +8 -0
- package/hooks/dist/gsd-check-update.js +8 -0
- package/hooks/dist/gsd-context-monitor.js +31 -8
- package/hooks/dist/gsd-cursor-subagent-start.js +8 -0
- package/hooks/dist/gsd-secret-read-guard.js +147 -16
- package/hooks/dist/gsd-statusline.js +15 -7
- package/hooks/dist/gsd-update-banner.js +8 -0
- package/hooks/dist/gsd-windsurf-pre-write.js +11 -2
- package/hooks/dist/gsd-workflow-guard.js +5 -4
- package/hooks/dist/gsd-worktree-path-guard.js +6 -2
- package/hooks/dist/lib/cli-exit.js +12 -0
- package/hooks/dist/lib/git-probe.js +17 -1
- package/hooks/dist/lib/isolation-sentinel.js +2 -2
- package/hooks/gsd-agent-isolation-guard.js +8 -0
- package/hooks/gsd-check-update-worker.js +8 -0
- package/hooks/gsd-check-update.js +8 -0
- package/hooks/gsd-context-monitor.js +31 -8
- package/hooks/gsd-cursor-subagent-start.js +8 -0
- package/hooks/gsd-secret-read-guard.js +147 -16
- package/hooks/gsd-statusline.js +15 -7
- package/hooks/gsd-update-banner.js +8 -0
- package/hooks/gsd-windsurf-pre-write.js +11 -2
- package/hooks/gsd-workflow-guard.js +5 -4
- package/hooks/gsd-worktree-path-guard.js +6 -2
- package/hooks/hooks.json +5 -5
- package/hooks/lib/cli-exit.js +12 -0
- package/hooks/lib/git-probe.js +17 -1
- package/hooks/lib/isolation-sentinel.js +2 -2
- package/package.json +21 -4
- package/scripts/changeset/parse.cjs +52 -4
- package/scripts/ci-timeout-report.cjs +770 -4
- package/scripts/command-contract-helpers.cjs +12 -8
- package/scripts/docs-guard-registry.cjs +6 -0
- package/scripts/gen-features.cjs +13 -8
- package/scripts/gen-hooks-cli-exit.cjs +12 -28
- package/scripts/gen-loop-host-contract.cjs +10 -1
- package/scripts/gen-platform-conformance-tier.cjs +187 -1
- package/scripts/gen-plugin-skills.cjs +87 -1
- package/scripts/gen-research-agents.cjs +24 -31
- package/scripts/gen-scripts-cli-exit.cjs +30 -3
- package/scripts/gen-test-timings.cjs +32 -7
- package/scripts/lib/cli-exit.cjs +12 -0
- package/scripts/lib/macos-conformance-tier.generated.cjs +20 -2
- package/scripts/lib/ndjson-reporter.cjs +28 -3
- package/scripts/lib/platform-conformance-tier.generated.cjs +34 -5
- package/scripts/lib/registration-ledger-preload.cjs +155 -0
- package/scripts/lib/vendor-bundle.cjs +59 -0
- package/scripts/lib/vendor-licenses/saxes-6.0.0.txt +64 -0
- package/scripts/lint-allow-test-rule-refs.effective-ceiling.json +1 -1
- package/scripts/lint-allow-test-rule-refs.unverified-ceiling.json +1 -1
- package/scripts/lint-completion-predicate-drift.cjs +18 -19
- package/scripts/lint-descriptions.cjs +7 -3
- package/scripts/lint-docs-guard-registration.exempt-baseline.cjs +10 -0
- package/scripts/lint-eslint-glob-coverage.allowlist.json +20 -0
- package/scripts/lint-frontmatter-fence-drift.cjs +313 -0
- package/scripts/lint-frontmatter-scalar-broad-grep.cjs +122 -16
- package/scripts/lint-phase-enumeration-drift.cjs +12 -8
- package/scripts/lint-phase-id-drift.cjs +29 -0
- package/scripts/lint-planning-document-positive-control.cjs +329 -0
- package/scripts/lint-response-language-coverage.cjs +3 -0
- package/scripts/lint-skill-deps.cjs +7 -3
- package/scripts/lint-test-file-count.allowlist.json +11 -1
- package/scripts/lint-test-file-count.cjs +34 -1
- package/scripts/lint-vendored-deps.cjs +41 -5
- package/scripts/lint-workflow-shellcheck-baseline.json +10 -10
- package/scripts/mutation-matrix.cjs +50 -5
- package/scripts/require-issue-link-policy.cjs +6 -2
- package/scripts/sync-runtime-launcher.cjs +184 -2
- package/scripts/verify-npm-publish.cjs +76 -20
- package/skills/gsd-add-tests/SKILL.md +6 -1
- package/skills/gsd-ai-integration-phase/SKILL.md +6 -1
- package/skills/gsd-audit-fix/SKILL.md +5 -0
- package/skills/gsd-audit-milestone/SKILL.md +6 -1
- package/skills/gsd-autonomous/SKILL.md +5 -0
- package/skills/gsd-capture/SKILL.md +8 -4
- package/skills/gsd-code-review/SKILL.md +7 -2
- package/skills/gsd-complete-milestone/SKILL.md +4 -0
- package/skills/gsd-config/SKILL.md +8 -4
- package/skills/gsd-debug/SKILL.md +11 -7
- package/skills/gsd-discuss-phase/SKILL.md +7 -3
- package/skills/gsd-docs-update/SKILL.md +12 -7
- package/skills/gsd-eval-review/SKILL.md +6 -1
- package/skills/gsd-execute-phase/SKILL.md +12 -7
- package/skills/gsd-extract-learnings/SKILL.md +5 -0
- package/skills/gsd-fast/SKILL.md +4 -0
- package/skills/gsd-forensics/SKILL.md +5 -1
- package/skills/gsd-graphify/SKILL.md +10 -6
- package/skills/gsd-health/SKILL.md +5 -0
- package/skills/gsd-help/SKILL.md +7 -2
- package/skills/gsd-import/SKILL.md +7 -3
- package/skills/gsd-inbox/SKILL.md +5 -0
- package/skills/gsd-ingest-docs/SKILL.md +5 -1
- package/skills/gsd-manager/SKILL.md +6 -1
- package/skills/gsd-map-codebase/SKILL.md +7 -3
- package/skills/gsd-mempalace-capture/SKILL.md +5 -1
- package/skills/gsd-mempalace-recall/SKILL.md +5 -1
- package/skills/gsd-milestone-summary/SKILL.md +5 -1
- package/skills/gsd-mvp-phase/SKILL.md +8 -3
- package/skills/gsd-new-milestone/SKILL.md +6 -1
- package/skills/gsd-new-project/SKILL.md +5 -0
- package/skills/gsd-next/SKILL.md +6 -1
- package/skills/gsd-ns-context/SKILL.md +4 -0
- package/skills/gsd-ns-ideate/SKILL.md +4 -0
- package/skills/gsd-ns-manage/SKILL.md +4 -0
- package/skills/gsd-ns-project/SKILL.md +4 -0
- package/skills/gsd-ns-review/SKILL.md +4 -0
- package/skills/gsd-ns-workflow/SKILL.md +4 -0
- package/skills/gsd-onboard/SKILL.md +6 -1
- package/skills/gsd-pause-work/SKILL.md +5 -1
- package/skills/gsd-phase/SKILL.md +8 -4
- package/skills/gsd-plan-phase/SKILL.md +6 -1
- package/skills/gsd-plan-review-convergence/SKILL.md +5 -1
- package/skills/gsd-pr-branch/SKILL.md +4 -0
- package/skills/gsd-profile-user/SKILL.md +5 -1
- package/skills/gsd-progress/SKILL.md +6 -1
- package/skills/gsd-quick/SKILL.md +16 -10
- package/skills/gsd-quick-batch/SKILL.md +20 -8
- package/skills/gsd-review/SKILL.md +5 -1
- package/skills/gsd-review-backlog/SKILL.md +3 -2
- package/skills/gsd-secure-phase/SKILL.md +6 -1
- package/skills/gsd-ship/SKILL.md +5 -0
- package/skills/gsd-sketch/SKILL.md +7 -2
- package/skills/gsd-spec-phase/SKILL.md +5 -1
- package/skills/gsd-spike/SKILL.md +8 -3
- package/skills/gsd-surface/SKILL.md +5 -1
- package/skills/gsd-thread/SKILL.md +4 -0
- package/skills/gsd-ui-phase/SKILL.md +6 -1
- package/skills/gsd-ui-review/SKILL.md +6 -1
- package/skills/gsd-ultraplan-phase/SKILL.md +5 -1
- package/skills/gsd-undo/SKILL.md +5 -1
- package/skills/gsd-update/SKILL.md +6 -2
- package/skills/gsd-validate-phase/SKILL.md +6 -1
- package/skills/gsd-verify-work/SKILL.md +6 -1
- package/skills/gsd-workspace/SKILL.md +7 -3
- package/skills/gsd-workstreams/SKILL.md +6 -6
- package/vscode/package.json +1 -1
- package/gsd-core/workflows/execute-phase/steps/stale-reverification.md +0 -24
|
@@ -0,0 +1,1934 @@
|
|
|
1
|
+
// Generated from locked npm dependencies by lint-vendored-deps.cjs --fix. Do not edit.
|
|
2
|
+
"use strict";
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
5
|
+
try {
|
|
6
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
7
|
+
} catch (e) {
|
|
8
|
+
throw mod = 0, e;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// node_modules/xmlchars/xml/1.0/ed5.js
|
|
13
|
+
var require_ed5 = __commonJS({
|
|
14
|
+
"node_modules/xmlchars/xml/1.0/ed5.js"(exports2) {
|
|
15
|
+
"use strict";
|
|
16
|
+
/**
|
|
17
|
+
* Character classes and associated utilities for the 5th edition of XML 1.0.
|
|
18
|
+
*
|
|
19
|
+
* @author Louis-Dominique Dubeau
|
|
20
|
+
* @license MIT
|
|
21
|
+
* @copyright Louis-Dominique Dubeau
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
24
|
+
exports2.CHAR = " \n\r -\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}";
|
|
25
|
+
exports2.S = " \r\n";
|
|
26
|
+
exports2.NAME_START_CHAR = ":A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}";
|
|
27
|
+
exports2.NAME_CHAR = "-" + exports2.NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040";
|
|
28
|
+
exports2.CHAR_RE = new RegExp("^[" + exports2.CHAR + "]$", "u");
|
|
29
|
+
exports2.S_RE = new RegExp("^[" + exports2.S + "]+$", "u");
|
|
30
|
+
exports2.NAME_START_CHAR_RE = new RegExp("^[" + exports2.NAME_START_CHAR + "]$", "u");
|
|
31
|
+
exports2.NAME_CHAR_RE = new RegExp("^[" + exports2.NAME_CHAR + "]$", "u");
|
|
32
|
+
exports2.NAME_RE = new RegExp("^[" + exports2.NAME_START_CHAR + "][" + exports2.NAME_CHAR + "]*$", "u");
|
|
33
|
+
exports2.NMTOKEN_RE = new RegExp("^[" + exports2.NAME_CHAR + "]+$", "u");
|
|
34
|
+
var TAB2 = 9;
|
|
35
|
+
var NL2 = 10;
|
|
36
|
+
var CR2 = 13;
|
|
37
|
+
var SPACE2 = 32;
|
|
38
|
+
exports2.S_LIST = [SPACE2, NL2, CR2, TAB2];
|
|
39
|
+
function isChar(c) {
|
|
40
|
+
return c >= SPACE2 && c <= 55295 || c === NL2 || c === CR2 || c === TAB2 || c >= 57344 && c <= 65533 || c >= 65536 && c <= 1114111;
|
|
41
|
+
}
|
|
42
|
+
exports2.isChar = isChar;
|
|
43
|
+
function isS2(c) {
|
|
44
|
+
return c === SPACE2 || c === NL2 || c === CR2 || c === TAB2;
|
|
45
|
+
}
|
|
46
|
+
exports2.isS = isS2;
|
|
47
|
+
function isNameStartChar2(c) {
|
|
48
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 58 || c === 95 || c === 8204 || c === 8205 || c >= 192 && c <= 214 || c >= 216 && c <= 246 || c >= 248 && c <= 767 || c >= 880 && c <= 893 || c >= 895 && c <= 8191 || c >= 8304 && c <= 8591 || c >= 11264 && c <= 12271 || c >= 12289 && c <= 55295 || c >= 63744 && c <= 64975 || c >= 65008 && c <= 65533 || c >= 65536 && c <= 983039;
|
|
49
|
+
}
|
|
50
|
+
exports2.isNameStartChar = isNameStartChar2;
|
|
51
|
+
function isNameChar2(c) {
|
|
52
|
+
return isNameStartChar2(c) || c >= 48 && c <= 57 || c === 45 || c === 46 || c === 183 || c >= 768 && c <= 879 || c >= 8255 && c <= 8256;
|
|
53
|
+
}
|
|
54
|
+
exports2.isNameChar = isNameChar2;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// node_modules/xmlchars/xml/1.1/ed2.js
|
|
59
|
+
var require_ed2 = __commonJS({
|
|
60
|
+
"node_modules/xmlchars/xml/1.1/ed2.js"(exports2) {
|
|
61
|
+
"use strict";
|
|
62
|
+
/**
|
|
63
|
+
* Character classes and associated utilities for the 2nd edition of XML 1.1.
|
|
64
|
+
*
|
|
65
|
+
* @author Louis-Dominique Dubeau
|
|
66
|
+
* @license MIT
|
|
67
|
+
* @copyright Louis-Dominique Dubeau
|
|
68
|
+
*/
|
|
69
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
70
|
+
exports2.CHAR = "-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}";
|
|
71
|
+
exports2.RESTRICTED_CHAR = "-\b\v\f-\x7F-\x84\x86-\x9F";
|
|
72
|
+
exports2.S = " \r\n";
|
|
73
|
+
exports2.NAME_START_CHAR = ":A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}";
|
|
74
|
+
exports2.NAME_CHAR = "-" + exports2.NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040";
|
|
75
|
+
exports2.CHAR_RE = new RegExp("^[" + exports2.CHAR + "]$", "u");
|
|
76
|
+
exports2.RESTRICTED_CHAR_RE = new RegExp("^[" + exports2.RESTRICTED_CHAR + "]$", "u");
|
|
77
|
+
exports2.S_RE = new RegExp("^[" + exports2.S + "]+$", "u");
|
|
78
|
+
exports2.NAME_START_CHAR_RE = new RegExp("^[" + exports2.NAME_START_CHAR + "]$", "u");
|
|
79
|
+
exports2.NAME_CHAR_RE = new RegExp("^[" + exports2.NAME_CHAR + "]$", "u");
|
|
80
|
+
exports2.NAME_RE = new RegExp("^[" + exports2.NAME_START_CHAR + "][" + exports2.NAME_CHAR + "]*$", "u");
|
|
81
|
+
exports2.NMTOKEN_RE = new RegExp("^[" + exports2.NAME_CHAR + "]+$", "u");
|
|
82
|
+
var TAB2 = 9;
|
|
83
|
+
var NL2 = 10;
|
|
84
|
+
var CR2 = 13;
|
|
85
|
+
var SPACE2 = 32;
|
|
86
|
+
exports2.S_LIST = [SPACE2, NL2, CR2, TAB2];
|
|
87
|
+
function isChar(c) {
|
|
88
|
+
return c >= 1 && c <= 55295 || c >= 57344 && c <= 65533 || c >= 65536 && c <= 1114111;
|
|
89
|
+
}
|
|
90
|
+
exports2.isChar = isChar;
|
|
91
|
+
function isRestrictedChar(c) {
|
|
92
|
+
return c >= 1 && c <= 8 || c === 11 || c === 12 || c >= 14 && c <= 31 || c >= 127 && c <= 132 || c >= 134 && c <= 159;
|
|
93
|
+
}
|
|
94
|
+
exports2.isRestrictedChar = isRestrictedChar;
|
|
95
|
+
function isCharAndNotRestricted(c) {
|
|
96
|
+
return c === 9 || c === 10 || c === 13 || c > 31 && c < 127 || c === 133 || c > 159 && c <= 55295 || c >= 57344 && c <= 65533 || c >= 65536 && c <= 1114111;
|
|
97
|
+
}
|
|
98
|
+
exports2.isCharAndNotRestricted = isCharAndNotRestricted;
|
|
99
|
+
function isS2(c) {
|
|
100
|
+
return c === SPACE2 || c === NL2 || c === CR2 || c === TAB2;
|
|
101
|
+
}
|
|
102
|
+
exports2.isS = isS2;
|
|
103
|
+
function isNameStartChar2(c) {
|
|
104
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 58 || c === 95 || c === 8204 || c === 8205 || c >= 192 && c <= 214 || c >= 216 && c <= 246 || c >= 248 && c <= 767 || c >= 880 && c <= 893 || c >= 895 && c <= 8191 || c >= 8304 && c <= 8591 || c >= 11264 && c <= 12271 || c >= 12289 && c <= 55295 || c >= 63744 && c <= 64975 || c >= 65008 && c <= 65533 || c >= 65536 && c <= 983039;
|
|
105
|
+
}
|
|
106
|
+
exports2.isNameStartChar = isNameStartChar2;
|
|
107
|
+
function isNameChar2(c) {
|
|
108
|
+
return isNameStartChar2(c) || c >= 48 && c <= 57 || c === 45 || c === 46 || c === 183 || c >= 768 && c <= 879 || c >= 8255 && c <= 8256;
|
|
109
|
+
}
|
|
110
|
+
exports2.isNameChar = isNameChar2;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// node_modules/xmlchars/xmlns/1.0/ed3.js
|
|
115
|
+
var require_ed3 = __commonJS({
|
|
116
|
+
"node_modules/xmlchars/xmlns/1.0/ed3.js"(exports2) {
|
|
117
|
+
"use strict";
|
|
118
|
+
/**
|
|
119
|
+
* Character class utilities for XML NS 1.0 edition 3.
|
|
120
|
+
*
|
|
121
|
+
* @author Louis-Dominique Dubeau
|
|
122
|
+
* @license MIT
|
|
123
|
+
* @copyright Louis-Dominique Dubeau
|
|
124
|
+
*/
|
|
125
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
126
|
+
exports2.NC_NAME_START_CHAR = "A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}";
|
|
127
|
+
exports2.NC_NAME_CHAR = "-" + exports2.NC_NAME_START_CHAR + ".0-9\xB7\u0300-\u036F\u203F-\u2040";
|
|
128
|
+
exports2.NC_NAME_START_CHAR_RE = new RegExp("^[" + exports2.NC_NAME_START_CHAR + "]$", "u");
|
|
129
|
+
exports2.NC_NAME_CHAR_RE = new RegExp("^[" + exports2.NC_NAME_CHAR + "]$", "u");
|
|
130
|
+
exports2.NC_NAME_RE = new RegExp("^[" + exports2.NC_NAME_START_CHAR + "][" + exports2.NC_NAME_CHAR + "]*$", "u");
|
|
131
|
+
function isNCNameStartChar2(c) {
|
|
132
|
+
return c >= 65 && c <= 90 || c === 95 || c >= 97 && c <= 122 || c >= 192 && c <= 214 || c >= 216 && c <= 246 || c >= 248 && c <= 767 || c >= 880 && c <= 893 || c >= 895 && c <= 8191 || c >= 8204 && c <= 8205 || c >= 8304 && c <= 8591 || c >= 11264 && c <= 12271 || c >= 12289 && c <= 55295 || c >= 63744 && c <= 64975 || c >= 65008 && c <= 65533 || c >= 65536 && c <= 983039;
|
|
133
|
+
}
|
|
134
|
+
exports2.isNCNameStartChar = isNCNameStartChar2;
|
|
135
|
+
function isNCNameChar2(c) {
|
|
136
|
+
return isNCNameStartChar2(c) || (c === 45 || c === 46 || c >= 48 && c <= 57 || c === 183 || c >= 768 && c <= 879 || c >= 8255 && c <= 8256);
|
|
137
|
+
}
|
|
138
|
+
exports2.isNCNameChar = isNCNameChar2;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// node_modules/saxes/saxes.js
|
|
143
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
144
|
+
exports.SaxesParser = exports.EVENTS = void 0;
|
|
145
|
+
var ed5 = require_ed5();
|
|
146
|
+
var ed2 = require_ed2();
|
|
147
|
+
var NSed3 = require_ed3();
|
|
148
|
+
var isS = ed5.isS;
|
|
149
|
+
var isChar10 = ed5.isChar;
|
|
150
|
+
var isNameStartChar = ed5.isNameStartChar;
|
|
151
|
+
var isNameChar = ed5.isNameChar;
|
|
152
|
+
var S_LIST = ed5.S_LIST;
|
|
153
|
+
var NAME_RE = ed5.NAME_RE;
|
|
154
|
+
var isChar11 = ed2.isChar;
|
|
155
|
+
var isNCNameStartChar = NSed3.isNCNameStartChar;
|
|
156
|
+
var isNCNameChar = NSed3.isNCNameChar;
|
|
157
|
+
var NC_NAME_RE = NSed3.NC_NAME_RE;
|
|
158
|
+
var XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
|
|
159
|
+
var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
|
|
160
|
+
var rootNS = {
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
|
162
|
+
__proto__: null,
|
|
163
|
+
xml: XML_NAMESPACE,
|
|
164
|
+
xmlns: XMLNS_NAMESPACE
|
|
165
|
+
};
|
|
166
|
+
var XML_ENTITIES = {
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
|
168
|
+
__proto__: null,
|
|
169
|
+
amp: "&",
|
|
170
|
+
gt: ">",
|
|
171
|
+
lt: "<",
|
|
172
|
+
quot: '"',
|
|
173
|
+
apos: "'"
|
|
174
|
+
};
|
|
175
|
+
var EOC = -1;
|
|
176
|
+
var NL_LIKE = -2;
|
|
177
|
+
var S_BEGIN = 0;
|
|
178
|
+
var S_BEGIN_WHITESPACE = 1;
|
|
179
|
+
var S_DOCTYPE = 2;
|
|
180
|
+
var S_DOCTYPE_QUOTE = 3;
|
|
181
|
+
var S_DTD = 4;
|
|
182
|
+
var S_DTD_QUOTED = 5;
|
|
183
|
+
var S_DTD_OPEN_WAKA = 6;
|
|
184
|
+
var S_DTD_OPEN_WAKA_BANG = 7;
|
|
185
|
+
var S_DTD_COMMENT = 8;
|
|
186
|
+
var S_DTD_COMMENT_ENDING = 9;
|
|
187
|
+
var S_DTD_COMMENT_ENDED = 10;
|
|
188
|
+
var S_DTD_PI = 11;
|
|
189
|
+
var S_DTD_PI_ENDING = 12;
|
|
190
|
+
var S_TEXT = 13;
|
|
191
|
+
var S_ENTITY = 14;
|
|
192
|
+
var S_OPEN_WAKA = 15;
|
|
193
|
+
var S_OPEN_WAKA_BANG = 16;
|
|
194
|
+
var S_COMMENT = 17;
|
|
195
|
+
var S_COMMENT_ENDING = 18;
|
|
196
|
+
var S_COMMENT_ENDED = 19;
|
|
197
|
+
var S_CDATA = 20;
|
|
198
|
+
var S_CDATA_ENDING = 21;
|
|
199
|
+
var S_CDATA_ENDING_2 = 22;
|
|
200
|
+
var S_PI_FIRST_CHAR = 23;
|
|
201
|
+
var S_PI_REST = 24;
|
|
202
|
+
var S_PI_BODY = 25;
|
|
203
|
+
var S_PI_ENDING = 26;
|
|
204
|
+
var S_XML_DECL_NAME_START = 27;
|
|
205
|
+
var S_XML_DECL_NAME = 28;
|
|
206
|
+
var S_XML_DECL_EQ = 29;
|
|
207
|
+
var S_XML_DECL_VALUE_START = 30;
|
|
208
|
+
var S_XML_DECL_VALUE = 31;
|
|
209
|
+
var S_XML_DECL_SEPARATOR = 32;
|
|
210
|
+
var S_XML_DECL_ENDING = 33;
|
|
211
|
+
var S_OPEN_TAG = 34;
|
|
212
|
+
var S_OPEN_TAG_SLASH = 35;
|
|
213
|
+
var S_ATTRIB = 36;
|
|
214
|
+
var S_ATTRIB_NAME = 37;
|
|
215
|
+
var S_ATTRIB_NAME_SAW_WHITE = 38;
|
|
216
|
+
var S_ATTRIB_VALUE = 39;
|
|
217
|
+
var S_ATTRIB_VALUE_QUOTED = 40;
|
|
218
|
+
var S_ATTRIB_VALUE_CLOSED = 41;
|
|
219
|
+
var S_ATTRIB_VALUE_UNQUOTED = 42;
|
|
220
|
+
var S_CLOSE_TAG = 43;
|
|
221
|
+
var S_CLOSE_TAG_SAW_WHITE = 44;
|
|
222
|
+
var TAB = 9;
|
|
223
|
+
var NL = 10;
|
|
224
|
+
var CR = 13;
|
|
225
|
+
var SPACE = 32;
|
|
226
|
+
var BANG = 33;
|
|
227
|
+
var DQUOTE = 34;
|
|
228
|
+
var AMP = 38;
|
|
229
|
+
var SQUOTE = 39;
|
|
230
|
+
var MINUS = 45;
|
|
231
|
+
var FORWARD_SLASH = 47;
|
|
232
|
+
var SEMICOLON = 59;
|
|
233
|
+
var LESS = 60;
|
|
234
|
+
var EQUAL = 61;
|
|
235
|
+
var GREATER = 62;
|
|
236
|
+
var QUESTION = 63;
|
|
237
|
+
var OPEN_BRACKET = 91;
|
|
238
|
+
var CLOSE_BRACKET = 93;
|
|
239
|
+
var NEL = 133;
|
|
240
|
+
var LS = 8232;
|
|
241
|
+
var isQuote = (c) => c === DQUOTE || c === SQUOTE;
|
|
242
|
+
var QUOTES = [DQUOTE, SQUOTE];
|
|
243
|
+
var DOCTYPE_TERMINATOR = [...QUOTES, OPEN_BRACKET, GREATER];
|
|
244
|
+
var DTD_TERMINATOR = [...QUOTES, LESS, CLOSE_BRACKET];
|
|
245
|
+
var XML_DECL_NAME_TERMINATOR = [EQUAL, QUESTION, ...S_LIST];
|
|
246
|
+
var ATTRIB_VALUE_UNQUOTED_TERMINATOR = [...S_LIST, GREATER, AMP, LESS];
|
|
247
|
+
function nsPairCheck(parser, prefix, uri) {
|
|
248
|
+
switch (prefix) {
|
|
249
|
+
case "xml":
|
|
250
|
+
if (uri !== XML_NAMESPACE) {
|
|
251
|
+
parser.fail(`xml prefix must be bound to ${XML_NAMESPACE}.`);
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
case "xmlns":
|
|
255
|
+
if (uri !== XMLNS_NAMESPACE) {
|
|
256
|
+
parser.fail(`xmlns prefix must be bound to ${XMLNS_NAMESPACE}.`);
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
default:
|
|
260
|
+
}
|
|
261
|
+
switch (uri) {
|
|
262
|
+
case XMLNS_NAMESPACE:
|
|
263
|
+
parser.fail(prefix === "" ? `the default namespace may not be set to ${uri}.` : `may not assign a prefix (even "xmlns") to the URI ${XMLNS_NAMESPACE}.`);
|
|
264
|
+
break;
|
|
265
|
+
case XML_NAMESPACE:
|
|
266
|
+
switch (prefix) {
|
|
267
|
+
case "xml":
|
|
268
|
+
break;
|
|
269
|
+
case "":
|
|
270
|
+
parser.fail(`the default namespace may not be set to ${uri}.`);
|
|
271
|
+
break;
|
|
272
|
+
default:
|
|
273
|
+
parser.fail("may not assign the xml namespace to another prefix.");
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function nsMappingCheck(parser, mapping) {
|
|
280
|
+
for (const local of Object.keys(mapping)) {
|
|
281
|
+
nsPairCheck(parser, local, mapping[local]);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
var isNCName = (name) => NC_NAME_RE.test(name);
|
|
285
|
+
var isName = (name) => NAME_RE.test(name);
|
|
286
|
+
var FORBIDDEN_START = 0;
|
|
287
|
+
var FORBIDDEN_BRACKET = 1;
|
|
288
|
+
var FORBIDDEN_BRACKET_BRACKET = 2;
|
|
289
|
+
exports.EVENTS = [
|
|
290
|
+
"xmldecl",
|
|
291
|
+
"text",
|
|
292
|
+
"processinginstruction",
|
|
293
|
+
"doctype",
|
|
294
|
+
"comment",
|
|
295
|
+
"opentagstart",
|
|
296
|
+
"attribute",
|
|
297
|
+
"opentag",
|
|
298
|
+
"closetag",
|
|
299
|
+
"cdata",
|
|
300
|
+
"error",
|
|
301
|
+
"end",
|
|
302
|
+
"ready"
|
|
303
|
+
];
|
|
304
|
+
var EVENT_NAME_TO_HANDLER_NAME = {
|
|
305
|
+
xmldecl: "xmldeclHandler",
|
|
306
|
+
text: "textHandler",
|
|
307
|
+
processinginstruction: "piHandler",
|
|
308
|
+
doctype: "doctypeHandler",
|
|
309
|
+
comment: "commentHandler",
|
|
310
|
+
opentagstart: "openTagStartHandler",
|
|
311
|
+
attribute: "attributeHandler",
|
|
312
|
+
opentag: "openTagHandler",
|
|
313
|
+
closetag: "closeTagHandler",
|
|
314
|
+
cdata: "cdataHandler",
|
|
315
|
+
error: "errorHandler",
|
|
316
|
+
end: "endHandler",
|
|
317
|
+
ready: "readyHandler"
|
|
318
|
+
};
|
|
319
|
+
var SaxesParser = class {
|
|
320
|
+
/**
|
|
321
|
+
* @param opt The parser options.
|
|
322
|
+
*/
|
|
323
|
+
constructor(opt) {
|
|
324
|
+
this.opt = opt !== null && opt !== void 0 ? opt : {};
|
|
325
|
+
this.fragmentOpt = !!this.opt.fragment;
|
|
326
|
+
const xmlnsOpt = this.xmlnsOpt = !!this.opt.xmlns;
|
|
327
|
+
this.trackPosition = this.opt.position !== false;
|
|
328
|
+
this.fileName = this.opt.fileName;
|
|
329
|
+
if (xmlnsOpt) {
|
|
330
|
+
this.nameStartCheck = isNCNameStartChar;
|
|
331
|
+
this.nameCheck = isNCNameChar;
|
|
332
|
+
this.isName = isNCName;
|
|
333
|
+
this.processAttribs = this.processAttribsNS;
|
|
334
|
+
this.pushAttrib = this.pushAttribNS;
|
|
335
|
+
this.ns = Object.assign({ __proto__: null }, rootNS);
|
|
336
|
+
const additional = this.opt.additionalNamespaces;
|
|
337
|
+
if (additional != null) {
|
|
338
|
+
nsMappingCheck(this, additional);
|
|
339
|
+
Object.assign(this.ns, additional);
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
this.nameStartCheck = isNameStartChar;
|
|
343
|
+
this.nameCheck = isNameChar;
|
|
344
|
+
this.isName = isName;
|
|
345
|
+
this.processAttribs = this.processAttribsPlain;
|
|
346
|
+
this.pushAttrib = this.pushAttribPlain;
|
|
347
|
+
}
|
|
348
|
+
this.stateTable = [
|
|
349
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
350
|
+
this.sBegin,
|
|
351
|
+
this.sBeginWhitespace,
|
|
352
|
+
this.sDoctype,
|
|
353
|
+
this.sDoctypeQuote,
|
|
354
|
+
this.sDTD,
|
|
355
|
+
this.sDTDQuoted,
|
|
356
|
+
this.sDTDOpenWaka,
|
|
357
|
+
this.sDTDOpenWakaBang,
|
|
358
|
+
this.sDTDComment,
|
|
359
|
+
this.sDTDCommentEnding,
|
|
360
|
+
this.sDTDCommentEnded,
|
|
361
|
+
this.sDTDPI,
|
|
362
|
+
this.sDTDPIEnding,
|
|
363
|
+
this.sText,
|
|
364
|
+
this.sEntity,
|
|
365
|
+
this.sOpenWaka,
|
|
366
|
+
this.sOpenWakaBang,
|
|
367
|
+
this.sComment,
|
|
368
|
+
this.sCommentEnding,
|
|
369
|
+
this.sCommentEnded,
|
|
370
|
+
this.sCData,
|
|
371
|
+
this.sCDataEnding,
|
|
372
|
+
this.sCDataEnding2,
|
|
373
|
+
this.sPIFirstChar,
|
|
374
|
+
this.sPIRest,
|
|
375
|
+
this.sPIBody,
|
|
376
|
+
this.sPIEnding,
|
|
377
|
+
this.sXMLDeclNameStart,
|
|
378
|
+
this.sXMLDeclName,
|
|
379
|
+
this.sXMLDeclEq,
|
|
380
|
+
this.sXMLDeclValueStart,
|
|
381
|
+
this.sXMLDeclValue,
|
|
382
|
+
this.sXMLDeclSeparator,
|
|
383
|
+
this.sXMLDeclEnding,
|
|
384
|
+
this.sOpenTag,
|
|
385
|
+
this.sOpenTagSlash,
|
|
386
|
+
this.sAttrib,
|
|
387
|
+
this.sAttribName,
|
|
388
|
+
this.sAttribNameSawWhite,
|
|
389
|
+
this.sAttribValue,
|
|
390
|
+
this.sAttribValueQuoted,
|
|
391
|
+
this.sAttribValueClosed,
|
|
392
|
+
this.sAttribValueUnquoted,
|
|
393
|
+
this.sCloseTag,
|
|
394
|
+
this.sCloseTagSawWhite
|
|
395
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
396
|
+
];
|
|
397
|
+
this._init();
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Indicates whether or not the parser is closed. If ``true``, wait for
|
|
401
|
+
* the ``ready`` event to write again.
|
|
402
|
+
*/
|
|
403
|
+
get closed() {
|
|
404
|
+
return this._closed;
|
|
405
|
+
}
|
|
406
|
+
_init() {
|
|
407
|
+
var _a;
|
|
408
|
+
this.openWakaBang = "";
|
|
409
|
+
this.text = "";
|
|
410
|
+
this.name = "";
|
|
411
|
+
this.piTarget = "";
|
|
412
|
+
this.entity = "";
|
|
413
|
+
this.q = null;
|
|
414
|
+
this.tags = [];
|
|
415
|
+
this.tag = null;
|
|
416
|
+
this.topNS = null;
|
|
417
|
+
this.chunk = "";
|
|
418
|
+
this.chunkPosition = 0;
|
|
419
|
+
this.i = 0;
|
|
420
|
+
this.prevI = 0;
|
|
421
|
+
this.carriedFromPrevious = void 0;
|
|
422
|
+
this.forbiddenState = FORBIDDEN_START;
|
|
423
|
+
this.attribList = [];
|
|
424
|
+
const { fragmentOpt } = this;
|
|
425
|
+
this.state = fragmentOpt ? S_TEXT : S_BEGIN;
|
|
426
|
+
this.reportedTextBeforeRoot = this.reportedTextAfterRoot = this.closedRoot = this.sawRoot = fragmentOpt;
|
|
427
|
+
this.xmlDeclPossible = !fragmentOpt;
|
|
428
|
+
this.xmlDeclExpects = ["version"];
|
|
429
|
+
this.entityReturnState = void 0;
|
|
430
|
+
let { defaultXMLVersion } = this.opt;
|
|
431
|
+
if (defaultXMLVersion === void 0) {
|
|
432
|
+
if (this.opt.forceXMLVersion === true) {
|
|
433
|
+
throw new Error("forceXMLVersion set but defaultXMLVersion is not set");
|
|
434
|
+
}
|
|
435
|
+
defaultXMLVersion = "1.0";
|
|
436
|
+
}
|
|
437
|
+
this.setXMLVersion(defaultXMLVersion);
|
|
438
|
+
this.positionAtNewLine = 0;
|
|
439
|
+
this.doctype = false;
|
|
440
|
+
this._closed = false;
|
|
441
|
+
this.xmlDecl = {
|
|
442
|
+
version: void 0,
|
|
443
|
+
encoding: void 0,
|
|
444
|
+
standalone: void 0
|
|
445
|
+
};
|
|
446
|
+
this.line = 1;
|
|
447
|
+
this.column = 0;
|
|
448
|
+
this.ENTITIES = Object.create(XML_ENTITIES);
|
|
449
|
+
(_a = this.readyHandler) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* The stream position the parser is currently looking at. This field is
|
|
453
|
+
* zero-based.
|
|
454
|
+
*
|
|
455
|
+
* This field is not based on counting Unicode characters but is to be
|
|
456
|
+
* interpreted as a plain index into a JavaScript string.
|
|
457
|
+
*/
|
|
458
|
+
get position() {
|
|
459
|
+
return this.chunkPosition + this.i;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* The column number of the next character to be read by the parser. *
|
|
463
|
+
* This field is zero-based. (The first column in a line is 0.)
|
|
464
|
+
*
|
|
465
|
+
* This field reports the index at which the next character would be in the
|
|
466
|
+
* line if the line were represented as a JavaScript string. Note that this
|
|
467
|
+
* *can* be different to a count based on the number of *Unicode characters*
|
|
468
|
+
* due to how JavaScript handles astral plane characters.
|
|
469
|
+
*
|
|
470
|
+
* See [[column]] for a number that corresponds to a count of Unicode
|
|
471
|
+
* characters.
|
|
472
|
+
*/
|
|
473
|
+
get columnIndex() {
|
|
474
|
+
return this.position - this.positionAtNewLine;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Set an event listener on an event. The parser supports one handler per
|
|
478
|
+
* event type. If you try to set an event handler over an existing handler,
|
|
479
|
+
* the old handler is silently overwritten.
|
|
480
|
+
*
|
|
481
|
+
* @param name The event to listen to.
|
|
482
|
+
*
|
|
483
|
+
* @param handler The handler to set.
|
|
484
|
+
*/
|
|
485
|
+
on(name, handler) {
|
|
486
|
+
this[EVENT_NAME_TO_HANDLER_NAME[name]] = handler;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Unset an event handler.
|
|
490
|
+
*
|
|
491
|
+
* @parma name The event to stop listening to.
|
|
492
|
+
*/
|
|
493
|
+
off(name) {
|
|
494
|
+
this[EVENT_NAME_TO_HANDLER_NAME[name]] = void 0;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Make an error object. The error object will have a message that contains
|
|
498
|
+
* the ``fileName`` option passed at the creation of the parser. If position
|
|
499
|
+
* tracking was turned on, it will also have line and column number
|
|
500
|
+
* information.
|
|
501
|
+
*
|
|
502
|
+
* @param message The message describing the error to report.
|
|
503
|
+
*
|
|
504
|
+
* @returns An error object with a properly formatted message.
|
|
505
|
+
*/
|
|
506
|
+
makeError(message) {
|
|
507
|
+
var _a;
|
|
508
|
+
let msg = (_a = this.fileName) !== null && _a !== void 0 ? _a : "";
|
|
509
|
+
if (this.trackPosition) {
|
|
510
|
+
if (msg.length > 0) {
|
|
511
|
+
msg += ":";
|
|
512
|
+
}
|
|
513
|
+
msg += `${this.line}:${this.column}`;
|
|
514
|
+
}
|
|
515
|
+
if (msg.length > 0) {
|
|
516
|
+
msg += ": ";
|
|
517
|
+
}
|
|
518
|
+
return new Error(msg + message);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Report a parsing error. This method is made public so that client code may
|
|
522
|
+
* check for issues that are outside the scope of this project and can report
|
|
523
|
+
* errors.
|
|
524
|
+
*
|
|
525
|
+
* @param message The error to report.
|
|
526
|
+
*
|
|
527
|
+
* @returns this
|
|
528
|
+
*/
|
|
529
|
+
fail(message) {
|
|
530
|
+
const err = this.makeError(message);
|
|
531
|
+
const handler = this.errorHandler;
|
|
532
|
+
if (handler === void 0) {
|
|
533
|
+
throw err;
|
|
534
|
+
} else {
|
|
535
|
+
handler(err);
|
|
536
|
+
}
|
|
537
|
+
return this;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Write a XML data to the parser.
|
|
541
|
+
*
|
|
542
|
+
* @param chunk The XML data to write.
|
|
543
|
+
*
|
|
544
|
+
* @returns this
|
|
545
|
+
*/
|
|
546
|
+
// We do need object for the type here. Yes, it often causes problems
|
|
547
|
+
// but not in this case.
|
|
548
|
+
write(chunk) {
|
|
549
|
+
if (this.closed) {
|
|
550
|
+
return this.fail("cannot write after close; assign an onready handler.");
|
|
551
|
+
}
|
|
552
|
+
let end = false;
|
|
553
|
+
if (chunk === null) {
|
|
554
|
+
end = true;
|
|
555
|
+
chunk = "";
|
|
556
|
+
} else if (typeof chunk === "object") {
|
|
557
|
+
chunk = chunk.toString();
|
|
558
|
+
}
|
|
559
|
+
if (this.carriedFromPrevious !== void 0) {
|
|
560
|
+
chunk = `${this.carriedFromPrevious}${chunk}`;
|
|
561
|
+
this.carriedFromPrevious = void 0;
|
|
562
|
+
}
|
|
563
|
+
let limit = chunk.length;
|
|
564
|
+
const lastCode = chunk.charCodeAt(limit - 1);
|
|
565
|
+
if (!end && // A trailing CR or surrogate must be carried over to the next
|
|
566
|
+
// chunk.
|
|
567
|
+
(lastCode === CR || lastCode >= 55296 && lastCode <= 56319)) {
|
|
568
|
+
this.carriedFromPrevious = chunk[limit - 1];
|
|
569
|
+
limit--;
|
|
570
|
+
chunk = chunk.slice(0, limit);
|
|
571
|
+
}
|
|
572
|
+
const { stateTable } = this;
|
|
573
|
+
this.chunk = chunk;
|
|
574
|
+
this.i = 0;
|
|
575
|
+
while (this.i < limit) {
|
|
576
|
+
stateTable[this.state].call(this);
|
|
577
|
+
}
|
|
578
|
+
this.chunkPosition += limit;
|
|
579
|
+
return end ? this.end() : this;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Close the current stream. Perform final well-formedness checks and reset
|
|
583
|
+
* the parser tstate.
|
|
584
|
+
*
|
|
585
|
+
* @returns this
|
|
586
|
+
*/
|
|
587
|
+
close() {
|
|
588
|
+
return this.write(null);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Get a single code point out of the current chunk. This updates the current
|
|
592
|
+
* position if we do position tracking.
|
|
593
|
+
*
|
|
594
|
+
* This is the algorithm to use for XML 1.0.
|
|
595
|
+
*
|
|
596
|
+
* @returns The character read.
|
|
597
|
+
*/
|
|
598
|
+
getCode10() {
|
|
599
|
+
const { chunk, i } = this;
|
|
600
|
+
this.prevI = i;
|
|
601
|
+
this.i = i + 1;
|
|
602
|
+
if (i >= chunk.length) {
|
|
603
|
+
return EOC;
|
|
604
|
+
}
|
|
605
|
+
const code = chunk.charCodeAt(i);
|
|
606
|
+
this.column++;
|
|
607
|
+
if (code < 55296) {
|
|
608
|
+
if (code >= SPACE || code === TAB) {
|
|
609
|
+
return code;
|
|
610
|
+
}
|
|
611
|
+
switch (code) {
|
|
612
|
+
case NL:
|
|
613
|
+
this.line++;
|
|
614
|
+
this.column = 0;
|
|
615
|
+
this.positionAtNewLine = this.position;
|
|
616
|
+
return NL;
|
|
617
|
+
case CR:
|
|
618
|
+
if (chunk.charCodeAt(i + 1) === NL) {
|
|
619
|
+
this.i = i + 2;
|
|
620
|
+
}
|
|
621
|
+
this.line++;
|
|
622
|
+
this.column = 0;
|
|
623
|
+
this.positionAtNewLine = this.position;
|
|
624
|
+
return NL_LIKE;
|
|
625
|
+
default:
|
|
626
|
+
this.fail("disallowed character.");
|
|
627
|
+
return code;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (code > 56319) {
|
|
631
|
+
if (!(code >= 57344 && code <= 65533)) {
|
|
632
|
+
this.fail("disallowed character.");
|
|
633
|
+
}
|
|
634
|
+
return code;
|
|
635
|
+
}
|
|
636
|
+
const final = 65536 + (code - 55296) * 1024 + (chunk.charCodeAt(i + 1) - 56320);
|
|
637
|
+
this.i = i + 2;
|
|
638
|
+
if (final > 1114111) {
|
|
639
|
+
this.fail("disallowed character.");
|
|
640
|
+
}
|
|
641
|
+
return final;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Get a single code point out of the current chunk. This updates the current
|
|
645
|
+
* position if we do position tracking.
|
|
646
|
+
*
|
|
647
|
+
* This is the algorithm to use for XML 1.1.
|
|
648
|
+
*
|
|
649
|
+
* @returns {number} The character read.
|
|
650
|
+
*/
|
|
651
|
+
getCode11() {
|
|
652
|
+
const { chunk, i } = this;
|
|
653
|
+
this.prevI = i;
|
|
654
|
+
this.i = i + 1;
|
|
655
|
+
if (i >= chunk.length) {
|
|
656
|
+
return EOC;
|
|
657
|
+
}
|
|
658
|
+
const code = chunk.charCodeAt(i);
|
|
659
|
+
this.column++;
|
|
660
|
+
if (code < 55296) {
|
|
661
|
+
if (code > 31 && code < 127 || code > 159 && code !== LS || code === TAB) {
|
|
662
|
+
return code;
|
|
663
|
+
}
|
|
664
|
+
switch (code) {
|
|
665
|
+
case NL:
|
|
666
|
+
this.line++;
|
|
667
|
+
this.column = 0;
|
|
668
|
+
this.positionAtNewLine = this.position;
|
|
669
|
+
return NL;
|
|
670
|
+
case CR: {
|
|
671
|
+
const next = chunk.charCodeAt(i + 1);
|
|
672
|
+
if (next === NL || next === NEL) {
|
|
673
|
+
this.i = i + 2;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
/* yes, fall through */
|
|
677
|
+
case NEL:
|
|
678
|
+
// 0x85
|
|
679
|
+
case LS:
|
|
680
|
+
this.line++;
|
|
681
|
+
this.column = 0;
|
|
682
|
+
this.positionAtNewLine = this.position;
|
|
683
|
+
return NL_LIKE;
|
|
684
|
+
default:
|
|
685
|
+
this.fail("disallowed character.");
|
|
686
|
+
return code;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (code > 56319) {
|
|
690
|
+
if (!(code >= 57344 && code <= 65533)) {
|
|
691
|
+
this.fail("disallowed character.");
|
|
692
|
+
}
|
|
693
|
+
return code;
|
|
694
|
+
}
|
|
695
|
+
const final = 65536 + (code - 55296) * 1024 + (chunk.charCodeAt(i + 1) - 56320);
|
|
696
|
+
this.i = i + 2;
|
|
697
|
+
if (final > 1114111) {
|
|
698
|
+
this.fail("disallowed character.");
|
|
699
|
+
}
|
|
700
|
+
return final;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Like ``getCode`` but with the return value normalized so that ``NL`` is
|
|
704
|
+
* returned for ``NL_LIKE``.
|
|
705
|
+
*/
|
|
706
|
+
getCodeNorm() {
|
|
707
|
+
const c = this.getCode();
|
|
708
|
+
return c === NL_LIKE ? NL : c;
|
|
709
|
+
}
|
|
710
|
+
unget() {
|
|
711
|
+
this.i = this.prevI;
|
|
712
|
+
this.column--;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Capture characters into a buffer until encountering one of a set of
|
|
716
|
+
* characters.
|
|
717
|
+
*
|
|
718
|
+
* @param chars An array of codepoints. Encountering a character in the array
|
|
719
|
+
* ends the capture. (``chars`` may safely contain ``NL``.)
|
|
720
|
+
*
|
|
721
|
+
* @return The character code that made the capture end, or ``EOC`` if we hit
|
|
722
|
+
* the end of the chunk. The return value cannot be NL_LIKE: NL is returned
|
|
723
|
+
* instead.
|
|
724
|
+
*/
|
|
725
|
+
captureTo(chars) {
|
|
726
|
+
let { i: start } = this;
|
|
727
|
+
const { chunk } = this;
|
|
728
|
+
while (true) {
|
|
729
|
+
const c = this.getCode();
|
|
730
|
+
const isNLLike = c === NL_LIKE;
|
|
731
|
+
const final = isNLLike ? NL : c;
|
|
732
|
+
if (final === EOC || chars.includes(final)) {
|
|
733
|
+
this.text += chunk.slice(start, this.prevI);
|
|
734
|
+
return final;
|
|
735
|
+
}
|
|
736
|
+
if (isNLLike) {
|
|
737
|
+
this.text += `${chunk.slice(start, this.prevI)}
|
|
738
|
+
`;
|
|
739
|
+
start = this.i;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Capture characters into a buffer until encountering a character.
|
|
745
|
+
*
|
|
746
|
+
* @param char The codepoint that ends the capture. **NOTE ``char`` MAY NOT
|
|
747
|
+
* CONTAIN ``NL``.** Passing ``NL`` will result in buggy behavior.
|
|
748
|
+
*
|
|
749
|
+
* @return ``true`` if we ran into the character. Otherwise, we ran into the
|
|
750
|
+
* end of the current chunk.
|
|
751
|
+
*/
|
|
752
|
+
captureToChar(char) {
|
|
753
|
+
let { i: start } = this;
|
|
754
|
+
const { chunk } = this;
|
|
755
|
+
while (true) {
|
|
756
|
+
let c = this.getCode();
|
|
757
|
+
switch (c) {
|
|
758
|
+
case NL_LIKE:
|
|
759
|
+
this.text += `${chunk.slice(start, this.prevI)}
|
|
760
|
+
`;
|
|
761
|
+
start = this.i;
|
|
762
|
+
c = NL;
|
|
763
|
+
break;
|
|
764
|
+
case EOC:
|
|
765
|
+
this.text += chunk.slice(start);
|
|
766
|
+
return false;
|
|
767
|
+
default:
|
|
768
|
+
}
|
|
769
|
+
if (c === char) {
|
|
770
|
+
this.text += chunk.slice(start, this.prevI);
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Capture characters that satisfy ``isNameChar`` into the ``name`` field of
|
|
777
|
+
* this parser.
|
|
778
|
+
*
|
|
779
|
+
* @return The character code that made the test fail, or ``EOC`` if we hit
|
|
780
|
+
* the end of the chunk. The return value cannot be NL_LIKE: NL is returned
|
|
781
|
+
* instead.
|
|
782
|
+
*/
|
|
783
|
+
captureNameChars() {
|
|
784
|
+
const { chunk, i: start } = this;
|
|
785
|
+
while (true) {
|
|
786
|
+
const c = this.getCode();
|
|
787
|
+
if (c === EOC) {
|
|
788
|
+
this.name += chunk.slice(start);
|
|
789
|
+
return EOC;
|
|
790
|
+
}
|
|
791
|
+
if (!isNameChar(c)) {
|
|
792
|
+
this.name += chunk.slice(start, this.prevI);
|
|
793
|
+
return c === NL_LIKE ? NL : c;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Skip white spaces.
|
|
799
|
+
*
|
|
800
|
+
* @return The character that ended the skip, or ``EOC`` if we hit
|
|
801
|
+
* the end of the chunk. The return value cannot be NL_LIKE: NL is returned
|
|
802
|
+
* instead.
|
|
803
|
+
*/
|
|
804
|
+
skipSpaces() {
|
|
805
|
+
while (true) {
|
|
806
|
+
const c = this.getCodeNorm();
|
|
807
|
+
if (c === EOC || !isS(c)) {
|
|
808
|
+
return c;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
setXMLVersion(version) {
|
|
813
|
+
this.currentXMLVersion = version;
|
|
814
|
+
if (version === "1.0") {
|
|
815
|
+
this.isChar = isChar10;
|
|
816
|
+
this.getCode = this.getCode10;
|
|
817
|
+
} else {
|
|
818
|
+
this.isChar = isChar11;
|
|
819
|
+
this.getCode = this.getCode11;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// STATE ENGINE METHODS
|
|
823
|
+
// This needs to be a state separate from S_BEGIN_WHITESPACE because we want
|
|
824
|
+
// to be sure never to come back to this state later.
|
|
825
|
+
sBegin() {
|
|
826
|
+
if (this.chunk.charCodeAt(0) === 65279) {
|
|
827
|
+
this.i++;
|
|
828
|
+
this.column++;
|
|
829
|
+
}
|
|
830
|
+
this.state = S_BEGIN_WHITESPACE;
|
|
831
|
+
}
|
|
832
|
+
sBeginWhitespace() {
|
|
833
|
+
const iBefore = this.i;
|
|
834
|
+
const c = this.skipSpaces();
|
|
835
|
+
if (this.prevI !== iBefore) {
|
|
836
|
+
this.xmlDeclPossible = false;
|
|
837
|
+
}
|
|
838
|
+
switch (c) {
|
|
839
|
+
case LESS:
|
|
840
|
+
this.state = S_OPEN_WAKA;
|
|
841
|
+
if (this.text.length !== 0) {
|
|
842
|
+
throw new Error("no-empty text at start");
|
|
843
|
+
}
|
|
844
|
+
break;
|
|
845
|
+
case EOC:
|
|
846
|
+
break;
|
|
847
|
+
default:
|
|
848
|
+
this.unget();
|
|
849
|
+
this.state = S_TEXT;
|
|
850
|
+
this.xmlDeclPossible = false;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
sDoctype() {
|
|
854
|
+
var _a;
|
|
855
|
+
const c = this.captureTo(DOCTYPE_TERMINATOR);
|
|
856
|
+
switch (c) {
|
|
857
|
+
case GREATER: {
|
|
858
|
+
(_a = this.doctypeHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
|
|
859
|
+
this.text = "";
|
|
860
|
+
this.state = S_TEXT;
|
|
861
|
+
this.doctype = true;
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
case EOC:
|
|
865
|
+
break;
|
|
866
|
+
default:
|
|
867
|
+
this.text += String.fromCodePoint(c);
|
|
868
|
+
if (c === OPEN_BRACKET) {
|
|
869
|
+
this.state = S_DTD;
|
|
870
|
+
} else if (isQuote(c)) {
|
|
871
|
+
this.state = S_DOCTYPE_QUOTE;
|
|
872
|
+
this.q = c;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
sDoctypeQuote() {
|
|
877
|
+
const q = this.q;
|
|
878
|
+
if (this.captureToChar(q)) {
|
|
879
|
+
this.text += String.fromCodePoint(q);
|
|
880
|
+
this.q = null;
|
|
881
|
+
this.state = S_DOCTYPE;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
sDTD() {
|
|
885
|
+
const c = this.captureTo(DTD_TERMINATOR);
|
|
886
|
+
if (c === EOC) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
this.text += String.fromCodePoint(c);
|
|
890
|
+
if (c === CLOSE_BRACKET) {
|
|
891
|
+
this.state = S_DOCTYPE;
|
|
892
|
+
} else if (c === LESS) {
|
|
893
|
+
this.state = S_DTD_OPEN_WAKA;
|
|
894
|
+
} else if (isQuote(c)) {
|
|
895
|
+
this.state = S_DTD_QUOTED;
|
|
896
|
+
this.q = c;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
sDTDQuoted() {
|
|
900
|
+
const q = this.q;
|
|
901
|
+
if (this.captureToChar(q)) {
|
|
902
|
+
this.text += String.fromCodePoint(q);
|
|
903
|
+
this.state = S_DTD;
|
|
904
|
+
this.q = null;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
sDTDOpenWaka() {
|
|
908
|
+
const c = this.getCodeNorm();
|
|
909
|
+
this.text += String.fromCodePoint(c);
|
|
910
|
+
switch (c) {
|
|
911
|
+
case BANG:
|
|
912
|
+
this.state = S_DTD_OPEN_WAKA_BANG;
|
|
913
|
+
this.openWakaBang = "";
|
|
914
|
+
break;
|
|
915
|
+
case QUESTION:
|
|
916
|
+
this.state = S_DTD_PI;
|
|
917
|
+
break;
|
|
918
|
+
default:
|
|
919
|
+
this.state = S_DTD;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
sDTDOpenWakaBang() {
|
|
923
|
+
const char = String.fromCodePoint(this.getCodeNorm());
|
|
924
|
+
const owb = this.openWakaBang += char;
|
|
925
|
+
this.text += char;
|
|
926
|
+
if (owb !== "-") {
|
|
927
|
+
this.state = owb === "--" ? S_DTD_COMMENT : S_DTD;
|
|
928
|
+
this.openWakaBang = "";
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
sDTDComment() {
|
|
932
|
+
if (this.captureToChar(MINUS)) {
|
|
933
|
+
this.text += "-";
|
|
934
|
+
this.state = S_DTD_COMMENT_ENDING;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
sDTDCommentEnding() {
|
|
938
|
+
const c = this.getCodeNorm();
|
|
939
|
+
this.text += String.fromCodePoint(c);
|
|
940
|
+
this.state = c === MINUS ? S_DTD_COMMENT_ENDED : S_DTD_COMMENT;
|
|
941
|
+
}
|
|
942
|
+
sDTDCommentEnded() {
|
|
943
|
+
const c = this.getCodeNorm();
|
|
944
|
+
this.text += String.fromCodePoint(c);
|
|
945
|
+
if (c === GREATER) {
|
|
946
|
+
this.state = S_DTD;
|
|
947
|
+
} else {
|
|
948
|
+
this.fail("malformed comment.");
|
|
949
|
+
this.state = S_DTD_COMMENT;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
sDTDPI() {
|
|
953
|
+
if (this.captureToChar(QUESTION)) {
|
|
954
|
+
this.text += "?";
|
|
955
|
+
this.state = S_DTD_PI_ENDING;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
sDTDPIEnding() {
|
|
959
|
+
const c = this.getCodeNorm();
|
|
960
|
+
this.text += String.fromCodePoint(c);
|
|
961
|
+
if (c === GREATER) {
|
|
962
|
+
this.state = S_DTD;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
sText() {
|
|
966
|
+
if (this.tags.length !== 0) {
|
|
967
|
+
this.handleTextInRoot();
|
|
968
|
+
} else {
|
|
969
|
+
this.handleTextOutsideRoot();
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
sEntity() {
|
|
973
|
+
let { i: start } = this;
|
|
974
|
+
const { chunk } = this;
|
|
975
|
+
loop:
|
|
976
|
+
while (true) {
|
|
977
|
+
switch (this.getCode()) {
|
|
978
|
+
case NL_LIKE:
|
|
979
|
+
this.entity += `${chunk.slice(start, this.prevI)}
|
|
980
|
+
`;
|
|
981
|
+
start = this.i;
|
|
982
|
+
break;
|
|
983
|
+
case SEMICOLON: {
|
|
984
|
+
const { entityReturnState } = this;
|
|
985
|
+
const entity = this.entity + chunk.slice(start, this.prevI);
|
|
986
|
+
this.state = entityReturnState;
|
|
987
|
+
let parsed;
|
|
988
|
+
if (entity === "") {
|
|
989
|
+
this.fail("empty entity name.");
|
|
990
|
+
parsed = "&;";
|
|
991
|
+
} else {
|
|
992
|
+
parsed = this.parseEntity(entity);
|
|
993
|
+
this.entity = "";
|
|
994
|
+
}
|
|
995
|
+
if (entityReturnState !== S_TEXT || this.textHandler !== void 0) {
|
|
996
|
+
this.text += parsed;
|
|
997
|
+
}
|
|
998
|
+
break loop;
|
|
999
|
+
}
|
|
1000
|
+
case EOC:
|
|
1001
|
+
this.entity += chunk.slice(start);
|
|
1002
|
+
break loop;
|
|
1003
|
+
default:
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
sOpenWaka() {
|
|
1008
|
+
const c = this.getCode();
|
|
1009
|
+
if (isNameStartChar(c)) {
|
|
1010
|
+
this.state = S_OPEN_TAG;
|
|
1011
|
+
this.unget();
|
|
1012
|
+
this.xmlDeclPossible = false;
|
|
1013
|
+
} else {
|
|
1014
|
+
switch (c) {
|
|
1015
|
+
case FORWARD_SLASH:
|
|
1016
|
+
this.state = S_CLOSE_TAG;
|
|
1017
|
+
this.xmlDeclPossible = false;
|
|
1018
|
+
break;
|
|
1019
|
+
case BANG:
|
|
1020
|
+
this.state = S_OPEN_WAKA_BANG;
|
|
1021
|
+
this.openWakaBang = "";
|
|
1022
|
+
this.xmlDeclPossible = false;
|
|
1023
|
+
break;
|
|
1024
|
+
case QUESTION:
|
|
1025
|
+
this.state = S_PI_FIRST_CHAR;
|
|
1026
|
+
break;
|
|
1027
|
+
default:
|
|
1028
|
+
this.fail("disallowed character in tag name");
|
|
1029
|
+
this.state = S_TEXT;
|
|
1030
|
+
this.xmlDeclPossible = false;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
sOpenWakaBang() {
|
|
1035
|
+
this.openWakaBang += String.fromCodePoint(this.getCodeNorm());
|
|
1036
|
+
switch (this.openWakaBang) {
|
|
1037
|
+
case "[CDATA[":
|
|
1038
|
+
if (!this.sawRoot && !this.reportedTextBeforeRoot) {
|
|
1039
|
+
this.fail("text data outside of root node.");
|
|
1040
|
+
this.reportedTextBeforeRoot = true;
|
|
1041
|
+
}
|
|
1042
|
+
if (this.closedRoot && !this.reportedTextAfterRoot) {
|
|
1043
|
+
this.fail("text data outside of root node.");
|
|
1044
|
+
this.reportedTextAfterRoot = true;
|
|
1045
|
+
}
|
|
1046
|
+
this.state = S_CDATA;
|
|
1047
|
+
this.openWakaBang = "";
|
|
1048
|
+
break;
|
|
1049
|
+
case "--":
|
|
1050
|
+
this.state = S_COMMENT;
|
|
1051
|
+
this.openWakaBang = "";
|
|
1052
|
+
break;
|
|
1053
|
+
case "DOCTYPE":
|
|
1054
|
+
this.state = S_DOCTYPE;
|
|
1055
|
+
if (this.doctype || this.sawRoot) {
|
|
1056
|
+
this.fail("inappropriately located doctype declaration.");
|
|
1057
|
+
}
|
|
1058
|
+
this.openWakaBang = "";
|
|
1059
|
+
break;
|
|
1060
|
+
default:
|
|
1061
|
+
if (this.openWakaBang.length >= 7) {
|
|
1062
|
+
this.fail("incorrect syntax.");
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
sComment() {
|
|
1067
|
+
if (this.captureToChar(MINUS)) {
|
|
1068
|
+
this.state = S_COMMENT_ENDING;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
sCommentEnding() {
|
|
1072
|
+
var _a;
|
|
1073
|
+
const c = this.getCodeNorm();
|
|
1074
|
+
if (c === MINUS) {
|
|
1075
|
+
this.state = S_COMMENT_ENDED;
|
|
1076
|
+
(_a = this.commentHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
|
|
1077
|
+
this.text = "";
|
|
1078
|
+
} else {
|
|
1079
|
+
this.text += `-${String.fromCodePoint(c)}`;
|
|
1080
|
+
this.state = S_COMMENT;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
sCommentEnded() {
|
|
1084
|
+
const c = this.getCodeNorm();
|
|
1085
|
+
if (c !== GREATER) {
|
|
1086
|
+
this.fail("malformed comment.");
|
|
1087
|
+
this.text += `--${String.fromCodePoint(c)}`;
|
|
1088
|
+
this.state = S_COMMENT;
|
|
1089
|
+
} else {
|
|
1090
|
+
this.state = S_TEXT;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
sCData() {
|
|
1094
|
+
if (this.captureToChar(CLOSE_BRACKET)) {
|
|
1095
|
+
this.state = S_CDATA_ENDING;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
sCDataEnding() {
|
|
1099
|
+
const c = this.getCodeNorm();
|
|
1100
|
+
if (c === CLOSE_BRACKET) {
|
|
1101
|
+
this.state = S_CDATA_ENDING_2;
|
|
1102
|
+
} else {
|
|
1103
|
+
this.text += `]${String.fromCodePoint(c)}`;
|
|
1104
|
+
this.state = S_CDATA;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
sCDataEnding2() {
|
|
1108
|
+
var _a;
|
|
1109
|
+
const c = this.getCodeNorm();
|
|
1110
|
+
switch (c) {
|
|
1111
|
+
case GREATER: {
|
|
1112
|
+
(_a = this.cdataHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
|
|
1113
|
+
this.text = "";
|
|
1114
|
+
this.state = S_TEXT;
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
case CLOSE_BRACKET:
|
|
1118
|
+
this.text += "]";
|
|
1119
|
+
break;
|
|
1120
|
+
default:
|
|
1121
|
+
this.text += `]]${String.fromCodePoint(c)}`;
|
|
1122
|
+
this.state = S_CDATA;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
// We need this separate state to check the first character fo the pi target
|
|
1126
|
+
// with this.nameStartCheck which allows less characters than this.nameCheck.
|
|
1127
|
+
sPIFirstChar() {
|
|
1128
|
+
const c = this.getCodeNorm();
|
|
1129
|
+
if (this.nameStartCheck(c)) {
|
|
1130
|
+
this.piTarget += String.fromCodePoint(c);
|
|
1131
|
+
this.state = S_PI_REST;
|
|
1132
|
+
} else if (c === QUESTION || isS(c)) {
|
|
1133
|
+
this.fail("processing instruction without a target.");
|
|
1134
|
+
this.state = c === QUESTION ? S_PI_ENDING : S_PI_BODY;
|
|
1135
|
+
} else {
|
|
1136
|
+
this.fail("disallowed character in processing instruction name.");
|
|
1137
|
+
this.piTarget += String.fromCodePoint(c);
|
|
1138
|
+
this.state = S_PI_REST;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
sPIRest() {
|
|
1142
|
+
const { chunk, i: start } = this;
|
|
1143
|
+
while (true) {
|
|
1144
|
+
const c = this.getCodeNorm();
|
|
1145
|
+
if (c === EOC) {
|
|
1146
|
+
this.piTarget += chunk.slice(start);
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
if (!this.nameCheck(c)) {
|
|
1150
|
+
this.piTarget += chunk.slice(start, this.prevI);
|
|
1151
|
+
const isQuestion = c === QUESTION;
|
|
1152
|
+
if (isQuestion || isS(c)) {
|
|
1153
|
+
if (this.piTarget === "xml") {
|
|
1154
|
+
if (!this.xmlDeclPossible) {
|
|
1155
|
+
this.fail("an XML declaration must be at the start of the document.");
|
|
1156
|
+
}
|
|
1157
|
+
this.state = isQuestion ? S_XML_DECL_ENDING : S_XML_DECL_NAME_START;
|
|
1158
|
+
} else {
|
|
1159
|
+
this.state = isQuestion ? S_PI_ENDING : S_PI_BODY;
|
|
1160
|
+
}
|
|
1161
|
+
} else {
|
|
1162
|
+
this.fail("disallowed character in processing instruction name.");
|
|
1163
|
+
this.piTarget += String.fromCodePoint(c);
|
|
1164
|
+
}
|
|
1165
|
+
break;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
sPIBody() {
|
|
1170
|
+
if (this.text.length === 0) {
|
|
1171
|
+
const c = this.getCodeNorm();
|
|
1172
|
+
if (c === QUESTION) {
|
|
1173
|
+
this.state = S_PI_ENDING;
|
|
1174
|
+
} else if (!isS(c)) {
|
|
1175
|
+
this.text = String.fromCodePoint(c);
|
|
1176
|
+
}
|
|
1177
|
+
} else if (this.captureToChar(QUESTION)) {
|
|
1178
|
+
this.state = S_PI_ENDING;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
sPIEnding() {
|
|
1182
|
+
var _a;
|
|
1183
|
+
const c = this.getCodeNorm();
|
|
1184
|
+
if (c === GREATER) {
|
|
1185
|
+
const { piTarget } = this;
|
|
1186
|
+
if (piTarget.toLowerCase() === "xml") {
|
|
1187
|
+
this.fail("the XML declaration must appear at the start of the document.");
|
|
1188
|
+
}
|
|
1189
|
+
(_a = this.piHandler) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
1190
|
+
target: piTarget,
|
|
1191
|
+
body: this.text
|
|
1192
|
+
});
|
|
1193
|
+
this.piTarget = this.text = "";
|
|
1194
|
+
this.state = S_TEXT;
|
|
1195
|
+
} else if (c === QUESTION) {
|
|
1196
|
+
this.text += "?";
|
|
1197
|
+
} else {
|
|
1198
|
+
this.text += `?${String.fromCodePoint(c)}`;
|
|
1199
|
+
this.state = S_PI_BODY;
|
|
1200
|
+
}
|
|
1201
|
+
this.xmlDeclPossible = false;
|
|
1202
|
+
}
|
|
1203
|
+
sXMLDeclNameStart() {
|
|
1204
|
+
const c = this.skipSpaces();
|
|
1205
|
+
if (c === QUESTION) {
|
|
1206
|
+
this.state = S_XML_DECL_ENDING;
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
if (c !== EOC) {
|
|
1210
|
+
this.state = S_XML_DECL_NAME;
|
|
1211
|
+
this.name = String.fromCodePoint(c);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
sXMLDeclName() {
|
|
1215
|
+
const c = this.captureTo(XML_DECL_NAME_TERMINATOR);
|
|
1216
|
+
if (c === QUESTION) {
|
|
1217
|
+
this.state = S_XML_DECL_ENDING;
|
|
1218
|
+
this.name += this.text;
|
|
1219
|
+
this.text = "";
|
|
1220
|
+
this.fail("XML declaration is incomplete.");
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
if (!(isS(c) || c === EQUAL)) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
this.name += this.text;
|
|
1227
|
+
this.text = "";
|
|
1228
|
+
if (!this.xmlDeclExpects.includes(this.name)) {
|
|
1229
|
+
switch (this.name.length) {
|
|
1230
|
+
case 0:
|
|
1231
|
+
this.fail("did not expect any more name/value pairs.");
|
|
1232
|
+
break;
|
|
1233
|
+
case 1:
|
|
1234
|
+
this.fail(`expected the name ${this.xmlDeclExpects[0]}.`);
|
|
1235
|
+
break;
|
|
1236
|
+
default:
|
|
1237
|
+
this.fail(`expected one of ${this.xmlDeclExpects.join(", ")}`);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
this.state = c === EQUAL ? S_XML_DECL_VALUE_START : S_XML_DECL_EQ;
|
|
1241
|
+
}
|
|
1242
|
+
sXMLDeclEq() {
|
|
1243
|
+
const c = this.getCodeNorm();
|
|
1244
|
+
if (c === QUESTION) {
|
|
1245
|
+
this.state = S_XML_DECL_ENDING;
|
|
1246
|
+
this.fail("XML declaration is incomplete.");
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
if (isS(c)) {
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
if (c !== EQUAL) {
|
|
1253
|
+
this.fail("value required.");
|
|
1254
|
+
}
|
|
1255
|
+
this.state = S_XML_DECL_VALUE_START;
|
|
1256
|
+
}
|
|
1257
|
+
sXMLDeclValueStart() {
|
|
1258
|
+
const c = this.getCodeNorm();
|
|
1259
|
+
if (c === QUESTION) {
|
|
1260
|
+
this.state = S_XML_DECL_ENDING;
|
|
1261
|
+
this.fail("XML declaration is incomplete.");
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
if (isS(c)) {
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
if (!isQuote(c)) {
|
|
1268
|
+
this.fail("value must be quoted.");
|
|
1269
|
+
this.q = SPACE;
|
|
1270
|
+
} else {
|
|
1271
|
+
this.q = c;
|
|
1272
|
+
}
|
|
1273
|
+
this.state = S_XML_DECL_VALUE;
|
|
1274
|
+
}
|
|
1275
|
+
sXMLDeclValue() {
|
|
1276
|
+
const c = this.captureTo([this.q, QUESTION]);
|
|
1277
|
+
if (c === QUESTION) {
|
|
1278
|
+
this.state = S_XML_DECL_ENDING;
|
|
1279
|
+
this.text = "";
|
|
1280
|
+
this.fail("XML declaration is incomplete.");
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
if (c === EOC) {
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
const value = this.text;
|
|
1287
|
+
this.text = "";
|
|
1288
|
+
switch (this.name) {
|
|
1289
|
+
case "version": {
|
|
1290
|
+
this.xmlDeclExpects = ["encoding", "standalone"];
|
|
1291
|
+
const version = value;
|
|
1292
|
+
this.xmlDecl.version = version;
|
|
1293
|
+
if (!/^1\.[0-9]+$/.test(version)) {
|
|
1294
|
+
this.fail("version number must match /^1\\.[0-9]+$/.");
|
|
1295
|
+
} else if (!this.opt.forceXMLVersion) {
|
|
1296
|
+
this.setXMLVersion(version);
|
|
1297
|
+
}
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
case "encoding":
|
|
1301
|
+
if (!/^[A-Za-z][A-Za-z0-9._-]*$/.test(value)) {
|
|
1302
|
+
this.fail("encoding value must match /^[A-Za-z0-9][A-Za-z0-9._-]*$/.");
|
|
1303
|
+
}
|
|
1304
|
+
this.xmlDeclExpects = ["standalone"];
|
|
1305
|
+
this.xmlDecl.encoding = value;
|
|
1306
|
+
break;
|
|
1307
|
+
case "standalone":
|
|
1308
|
+
if (value !== "yes" && value !== "no") {
|
|
1309
|
+
this.fail('standalone value must match "yes" or "no".');
|
|
1310
|
+
}
|
|
1311
|
+
this.xmlDeclExpects = [];
|
|
1312
|
+
this.xmlDecl.standalone = value;
|
|
1313
|
+
break;
|
|
1314
|
+
default:
|
|
1315
|
+
}
|
|
1316
|
+
this.name = "";
|
|
1317
|
+
this.state = S_XML_DECL_SEPARATOR;
|
|
1318
|
+
}
|
|
1319
|
+
sXMLDeclSeparator() {
|
|
1320
|
+
const c = this.getCodeNorm();
|
|
1321
|
+
if (c === QUESTION) {
|
|
1322
|
+
this.state = S_XML_DECL_ENDING;
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
if (!isS(c)) {
|
|
1326
|
+
this.fail("whitespace required.");
|
|
1327
|
+
this.unget();
|
|
1328
|
+
}
|
|
1329
|
+
this.state = S_XML_DECL_NAME_START;
|
|
1330
|
+
}
|
|
1331
|
+
sXMLDeclEnding() {
|
|
1332
|
+
var _a;
|
|
1333
|
+
const c = this.getCodeNorm();
|
|
1334
|
+
if (c === GREATER) {
|
|
1335
|
+
if (this.piTarget !== "xml") {
|
|
1336
|
+
this.fail("processing instructions are not allowed before root.");
|
|
1337
|
+
} else if (this.name !== "version" && this.xmlDeclExpects.includes("version")) {
|
|
1338
|
+
this.fail("XML declaration must contain a version.");
|
|
1339
|
+
}
|
|
1340
|
+
(_a = this.xmldeclHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.xmlDecl);
|
|
1341
|
+
this.name = "";
|
|
1342
|
+
this.piTarget = this.text = "";
|
|
1343
|
+
this.state = S_TEXT;
|
|
1344
|
+
} else {
|
|
1345
|
+
this.fail("The character ? is disallowed anywhere in XML declarations.");
|
|
1346
|
+
}
|
|
1347
|
+
this.xmlDeclPossible = false;
|
|
1348
|
+
}
|
|
1349
|
+
sOpenTag() {
|
|
1350
|
+
var _a;
|
|
1351
|
+
const c = this.captureNameChars();
|
|
1352
|
+
if (c === EOC) {
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
const tag = this.tag = {
|
|
1356
|
+
name: this.name,
|
|
1357
|
+
attributes: /* @__PURE__ */ Object.create(null)
|
|
1358
|
+
};
|
|
1359
|
+
this.name = "";
|
|
1360
|
+
if (this.xmlnsOpt) {
|
|
1361
|
+
this.topNS = tag.ns = /* @__PURE__ */ Object.create(null);
|
|
1362
|
+
}
|
|
1363
|
+
(_a = this.openTagStartHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
|
|
1364
|
+
this.sawRoot = true;
|
|
1365
|
+
if (!this.fragmentOpt && this.closedRoot) {
|
|
1366
|
+
this.fail("documents may contain only one root.");
|
|
1367
|
+
}
|
|
1368
|
+
switch (c) {
|
|
1369
|
+
case GREATER:
|
|
1370
|
+
this.openTag();
|
|
1371
|
+
break;
|
|
1372
|
+
case FORWARD_SLASH:
|
|
1373
|
+
this.state = S_OPEN_TAG_SLASH;
|
|
1374
|
+
break;
|
|
1375
|
+
default:
|
|
1376
|
+
if (!isS(c)) {
|
|
1377
|
+
this.fail("disallowed character in tag name.");
|
|
1378
|
+
}
|
|
1379
|
+
this.state = S_ATTRIB;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
sOpenTagSlash() {
|
|
1383
|
+
if (this.getCode() === GREATER) {
|
|
1384
|
+
this.openSelfClosingTag();
|
|
1385
|
+
} else {
|
|
1386
|
+
this.fail("forward-slash in opening tag not followed by >.");
|
|
1387
|
+
this.state = S_ATTRIB;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
sAttrib() {
|
|
1391
|
+
const c = this.skipSpaces();
|
|
1392
|
+
if (c === EOC) {
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
if (isNameStartChar(c)) {
|
|
1396
|
+
this.unget();
|
|
1397
|
+
this.state = S_ATTRIB_NAME;
|
|
1398
|
+
} else if (c === GREATER) {
|
|
1399
|
+
this.openTag();
|
|
1400
|
+
} else if (c === FORWARD_SLASH) {
|
|
1401
|
+
this.state = S_OPEN_TAG_SLASH;
|
|
1402
|
+
} else {
|
|
1403
|
+
this.fail("disallowed character in attribute name.");
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
sAttribName() {
|
|
1407
|
+
const c = this.captureNameChars();
|
|
1408
|
+
if (c === EQUAL) {
|
|
1409
|
+
this.state = S_ATTRIB_VALUE;
|
|
1410
|
+
} else if (isS(c)) {
|
|
1411
|
+
this.state = S_ATTRIB_NAME_SAW_WHITE;
|
|
1412
|
+
} else if (c === GREATER) {
|
|
1413
|
+
this.fail("attribute without value.");
|
|
1414
|
+
this.pushAttrib(this.name, this.name);
|
|
1415
|
+
this.name = this.text = "";
|
|
1416
|
+
this.openTag();
|
|
1417
|
+
} else if (c !== EOC) {
|
|
1418
|
+
this.fail("disallowed character in attribute name.");
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
sAttribNameSawWhite() {
|
|
1422
|
+
const c = this.skipSpaces();
|
|
1423
|
+
switch (c) {
|
|
1424
|
+
case EOC:
|
|
1425
|
+
return;
|
|
1426
|
+
case EQUAL:
|
|
1427
|
+
this.state = S_ATTRIB_VALUE;
|
|
1428
|
+
break;
|
|
1429
|
+
default:
|
|
1430
|
+
this.fail("attribute without value.");
|
|
1431
|
+
this.text = "";
|
|
1432
|
+
this.name = "";
|
|
1433
|
+
if (c === GREATER) {
|
|
1434
|
+
this.openTag();
|
|
1435
|
+
} else if (isNameStartChar(c)) {
|
|
1436
|
+
this.unget();
|
|
1437
|
+
this.state = S_ATTRIB_NAME;
|
|
1438
|
+
} else {
|
|
1439
|
+
this.fail("disallowed character in attribute name.");
|
|
1440
|
+
this.state = S_ATTRIB;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
sAttribValue() {
|
|
1445
|
+
const c = this.getCodeNorm();
|
|
1446
|
+
if (isQuote(c)) {
|
|
1447
|
+
this.q = c;
|
|
1448
|
+
this.state = S_ATTRIB_VALUE_QUOTED;
|
|
1449
|
+
} else if (!isS(c)) {
|
|
1450
|
+
this.fail("unquoted attribute value.");
|
|
1451
|
+
this.state = S_ATTRIB_VALUE_UNQUOTED;
|
|
1452
|
+
this.unget();
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
sAttribValueQuoted() {
|
|
1456
|
+
const { q, chunk } = this;
|
|
1457
|
+
let { i: start } = this;
|
|
1458
|
+
while (true) {
|
|
1459
|
+
switch (this.getCode()) {
|
|
1460
|
+
case q:
|
|
1461
|
+
this.pushAttrib(this.name, this.text + chunk.slice(start, this.prevI));
|
|
1462
|
+
this.name = this.text = "";
|
|
1463
|
+
this.q = null;
|
|
1464
|
+
this.state = S_ATTRIB_VALUE_CLOSED;
|
|
1465
|
+
return;
|
|
1466
|
+
case AMP:
|
|
1467
|
+
this.text += chunk.slice(start, this.prevI);
|
|
1468
|
+
this.state = S_ENTITY;
|
|
1469
|
+
this.entityReturnState = S_ATTRIB_VALUE_QUOTED;
|
|
1470
|
+
return;
|
|
1471
|
+
case NL:
|
|
1472
|
+
case NL_LIKE:
|
|
1473
|
+
case TAB:
|
|
1474
|
+
this.text += `${chunk.slice(start, this.prevI)} `;
|
|
1475
|
+
start = this.i;
|
|
1476
|
+
break;
|
|
1477
|
+
case LESS:
|
|
1478
|
+
this.text += chunk.slice(start, this.prevI);
|
|
1479
|
+
this.fail("disallowed character.");
|
|
1480
|
+
return;
|
|
1481
|
+
case EOC:
|
|
1482
|
+
this.text += chunk.slice(start);
|
|
1483
|
+
return;
|
|
1484
|
+
default:
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
sAttribValueClosed() {
|
|
1489
|
+
const c = this.getCodeNorm();
|
|
1490
|
+
if (isS(c)) {
|
|
1491
|
+
this.state = S_ATTRIB;
|
|
1492
|
+
} else if (c === GREATER) {
|
|
1493
|
+
this.openTag();
|
|
1494
|
+
} else if (c === FORWARD_SLASH) {
|
|
1495
|
+
this.state = S_OPEN_TAG_SLASH;
|
|
1496
|
+
} else if (isNameStartChar(c)) {
|
|
1497
|
+
this.fail("no whitespace between attributes.");
|
|
1498
|
+
this.unget();
|
|
1499
|
+
this.state = S_ATTRIB_NAME;
|
|
1500
|
+
} else {
|
|
1501
|
+
this.fail("disallowed character in attribute name.");
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
sAttribValueUnquoted() {
|
|
1505
|
+
const c = this.captureTo(ATTRIB_VALUE_UNQUOTED_TERMINATOR);
|
|
1506
|
+
switch (c) {
|
|
1507
|
+
case AMP:
|
|
1508
|
+
this.state = S_ENTITY;
|
|
1509
|
+
this.entityReturnState = S_ATTRIB_VALUE_UNQUOTED;
|
|
1510
|
+
break;
|
|
1511
|
+
case LESS:
|
|
1512
|
+
this.fail("disallowed character.");
|
|
1513
|
+
break;
|
|
1514
|
+
case EOC:
|
|
1515
|
+
break;
|
|
1516
|
+
default:
|
|
1517
|
+
if (this.text.includes("]]>")) {
|
|
1518
|
+
this.fail('the string "]]>" is disallowed in char data.');
|
|
1519
|
+
}
|
|
1520
|
+
this.pushAttrib(this.name, this.text);
|
|
1521
|
+
this.name = this.text = "";
|
|
1522
|
+
if (c === GREATER) {
|
|
1523
|
+
this.openTag();
|
|
1524
|
+
} else {
|
|
1525
|
+
this.state = S_ATTRIB;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
sCloseTag() {
|
|
1530
|
+
const c = this.captureNameChars();
|
|
1531
|
+
if (c === GREATER) {
|
|
1532
|
+
this.closeTag();
|
|
1533
|
+
} else if (isS(c)) {
|
|
1534
|
+
this.state = S_CLOSE_TAG_SAW_WHITE;
|
|
1535
|
+
} else if (c !== EOC) {
|
|
1536
|
+
this.fail("disallowed character in closing tag.");
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
sCloseTagSawWhite() {
|
|
1540
|
+
switch (this.skipSpaces()) {
|
|
1541
|
+
case GREATER:
|
|
1542
|
+
this.closeTag();
|
|
1543
|
+
break;
|
|
1544
|
+
case EOC:
|
|
1545
|
+
break;
|
|
1546
|
+
default:
|
|
1547
|
+
this.fail("disallowed character in closing tag.");
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
// END OF STATE ENGINE METHODS
|
|
1551
|
+
handleTextInRoot() {
|
|
1552
|
+
let { i: start, forbiddenState } = this;
|
|
1553
|
+
const { chunk, textHandler: handler } = this;
|
|
1554
|
+
scanLoop:
|
|
1555
|
+
while (true) {
|
|
1556
|
+
switch (this.getCode()) {
|
|
1557
|
+
case LESS: {
|
|
1558
|
+
this.state = S_OPEN_WAKA;
|
|
1559
|
+
if (handler !== void 0) {
|
|
1560
|
+
const { text } = this;
|
|
1561
|
+
const slice = chunk.slice(start, this.prevI);
|
|
1562
|
+
if (text.length !== 0) {
|
|
1563
|
+
handler(text + slice);
|
|
1564
|
+
this.text = "";
|
|
1565
|
+
} else if (slice.length !== 0) {
|
|
1566
|
+
handler(slice);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
forbiddenState = FORBIDDEN_START;
|
|
1570
|
+
break scanLoop;
|
|
1571
|
+
}
|
|
1572
|
+
case AMP:
|
|
1573
|
+
this.state = S_ENTITY;
|
|
1574
|
+
this.entityReturnState = S_TEXT;
|
|
1575
|
+
if (handler !== void 0) {
|
|
1576
|
+
this.text += chunk.slice(start, this.prevI);
|
|
1577
|
+
}
|
|
1578
|
+
forbiddenState = FORBIDDEN_START;
|
|
1579
|
+
break scanLoop;
|
|
1580
|
+
case CLOSE_BRACKET:
|
|
1581
|
+
switch (forbiddenState) {
|
|
1582
|
+
case FORBIDDEN_START:
|
|
1583
|
+
forbiddenState = FORBIDDEN_BRACKET;
|
|
1584
|
+
break;
|
|
1585
|
+
case FORBIDDEN_BRACKET:
|
|
1586
|
+
forbiddenState = FORBIDDEN_BRACKET_BRACKET;
|
|
1587
|
+
break;
|
|
1588
|
+
case FORBIDDEN_BRACKET_BRACKET:
|
|
1589
|
+
break;
|
|
1590
|
+
default:
|
|
1591
|
+
throw new Error("impossible state");
|
|
1592
|
+
}
|
|
1593
|
+
break;
|
|
1594
|
+
case GREATER:
|
|
1595
|
+
if (forbiddenState === FORBIDDEN_BRACKET_BRACKET) {
|
|
1596
|
+
this.fail('the string "]]>" is disallowed in char data.');
|
|
1597
|
+
}
|
|
1598
|
+
forbiddenState = FORBIDDEN_START;
|
|
1599
|
+
break;
|
|
1600
|
+
case NL_LIKE:
|
|
1601
|
+
if (handler !== void 0) {
|
|
1602
|
+
this.text += `${chunk.slice(start, this.prevI)}
|
|
1603
|
+
`;
|
|
1604
|
+
}
|
|
1605
|
+
start = this.i;
|
|
1606
|
+
forbiddenState = FORBIDDEN_START;
|
|
1607
|
+
break;
|
|
1608
|
+
case EOC:
|
|
1609
|
+
if (handler !== void 0) {
|
|
1610
|
+
this.text += chunk.slice(start);
|
|
1611
|
+
}
|
|
1612
|
+
break scanLoop;
|
|
1613
|
+
default:
|
|
1614
|
+
forbiddenState = FORBIDDEN_START;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
this.forbiddenState = forbiddenState;
|
|
1618
|
+
}
|
|
1619
|
+
handleTextOutsideRoot() {
|
|
1620
|
+
let { i: start } = this;
|
|
1621
|
+
const { chunk, textHandler: handler } = this;
|
|
1622
|
+
let nonSpace = false;
|
|
1623
|
+
outRootLoop:
|
|
1624
|
+
while (true) {
|
|
1625
|
+
const code = this.getCode();
|
|
1626
|
+
switch (code) {
|
|
1627
|
+
case LESS: {
|
|
1628
|
+
this.state = S_OPEN_WAKA;
|
|
1629
|
+
if (handler !== void 0) {
|
|
1630
|
+
const { text } = this;
|
|
1631
|
+
const slice = chunk.slice(start, this.prevI);
|
|
1632
|
+
if (text.length !== 0) {
|
|
1633
|
+
handler(text + slice);
|
|
1634
|
+
this.text = "";
|
|
1635
|
+
} else if (slice.length !== 0) {
|
|
1636
|
+
handler(slice);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
break outRootLoop;
|
|
1640
|
+
}
|
|
1641
|
+
case AMP:
|
|
1642
|
+
this.state = S_ENTITY;
|
|
1643
|
+
this.entityReturnState = S_TEXT;
|
|
1644
|
+
if (handler !== void 0) {
|
|
1645
|
+
this.text += chunk.slice(start, this.prevI);
|
|
1646
|
+
}
|
|
1647
|
+
nonSpace = true;
|
|
1648
|
+
break outRootLoop;
|
|
1649
|
+
case NL_LIKE:
|
|
1650
|
+
if (handler !== void 0) {
|
|
1651
|
+
this.text += `${chunk.slice(start, this.prevI)}
|
|
1652
|
+
`;
|
|
1653
|
+
}
|
|
1654
|
+
start = this.i;
|
|
1655
|
+
break;
|
|
1656
|
+
case EOC:
|
|
1657
|
+
if (handler !== void 0) {
|
|
1658
|
+
this.text += chunk.slice(start);
|
|
1659
|
+
}
|
|
1660
|
+
break outRootLoop;
|
|
1661
|
+
default:
|
|
1662
|
+
if (!isS(code)) {
|
|
1663
|
+
nonSpace = true;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
if (!nonSpace) {
|
|
1668
|
+
return;
|
|
1669
|
+
}
|
|
1670
|
+
if (!this.sawRoot && !this.reportedTextBeforeRoot) {
|
|
1671
|
+
this.fail("text data outside of root node.");
|
|
1672
|
+
this.reportedTextBeforeRoot = true;
|
|
1673
|
+
}
|
|
1674
|
+
if (this.closedRoot && !this.reportedTextAfterRoot) {
|
|
1675
|
+
this.fail("text data outside of root node.");
|
|
1676
|
+
this.reportedTextAfterRoot = true;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
pushAttribNS(name, value) {
|
|
1680
|
+
var _a;
|
|
1681
|
+
const { prefix, local } = this.qname(name);
|
|
1682
|
+
const attr = { name, prefix, local, value };
|
|
1683
|
+
this.attribList.push(attr);
|
|
1684
|
+
(_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
|
|
1685
|
+
if (prefix === "xmlns") {
|
|
1686
|
+
const trimmed = value.trim();
|
|
1687
|
+
if (this.currentXMLVersion === "1.0" && trimmed === "") {
|
|
1688
|
+
this.fail("invalid attempt to undefine prefix in XML 1.0");
|
|
1689
|
+
}
|
|
1690
|
+
this.topNS[local] = trimmed;
|
|
1691
|
+
nsPairCheck(this, local, trimmed);
|
|
1692
|
+
} else if (name === "xmlns") {
|
|
1693
|
+
const trimmed = value.trim();
|
|
1694
|
+
this.topNS[""] = trimmed;
|
|
1695
|
+
nsPairCheck(this, "", trimmed);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
pushAttribPlain(name, value) {
|
|
1699
|
+
var _a;
|
|
1700
|
+
const attr = { name, value };
|
|
1701
|
+
this.attribList.push(attr);
|
|
1702
|
+
(_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* End parsing. This performs final well-formedness checks and resets the
|
|
1706
|
+
* parser to a clean state.
|
|
1707
|
+
*
|
|
1708
|
+
* @returns this
|
|
1709
|
+
*/
|
|
1710
|
+
end() {
|
|
1711
|
+
var _a, _b;
|
|
1712
|
+
if (!this.sawRoot) {
|
|
1713
|
+
this.fail("document must contain a root element.");
|
|
1714
|
+
}
|
|
1715
|
+
const { tags } = this;
|
|
1716
|
+
while (tags.length > 0) {
|
|
1717
|
+
const tag = tags.pop();
|
|
1718
|
+
this.fail(`unclosed tag: ${tag.name}`);
|
|
1719
|
+
}
|
|
1720
|
+
if (this.state !== S_BEGIN && this.state !== S_TEXT) {
|
|
1721
|
+
this.fail("unexpected end.");
|
|
1722
|
+
}
|
|
1723
|
+
const { text } = this;
|
|
1724
|
+
if (text.length !== 0) {
|
|
1725
|
+
(_a = this.textHandler) === null || _a === void 0 ? void 0 : _a.call(this, text);
|
|
1726
|
+
this.text = "";
|
|
1727
|
+
}
|
|
1728
|
+
this._closed = true;
|
|
1729
|
+
(_b = this.endHandler) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
1730
|
+
this._init();
|
|
1731
|
+
return this;
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Resolve a namespace prefix.
|
|
1735
|
+
*
|
|
1736
|
+
* @param prefix The prefix to resolve.
|
|
1737
|
+
*
|
|
1738
|
+
* @returns The namespace URI or ``undefined`` if the prefix is not defined.
|
|
1739
|
+
*/
|
|
1740
|
+
resolve(prefix) {
|
|
1741
|
+
var _a, _b;
|
|
1742
|
+
let uri = this.topNS[prefix];
|
|
1743
|
+
if (uri !== void 0) {
|
|
1744
|
+
return uri;
|
|
1745
|
+
}
|
|
1746
|
+
const { tags } = this;
|
|
1747
|
+
for (let index = tags.length - 1; index >= 0; index--) {
|
|
1748
|
+
uri = tags[index].ns[prefix];
|
|
1749
|
+
if (uri !== void 0) {
|
|
1750
|
+
return uri;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
uri = this.ns[prefix];
|
|
1754
|
+
if (uri !== void 0) {
|
|
1755
|
+
return uri;
|
|
1756
|
+
}
|
|
1757
|
+
return (_b = (_a = this.opt).resolvePrefix) === null || _b === void 0 ? void 0 : _b.call(_a, prefix);
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Parse a qname into its prefix and local name parts.
|
|
1761
|
+
*
|
|
1762
|
+
* @param name The name to parse
|
|
1763
|
+
*
|
|
1764
|
+
* @returns
|
|
1765
|
+
*/
|
|
1766
|
+
qname(name) {
|
|
1767
|
+
const colon = name.indexOf(":");
|
|
1768
|
+
if (colon === -1) {
|
|
1769
|
+
return { prefix: "", local: name };
|
|
1770
|
+
}
|
|
1771
|
+
const local = name.slice(colon + 1);
|
|
1772
|
+
const prefix = name.slice(0, colon);
|
|
1773
|
+
if (prefix === "" || local === "" || local.includes(":")) {
|
|
1774
|
+
this.fail(`malformed name: ${name}.`);
|
|
1775
|
+
}
|
|
1776
|
+
return { prefix, local };
|
|
1777
|
+
}
|
|
1778
|
+
processAttribsNS() {
|
|
1779
|
+
var _a;
|
|
1780
|
+
const { attribList } = this;
|
|
1781
|
+
const tag = this.tag;
|
|
1782
|
+
{
|
|
1783
|
+
const { prefix, local } = this.qname(tag.name);
|
|
1784
|
+
tag.prefix = prefix;
|
|
1785
|
+
tag.local = local;
|
|
1786
|
+
const uri = tag.uri = (_a = this.resolve(prefix)) !== null && _a !== void 0 ? _a : "";
|
|
1787
|
+
if (prefix !== "") {
|
|
1788
|
+
if (prefix === "xmlns") {
|
|
1789
|
+
this.fail('tags may not have "xmlns" as prefix.');
|
|
1790
|
+
}
|
|
1791
|
+
if (uri === "") {
|
|
1792
|
+
this.fail(`unbound namespace prefix: ${JSON.stringify(prefix)}.`);
|
|
1793
|
+
tag.uri = prefix;
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
if (attribList.length === 0) {
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
const { attributes } = tag;
|
|
1801
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1802
|
+
for (const attr of attribList) {
|
|
1803
|
+
const { name, prefix, local } = attr;
|
|
1804
|
+
let uri;
|
|
1805
|
+
let eqname;
|
|
1806
|
+
if (prefix === "") {
|
|
1807
|
+
uri = name === "xmlns" ? XMLNS_NAMESPACE : "";
|
|
1808
|
+
eqname = name;
|
|
1809
|
+
} else {
|
|
1810
|
+
uri = this.resolve(prefix);
|
|
1811
|
+
if (uri === void 0) {
|
|
1812
|
+
this.fail(`unbound namespace prefix: ${JSON.stringify(prefix)}.`);
|
|
1813
|
+
uri = prefix;
|
|
1814
|
+
}
|
|
1815
|
+
eqname = `{${uri}}${local}`;
|
|
1816
|
+
}
|
|
1817
|
+
if (seen.has(eqname)) {
|
|
1818
|
+
this.fail(`duplicate attribute: ${eqname}.`);
|
|
1819
|
+
}
|
|
1820
|
+
seen.add(eqname);
|
|
1821
|
+
attr.uri = uri;
|
|
1822
|
+
attributes[name] = attr;
|
|
1823
|
+
}
|
|
1824
|
+
this.attribList = [];
|
|
1825
|
+
}
|
|
1826
|
+
processAttribsPlain() {
|
|
1827
|
+
const { attribList } = this;
|
|
1828
|
+
const attributes = this.tag.attributes;
|
|
1829
|
+
for (const { name, value } of attribList) {
|
|
1830
|
+
if (attributes[name] !== void 0) {
|
|
1831
|
+
this.fail(`duplicate attribute: ${name}.`);
|
|
1832
|
+
}
|
|
1833
|
+
attributes[name] = value;
|
|
1834
|
+
}
|
|
1835
|
+
this.attribList = [];
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Handle a complete open tag. This parser code calls this once it has seen
|
|
1839
|
+
* the whole tag. This method checks for well-formeness and then emits
|
|
1840
|
+
* ``onopentag``.
|
|
1841
|
+
*/
|
|
1842
|
+
openTag() {
|
|
1843
|
+
var _a;
|
|
1844
|
+
this.processAttribs();
|
|
1845
|
+
const { tags } = this;
|
|
1846
|
+
const tag = this.tag;
|
|
1847
|
+
tag.isSelfClosing = false;
|
|
1848
|
+
(_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
|
|
1849
|
+
tags.push(tag);
|
|
1850
|
+
this.state = S_TEXT;
|
|
1851
|
+
this.name = "";
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Handle a complete self-closing tag. This parser code calls this once it has
|
|
1855
|
+
* seen the whole tag. This method checks for well-formeness and then emits
|
|
1856
|
+
* ``onopentag`` and ``onclosetag``.
|
|
1857
|
+
*/
|
|
1858
|
+
openSelfClosingTag() {
|
|
1859
|
+
var _a, _b, _c;
|
|
1860
|
+
this.processAttribs();
|
|
1861
|
+
const { tags } = this;
|
|
1862
|
+
const tag = this.tag;
|
|
1863
|
+
tag.isSelfClosing = true;
|
|
1864
|
+
(_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
|
|
1865
|
+
(_b = this.closeTagHandler) === null || _b === void 0 ? void 0 : _b.call(this, tag);
|
|
1866
|
+
const top = this.tag = (_c = tags[tags.length - 1]) !== null && _c !== void 0 ? _c : null;
|
|
1867
|
+
if (top === null) {
|
|
1868
|
+
this.closedRoot = true;
|
|
1869
|
+
}
|
|
1870
|
+
this.state = S_TEXT;
|
|
1871
|
+
this.name = "";
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Handle a complete close tag. This parser code calls this once it has seen
|
|
1875
|
+
* the whole tag. This method checks for well-formeness and then emits
|
|
1876
|
+
* ``onclosetag``.
|
|
1877
|
+
*/
|
|
1878
|
+
closeTag() {
|
|
1879
|
+
const { tags, name } = this;
|
|
1880
|
+
this.state = S_TEXT;
|
|
1881
|
+
this.name = "";
|
|
1882
|
+
if (name === "") {
|
|
1883
|
+
this.fail("weird empty close tag.");
|
|
1884
|
+
this.text += "</>";
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const handler = this.closeTagHandler;
|
|
1888
|
+
let l = tags.length;
|
|
1889
|
+
while (l-- > 0) {
|
|
1890
|
+
const tag = this.tag = tags.pop();
|
|
1891
|
+
this.topNS = tag.ns;
|
|
1892
|
+
handler === null || handler === void 0 ? void 0 : handler(tag);
|
|
1893
|
+
if (tag.name === name) {
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
this.fail("unexpected close tag.");
|
|
1897
|
+
}
|
|
1898
|
+
if (l === 0) {
|
|
1899
|
+
this.closedRoot = true;
|
|
1900
|
+
} else if (l < 0) {
|
|
1901
|
+
this.fail(`unmatched closing tag: ${name}.`);
|
|
1902
|
+
this.text += `</${name}>`;
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* Resolves an entity. Makes any necessary well-formedness checks.
|
|
1907
|
+
*
|
|
1908
|
+
* @param entity The entity to resolve.
|
|
1909
|
+
*
|
|
1910
|
+
* @returns The parsed entity.
|
|
1911
|
+
*/
|
|
1912
|
+
parseEntity(entity) {
|
|
1913
|
+
if (entity[0] !== "#") {
|
|
1914
|
+
const defined = this.ENTITIES[entity];
|
|
1915
|
+
if (defined !== void 0) {
|
|
1916
|
+
return defined;
|
|
1917
|
+
}
|
|
1918
|
+
this.fail(this.isName(entity) ? "undefined entity." : "disallowed character in entity name.");
|
|
1919
|
+
return `&${entity};`;
|
|
1920
|
+
}
|
|
1921
|
+
let num = NaN;
|
|
1922
|
+
if (entity[1] === "x" && /^#x[0-9a-f]+$/i.test(entity)) {
|
|
1923
|
+
num = parseInt(entity.slice(2), 16);
|
|
1924
|
+
} else if (/^#[0-9]+$/.test(entity)) {
|
|
1925
|
+
num = parseInt(entity.slice(1), 10);
|
|
1926
|
+
}
|
|
1927
|
+
if (!this.isChar(num)) {
|
|
1928
|
+
this.fail("malformed character entity.");
|
|
1929
|
+
return `&${entity};`;
|
|
1930
|
+
}
|
|
1931
|
+
return String.fromCodePoint(num);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
exports.SaxesParser = SaxesParser;
|