@temelj/mdx 0.13.0 → 0.15.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/README.md +468 -82
- package/dist/character-entities.d.mts +4 -0
- package/dist/character-entities.d.mts.map +1 -0
- package/dist/character-entities.mjs +2132 -0
- package/dist/character-entities.mjs.map +1 -0
- package/dist/character-reference.d.mts +6 -0
- package/dist/character-reference.d.mts.map +1 -0
- package/dist/character-reference.mjs +18 -0
- package/dist/character-reference.mjs.map +1 -0
- package/dist/compile-analysis.d.mts +28 -0
- package/dist/compile-analysis.d.mts.map +1 -0
- package/dist/compile-analysis.mjs +74 -0
- package/dist/compile-analysis.mjs.map +1 -0
- package/dist/compile-emit.d.mts +9 -0
- package/dist/compile-emit.d.mts.map +1 -0
- package/dist/compile-emit.mjs +187 -0
- package/dist/compile-emit.mjs.map +1 -0
- package/dist/compile-esm.d.mts +34 -0
- package/dist/compile-esm.d.mts.map +1 -0
- package/dist/compile-esm.mjs +187 -0
- package/dist/compile-esm.mjs.map +1 -0
- package/dist/compile-names.d.mts +13 -0
- package/dist/compile-names.d.mts.map +1 -0
- package/dist/compile-names.mjs +32 -0
- package/dist/compile-names.mjs.map +1 -0
- package/dist/compiler.d.mts +69 -85
- package/dist/compiler.d.mts.map +1 -1
- package/dist/compiler.mjs +185 -418
- package/dist/compiler.mjs.map +1 -1
- package/dist/diagnostics.d.mts +37 -0
- package/dist/diagnostics.d.mts.map +1 -0
- package/dist/diagnostics.mjs +57 -0
- package/dist/diagnostics.mjs.map +1 -0
- package/dist/errors.d.mts +157 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +263 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/footnote-numbering.d.mts +27 -0
- package/dist/footnote-numbering.d.mts.map +1 -0
- package/dist/footnote-numbering.mjs +49 -0
- package/dist/footnote-numbering.mjs.map +1 -0
- package/dist/format-context.d.mts +46 -0
- package/dist/format-context.d.mts.map +1 -0
- package/dist/format-context.mjs +26 -0
- package/dist/format-context.mjs.map +1 -0
- package/dist/format-directive.d.mts +9 -0
- package/dist/format-directive.d.mts.map +1 -0
- package/dist/format-directive.mjs +99 -0
- package/dist/format-directive.mjs.map +1 -0
- package/dist/format-jsx.d.mts +8 -0
- package/dist/format-jsx.d.mts.map +1 -0
- package/dist/format-jsx.mjs +47 -0
- package/dist/format-jsx.mjs.map +1 -0
- package/dist/format-math.d.mts +9 -0
- package/dist/format-math.d.mts.map +1 -0
- package/dist/format-math.mjs +79 -0
- package/dist/format-math.mjs.map +1 -0
- package/dist/format-safe.d.mts +25 -0
- package/dist/format-safe.d.mts.map +1 -0
- package/dist/format-safe.mjs +366 -0
- package/dist/format-safe.mjs.map +1 -0
- package/dist/format-table.d.mts +8 -0
- package/dist/format-table.d.mts.map +1 -0
- package/dist/format-table.mjs +55 -0
- package/dist/format-table.mjs.map +1 -0
- package/dist/format-track.d.mts +18 -0
- package/dist/format-track.d.mts.map +1 -0
- package/dist/format-track.mjs +34 -0
- package/dist/format-track.mjs.map +1 -0
- package/dist/format.d.mts +7 -0
- package/dist/format.d.mts.map +1 -0
- package/dist/format.mjs +549 -0
- package/dist/format.mjs.map +1 -0
- package/dist/frontmatter.d.mts +15 -0
- package/dist/frontmatter.d.mts.map +1 -0
- package/dist/frontmatter.mjs +187 -0
- package/dist/frontmatter.mjs.map +1 -0
- package/dist/heading.d.mts +6 -0
- package/dist/heading.d.mts.map +1 -0
- package/dist/heading.mjs +19 -0
- package/dist/heading.mjs.map +1 -0
- package/dist/html-format.d.mts +32 -0
- package/dist/html-format.d.mts.map +1 -0
- package/dist/html-format.mjs +127 -0
- package/dist/html-format.mjs.map +1 -0
- package/dist/html-lower.d.mts +78 -0
- package/dist/html-lower.d.mts.map +1 -0
- package/dist/html-lower.mjs +583 -0
- package/dist/html-lower.mjs.map +1 -0
- package/dist/html-stream.d.mts +13 -0
- package/dist/html-stream.d.mts.map +1 -0
- package/dist/html-stream.mjs +32 -0
- package/dist/html-stream.mjs.map +1 -0
- package/dist/html.d.mts +120 -0
- package/dist/html.d.mts.map +1 -0
- package/dist/html.mjs +77 -0
- package/dist/html.mjs.map +1 -0
- package/dist/identifier.d.mts +4 -0
- package/dist/identifier.d.mts.map +1 -0
- package/dist/identifier.mjs +8 -0
- package/dist/identifier.mjs.map +1 -0
- package/dist/javascript-ast.d.mts +16 -0
- package/dist/javascript-ast.d.mts.map +1 -0
- package/dist/javascript-ast.mjs +39 -0
- package/dist/javascript-ast.mjs.map +1 -0
- package/dist/javascript-jsx.d.mts +24 -0
- package/dist/javascript-jsx.d.mts.map +1 -0
- package/dist/javascript-jsx.mjs +189 -0
- package/dist/javascript-jsx.mjs.map +1 -0
- package/dist/javascript.d.mts +9 -0
- package/dist/javascript.d.mts.map +1 -0
- package/dist/javascript.mjs +31 -0
- package/dist/javascript.mjs.map +1 -0
- package/dist/jsx-reference.d.mts +15 -0
- package/dist/jsx-reference.d.mts.map +1 -0
- package/dist/jsx-reference.mjs +31 -0
- package/dist/jsx-reference.mjs.map +1 -0
- package/dist/mod.d.mts +25 -8
- package/dist/mod.mjs +19 -7
- package/dist/model.d.mts +196 -0
- package/dist/model.d.mts.map +1 -0
- package/dist/model.mjs +113 -0
- package/dist/model.mjs.map +1 -0
- package/dist/parser/block-container-recognizers.d.mts +40 -0
- package/dist/parser/block-container-recognizers.d.mts.map +1 -0
- package/dist/parser/block-container-recognizers.mjs +90 -0
- package/dist/parser/block-container-recognizers.mjs.map +1 -0
- package/dist/parser/block-directive-recognizers.d.mts +22 -0
- package/dist/parser/block-directive-recognizers.d.mts.map +1 -0
- package/dist/parser/block-directive-recognizers.mjs +77 -0
- package/dist/parser/block-directive-recognizers.mjs.map +1 -0
- package/dist/parser/block-leaf-recognizers.d.mts +53 -0
- package/dist/parser/block-leaf-recognizers.d.mts.map +1 -0
- package/dist/parser/block-leaf-recognizers.mjs +386 -0
- package/dist/parser/block-leaf-recognizers.mjs.map +1 -0
- package/dist/parser/block-parser.d.mts +38 -0
- package/dist/parser/block-parser.d.mts.map +1 -0
- package/dist/parser/block-parser.mjs +895 -0
- package/dist/parser/block-parser.mjs.map +1 -0
- package/dist/parser/block-syntax.d.mts +240 -0
- package/dist/parser/block-syntax.d.mts.map +1 -0
- package/dist/parser/characters.d.mts +19 -0
- package/dist/parser/characters.d.mts.map +1 -0
- package/dist/parser/characters.mjs +52 -0
- package/dist/parser/characters.mjs.map +1 -0
- package/dist/parser/config.d.mts +16 -0
- package/dist/parser/config.d.mts.map +1 -0
- package/dist/parser/config.mjs +25 -0
- package/dist/parser/config.mjs.map +1 -0
- package/dist/parser/directive-attributes.d.mts +9 -0
- package/dist/parser/directive-attributes.d.mts.map +1 -0
- package/dist/parser/directive-attributes.mjs +24 -0
- package/dist/parser/directive-attributes.mjs.map +1 -0
- package/dist/parser/embedded-scanner.d.mts +18 -0
- package/dist/parser/embedded-scanner.d.mts.map +1 -0
- package/dist/parser/embedded-scanner.mjs +199 -0
- package/dist/parser/embedded-scanner.mjs.map +1 -0
- package/dist/parser/inline-autolink.d.mts +7 -0
- package/dist/parser/inline-autolink.d.mts.map +1 -0
- package/dist/parser/inline-autolink.mjs +42 -0
- package/dist/parser/inline-autolink.mjs.map +1 -0
- package/dist/parser/inline-character-reference.d.mts +7 -0
- package/dist/parser/inline-character-reference.d.mts.map +1 -0
- package/dist/parser/inline-character-reference.mjs +22 -0
- package/dist/parser/inline-character-reference.mjs.map +1 -0
- package/dist/parser/inline-code.d.mts +7 -0
- package/dist/parser/inline-code.d.mts.map +1 -0
- package/dist/parser/inline-code.mjs +29 -0
- package/dist/parser/inline-code.mjs.map +1 -0
- package/dist/parser/inline-directive.d.mts +9 -0
- package/dist/parser/inline-directive.d.mts.map +1 -0
- package/dist/parser/inline-directive.mjs +45 -0
- package/dist/parser/inline-directive.mjs.map +1 -0
- package/dist/parser/inline-embedded.d.mts +19 -0
- package/dist/parser/inline-embedded.d.mts.map +1 -0
- package/dist/parser/inline-embedded.mjs +92 -0
- package/dist/parser/inline-embedded.mjs.map +1 -0
- package/dist/parser/inline-emphasis.d.mts +11 -0
- package/dist/parser/inline-emphasis.d.mts.map +1 -0
- package/dist/parser/inline-emphasis.mjs +79 -0
- package/dist/parser/inline-emphasis.mjs.map +1 -0
- package/dist/parser/inline-input.d.mts +46 -0
- package/dist/parser/inline-input.d.mts.map +1 -0
- package/dist/parser/inline-input.mjs +137 -0
- package/dist/parser/inline-input.mjs.map +1 -0
- package/dist/parser/inline-link.d.mts +12 -0
- package/dist/parser/inline-link.d.mts.map +1 -0
- package/dist/parser/inline-link.mjs +187 -0
- package/dist/parser/inline-link.mjs.map +1 -0
- package/dist/parser/inline-math.d.mts +10 -0
- package/dist/parser/inline-math.d.mts.map +1 -0
- package/dist/parser/inline-math.mjs +46 -0
- package/dist/parser/inline-math.mjs.map +1 -0
- package/dist/parser/inline-output.d.mts +34 -0
- package/dist/parser/inline-output.d.mts.map +1 -0
- package/dist/parser/inline-output.mjs +62 -0
- package/dist/parser/inline-output.mjs.map +1 -0
- package/dist/parser/inline-parser.d.mts +14 -0
- package/dist/parser/inline-parser.d.mts.map +1 -0
- package/dist/parser/inline-parser.mjs +328 -0
- package/dist/parser/inline-parser.mjs.map +1 -0
- package/dist/parser/inline-pending.d.mts +23 -0
- package/dist/parser/inline-pending.d.mts.map +1 -0
- package/dist/parser/inline-pending.mjs +100 -0
- package/dist/parser/inline-pending.mjs.map +1 -0
- package/dist/parser/inline-syntax.d.mts +118 -0
- package/dist/parser/inline-syntax.d.mts.map +1 -0
- package/dist/parser/inline-syntax.mjs +1 -0
- package/dist/parser/javascript-boundary.d.mts +16 -0
- package/dist/parser/javascript-boundary.d.mts.map +1 -0
- package/dist/parser/javascript-boundary.mjs +42 -0
- package/dist/parser/javascript-boundary.mjs.map +1 -0
- package/dist/parser/javascript-scanner.d.mts +22 -0
- package/dist/parser/javascript-scanner.d.mts.map +1 -0
- package/dist/parser/javascript-scanner.mjs +122 -0
- package/dist/parser/javascript-scanner.mjs.map +1 -0
- package/dist/parser/materialize-cache.d.mts +34 -0
- package/dist/parser/materialize-cache.d.mts.map +1 -0
- package/dist/parser/materialize-cache.mjs +12 -0
- package/dist/parser/materialize-cache.mjs.map +1 -0
- package/dist/parser/materialize-jsx.d.mts +14 -0
- package/dist/parser/materialize-jsx.d.mts.map +1 -0
- package/dist/parser/materialize-jsx.mjs +76 -0
- package/dist/parser/materialize-jsx.mjs.map +1 -0
- package/dist/parser/materialize.d.mts +61 -0
- package/dist/parser/materialize.d.mts.map +1 -0
- package/dist/parser/materialize.mjs +736 -0
- package/dist/parser/materialize.mjs.map +1 -0
- package/dist/parser/recognizer.d.mts +20 -0
- package/dist/parser/recognizer.d.mts.map +1 -0
- package/dist/parser/recognizer.mjs +24 -0
- package/dist/parser/recognizer.mjs.map +1 -0
- package/dist/parser/session.d.mts +42 -0
- package/dist/parser/session.d.mts.map +1 -0
- package/dist/parser/session.mjs +89 -0
- package/dist/parser/session.mjs.map +1 -0
- package/dist/parser.d.mts +25 -0
- package/dist/parser.d.mts.map +1 -0
- package/dist/parser.mjs +37 -0
- package/dist/parser.mjs.map +1 -0
- package/dist/plugin-internal.d.mts +25 -0
- package/dist/plugin-internal.d.mts.map +1 -0
- package/dist/plugin-internal.mjs +99 -0
- package/dist/plugin-internal.mjs.map +1 -0
- package/dist/plugin.d.mts +37 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/plugin.mjs +1 -0
- package/dist/plugins/code-block-metadata.d.mts +42 -0
- package/dist/plugins/code-block-metadata.d.mts.map +1 -0
- package/dist/plugins/code-block-metadata.mjs +133 -0
- package/dist/plugins/code-block-metadata.mjs.map +1 -0
- package/dist/plugins/heading-id.d.mts +15 -0
- package/dist/plugins/heading-id.d.mts.map +1 -0
- package/dist/plugins/heading-id.mjs +45 -0
- package/dist/plugins/heading-id.mjs.map +1 -0
- package/dist/plugins/lower-heading.d.mts +16 -0
- package/dist/plugins/lower-heading.d.mts.map +1 -0
- package/dist/plugins/lower-heading.mjs +28 -0
- package/dist/plugins/lower-heading.mjs.map +1 -0
- package/dist/plugins/math-render.d.mts +26 -0
- package/dist/plugins/math-render.d.mts.map +1 -0
- package/dist/plugins/math-render.mjs +51 -0
- package/dist/plugins/math-render.mjs.map +1 -0
- package/dist/plugins/mod.d.mts +9 -5
- package/dist/plugins/mod.mjs +8 -5
- package/dist/plugins/remove-esm.d.mts +10 -0
- package/dist/plugins/remove-esm.d.mts.map +1 -0
- package/dist/plugins/remove-esm.mjs +12 -0
- package/dist/plugins/remove-esm.mjs.map +1 -0
- package/dist/plugins/shiki.d.mts +21 -0
- package/dist/plugins/shiki.d.mts.map +1 -0
- package/dist/plugins/shiki.mjs +144 -0
- package/dist/plugins/shiki.mjs.map +1 -0
- package/dist/plugins/syntax-highlight.d.mts +38 -0
- package/dist/plugins/syntax-highlight.d.mts.map +1 -0
- package/dist/plugins/syntax-highlight.mjs +106 -0
- package/dist/plugins/syntax-highlight.mjs.map +1 -0
- package/dist/processor.d.mts +60 -0
- package/dist/processor.d.mts.map +1 -0
- package/dist/processor.mjs +106 -0
- package/dist/processor.mjs.map +1 -0
- package/dist/ranges.d.mts +10 -0
- package/dist/ranges.d.mts.map +1 -0
- package/dist/ranges.mjs +22 -0
- package/dist/ranges.mjs.map +1 -0
- package/dist/source-map.d.mts +28 -0
- package/dist/source-map.d.mts.map +1 -0
- package/dist/source-map.mjs +90 -0
- package/dist/source-map.mjs.map +1 -0
- package/dist/source-text.d.mts +35 -0
- package/dist/source-text.d.mts.map +1 -0
- package/dist/source-text.mjs +132 -0
- package/dist/source-text.mjs.map +1 -0
- package/dist/source.d.mts +86 -0
- package/dist/source.d.mts.map +1 -0
- package/dist/source.mjs +264 -0
- package/dist/source.mjs.map +1 -0
- package/dist/stream-events.d.mts +59 -0
- package/dist/stream-events.d.mts.map +1 -0
- package/dist/stream-events.mjs +115 -0
- package/dist/stream-events.mjs.map +1 -0
- package/dist/stream-session.d.mts +79 -0
- package/dist/stream-session.d.mts.map +1 -0
- package/dist/stream-session.mjs +904 -0
- package/dist/stream-session.mjs.map +1 -0
- package/dist/stream-tail.d.mts +84 -0
- package/dist/stream-tail.d.mts.map +1 -0
- package/dist/stream-tail.mjs +359 -0
- package/dist/stream-tail.mjs.map +1 -0
- package/dist/stream-types.d.mts +89 -0
- package/dist/stream-types.d.mts.map +1 -0
- package/dist/stream-types.mjs +1 -0
- package/dist/stream.d.mts +28 -0
- package/dist/stream.d.mts.map +1 -0
- package/dist/stream.mjs +68 -0
- package/dist/stream.mjs.map +1 -0
- package/dist/syntax-options.d.mts +21 -0
- package/dist/syntax-options.d.mts.map +1 -0
- package/dist/syntax-options.mjs +26 -0
- package/dist/syntax-options.mjs.map +1 -0
- package/dist/traversal.d.mts +25 -0
- package/dist/traversal.d.mts.map +1 -0
- package/dist/traversal.mjs +136 -0
- package/dist/traversal.mjs.map +1 -0
- package/dist/tree.d.mts +18 -0
- package/dist/tree.d.mts.map +1 -0
- package/dist/tree.mjs +43 -0
- package/dist/tree.mjs.map +1 -0
- package/dist/unified/adapter.d.mts +24 -0
- package/dist/unified/adapter.d.mts.map +1 -0
- package/dist/unified/adapter.mjs +44 -0
- package/dist/unified/adapter.mjs.map +1 -0
- package/dist/unified/mod.d.mts +2 -0
- package/dist/unified/mod.mjs +1 -0
- package/dist/unified/runtime.d.mts +10 -0
- package/dist/unified/runtime.d.mts.map +1 -0
- package/dist/unified/runtime.mjs +115 -0
- package/dist/unified/runtime.mjs.map +1 -0
- package/dist/unified/tree-bridge.d.mts +63 -0
- package/dist/unified/tree-bridge.d.mts.map +1 -0
- package/dist/unified/tree-bridge.mjs +876 -0
- package/dist/unified/tree-bridge.mjs.map +1 -0
- package/dist/uri.d.mts +5 -0
- package/dist/uri.d.mts.map +1 -0
- package/dist/uri.mjs +32 -0
- package/dist/uri.mjs.map +1 -0
- package/package.json +56 -27
- package/dist/plugins/heading-id/plugin.d.mts +0 -17
- package/dist/plugins/heading-id/plugin.d.mts.map +0 -1
- package/dist/plugins/heading-id/plugin.mjs +0 -23
- package/dist/plugins/heading-id/plugin.mjs.map +0 -1
- package/dist/plugins/remove-imports-exports.d.mts +0 -10
- package/dist/plugins/remove-imports-exports.d.mts.map +0 -1
- package/dist/plugins/remove-imports-exports.mjs +0 -15
- package/dist/plugins/remove-imports-exports.mjs.map +0 -1
- package/dist/plugins/syntax-highlight/code-meta.d.mts +0 -22
- package/dist/plugins/syntax-highlight/code-meta.d.mts.map +0 -1
- package/dist/plugins/syntax-highlight/code-meta.mjs +0 -38
- package/dist/plugins/syntax-highlight/code-meta.mjs.map +0 -1
- package/dist/plugins/syntax-highlight/plugin.d.mts +0 -57
- package/dist/plugins/syntax-highlight/plugin.d.mts.map +0 -1
- package/dist/plugins/syntax-highlight/plugin.mjs +0 -93
- package/dist/plugins/syntax-highlight/plugin.mjs.map +0 -1
- package/dist/plugins/tree-processor/plugin.d.mts +0 -19
- package/dist/plugins/tree-processor/plugin.d.mts.map +0 -1
- package/dist/plugins/tree-processor/plugin.mjs +0 -21
- package/dist/plugins/tree-processor/plugin.mjs.map +0 -1
- package/dist/types.d.mts +0 -2
- /package/dist/{types.mjs → parser/block-syntax.mjs} +0 -0
package/dist/compiler.mjs
CHANGED
|
@@ -1,441 +1,208 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { createDiagnostic } from "./diagnostics.mjs";
|
|
2
|
+
import { CompileError, ConfigurationError, FrontmatterError, LimitError, MdxError } from "./errors.mjs";
|
|
3
|
+
import { javascriptPropertyName } from "./javascript-ast.mjs";
|
|
4
|
+
import { parseJavaScriptProgram } from "./javascript.mjs";
|
|
5
|
+
import { analyzeDocument } from "./compile-analysis.mjs";
|
|
6
|
+
import { contentUsesAwait, emitContent } from "./compile-emit.mjs";
|
|
7
|
+
import { documentFrontmatter } from "./model.mjs";
|
|
8
|
+
import { lowerHtml } from "./html-lower.mjs";
|
|
9
|
+
import { CodeWriter } from "./source-map.mjs";
|
|
10
|
+
import { isBigInt, isBoolean, isNumber, isObject, isString } from "@temelj/value";
|
|
7
11
|
//#region src/compiler.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
static create(reason, options = {}) {
|
|
47
|
-
return new MdxCompileError(reason, options, MdxCompileError.create);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* A reusable compiler for compiling MDX.
|
|
52
|
-
*/
|
|
53
|
-
var MdxCompiler = class {
|
|
54
|
-
mdxOptions;
|
|
55
|
-
remarkPlugins;
|
|
56
|
-
rehypePlugins;
|
|
57
|
-
constructor(mdxOptions = {}) {
|
|
58
|
-
this.mdxOptions = mdxOptions;
|
|
59
|
-
this.remarkPlugins = [remarkFrontmatterPlugin, remarkGfmPlugin];
|
|
60
|
-
this.rehypePlugins = [];
|
|
61
|
-
}
|
|
62
|
-
withRemarkPlugin(plugin, options) {
|
|
63
|
-
if (options === void 0) this.remarkPlugins.push(plugin);
|
|
64
|
-
else this.remarkPlugins.push([plugin, options]);
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
withRehypePlugin(plugin, options) {
|
|
68
|
-
if (options === void 0) this.rehypePlugins.push(plugin);
|
|
69
|
-
else this.rehypePlugins.push([plugin, options]);
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
async compile(source, { frontmatterOnly = false, mdxOptions } = {}, frontmatterSchema) {
|
|
73
|
-
const sourceText = toSourceText(source);
|
|
74
|
-
const vfile = new VFile({
|
|
75
|
-
value: source,
|
|
76
|
-
cwd: "/",
|
|
77
|
-
path: "/source.mdx"
|
|
12
|
+
const DEFAULT_MAXIMUM_GENERATED_CODE_BYTES = 10485760;
|
|
13
|
+
const DEFAULT_MAXIMUM_SOURCE_MAP_BYTES = 5242880;
|
|
14
|
+
/** Emits JavaScript for a strict document. Throws for configuration errors and compiler limits. */
|
|
15
|
+
function emitArtifact(document, options, frontmatter) {
|
|
16
|
+
try {
|
|
17
|
+
if (options.maximumGeneratedCodeBytes !== void 0 && (!Number.isSafeInteger(options.maximumGeneratedCodeBytes) || options.maximumGeneratedCodeBytes < 0)) throw ConfigurationError.invalidCompilerLimit("maximumGeneratedCodeBytes", options.maximumGeneratedCodeBytes);
|
|
18
|
+
if (options.maximumSourceMapBytes !== void 0 && (!Number.isSafeInteger(options.maximumSourceMapBytes) || options.maximumSourceMapBytes < 0)) throw ConfigurationError.invalidCompilerLimit("maximumSourceMapBytes", options.maximumSourceMapBytes);
|
|
19
|
+
const content = lowerHtml(document, options);
|
|
20
|
+
const analysis = analyzeDocument(document, content, options);
|
|
21
|
+
const usesAwait = contentUsesAwait(content);
|
|
22
|
+
const format = options.outputFormat ?? "functionBody";
|
|
23
|
+
const writer = new CodeWriter(options.source);
|
|
24
|
+
emitModulePreamble(writer, analysis, options, format);
|
|
25
|
+
emitContentFunction(writer, content, analysis, options, usesAwait);
|
|
26
|
+
emitPublicComponent(writer, analysis, options, usesAwait, format);
|
|
27
|
+
if (analysis.scope.missingReferences.size > 0) emitMissingReferenceHelper(writer, analysis);
|
|
28
|
+
if (format === "functionBody") writer.write(`return {${[...analysis.esm.exports, `default: ${analysis.scope.names.get("Content")}`].join(", ")}};\n}\n`);
|
|
29
|
+
const code = writer.toString();
|
|
30
|
+
enforceGeneratedCodeLimit(options.source, code, options.maximumGeneratedCodeBytes);
|
|
31
|
+
try {
|
|
32
|
+
parseJavaScriptProgram(format === "program" ? code : `async function __evaluateMdx(){\n${code}\n}`);
|
|
33
|
+
} catch (cause) {
|
|
34
|
+
throw CompileError.generatedProgramInvalid(cause);
|
|
35
|
+
}
|
|
36
|
+
const map = writer.sourceMap(analysis.scope.sourceName, options.outputName);
|
|
37
|
+
enforceSourceMapLimit(options.source, map, options.maximumSourceMapBytes);
|
|
38
|
+
return format === "program" ? Object.freeze({
|
|
39
|
+
format,
|
|
40
|
+
code,
|
|
41
|
+
map,
|
|
42
|
+
frontmatter
|
|
43
|
+
}) : Object.freeze({
|
|
44
|
+
format,
|
|
45
|
+
code,
|
|
46
|
+
map,
|
|
47
|
+
imports: Object.freeze(options.providerImportSource === void 0 || analysis.esm.imports.includes(options.providerImportSource) ? [...analysis.esm.imports] : [...analysis.esm.imports, options.providerImportSource]),
|
|
48
|
+
frontmatter
|
|
78
49
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
remarkPlugins,
|
|
98
|
-
rehypePlugins
|
|
99
|
-
})).value.toString();
|
|
100
|
-
} catch (error) {
|
|
101
|
-
throw toMdxCompileError(error, sourceContext, vfile.messages);
|
|
50
|
+
} catch (cause) {
|
|
51
|
+
if (cause instanceof MdxError) throw cause;
|
|
52
|
+
throw CompileError.generationFailed(cause);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function compile(input, options = {}) {
|
|
56
|
+
const frontmatterNode = documentFrontmatter(input.document);
|
|
57
|
+
let frontmatter = frontmatterNode?.data ?? Object.freeze({});
|
|
58
|
+
if (options.frontmatterSchema !== void 0) {
|
|
59
|
+
const validated = await options.frontmatterSchema["~standard"].validate(frontmatter);
|
|
60
|
+
if (validated.issues !== void 0) {
|
|
61
|
+
const diagnostics = validated.issues.map((issue) => createDiagnostic({
|
|
62
|
+
severity: "error",
|
|
63
|
+
code: "mdx.frontmatter.schema",
|
|
64
|
+
message: formatSchemaIssue(issue),
|
|
65
|
+
span: fileSpan(input.file, frontmatterNode?.origin)
|
|
66
|
+
}));
|
|
67
|
+
throw FrontmatterError.schemaValidationFailed(input.file, diagnostics, validated.issues);
|
|
102
68
|
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
compiled,
|
|
106
|
-
frontmatter,
|
|
107
|
-
messages: normalizeMessages(vfile.messages, sourceContext)
|
|
108
|
-
};
|
|
69
|
+
frontmatter = validated.value;
|
|
109
70
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return MdxCompileError.create(getErrorReason(error), {
|
|
115
|
-
source: getErrorField(error, "source"),
|
|
116
|
-
ruleId: getErrorField(error, "ruleId"),
|
|
117
|
-
line: details.line,
|
|
118
|
-
column: details.column,
|
|
119
|
-
place: details.place,
|
|
120
|
-
sourceLine: details.sourceLine,
|
|
121
|
-
snippet: details.snippet,
|
|
122
|
-
sourcePointer: details.sourcePointer,
|
|
123
|
-
hint: details.hint,
|
|
124
|
-
causeMessage: cause?.message,
|
|
125
|
-
diagnostics: normalizeMessages(diagnostics, sourceContext),
|
|
126
|
-
cause: error
|
|
71
|
+
const transported = copyTransportValue(frontmatter, "frontmatter", {
|
|
72
|
+
file: input.file,
|
|
73
|
+
origin: frontmatterNode?.origin,
|
|
74
|
+
ancestors: /* @__PURE__ */ new WeakSet()
|
|
127
75
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
source,
|
|
139
|
-
ruleId,
|
|
140
|
-
line: details.line,
|
|
141
|
-
column: details.column,
|
|
142
|
-
sourceLine: details.sourceLine,
|
|
143
|
-
snippet: details.snippet,
|
|
144
|
-
sourcePointer: details.sourcePointer,
|
|
145
|
-
hint: details.hint,
|
|
146
|
-
causeMessage: cause?.message
|
|
147
|
-
}),
|
|
148
|
-
reason,
|
|
149
|
-
source,
|
|
150
|
-
ruleId,
|
|
151
|
-
fatal: typeof message.fatal === "boolean" ? message.fatal : void 0,
|
|
152
|
-
line: details.line,
|
|
153
|
-
column: details.column,
|
|
154
|
-
place: details.place,
|
|
155
|
-
sourceLine: details.sourceLine,
|
|
156
|
-
snippet: details.snippet,
|
|
157
|
-
sourcePointer: details.sourcePointer,
|
|
158
|
-
hint: details.hint,
|
|
159
|
-
cause
|
|
160
|
-
};
|
|
76
|
+
const artifact = emitArtifact(input.document, {
|
|
77
|
+
...options,
|
|
78
|
+
source: input.file
|
|
79
|
+
}, transported);
|
|
80
|
+
return Object.freeze({
|
|
81
|
+
file: input.file,
|
|
82
|
+
document: input.document,
|
|
83
|
+
diagnostics: input.diagnostics,
|
|
84
|
+
artifact,
|
|
85
|
+
frontmatter
|
|
161
86
|
});
|
|
162
87
|
}
|
|
163
|
-
function
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
function getDiagnosticDetails(sourceContext, place, error) {
|
|
179
|
-
const compileLine = place?.start?.line ?? getErrorNumberField(error, "line");
|
|
180
|
-
let line = compileLine === void 0 ? void 0 : compileLine + sourceContext.lineOffset;
|
|
181
|
-
let column = place?.start?.column ?? getErrorNumberField(error, "column");
|
|
182
|
-
let normalizedPlace = mapPlaceToOriginalSource(place === void 0 && compileLine === void 0 && column === void 0 ? void 0 : {
|
|
183
|
-
start: {
|
|
184
|
-
line: compileLine,
|
|
185
|
-
column,
|
|
186
|
-
offset: place?.start?.offset
|
|
187
|
-
},
|
|
188
|
-
end: place?.end === void 0 ? void 0 : {
|
|
189
|
-
line: place.end.line,
|
|
190
|
-
column: place.end.column,
|
|
191
|
-
offset: place.end.offset
|
|
88
|
+
function formatSchemaIssue(issue) {
|
|
89
|
+
const path = issue.path?.map((part) => String(isObject(part) ? part.key : part)).join(".");
|
|
90
|
+
return path === void 0 || path.length === 0 ? issue.message : `${path}: ${issue.message}`;
|
|
91
|
+
}
|
|
92
|
+
function copyTransportValue(value, path, context) {
|
|
93
|
+
const { ancestors } = context;
|
|
94
|
+
if (value === null || isBoolean(value) || isNumber(value) || isBigInt(value) || isString(value)) return value;
|
|
95
|
+
if (!isObject(value)) throw FrontmatterError.nonTransportableValue(context.file, context.origin, `${path} contains unsupported ${Object.prototype.toString.call(value)}`);
|
|
96
|
+
if (ancestors.has(value)) throw FrontmatterError.nonTransportableValue(context.file, context.origin, `${path} contains a cycle`);
|
|
97
|
+
ancestors.add(value);
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
const output = [];
|
|
100
|
+
for (let index = 0; index < value.length; index++) {
|
|
101
|
+
const item = copyTransportValue(value[index], `${path}[${index}]`, context);
|
|
102
|
+
output.push(item);
|
|
192
103
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
let snippet = getSourceSnippet(sourceContext.originalSourceText, normalizedPlace);
|
|
196
|
-
let sourcePointer = getSourcePointer(column);
|
|
197
|
-
let hint;
|
|
198
|
-
const refinedExpressionContext = getMdxExpressionContext(sourceContext.originalSourceText, {
|
|
199
|
-
line,
|
|
200
|
-
column,
|
|
201
|
-
sourceLine,
|
|
202
|
-
snippet,
|
|
203
|
-
error
|
|
204
|
-
});
|
|
205
|
-
if (refinedExpressionContext !== void 0) {
|
|
206
|
-
line = refinedExpressionContext.line;
|
|
207
|
-
column = refinedExpressionContext.column;
|
|
208
|
-
sourceLine = refinedExpressionContext.sourceLine;
|
|
209
|
-
snippet = refinedExpressionContext.snippet;
|
|
210
|
-
sourcePointer = refinedExpressionContext.sourcePointer;
|
|
211
|
-
hint = refinedExpressionContext.hint;
|
|
212
|
-
normalizedPlace = {
|
|
213
|
-
start: {
|
|
214
|
-
line,
|
|
215
|
-
column,
|
|
216
|
-
offset: void 0
|
|
217
|
-
},
|
|
218
|
-
end: void 0
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
line,
|
|
223
|
-
column,
|
|
224
|
-
place: normalizedPlace,
|
|
225
|
-
sourceLine,
|
|
226
|
-
snippet,
|
|
227
|
-
sourcePointer,
|
|
228
|
-
hint
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function getMdxExpressionContext(sourceText, options) {
|
|
232
|
-
if (!shouldRefineMdxExpressionContext(options)) return;
|
|
233
|
-
const candidate = findSuspiciousBraceExpression(sourceText, options.line, options.column);
|
|
234
|
-
if (candidate === void 0) return;
|
|
235
|
-
return {
|
|
236
|
-
line: candidate.line,
|
|
237
|
-
column: candidate.column,
|
|
238
|
-
sourceLine: candidate.sourceLine,
|
|
239
|
-
snippet: candidate.snippet,
|
|
240
|
-
sourcePointer: getSourcePointer(candidate.column) ?? "^",
|
|
241
|
-
hint: getErrorCause(options.error)?.message === "Unexpected content after expression" ? "MDX treats `{...}` as JavaScript. If you meant literal braces in text, escape them or wrap the text in code." : void 0
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function shouldRefineMdxExpressionContext(options) {
|
|
245
|
-
const trimmedSourceLine = options.sourceLine?.trim();
|
|
246
|
-
return isMdxExpressionError(options.error) && getErrorCause(options.error)?.message === "Unexpected content after expression" && (options.sourceLine === void 0 || options.sourceLine.trim() === "" || options.snippet === void 0) && !(trimmedSourceLine?.startsWith("{") && trimmedSourceLine.endsWith("}"));
|
|
247
|
-
}
|
|
248
|
-
function getSourceLine(sourceText, line) {
|
|
249
|
-
if (line === void 0 || line < 1) return;
|
|
250
|
-
return sourceText.split(/\r?\n/u)[line - 1];
|
|
251
|
-
}
|
|
252
|
-
function getSourceSnippet(sourceText, place) {
|
|
253
|
-
if (place?.start?.offset !== void 0 && place.end?.offset !== void 0) return sourceText.slice(place.start.offset, place.end.offset) || void 0;
|
|
254
|
-
if (place?.start?.line === void 0 || place.start.column === void 0) return;
|
|
255
|
-
if (place.end === void 0) {
|
|
256
|
-
const line = sourceText.split(/\r?\n/u)[place.start.line - 1];
|
|
257
|
-
if (line === void 0) return;
|
|
258
|
-
const character = line.at(place.start.column - 1);
|
|
259
|
-
return character === void 0 || character.trim() === "" ? void 0 : character;
|
|
104
|
+
ancestors.delete(value);
|
|
105
|
+
return Object.freeze(output);
|
|
260
106
|
}
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
107
|
+
const prototype = Object.getPrototypeOf(value);
|
|
108
|
+
if (prototype !== Object.prototype && prototype !== null) throw FrontmatterError.nonTransportableValue(context.file, context.origin, `${path} contains a non-plain object`);
|
|
109
|
+
if (Object.getOwnPropertySymbols(value).length > 0) throw FrontmatterError.nonTransportableValue(context.file, context.origin, `${path} contains a symbol property`);
|
|
110
|
+
const output = {};
|
|
111
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
112
|
+
if (!descriptor.enumerable) continue;
|
|
113
|
+
if (!("value" in descriptor)) throw FrontmatterError.nonTransportableValue(context.file, context.origin, `${path}.${key} is an accessor property`);
|
|
114
|
+
const item = copyTransportValue(descriptor.value, `${path}.${key}`, context);
|
|
115
|
+
Object.defineProperty(output, key, {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
value: item
|
|
118
|
+
});
|
|
272
119
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return {
|
|
282
|
-
start: mapPointToOriginalSource(place.start, lineOffset),
|
|
283
|
-
end: mapPointToOriginalSource(place.end, lineOffset)
|
|
120
|
+
ancestors.delete(value);
|
|
121
|
+
return Object.freeze(output);
|
|
122
|
+
}
|
|
123
|
+
function fileSpan(file, range) {
|
|
124
|
+
return range === void 0 ? void 0 : {
|
|
125
|
+
file,
|
|
126
|
+
start: range.start,
|
|
127
|
+
end: range.end
|
|
284
128
|
};
|
|
285
129
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const sourceLine = lines[lineNumber - 1];
|
|
300
|
-
if (sourceLine === void 0 || sourceLine.trim() === "") continue;
|
|
301
|
-
const expression = findLineBraceExpression(sourceLine, lineNumber, column);
|
|
302
|
-
if (expression === void 0) continue;
|
|
303
|
-
const score = (line === void 0 ? 0 : Math.abs(lineNumber - line)) * 10 + expression.distance;
|
|
304
|
-
if (bestMatch === void 0 || score < bestMatch.score) bestMatch = {
|
|
305
|
-
...expression,
|
|
306
|
-
score
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
return bestMatch;
|
|
310
|
-
}
|
|
311
|
-
function getNearbyLineNumbers(line, totalLines, radius) {
|
|
312
|
-
if (line === void 0) return Array.from({ length: totalLines }, (_, index) => index + 1);
|
|
313
|
-
const lineNumbers = [];
|
|
314
|
-
for (let distance = 0; distance <= radius; distance++) {
|
|
315
|
-
const before = line - distance;
|
|
316
|
-
if (before >= 1) lineNumbers.push(before);
|
|
317
|
-
if (distance === 0) continue;
|
|
318
|
-
const after = line + distance;
|
|
319
|
-
if (after <= totalLines) lineNumbers.push(after);
|
|
320
|
-
}
|
|
321
|
-
return lineNumbers;
|
|
322
|
-
}
|
|
323
|
-
function findLineBraceExpression(sourceLine, line, column) {
|
|
324
|
-
let bestMatch;
|
|
325
|
-
for (const match of sourceLine.matchAll(/\{[^{}\n]+\}/gu)) {
|
|
326
|
-
const braceStart = match.index;
|
|
327
|
-
if (braceStart === void 0) continue;
|
|
328
|
-
const expanded = expandBraceExpression(sourceLine, braceStart);
|
|
329
|
-
if (expanded === void 0) continue;
|
|
330
|
-
const distance = column === void 0 ? 0 : Math.abs(braceStart + 1 - column);
|
|
331
|
-
if (bestMatch === void 0 || distance < bestMatch.distance) bestMatch = {
|
|
332
|
-
line,
|
|
333
|
-
column: braceStart + 1,
|
|
334
|
-
sourceLine,
|
|
335
|
-
snippet: expanded,
|
|
336
|
-
distance
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
return bestMatch;
|
|
340
|
-
}
|
|
341
|
-
function expandBraceExpression(sourceLine, braceStart) {
|
|
342
|
-
const braceEnd = sourceLine.indexOf("}", braceStart);
|
|
343
|
-
if (braceEnd === -1) return;
|
|
344
|
-
let start = braceStart;
|
|
345
|
-
while (start > 0 && /[A-Za-z0-9_]/u.test(sourceLine[start - 1])) start--;
|
|
346
|
-
let end = braceEnd + 1;
|
|
347
|
-
while (end < sourceLine.length) {
|
|
348
|
-
while (end < sourceLine.length && /[A-Za-z0-9_]/u.test(sourceLine[end])) end++;
|
|
349
|
-
if (sourceLine[end] !== "{") break;
|
|
350
|
-
const chainedEnd = sourceLine.indexOf("}", end);
|
|
351
|
-
if (chainedEnd === -1) break;
|
|
352
|
-
end = chainedEnd + 1;
|
|
130
|
+
/**
|
|
131
|
+
* Authored ESM, the JSX runtime, and the optional provider. A function body
|
|
132
|
+
* receives the runtime as `__mdxRuntime` and resolves imports through
|
|
133
|
+
* `__resolveMdxImport` instead of importing.
|
|
134
|
+
*/
|
|
135
|
+
function emitModulePreamble(writer, analysis, options, format) {
|
|
136
|
+
const names = analysis.scope.names;
|
|
137
|
+
const runtime = analysis.scope.development ? `{Fragment: ${names.get("_Fragment")}, jsxDEV: ${names.get("_jsxDEV")}}` : `{Fragment: ${names.get("_Fragment")}, jsx: ${names.get("_jsx")}, jsxs: ${names.get("_jsxs")}}`;
|
|
138
|
+
const importSource = `${options.jsxImportSource ?? "react"}/${analysis.scope.development ? "jsx-dev-runtime" : "jsx-runtime"}`;
|
|
139
|
+
writer.write(format === "program" ? `import ${runtime.replaceAll(": ", " as ")} from ${JSON.stringify(importSource)};\n` : `const ${runtime} = __mdxRuntime;\n`);
|
|
140
|
+
if (format === "functionBody") {
|
|
141
|
+
if (analysis.esm.imports.length > 0 || options.providerImportSource !== void 0) writer.write(`const ${names.get("_resolveMdxImport")} = __resolveMdxImport;\n`);
|
|
142
|
+
writer.write("{\n");
|
|
353
143
|
}
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
144
|
+
for (const entry of analysis.esm.blocks) writer.write(`${entry.code.trimEnd()}\n`, entry.origin);
|
|
145
|
+
if (options.providerImportSource !== void 0) writer.write(format === "program" ? `import {useMDXComponents as ${names.get("_provideComponents")}} from ${JSON.stringify(options.providerImportSource)};\n` : `const {useMDXComponents: ${names.get("_provideComponents")}} = await ${names.get("_resolveMdxImport")}(${JSON.stringify(options.providerImportSource)});\n`);
|
|
146
|
+
}
|
|
147
|
+
function emitContentFunction(writer, content, analysis, options, usesAwait) {
|
|
148
|
+
const names = analysis.scope.names;
|
|
149
|
+
const props = analysis.propsName;
|
|
150
|
+
const componentsName = names.get("_components");
|
|
151
|
+
writer.write(`${usesAwait ? "async " : ""}function ${names.get("_createContent")}(${props}) {\n`);
|
|
152
|
+
writer.write(` const ${componentsName} = {`);
|
|
153
|
+
const tags = [...analysis.intrinsicTags].sort();
|
|
154
|
+
tags.forEach((tag, index) => {
|
|
155
|
+
if (index > 0) writer.write(", ");
|
|
156
|
+
writer.write(`${javascriptPropertyName(tag)}:${JSON.stringify(tag)}`);
|
|
157
|
+
});
|
|
158
|
+
if (options.providerImportSource !== void 0) writer.write(`${tags.length === 0 ? "" : ", "}...${names.get("_provideComponents")}()`);
|
|
159
|
+
writer.write(`${tags.length === 0 && options.providerImportSource === void 0 ? "" : ", "}...${props}.components};\n`);
|
|
160
|
+
const components = [...analysis.scope.referencedComponents].sort();
|
|
161
|
+
for (const component of components) writer.write(` const ${component} = ${componentsName}[${JSON.stringify(component)}];\n`);
|
|
162
|
+
for (const [reference, component] of analysis.scope.missingReferences) writer.write(` if (!${reference}) ${names.get("_missingReference")}(${JSON.stringify(reference)}, ${component});\n`);
|
|
163
|
+
writer.write(" return ");
|
|
164
|
+
emitContent(writer, content, analysis);
|
|
165
|
+
writer.write(";\n}\n");
|
|
166
|
+
}
|
|
167
|
+
function emitPublicComponent(writer, analysis, options, usesAwait, format) {
|
|
168
|
+
const names = analysis.scope.names;
|
|
169
|
+
const props = analysis.propsName;
|
|
170
|
+
const layout = names.get("Layout");
|
|
171
|
+
writer.write(`${format === "program" ? "export default " : ""}${usesAwait ? "async " : ""}function ${names.get("Content")}(${props} = {}) {\n`);
|
|
172
|
+
const content = `${usesAwait ? "await " : ""}${names.get("_createContent")}(${props})`;
|
|
173
|
+
if (analysis.esm.hasLayout) writer.write(` return ${runtimeCall(analysis, layout, `{...${props}, children: ${content}}`)};\n`);
|
|
174
|
+
else {
|
|
175
|
+
writer.write(` const {wrapper: ${layout}} = {`);
|
|
176
|
+
if (options.providerImportSource !== void 0) writer.write(`...${names.get("_provideComponents")}(), `);
|
|
177
|
+
writer.write(`...${props}.components};\n`);
|
|
178
|
+
writer.write(` return ${layout} ? ${runtimeCall(analysis, layout, `{...${props}, children: ${content}}`)} : ${content};\n`);
|
|
376
179
|
}
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
function getErrorPlace(error) {
|
|
380
|
-
if (typeof error !== "object" || error === null) return;
|
|
381
|
-
const candidate = error;
|
|
382
|
-
return toPlace(candidate.place) ?? toPlace(candidate.position);
|
|
180
|
+
writer.write("}\n");
|
|
383
181
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
182
|
+
function emitMissingReferenceHelper(writer, analysis) {
|
|
183
|
+
const names = analysis.scope.names;
|
|
184
|
+
writer.write(`class ${names.get("ReferenceError")} extends Error {\n constructor(id, component) {
|
|
185
|
+
super(\`Expected \${component ? "component" : "object"} \${id} to be defined: you likely forgot to import, pass, or provide it.\`);
|
|
186
|
+
this.name = "ReferenceError";
|
|
187
|
+
}
|
|
386
188
|
}
|
|
387
|
-
function
|
|
388
|
-
|
|
389
|
-
const candidate = value;
|
|
390
|
-
if (candidate.start !== void 0 || candidate.end !== void 0) return {
|
|
391
|
-
start: toPoint(candidate.start),
|
|
392
|
-
end: toPoint(candidate.end)
|
|
393
|
-
};
|
|
394
|
-
const point = toPoint(candidate);
|
|
395
|
-
return point === void 0 ? void 0 : { start: point };
|
|
396
|
-
}
|
|
397
|
-
function toPoint(value) {
|
|
398
|
-
if (typeof value !== "object" || value === null) return;
|
|
399
|
-
const candidate = value;
|
|
400
|
-
const line = typeof candidate.line === "number" ? candidate.line : void 0;
|
|
401
|
-
const column = typeof candidate.column === "number" ? candidate.column : void 0;
|
|
402
|
-
const offset = typeof candidate.offset === "number" ? candidate.offset : void 0;
|
|
403
|
-
if (line === void 0 && column === void 0 && offset === void 0) return;
|
|
404
|
-
return {
|
|
405
|
-
line,
|
|
406
|
-
column,
|
|
407
|
-
offset
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
function getErrorReason(error) {
|
|
411
|
-
if (error instanceof Error && error.message !== "") return error.message;
|
|
412
|
-
const reason = getErrorField(error, "reason");
|
|
413
|
-
if (reason !== void 0 && reason !== "") return reason;
|
|
414
|
-
return String(error);
|
|
415
|
-
}
|
|
416
|
-
function getErrorCause(error) {
|
|
417
|
-
if (typeof error !== "object" || error === null || !("cause" in error)) return;
|
|
418
|
-
const cause = error.cause;
|
|
419
|
-
if (cause instanceof Error) return {
|
|
420
|
-
name: cause.name,
|
|
421
|
-
message: cause.message
|
|
422
|
-
};
|
|
423
|
-
if (typeof cause === "string" && cause !== "") return { message: cause };
|
|
189
|
+
function ${names.get("_missingReference")}(id, component) {\n throw new ${names.get("ReferenceError")}(id, component);\n}
|
|
190
|
+
`);
|
|
424
191
|
}
|
|
425
|
-
function
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
|
|
192
|
+
function enforceGeneratedCodeLimit(file, code, configuredMaximum) {
|
|
193
|
+
const maximum = configuredMaximum ?? DEFAULT_MAXIMUM_GENERATED_CODE_BYTES;
|
|
194
|
+
const actual = new TextEncoder().encode(code).byteLength;
|
|
195
|
+
if (actual > maximum) throw LimitError.exceeded(file, "maximumGeneratedCodeBytes", maximum, void 0, actual);
|
|
429
196
|
}
|
|
430
|
-
function
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
-
|
|
197
|
+
function enforceSourceMapLimit(file, map, configuredMaximum) {
|
|
198
|
+
const maximum = configuredMaximum ?? DEFAULT_MAXIMUM_SOURCE_MAP_BYTES;
|
|
199
|
+
const actual = new TextEncoder().encode(JSON.stringify(map)).byteLength;
|
|
200
|
+
if (actual > maximum) throw LimitError.exceeded(file, "maximumSourceMapBytes", maximum, void 0, actual);
|
|
434
201
|
}
|
|
435
|
-
function
|
|
436
|
-
return
|
|
202
|
+
function runtimeCall(analysis, tag, properties) {
|
|
203
|
+
return analysis.scope.development ? `${analysis.scope.names.get("_jsxDEV")}(${tag}, ${properties}, undefined, false, undefined, undefined)` : `${analysis.scope.names.get("_jsx")}(${tag}, ${properties})`;
|
|
437
204
|
}
|
|
438
205
|
//#endregion
|
|
439
|
-
export {
|
|
206
|
+
export { compile };
|
|
440
207
|
|
|
441
208
|
//# sourceMappingURL=compiler.mjs.map
|