Parse - 解析

发布于: 5/25/2022 阅读大约需要1分钟

解析过程

解析过程是将字符串模板解析为VueAST对象

方法定义:

export function baseParse(
  content: string,
  options: ParserOptions = {}
): RootNode {
  const context = createParserContext(content, options)
  const start = getCursor(context)
  return createRoot(
    parseChildren(context, TextModes.DATA, []),
    getSelection(context, start)
  )
}
  1. 创建解析上下文对象(**createParserContext**)
    该对象在解析过程中全程参与, 主要用于记录当前解析进度信息.
    该对象在代码中的定义如下:
export interface ParserContext {
  // 解析器选项
  options: MergedParserOptions
  // 原始字符串模板
  readonly originalSource: string
  // 当前剩余待解析字符串模板
  source: string
  // 偏移量
  offset: number
  // 行数
  line: number
  // 列数
  column: number
  // 是否是在`