refactor(parser): remove ignoreSpaces option
This commit is contained in:
parent
abfb2ec8ed
commit
f7a7e8d71d
@ -36,7 +36,6 @@ export interface ParserOptions {
|
|||||||
getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
|
getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
|
||||||
getTextMode?: (tag: string, ns: Namespace) => TextModes
|
getTextMode?: (tag: string, ns: Namespace) => TextModes
|
||||||
delimiters?: [string, string] // ['{{', '}}']
|
delimiters?: [string, string] // ['{{', '}}']
|
||||||
ignoreSpaces?: boolean
|
|
||||||
|
|
||||||
// Map to HTML entities. E.g., `{ "amp;": "&" }`
|
// Map to HTML entities. E.g., `{ "amp;": "&" }`
|
||||||
// The full set is https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references
|
// The full set is https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references
|
||||||
@ -51,7 +50,6 @@ type MergedParserOptions = Omit<Required<ParserOptions>, 'isNativeTag'> &
|
|||||||
|
|
||||||
export const defaultParserOptions: MergedParserOptions = {
|
export const defaultParserOptions: MergedParserOptions = {
|
||||||
delimiters: [`{{`, `}}`],
|
delimiters: [`{{`, `}}`],
|
||||||
ignoreSpaces: true,
|
|
||||||
getNamespace: () => Namespaces.HTML,
|
getNamespace: () => Namespaces.HTML,
|
||||||
getTextMode: () => TextModes.DATA,
|
getTextMode: () => TextModes.DATA,
|
||||||
isVoidTag: NO,
|
isVoidTag: NO,
|
||||||
@ -219,30 +217,29 @@ function pushNode(
|
|||||||
if (!__DEV__ && node.type === NodeTypes.COMMENT) {
|
if (!__DEV__ && node.type === NodeTypes.COMMENT) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
context.options.ignoreSpaces &&
|
if (node.type === NodeTypes.TEXT) {
|
||||||
node.type === NodeTypes.TEXT &&
|
if (node.isEmpty) {
|
||||||
node.isEmpty
|
return
|
||||||
) {
|
}
|
||||||
return
|
|
||||||
|
// Merge if both this and the previous node are text and those are
|
||||||
|
// consecutive. This happens for cases like "a < b".
|
||||||
|
const prev = last(nodes)
|
||||||
|
if (
|
||||||
|
prev &&
|
||||||
|
prev.type === NodeTypes.TEXT &&
|
||||||
|
prev.loc.end.offset === node.loc.start.offset
|
||||||
|
) {
|
||||||
|
prev.content += node.content
|
||||||
|
prev.isEmpty = prev.content.trim().length === 0
|
||||||
|
prev.loc.end = node.loc.end
|
||||||
|
prev.loc.source += node.loc.source
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge if both this and the previous node are text and those are consecutive.
|
nodes.push(node)
|
||||||
// This happens on "a < b" or something like.
|
|
||||||
const prev = last(nodes)
|
|
||||||
if (
|
|
||||||
prev &&
|
|
||||||
prev.type === NodeTypes.TEXT &&
|
|
||||||
node.type === NodeTypes.TEXT &&
|
|
||||||
prev.loc.end.offset === node.loc.start.offset
|
|
||||||
) {
|
|
||||||
prev.content += node.content
|
|
||||||
prev.isEmpty = prev.content.trim().length === 0
|
|
||||||
prev.loc.end = node.loc.end
|
|
||||||
prev.loc.source += node.loc.source
|
|
||||||
} else {
|
|
||||||
nodes.push(node)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCDATA(
|
function parseCDATA(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user