@lexical/compiler/SchemaJsonCodegen
Classes
NotCompilable
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:115
A schema whose domain cannot be expressed as straight-line code, or a compiled expression that turned out to disagree with it.
Extends
Error
Constructors
Constructor
new NotCompilable(
message?):NotCompilable
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1080
Parameters
message?
string
Returns
Inherited from
Error.constructor
Constructor
new NotCompilable(
message?,options?):NotCompilable
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1080
Parameters
message?
string
options?
ErrorOptions
Returns
Inherited from
Error.constructor
Properties
cause?
optionalcause?:unknown
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
Inherited from
Error.cause
message
message:
string
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
Inherited from
Error.message
name
name:
string
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
Inherited from
Error.name
stack?
optionalstack?:string
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
Inherited from
Error.stack
stackTraceLimit
staticstackTraceLimit:number
Defined in: node_modules/.pnpm/@types+node@26.4.1/node_modules/@types/node/globals.d.ts:67
The Error.stackTraceLimit property specifies the number of stack frames
collected by a stack trace (whether generated by new Error().stack or
Error.captureStackTrace(obj)).
The default value is 10 but may be set to any valid JavaScript number. Changes
will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Inherited from
Error.stackTraceLimit
Methods
captureStackTrace()
staticcaptureStackTrace(targetObject,constructorOpt?):void
Defined in: node_modules/.pnpm/@types+node@26.4.1/node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`
The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames
above constructorOpt, including constructorOpt, will be omitted from the
generated stack trace.
The constructorOpt argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
Parameters
targetObject
object
constructorOpt?
Function
Returns
void
Inherited from
Error.captureStackTrace
isError()
staticisError(error):error is Error
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.error.d.ts:21
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
error
unknown
Returns
error is Error
Inherited from
Error.isError
prepareStackTrace()
staticprepareStackTrace(err,stackTraces):any
Defined in: node_modules/.pnpm/@types+node@26.4.1/node_modules/@types/node/globals.d.ts:55
Parameters
err
Error
stackTraces
CallSite[]
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTrace
Interfaces
CompiledExpression
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:45
An expression, with whatever has to be bound before it is evaluated.
Extended by
Properties
expression
expression:
string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:47
A JavaScript expression over v that parses exactly as the schema does.
statements
statements:
string[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:57
Statements the caller emits before the expression, in the same scope.
A collapsing wrapper (optional({omitDefault}),
nullable({defaultAsNull})) compares the parsed value against the inner
default and then returns it, so it names the parse once here rather than
writing it into the expression twice. Empty for every other kind, which is
why the emitted code is otherwise unchanged.
CompileParseResult
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:60
An expression, with whatever has to be bound before it is evaluated.
Extends
Properties
expression
expression:
string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:47
A JavaScript expression over v that parses exactly as the schema does.
Inherited from
helpers
helpers:
string[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:79
The numeric helpers the expression calls, by name, sorted — a subset of
num, numC and numK, whose sources are NUM_HELPER_SOURCE,
NUM_RANGE_HELPER_SOURCE and NUM_CLAMP_HELPER_SOURCE. The
caller emits their definitions, so it has to know which ones to emit, and
only what compiled the expression knows for certain: reading the answer
back off the emitted text cannot tell a call from a property named num
(json.num, or {num: ...} in the exporter beside it).
numC and numK call num, which is a fact about the sources rather
than about this expression: what is listed here is what the expression
itself calls.
statements
statements:
string[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:57
Statements the caller emits before the expression, in the same scope.
A collapsing wrapper (optional({omitDefault}),
nullable({defaultAsNull})) compares the parsed value against the inner
default and then returns it, so it names the parse once here rather than
writing it into the expression twice. Empty for every other kind, which is
why the emitted code is otherwise unchanged.
Inherited from
tables
tables:
SchemaJsonTable[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:65
The lookup tables the expression refers to. The caller decides where they live; a table an untrusted key reaches must be given a null prototype.
SchemaJsonTable
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:39
A lookup table a compiled expression refers to by name.
Properties
name
name:
string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:40
table
table:
object
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:41
Index Signature
[key: string]: unknown
VerifyCompiledParseOptions
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:82
Properties
expression
expression:
string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:86
A compiled expression over v, usually from compileParse.
nullPrototypeTables?
optionalnullPrototypeTables?: readonlystring[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:101
Which of the tables an untrusted key can reach, and so must not inherit
from Object.prototype. Verified by running the hostile keys in
verificationCorpus through the expression.
schema
schema:
AnySerializationSchema
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:84
The real schema, called for the expected value.
statements?
optionalstatements?: readonlystring[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:93
The statements that expression was compiled with, which are run before it here exactly as the generated code runs them. Omitting them where the compile produced some would evaluate an unbound name, so this is not a check that can quietly pass against the wrong thing.
tables
tables: readonly
SchemaJsonTable[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:95
The tables the expression refers to.
valueName?
optionalvalueName?:string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:108
The variable the expression reads the serialized value from — whatever was
passed to compileParse as valueName, v by default. It is the
parameter the expression is evaluated with here, so an expression compiled
against another name reads an unbound one without it.
Type Aliases
BindingNaming
BindingNaming = () =>
string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:303
How compileParse names a local it binds; see CompiledExpression.statements.
A callback rather than a prefix, because the scope these are emitted into is the caller's: a generated parser applies every property of a class in one function, so two properties that each bind one need two names, and only the caller knows how many have gone before. The default numbers them from zero, which suits a caller compiling one expression on its own.
Returns
string
TableNaming
TableNaming =
string| ((table,index) =>string)
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:289
How compileParse names the tables an expression reads.
Variables
JSON_NUMBER_SOURCE
constJSON_NUMBER_SOURCE: "/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/" = '/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/'
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:123
The JSON number grammar, anchored, as source text — matching numberValue's
treatment of a stringified number. Kept as one string so an emitted module
and the verification here are the same regexp rather than two copies that
could drift.
NUM_CLAMP_HELPER_SOURCE
constNUM_CLAMP_HELPER_SOURCE:string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:182
The numK helper, emitted alongside num when a domain clamps.
NUM_HELPER_SOURCE
constNUM_HELPER_SOURCE:string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:176
The num helper as TypeScript source, for a module that emits a compiled
parse. The verification evaluates the same body, so the emitted helper and
the checked one cannot be different functions.
NUM_RANGE_HELPER_SOURCE
constNUM_RANGE_HELPER_SOURCE:string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:179
The numC helper, emitted alongside num when a domain is constrained.
Functions
compileDiffersFromDefault()
compileDiffersFromDefault(
schema,name):string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:976
A JavaScript expression over the variable name, true exactly when a value
of schema is not its default — the negation of the walk's
value === defaultValue || isEqual(value, defaultValue), which is what the
compact form tests before writing a property, and what a property gated by a
predicate tests before calling it.
A primitive default compares against its literal. A reference-typed default
has no literal a value could be ===; the walk compares those through the
schema's own equality, and the one such equality this can restate from the
default alone is arrayValue's against an empty array, which reduces to a
length test. Anything else — an object, a non-empty array, a non-finite
number — throws NotCompilable. Like a compiled parse, the result is
a claim about the schema, not a fact about it: run it through
verifyDiffersFromDefault before emitting it.
Parameters
schema
the property's schema
name
string
the variable holding the value
Returns
string
compileParse()
compileParse(
meta,defaultValue,tableBaseName,bindingName?,valueName?):CompileParseResult
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:266
A JavaScript expression over v that parses exactly as meta's schema does,
with any lookup tables it needs.
Only the kinds whose meta fully determines the parse are compiled; the rest
throw NotCompilable. A transformValue post-processes what its meta
describes and keeps the function to itself, so its meta is indistinguishable
from its inner schema's — compiling one yields an expression that stores the
un-transformed value, and no inspection of the meta can tell. That is what
verifyCompiledParse is for: compiling is not trusting.
Any lookup table the expression needs is returned with it rather than registered somewhere: the caller decides where tables live, and a compile that throws leaves nothing behind.
Parameters
meta
the schema's introspectable description
defaultValue
unknown
the schema's own default, i.e. schema(undefined)
tableBaseName
how to name a lookup table the expression needs: a prefix, or a callback given the table and its index. The callback is what lets a caller share one emitted table between the schemas that use the same object — the name has to be settled before it is written into the expression, so this cannot be done afterwards.
bindingName?
how to name a local the expression binds; see BindingNaming.
valueName?
string = 'v'
the variable the expression reads the serialized value
from, v by default. A caller emitting one parse per property of a node
names it for the property, so the emitted code reads like the exporter
beside it rather than reassigning one scratch variable per property.
Returns
literal()
literal(
value):string
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:233
A JavaScript literal denoting value, or the token undefined. Faithful
only for the primitives JSON round-trips — which is exactly what a caller
emitting a comparison against it must check first.
Parameters
value
unknown
Returns
string
verificationCorpus()
verificationCorpus(
meta):unknown[]
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:626
The values a compiled parse is checked against: whatever the schema itself
names — every enum member, both sides of every alias — plus the shapes
untrusted JSON actually arrives in, Object.prototype member names
included. Fixed rather than sampled, so a generator using it produces
byte-reproducible output.
Parameters
meta
Returns
unknown[]
verifyCompiledParse()
verifyCompiledParse(
__namedParameters):void
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:762
Parameters
__namedParameters
Returns
void
verifyDiffersFromDefault()
verifyDiffersFromDefault(
__namedParameters):void
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:1046
Run a compileDiffersFromDefault expression against the schema's own
rule — value === defaultValue || isEqual(value, defaultValue), negated —
and throw NotCompilable naming the first value they disagree on.
The values are verificationCorpus plus the default itself, a copy of
it (which is === to nothing the schema holds), and the array and object
shapes a structural comparison could confuse.
This samples; it does not prove. It catches an expression that is wrong about
a value the schema itself names — an enum member, an alias, the default's own
shape — which is what a mistake in the emitted comparison looks like. It
cannot catch an expression that is wrong only about values nobody listed,
which is what an arbitrary isEqual produces, so
compileDiffersFromDefault refuses to emit against one rather than
bring it here.
Parameters
__namedParameters
expression
string
name
string
schema
Returns
void
verifyTableCoversDomain()
verifyTableCoversDomain(
__namedParameters):void
Defined in: packages/lexical-compiler/src/SchemaJsonCodegen.ts:894
Prove a lookup table maps every value schema can produce, and — for an
enum, where the domain is decidable — nothing else.
A generated parse that ends in a table lookup emits a fallback for the key that is not there, because the emitted TypeScript needs one. That fallback is only ever right if it is unreachable: a domain member missing from the table would otherwise be stored as whatever the default encodes to, silently turning one value into another. So the table has to be total, and this is where that is established rather than assumed.
Parameters
__namedParameters
schema
table
{[key: string]: unknown; }
Returns
void