MCPcopy
hub / github.com/vuejs/core / baseParse

Function baseParse

packages/compiler-core/src/parser.ts:1028–1079  ·  view source on GitHub ↗
(input: string, options?: ParserOptions)

Source from the content-addressed store, hash-verified

1026}
1027
1028export function baseParse(input: string, options?: ParserOptions): RootNode {
1029 reset()
1030 currentInput = input
1031 currentOptions = extend({}, defaultParserOptions)
1032
1033 if (options) {
1034 let key: keyof ParserOptions
1035 for (key in options) {
1036 if (options[key] != null) {
1037 // @ts-expect-error
1038 currentOptions[key] = options[key]
1039 }
1040 }
1041 }
1042
1043 if (__DEV__) {
1044 if (!__BROWSER__ && currentOptions.decodeEntities) {
1045 console.warn(
1046 `[@vue/compiler-core] decodeEntities option is passed but will be ` +
1047 `ignored in non-browser builds.`,
1048 )
1049 } else if (__BROWSER__ && !__TEST__ && !currentOptions.decodeEntities) {
1050 throw new Error(
1051 `[@vue/compiler-core] decodeEntities option is required in browser builds.`,
1052 )
1053 }
1054 }
1055
1056 tokenizer.mode =
1057 currentOptions.parseMode === 'html'
1058 ? ParseMode.HTML
1059 : currentOptions.parseMode === 'sfc'
1060 ? ParseMode.SFC
1061 : ParseMode.BASE
1062
1063 tokenizer.inXML =
1064 currentOptions.ns === Namespaces.SVG ||
1065 currentOptions.ns === Namespaces.MATH_ML
1066
1067 const delimiters = options && options.delimiters
1068 if (delimiters) {
1069 tokenizer.delimiterOpen = toCharCodes(delimiters[0])
1070 tokenizer.delimiterClose = toCharCodes(delimiters[1])
1071 }
1072
1073 const root = (currentRoot = createRoot([], input))
1074 tokenizer.parse(currentInput)
1075 root.loc = getLoc(0, input.length)
1076 root.children = condenseWhitespace(root.children)
1077 currentRoot = null
1078 return root
1079}

Callers 9

parseFunction · 0.90
compileWithAssetUrlsFunction · 0.90
compileWithSrcsetFunction · 0.90
baseCompileFunction · 0.90
parse.spec.tsFile · 0.90
parseFunction · 0.90
transform.spec.tsFile · 0.90
transformWithCodegenFunction · 0.90
compileFunction · 0.85

Calls 7

toCharCodesFunction · 0.90
createRootFunction · 0.90
getLocFunction · 0.85
condenseWhitespaceFunction · 0.85
warnMethod · 0.80
resetFunction · 0.70
parseMethod · 0.65

Tested by 4

compileWithAssetUrlsFunction · 0.72
compileWithSrcsetFunction · 0.72
parseFunction · 0.72
transformWithCodegenFunction · 0.72