| 1026 | } |
| 1027 | |
| 1028 | export 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 | } |