UNPKG

@vue/compiler-core

Version:
1,625 lines (1,618 loc) 173 kB
/** * @vue/compiler-core v3.5.16 * (c) 2018-present Yuxi (Evan) You and Vue contributors * @license MIT **/ import { isString, NOOP, isObject, extend, NO, isSymbol, isArray, capitalize, camelize, EMPTY_OBJ, PatchFlagNames, slotFlagsText, isOn, isBuiltInDirective, isReservedProp, toHandlerKey } from '@vue/shared'; export { generateCodeFrame } from '@vue/shared'; const FRAGMENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Fragment` : ``); const TELEPORT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Teleport` : ``); const SUSPENSE = Symbol(!!(process.env.NODE_ENV !== "production") ? `Suspense` : ``); const KEEP_ALIVE = Symbol(!!(process.env.NODE_ENV !== "production") ? `KeepAlive` : ``); const BASE_TRANSITION = Symbol( !!(process.env.NODE_ENV !== "production") ? `BaseTransition` : `` ); const OPEN_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `openBlock` : ``); const CREATE_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `createBlock` : ``); const CREATE_ELEMENT_BLOCK = Symbol( !!(process.env.NODE_ENV !== "production") ? `createElementBlock` : `` ); const CREATE_VNODE = Symbol(!!(process.env.NODE_ENV !== "production") ? `createVNode` : ``); const CREATE_ELEMENT_VNODE = Symbol( !!(process.env.NODE_ENV !== "production") ? `createElementVNode` : `` ); const CREATE_COMMENT = Symbol( !!(process.env.NODE_ENV !== "production") ? `createCommentVNode` : `` ); const CREATE_TEXT = Symbol( !!(process.env.NODE_ENV !== "production") ? `createTextVNode` : `` ); const CREATE_STATIC = Symbol( !!(process.env.NODE_ENV !== "production") ? `createStaticVNode` : `` ); const RESOLVE_COMPONENT = Symbol( !!(process.env.NODE_ENV !== "production") ? `resolveComponent` : `` ); const RESOLVE_DYNAMIC_COMPONENT = Symbol( !!(process.env.NODE_ENV !== "production") ? `resolveDynamicComponent` : `` ); const RESOLVE_DIRECTIVE = Symbol( !!(process.env.NODE_ENV !== "production") ? `resolveDirective` : `` ); const RESOLVE_FILTER = Symbol( !!(process.env.NODE_ENV !== "production") ? `resolveFilter` : `` ); const WITH_DIRECTIVES = Symbol( !!(process.env.NODE_ENV !== "production") ? `withDirectives` : `` ); const RENDER_LIST = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderList` : ``); const RENDER_SLOT = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderSlot` : ``); const CREATE_SLOTS = Symbol(!!(process.env.NODE_ENV !== "production") ? `createSlots` : ``); const TO_DISPLAY_STRING = Symbol( !!(process.env.NODE_ENV !== "production") ? `toDisplayString` : `` ); const MERGE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `mergeProps` : ``); const NORMALIZE_CLASS = Symbol( !!(process.env.NODE_ENV !== "production") ? `normalizeClass` : `` ); const NORMALIZE_STYLE = Symbol( !!(process.env.NODE_ENV !== "production") ? `normalizeStyle` : `` ); const NORMALIZE_PROPS = Symbol( !!(process.env.NODE_ENV !== "production") ? `normalizeProps` : `` ); const GUARD_REACTIVE_PROPS = Symbol( !!(process.env.NODE_ENV !== "production") ? `guardReactiveProps` : `` ); const TO_HANDLERS = Symbol(!!(process.env.NODE_ENV !== "production") ? `toHandlers` : ``); const CAMELIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `camelize` : ``); const CAPITALIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `capitalize` : ``); const TO_HANDLER_KEY = Symbol( !!(process.env.NODE_ENV !== "production") ? `toHandlerKey` : `` ); const SET_BLOCK_TRACKING = Symbol( !!(process.env.NODE_ENV !== "production") ? `setBlockTracking` : `` ); const PUSH_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `pushScopeId` : ``); const POP_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `popScopeId` : ``); const WITH_CTX = Symbol(!!(process.env.NODE_ENV !== "production") ? `withCtx` : ``); const UNREF = Symbol(!!(process.env.NODE_ENV !== "production") ? `unref` : ``); const IS_REF = Symbol(!!(process.env.NODE_ENV !== "production") ? `isRef` : ``); const WITH_MEMO = Symbol(!!(process.env.NODE_ENV !== "production") ? `withMemo` : ``); const IS_MEMO_SAME = Symbol(!!(process.env.NODE_ENV !== "production") ? `isMemoSame` : ``); const helperNameMap = { [FRAGMENT]: `Fragment`, [TELEPORT]: `Teleport`, [SUSPENSE]: `Suspense`, [KEEP_ALIVE]: `KeepAlive`, [BASE_TRANSITION]: `BaseTransition`, [OPEN_BLOCK]: `openBlock`, [CREATE_BLOCK]: `createBlock`, [CREATE_ELEMENT_BLOCK]: `createElementBlock`, [CREATE_VNODE]: `createVNode`, [CREATE_ELEMENT_VNODE]: `createElementVNode`, [CREATE_COMMENT]: `createCommentVNode`, [CREATE_TEXT]: `createTextVNode`, [CREATE_STATIC]: `createStaticVNode`, [RESOLVE_COMPONENT]: `resolveComponent`, [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`, [RESOLVE_DIRECTIVE]: `resolveDirective`, [RESOLVE_FILTER]: `resolveFilter`, [WITH_DIRECTIVES]: `withDirectives`, [RENDER_LIST]: `renderList`, [RENDER_SLOT]: `renderSlot`, [CREATE_SLOTS]: `createSlots`, [TO_DISPLAY_STRING]: `toDisplayString`, [MERGE_PROPS]: `mergeProps`, [NORMALIZE_CLASS]: `normalizeClass`, [NORMALIZE_STYLE]: `normalizeStyle`, [NORMALIZE_PROPS]: `normalizeProps`, [GUARD_REACTIVE_PROPS]: `guardReactiveProps`, [TO_HANDLERS]: `toHandlers`, [CAMELIZE]: `camelize`, [CAPITALIZE]: `capitalize`, [TO_HANDLER_KEY]: `toHandlerKey`, [SET_BLOCK_TRACKING]: `setBlockTracking`, [PUSH_SCOPE_ID]: `pushScopeId`, [POP_SCOPE_ID]: `popScopeId`, [WITH_CTX]: `withCtx`, [UNREF]: `unref`, [IS_REF]: `isRef`, [WITH_MEMO]: `withMemo`, [IS_MEMO_SAME]: `isMemoSame` }; function registerRuntimeHelpers(helpers) { Object.getOwnPropertySymbols(helpers).forEach((s) => { helperNameMap[s] = helpers[s]; }); } const Namespaces = { "HTML": 0, "0": "HTML", "SVG": 1, "1": "SVG", "MATH_ML": 2, "2": "MATH_ML" }; const NodeTypes = { "ROOT": 0, "0": "ROOT", "ELEMENT": 1, "1": "ELEMENT", "TEXT": 2, "2": "TEXT", "COMMENT": 3, "3": "COMMENT", "SIMPLE_EXPRESSION": 4, "4": "SIMPLE_EXPRESSION", "INTERPOLATION": 5, "5": "INTERPOLATION", "ATTRIBUTE": 6, "6": "ATTRIBUTE", "DIRECTIVE": 7, "7": "DIRECTIVE", "COMPOUND_EXPRESSION": 8, "8": "COMPOUND_EXPRESSION", "IF": 9, "9": "IF", "IF_BRANCH": 10, "10": "IF_BRANCH", "FOR": 11, "11": "FOR", "TEXT_CALL": 12, "12": "TEXT_CALL", "VNODE_CALL": 13, "13": "VNODE_CALL", "JS_CALL_EXPRESSION": 14, "14": "JS_CALL_EXPRESSION", "JS_OBJECT_EXPRESSION": 15, "15": "JS_OBJECT_EXPRESSION", "JS_PROPERTY": 16, "16": "JS_PROPERTY", "JS_ARRAY_EXPRESSION": 17, "17": "JS_ARRAY_EXPRESSION", "JS_FUNCTION_EXPRESSION": 18, "18": "JS_FUNCTION_EXPRESSION", "JS_CONDITIONAL_EXPRESSION": 19, "19": "JS_CONDITIONAL_EXPRESSION", "JS_CACHE_EXPRESSION": 20, "20": "JS_CACHE_EXPRESSION", "JS_BLOCK_STATEMENT": 21, "21": "JS_BLOCK_STATEMENT", "JS_TEMPLATE_LITERAL": 22, "22": "JS_TEMPLATE_LITERAL", "JS_IF_STATEMENT": 23, "23": "JS_IF_STATEMENT", "JS_ASSIGNMENT_EXPRESSION": 24, "24": "JS_ASSIGNMENT_EXPRESSION", "JS_SEQUENCE_EXPRESSION": 25, "25": "JS_SEQUENCE_EXPRESSION", "JS_RETURN_STATEMENT": 26, "26": "JS_RETURN_STATEMENT" }; const ElementTypes = { "ELEMENT": 0, "0": "ELEMENT", "COMPONENT": 1, "1": "COMPONENT", "SLOT": 2, "2": "SLOT", "TEMPLATE": 3, "3": "TEMPLATE" }; const ConstantTypes = { "NOT_CONSTANT": 0, "0": "NOT_CONSTANT", "CAN_SKIP_PATCH": 1, "1": "CAN_SKIP_PATCH", "CAN_CACHE": 2, "2": "CAN_CACHE", "CAN_STRINGIFY": 3, "3": "CAN_STRINGIFY" }; const locStub = { start: { line: 1, column: 1, offset: 0 }, end: { line: 1, column: 1, offset: 0 }, source: "" }; function createRoot(children, source = "") { return { type: 0, source, children, helpers: /* @__PURE__ */ new Set(), components: [], directives: [], hoists: [], imports: [], cached: [], temps: 0, codegenNode: void 0, loc: locStub }; } function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) { if (context) { if (isBlock) { context.helper(OPEN_BLOCK); context.helper(getVNodeBlockHelper(context.inSSR, isComponent)); } else { context.helper(getVNodeHelper(context.inSSR, isComponent)); } if (directives) { context.helper(WITH_DIRECTIVES); } } return { type: 13, tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent, loc }; } function createArrayExpression(elements, loc = locStub) { return { type: 17, loc, elements }; } function createObjectExpression(properties, loc = locStub) { return { type: 15, loc, properties }; } function createObjectProperty(key, value) { return { type: 16, loc: locStub, key: isString(key) ? createSimpleExpression(key, true) : key, value }; } function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) { return { type: 4, loc, content, isStatic, constType: isStatic ? 3 : constType }; } function createInterpolation(content, loc) { return { type: 5, loc, content: isString(content) ? createSimpleExpression(content, false, loc) : content }; } function createCompoundExpression(children, loc = locStub) { return { type: 8, loc, children }; } function createCallExpression(callee, args = [], loc = locStub) { return { type: 14, loc, callee, arguments: args }; } function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) { return { type: 18, params, returns, newline, isSlot, loc }; } function createConditionalExpression(test, consequent, alternate, newline = true) { return { type: 19, test, consequent, alternate, newline, loc: locStub }; } function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) { return { type: 20, index, value, needPauseTracking, inVOnce, needArraySpread: false, loc: locStub }; } function createBlockStatement(body) { return { type: 21, body, loc: locStub }; } function createTemplateLiteral(elements) { return { type: 22, elements, loc: locStub }; } function createIfStatement(test, consequent, alternate) { return { type: 23, test, consequent, alternate, loc: locStub }; } function createAssignmentExpression(left, right) { return { type: 24, left, right, loc: locStub }; } function createSequenceExpression(expressions) { return { type: 25, expressions, loc: locStub }; } function createReturnStatement(returns) { return { type: 26, returns, loc: locStub }; } function getVNodeHelper(ssr, isComponent) { return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE; } function getVNodeBlockHelper(ssr, isComponent) { return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK; } function convertToBlock(node, { helper, removeHelper, inSSR }) { if (!node.isBlock) { node.isBlock = true; removeHelper(getVNodeHelper(inSSR, node.isComponent)); helper(OPEN_BLOCK); helper(getVNodeBlockHelper(inSSR, node.isComponent)); } } const defaultDelimitersOpen = new Uint8Array([123, 123]); const defaultDelimitersClose = new Uint8Array([125, 125]); function isTagStartChar(c) { return c >= 97 && c <= 122 || c >= 65 && c <= 90; } function isWhitespace(c) { return c === 32 || c === 10 || c === 9 || c === 12 || c === 13; } function isEndOfTagSection(c) { return c === 47 || c === 62 || isWhitespace(c); } function toCharCodes(str) { const ret = new Uint8Array(str.length); for (let i = 0; i < str.length; i++) { ret[i] = str.charCodeAt(i); } return ret; } const Sequences = { Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]), // CDATA[ CdataEnd: new Uint8Array([93, 93, 62]), // ]]> CommentEnd: new Uint8Array([45, 45, 62]), // `-->` ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]), // `<\/script` StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]), // `</style` TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]), // `</title` TextareaEnd: new Uint8Array([ 60, 47, 116, 101, 120, 116, 97, 114, 101, 97 ]) // `</textarea }; class Tokenizer { constructor(stack, cbs) { this.stack = stack; this.cbs = cbs; /** The current state the tokenizer is in. */ this.state = 1; /** The read buffer. */ this.buffer = ""; /** The beginning of the section that is currently being read. */ this.sectionStart = 0; /** The index within the buffer that we are currently looking at. */ this.index = 0; /** The start of the last entity. */ this.entityStart = 0; /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */ this.baseState = 1; /** For special parsing behavior inside of script and style tags. */ this.inRCDATA = false; /** For disabling RCDATA tags handling */ this.inXML = false; /** For disabling interpolation parsing in v-pre */ this.inVPre = false; /** Record newline positions for fast line / column calculation */ this.newlines = []; this.mode = 0; this.delimiterOpen = defaultDelimitersOpen; this.delimiterClose = defaultDelimitersClose; this.delimiterIndex = -1; this.currentSequence = void 0; this.sequenceIndex = 0; } get inSFCRoot() { return this.mode === 2 && this.stack.length === 0; } reset() { this.state = 1; this.mode = 0; this.buffer = ""; this.sectionStart = 0; this.index = 0; this.baseState = 1; this.inRCDATA = false; this.currentSequence = void 0; this.newlines.length = 0; this.delimiterOpen = defaultDelimitersOpen; this.delimiterClose = defaultDelimitersClose; } /** * Generate Position object with line / column information using recorded * newline positions. We know the index is always going to be an already * processed index, so all the newlines up to this index should have been * recorded. */ getPos(index) { let line = 1; let column = index + 1; for (let i = this.newlines.length - 1; i >= 0; i--) { const newlineIndex = this.newlines[i]; if (index > newlineIndex) { line = i + 2; column = index - newlineIndex; break; } } return { column, line, offset: index }; } peek() { return this.buffer.charCodeAt(this.index + 1); } stateText(c) { if (c === 60) { if (this.index > this.sectionStart) { this.cbs.ontext(this.sectionStart, this.index); } this.state = 5; this.sectionStart = this.index; } else if (!this.inVPre && c === this.delimiterOpen[0]) { this.state = 2; this.delimiterIndex = 0; this.stateInterpolationOpen(c); } } stateInterpolationOpen(c) { if (c === this.delimiterOpen[this.delimiterIndex]) { if (this.delimiterIndex === this.delimiterOpen.length - 1) { const start = this.index + 1 - this.delimiterOpen.length; if (start > this.sectionStart) { this.cbs.ontext(this.sectionStart, start); } this.state = 3; this.sectionStart = start; } else { this.delimiterIndex++; } } else if (this.inRCDATA) { this.state = 32; this.stateInRCDATA(c); } else { this.state = 1; this.stateText(c); } } stateInterpolation(c) { if (c === this.delimiterClose[0]) { this.state = 4; this.delimiterIndex = 0; this.stateInterpolationClose(c); } } stateInterpolationClose(c) { if (c === this.delimiterClose[this.delimiterIndex]) { if (this.delimiterIndex === this.delimiterClose.length - 1) { this.cbs.oninterpolation(this.sectionStart, this.index + 1); if (this.inRCDATA) { this.state = 32; } else { this.state = 1; } this.sectionStart = this.index + 1; } else { this.delimiterIndex++; } } else { this.state = 3; this.stateInterpolation(c); } } stateSpecialStartSequence(c) { const isEnd = this.sequenceIndex === this.currentSequence.length; const isMatch = isEnd ? ( // If we are at the end of the sequence, make sure the tag name has ended isEndOfTagSection(c) ) : ( // Otherwise, do a case-insensitive comparison (c | 32) === this.currentSequence[this.sequenceIndex] ); if (!isMatch) { this.inRCDATA = false; } else if (!isEnd) { this.sequenceIndex++; return; } this.sequenceIndex = 0; this.state = 6; this.stateInTagName(c); } /** Look for an end tag. For <title> and <textarea>, also decode entities. */ stateInRCDATA(c) { if (this.sequenceIndex === this.currentSequence.length) { if (c === 62 || isWhitespace(c)) { const endOfText = this.index - this.currentSequence.length; if (this.sectionStart < endOfText) { const actualIndex = this.index; this.index = endOfText; this.cbs.ontext(this.sectionStart, endOfText); this.index = actualIndex; } this.sectionStart = endOfText + 2; this.stateInClosingTagName(c); this.inRCDATA = false; return; } this.sequenceIndex = 0; } if ((c | 32) === this.currentSequence[this.sequenceIndex]) { this.sequenceIndex += 1; } else if (this.sequenceIndex === 0) { if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) { if (!this.inVPre && c === this.delimiterOpen[0]) { this.state = 2; this.delimiterIndex = 0; this.stateInterpolationOpen(c); } } else if (this.fastForwardTo(60)) { this.sequenceIndex = 1; } } else { this.sequenceIndex = Number(c === 60); } } stateCDATASequence(c) { if (c === Sequences.Cdata[this.sequenceIndex]) { if (++this.sequenceIndex === Sequences.Cdata.length) { this.state = 28; this.currentSequence = Sequences.CdataEnd; this.sequenceIndex = 0; this.sectionStart = this.index + 1; } } else { this.sequenceIndex = 0; this.state = 23; this.stateInDeclaration(c); } } /** * When we wait for one specific character, we can speed things up * by skipping through the buffer until we find it. * * @returns Whether the character was found. */ fastForwardTo(c) { while (++this.index < this.buffer.length) { const cc = this.buffer.charCodeAt(this.index); if (cc === 10) { this.newlines.push(this.index); } if (cc === c) { return true; } } this.index = this.buffer.length - 1; return false; } /** * Comments and CDATA end with `-->` and `]]>`. * * Their common qualities are: * - Their end sequences have a distinct character they start with. * - That character is then repeated, so we have to check multiple repeats. * - All characters but the start character of the sequence can be skipped. */ stateInCommentLike(c) { if (c === this.currentSequence[this.sequenceIndex]) { if (++this.sequenceIndex === this.currentSequence.length) { if (this.currentSequence === Sequences.CdataEnd) { this.cbs.oncdata(this.sectionStart, this.index - 2); } else { this.cbs.oncomment(this.sectionStart, this.index - 2); } this.sequenceIndex = 0; this.sectionStart = this.index + 1; this.state = 1; } } else if (this.sequenceIndex === 0) { if (this.fastForwardTo(this.currentSequence[0])) { this.sequenceIndex = 1; } } else if (c !== this.currentSequence[this.sequenceIndex - 1]) { this.sequenceIndex = 0; } } startSpecial(sequence, offset) { this.enterRCDATA(sequence, offset); this.state = 31; } enterRCDATA(sequence, offset) { this.inRCDATA = true; this.currentSequence = sequence; this.sequenceIndex = offset; } stateBeforeTagName(c) { if (c === 33) { this.state = 22; this.sectionStart = this.index + 1; } else if (c === 63) { this.state = 24; this.sectionStart = this.index + 1; } else if (isTagStartChar(c)) { this.sectionStart = this.index; if (this.mode === 0) { this.state = 6; } else if (this.inSFCRoot) { this.state = 34; } else if (!this.inXML) { if (c === 116) { this.state = 30; } else { this.state = c === 115 ? 29 : 6; } } else { this.state = 6; } } else if (c === 47) { this.state = 8; } else { this.state = 1; this.stateText(c); } } stateInTagName(c) { if (isEndOfTagSection(c)) { this.handleTagName(c); } } stateInSFCRootTagName(c) { if (isEndOfTagSection(c)) { const tag = this.buffer.slice(this.sectionStart, this.index); if (tag !== "template") { this.enterRCDATA(toCharCodes(`</` + tag), 0); } this.handleTagName(c); } } handleTagName(c) { this.cbs.onopentagname(this.sectionStart, this.index); this.sectionStart = -1; this.state = 11; this.stateBeforeAttrName(c); } stateBeforeClosingTagName(c) { if (isWhitespace(c)) ; else if (c === 62) { if (!!(process.env.NODE_ENV !== "production") || false) { this.cbs.onerr(14, this.index); } this.state = 1; this.sectionStart = this.index + 1; } else { this.state = isTagStartChar(c) ? 9 : 27; this.sectionStart = this.index; } } stateInClosingTagName(c) { if (c === 62 || isWhitespace(c)) { this.cbs.onclosetag(this.sectionStart, this.index); this.sectionStart = -1; this.state = 10; this.stateAfterClosingTagName(c); } } stateAfterClosingTagName(c) { if (c === 62) { this.state = 1; this.sectionStart = this.index + 1; } } stateBeforeAttrName(c) { if (c === 62) { this.cbs.onopentagend(this.index); if (this.inRCDATA) { this.state = 32; } else { this.state = 1; } this.sectionStart = this.index + 1; } else if (c === 47) { this.state = 7; if ((!!(process.env.NODE_ENV !== "production") || false) && this.peek() !== 62) { this.cbs.onerr(22, this.index); } } else if (c === 60 && this.peek() === 47) { this.cbs.onopentagend(this.index); this.state = 5; this.sectionStart = this.index; } else if (!isWhitespace(c)) { if ((!!(process.env.NODE_ENV !== "production") || false) && c === 61) { this.cbs.onerr( 19, this.index ); } this.handleAttrStart(c); } } handleAttrStart(c) { if (c === 118 && this.peek() === 45) { this.state = 13; this.sectionStart = this.index; } else if (c === 46 || c === 58 || c === 64 || c === 35) { this.cbs.ondirname(this.index, this.index + 1); this.state = 14; this.sectionStart = this.index + 1; } else { this.state = 12; this.sectionStart = this.index; } } stateInSelfClosingTag(c) { if (c === 62) { this.cbs.onselfclosingtag(this.index); this.state = 1; this.sectionStart = this.index + 1; this.inRCDATA = false; } else if (!isWhitespace(c)) { this.state = 11; this.stateBeforeAttrName(c); } } stateInAttrName(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.onattribname(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if ((!!(process.env.NODE_ENV !== "production") || false) && (c === 34 || c === 39 || c === 60)) { this.cbs.onerr( 17, this.index ); } } stateInDirName(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirname(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if (c === 58) { this.cbs.ondirname(this.sectionStart, this.index); this.state = 14; this.sectionStart = this.index + 1; } else if (c === 46) { this.cbs.ondirname(this.sectionStart, this.index); this.state = 16; this.sectionStart = this.index + 1; } } stateInDirArg(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirarg(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if (c === 91) { this.state = 15; } else if (c === 46) { this.cbs.ondirarg(this.sectionStart, this.index); this.state = 16; this.sectionStart = this.index + 1; } } stateInDynamicDirArg(c) { if (c === 93) { this.state = 14; } else if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirarg(this.sectionStart, this.index + 1); this.handleAttrNameEnd(c); if (!!(process.env.NODE_ENV !== "production") || false) { this.cbs.onerr( 27, this.index ); } } } stateInDirModifier(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirmodifier(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if (c === 46) { this.cbs.ondirmodifier(this.sectionStart, this.index); this.sectionStart = this.index + 1; } } handleAttrNameEnd(c) { this.sectionStart = this.index; this.state = 17; this.cbs.onattribnameend(this.index); this.stateAfterAttrName(c); } stateAfterAttrName(c) { if (c === 61) { this.state = 18; } else if (c === 47 || c === 62) { this.cbs.onattribend(0, this.sectionStart); this.sectionStart = -1; this.state = 11; this.stateBeforeAttrName(c); } else if (!isWhitespace(c)) { this.cbs.onattribend(0, this.sectionStart); this.handleAttrStart(c); } } stateBeforeAttrValue(c) { if (c === 34) { this.state = 19; this.sectionStart = this.index + 1; } else if (c === 39) { this.state = 20; this.sectionStart = this.index + 1; } else if (!isWhitespace(c)) { this.sectionStart = this.index; this.state = 21; this.stateInAttrValueNoQuotes(c); } } handleInAttrValue(c, quote) { if (c === quote || this.fastForwardTo(quote)) { this.cbs.onattribdata(this.sectionStart, this.index); this.sectionStart = -1; this.cbs.onattribend( quote === 34 ? 3 : 2, this.index + 1 ); this.state = 11; } } stateInAttrValueDoubleQuotes(c) { this.handleInAttrValue(c, 34); } stateInAttrValueSingleQuotes(c) { this.handleInAttrValue(c, 39); } stateInAttrValueNoQuotes(c) { if (isWhitespace(c) || c === 62) { this.cbs.onattribdata(this.sectionStart, this.index); this.sectionStart = -1; this.cbs.onattribend(1, this.index); this.state = 11; this.stateBeforeAttrName(c); } else if ((!!(process.env.NODE_ENV !== "production") || false) && c === 34 || c === 39 || c === 60 || c === 61 || c === 96) { this.cbs.onerr( 18, this.index ); } else ; } stateBeforeDeclaration(c) { if (c === 91) { this.state = 26; this.sequenceIndex = 0; } else { this.state = c === 45 ? 25 : 23; } } stateInDeclaration(c) { if (c === 62 || this.fastForwardTo(62)) { this.state = 1; this.sectionStart = this.index + 1; } } stateInProcessingInstruction(c) { if (c === 62 || this.fastForwardTo(62)) { this.cbs.onprocessinginstruction(this.sectionStart, this.index); this.state = 1; this.sectionStart = this.index + 1; } } stateBeforeComment(c) { if (c === 45) { this.state = 28; this.currentSequence = Sequences.CommentEnd; this.sequenceIndex = 2; this.sectionStart = this.index + 1; } else { this.state = 23; } } stateInSpecialComment(c) { if (c === 62 || this.fastForwardTo(62)) { this.cbs.oncomment(this.sectionStart, this.index); this.state = 1; this.sectionStart = this.index + 1; } } stateBeforeSpecialS(c) { if (c === Sequences.ScriptEnd[3]) { this.startSpecial(Sequences.ScriptEnd, 4); } else if (c === Sequences.StyleEnd[3]) { this.startSpecial(Sequences.StyleEnd, 4); } else { this.state = 6; this.stateInTagName(c); } } stateBeforeSpecialT(c) { if (c === Sequences.TitleEnd[3]) { this.startSpecial(Sequences.TitleEnd, 4); } else if (c === Sequences.TextareaEnd[3]) { this.startSpecial(Sequences.TextareaEnd, 4); } else { this.state = 6; this.stateInTagName(c); } } startEntity() { } stateInEntity() { } /** * Iterates through the buffer, calling the function corresponding to the current state. * * States that are more likely to be hit are higher up, as a performance improvement. */ parse(input) { this.buffer = input; while (this.index < this.buffer.length) { const c = this.buffer.charCodeAt(this.index); if (c === 10) { this.newlines.push(this.index); } switch (this.state) { case 1: { this.stateText(c); break; } case 2: { this.stateInterpolationOpen(c); break; } case 3: { this.stateInterpolation(c); break; } case 4: { this.stateInterpolationClose(c); break; } case 31: { this.stateSpecialStartSequence(c); break; } case 32: { this.stateInRCDATA(c); break; } case 26: { this.stateCDATASequence(c); break; } case 19: { this.stateInAttrValueDoubleQuotes(c); break; } case 12: { this.stateInAttrName(c); break; } case 13: { this.stateInDirName(c); break; } case 14: { this.stateInDirArg(c); break; } case 15: { this.stateInDynamicDirArg(c); break; } case 16: { this.stateInDirModifier(c); break; } case 28: { this.stateInCommentLike(c); break; } case 27: { this.stateInSpecialComment(c); break; } case 11: { this.stateBeforeAttrName(c); break; } case 6: { this.stateInTagName(c); break; } case 34: { this.stateInSFCRootTagName(c); break; } case 9: { this.stateInClosingTagName(c); break; } case 5: { this.stateBeforeTagName(c); break; } case 17: { this.stateAfterAttrName(c); break; } case 20: { this.stateInAttrValueSingleQuotes(c); break; } case 18: { this.stateBeforeAttrValue(c); break; } case 8: { this.stateBeforeClosingTagName(c); break; } case 10: { this.stateAfterClosingTagName(c); break; } case 29: { this.stateBeforeSpecialS(c); break; } case 30: { this.stateBeforeSpecialT(c); break; } case 21: { this.stateInAttrValueNoQuotes(c); break; } case 7: { this.stateInSelfClosingTag(c); break; } case 23: { this.stateInDeclaration(c); break; } case 22: { this.stateBeforeDeclaration(c); break; } case 25: { this.stateBeforeComment(c); break; } case 24: { this.stateInProcessingInstruction(c); break; } case 33: { this.stateInEntity(); break; } } this.index++; } this.cleanup(); this.finish(); } /** * Remove data that has already been consumed from the buffer. */ cleanup() { if (this.sectionStart !== this.index) { if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) { this.cbs.ontext(this.sectionStart, this.index); this.sectionStart = this.index; } else if (this.state === 19 || this.state === 20 || this.state === 21) { this.cbs.onattribdata(this.sectionStart, this.index); this.sectionStart = this.index; } } } finish() { this.handleTrailingData(); this.cbs.onend(); } /** Handle any trailing data. */ handleTrailingData() { const endIndex = this.buffer.length; if (this.sectionStart >= endIndex) { return; } if (this.state === 28) { if (this.currentSequence === Sequences.CdataEnd) { this.cbs.oncdata(this.sectionStart, endIndex); } else { this.cbs.oncomment(this.sectionStart, endIndex); } } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else { this.cbs.ontext(this.sectionStart, endIndex); } } emitCodePoint(cp, consumed) { } } const CompilerDeprecationTypes = { "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT", "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC", "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER", "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE", "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE", "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE", "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE", "COMPILER_FILTERS": "COMPILER_FILTERS" }; const deprecationData = { ["COMPILER_IS_ON_ELEMENT"]: { message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`, link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html` }, ["COMPILER_V_BIND_SYNC"]: { message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`, link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html` }, ["COMPILER_V_BIND_OBJECT_ORDER"]: { message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`, link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html` }, ["COMPILER_V_ON_NATIVE"]: { message: `.native modifier for v-on has been removed as is no longer necessary.`, link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html` }, ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: { message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`, link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html` }, ["COMPILER_NATIVE_TEMPLATE"]: { message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.` }, ["COMPILER_INLINE_TEMPLATE"]: { message: `"inline-template" has been removed in Vue 3.`, link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html` }, ["COMPILER_FILTERS"]: { message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`, link: `https://v3-migration.vuejs.org/breaking-changes/filters.html` } }; function getCompatValue(key, { compatConfig }) { const value = compatConfig && compatConfig[key]; if (key === "MODE") { return value || 3; } else { return value; } } function isCompatEnabled(key, context) { const mode = getCompatValue("MODE", context); const value = getCompatValue(key, context); return mode === 3 ? value === true : value !== false; } function checkCompatEnabled(key, context, loc, ...args) { const enabled = isCompatEnabled(key, context); if (!!(process.env.NODE_ENV !== "production") && enabled) { warnDeprecation(key, context, loc, ...args); } return enabled; } function warnDeprecation(key, context, loc, ...args) { const val = getCompatValue(key, context); if (val === "suppress-warning") { return; } const { message, link } = deprecationData[key]; const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? ` Details: ${link}` : ``}`; const err = new SyntaxError(msg); err.code = key; if (loc) err.loc = loc; context.onWarn(err); } function defaultOnError(error) { throw error; } function defaultOnWarn(msg) { !!(process.env.NODE_ENV !== "production") && console.warn(`[Vue warn] ${msg.message}`); } function createCompilerError(code, loc, messages, additionalMessage) { const msg = !!(process.env.NODE_ENV !== "production") || false ? (messages || errorMessages)[code] + (additionalMessage || ``) : `https://vuejs.org/error-reference/#compiler-${code}`; const error = new SyntaxError(String(msg)); error.code = code; error.loc = loc; return error; } const ErrorCodes = { "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0, "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT", "CDATA_IN_HTML_CONTENT": 1, "1": "CDATA_IN_HTML_CONTENT", "DUPLICATE_ATTRIBUTE": 2, "2": "DUPLICATE_ATTRIBUTE", "END_TAG_WITH_ATTRIBUTES": 3, "3": "END_TAG_WITH_ATTRIBUTES", "END_TAG_WITH_TRAILING_SOLIDUS": 4, "4": "END_TAG_WITH_TRAILING_SOLIDUS", "EOF_BEFORE_TAG_NAME": 5, "5": "EOF_BEFORE_TAG_NAME", "EOF_IN_CDATA": 6, "6": "EOF_IN_CDATA", "EOF_IN_COMMENT": 7, "7": "EOF_IN_COMMENT", "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8, "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT", "EOF_IN_TAG": 9, "9": "EOF_IN_TAG", "INCORRECTLY_CLOSED_COMMENT": 10, "10": "INCORRECTLY_CLOSED_COMMENT", "INCORRECTLY_OPENED_COMMENT": 11, "11": "INCORRECTLY_OPENED_COMMENT", "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12, "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME", "MISSING_ATTRIBUTE_VALUE": 13, "13": "MISSING_ATTRIBUTE_VALUE", "MISSING_END_TAG_NAME": 14, "14": "MISSING_END_TAG_NAME", "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15, "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES", "NESTED_COMMENT": 16, "16": "NESTED_COMMENT", "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17, "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME", "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18, "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE", "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19, "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME", "UNEXPECTED_NULL_CHARACTER": 20, "20": "UNEXPECTED_NULL_CHARACTER", "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21, "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME", "UNEXPECTED_SOLIDUS_IN_TAG": 22, "22": "UNEXPECTED_SOLIDUS_IN_TAG", "X_INVALID_END_TAG": 23, "23": "X_INVALID_END_TAG", "X_MISSING_END_TAG": 24, "24": "X_MISSING_END_TAG", "X_MISSING_INTERPOLATION_END": 25, "25": "X_MISSING_INTERPOLATION_END", "X_MISSING_DIRECTIVE_NAME": 26, "26": "X_MISSING_DIRECTIVE_NAME", "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27, "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END", "X_V_IF_NO_EXPRESSION": 28, "28": "X_V_IF_NO_EXPRESSION", "X_V_IF_SAME_KEY": 29, "29": "X_V_IF_SAME_KEY", "X_V_ELSE_NO_ADJACENT_IF": 30, "30": "X_V_ELSE_NO_ADJACENT_IF", "X_V_FOR_NO_EXPRESSION": 31, "31": "X_V_FOR_NO_EXPRESSION", "X_V_FOR_MALFORMED_EXPRESSION": 32, "32": "X_V_FOR_MALFORMED_EXPRESSION", "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33, "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT", "X_V_BIND_NO_EXPRESSION": 34, "34": "X_V_BIND_NO_EXPRESSION", "X_V_ON_NO_EXPRESSION": 35, "35": "X_V_ON_NO_EXPRESSION", "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36, "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET", "X_V_SLOT_MIXED_SLOT_USAGE": 37, "37": "X_V_SLOT_MIXED_SLOT_USAGE", "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38, "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES", "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39, "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN", "X_V_SLOT_MISPLACED": 40, "40": "X_V_SLOT_MISPLACED", "X_V_MODEL_NO_EXPRESSION": 41, "41": "X_V_MODEL_NO_EXPRESSION", "X_V_MODEL_MALFORMED_EXPRESSION": 42, "42": "X_V_MODEL_MALFORMED_EXPRESSION", "X_V_MODEL_ON_SCOPE_VARIABLE": 43, "43": "X_V_MODEL_ON_SCOPE_VARIABLE", "X_V_MODEL_ON_PROPS": 44, "44": "X_V_MODEL_ON_PROPS", "X_INVALID_EXPRESSION": 45, "45": "X_INVALID_EXPRESSION", "X_KEEP_ALIVE_INVALID_CHILDREN": 46, "46": "X_KEEP_ALIVE_INVALID_CHILDREN", "X_PREFIX_ID_NOT_SUPPORTED": 47, "47": "X_PREFIX_ID_NOT_SUPPORTED", "X_MODULE_MODE_NOT_SUPPORTED": 48, "48": "X_MODULE_MODE_NOT_SUPPORTED", "X_CACHE_HANDLER_NOT_SUPPORTED": 49, "49": "X_CACHE_HANDLER_NOT_SUPPORTED", "X_SCOPE_ID_NOT_SUPPORTED": 50, "50": "X_SCOPE_ID_NOT_SUPPORTED", "X_VNODE_HOOKS": 51, "51": "X_VNODE_HOOKS", "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 52, "52": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT", "__EXTEND_POINT__": 53, "53": "__EXTEND_POINT__" }; const errorMessages = { // parse errors [0]: "Illegal comment.", [1]: "CDATA section is allowed only in XML context.", [2]: "Duplicate attribute.", [3]: "End tag cannot have attributes.", [4]: "Illegal '/' in tags.", [5]: "Unexpected EOF in tag.", [6]: "Unexpected EOF in CDATA section.", [7]: "Unexpected EOF in comment.", [8]: "Unexpected EOF in script.", [9]: "Unexpected EOF in tag.", [10]: "Incorrectly closed comment.", [11]: "Incorrectly opened comment.", [12]: "Illegal tag name. Use '&lt;' to print '<'.", [13]: "Attribute value was expected.", [14]: "End tag name was expected.", [15]: "Whitespace was expected.", [16]: "Unexpected '<!--' in comment.", [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`, [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).", [19]: "Attribute name cannot start with '='.", [21]: "'<?' is allowed only in XML context.", [20]: `Unexpected null character.`, [22]: "Illegal '/' in tags.", // Vue-specific parse errors [23]: "Invalid end tag.", [24]: "Element is missing end tag.", [25]: "Interpolation end sign was not found.", [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.", [26]: "Legal directive name was expected.", // transform errors [28]: `v-if/v-else-if is missing expression.`, [29]: `v-if/else branches must use unique keys.`, [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`, [31]: `v-for is missing expression.`, [32]: `v-for has invalid expression.`, [33]: `<template v-for> key should be placed on the <template> tag.`, [34]: `v-bind is missing expression.`, [52]: `v-bind with same-name shorthand only allows static argument.`, [35]: `v-on is missing expression.`, [36]: `Unexpected custom directive on <slot> outlet.`, [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`, [38]: `Duplicate slot names found. `, [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`, [40]: `v-slot can only be used on components or <template> tags.`, [41]: `v-model is missing expression.`, [42]: `v-model value must be a valid JavaScript member expression.`, [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`, [44]: `v-model cannot be used on a prop, because local prop bindings are not writable. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`, [45]: `Error parsing JavaScript expression: `, [46]: `<KeepAlive> expects exactly one child component.`, [51]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`, // generic errors [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`, [48]: `ES module mode is not supported in this build of compiler.`, [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`, [50]: `"scopeId" option is only supported in module mode.`, // just to fulfill types [53]: `` }; function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) { { return; } } function isReferencedIdentifier(id, parent, parentStack) { { return false; } } function isInDestructureAssignment(parent, parentStack) { if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) { let i = parentStack.length; while (i--) { const p = parentStack[i]; if (p.type === "AssignmentExpression") { return true; } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) { break; } } } return false; } function isInNewExpression(parentStack) { let i = parentStack.length; while (i--) { const p = parentStack[i]; if (p.type === "NewExpression") { return true; } else if (p.type !== "MemberExpression") { break; } } return false; } function walkFunctionParams(node, onIdent) { for (const p of node.params) { for (const id of extractIdentifiers(p)) { onIdent(id); } } } function walkBlockDeclarations(block, onIdent) { for (const stmt of block.body) { if (stmt.type === "VariableDeclaration") { if (stmt.declare) continue; for (const decl of stmt.declarations) { for (const id of extractIdentifiers(decl.id)) { onIdent(id); } } } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") { if (stmt.declare || !stmt.id) continue; onIdent(stmt.id); } else if (isForStatement(stmt)) { walkForStatement(stmt, true, onIdent); } } } function isForStatement(stmt) { return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement"; } function walkForStatement(stmt, isVar, onIdent) { const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left; if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : false)) { for (const decl of variable.declarations) { for (const id of extractIdentifiers(decl.id)) { onIdent(id); } } } } function extractIdentifiers(param, nodes = []) { switch (param.type) { case "Identifier": nodes.push(param); break; case "MemberExpression": let object = param; while (object.type === "MemberExpression") { object = object.object; } nodes.push(object); break; case "ObjectPattern": for (const prop of param.properties) { if (prop.type === "RestElement") { extractIdentifiers(prop.argument, nodes); } else { extractIdentifiers(prop.value, nodes); } } break; case "ArrayPattern": param.elements.forEach((element) => { if (element) extractIdentifiers(element, nodes); }); break; case "RestElement": extractIdentifiers(param.argument, nodes); break; case "AssignmentPattern": extractIdentifiers(param.left, nodes); break; } return nodes; } const isFunctionType = (node) => { return /Function(?:Expression|Declaration)$|Method$/.test(node.type); }; const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed; const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node; const TS_NODE_TYPES = [ "TSAsExpression", // foo as number "TSTypeAssertion", // (<number>foo) "TSNonNullExpression", // foo! "TSInstantiationExpression", // foo<string> "TSSatisfiesExpression" // foo satisfies T ]; function unwrapTSNode(node) { if (TS_NODE_TYPES.includes(node.type)) { return unwrapTSNode(node.expression); } else { return node; } } const isStaticExp = (p) => p.type === 4 && p.isStatic; function isCoreComponent(tag) { switch (tag) { case "Teleport": case "teleport": return TELEPORT; case "Suspense": case "suspense": return SUSPENSE; case "KeepAlive": case "keep-alive": return KEEP_ALIVE; case "BaseTransition": case "base-transition": return BASE_TRANSITION; } } const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/; const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name); const validFi