@@ -9,23 +9,44 @@ import {
9
9
import { ParserPlugin } from '@babel/parser'
10
10
11
11
export interface ParserOptions {
12
- // e.g. platform native elements, e.g. <div> for browsers
12
+ /**
13
+ * e.g. platform native elements, e.g. <div> for browsers
14
+ */
13
15
isNativeTag ?: ( tag : string ) => boolean
14
- // e.g. native elements that can self-close, e.g. <img>, <br>, <hr>
16
+ /**
17
+ * e.g. native elements that can self-close, e.g. <img>, <br>, <hr>
18
+ */
15
19
isVoidTag ?: ( tag : string ) => boolean
16
- // e.g. elements that should preserve whitespace inside, e.g. <pre>
20
+ /**
21
+ * e.g. elements that should preserve whitespace inside, e.g. <pre>
22
+ */
17
23
isPreTag ?: ( tag : string ) => boolean
18
- // platform-specific built-in components e.g. <Transition>
24
+ /**
25
+ * Platform-specific built-in components e.g. <Transition>
26
+ */
19
27
isBuiltInComponent ?: ( tag : string ) => symbol | void
20
- // separate option for end users to extend the native elements list
28
+ /**
29
+ * Separate option for end users to extend the native elements list
30
+ */
21
31
isCustomElement ?: ( tag : string ) => boolean
32
+ /**
33
+ * Get tag namespace
34
+ */
22
35
getNamespace ?: ( tag : string , parent : ElementNode | undefined ) => Namespace
36
+ /**
37
+ * Get text parsing mode for this element
38
+ */
23
39
getTextMode ?: (
24
- tag : string ,
25
- ns : Namespace ,
40
+ node : ElementNode ,
26
41
parent : ElementNode | undefined
27
42
) => TextModes
28
- delimiters ?: [ string , string ] // ['{{', '}}']
43
+ /**
44
+ * @default ['{{', '}}']
45
+ */
46
+ delimiters ?: [ string , string ]
47
+ /**
48
+ * Only needed for DOM compilers
49
+ */
29
50
decodeEntities ?: ( rawText : string , asAttr : boolean ) => string
30
51
onError ?: ( error : CompilerError ) => void
31
52
}
@@ -36,64 +57,117 @@ export type HoistTransform = (
36
57
) => JSChildNode
37
58
38
59
export interface TransformOptions {
60
+ /**
61
+ * An array of node trasnforms to be applied to every AST node.
62
+ */
39
63
nodeTransforms ?: NodeTransform [ ]
64
+ /**
65
+ * An object of { name: transform } to be applied to every directive attribute
66
+ * node found on element nodes.
67
+ */
40
68
directiveTransforms ?: Record < string , DirectiveTransform | undefined >
41
- // an optional hook to transform a node being hoisted.
42
- // used by compiler-dom to turn hoisted nodes into stringified HTML vnodes.
69
+ /**
70
+ * An optional hook to transform a node being hoisted.
71
+ * used by compiler-dom to turn hoisted nodes into stringified HTML vnodes.
72
+ * @default null
73
+ */
43
74
transformHoist ?: HoistTransform | null
75
+ /**
76
+ * If the pairing runtime provides additional built-in elements, use this to
77
+ * mark them as built-in so the compiler will generate component vnodes
78
+ * for them.
79
+ */
44
80
isBuiltInComponent ?: ( tag : string ) => symbol | void
45
- // Transform expressions like {{ foo }} to `_ctx.foo`.
46
- // If this option is false, the generated code will be wrapped in a
47
- // `with (this) { ... }` block.
48
- // - This is force-enabled in module mode, since modules are by default strict
49
- // and cannot use `with`
50
- // - Default: mode === 'module'
81
+ /**
82
+ * Transform expressions like {{ foo }} to `_ctx.foo`.
83
+ * If this option is false, the generated code will be wrapped in a
84
+ * `with (this) { ... }` block.
85
+ * - This is force-enabled in module mode, since modules are by default strict
86
+ * and cannot use `with`
87
+ * @default mode === 'module'
88
+ */
51
89
prefixIdentifiers ?: boolean
52
- // Hoist static VNodes and props objects to `_hoisted_x` constants
53
- // - Default: false
90
+ /**
91
+ * Hoist static VNodes and props objects to `_hoisted_x` constants
92
+ * @default false
93
+ */
54
94
hoistStatic ?: boolean
55
- // Cache v-on handlers to avoid creating new inline functions on each render,
56
- // also avoids the need for dynamically patching the handlers by wrapping it.
57
- // e.g `@click="foo"` by default is compiled to `{ onClick: foo }`. With this
58
- // option it's compiled to:
59
- // `{ onClick: _cache[0] || (_cache[0] = e => _ctx.foo(e)) }`
60
- // - Requires "prefixIdentifiers" to be enabled because it relies on scope
61
- // analysis to determine if a handler is safe to cache.
62
- // - Default: false
95
+ /**
96
+ * Cache v-on handlers to avoid creating new inline functions on each render,
97
+ * also avoids the need for dynamically patching the handlers by wrapping it.
98
+ * e.g `@click="foo"` by default is compiled to `{ onClick: foo }`. With this
99
+ * option it's compiled to:
100
+ * ```js
101
+ * { onClick: _cache[0] || (_cache[0] = e => _ctx.foo(e)) }
102
+ * ```
103
+ * - Requires "prefixIdentifiers" to be enabled because it relies on scope
104
+ * analysis to determine if a handler is safe to cache.
105
+ * @default false
106
+ */
63
107
cacheHandlers ?: boolean
64
- // a list of parser plugins to enable for @babel /parser
65
- // https://babeljs.io/docs/en/next/babel-parser#plugins
108
+ /**
109
+ * A list of parser plugins to enable for `@babel/parser`, which is used to
110
+ * parse expressions in bindings and interpolations.
111
+ * https://babeljs.io/docs/en/next/babel-parser#plugins
112
+ */
66
113
expressionPlugins ?: ParserPlugin [ ]
67
- // SFC scoped styles ID
114
+ /**
115
+ * SFC scoped styles ID
116
+ */
68
117
scopeId ?: string | null
118
+ /**
119
+ * Generate SSR-optimized render functions instead.
120
+ * The resulting funciton must be attached to the component via the
121
+ * `ssrRender` option instead of `render`.
122
+ */
69
123
ssr ?: boolean
70
124
onError ?: ( error : CompilerError ) => void
71
125
}
72
126
73
127
export interface CodegenOptions {
74
- // - Module mode will generate ES module import statements for helpers
75
- // and export the render function as the default export.
76
- // - Function mode will generate a single `const { helpers... } = Vue`
77
- // statement and return the render function. It is meant to be used with
78
- // `new Function(code)()` to generate a render function at runtime.
79
- // - Default: 'function'
128
+ /**
129
+ * - `module` mode will generate ES module import statements for helpers
130
+ * and export the render function as the default export.
131
+ * - `function` mode will generate a single `const { helpers... } = Vue`
132
+ * statement and return the render function. It expects `Vue` to be globally
133
+ * available (or passed by wrapping the code with an IIFE). It is meant to be
134
+ * used with `new Function(code)()` to generate a render function at runtime.
135
+ * @default 'function'
136
+ */
80
137
mode ?: 'module' | 'function'
81
- // Generate source map?
82
- // - Default: false
138
+ /**
139
+ * Generate source map?
140
+ * @default false
141
+ */
83
142
sourceMap ?: boolean
84
- // Filename for source map generation.
85
- // - Default: `template.vue.html`
143
+ /**
144
+ * Filename for source map generation.
145
+ * @default 'template.vue.html'
146
+ */
86
147
filename ?: string
87
- // SFC scoped styles ID
148
+ /**
149
+ * SFC scoped styles ID
150
+ */
88
151
scopeId ?: string | null
89
- // we need to know about this to generate proper preambles
90
- prefixIdentifiers ?: boolean
91
- // option to optimize helper import bindings via variable assignment
92
- // (only used for webpack code-split)
152
+ /**
153
+ * Option to optimize helper import bindings via variable assignment
154
+ * (only used for webpack code-split)
155
+ * @default false
156
+ */
93
157
optimizeBindings ?: boolean
94
- // for specifying where to import helpers
158
+ /**
159
+ * Customize where to import runtime helpers from.
160
+ * @default 'vue'
161
+ */
95
162
runtimeModuleName ?: string
163
+ /**
164
+ * Customize the global variable name of `Vue` to get helpers from
165
+ * in function mode
166
+ * @default 'Vue'
167
+ */
96
168
runtimeGlobalName ?: string
169
+ // we need to know this during codegen to generate proper preambles
170
+ prefixIdentifiers ?: boolean
97
171
// generate ssr-specific code?
98
172
ssr ?: boolean
99
173
}
0 commit comments