compiler-core.d.ts 34 KB

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