mirror of https://github.com/vuejs/core.git
wip: getting ready for textmode handling
This commit is contained in:
parent
5a855c57d7
commit
81e941da5b
|
|
@ -65,8 +65,8 @@ export const enum CharCodes {
|
||||||
RightSquare = 93 // "]"
|
RightSquare = 93 // "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultDelimitersOpen = [123, 123] // "{{"
|
const defaultDelimitersOpen = new Uint8Array([123, 123]) // "{{"
|
||||||
const defaultDelimitersClose = [125, 125] // "}}"
|
const defaultDelimitersClose = new Uint8Array([125, 125]) // "}}"
|
||||||
|
|
||||||
/** All the states the tokenizer can be in. */
|
/** All the states the tokenizer can be in. */
|
||||||
const enum State {
|
const enum State {
|
||||||
|
|
@ -115,6 +115,17 @@ const enum State {
|
||||||
InEntity
|
InEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a
|
||||||
|
* tag name.
|
||||||
|
*/
|
||||||
|
function isTagStartChar(c: number): boolean {
|
||||||
|
return (
|
||||||
|
(c >= CharCodes.LowerA && c <= CharCodes.LowerZ) ||
|
||||||
|
(c >= CharCodes.UpperA && c <= CharCodes.UpperZ)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function isWhitespace(c: number): boolean {
|
export function isWhitespace(c: number): boolean {
|
||||||
return (
|
return (
|
||||||
c === CharCodes.Space ||
|
c === CharCodes.Space ||
|
||||||
|
|
@ -261,9 +272,9 @@ export default class Tokenizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delimiterOpen: number[] = defaultDelimitersOpen
|
public delimiterOpen: Uint8Array = defaultDelimitersOpen
|
||||||
public delimiterClose: number[] = defaultDelimitersClose
|
public delimiterClose: Uint8Array = defaultDelimitersClose
|
||||||
private matchDelimiter(c: number, delimiter: number[]): boolean {
|
private matchDelimiter(c: number, delimiter: Uint8Array): boolean {
|
||||||
if (c === delimiter[0]) {
|
if (c === delimiter[0]) {
|
||||||
const l = delimiter.length
|
const l = delimiter.length
|
||||||
for (let i = 1; i < l; i++) {
|
for (let i = 1; i < l; i++) {
|
||||||
|
|
@ -420,16 +431,6 @@ export default class Tokenizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
|
|
||||||
*/
|
|
||||||
private isTagStartChar(c: number) {
|
|
||||||
return (
|
|
||||||
(c >= CharCodes.LowerA && c <= CharCodes.LowerZ) ||
|
|
||||||
(c >= CharCodes.UpperA && c <= CharCodes.UpperZ)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private startSpecial(sequence: Uint8Array, offset: number) {
|
private startSpecial(sequence: Uint8Array, offset: number) {
|
||||||
this.isSpecial = true
|
this.isSpecial = true
|
||||||
this.currentSequence = sequence
|
this.currentSequence = sequence
|
||||||
|
|
@ -444,7 +445,7 @@ export default class Tokenizer {
|
||||||
} else if (c === CharCodes.Questionmark) {
|
} else if (c === CharCodes.Questionmark) {
|
||||||
this.state = State.InProcessingInstruction
|
this.state = State.InProcessingInstruction
|
||||||
this.sectionStart = this.index + 1
|
this.sectionStart = this.index + 1
|
||||||
} else if (this.isTagStartChar(c)) {
|
} else if (isTagStartChar(c)) {
|
||||||
const lower = c | 0x20
|
const lower = c | 0x20
|
||||||
this.sectionStart = this.index
|
this.sectionStart = this.index
|
||||||
if (lower === Sequences.TitleEnd[2]) {
|
if (lower === Sequences.TitleEnd[2]) {
|
||||||
|
|
@ -476,7 +477,7 @@ export default class Tokenizer {
|
||||||
} else if (c === CharCodes.Gt) {
|
} else if (c === CharCodes.Gt) {
|
||||||
this.state = State.Text
|
this.state = State.Text
|
||||||
} else {
|
} else {
|
||||||
this.state = this.isTagStartChar(c)
|
this.state = isTagStartChar(c)
|
||||||
? State.InClosingTagName
|
? State.InClosingTagName
|
||||||
: State.InSpecialComment
|
: State.InSpecialComment
|
||||||
this.sectionStart = this.index
|
this.sectionStart = this.index
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ import { CompilerCompatOptions } from '../compat/compatConfig'
|
||||||
import { NO, extend } from '@vue/shared'
|
import { NO, extend } from '@vue/shared'
|
||||||
import { defaultOnError, defaultOnWarn } from '../errors'
|
import { defaultOnError, defaultOnWarn } from '../errors'
|
||||||
import { isCoreComponent } from '../utils'
|
import { isCoreComponent } from '../utils'
|
||||||
|
import { TextModes } from '../parse'
|
||||||
|
|
||||||
type OptionalOptions =
|
type OptionalOptions =
|
||||||
| 'getTextMode' // TODO
|
|
||||||
| 'whitespace'
|
| 'whitespace'
|
||||||
| 'isNativeTag'
|
| 'isNativeTag'
|
||||||
| 'isBuiltInComponent'
|
| 'isBuiltInComponent'
|
||||||
|
|
@ -45,7 +45,7 @@ const decodeMap: Record<string, string> = {
|
||||||
export const defaultParserOptions: MergedParserOptions = {
|
export const defaultParserOptions: MergedParserOptions = {
|
||||||
delimiters: [`{{`, `}}`],
|
delimiters: [`{{`, `}}`],
|
||||||
getNamespace: () => Namespaces.HTML,
|
getNamespace: () => Namespaces.HTML,
|
||||||
// getTextMode: () => TextModes.DATA,
|
getTextMode: () => TextModes.DATA,
|
||||||
isVoidTag: NO,
|
isVoidTag: NO,
|
||||||
isPreTag: NO,
|
isPreTag: NO,
|
||||||
isCustomElement: NO,
|
isCustomElement: NO,
|
||||||
|
|
@ -598,8 +598,12 @@ function reset() {
|
||||||
stack.length = 0
|
stack.length = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function toCharCodes(str: string): number[] {
|
function toCharCodes(str: string): Uint8Array {
|
||||||
return str.split('').map(c => c.charCodeAt(0))
|
const ret = new Uint8Array()
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
ret[i] = str.charCodeAt(i)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
export function baseParse(input: string, options?: ParserOptions): RootNode {
|
export function baseParse(input: string, options?: ParserOptions): RootNode {
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,11 @@ import {
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
isBuiltInType
|
isBuiltInType
|
||||||
} from '@vue/compiler-core'
|
} from '@vue/compiler-core'
|
||||||
import { makeMap, isVoidTag, isHTMLTag, isSVGTag } from '@vue/shared'
|
import { isVoidTag, isHTMLTag, isSVGTag } from '@vue/shared'
|
||||||
import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
|
import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
|
||||||
import { decodeHtml } from './decodeHtml'
|
import { decodeHtml } from './decodeHtml'
|
||||||
import { decodeHtmlBrowser } from './decodeHtmlBrowser'
|
import { decodeHtmlBrowser } from './decodeHtmlBrowser'
|
||||||
|
|
||||||
const isRawTextContainer = /*#__PURE__*/ makeMap(
|
|
||||||
'style,iframe,script,noscript',
|
|
||||||
true
|
|
||||||
)
|
|
||||||
|
|
||||||
export const enum DOMNamespaces {
|
export const enum DOMNamespaces {
|
||||||
HTML = 0 /* Namespaces.HTML */,
|
HTML = 0 /* Namespaces.HTML */,
|
||||||
SVG,
|
SVG,
|
||||||
|
|
@ -38,7 +33,6 @@ export const parserOptions: ParserOptions = {
|
||||||
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
||||||
getNamespace(tag: string, parent: ElementNode | undefined): DOMNamespaces {
|
getNamespace(tag: string, parent: ElementNode | undefined): DOMNamespaces {
|
||||||
let ns = parent ? parent.ns : DOMNamespaces.HTML
|
let ns = parent ? parent.ns : DOMNamespaces.HTML
|
||||||
|
|
||||||
if (parent && ns === DOMNamespaces.MATH_ML) {
|
if (parent && ns === DOMNamespaces.MATH_ML) {
|
||||||
if (parent.tag === 'annotation-xml') {
|
if (parent.tag === 'annotation-xml') {
|
||||||
if (tag === 'svg') {
|
if (tag === 'svg') {
|
||||||
|
|
@ -90,7 +84,7 @@ export const parserOptions: ParserOptions = {
|
||||||
if (tag === 'textarea' || tag === 'title') {
|
if (tag === 'textarea' || tag === 'title') {
|
||||||
return TextModes.RCDATA
|
return TextModes.RCDATA
|
||||||
}
|
}
|
||||||
if (isRawTextContainer(tag)) {
|
if (tag === 'style' || tag === 'script') {
|
||||||
return TextModes.RAWTEXT
|
return TextModes.RAWTEXT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue