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. 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_V_MODEL_ON_CONST = 45,
  612. X_INVALID_EXPRESSION = 46,
  613. X_KEEP_ALIVE_INVALID_CHILDREN = 47,
  614. X_PREFIX_ID_NOT_SUPPORTED = 48,
  615. X_MODULE_MODE_NOT_SUPPORTED = 49,
  616. X_CACHE_HANDLER_NOT_SUPPORTED = 50,
  617. X_SCOPE_ID_NOT_SUPPORTED = 51,
  618. X_VNODE_HOOKS = 52,
  619. X_V_BIND_INVALID_SAME_NAME_ARGUMENT = 53,
  620. __EXTEND_POINT__ = 54
  621. }
  622. export declare const errorMessages: Record<ErrorCodes, string>;
  623. interface ErrorHandlingOptions {
  624. onWarn?: (warning: CompilerError) => void;
  625. onError?: (error: CompilerError) => void;
  626. }
  627. export interface ParserOptions extends ErrorHandlingOptions, CompilerCompatOptions {
  628. /**
  629. * Base mode is platform agnostic and only parses HTML-like template syntax,
  630. * treating all tags the same way. Specific tag parsing behavior can be
  631. * configured by higher-level compilers.
  632. *
  633. * HTML mode adds additional logic for handling special parsing behavior in
  634. * `<script>`, `<style>`,`<title>` and `<textarea>`.
  635. * The logic is handled inside compiler-core for efficiency.
  636. *
  637. * SFC mode treats content of all root-level tags except `<template>` as plain
  638. * text.
  639. */
  640. parseMode?: 'base' | 'html' | 'sfc';
  641. /**
  642. * Specify the root namespace to use when parsing a template.
  643. * Defaults to `Namespaces.HTML` (0).
  644. */
  645. ns?: Namespaces;
  646. /**
  647. * e.g. platform native elements, e.g. `<div>` for browsers
  648. */
  649. isNativeTag?: (tag: string) => boolean;
  650. /**
  651. * e.g. native elements that can self-close, e.g. `<img>`, `<br>`, `<hr>`
  652. */
  653. isVoidTag?: (tag: string) => boolean;
  654. /**
  655. * e.g. elements that should preserve whitespace inside, e.g. `<pre>`
  656. */
  657. isPreTag?: (tag: string) => boolean;
  658. /**
  659. * Elements that should ignore the first newline token per parinsg spec
  660. * e.g. `<textarea>` and `<pre>`
  661. */
  662. isIgnoreNewlineTag?: (tag: string) => boolean;
  663. /**
  664. * Platform-specific built-in components e.g. `<Transition>`
  665. */
  666. isBuiltInComponent?: (tag: string) => symbol | void;
  667. /**
  668. * Separate option for end users to extend the native elements list
  669. */
  670. isCustomElement?: (tag: string) => boolean | void;
  671. /**
  672. * Get tag namespace
  673. */
  674. getNamespace?: (tag: string, parent: ElementNode | undefined, rootNamespace: Namespace) => Namespace;
  675. /**
  676. * @default ['{{', '}}']
  677. */
  678. delimiters?: [string, string];
  679. /**
  680. * Whitespace handling strategy
  681. * @default 'condense'
  682. */
  683. whitespace?: 'preserve' | 'condense';
  684. /**
  685. * Only used for DOM compilers that runs in the browser.
  686. * In non-browser builds, this option is ignored.
  687. */
  688. decodeEntities?: (rawText: string, asAttr: boolean) => string;
  689. /**
  690. * Whether to keep comments in the templates AST.
  691. * This defaults to `true` in development and `false` in production builds.
  692. */
  693. comments?: boolean;
  694. /**
  695. * Parse JavaScript expressions with Babel.
  696. * @default false
  697. */
  698. prefixIdentifiers?: boolean;
  699. /**
  700. * A list of parser plugins to enable for `@babel/parser`, which is used to
  701. * parse expressions in bindings and interpolations.
  702. * https://babeljs.io/docs/en/next/babel-parser#plugins
  703. */
  704. expressionPlugins?: ParserPlugin[];
  705. }
  706. export type HoistTransform = (children: TemplateChildNode[], context: TransformContext, parent: ParentNode) => void;
  707. export declare enum BindingTypes {
  708. /**
  709. * returned from data()
  710. */
  711. DATA = "data",
  712. /**
  713. * declared as a prop
  714. */
  715. PROPS = "props",
  716. /**
  717. * a local alias of a `<script setup>` destructured prop.
  718. * the original is stored in __propsAliases of the bindingMetadata object.
  719. */
  720. PROPS_ALIASED = "props-aliased",
  721. /**
  722. * a let binding (may or may not be a ref)
  723. */
  724. SETUP_LET = "setup-let",
  725. /**
  726. * a const binding that can never be a ref.
  727. * these bindings don't need `unref()` calls when processed in inlined
  728. * template expressions.
  729. */
  730. SETUP_CONST = "setup-const",
  731. /**
  732. * a const binding that does not need `unref()`, but may be mutated.
  733. */
  734. SETUP_REACTIVE_CONST = "setup-reactive-const",
  735. /**
  736. * a const binding that may be a ref.
  737. */
  738. SETUP_MAYBE_REF = "setup-maybe-ref",
  739. /**
  740. * bindings that are guaranteed to be refs
  741. */
  742. SETUP_REF = "setup-ref",
  743. /**
  744. * declared by other options, e.g. computed, inject
  745. */
  746. OPTIONS = "options",
  747. /**
  748. * a literal constant, e.g. 'foo', 1, true
  749. */
  750. LITERAL_CONST = "literal-const"
  751. }
  752. export type BindingMetadata = {
  753. [key: string]: BindingTypes | undefined;
  754. } & {
  755. __isScriptSetup?: boolean;
  756. __propsAliases?: Record<string, string>;
  757. };
  758. interface SharedTransformCodegenOptions {
  759. /**
  760. * Transform expressions like {{ foo }} to `_ctx.foo`.
  761. * If this option is false, the generated code will be wrapped in a
  762. * `with (this) { ... }` block.
  763. * - This is force-enabled in module mode, since modules are by default strict
  764. * and cannot use `with`
  765. * @default mode === 'module'
  766. */
  767. prefixIdentifiers?: boolean;
  768. /**
  769. * Control whether generate SSR-optimized render functions instead.
  770. * The resulting function must be attached to the component via the
  771. * `ssrRender` option instead of `render`.
  772. *
  773. * When compiler generates code for SSR's fallback branch, we need to set it to false:
  774. * - context.ssr = false
  775. *
  776. * see `subTransform` in `ssrTransformComponent.ts`
  777. */
  778. ssr?: boolean;
  779. /**
  780. * Indicates whether the compiler generates code for SSR,
  781. * it is always true when generating code for SSR,
  782. * regardless of whether we are generating code for SSR's fallback branch,
  783. * this means that when the compiler generates code for SSR's fallback branch:
  784. * - context.ssr = false
  785. * - context.inSSR = true
  786. */
  787. inSSR?: boolean;
  788. /**
  789. * Optional binding metadata analyzed from script - used to optimize
  790. * binding access when `prefixIdentifiers` is enabled.
  791. */
  792. bindingMetadata?: BindingMetadata;
  793. /**
  794. * Compile the function for inlining inside setup().
  795. * This allows the function to directly access setup() local bindings.
  796. */
  797. inline?: boolean;
  798. /**
  799. * Indicates that transforms and codegen should try to output valid TS code
  800. */
  801. isTS?: boolean;
  802. /**
  803. * Filename for source map generation.
  804. * Also used for self-recursive reference in templates
  805. * @default 'template.vue.html'
  806. */
  807. filename?: string;
  808. }
  809. export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHandlingOptions, CompilerCompatOptions {
  810. /**
  811. * An array of node transforms to be applied to every AST node.
  812. */
  813. nodeTransforms?: NodeTransform[];
  814. /**
  815. * An object of { name: transform } to be applied to every directive attribute
  816. * node found on element nodes.
  817. */
  818. directiveTransforms?: Record<string, DirectiveTransform | undefined>;
  819. /**
  820. * An optional hook to transform a node being hoisted.
  821. * used by compiler-dom to turn hoisted nodes into stringified HTML vnodes.
  822. * @default null
  823. */
  824. transformHoist?: HoistTransform | null;
  825. /**
  826. * If the pairing runtime provides additional built-in elements, use this to
  827. * mark them as built-in so the compiler will generate component vnodes
  828. * for them.
  829. */
  830. isBuiltInComponent?: (tag: string) => symbol | void;
  831. /**
  832. * Used by some transforms that expects only native elements
  833. */
  834. isCustomElement?: (tag: string) => boolean | void;
  835. /**
  836. * Transform expressions like {{ foo }} to `_ctx.foo`.
  837. * If this option is false, the generated code will be wrapped in a
  838. * `with (this) { ... }` block.
  839. * - This is force-enabled in module mode, since modules are by default strict
  840. * and cannot use `with`
  841. * @default mode === 'module'
  842. */
  843. prefixIdentifiers?: boolean;
  844. /**
  845. * Cache static VNodes and props objects to `_hoisted_x` constants
  846. * @default false
  847. */
  848. hoistStatic?: boolean;
  849. /**
  850. * Cache v-on handlers to avoid creating new inline functions on each render,
  851. * also avoids the need for dynamically patching the handlers by wrapping it.
  852. * e.g `@click="foo"` by default is compiled to `{ onClick: foo }`. With this
  853. * option it's compiled to:
  854. * ```js
  855. * { onClick: _cache[0] || (_cache[0] = e => _ctx.foo(e)) }
  856. * ```
  857. * - Requires "prefixIdentifiers" to be enabled because it relies on scope
  858. * analysis to determine if a handler is safe to cache.
  859. * @default false
  860. */
  861. cacheHandlers?: boolean;
  862. /**
  863. * A list of parser plugins to enable for `@babel/parser`, which is used to
  864. * parse expressions in bindings and interpolations.
  865. * https://babeljs.io/docs/en/next/babel-parser#plugins
  866. */
  867. expressionPlugins?: ParserPlugin[];
  868. /**
  869. * SFC scoped styles ID
  870. */
  871. scopeId?: string | null;
  872. /**
  873. * Indicates this SFC template has used :slotted in its styles
  874. * Defaults to `true` for backwards compatibility - SFC tooling should set it
  875. * to `false` if no `:slotted` usage is detected in `<style>`
  876. */
  877. slotted?: boolean;
  878. /**
  879. * SFC `<style vars>` injection string
  880. * Should already be an object expression, e.g. `{ 'xxxx-color': color }`
  881. * needed to render inline CSS variables on component root
  882. */
  883. ssrCssVars?: string;
  884. /**
  885. * Whether to compile the template assuming it needs to handle HMR.
  886. * Some edge cases may need to generate different code for HMR to work
  887. * correctly, e.g. #6938, #7138
  888. */
  889. hmr?: boolean;
  890. }
  891. export interface CodegenOptions extends SharedTransformCodegenOptions {
  892. /**
  893. * - `module` mode will generate ES module import statements for helpers
  894. * and export the render function as the default export.
  895. * - `function` mode will generate a single `const { helpers... } = Vue`
  896. * statement and return the render function. It expects `Vue` to be globally
  897. * available (or passed by wrapping the code with an IIFE). It is meant to be
  898. * used with `new Function(code)()` to generate a render function at runtime.
  899. * @default 'function'
  900. */
  901. mode?: 'module' | 'function';
  902. /**
  903. * Generate source map?
  904. * @default false
  905. */
  906. sourceMap?: boolean;
  907. /**
  908. * SFC scoped styles ID
  909. */
  910. scopeId?: string | null;
  911. /**
  912. * Option to optimize helper import bindings via variable assignment
  913. * (only used for webpack code-split)
  914. * @default false
  915. */
  916. optimizeImports?: boolean;
  917. /**
  918. * Customize where to import runtime helpers from.
  919. * @default 'vue'
  920. */
  921. runtimeModuleName?: string;
  922. /**
  923. * Customize where to import ssr runtime helpers from/**
  924. * @default 'vue/server-renderer'
  925. */
  926. ssrRuntimeModuleName?: string;
  927. /**
  928. * Customize the global variable name of `Vue` to get helpers from
  929. * in function mode
  930. * @default 'Vue'
  931. */
  932. runtimeGlobalName?: string;
  933. }
  934. export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions;
  935. /**
  936. * The `SourceMapGenerator` type from `source-map-js` is a bit incomplete as it
  937. * misses `toJSON()`. We also need to add types for internal properties which we
  938. * need to access for better performance.
  939. *
  940. * Since TS 5.3, dts generation starts to strangely include broken triple slash
  941. * references for source-map-js, so we are inlining all source map related types
  942. * here to to workaround that.
  943. */
  944. export interface CodegenSourceMapGenerator {
  945. setSourceContent(sourceFile: string, sourceContent: string): void;
  946. toJSON(): RawSourceMap;
  947. _sources: Set<string>;
  948. _names: Set<string>;
  949. _mappings: {
  950. add(mapping: MappingItem): void;
  951. };
  952. }
  953. export interface RawSourceMap {
  954. file?: string;
  955. sourceRoot?: string;
  956. version: string;
  957. sources: string[];
  958. names: string[];
  959. sourcesContent?: string[];
  960. mappings: string;
  961. }
  962. interface MappingItem {
  963. source: string;
  964. generatedLine: number;
  965. generatedColumn: number;
  966. originalLine: number;
  967. originalColumn: number;
  968. name: string | null;
  969. }
  970. type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode;
  971. export interface CodegenResult {
  972. code: string;
  973. preamble: string;
  974. ast: RootNode;
  975. map?: RawSourceMap;
  976. }
  977. export interface CodegenContext extends Omit<Required<CodegenOptions>, 'bindingMetadata' | 'inline'> {
  978. source: string;
  979. code: string;
  980. line: number;
  981. column: number;
  982. offset: number;
  983. indentLevel: number;
  984. pure: boolean;
  985. map?: CodegenSourceMapGenerator;
  986. helper(key: symbol): string;
  987. push(code: string, newlineIndex?: number, node?: CodegenNode): void;
  988. indent(): void;
  989. deindent(withoutNewLine?: boolean): void;
  990. newline(): void;
  991. }
  992. export declare function generate(ast: RootNode, options?: CodegenOptions & {
  993. onContextCreated?: (context: CodegenContext) => void;
  994. }): CodegenResult;
  995. export type TransformPreset = [
  996. NodeTransform[],
  997. Record<string, DirectiveTransform>
  998. ];
  999. export declare function getBaseTransformPreset(prefixIdentifiers?: boolean): TransformPreset;
  1000. export declare function baseCompile(source: string | RootNode, options?: CompilerOptions): CodegenResult;
  1001. export declare const isStaticExp: (p: JSChildNode) => p is SimpleExpressionNode;
  1002. export declare function isCoreComponent(tag: string): symbol | void;
  1003. export declare const isSimpleIdentifier: (name: string) => boolean;
  1004. export declare const validFirstIdentCharRE: RegExp;
  1005. /**
  1006. * Simple lexer to check if an expression is a member expression. This is
  1007. * lax and only checks validity at the root level (i.e. does not validate exps
  1008. * inside square brackets), but it's ok since these are only used on template
  1009. * expressions and false positives are invalid expressions in the first place.
  1010. */
  1011. export declare const isMemberExpressionBrowser: (exp: ExpressionNode) => boolean;
  1012. export declare const isMemberExpressionNode: (exp: ExpressionNode, context: TransformContext) => boolean;
  1013. export declare const isMemberExpression: (exp: ExpressionNode, context: TransformContext) => boolean;
  1014. export declare const isFnExpressionBrowser: (exp: ExpressionNode) => boolean;
  1015. export declare const isFnExpressionNode: (exp: ExpressionNode, context: TransformContext) => boolean;
  1016. export declare const isFnExpression: (exp: ExpressionNode, context: TransformContext) => boolean;
  1017. export declare function advancePositionWithClone(pos: Position, source: string, numberOfCharacters?: number): Position;
  1018. export declare function advancePositionWithMutation(pos: Position, source: string, numberOfCharacters?: number): Position;
  1019. export declare function assert(condition: boolean, msg?: string): void;
  1020. export declare function findDir(node: ElementNode, name: string | RegExp, allowEmpty?: boolean): DirectiveNode | undefined;
  1021. export declare function findProp(node: ElementNode, name: string, dynamicOnly?: boolean, allowEmpty?: boolean): ElementNode['props'][0] | undefined;
  1022. export declare function isStaticArgOf(arg: DirectiveNode['arg'], name: string): boolean;
  1023. export declare function hasDynamicKeyVBind(node: ElementNode): boolean;
  1024. export declare function isText(node: TemplateChildNode): node is TextNode | InterpolationNode;
  1025. export declare function isVPre(p: ElementNode['props'][0]): p is DirectiveNode;
  1026. export declare function isVSlot(p: ElementNode['props'][0]): p is DirectiveNode;
  1027. export declare function isTemplateNode(node: RootNode | TemplateChildNode): node is TemplateNode;
  1028. export declare function isSlotOutlet(node: RootNode | TemplateChildNode): node is SlotOutletNode;
  1029. export declare function injectProp(node: VNodeCall | RenderSlotCall, prop: Property, context: TransformContext): void;
  1030. export declare function toValidAssetId(name: string, type: 'component' | 'directive' | 'filter'): string;
  1031. export declare function hasScopeRef(node: TemplateChildNode | IfBranchNode | ExpressionNode | CacheExpression | undefined, ids: TransformContext['identifiers']): boolean;
  1032. export declare function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression): VNodeCall | RenderSlotCall;
  1033. export declare const forAliasRE: RegExp;
  1034. export declare function isAllWhitespace(str: string): boolean;
  1035. export declare function isWhitespaceText(node: TemplateChildNode): boolean;
  1036. export declare function isCommentOrWhitespace(node: TemplateChildNode): boolean;
  1037. /**
  1038. * Return value indicates whether the AST walked can be a constant
  1039. */
  1040. 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;
  1041. export declare function isReferencedIdentifier(id: Identifier, parent: Node$1 | null, parentStack: Node$1[]): boolean;
  1042. export declare function isInDestructureAssignment(parent: Node$1, parentStack: Node$1[]): boolean;
  1043. export declare function isInNewExpression(parentStack: Node$1[]): boolean;
  1044. export declare function walkFunctionParams(node: Function, onIdent: (id: Identifier) => void): void;
  1045. export declare function walkBlockDeclarations(block: BlockStatement$1 | SwitchCase | Program, onIdent: (node: Identifier) => void): void;
  1046. export declare function extractIdentifiers(param: Node$1, nodes?: Identifier[]): Identifier[];
  1047. export declare const isFunctionType: (node: Node$1) => node is Function;
  1048. export declare const isStaticProperty: (node: Node$1) => node is ObjectProperty;
  1049. export declare const isStaticPropertyKey: (node: Node$1, parent: Node$1) => boolean;
  1050. export declare const TS_NODE_TYPES: string[];
  1051. export declare function unwrapTSNode(node: Node$1): Node$1;
  1052. export declare const transformModel: DirectiveTransform;
  1053. export declare const transformOn: DirectiveTransform;
  1054. export declare const transformBind: DirectiveTransform;
  1055. export declare const noopDirectiveTransform: DirectiveTransform;
  1056. export declare function processIf(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (node: IfNode, branch: IfBranchNode, isRoot: boolean) => (() => void) | undefined): (() => void) | undefined;
  1057. export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
  1058. export declare function createForLoopParams({ value, key, index }: ForParseResult, memoArgs?: ExpressionNode[]): ExpressionNode[];
  1059. export declare const transformExpression: NodeTransform;
  1060. export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean, localVars?: Record<string, number>): ExpressionNode;
  1061. export declare function stringifyExpression(exp: ExpressionNode | string): string;
  1062. export declare const trackSlotScopes: NodeTransform;
  1063. export declare const trackVForSlotScopes: NodeTransform;
  1064. export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, vFor: DirectiveNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
  1065. export declare function buildSlots(node: ElementNode, context: TransformContext, buildSlotFn?: SlotFnBuilder): {
  1066. slots: SlotsExpression;
  1067. hasDynamicSlots: boolean;
  1068. };
  1069. export declare const transformVBindShorthand: NodeTransform;
  1070. interface SlotOutletProcessResult {
  1071. slotName: string | ExpressionNode;
  1072. slotProps: PropsExpression | undefined;
  1073. }
  1074. export declare function processSlotOutlet(node: SlotOutletNode, context: TransformContext): SlotOutletProcessResult;
  1075. export declare function getConstantType(node: TemplateChildNode | SimpleExpressionNode | CacheExpression, context: TransformContext): ConstantTypes;