compiler-core.d.ts 45 KB

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