refactor(compiler/types): convert compiler options documentation to jsdoc
BREAKING CHANGE: `getTextMode` compiler option signature has changed from ```ts (tag: string, ns: string, parent: ElementNode | undefined) => TextModes ``` to ```ts (node: ElementNode, parent: ElementNode | undefined) => TextModes ```
This commit is contained in:
parent
304ab8c99b
commit
e58beecc97
@ -2515,7 +2515,7 @@ foo
|
|||||||
}
|
}
|
||||||
return ns
|
return ns
|
||||||
},
|
},
|
||||||
getTextMode: tag => {
|
getTextMode: ({ tag }) => {
|
||||||
if (tag === 'textarea') {
|
if (tag === 'textarea') {
|
||||||
return TextModes.RCDATA
|
return TextModes.RCDATA
|
||||||
}
|
}
|
||||||
|
@ -9,23 +9,44 @@ import {
|
|||||||
import { ParserPlugin } from '@babel/parser'
|
import { ParserPlugin } from '@babel/parser'
|
||||||
|
|
||||||
export interface ParserOptions {
|
export interface ParserOptions {
|
||||||
// e.g. platform native elements, e.g. <div> for browsers
|
/**
|
||||||
|
* e.g. platform native elements, e.g. <div> for browsers
|
||||||
|
*/
|
||||||
isNativeTag?: (tag: string) => boolean
|
isNativeTag?: (tag: string) => boolean
|
||||||
// e.g. native elements that can self-close, e.g. <img>, <br>, <hr>
|
/**
|
||||||
|
* e.g. native elements that can self-close, e.g. <img>, <br>, <hr>
|
||||||
|
*/
|
||||||
isVoidTag?: (tag: string) => boolean
|
isVoidTag?: (tag: string) => boolean
|
||||||
// e.g. elements that should preserve whitespace inside, e.g. <pre>
|
/**
|
||||||
|
* e.g. elements that should preserve whitespace inside, e.g. <pre>
|
||||||
|
*/
|
||||||
isPreTag?: (tag: string) => boolean
|
isPreTag?: (tag: string) => boolean
|
||||||
// platform-specific built-in components e.g. <Transition>
|
/**
|
||||||
|
* Platform-specific built-in components e.g. <Transition>
|
||||||
|
*/
|
||||||
isBuiltInComponent?: (tag: string) => symbol | void
|
isBuiltInComponent?: (tag: string) => symbol | void
|
||||||
// separate option for end users to extend the native elements list
|
/**
|
||||||
|
* Separate option for end users to extend the native elements list
|
||||||
|
*/
|
||||||
isCustomElement?: (tag: string) => boolean
|
isCustomElement?: (tag: string) => boolean
|
||||||
|
/**
|
||||||
|
* Get tag namespace
|
||||||
|
*/
|
||||||
getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
|
getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
|
||||||
|
/**
|
||||||
|
* Get text parsing mode for this element
|
||||||
|
*/
|
||||||
getTextMode?: (
|
getTextMode?: (
|
||||||
tag: string,
|
node: ElementNode,
|
||||||
ns: Namespace,
|
|
||||||
parent: ElementNode | undefined
|
parent: ElementNode | undefined
|
||||||
) => TextModes
|
) => TextModes
|
||||||
delimiters?: [string, string] // ['{{', '}}']
|
/**
|
||||||
|
* @default ['{{', '}}']
|
||||||
|
*/
|
||||||
|
delimiters?: [string, string]
|
||||||
|
/**
|
||||||
|
* Only needed for DOM compilers
|
||||||
|
*/
|
||||||
decodeEntities?: (rawText: string, asAttr: boolean) => string
|
decodeEntities?: (rawText: string, asAttr: boolean) => string
|
||||||
onError?: (error: CompilerError) => void
|
onError?: (error: CompilerError) => void
|
||||||
}
|
}
|
||||||
@ -36,64 +57,117 @@ export type HoistTransform = (
|
|||||||
) => JSChildNode
|
) => JSChildNode
|
||||||
|
|
||||||
export interface TransformOptions {
|
export interface TransformOptions {
|
||||||
|
/**
|
||||||
|
* An array of node trasnforms to be applied to every AST node.
|
||||||
|
*/
|
||||||
nodeTransforms?: NodeTransform[]
|
nodeTransforms?: NodeTransform[]
|
||||||
|
/**
|
||||||
|
* An object of { name: transform } to be applied to every directive attribute
|
||||||
|
* node found on element nodes.
|
||||||
|
*/
|
||||||
directiveTransforms?: Record<string, DirectiveTransform | undefined>
|
directiveTransforms?: Record<string, DirectiveTransform | undefined>
|
||||||
// an optional hook to transform a node being hoisted.
|
/**
|
||||||
// used by compiler-dom to turn hoisted nodes into stringified HTML vnodes.
|
* An optional hook to transform a node being hoisted.
|
||||||
|
* used by compiler-dom to turn hoisted nodes into stringified HTML vnodes.
|
||||||
|
* @default null
|
||||||
|
*/
|
||||||
transformHoist?: HoistTransform | null
|
transformHoist?: HoistTransform | null
|
||||||
|
/**
|
||||||
|
* If the pairing runtime provides additional built-in elements, use this to
|
||||||
|
* mark them as built-in so the compiler will generate component vnodes
|
||||||
|
* for them.
|
||||||
|
*/
|
||||||
isBuiltInComponent?: (tag: string) => symbol | void
|
isBuiltInComponent?: (tag: string) => symbol | void
|
||||||
// Transform expressions like {{ foo }} to `_ctx.foo`.
|
/**
|
||||||
// If this option is false, the generated code will be wrapped in a
|
* Transform expressions like {{ foo }} to `_ctx.foo`.
|
||||||
// `with (this) { ... }` block.
|
* If this option is false, the generated code will be wrapped in a
|
||||||
// - This is force-enabled in module mode, since modules are by default strict
|
* `with (this) { ... }` block.
|
||||||
// and cannot use `with`
|
* - This is force-enabled in module mode, since modules are by default strict
|
||||||
// - Default: mode === 'module'
|
* and cannot use `with`
|
||||||
|
* @default mode === 'module'
|
||||||
|
*/
|
||||||
prefixIdentifiers?: boolean
|
prefixIdentifiers?: boolean
|
||||||
// Hoist static VNodes and props objects to `_hoisted_x` constants
|
/**
|
||||||
// - Default: false
|
* Hoist static VNodes and props objects to `_hoisted_x` constants
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
hoistStatic?: boolean
|
hoistStatic?: boolean
|
||||||
// Cache v-on handlers to avoid creating new inline functions on each render,
|
/**
|
||||||
// also avoids the need for dynamically patching the handlers by wrapping it.
|
* Cache v-on handlers to avoid creating new inline functions on each render,
|
||||||
// e.g `@click="foo"` by default is compiled to `{ onClick: foo }`. With this
|
* also avoids the need for dynamically patching the handlers by wrapping it.
|
||||||
// option it's compiled to:
|
* e.g `@click="foo"` by default is compiled to `{ onClick: foo }`. With this
|
||||||
// `{ onClick: _cache[0] || (_cache[0] = e => _ctx.foo(e)) }`
|
* option it's compiled to:
|
||||||
// - Requires "prefixIdentifiers" to be enabled because it relies on scope
|
* ```js
|
||||||
// analysis to determine if a handler is safe to cache.
|
* { onClick: _cache[0] || (_cache[0] = e => _ctx.foo(e)) }
|
||||||
// - Default: false
|
* ```
|
||||||
|
* - Requires "prefixIdentifiers" to be enabled because it relies on scope
|
||||||
|
* analysis to determine if a handler is safe to cache.
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
cacheHandlers?: boolean
|
cacheHandlers?: boolean
|
||||||
// a list of parser plugins to enable for @babel/parser
|
/**
|
||||||
// https://babeljs.io/docs/en/next/babel-parser#plugins
|
* A list of parser plugins to enable for `@babel/parser`, which is used to
|
||||||
|
* parse expressions in bindings and interpolations.
|
||||||
|
* https://babeljs.io/docs/en/next/babel-parser#plugins
|
||||||
|
*/
|
||||||
expressionPlugins?: ParserPlugin[]
|
expressionPlugins?: ParserPlugin[]
|
||||||
// SFC scoped styles ID
|
/**
|
||||||
|
* SFC scoped styles ID
|
||||||
|
*/
|
||||||
scopeId?: string | null
|
scopeId?: string | null
|
||||||
|
/**
|
||||||
|
* Generate SSR-optimized render functions instead.
|
||||||
|
* The resulting funciton must be attached to the component via the
|
||||||
|
* `ssrRender` option instead of `render`.
|
||||||
|
*/
|
||||||
ssr?: boolean
|
ssr?: boolean
|
||||||
onError?: (error: CompilerError) => void
|
onError?: (error: CompilerError) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CodegenOptions {
|
export interface CodegenOptions {
|
||||||
// - Module mode will generate ES module import statements for helpers
|
/**
|
||||||
// and export the render function as the default export.
|
* - `module` mode will generate ES module import statements for helpers
|
||||||
// - Function mode will generate a single `const { helpers... } = Vue`
|
* and export the render function as the default export.
|
||||||
// statement and return the render function. It is meant to be used with
|
* - `function` mode will generate a single `const { helpers... } = Vue`
|
||||||
// `new Function(code)()` to generate a render function at runtime.
|
* statement and return the render function. It expects `Vue` to be globally
|
||||||
// - Default: 'function'
|
* available (or passed by wrapping the code with an IIFE). It is meant to be
|
||||||
|
* used with `new Function(code)()` to generate a render function at runtime.
|
||||||
|
* @default 'function'
|
||||||
|
*/
|
||||||
mode?: 'module' | 'function'
|
mode?: 'module' | 'function'
|
||||||
// Generate source map?
|
/**
|
||||||
// - Default: false
|
* Generate source map?
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
sourceMap?: boolean
|
sourceMap?: boolean
|
||||||
// Filename for source map generation.
|
/**
|
||||||
// - Default: `template.vue.html`
|
* Filename for source map generation.
|
||||||
|
* @default 'template.vue.html'
|
||||||
|
*/
|
||||||
filename?: string
|
filename?: string
|
||||||
// SFC scoped styles ID
|
/**
|
||||||
|
* SFC scoped styles ID
|
||||||
|
*/
|
||||||
scopeId?: string | null
|
scopeId?: string | null
|
||||||
// we need to know about this to generate proper preambles
|
/**
|
||||||
prefixIdentifiers?: boolean
|
* Option to optimize helper import bindings via variable assignment
|
||||||
// option to optimize helper import bindings via variable assignment
|
* (only used for webpack code-split)
|
||||||
// (only used for webpack code-split)
|
* @default false
|
||||||
|
*/
|
||||||
optimizeBindings?: boolean
|
optimizeBindings?: boolean
|
||||||
// for specifying where to import helpers
|
/**
|
||||||
|
* Customize where to import runtime helpers from.
|
||||||
|
* @default 'vue'
|
||||||
|
*/
|
||||||
runtimeModuleName?: string
|
runtimeModuleName?: string
|
||||||
|
/**
|
||||||
|
* Customize the global variable name of `Vue` to get helpers from
|
||||||
|
* in function mode
|
||||||
|
* @default 'Vue'
|
||||||
|
*/
|
||||||
runtimeGlobalName?: string
|
runtimeGlobalName?: string
|
||||||
|
// we need to know this during codegen to generate proper preambles
|
||||||
|
prefixIdentifiers?: boolean
|
||||||
// generate ssr-specific code?
|
// generate ssr-specific code?
|
||||||
ssr?: boolean
|
ssr?: boolean
|
||||||
}
|
}
|
||||||
|
@ -373,7 +373,7 @@ function parseElement(
|
|||||||
|
|
||||||
// Children.
|
// Children.
|
||||||
ancestors.push(element)
|
ancestors.push(element)
|
||||||
const mode = context.options.getTextMode(element.tag, element.ns, parent)
|
const mode = context.options.getTextMode(element, parent)
|
||||||
const children = parseChildren(context, mode, ancestors)
|
const children = parseChildren(context, mode, ancestors)
|
||||||
ancestors.pop()
|
ancestors.pop()
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ export const parserOptions: ParserOptions = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
|
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
|
||||||
getTextMode(tag: string, ns: DOMNamespaces): TextModes {
|
getTextMode({ tag, ns }: ElementNode): TextModes {
|
||||||
if (ns === DOMNamespaces.HTML) {
|
if (ns === DOMNamespaces.HTML) {
|
||||||
if (tag === 'textarea' || tag === 'title') {
|
if (tag === 'textarea' || tag === 'title') {
|
||||||
return TextModes.RCDATA
|
return TextModes.RCDATA
|
||||||
|
@ -96,7 +96,7 @@ export function parse(
|
|||||||
isNativeTag: () => true,
|
isNativeTag: () => true,
|
||||||
// preserve all whitespaces
|
// preserve all whitespaces
|
||||||
isPreTag: () => true,
|
isPreTag: () => true,
|
||||||
getTextMode: (tag, _ns, parent) => {
|
getTextMode: ({ tag }, parent) => {
|
||||||
// all top level elements except <template> are parsed as raw text
|
// all top level elements except <template> are parsed as raw text
|
||||||
// containers
|
// containers
|
||||||
if (!parent && tag !== 'template') {
|
if (!parent && tag !== 'template') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user