compiler-core.d.ts 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. import { PatchFlags } from '@vue/shared';
  2. export { generateCodeFrame } from '@vue/shared';
  3. import { Node as Node$1, Identifier, Function, BlockStatement as BlockStatement$1, Program, ObjectProperty } from '@babel/types';
  4. import { ParserPlugin } from '@babel/parser';
  5. export declare const FRAGMENT: unique symbol;
  6. export declare const TELEPORT: unique symbol;
  7. export declare const SUSPENSE: unique symbol;
  8. export declare const KEEP_ALIVE: unique symbol;
  9. export declare const BASE_TRANSITION: unique symbol;
  10. export declare const OPEN_BLOCK: unique symbol;
  11. export declare const CREATE_BLOCK: unique symbol;
  12. export declare const CREATE_ELEMENT_BLOCK: unique symbol;
  13. export declare const CREATE_VNODE: unique symbol;
  14. export declare const CREATE_ELEMENT_VNODE: unique symbol;
  15. export declare const CREATE_COMMENT: unique symbol;
  16. export declare const CREATE_TEXT: unique symbol;
  17. export declare const CREATE_STATIC: unique symbol;
  18. export declare const RESOLVE_COMPONENT: unique symbol;
  19. export declare const RESOLVE_DYNAMIC_COMPONENT: unique symbol;
  20. export declare const RESOLVE_DIRECTIVE: unique symbol;
  21. export declare const RESOLVE_FILTER: unique symbol;
  22. export declare const WITH_DIRECTIVES: unique symbol;
  23. export declare const RENDER_LIST: unique symbol;
  24. export declare const RENDER_SLOT: unique symbol;
  25. export declare const CREATE_SLOTS: unique symbol;
  26. export declare const TO_DISPLAY_STRING: unique symbol;
  27. export declare const MERGE_PROPS: unique symbol;
  28. export declare const NORMALIZE_CLASS: unique symbol;
  29. export declare const NORMALIZE_STYLE: unique symbol;
  30. export declare const NORMALIZE_PROPS: unique symbol;
  31. export declare const GUARD_REACTIVE_PROPS: unique symbol;
  32. export declare const TO_HANDLERS: unique symbol;
  33. export declare const CAMELIZE: unique symbol;
  34. export declare const CAPITALIZE: unique symbol;
  35. export declare const TO_HANDLER_KEY: unique symbol;
  36. export declare const SET_BLOCK_TRACKING: unique symbol;
  37. /**
  38. * @deprecated no longer needed in 3.5+ because we no longer hoist element nodes
  39. * but kept for backwards compat
  40. */
  41. export declare const PUSH_SCOPE_ID: unique symbol;
  42. /**
  43. * @deprecated kept for backwards compat
  44. */
  45. export declare const POP_SCOPE_ID: unique symbol;
  46. export declare const WITH_CTX: unique symbol;
  47. export declare const UNREF: unique symbol;
  48. export declare const IS_REF: unique symbol;
  49. export declare const WITH_MEMO: unique symbol;
  50. export declare const IS_MEMO_SAME: unique symbol;
  51. export declare const helperNameMap: Record<symbol, string>;
  52. export declare function registerRuntimeHelpers(helpers: Record<symbol, string>): void;
  53. type OptionalOptions = 'decodeEntities' | 'whitespace' | 'isNativeTag' | 'isBuiltInComponent' | 'expressionPlugins' | keyof CompilerCompatOptions;
  54. type MergedParserOptions = Omit<Required<ParserOptions>, OptionalOptions> & Pick<ParserOptions, OptionalOptions>;
  55. export declare function baseParse(input: string, options?: ParserOptions): RootNode;
  56. type CompilerCompatConfig = Partial<Record<CompilerDeprecationTypes, boolean | 'suppress-warning'>> & {
  57. MODE?: 2 | 3;
  58. };
  59. interface CompilerCompatOptions {
  60. compatConfig?: CompilerCompatConfig;
  61. }
  62. export declare enum CompilerDeprecationTypes {
  63. COMPILER_IS_ON_ELEMENT = "COMPILER_IS_ON_ELEMENT",
  64. COMPILER_V_BIND_SYNC = "COMPILER_V_BIND_SYNC",
  65. COMPILER_V_BIND_OBJECT_ORDER = "COMPILER_V_BIND_OBJECT_ORDER",
  66. COMPILER_V_ON_NATIVE = "COMPILER_V_ON_NATIVE",
  67. COMPILER_V_IF_V_FOR_PRECEDENCE = "COMPILER_V_IF_V_FOR_PRECEDENCE",
  68. COMPILER_NATIVE_TEMPLATE = "COMPILER_NATIVE_TEMPLATE",
  69. COMPILER_INLINE_TEMPLATE = "COMPILER_INLINE_TEMPLATE",
  70. COMPILER_FILTERS = "COMPILER_FILTERS"
  71. }
  72. export declare function checkCompatEnabled(key: CompilerDeprecationTypes, context: MergedParserOptions | TransformContext, loc: SourceLocation | null, ...args: any[]): boolean;
  73. export declare function warnDeprecation(key: CompilerDeprecationTypes, context: MergedParserOptions | TransformContext, loc: SourceLocation | null, ...args: any[]): void;
  74. export type NodeTransform = (node: RootNode | TemplateChildNode, context: TransformContext) => void | (() => void) | (() => void)[];
  75. export type DirectiveTransform = (dir: DirectiveNode, node: ElementNode, context: TransformContext, augmentor?: (ret: DirectiveTransformResult) => DirectiveTransformResult) => DirectiveTransformResult;
  76. interface DirectiveTransformResult {
  77. props: Property[];
  78. needRuntime?: boolean | symbol;
  79. ssrTagParts?: TemplateLiteral['elements'];
  80. }
  81. export type StructuralDirectiveTransform = (node: ElementNode, dir: DirectiveNode, context: TransformContext) => void | (() => void);
  82. interface ImportItem {
  83. exp: string | ExpressionNode;
  84. path: string;
  85. }
  86. export interface TransformContext extends Required<Omit<TransformOptions, keyof CompilerCompatOptions>>, CompilerCompatOptions {
  87. selfName: string | null;
  88. root: RootNode;
  89. helpers: Map<symbol, number>;
  90. components: Set<string>;
  91. directives: Set<string>;
  92. hoists: (JSChildNode | null)[];
  93. imports: ImportItem[];
  94. temps: number;
  95. cached: (CacheExpression | null)[];
  96. identifiers: {
  97. [name: string]: number | undefined;
  98. };
  99. scopes: {
  100. vFor: number;
  101. vSlot: number;
  102. vPre: number;
  103. vOnce: number;
  104. };
  105. parent: ParentNode | null;
  106. grandParent: ParentNode | null;
  107. childIndex: number;
  108. currentNode: RootNode | TemplateChildNode | null;
  109. inVOnce: boolean;
  110. helper<T extends symbol>(name: T): T;
  111. removeHelper<T extends symbol>(name: T): void;
  112. helperString(name: symbol): string;
  113. replaceNode(node: TemplateChildNode): void;
  114. removeNode(node?: TemplateChildNode): void;
  115. onNodeRemoved(): void;
  116. addIdentifiers(exp: ExpressionNode | string): void;
  117. removeIdentifiers(exp: ExpressionNode | string): void;
  118. hoist(exp: string | JSChildNode | ArrayExpression): SimpleExpressionNode;
  119. cache(exp: JSChildNode, isVNode?: boolean, inVOnce?: boolean): CacheExpression;
  120. constantCache: WeakMap<TemplateChildNode, ConstantTypes>;
  121. filters?: Set<string>;
  122. }
  123. export declare function createTransformContext(root: RootNode, { filename, prefixIdentifiers, hoistStatic, hmr, cacheHandlers, nodeTransforms, directiveTransforms, transformHoist, isBuiltInComponent, isCustomElement, expressionPlugins, scopeId, slotted, ssr, inSSR, ssrCssVars, bindingMetadata, inline, isTS, onError, onWarn, compatConfig, }: TransformOptions): TransformContext;
  124. export declare function transform(root: RootNode, options: TransformOptions): void;
  125. export declare function traverseNode(node: RootNode | TemplateChildNode, context: TransformContext): void;
  126. export declare function createStructuralDirectiveTransform(name: string | RegExp, fn: StructuralDirectiveTransform): NodeTransform;
  127. export declare const transformElement: NodeTransform;
  128. export declare function resolveComponentType(node: ComponentNode, context: TransformContext, ssr?: boolean): string | symbol | CallExpression;
  129. export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode;
  130. export declare function buildProps(node: ElementNode, context: TransformContext, props: ElementNode['props'] | undefined, isComponent: boolean, isDynamicComponent: boolean, ssr?: boolean): {
  131. props: PropsExpression | undefined;
  132. directives: DirectiveNode[];
  133. patchFlag: number;
  134. dynamicPropNames: string[];
  135. shouldUseBlock: boolean;
  136. };
  137. export declare function buildDirectiveArgs(dir: DirectiveNode, context: TransformContext): ArrayExpression;
  138. export type Namespace = number;
  139. export declare enum Namespaces {
  140. HTML = 0,
  141. SVG = 1,
  142. MATH_ML = 2
  143. }
  144. export declare enum NodeTypes {
  145. ROOT = 0,
  146. ELEMENT = 1,
  147. TEXT = 2,
  148. COMMENT = 3,
  149. SIMPLE_EXPRESSION = 4,
  150. INTERPOLATION = 5,
  151. ATTRIBUTE = 6,
  152. DIRECTIVE = 7,
  153. COMPOUND_EXPRESSION = 8,
  154. IF = 9,
  155. IF_BRANCH = 10,
  156. FOR = 11,
  157. TEXT_CALL = 12,
  158. VNODE_CALL = 13,
  159. JS_CALL_EXPRESSION = 14,
  160. JS_OBJECT_EXPRESSION = 15,
  161. JS_PROPERTY = 16,
  162. JS_ARRAY_EXPRESSION = 17,
  163. JS_FUNCTION_EXPRESSION = 18,
  164. JS_CONDITIONAL_EXPRESSION = 19,
  165. JS_CACHE_EXPRESSION = 20,
  166. JS_BLOCK_STATEMENT = 21,
  167. JS_TEMPLATE_LITERAL = 22,
  168. JS_IF_STATEMENT = 23,
  169. JS_ASSIGNMENT_EXPRESSION = 24,
  170. JS_SEQUENCE_EXPRESSION = 25,
  171. JS_RETURN_STATEMENT = 26
  172. }
  173. export declare enum ElementTypes {
  174. ELEMENT = 0,
  175. COMPONENT = 1,
  176. SLOT = 2,
  177. TEMPLATE = 3
  178. }
  179. export interface Node {
  180. type: NodeTypes;
  181. loc: SourceLocation;
  182. }
  183. export interface SourceLocation {
  184. start: Position;
  185. end: Position;
  186. source: string;
  187. }
  188. export interface Position {
  189. offset: number;
  190. line: number;
  191. column: number;
  192. }
  193. export type ParentNode = RootNode | ElementNode | IfBranchNode | ForNode;
  194. export type ExpressionNode = SimpleExpressionNode | CompoundExpressionNode;
  195. export type TemplateChildNode = ElementNode | InterpolationNode | CompoundExpressionNode | TextNode | CommentNode | IfNode | IfBranchNode | ForNode | TextCallNode;
  196. export interface RootNode extends Node {
  197. type: NodeTypes.ROOT;
  198. source: string;
  199. children: TemplateChildNode[];
  200. helpers: Set<symbol>;
  201. components: string[];
  202. directives: string[];
  203. hoists: (JSChildNode | null)[];
  204. imports: ImportItem[];
  205. cached: (CacheExpression | null)[];
  206. temps: number;
  207. ssrHelpers?: symbol[];
  208. codegenNode?: TemplateChildNode | JSChildNode | BlockStatement;
  209. transformed?: boolean;
  210. filters?: string[];
  211. }
  212. export type ElementNode = PlainElementNode | ComponentNode | SlotOutletNode | TemplateNode;
  213. export interface BaseElementNode extends Node {
  214. type: NodeTypes.ELEMENT;
  215. ns: Namespace;
  216. tag: string;
  217. tagType: ElementTypes;
  218. props: Array<AttributeNode | DirectiveNode>;
  219. children: TemplateChildNode[];
  220. isSelfClosing?: boolean;
  221. innerLoc?: SourceLocation;
  222. }
  223. export interface PlainElementNode extends BaseElementNode {
  224. tagType: ElementTypes.ELEMENT;
  225. codegenNode: VNodeCall | SimpleExpressionNode | CacheExpression | MemoExpression | undefined;
  226. ssrCodegenNode?: TemplateLiteral;
  227. }
  228. export interface ComponentNode extends BaseElementNode {
  229. tagType: ElementTypes.COMPONENT;
  230. codegenNode: VNodeCall | CacheExpression | MemoExpression | undefined;
  231. ssrCodegenNode?: CallExpression;
  232. }
  233. export interface SlotOutletNode extends BaseElementNode {
  234. tagType: ElementTypes.SLOT;
  235. codegenNode: RenderSlotCall | CacheExpression | undefined;
  236. ssrCodegenNode?: CallExpression;
  237. }
  238. export interface TemplateNode extends BaseElementNode {
  239. tagType: ElementTypes.TEMPLATE;
  240. codegenNode: undefined;
  241. }
  242. export interface TextNode extends Node {
  243. type: NodeTypes.TEXT;
  244. content: string;
  245. }
  246. export interface CommentNode extends Node {
  247. type: NodeTypes.COMMENT;
  248. content: string;
  249. }
  250. export interface AttributeNode extends Node {
  251. type: NodeTypes.ATTRIBUTE;
  252. name: string;
  253. nameLoc: SourceLocation;
  254. value: TextNode | undefined;
  255. }
  256. export interface DirectiveNode extends Node {
  257. type: NodeTypes.DIRECTIVE;
  258. /**
  259. * the normalized name without prefix or shorthands, e.g. "bind", "on"
  260. */
  261. name: string;
  262. /**
  263. * the raw attribute name, preserving shorthand, and including arg & modifiers
  264. * this is only used during parse.
  265. */
  266. rawName?: string;
  267. exp: ExpressionNode | undefined;
  268. arg: ExpressionNode | undefined;
  269. modifiers: SimpleExpressionNode[];
  270. /**
  271. * optional property to cache the expression parse result for v-for
  272. */
  273. forParseResult?: ForParseResult;
  274. }
  275. /**
  276. * Static types have several levels.
  277. * Higher levels implies lower levels. e.g. a node that can be stringified
  278. * can always be hoisted and skipped for patch.
  279. */
  280. export declare enum ConstantTypes {
  281. NOT_CONSTANT = 0,
  282. CAN_SKIP_PATCH = 1,
  283. CAN_CACHE = 2,
  284. CAN_STRINGIFY = 3
  285. }
  286. export interface SimpleExpressionNode extends Node {
  287. type: NodeTypes.SIMPLE_EXPRESSION;
  288. content: string;
  289. isStatic: boolean;
  290. constType: ConstantTypes;
  291. /**
  292. * - `null` means the expression is a simple identifier that doesn't need
  293. * parsing
  294. * - `false` means there was a parsing error
  295. */
  296. ast?: Node$1 | null | false;
  297. /**
  298. * Indicates this is an identifier for a hoist vnode call and points to the
  299. * hoisted node.
  300. */
  301. hoisted?: JSChildNode;
  302. /**
  303. * an expression parsed as the params of a function will track
  304. * the identifiers declared inside the function body.
  305. */
  306. identifiers?: string[];
  307. isHandlerKey?: boolean;
  308. }
  309. export interface InterpolationNode extends Node {
  310. type: NodeTypes.INTERPOLATION;
  311. content: ExpressionNode;
  312. }
  313. export interface CompoundExpressionNode extends Node {
  314. type: NodeTypes.COMPOUND_EXPRESSION;
  315. /**
  316. * - `null` means the expression is a simple identifier that doesn't need
  317. * parsing
  318. * - `false` means there was a parsing error
  319. */
  320. ast?: Node$1 | null | false;
  321. children: (SimpleExpressionNode | CompoundExpressionNode | InterpolationNode | TextNode | string | symbol)[];
  322. /**
  323. * an expression parsed as the params of a function will track
  324. * the identifiers declared inside the function body.
  325. */
  326. identifiers?: string[];
  327. isHandlerKey?: boolean;
  328. }
  329. export interface IfNode extends Node {
  330. type: NodeTypes.IF;
  331. branches: IfBranchNode[];
  332. codegenNode?: IfConditionalExpression | CacheExpression;
  333. }
  334. export interface IfBranchNode extends Node {
  335. type: NodeTypes.IF_BRANCH;
  336. condition: ExpressionNode | undefined;
  337. children: TemplateChildNode[];
  338. userKey?: AttributeNode | DirectiveNode;
  339. isTemplateIf?: boolean;
  340. }
  341. export interface ForNode extends Node {
  342. type: NodeTypes.FOR;
  343. source: ExpressionNode;
  344. valueAlias: ExpressionNode | undefined;
  345. keyAlias: ExpressionNode | undefined;
  346. objectIndexAlias: ExpressionNode | undefined;
  347. parseResult: ForParseResult;
  348. children: TemplateChildNode[];
  349. codegenNode?: ForCodegenNode;
  350. }
  351. export interface ForParseResult {
  352. source: ExpressionNode;
  353. value: ExpressionNode | undefined;
  354. key: ExpressionNode | undefined;
  355. index: ExpressionNode | undefined;
  356. finalized: boolean;
  357. }
  358. export interface TextCallNode extends Node {
  359. type: NodeTypes.TEXT_CALL;
  360. content: TextNode | InterpolationNode | CompoundExpressionNode;
  361. codegenNode: CallExpression | SimpleExpressionNode;
  362. }
  363. export type TemplateTextChildNode = TextNode | InterpolationNode | CompoundExpressionNode;
  364. export interface VNodeCall extends Node {
  365. type: NodeTypes.VNODE_CALL;
  366. tag: string | symbol | CallExpression;
  367. props: PropsExpression | undefined;
  368. children: TemplateChildNode[] | TemplateTextChildNode | SlotsExpression | ForRenderListExpression | SimpleExpressionNode | CacheExpression | undefined;
  369. patchFlag: PatchFlags | undefined;
  370. dynamicProps: string | SimpleExpressionNode | undefined;
  371. directives: DirectiveArguments | undefined;
  372. isBlock: boolean;
  373. disableTracking: boolean;
  374. isComponent: boolean;
  375. }
  376. export type JSChildNode = VNodeCall | CallExpression | ObjectExpression | ArrayExpression | ExpressionNode | FunctionExpression | ConditionalExpression | CacheExpression | AssignmentExpression | SequenceExpression;
  377. export interface CallExpression extends Node {
  378. type: NodeTypes.JS_CALL_EXPRESSION;
  379. callee: string | symbol;
  380. arguments: (string | symbol | JSChildNode | SSRCodegenNode | TemplateChildNode | TemplateChildNode[])[];
  381. }
  382. export interface ObjectExpression extends Node {
  383. type: NodeTypes.JS_OBJECT_EXPRESSION;
  384. properties: Array<Property>;
  385. }
  386. export interface Property extends Node {
  387. type: NodeTypes.JS_PROPERTY;
  388. key: ExpressionNode;
  389. value: JSChildNode;
  390. }
  391. export interface ArrayExpression extends Node {
  392. type: NodeTypes.JS_ARRAY_EXPRESSION;
  393. elements: Array<string | Node>;
  394. }
  395. export interface FunctionExpression extends Node {
  396. type: NodeTypes.JS_FUNCTION_EXPRESSION;
  397. params: ExpressionNode | string | (ExpressionNode | string)[] | undefined;
  398. returns?: TemplateChildNode | TemplateChildNode[] | JSChildNode;
  399. body?: BlockStatement | IfStatement;
  400. newline: boolean;
  401. /**
  402. * This flag is for codegen to determine whether it needs to generate the
  403. * withScopeId() wrapper
  404. */
  405. isSlot: boolean;
  406. /**
  407. * __COMPAT__ only, indicates a slot function that should be excluded from
  408. * the legacy $scopedSlots instance property.
  409. */
  410. isNonScopedSlot?: boolean;
  411. }
  412. export interface ConditionalExpression extends Node {
  413. type: NodeTypes.JS_CONDITIONAL_EXPRESSION;
  414. test: JSChildNode;
  415. consequent: JSChildNode;
  416. alternate: JSChildNode;
  417. newline: boolean;
  418. }
  419. export interface CacheExpression extends Node {
  420. type: NodeTypes.JS_CACHE_EXPRESSION;
  421. index: number;
  422. value: JSChildNode;
  423. needPauseTracking: boolean;
  424. inVOnce: boolean;
  425. needArraySpread: boolean;
  426. }
  427. export interface MemoExpression extends CallExpression {
  428. callee: typeof WITH_MEMO;
  429. arguments: [ExpressionNode, MemoFactory, string, string];
  430. }
  431. interface MemoFactory extends FunctionExpression {
  432. returns: BlockCodegenNode;
  433. }
  434. export type SSRCodegenNode = BlockStatement | TemplateLiteral | IfStatement | AssignmentExpression | ReturnStatement | SequenceExpression;
  435. export interface BlockStatement extends Node {
  436. type: NodeTypes.JS_BLOCK_STATEMENT;
  437. body: (JSChildNode | IfStatement)[];
  438. }
  439. export interface TemplateLiteral extends Node {
  440. type: NodeTypes.JS_TEMPLATE_LITERAL;
  441. elements: (string | JSChildNode)[];
  442. }
  443. export interface IfStatement extends Node {
  444. type: NodeTypes.JS_IF_STATEMENT;
  445. test: ExpressionNode;
  446. consequent: BlockStatement;
  447. alternate: IfStatement | BlockStatement | ReturnStatement | undefined;
  448. }
  449. export interface AssignmentExpression extends Node {
  450. type: NodeTypes.JS_ASSIGNMENT_EXPRESSION;
  451. left: SimpleExpressionNode;
  452. right: JSChildNode;
  453. }
  454. export interface SequenceExpression extends Node {
  455. type: NodeTypes.JS_SEQUENCE_EXPRESSION;
  456. expressions: JSChildNode[];
  457. }
  458. export interface ReturnStatement extends Node {
  459. type: NodeTypes.JS_RETURN_STATEMENT;
  460. returns: TemplateChildNode | TemplateChildNode[] | JSChildNode;
  461. }
  462. export interface DirectiveArguments extends ArrayExpression {
  463. elements: DirectiveArgumentNode[];
  464. }
  465. export interface DirectiveArgumentNode extends ArrayExpression {
  466. elements: [string] | [string, ExpressionNode] | [string, ExpressionNode, ExpressionNode] | [string, ExpressionNode, ExpressionNode, ObjectExpression];
  467. }
  468. export interface RenderSlotCall extends CallExpression {
  469. callee: typeof RENDER_SLOT;
  470. arguments: [string, string | ExpressionNode] | [string, string | ExpressionNode, PropsExpression] | [
  471. string,
  472. string | ExpressionNode,
  473. PropsExpression | '{}',
  474. TemplateChildNode[]
  475. ];
  476. }
  477. export type SlotsExpression = SlotsObjectExpression | DynamicSlotsExpression;
  478. export interface SlotsObjectExpression extends ObjectExpression {
  479. properties: SlotsObjectProperty[];
  480. }
  481. export interface SlotsObjectProperty extends Property {
  482. value: SlotFunctionExpression;
  483. }
  484. export interface SlotFunctionExpression extends FunctionExpression {
  485. returns: TemplateChildNode[] | CacheExpression;
  486. }
  487. export interface DynamicSlotsExpression extends CallExpression {
  488. callee: typeof CREATE_SLOTS;
  489. arguments: [SlotsObjectExpression, DynamicSlotEntries];
  490. }
  491. export interface DynamicSlotEntries extends ArrayExpression {
  492. elements: (ConditionalDynamicSlotNode | ListDynamicSlotNode)[];
  493. }
  494. export interface ConditionalDynamicSlotNode extends ConditionalExpression {
  495. consequent: DynamicSlotNode;
  496. alternate: DynamicSlotNode | SimpleExpressionNode;
  497. }
  498. export interface ListDynamicSlotNode extends CallExpression {
  499. callee: typeof RENDER_LIST;
  500. arguments: [ExpressionNode, ListDynamicSlotIterator];
  501. }
  502. export interface ListDynamicSlotIterator extends FunctionExpression {
  503. returns: DynamicSlotNode;
  504. }
  505. export interface DynamicSlotNode extends ObjectExpression {
  506. properties: [Property, DynamicSlotFnProperty];
  507. }
  508. export interface DynamicSlotFnProperty extends Property {
  509. value: SlotFunctionExpression;
  510. }
  511. export type BlockCodegenNode = VNodeCall | RenderSlotCall;
  512. export interface IfConditionalExpression extends ConditionalExpression {
  513. consequent: BlockCodegenNode | MemoExpression;
  514. alternate: BlockCodegenNode | IfConditionalExpression | MemoExpression;
  515. }
  516. export interface ForCodegenNode extends VNodeCall {
  517. isBlock: true;
  518. tag: typeof FRAGMENT;
  519. props: undefined;
  520. children: ForRenderListExpression;
  521. patchFlag: PatchFlags;
  522. disableTracking: boolean;
  523. }
  524. export interface ForRenderListExpression extends CallExpression {
  525. callee: typeof RENDER_LIST;
  526. arguments: [ExpressionNode, ForIteratorExpression];
  527. }
  528. export interface ForIteratorExpression extends FunctionExpression {
  529. returns?: BlockCodegenNode;
  530. }
  531. export declare const locStub: SourceLocation;
  532. export declare function createRoot(children: TemplateChildNode[], source?: string): RootNode;
  533. export declare function createVNodeCall(context: TransformContext | null, tag: VNodeCall['tag'], props?: VNodeCall['props'], children?: VNodeCall['children'], patchFlag?: VNodeCall['patchFlag'], dynamicProps?: VNodeCall['dynamicProps'], directives?: VNodeCall['directives'], isBlock?: VNodeCall['isBlock'], disableTracking?: VNodeCall['disableTracking'], isComponent?: VNodeCall['isComponent'], loc?: SourceLocation): VNodeCall;
  534. export declare function createArrayExpression(elements: ArrayExpression['elements'], loc?: SourceLocation): ArrayExpression;
  535. export declare function createObjectExpression(properties: ObjectExpression['properties'], loc?: SourceLocation): ObjectExpression;
  536. export declare function createObjectProperty(key: Property['key'] | string, value: Property['value']): Property;
  537. export declare function createSimpleExpression(content: SimpleExpressionNode['content'], isStatic?: SimpleExpressionNode['isStatic'], loc?: SourceLocation, constType?: ConstantTypes): SimpleExpressionNode;
  538. export declare function createInterpolation(content: InterpolationNode['content'] | string, loc: SourceLocation): InterpolationNode;
  539. export declare function createCompoundExpression(children: CompoundExpressionNode['children'], loc?: SourceLocation): CompoundExpressionNode;
  540. type InferCodegenNodeType<T> = T extends typeof RENDER_SLOT ? RenderSlotCall : CallExpression;
  541. export declare function createCallExpression<T extends CallExpression['callee']>(callee: T, args?: CallExpression['arguments'], loc?: SourceLocation): InferCodegenNodeType<T>;
  542. export declare function createFunctionExpression(params: FunctionExpression['params'], returns?: FunctionExpression['returns'], newline?: boolean, isSlot?: boolean, loc?: SourceLocation): FunctionExpression;
  543. export declare function createConditionalExpression(test: ConditionalExpression['test'], consequent: ConditionalExpression['consequent'], alternate: ConditionalExpression['alternate'], newline?: boolean): ConditionalExpression;
  544. export declare function createCacheExpression(index: number, value: JSChildNode, needPauseTracking?: boolean, inVOnce?: boolean): CacheExpression;
  545. export declare function createBlockStatement(body: BlockStatement['body']): BlockStatement;
  546. export declare function createTemplateLiteral(elements: TemplateLiteral['elements']): TemplateLiteral;
  547. export declare function createIfStatement(test: IfStatement['test'], consequent: IfStatement['consequent'], alternate?: IfStatement['alternate']): IfStatement;
  548. export declare function createAssignmentExpression(left: AssignmentExpression['left'], right: AssignmentExpression['right']): AssignmentExpression;
  549. export declare function createSequenceExpression(expressions: SequenceExpression['expressions']): SequenceExpression;
  550. export declare function createReturnStatement(returns: ReturnStatement['returns']): ReturnStatement;
  551. export declare function getVNodeHelper(ssr: boolean, isComponent: boolean): typeof CREATE_VNODE | typeof CREATE_ELEMENT_VNODE;
  552. export declare function getVNodeBlockHelper(ssr: boolean, isComponent: boolean): typeof CREATE_BLOCK | typeof CREATE_ELEMENT_BLOCK;
  553. export declare function convertToBlock(node: VNodeCall, { helper, removeHelper, inSSR }: TransformContext): void;
  554. export interface CompilerError extends SyntaxError {
  555. code: number | string;
  556. loc?: SourceLocation;
  557. }
  558. export interface CoreCompilerError extends CompilerError {
  559. code: ErrorCodes;
  560. }
  561. type InferCompilerError<T> = T extends ErrorCodes ? CoreCompilerError : CompilerError;
  562. export declare function createCompilerError<T extends number>(code: T, loc?: SourceLocation, messages?: {
  563. [code: number]: string;
  564. }, additionalMessage?: string): InferCompilerError<T>;
  565. export declare enum ErrorCodes {
  566. ABRUPT_CLOSING_OF_EMPTY_COMMENT = 0,
  567. CDATA_IN_HTML_CONTENT = 1,
  568. DUPLICATE_ATTRIBUTE = 2,
  569. END_TAG_WITH_ATTRIBUTES = 3,
  570. END_TAG_WITH_TRAILING_SOLIDUS = 4,
  571. EOF_BEFORE_TAG_NAME = 5,
  572. EOF_IN_CDATA = 6,
  573. EOF_IN_COMMENT = 7,
  574. EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT = 8,
  575. EOF_IN_TAG = 9,
  576. INCORRECTLY_CLOSED_COMMENT = 10,
  577. INCORRECTLY_OPENED_COMMENT = 11,
  578. INVALID_FIRST_CHARACTER_OF_TAG_NAME = 12,
  579. MISSING_ATTRIBUTE_VALUE = 13,
  580. MISSING_END_TAG_NAME = 14,
  581. MISSING_WHITESPACE_BETWEEN_ATTRIBUTES = 15,
  582. NESTED_COMMENT = 16,
  583. UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME = 17,
  584. UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE = 18,
  585. UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME = 19,
  586. UNEXPECTED_NULL_CHARACTER = 20,
  587. UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME = 21,
  588. UNEXPECTED_SOLIDUS_IN_TAG = 22,
  589. X_INVALID_END_TAG = 23,
  590. X_MISSING_END_TAG = 24,
  591. X_MISSING_INTERPOLATION_END = 25,
  592. X_MISSING_DIRECTIVE_NAME = 26,
  593. X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END = 27,
  594. X_V_IF_NO_EXPRESSION = 28,
  595. X_V_IF_SAME_KEY = 29,
  596. X_V_ELSE_NO_ADJACENT_IF = 30,
  597. X_V_FOR_NO_EXPRESSION = 31,
  598. X_V_FOR_MALFORMED_EXPRESSION = 32,
  599. X_V_FOR_TEMPLATE_KEY_PLACEMENT = 33,
  600. X_V_BIND_NO_EXPRESSION = 34,
  601. X_V_ON_NO_EXPRESSION = 35,
  602. X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET = 36,
  603. X_V_SLOT_MIXED_SLOT_USAGE = 37,
  604. X_V_SLOT_DUPLICATE_SLOT_NAMES = 38,
  605. X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN = 39,
  606. X_V_SLOT_MISPLACED = 40,
  607. X_V_MODEL_NO_EXPRESSION = 41,
  608. X_V_MODEL_MALFORMED_EXPRESSION = 42,
  609. X_V_MODEL_ON_SCOPE_VARIABLE = 43,
  610. X_V_MODEL_ON_PROPS = 44,
  611. X_INVALID_EXPRESSION = 45,
  612. X_KEEP_ALIVE_INVALID_CHILDREN = 46,
  613. X_PREFIX_ID_NOT_SUPPORTED = 47,
  614. X_MODULE_MODE_NOT_SUPPORTED = 48,
  615. X_CACHE_HANDLER_NOT_SUPPORTED = 49,
  616. X_SCOPE_ID_NOT_SUPPORTED = 50,
  617. X_VNODE_HOOKS = 51,
  618. X_V_BIND_INVALID_SAME_NAME_ARGUMENT = 52,
  619. __EXTEND_POINT__ = 53
  620. }
  621. export declare const errorMessages: Record<ErrorCodes, string>;
  622. interface ErrorHandlingOptions {
  623. onWarn?: (warning: CompilerError) => void;
  624. onError?: (error: CompilerError) => void;
  625. }
  626. export interface ParserOptions extends ErrorHandlingOptions, CompilerCompatOptions {
  627. /**
  628. * Base mode is platform agnostic and only parses HTML-like template syntax,
  629. * treating all tags the same way. Specific tag parsing behavior can be
  630. * configured by higher-level compilers.
  631. *
  632. * HTML mode adds additional logic for handling special parsing behavior in
  633. * `<script>`, `<style>`,`<title>` and `<textarea>`.
  634. * The logic is handled inside compiler-core for efficiency.
  635. *
  636. * SFC mode treats content of all root-level tags except `<template>` as plain
  637. * text.
  638. */
  639. parseMode?: 'base' | 'html' | 'sfc';
  640. /**
  641. * Specify the root namespace to use when parsing a template.
  642. * Defaults to `Namespaces.HTML` (0).
  643. */
  644. ns?: Namespaces;
  645. /**
  646. * e.g. platform native elements, e.g. `<div>` for browsers
  647. */
  648. isNativeTag?: (tag: string) => boolean;
  649. /**
  650. * e.g. native elements that can self-close, e.g. `<img>`, `<br>`, `<hr>`
  651. */
  652. isVoidTag?: (tag: string) => boolean;
  653. /**
  654. * e.g. elements that should preserve whitespace inside, e.g. `<pre>`
  655. */
  656. isPreTag?: (tag: string) => boolean;
  657. /**
  658. * Elements that should ignore the first newline token per parinsg spec
  659. * e.g. `<textarea>` and `<pre>`
  660. */
  661. isIgnoreNewlineTag?: (tag: string) => boolean;
  662. /**
  663. * Platform-specific built-in components e.g. `<Transition>`
  664. */
  665. isBuiltInComponent?: (tag: string) => symbol | void;
  666. /**
  667. * Separate option for end users to extend the native elements list
  668. */
  669. isCustomElement?: (tag: string) => boolean | void;
  670. /**
  671. * Get tag namespace
  672. */
  673. getNamespace?: (tag: string, parent: ElementNode | undefined, rootNamespace: Namespace) => Namespace;
  674. /**
  675. * @default ['{{', '}}']
  676. */
  677. delimiters?: [string, string];
  678. /**
  679. * Whitespace handling strategy
  680. * @default 'condense'
  681. */
  682. whitespace?: 'preserve' | 'condense';
  683. /**
  684. * Only used for DOM compilers that runs in the browser.
  685. * In non-browser builds, this option is ignored.
  686. */
  687. decodeEntities?: (rawText: string, asAttr: boolean) => string;
  688. /**
  689. * Whether to keep comments in the templates AST.
  690. * This defaults to `true` in development and `false` in production builds.
  691. */
  692. comments?: boolean;
  693. /**
  694. * Parse JavaScript expressions with Babel.
  695. * @default false
  696. */
  697. prefixIdentifiers?: boolean;
  698. /**
  699. * A list of parser plugins to enable for `@babel/parser`, which is used to
  700. * parse expressions in bindings and interpolations.
  701. * https://babeljs.io/docs/en/next/babel-parser#plugins
  702. */
  703. expressionPlugins?: ParserPlugin[];
  704. }
  705. export type HoistTransform = (children: TemplateChildNode[], context: TransformContext, parent: ParentNode) => void;
  706. export declare enum BindingTypes {
  707. /**
  708. * returned from data()
  709. */
  710. DATA = "data",
  711. /**
  712. * declared as a prop
  713. */
  714. PROPS = "props",
  715. /**
  716. * a local alias of a `<script setup>` destructured prop.
  717. * the original is stored in __propsAliases of the bindingMetadata object.
  718. */
  719. PROPS_ALIASED = "props-aliased",
  720. /**
  721. * a let binding (may or may not be a ref)
  722. */
  723. SETUP_LET = "setup-let",
  724. /**
  725. * a const binding that can never be a ref.
  726. * these bindings don't need `unref()` calls when processed in inlined
  727. * template expressions.
  728. */
  729. SETUP_CONST = "setup-const",
  730. /**
  731. * a const binding that does not need `unref()`, but may be mutated.
  732. */
  733. SETUP_REACTIVE_CONST = "setup-reactive-const",
  734. /**
  735. * a const binding that may be a ref.
  736. */
  737. SETUP_MAYBE_REF = "setup-maybe-ref",
  738. /**
  739. * bindings that are guaranteed to be refs
  740. */
  741. SETUP_REF = "setup-ref",
  742. /**
  743. * declared by other options, e.g. computed, inject
  744. */
  745. OPTIONS = "options",
  746. /**
  747. * a literal constant, e.g. 'foo', 1, true
  748. */
  749. LITERAL_CONST = "literal-const"
  750. }
  751. export type BindingMetadata = {
  752. [key: string]: BindingTypes | undefined;
  753. } & {
  754. __isScriptSetup?: boolean;
  755. __propsAliases?: Record<string, string>;
  756. };
  757. interface SharedTransformCodegenOptions {
  758. /**
  759. * Transform expressions like {{ foo }} to `_ctx.foo`.
  760. * If this option is false, the generated code will be wrapped in a
  761. * `with (this) { ... }` block.
  762. * - This is force-enabled in module mode, since modules are by default strict
  763. * and cannot use `with`
  764. * @default mode === 'module'
  765. */
  766. prefixIdentifiers?: boolean;
  767. /**
  768. * Control whether generate SSR-optimized render functions instead.
  769. * The resulting function must be attached to the component via the
  770. * `ssrRender` option instead of `render`.
  771. *
  772. * When compiler generates code for SSR's fallback branch, we need to set it to false:
  773. * - context.ssr = false
  774. *
  775. * see `subTransform` in `ssrTransformComponent.ts`
  776. */
  777. ssr?: boolean;
  778. /**
  779. * Indicates whether the compiler generates code for SSR,
  780. * it is always true when generating code for SSR,
  781. * regardless of whether we are generating code for SSR's fallback branch,
  782. * this means that when the compiler generates code for SSR's fallback branch:
  783. * - context.ssr = false
  784. * - context.inSSR = true
  785. */
  786. inSSR?: boolean;
  787. /**
  788. * Optional binding metadata analyzed from script - used to optimize
  789. * binding access when `prefixIdentifiers` is enabled.
  790. */
  791. bindingMetadata?: BindingMetadata;
  792. /**
  793. * Compile the function for inlining inside setup().
  794. * This allows the function to directly access setup() local bindings.
  795. */
  796. inline?: boolean;
  797. /**
  798. * Indicates that transforms and codegen should try to output valid TS code
  799. */
  800. isTS?: boolean;
  801. /**
  802. * Filename for source map generation.
  803. * Also used for self-recursive reference in templates
  804. * @default 'template.vue.html'
  805. */
  806. filename?: string;
  807. }
  808. export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHandlingOptions, CompilerCompatOptions {
  809. /**
  810. * An array of node transforms to be applied to every AST node.
  811. */
  812. nodeTransforms?: NodeTransform[];
  813. /**
  814. * An object of { name: transform } to be applied to every directive attribute
  815. * node found on element nodes.
  816. */
  817. directiveTransforms?: Record<string, DirectiveTransform | undefined>;
  818. /**
  819. * An optional hook to transform a node being hoisted.
  820. * used by compiler-dom to turn hoisted nodes into stringified HTML vnodes.
  821. * @default null
  822. */
  823. transformHoist?: HoistTransform | null;
  824. /**
  825. * If the pairing runtime provides additional built-in elements, use this to
  826. * mark them as built-in so the compiler will generate component vnodes
  827. * for them.
  828. */
  829. isBuiltInComponent?: (tag: string) => symbol | void;
  830. /**
  831. * Used by some transforms that expects only native elements
  832. */
  833. isCustomElement?: (tag: string) => boolean | void;
  834. /**
  835. * Transform expressions like {{ foo }} to `_ctx.foo`.
  836. * If this option is false, the generated code will be wrapped in a
  837. * `with (this) { ... }` block.
  838. * - This is force-enabled in module mode, since modules are by default strict
  839. * and cannot use `with`
  840. * @default mode === 'module'
  841. */
  842. prefixIdentifiers?: boolean;
  843. /**
  844. * Cache static VNodes and props objects to `_hoisted_x` constants
  845. * @default false
  846. */
  847. hoistStatic?: boolean;
  848. /**
  849. * Cache v-on handlers to avoid creating new inline functions on each render,
  850. * also avoids the need for dynamically patching the handlers by wrapping it.
  851. * e.g `@click="foo"` by default is compiled to `{ onClick: foo }`. With this
  852. * option it's compiled to:
  853. * ```js
  854. * { onClick: _cache[0] || (_cache[0] = e => _ctx.foo(e)) }
  855. * ```
  856. * - Requires "prefixIdentifiers" to be enabled because it relies on scope
  857. * analysis to determine if a handler is safe to cache.
  858. * @default false
  859. */
  860. cacheHandlers?: boolean;
  861. /**
  862. * A list of parser plugins to enable for `@babel/parser`, which is used to
  863. * parse expressions in bindings and interpolations.
  864. * https://babeljs.io/docs/en/next/babel-parser#plugins
  865. */
  866. expressionPlugins?: ParserPlugin[];
  867. /**
  868. * SFC scoped styles ID
  869. */
  870. scopeId?: string | null;
  871. /**
  872. * Indicates this SFC template has used :slotted in its styles
  873. * Defaults to `true` for backwards compatibility - SFC tooling should set it
  874. * to `false` if no `:slotted` usage is detected in `<style>`
  875. */
  876. slotted?: boolean;
  877. /**
  878. * SFC `<style vars>` injection string
  879. * Should already be an object expression, e.g. `{ 'xxxx-color': color }`
  880. * needed to render inline CSS variables on component root
  881. */
  882. ssrCssVars?: string;
  883. /**
  884. * Whether to compile the template assuming it needs to handle HMR.
  885. * Some edge cases may need to generate different code for HMR to work
  886. * correctly, e.g. #6938, #7138
  887. */
  888. hmr?: boolean;
  889. }
  890. export interface CodegenOptions extends SharedTransformCodegenOptions {
  891. /**
  892. * - `module` mode will generate ES module import statements for helpers
  893. * and export the render function as the default export.
  894. * - `function` mode will generate a single `const { helpers... } = Vue`
  895. * statement and return the render function. It expects `Vue` to be globally
  896. * available (or passed by wrapping the code with an IIFE). It is meant to be
  897. * used with `new Function(code)()` to generate a render function at runtime.
  898. * @default 'function'
  899. */
  900. mode?: 'module' | 'function';
  901. /**
  902. * Generate source map?
  903. * @default false
  904. */
  905. sourceMap?: boolean;
  906. /**
  907. * SFC scoped styles ID
  908. */
  909. scopeId?: string | null;
  910. /**
  911. * Option to optimize helper import bindings via variable assignment
  912. * (only used for webpack code-split)
  913. * @default false
  914. */
  915. optimizeImports?: boolean;
  916. /**
  917. * Customize where to import runtime helpers from.
  918. * @default 'vue'
  919. */
  920. runtimeModuleName?: string;
  921. /**
  922. * Customize where to import ssr runtime helpers from/**
  923. * @default 'vue/server-renderer'
  924. */
  925. ssrRuntimeModuleName?: string;
  926. /**
  927. * Customize the global variable name of `Vue` to get helpers from
  928. * in function mode
  929. * @default 'Vue'
  930. */
  931. runtimeGlobalName?: string;
  932. }
  933. export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions;
  934. /**
  935. * The `SourceMapGenerator` type from `source-map-js` is a bit incomplete as it
  936. * misses `toJSON()`. We also need to add types for internal properties which we
  937. * need to access for better performance.
  938. *
  939. * Since TS 5.3, dts generation starts to strangely include broken triple slash
  940. * references for source-map-js, so we are inlining all source map related types
  941. * here to to workaround that.
  942. */
  943. export interface CodegenSourceMapGenerator {
  944. setSourceContent(sourceFile: string, sourceContent: string): void;
  945. toJSON(): RawSourceMap;
  946. _sources: Set<string>;
  947. _names: Set<string>;
  948. _mappings: {
  949. add(mapping: MappingItem): void;
  950. };
  951. }
  952. export interface RawSourceMap {
  953. file?: string;
  954. sourceRoot?: string;
  955. version: string;
  956. sources: string[];
  957. names: string[];
  958. sourcesContent?: string[];
  959. mappings: string;
  960. }
  961. interface MappingItem {
  962. source: string;
  963. generatedLine: number;
  964. generatedColumn: number;
  965. originalLine: number;
  966. originalColumn: number;
  967. name: string | null;
  968. }
  969. type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode;
  970. export interface CodegenResult {
  971. code: string;
  972. preamble: string;
  973. ast: RootNode;
  974. map?: RawSourceMap;
  975. }
  976. export interface CodegenContext extends Omit<Required<CodegenOptions>, 'bindingMetadata' | 'inline'> {
  977. source: string;
  978. code: string;
  979. line: number;
  980. column: number;
  981. offset: number;
  982. indentLevel: number;
  983. pure: boolean;
  984. map?: CodegenSourceMapGenerator;
  985. helper(key: symbol): string;
  986. push(code: string, newlineIndex?: number, node?: CodegenNode): void;
  987. indent(): void;
  988. deindent(withoutNewLine?: boolean): void;
  989. newline(): void;
  990. }
  991. export declare function generate(ast: RootNode, options?: CodegenOptions & {
  992. onContextCreated?: (context: CodegenContext) => void;
  993. }): CodegenResult;
  994. export type TransformPreset = [
  995. NodeTransform[],
  996. Record<string, DirectiveTransform>
  997. ];
  998. export declare function getBaseTransformPreset(prefixIdentifiers?: boolean): TransformPreset;
  999. export declare function baseCompile(source: string | RootNode, options?: CompilerOptions): CodegenResult;
  1000. export declare const isStaticExp: (p: JSChildNode) => p is SimpleExpressionNode;
  1001. export declare function isCoreComponent(tag: string): symbol | void;
  1002. export declare const isSimpleIdentifier: (name: string) => boolean;
  1003. /**
  1004. * Simple lexer to check if an expression is a member expression. This is
  1005. * lax and only checks validity at the root level (i.e. does not validate exps
  1006. * inside square brackets), but it's ok since these are only used on template
  1007. * expressions and false positives are invalid expressions in the first place.
  1008. */
  1009. export declare const isMemberExpressionBrowser: (exp: ExpressionNode) => boolean;
  1010. export declare const isMemberExpressionNode: (exp: ExpressionNode, context: TransformContext) => boolean;
  1011. export declare const isMemberExpression: (exp: ExpressionNode, context: TransformContext) => boolean;
  1012. export declare const isFnExpressionBrowser: (exp: ExpressionNode) => boolean;
  1013. export declare const isFnExpressionNode: (exp: ExpressionNode, context: TransformContext) => boolean;
  1014. export declare const isFnExpression: (exp: ExpressionNode, context: TransformContext) => boolean;
  1015. export declare function advancePositionWithClone(pos: Position, source: string, numberOfCharacters?: number): Position;
  1016. export declare function advancePositionWithMutation(pos: Position, source: string, numberOfCharacters?: number): Position;
  1017. export declare function assert(condition: boolean, msg?: string): void;
  1018. export declare function findDir(node: ElementNode, name: string | RegExp, allowEmpty?: boolean): DirectiveNode | undefined;
  1019. export declare function findProp(node: ElementNode, name: string, dynamicOnly?: boolean, allowEmpty?: boolean): ElementNode['props'][0] | undefined;
  1020. export declare function isStaticArgOf(arg: DirectiveNode['arg'], name: string): boolean;
  1021. export declare function hasDynamicKeyVBind(node: ElementNode): boolean;
  1022. export declare function isText(node: TemplateChildNode): node is TextNode | InterpolationNode;
  1023. export declare function isVSlot(p: ElementNode['props'][0]): p is DirectiveNode;
  1024. export declare function isTemplateNode(node: RootNode | TemplateChildNode): node is TemplateNode;
  1025. export declare function isSlotOutlet(node: RootNode | TemplateChildNode): node is SlotOutletNode;
  1026. export declare function injectProp(node: VNodeCall | RenderSlotCall, prop: Property, context: TransformContext): void;
  1027. export declare function toValidAssetId(name: string, type: 'component' | 'directive' | 'filter'): string;
  1028. export declare function hasScopeRef(node: TemplateChildNode | IfBranchNode | ExpressionNode | CacheExpression | undefined, ids: TransformContext['identifiers']): boolean;
  1029. export declare function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression): VNodeCall | RenderSlotCall;
  1030. export declare const forAliasRE: RegExp;
  1031. /**
  1032. * Return value indicates whether the AST walked can be a constant
  1033. */
  1034. export declare function walkIdentifiers(root: Node$1, onIdentifier: (node: Identifier, parent: Node$1 | null, parentStack: Node$1[], isReference: boolean, isLocal: boolean) => void, includeAll?: boolean, parentStack?: Node$1[], knownIds?: Record<string, number>): void;
  1035. export declare function isReferencedIdentifier(id: Identifier, parent: Node$1 | null, parentStack: Node$1[]): boolean;
  1036. export declare function isInDestructureAssignment(parent: Node$1, parentStack: Node$1[]): boolean;
  1037. export declare function isInNewExpression(parentStack: Node$1[]): boolean;
  1038. export declare function walkFunctionParams(node: Function, onIdent: (id: Identifier) => void): void;
  1039. export declare function walkBlockDeclarations(block: BlockStatement$1 | Program, onIdent: (node: Identifier) => void): void;
  1040. export declare function extractIdentifiers(param: Node$1, nodes?: Identifier[]): Identifier[];
  1041. export declare const isFunctionType: (node: Node$1) => node is Function;
  1042. export declare const isStaticProperty: (node: Node$1) => node is ObjectProperty;
  1043. export declare const isStaticPropertyKey: (node: Node$1, parent: Node$1) => boolean;
  1044. export declare const TS_NODE_TYPES: string[];
  1045. export declare function unwrapTSNode(node: Node$1): Node$1;
  1046. export declare const transformModel: DirectiveTransform;
  1047. export declare const transformOn: DirectiveTransform;
  1048. export declare const transformBind: DirectiveTransform;
  1049. export declare const noopDirectiveTransform: DirectiveTransform;
  1050. export declare function processIf(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (node: IfNode, branch: IfBranchNode, isRoot: boolean) => (() => void) | undefined): (() => void) | undefined;
  1051. export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
  1052. export declare function createForLoopParams({ value, key, index }: ForParseResult, memoArgs?: ExpressionNode[]): ExpressionNode[];
  1053. export declare const transformExpression: NodeTransform;
  1054. export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean, localVars?: Record<string, number>): ExpressionNode;
  1055. export declare function stringifyExpression(exp: ExpressionNode | string): string;
  1056. export declare const trackSlotScopes: NodeTransform;
  1057. export declare const trackVForSlotScopes: NodeTransform;
  1058. export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, vFor: DirectiveNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
  1059. export declare function buildSlots(node: ElementNode, context: TransformContext, buildSlotFn?: SlotFnBuilder): {
  1060. slots: SlotsExpression;
  1061. hasDynamicSlots: boolean;
  1062. };
  1063. interface SlotOutletProcessResult {
  1064. slotName: string | ExpressionNode;
  1065. slotProps: PropsExpression | undefined;
  1066. }
  1067. export declare function processSlotOutlet(node: SlotOutletNode, context: TransformContext): SlotOutletProcessResult;
  1068. export declare function getConstantType(node: TemplateChildNode | SimpleExpressionNode | CacheExpression, context: TransformContext): ConstantTypes;