compiler-core.d.ts 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. import { generateCodeFrame } from '@vue/shared';
  2. import { ParserPlugin } from '@babel/parser';
  3. import { RawSourceMap } from 'source-map';
  4. import { SourceMapGenerator } from 'source-map';
  5. export declare function advancePositionWithClone(pos: Position_2, source: string, numberOfCharacters?: number): Position_2;
  6. export declare function advancePositionWithMutation(pos: Position_2, source: string, numberOfCharacters?: number): Position_2;
  7. export declare interface ArrayExpression extends Node_2 {
  8. type: NodeTypes.JS_ARRAY_EXPRESSION;
  9. elements: Array<string | JSChildNode>;
  10. }
  11. export declare function assert(condition: boolean, msg?: string): void;
  12. export declare interface AssignmentExpression extends Node_2 {
  13. type: NodeTypes.JS_ASSIGNMENT_EXPRESSION;
  14. left: SimpleExpressionNode;
  15. right: JSChildNode;
  16. }
  17. export declare interface AttributeNode extends Node_2 {
  18. type: NodeTypes.ATTRIBUTE;
  19. name: string;
  20. value: TextNode | undefined;
  21. }
  22. export declare const BASE_TRANSITION: unique symbol;
  23. export declare function baseCompile(template: string | RootNode, options?: CompilerOptions): CodegenResult;
  24. export declare interface BaseElementNode extends Node_2 {
  25. type: NodeTypes.ELEMENT;
  26. ns: Namespace;
  27. tag: string;
  28. tagType: ElementTypes;
  29. isSelfClosing: boolean;
  30. props: Array<AttributeNode | DirectiveNode>;
  31. children: TemplateChildNode[];
  32. }
  33. export declare function baseParse(content: string, options?: ParserOptions): RootNode;
  34. export declare interface BindingMetadata {
  35. [key: string]: 'data' | 'props' | 'setup' | 'options';
  36. }
  37. export declare type BlockCodegenNode = VNodeCall | RenderSlotCall;
  38. export declare interface BlockStatement extends Node_2 {
  39. type: NodeTypes.JS_BLOCK_STATEMENT;
  40. body: (JSChildNode | IfStatement)[];
  41. }
  42. export declare function buildProps(node: ElementNode, context: TransformContext, props?: ElementNode['props'], ssr?: boolean): {
  43. props: PropsExpression | undefined;
  44. directives: DirectiveNode[];
  45. patchFlag: number;
  46. dynamicPropNames: string[];
  47. };
  48. export declare function buildSlots(node: ElementNode, context: TransformContext, buildSlotFn?: SlotFnBuilder): {
  49. slots: SlotsExpression;
  50. hasDynamicSlots: boolean;
  51. };
  52. export declare interface CacheExpression extends Node_2 {
  53. type: NodeTypes.JS_CACHE_EXPRESSION;
  54. index: number;
  55. value: JSChildNode;
  56. isVNode: boolean;
  57. }
  58. export declare interface CallExpression extends Node_2 {
  59. type: NodeTypes.JS_CALL_EXPRESSION;
  60. callee: string | symbol;
  61. arguments: (string | symbol | JSChildNode | SSRCodegenNode | TemplateChildNode | TemplateChildNode[])[];
  62. }
  63. export declare const CAMELIZE: unique symbol;
  64. export declare const CAPITALIZE: unique symbol;
  65. export declare interface CodegenContext extends Omit<Required<CodegenOptions>, 'bindingMetadata'> {
  66. source: string;
  67. code: string;
  68. line: number;
  69. column: number;
  70. offset: number;
  71. indentLevel: number;
  72. pure: boolean;
  73. map?: SourceMapGenerator;
  74. helper(key: symbol): string;
  75. push(code: string, node?: CodegenNode): void;
  76. indent(): void;
  77. deindent(withoutNewLine?: boolean): void;
  78. newline(): void;
  79. }
  80. declare type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode;
  81. export declare interface CodegenOptions {
  82. /**
  83. * - `module` mode will generate ES module import statements for helpers
  84. * and export the render function as the default export.
  85. * - `function` mode will generate a single `const { helpers... } = Vue`
  86. * statement and return the render function. It expects `Vue` to be globally
  87. * available (or passed by wrapping the code with an IIFE). It is meant to be
  88. * used with `new Function(code)()` to generate a render function at runtime.
  89. * @default 'function'
  90. */
  91. mode?: 'module' | 'function';
  92. /**
  93. * Generate source map?
  94. * @default false
  95. */
  96. sourceMap?: boolean;
  97. /**
  98. * Filename for source map generation.
  99. * @default 'template.vue.html'
  100. */
  101. filename?: string;
  102. /**
  103. * SFC scoped styles ID
  104. */
  105. scopeId?: string | null;
  106. /**
  107. * Option to optimize helper import bindings via variable assignment
  108. * (only used for webpack code-split)
  109. * @default false
  110. */
  111. optimizeImports?: boolean;
  112. /**
  113. * Customize where to import runtime helpers from.
  114. * @default 'vue'
  115. */
  116. runtimeModuleName?: string;
  117. /**
  118. * Customize the global variable name of `Vue` to get helpers from
  119. * in function mode
  120. * @default 'Vue'
  121. */
  122. runtimeGlobalName?: string;
  123. prefixIdentifiers?: boolean;
  124. bindingMetadata?: BindingMetadata;
  125. ssr?: boolean;
  126. }
  127. export declare interface CodegenResult {
  128. code: string;
  129. ast: RootNode;
  130. map?: RawSourceMap;
  131. }
  132. export declare interface CommentNode extends Node_2 {
  133. type: NodeTypes.COMMENT;
  134. content: string;
  135. }
  136. export declare interface CompilerError extends SyntaxError {
  137. code: number;
  138. loc?: SourceLocation;
  139. }
  140. export declare type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions;
  141. export declare interface ComponentNode extends BaseElementNode {
  142. tagType: ElementTypes.COMPONENT;
  143. codegenNode: VNodeCall | CacheExpression | undefined;
  144. ssrCodegenNode?: CallExpression;
  145. }
  146. export declare interface CompoundExpressionNode extends Node_2 {
  147. type: NodeTypes.COMPOUND_EXPRESSION;
  148. children: (SimpleExpressionNode | CompoundExpressionNode | InterpolationNode | TextNode | string | symbol)[];
  149. /**
  150. * an expression parsed as the params of a function will track
  151. * the identifiers declared inside the function body.
  152. */
  153. identifiers?: string[];
  154. }
  155. export declare interface ConditionalDynamicSlotNode extends ConditionalExpression {
  156. consequent: DynamicSlotNode;
  157. alternate: DynamicSlotNode | SimpleExpressionNode;
  158. }
  159. export declare interface ConditionalExpression extends Node_2 {
  160. type: NodeTypes.JS_CONDITIONAL_EXPRESSION;
  161. test: JSChildNode;
  162. consequent: JSChildNode;
  163. alternate: JSChildNode;
  164. newline: boolean;
  165. }
  166. export declare interface CoreCompilerError extends CompilerError {
  167. code: ErrorCodes;
  168. }
  169. export declare const CREATE_BLOCK: unique symbol;
  170. export declare const CREATE_COMMENT: unique symbol;
  171. export declare const CREATE_SLOTS: unique symbol;
  172. export declare const CREATE_STATIC: unique symbol;
  173. export declare const CREATE_TEXT: unique symbol;
  174. export declare const CREATE_VNODE: unique symbol;
  175. export declare function createArrayExpression(elements: ArrayExpression['elements'], loc?: SourceLocation): ArrayExpression;
  176. export declare function createAssignmentExpression(left: AssignmentExpression['left'], right: AssignmentExpression['right']): AssignmentExpression;
  177. export declare function createBlockStatement(body: BlockStatement['body']): BlockStatement;
  178. export declare function createCacheExpression(index: number, value: JSChildNode, isVNode?: boolean): CacheExpression;
  179. export declare function createCallExpression<T extends CallExpression['callee']>(callee: T, args?: CallExpression['arguments'], loc?: SourceLocation): InferCodegenNodeType<T>;
  180. export declare function createCompilerError<T extends number>(code: T, loc?: SourceLocation, messages?: {
  181. [code: number]: string;
  182. }, additionalMessage?: string): T extends ErrorCodes ? CoreCompilerError : CompilerError;
  183. export declare function createCompoundExpression(children: CompoundExpressionNode['children'], loc?: SourceLocation): CompoundExpressionNode;
  184. export declare function createConditionalExpression(test: ConditionalExpression['test'], consequent: ConditionalExpression['consequent'], alternate: ConditionalExpression['alternate'], newline?: boolean): ConditionalExpression;
  185. export declare function createForLoopParams({ value, key, index }: ForParseResult): ExpressionNode[];
  186. export declare function createFunctionExpression(params: FunctionExpression['params'], returns?: FunctionExpression['returns'], newline?: boolean, isSlot?: boolean, loc?: SourceLocation): FunctionExpression;
  187. export declare function createIfStatement(test: IfStatement['test'], consequent: IfStatement['consequent'], alternate?: IfStatement['alternate']): IfStatement;
  188. export declare function createInterpolation(content: InterpolationNode['content'] | string, loc: SourceLocation): InterpolationNode;
  189. export declare function createObjectExpression(properties: ObjectExpression['properties'], loc?: SourceLocation): ObjectExpression;
  190. export declare function createObjectProperty(key: Property['key'] | string, value: Property['value']): Property;
  191. export declare function createReturnStatement(returns: ReturnStatement['returns']): ReturnStatement;
  192. export declare function createRoot(children: TemplateChildNode[], loc?: SourceLocation): RootNode;
  193. export declare function createSequenceExpression(expressions: SequenceExpression['expressions']): SequenceExpression;
  194. export declare function createSimpleExpression(content: SimpleExpressionNode['content'], isStatic: SimpleExpressionNode['isStatic'], loc?: SourceLocation, isConstant?: boolean): SimpleExpressionNode;
  195. export declare function createStructuralDirectiveTransform(name: string | RegExp, fn: StructuralDirectiveTransform): NodeTransform;
  196. export declare function createTemplateLiteral(elements: TemplateLiteral['elements']): TemplateLiteral;
  197. export declare function createTransformContext(root: RootNode, { prefixIdentifiers, hoistStatic, cacheHandlers, nodeTransforms, directiveTransforms, transformHoist, isBuiltInComponent, isCustomElement, expressionPlugins, scopeId, ssr, ssrCssVars, bindingMetadata, onError }: TransformOptions): TransformContext;
  198. 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'], loc?: SourceLocation): VNodeCall;
  199. export declare interface DirectiveArgumentNode extends ArrayExpression {
  200. elements: [string] | [string, ExpressionNode] | [string, ExpressionNode, ExpressionNode] | [string, ExpressionNode, ExpressionNode, ObjectExpression];
  201. }
  202. export declare interface DirectiveArguments extends ArrayExpression {
  203. elements: DirectiveArgumentNode[];
  204. }
  205. export declare interface DirectiveNode extends Node_2 {
  206. type: NodeTypes.DIRECTIVE;
  207. name: string;
  208. exp: ExpressionNode | undefined;
  209. arg: ExpressionNode | undefined;
  210. modifiers: string[];
  211. /**
  212. * optional property to cache the expression parse result for v-for
  213. */
  214. parseResult?: ForParseResult;
  215. }
  216. export declare type DirectiveTransform = (dir: DirectiveNode, node: ElementNode, context: TransformContext, augmentor?: (ret: DirectiveTransformResult) => DirectiveTransformResult) => DirectiveTransformResult;
  217. declare interface DirectiveTransformResult {
  218. props: Property[];
  219. needRuntime?: boolean | symbol;
  220. ssrTagParts?: TemplateLiteral['elements'];
  221. }
  222. export declare interface DynamicSlotEntries extends ArrayExpression {
  223. elements: (ConditionalDynamicSlotNode | ListDynamicSlotNode)[];
  224. }
  225. export declare interface DynamicSlotFnProperty extends Property {
  226. value: SlotFunctionExpression;
  227. }
  228. export declare interface DynamicSlotNode extends ObjectExpression {
  229. properties: [Property, DynamicSlotFnProperty];
  230. }
  231. export declare interface DynamicSlotsExpression extends CallExpression {
  232. callee: typeof CREATE_SLOTS;
  233. arguments: [SlotsObjectExpression, DynamicSlotEntries];
  234. }
  235. export declare type ElementNode = PlainElementNode | ComponentNode | SlotOutletNode | TemplateNode;
  236. export declare const enum ElementTypes {
  237. ELEMENT = 0,
  238. COMPONENT = 1,
  239. SLOT = 2,
  240. TEMPLATE = 3
  241. }
  242. export declare const enum ErrorCodes {
  243. ABRUPT_CLOSING_OF_EMPTY_COMMENT = 0,
  244. CDATA_IN_HTML_CONTENT = 1,
  245. DUPLICATE_ATTRIBUTE = 2,
  246. END_TAG_WITH_ATTRIBUTES = 3,
  247. END_TAG_WITH_TRAILING_SOLIDUS = 4,
  248. EOF_BEFORE_TAG_NAME = 5,
  249. EOF_IN_CDATA = 6,
  250. EOF_IN_COMMENT = 7,
  251. EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT = 8,
  252. EOF_IN_TAG = 9,
  253. INCORRECTLY_CLOSED_COMMENT = 10,
  254. INCORRECTLY_OPENED_COMMENT = 11,
  255. INVALID_FIRST_CHARACTER_OF_TAG_NAME = 12,
  256. MISSING_ATTRIBUTE_VALUE = 13,
  257. MISSING_END_TAG_NAME = 14,
  258. MISSING_WHITESPACE_BETWEEN_ATTRIBUTES = 15,
  259. NESTED_COMMENT = 16,
  260. UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME = 17,
  261. UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE = 18,
  262. UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME = 19,
  263. UNEXPECTED_NULL_CHARACTER = 20,
  264. UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME = 21,
  265. UNEXPECTED_SOLIDUS_IN_TAG = 22,
  266. X_INVALID_END_TAG = 23,
  267. X_MISSING_END_TAG = 24,
  268. X_MISSING_INTERPOLATION_END = 25,
  269. X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END = 26,
  270. X_V_IF_NO_EXPRESSION = 27,
  271. X_V_IF_SAME_KEY = 28,
  272. X_V_ELSE_NO_ADJACENT_IF = 29,
  273. X_V_FOR_NO_EXPRESSION = 30,
  274. X_V_FOR_MALFORMED_EXPRESSION = 31,
  275. X_V_FOR_TEMPLATE_KEY_PLACEMENT = 32,
  276. X_V_BIND_NO_EXPRESSION = 33,
  277. X_V_ON_NO_EXPRESSION = 34,
  278. X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET = 35,
  279. X_V_SLOT_MIXED_SLOT_USAGE = 36,
  280. X_V_SLOT_DUPLICATE_SLOT_NAMES = 37,
  281. X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN = 38,
  282. X_V_SLOT_MISPLACED = 39,
  283. X_V_MODEL_NO_EXPRESSION = 40,
  284. X_V_MODEL_MALFORMED_EXPRESSION = 41,
  285. X_V_MODEL_ON_SCOPE_VARIABLE = 42,
  286. X_INVALID_EXPRESSION = 43,
  287. X_KEEP_ALIVE_INVALID_CHILDREN = 44,
  288. X_PREFIX_ID_NOT_SUPPORTED = 45,
  289. X_MODULE_MODE_NOT_SUPPORTED = 46,
  290. X_CACHE_HANDLER_NOT_SUPPORTED = 47,
  291. X_SCOPE_ID_NOT_SUPPORTED = 48,
  292. __EXTEND_POINT__ = 49
  293. }
  294. export declare type ExpressionNode = SimpleExpressionNode | CompoundExpressionNode;
  295. export declare function findDir(node: ElementNode, name: string | RegExp, allowEmpty?: boolean): DirectiveNode | undefined;
  296. export declare function findProp(node: ElementNode, name: string, dynamicOnly?: boolean, allowEmpty?: boolean): ElementNode['props'][0] | undefined;
  297. export declare interface ForCodegenNode extends VNodeCall {
  298. isBlock: true;
  299. tag: typeof FRAGMENT;
  300. props: undefined;
  301. children: ForRenderListExpression;
  302. patchFlag: string;
  303. disableTracking: boolean;
  304. }
  305. export declare interface ForIteratorExpression extends FunctionExpression {
  306. returns: BlockCodegenNode;
  307. }
  308. export declare interface ForNode extends Node_2 {
  309. type: NodeTypes.FOR;
  310. source: ExpressionNode;
  311. valueAlias: ExpressionNode | undefined;
  312. keyAlias: ExpressionNode | undefined;
  313. objectIndexAlias: ExpressionNode | undefined;
  314. parseResult: ForParseResult;
  315. children: TemplateChildNode[];
  316. codegenNode?: ForCodegenNode;
  317. }
  318. declare interface ForParseResult {
  319. source: ExpressionNode;
  320. value: ExpressionNode | undefined;
  321. key: ExpressionNode | undefined;
  322. index: ExpressionNode | undefined;
  323. }
  324. export declare interface ForRenderListExpression extends CallExpression {
  325. callee: typeof RENDER_LIST;
  326. arguments: [ExpressionNode, ForIteratorExpression];
  327. }
  328. export declare const FRAGMENT: unique symbol;
  329. export declare interface FunctionExpression extends Node_2 {
  330. type: NodeTypes.JS_FUNCTION_EXPRESSION;
  331. params: ExpressionNode | string | (ExpressionNode | string)[] | undefined;
  332. returns?: TemplateChildNode | TemplateChildNode[] | JSChildNode;
  333. body?: BlockStatement | IfStatement;
  334. newline: boolean;
  335. /**
  336. * This flag is for codegen to determine whether it needs to generate the
  337. * withScopeId() wrapper
  338. */
  339. isSlot: boolean;
  340. }
  341. export declare function generate(ast: RootNode, options?: CodegenOptions & {
  342. onContextCreated?: (context: CodegenContext) => void;
  343. }): CodegenResult;
  344. export { generateCodeFrame }
  345. export declare function getBaseTransformPreset(prefixIdentifiers?: boolean): TransformPreset;
  346. export declare function getInnerRange(loc: SourceLocation, offset: number, length?: number): SourceLocation;
  347. export declare function hasDynamicKeyVBind(node: ElementNode): boolean;
  348. export declare function hasScopeRef(node: TemplateChildNode | IfBranchNode | ExpressionNode | undefined, ids: TransformContext['identifiers']): boolean;
  349. export declare const helperNameMap: any;
  350. export declare type HoistTransform = (children: TemplateChildNode[], context: TransformContext, parent: ParentNode_2) => void;
  351. export declare interface IfBranchNode extends Node_2 {
  352. type: NodeTypes.IF_BRANCH;
  353. condition: ExpressionNode | undefined;
  354. children: TemplateChildNode[];
  355. userKey?: AttributeNode | DirectiveNode;
  356. }
  357. export declare interface IfConditionalExpression extends ConditionalExpression {
  358. consequent: BlockCodegenNode;
  359. alternate: BlockCodegenNode | IfConditionalExpression;
  360. }
  361. export declare interface IfNode extends Node_2 {
  362. type: NodeTypes.IF;
  363. branches: IfBranchNode[];
  364. codegenNode?: IfConditionalExpression | CacheExpression;
  365. }
  366. export declare interface IfStatement extends Node_2 {
  367. type: NodeTypes.JS_IF_STATEMENT;
  368. test: ExpressionNode;
  369. consequent: BlockStatement;
  370. alternate: IfStatement | BlockStatement | ReturnStatement | undefined;
  371. }
  372. declare interface ImportItem {
  373. exp: string | ExpressionNode;
  374. path: string;
  375. }
  376. declare type InferCodegenNodeType<T> = T extends typeof RENDER_SLOT ? RenderSlotCall : CallExpression;
  377. export declare function injectProp(node: VNodeCall | RenderSlotCall, prop: Property, context: TransformContext): void;
  378. export declare interface InterpolationNode extends Node_2 {
  379. type: NodeTypes.INTERPOLATION;
  380. content: ExpressionNode;
  381. }
  382. export declare function isBindKey(arg: DirectiveNode['arg'], name: string): boolean;
  383. export declare const isBuiltInType: (tag: string, expected: string) => boolean;
  384. export declare function isCoreComponent(tag: string): symbol | void;
  385. export declare const isMemberExpression: (path: string) => boolean;
  386. export declare const isSimpleIdentifier: (name: string) => boolean;
  387. export declare function isSlotOutlet(node: RootNode | TemplateChildNode): node is SlotOutletNode;
  388. export declare const isStaticExp: (p: JSChildNode) => p is SimpleExpressionNode;
  389. export declare function isTemplateNode(node: RootNode | TemplateChildNode): node is TemplateNode;
  390. export declare function isText(node: TemplateChildNode): node is TextNode | InterpolationNode;
  391. export declare function isVSlot(p: ElementNode['props'][0]): p is DirectiveNode;
  392. export declare type JSChildNode = VNodeCall | CallExpression | ObjectExpression | ArrayExpression | ExpressionNode | FunctionExpression | ConditionalExpression | CacheExpression | AssignmentExpression | SequenceExpression;
  393. export declare const KEEP_ALIVE: unique symbol;
  394. export declare interface ListDynamicSlotIterator extends FunctionExpression {
  395. returns: DynamicSlotNode;
  396. }
  397. export declare interface ListDynamicSlotNode extends CallExpression {
  398. callee: typeof RENDER_LIST;
  399. arguments: [ExpressionNode, ListDynamicSlotIterator];
  400. }
  401. export declare const locStub: SourceLocation;
  402. export declare const MERGE_PROPS: unique symbol;
  403. export declare type Namespace = number;
  404. export declare const enum Namespaces {
  405. HTML = 0
  406. }
  407. declare interface Node_2 {
  408. type: NodeTypes;
  409. loc: SourceLocation;
  410. }
  411. export { Node_2 as Node }
  412. export declare type NodeTransform = (node: RootNode | TemplateChildNode, context: TransformContext) => void | (() => void) | (() => void)[];
  413. export declare const enum NodeTypes {
  414. ROOT = 0,
  415. ELEMENT = 1,
  416. TEXT = 2,
  417. COMMENT = 3,
  418. SIMPLE_EXPRESSION = 4,
  419. INTERPOLATION = 5,
  420. ATTRIBUTE = 6,
  421. DIRECTIVE = 7,
  422. COMPOUND_EXPRESSION = 8,
  423. IF = 9,
  424. IF_BRANCH = 10,
  425. FOR = 11,
  426. TEXT_CALL = 12,
  427. VNODE_CALL = 13,
  428. JS_CALL_EXPRESSION = 14,
  429. JS_OBJECT_EXPRESSION = 15,
  430. JS_PROPERTY = 16,
  431. JS_ARRAY_EXPRESSION = 17,
  432. JS_FUNCTION_EXPRESSION = 18,
  433. JS_CONDITIONAL_EXPRESSION = 19,
  434. JS_CACHE_EXPRESSION = 20,
  435. JS_BLOCK_STATEMENT = 21,
  436. JS_TEMPLATE_LITERAL = 22,
  437. JS_IF_STATEMENT = 23,
  438. JS_ASSIGNMENT_EXPRESSION = 24,
  439. JS_SEQUENCE_EXPRESSION = 25,
  440. JS_RETURN_STATEMENT = 26
  441. }
  442. export declare const noopDirectiveTransform: DirectiveTransform;
  443. export declare interface ObjectExpression extends Node_2 {
  444. type: NodeTypes.JS_OBJECT_EXPRESSION;
  445. properties: Array<Property>;
  446. }
  447. export declare const OPEN_BLOCK: unique symbol;
  448. declare type ParentNode_2 = RootNode | ElementNode | IfBranchNode | ForNode;
  449. export { ParentNode_2 as ParentNode }
  450. export declare interface ParserOptions {
  451. /**
  452. * e.g. platform native elements, e.g. `<div>` for browsers
  453. */
  454. isNativeTag?: (tag: string) => boolean;
  455. /**
  456. * e.g. native elements that can self-close, e.g. `<img>`, `<br>`, `<hr>`
  457. */
  458. isVoidTag?: (tag: string) => boolean;
  459. /**
  460. * e.g. elements that should preserve whitespace inside, e.g. `<pre>`
  461. */
  462. isPreTag?: (tag: string) => boolean;
  463. /**
  464. * Platform-specific built-in components e.g. `<Transition>`
  465. */
  466. isBuiltInComponent?: (tag: string) => symbol | void;
  467. /**
  468. * Separate option for end users to extend the native elements list
  469. */
  470. isCustomElement?: (tag: string) => boolean | void;
  471. /**
  472. * Get tag namespace
  473. */
  474. getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace;
  475. /**
  476. * Get text parsing mode for this element
  477. */
  478. getTextMode?: (node: ElementNode, parent: ElementNode | undefined) => TextModes;
  479. /**
  480. * @default ['{{', '}}']
  481. */
  482. delimiters?: [string, string];
  483. /**
  484. * Only needed for DOM compilers
  485. */
  486. decodeEntities?: (rawText: string, asAttr: boolean) => string;
  487. onError?: (error: CompilerError) => void;
  488. /**
  489. * Keep comments in the templates AST, even in production
  490. */
  491. comments?: boolean;
  492. }
  493. export declare interface PlainElementNode extends BaseElementNode {
  494. tagType: ElementTypes.ELEMENT;
  495. codegenNode: VNodeCall | SimpleExpressionNode | CacheExpression | undefined;
  496. ssrCodegenNode?: TemplateLiteral;
  497. }
  498. export declare const POP_SCOPE_ID: unique symbol;
  499. declare interface Position_2 {
  500. offset: number;
  501. line: number;
  502. column: number;
  503. }
  504. export { Position_2 as Position }
  505. export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean): ExpressionNode;
  506. export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
  507. export declare function processIf(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (node: IfNode, branch: IfBranchNode, isRoot: boolean) => (() => void) | undefined): (() => void) | undefined;
  508. export declare function processSlotOutlet(node: SlotOutletNode, context: TransformContext): SlotOutletProcessResult;
  509. export declare interface Property extends Node_2 {
  510. type: NodeTypes.JS_PROPERTY;
  511. key: ExpressionNode;
  512. value: JSChildNode;
  513. }
  514. declare type PropsExpression = ObjectExpression | CallExpression | ExpressionNode;
  515. export declare const PUSH_SCOPE_ID: unique symbol;
  516. export declare function registerRuntimeHelpers(helpers: any): void;
  517. export declare const RENDER_LIST: unique symbol;
  518. export declare const RENDER_SLOT: unique symbol;
  519. export declare interface RenderSlotCall extends CallExpression {
  520. callee: typeof RENDER_SLOT;
  521. arguments: [string, string | ExpressionNode] | [string, string | ExpressionNode, PropsExpression] | [
  522. string,
  523. string | ExpressionNode,
  524. PropsExpression | '{}',
  525. TemplateChildNode[]
  526. ];
  527. }
  528. export declare const RESOLVE_COMPONENT: unique symbol;
  529. export declare const RESOLVE_DIRECTIVE: unique symbol;
  530. export declare const RESOLVE_DYNAMIC_COMPONENT: unique symbol;
  531. export declare function resolveComponentType(node: ComponentNode, context: TransformContext, ssr?: boolean): string | symbol | CallExpression;
  532. export declare interface ReturnStatement extends Node_2 {
  533. type: NodeTypes.JS_RETURN_STATEMENT;
  534. returns: TemplateChildNode | TemplateChildNode[] | JSChildNode;
  535. }
  536. export declare interface RootNode extends Node_2 {
  537. type: NodeTypes.ROOT;
  538. children: TemplateChildNode[];
  539. helpers: symbol[];
  540. components: string[];
  541. directives: string[];
  542. hoists: (JSChildNode | null)[];
  543. imports: ImportItem[];
  544. cached: number;
  545. temps: number;
  546. ssrHelpers?: symbol[];
  547. codegenNode?: TemplateChildNode | JSChildNode | BlockStatement | undefined;
  548. }
  549. export declare interface SequenceExpression extends Node_2 {
  550. type: NodeTypes.JS_SEQUENCE_EXPRESSION;
  551. expressions: JSChildNode[];
  552. }
  553. export declare const SET_BLOCK_TRACKING: unique symbol;
  554. export declare interface SimpleExpressionNode extends Node_2 {
  555. type: NodeTypes.SIMPLE_EXPRESSION;
  556. content: string;
  557. isStatic: boolean;
  558. isConstant: boolean;
  559. /**
  560. * Indicates this is an identifier for a hoist vnode call and points to the
  561. * hoisted node.
  562. */
  563. hoisted?: JSChildNode;
  564. /**
  565. * an expression parsed as the params of a function will track
  566. * the identifiers declared inside the function body.
  567. */
  568. identifiers?: string[];
  569. /**
  570. * some expressions (e.g. transformAssetUrls import identifiers) are constant,
  571. * but cannot be stringified because they must be first evaluated at runtime.
  572. */
  573. isRuntimeConstant?: boolean;
  574. }
  575. export declare type SlotFnBuilder = (slotProps: ExpressionNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
  576. export declare interface SlotFunctionExpression extends FunctionExpression {
  577. returns: TemplateChildNode[];
  578. }
  579. export declare interface SlotOutletNode extends BaseElementNode {
  580. tagType: ElementTypes.SLOT;
  581. codegenNode: RenderSlotCall | CacheExpression | undefined;
  582. ssrCodegenNode?: CallExpression;
  583. }
  584. declare interface SlotOutletProcessResult {
  585. slotName: string | ExpressionNode;
  586. slotProps: PropsExpression | undefined;
  587. }
  588. export declare type SlotsExpression = SlotsObjectExpression | DynamicSlotsExpression;
  589. export declare interface SlotsObjectExpression extends ObjectExpression {
  590. properties: SlotsObjectProperty[];
  591. }
  592. export declare interface SlotsObjectProperty extends Property {
  593. value: SlotFunctionExpression;
  594. }
  595. export declare interface SourceLocation {
  596. start: Position_2;
  597. end: Position_2;
  598. source: string;
  599. }
  600. export declare type SSRCodegenNode = BlockStatement | TemplateLiteral | IfStatement | AssignmentExpression | ReturnStatement | SequenceExpression;
  601. export declare type StructuralDirectiveTransform = (node: ElementNode, dir: DirectiveNode, context: TransformContext) => void | (() => void);
  602. export declare const SUSPENSE: unique symbol;
  603. export declare const TELEPORT: unique symbol;
  604. export declare type TemplateChildNode = ElementNode | InterpolationNode | CompoundExpressionNode | TextNode | CommentNode | IfNode | IfBranchNode | ForNode | TextCallNode;
  605. export declare interface TemplateLiteral extends Node_2 {
  606. type: NodeTypes.JS_TEMPLATE_LITERAL;
  607. elements: (string | JSChildNode)[];
  608. }
  609. export declare interface TemplateNode extends BaseElementNode {
  610. tagType: ElementTypes.TEMPLATE;
  611. codegenNode: undefined;
  612. }
  613. export declare type TemplateTextChildNode = TextNode | InterpolationNode | CompoundExpressionNode;
  614. export declare interface TextCallNode extends Node_2 {
  615. type: NodeTypes.TEXT_CALL;
  616. content: TextNode | InterpolationNode | CompoundExpressionNode;
  617. codegenNode: CallExpression | SimpleExpressionNode;
  618. }
  619. export declare const enum TextModes {
  620. DATA = 0,
  621. RCDATA = 1,
  622. RAWTEXT = 2,
  623. CDATA = 3,
  624. ATTRIBUTE_VALUE = 4
  625. }
  626. export declare interface TextNode extends Node_2 {
  627. type: NodeTypes.TEXT;
  628. content: string;
  629. }
  630. export declare const TO_DISPLAY_STRING: unique symbol;
  631. export declare const TO_HANDLER_KEY: unique symbol;
  632. export declare const TO_HANDLERS: unique symbol;
  633. export declare function toValidAssetId(name: string, type: 'component' | 'directive'): string;
  634. export declare const trackSlotScopes: NodeTransform;
  635. export declare const trackVForSlotScopes: NodeTransform;
  636. export declare function transform(root: RootNode, options: TransformOptions): void;
  637. export declare const transformBind: DirectiveTransform;
  638. export declare interface TransformContext extends Required<TransformOptions> {
  639. root: RootNode;
  640. helpers: Set<symbol>;
  641. components: Set<string>;
  642. directives: Set<string>;
  643. hoists: (JSChildNode | null)[];
  644. imports: Set<ImportItem>;
  645. temps: number;
  646. cached: number;
  647. identifiers: {
  648. [name: string]: number | undefined;
  649. };
  650. scopes: {
  651. vFor: number;
  652. vSlot: number;
  653. vPre: number;
  654. vOnce: number;
  655. };
  656. parent: ParentNode_2 | null;
  657. childIndex: number;
  658. currentNode: RootNode | TemplateChildNode | null;
  659. helper<T extends symbol>(name: T): T;
  660. helperString(name: symbol): string;
  661. replaceNode(node: TemplateChildNode): void;
  662. removeNode(node?: TemplateChildNode): void;
  663. onNodeRemoved(): void;
  664. addIdentifiers(exp: ExpressionNode | string): void;
  665. removeIdentifiers(exp: ExpressionNode | string): void;
  666. hoist(exp: JSChildNode): SimpleExpressionNode;
  667. cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T;
  668. }
  669. export declare const transformElement: NodeTransform;
  670. export declare const transformExpression: NodeTransform;
  671. export declare const transformModel: DirectiveTransform;
  672. export declare const transformOn: DirectiveTransform;
  673. export declare interface TransformOptions {
  674. /**
  675. * An array of node transforms to be applied to every AST node.
  676. */
  677. nodeTransforms?: NodeTransform[];
  678. /**
  679. * An object of { name: transform } to be applied to every directive attribute
  680. * node found on element nodes.
  681. */
  682. directiveTransforms?: Record<string, DirectiveTransform | undefined>;
  683. /**
  684. * An optional hook to transform a node being hoisted.
  685. * used by compiler-dom to turn hoisted nodes into stringified HTML vnodes.
  686. * @default null
  687. */
  688. transformHoist?: HoistTransform | null;
  689. /**
  690. * If the pairing runtime provides additional built-in elements, use this to
  691. * mark them as built-in so the compiler will generate component vnodes
  692. * for them.
  693. */
  694. isBuiltInComponent?: (tag: string) => symbol | void;
  695. /**
  696. * Used by some transforms that expects only native elements
  697. */
  698. isCustomElement?: (tag: string) => boolean | void;
  699. /**
  700. * Transform expressions like {{ foo }} to `_ctx.foo`.
  701. * If this option is false, the generated code will be wrapped in a
  702. * `with (this) { ... }` block.
  703. * - This is force-enabled in module mode, since modules are by default strict
  704. * and cannot use `with`
  705. * @default mode === 'module'
  706. */
  707. prefixIdentifiers?: boolean;
  708. /**
  709. * Hoist static VNodes and props objects to `_hoisted_x` constants
  710. * @default false
  711. */
  712. hoistStatic?: boolean;
  713. /**
  714. * Cache v-on handlers to avoid creating new inline functions on each render,
  715. * also avoids the need for dynamically patching the handlers by wrapping it.
  716. * e.g `@click="foo"` by default is compiled to `{ onClick: foo }`. With this
  717. * option it's compiled to:
  718. * ```js
  719. * { onClick: _cache[0] || (_cache[0] = e => _ctx.foo(e)) }
  720. * ```
  721. * - Requires "prefixIdentifiers" to be enabled because it relies on scope
  722. * analysis to determine if a handler is safe to cache.
  723. * @default false
  724. */
  725. cacheHandlers?: boolean;
  726. /**
  727. * A list of parser plugins to enable for `@babel/parser`, which is used to
  728. * parse expressions in bindings and interpolations.
  729. * https://babeljs.io/docs/en/next/babel-parser#plugins
  730. */
  731. expressionPlugins?: ParserPlugin[];
  732. /**
  733. * SFC scoped styles ID
  734. */
  735. scopeId?: string | null;
  736. /**
  737. * Generate SSR-optimized render functions instead.
  738. * The resulting function must be attached to the component via the
  739. * `ssrRender` option instead of `render`.
  740. */
  741. ssr?: boolean;
  742. /**
  743. * SFC `<style vars>` injection string
  744. * needed to render inline CSS variables on component root
  745. */
  746. ssrCssVars?: string;
  747. /**
  748. * Optional binding metadata analyzed from script - used to optimize
  749. * binding access when `prefixIdentifiers` is enabled.
  750. */
  751. bindingMetadata?: BindingMetadata;
  752. onError?: (error: CompilerError) => void;
  753. }
  754. export declare type TransformPreset = [
  755. NodeTransform[],
  756. Record<string, DirectiveTransform>
  757. ];
  758. export declare function traverseNode(node: RootNode | TemplateChildNode, context: TransformContext): void;
  759. export declare interface VNodeCall extends Node_2 {
  760. type: NodeTypes.VNODE_CALL;
  761. tag: string | symbol | CallExpression;
  762. props: PropsExpression | undefined;
  763. children: TemplateChildNode[] | TemplateTextChildNode | SlotsExpression | ForRenderListExpression | undefined;
  764. patchFlag: string | undefined;
  765. dynamicProps: string | undefined;
  766. directives: DirectiveArguments | undefined;
  767. isBlock: boolean;
  768. disableTracking: boolean;
  769. }
  770. export declare const WITH_CTX: unique symbol;
  771. export declare const WITH_DIRECTIVES: unique symbol;
  772. export declare const WITH_SCOPE_ID: unique symbol;
  773. export { }