Expansion /expand
/expand expands supported templates and pure wikitext parser functions before parsing. It loads the parser but not React. Expansion is asynchronous.
Signature
Resolver
null/undefinedmeans the template is missing; an empty string is a valid template.- A title is parsed once per expansion; the same
titlemust return stable source. callerTitleis context only and does not participate in the cache key.invocationpoints at the top-level call range inoriginal.source; nested requests reuse that range.- The resolver performs remote fetching; the library makes no network requests.
Result
originalis the parse snapshot of the original source.documentis the parse snapshot of the expanded source and can be passed directly toprepareWikitext.status:complete: all calls expanded.partial: some calls were preserved or dependencies were unresolved.fallback: the final source failed to parse, so the original snapshot was returned.
expansion.diagnosticscoordinates are based onoriginal.source;document.diagnosticsmerges final parse diagnostics and mapped expansion diagnostics.
What is expanded
Supported: template transclusion and parameters, include tags, #if, #ifeq, #switch, #iferror, {{!}}, {{=}}, and implicit newlines.
Preserved with diagnostics by default:
#invokeand Lua.- Transclusion modifiers such as
subst. - Functions that depend on site state or an external runtime, such as
#ifexistand#time.
See the template expansion guide for details.
Budgets and failures
- A single over-long call is preserved with
LENGTH_BUDGET_EXCEEDED. - If even the preserved source exceeds
maxExpandedLength, the call throwsEXPANSION_TOO_LARGE. - With
strict: true, a budget overrun throwsEXPANSION_BUDGET_EXCEEDED. - By default, a final parse failure returns the original valid snapshot with
status: "fallback". - Cancellation rejects with
WikitextExpandErrorcodeABORTED; the original reason is stored incause.
parseOptions.maxSourceLength, template source length, and maxExpandedLength apply separately. Final parsing uses the effective maxExpandedLength.
Errors
Common codes:
With the view
The expanded document is already parsed; do not parse it again. Calls preserved after a failed expansion still render as template, function, or argument placeholders.