@vue/compiler-core 3.4.0-alpha.1 → 3.4.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,27 +3,51 @@ import { RawSourceMap, SourceMapGenerator } from 'source-map-js';
3
3
  import { Node as Node$1, Identifier, Function, BlockStatement as BlockStatement$1, Program, ObjectProperty } from '@babel/types';
4
4
  export { generateCodeFrame } from '@vue/shared';
5
5
 
6
- type OptionalOptions = 'whitespace' | 'isNativeTag' | 'isBuiltInComponent' | keyof CompilerCompatOptions;
6
+ export declare const FRAGMENT: unique symbol;
7
+ export declare const TELEPORT: unique symbol;
8
+ export declare const SUSPENSE: unique symbol;
9
+ export declare const KEEP_ALIVE: unique symbol;
10
+ export declare const BASE_TRANSITION: unique symbol;
11
+ export declare const OPEN_BLOCK: unique symbol;
12
+ export declare const CREATE_BLOCK: unique symbol;
13
+ export declare const CREATE_ELEMENT_BLOCK: unique symbol;
14
+ export declare const CREATE_VNODE: unique symbol;
15
+ export declare const CREATE_ELEMENT_VNODE: unique symbol;
16
+ export declare const CREATE_COMMENT: unique symbol;
17
+ export declare const CREATE_TEXT: unique symbol;
18
+ export declare const CREATE_STATIC: unique symbol;
19
+ export declare const RESOLVE_COMPONENT: unique symbol;
20
+ export declare const RESOLVE_DYNAMIC_COMPONENT: unique symbol;
21
+ export declare const RESOLVE_DIRECTIVE: unique symbol;
22
+ export declare const RESOLVE_FILTER: unique symbol;
23
+ export declare const WITH_DIRECTIVES: unique symbol;
24
+ export declare const RENDER_LIST: unique symbol;
25
+ export declare const RENDER_SLOT: unique symbol;
26
+ export declare const CREATE_SLOTS: unique symbol;
27
+ export declare const TO_DISPLAY_STRING: unique symbol;
28
+ export declare const MERGE_PROPS: unique symbol;
29
+ export declare const NORMALIZE_CLASS: unique symbol;
30
+ export declare const NORMALIZE_STYLE: unique symbol;
31
+ export declare const NORMALIZE_PROPS: unique symbol;
32
+ export declare const GUARD_REACTIVE_PROPS: unique symbol;
33
+ export declare const TO_HANDLERS: unique symbol;
34
+ export declare const CAMELIZE: unique symbol;
35
+ export declare const CAPITALIZE: unique symbol;
36
+ export declare const TO_HANDLER_KEY: unique symbol;
37
+ export declare const SET_BLOCK_TRACKING: unique symbol;
38
+ export declare const PUSH_SCOPE_ID: unique symbol;
39
+ export declare const POP_SCOPE_ID: unique symbol;
40
+ export declare const WITH_CTX: unique symbol;
41
+ export declare const UNREF: unique symbol;
42
+ export declare const IS_REF: unique symbol;
43
+ export declare const WITH_MEMO: unique symbol;
44
+ export declare const IS_MEMO_SAME: unique symbol;
45
+ export declare const helperNameMap: Record<symbol, string>;
46
+ export declare function registerRuntimeHelpers(helpers: Record<symbol, string>): void;
47
+
48
+ type OptionalOptions = 'decodeEntities' | 'whitespace' | 'isNativeTag' | 'isBuiltInComponent' | keyof CompilerCompatOptions;
7
49
  type MergedParserOptions = Omit<Required<ParserOptions>, OptionalOptions> & Pick<ParserOptions, OptionalOptions>;
8
- export declare const enum TextModes {
9
- DATA = 0,
10
- RCDATA = 1,
11
- RAWTEXT = 2,
12
- CDATA = 3,
13
- ATTRIBUTE_VALUE = 4
14
- }
15
- interface ParserContext {
16
- options: MergedParserOptions;
17
- readonly originalSource: string;
18
- source: string;
19
- offset: number;
20
- line: number;
21
- column: number;
22
- inPre: boolean;
23
- inVPre: boolean;
24
- onWarn: NonNullable<ErrorHandlingOptions['onWarn']>;
25
- }
26
- export declare function baseParse(content: string, options?: ParserOptions): RootNode;
50
+ export declare function baseParse(input: string, options?: ParserOptions): RootNode;
27
51
 
28
52
  type CompilerCompatConfig = Partial<Record<CompilerDeprecationTypes, boolean | 'suppress-warning'>> & {
29
53
  MODE?: 2 | 3;
@@ -34,7 +58,6 @@ interface CompilerCompatOptions {
34
58
  export declare const enum CompilerDeprecationTypes {
35
59
  COMPILER_IS_ON_ELEMENT = "COMPILER_IS_ON_ELEMENT",
36
60
  COMPILER_V_BIND_SYNC = "COMPILER_V_BIND_SYNC",
37
- COMPILER_V_BIND_PROP = "COMPILER_V_BIND_PROP",
38
61
  COMPILER_V_BIND_OBJECT_ORDER = "COMPILER_V_BIND_OBJECT_ORDER",
39
62
  COMPILER_V_ON_NATIVE = "COMPILER_V_ON_NATIVE",
40
63
  COMPILER_V_IF_V_FOR_PRECEDENCE = "COMPILER_V_IF_V_FOR_PRECEDENCE",
@@ -42,8 +65,8 @@ export declare const enum CompilerDeprecationTypes {
42
65
  COMPILER_INLINE_TEMPLATE = "COMPILER_INLINE_TEMPLATE",
43
66
  COMPILER_FILTERS = "COMPILER_FILTER"
44
67
  }
45
- export declare function checkCompatEnabled(key: CompilerDeprecationTypes, context: ParserContext | TransformContext, loc: SourceLocation | null, ...args: any[]): boolean;
46
- export declare function warnDeprecation(key: CompilerDeprecationTypes, context: ParserContext | TransformContext, loc: SourceLocation | null, ...args: any[]): void;
68
+ export declare function checkCompatEnabled(key: CompilerDeprecationTypes, context: MergedParserOptions | TransformContext, loc: SourceLocation | null, ...args: any[]): boolean;
69
+ export declare function warnDeprecation(key: CompilerDeprecationTypes, context: MergedParserOptions | TransformContext, loc: SourceLocation | null, ...args: any[]): void;
47
70
 
48
71
  export type NodeTransform = (node: RootNode | TemplateChildNode, context: TransformContext) => void | (() => void) | (() => void)[];
49
72
  export type DirectiveTransform = (dir: DirectiveNode, node: ElementNode, context: TransformContext, augmentor?: (ret: DirectiveTransformResult) => DirectiveTransformResult) => DirectiveTransformResult;
@@ -98,57 +121,6 @@ export declare function transform(root: RootNode, options: TransformOptions): vo
98
121
  export declare function traverseNode(node: RootNode | TemplateChildNode, context: TransformContext): void;
99
122
  export declare function createStructuralDirectiveTransform(name: string | RegExp, fn: StructuralDirectiveTransform): NodeTransform;
100
123
 
101
- export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
102
- interface ForParseResult {
103
- source: ExpressionNode;
104
- value: ExpressionNode | undefined;
105
- key: ExpressionNode | undefined;
106
- index: ExpressionNode | undefined;
107
- }
108
- export declare function createForLoopParams({ value, key, index }: ForParseResult, memoArgs?: ExpressionNode[]): ExpressionNode[];
109
-
110
- export declare const FRAGMENT: unique symbol;
111
- export declare const TELEPORT: unique symbol;
112
- export declare const SUSPENSE: unique symbol;
113
- export declare const KEEP_ALIVE: unique symbol;
114
- export declare const BASE_TRANSITION: unique symbol;
115
- export declare const OPEN_BLOCK: unique symbol;
116
- export declare const CREATE_BLOCK: unique symbol;
117
- export declare const CREATE_ELEMENT_BLOCK: unique symbol;
118
- export declare const CREATE_VNODE: unique symbol;
119
- export declare const CREATE_ELEMENT_VNODE: unique symbol;
120
- export declare const CREATE_COMMENT: unique symbol;
121
- export declare const CREATE_TEXT: unique symbol;
122
- export declare const CREATE_STATIC: unique symbol;
123
- export declare const RESOLVE_COMPONENT: unique symbol;
124
- export declare const RESOLVE_DYNAMIC_COMPONENT: unique symbol;
125
- export declare const RESOLVE_DIRECTIVE: unique symbol;
126
- export declare const RESOLVE_FILTER: unique symbol;
127
- export declare const WITH_DIRECTIVES: unique symbol;
128
- export declare const RENDER_LIST: unique symbol;
129
- export declare const RENDER_SLOT: unique symbol;
130
- export declare const CREATE_SLOTS: unique symbol;
131
- export declare const TO_DISPLAY_STRING: unique symbol;
132
- export declare const MERGE_PROPS: unique symbol;
133
- export declare const NORMALIZE_CLASS: unique symbol;
134
- export declare const NORMALIZE_STYLE: unique symbol;
135
- export declare const NORMALIZE_PROPS: unique symbol;
136
- export declare const GUARD_REACTIVE_PROPS: unique symbol;
137
- export declare const TO_HANDLERS: unique symbol;
138
- export declare const CAMELIZE: unique symbol;
139
- export declare const CAPITALIZE: unique symbol;
140
- export declare const TO_HANDLER_KEY: unique symbol;
141
- export declare const SET_BLOCK_TRACKING: unique symbol;
142
- export declare const PUSH_SCOPE_ID: unique symbol;
143
- export declare const POP_SCOPE_ID: unique symbol;
144
- export declare const WITH_CTX: unique symbol;
145
- export declare const UNREF: unique symbol;
146
- export declare const IS_REF: unique symbol;
147
- export declare const WITH_MEMO: unique symbol;
148
- export declare const IS_MEMO_SAME: unique symbol;
149
- export declare const helperNameMap: Record<symbol, string>;
150
- export declare function registerRuntimeHelpers(helpers: Record<symbol, string>): void;
151
-
152
124
  export declare const transformElement: NodeTransform;
153
125
  export declare function resolveComponentType(node: ComponentNode, context: TransformContext, ssr?: boolean): string | symbol | CallExpression;
154
126
  export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode;
@@ -163,7 +135,9 @@ export declare function buildDirectiveArgs(dir: DirectiveNode, context: Transfor
163
135
 
164
136
  export type Namespace = number;
165
137
  export declare const enum Namespaces {
166
- HTML = 0
138
+ HTML = 0,
139
+ SVG = 1,
140
+ MATH_ML = 2
167
141
  }
168
142
  export declare const enum NodeTypes {
169
143
  ROOT = 0,
@@ -219,6 +193,7 @@ export type ExpressionNode = SimpleExpressionNode | CompoundExpressionNode;
219
193
  export type TemplateChildNode = ElementNode | InterpolationNode | CompoundExpressionNode | TextNode | CommentNode | IfNode | IfBranchNode | ForNode | TextCallNode;
220
194
  export interface RootNode extends Node {
221
195
  type: NodeTypes.ROOT;
196
+ source: string;
222
197
  children: TemplateChildNode[];
223
198
  helpers: Set<symbol>;
224
199
  components: string[];
@@ -229,6 +204,7 @@ export interface RootNode extends Node {
229
204
  temps: number;
230
205
  ssrHelpers?: symbol[];
231
206
  codegenNode?: TemplateChildNode | JSChildNode | BlockStatement;
207
+ transformed?: boolean;
232
208
  filters?: string[];
233
209
  }
234
210
  export type ElementNode = PlainElementNode | ComponentNode | SlotOutletNode | TemplateNode;
@@ -237,9 +213,10 @@ export interface BaseElementNode extends Node {
237
213
  ns: Namespace;
238
214
  tag: string;
239
215
  tagType: ElementTypes;
240
- isSelfClosing: boolean;
241
216
  props: Array<AttributeNode | DirectiveNode>;
242
217
  children: TemplateChildNode[];
218
+ isSelfClosing?: boolean;
219
+ innerLoc?: SourceLocation;
243
220
  }
244
221
  export interface PlainElementNode extends BaseElementNode {
245
222
  tagType: ElementTypes.ELEMENT;
@@ -271,18 +248,27 @@ export interface CommentNode extends Node {
271
248
  export interface AttributeNode extends Node {
272
249
  type: NodeTypes.ATTRIBUTE;
273
250
  name: string;
251
+ nameLoc: SourceLocation;
274
252
  value: TextNode | undefined;
275
253
  }
276
254
  export interface DirectiveNode extends Node {
277
255
  type: NodeTypes.DIRECTIVE;
256
+ /**
257
+ * the normalized name without prefix or shorthands, e.g. "bind", "on"
258
+ */
278
259
  name: string;
260
+ /**
261
+ * the raw attribute name, preserving shorthand, and including arg & modifiers
262
+ * this is only used during parse.
263
+ */
264
+ rawName?: string;
279
265
  exp: ExpressionNode | undefined;
280
266
  arg: ExpressionNode | undefined;
281
267
  modifiers: string[];
282
268
  /**
283
269
  * optional property to cache the expression parse result for v-for
284
270
  */
285
- parseResult?: ForParseResult;
271
+ forParseResult?: ForParseResult;
286
272
  }
287
273
  /**
288
274
  * Static types have several levels.
@@ -348,6 +334,13 @@ export interface ForNode extends Node {
348
334
  children: TemplateChildNode[];
349
335
  codegenNode?: ForCodegenNode;
350
336
  }
337
+ export interface ForParseResult {
338
+ source: ExpressionNode;
339
+ value: ExpressionNode | undefined;
340
+ key: ExpressionNode | undefined;
341
+ index: ExpressionNode | undefined;
342
+ finalized: boolean;
343
+ }
351
344
  export interface TextCallNode extends Node {
352
345
  type: NodeTypes.TEXT_CALL;
353
346
  content: TextNode | InterpolationNode | CompoundExpressionNode;
@@ -520,7 +513,7 @@ export interface ForIteratorExpression extends FunctionExpression {
520
513
  returns: BlockCodegenNode;
521
514
  }
522
515
  export declare const locStub: SourceLocation;
523
- export declare function createRoot(children: TemplateChildNode[], loc?: SourceLocation): RootNode;
516
+ export declare function createRoot(children: TemplateChildNode[], source?: string): RootNode;
524
517
  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;
525
518
  export declare function createArrayExpression(elements: ArrayExpression['elements'], loc?: SourceLocation): ArrayExpression;
526
519
  export declare function createObjectExpression(properties: ObjectExpression['properties'], loc?: SourceLocation): ObjectExpression;
@@ -617,6 +610,24 @@ interface ErrorHandlingOptions {
617
610
  onError?: (error: CompilerError) => void;
618
611
  }
619
612
  export interface ParserOptions extends ErrorHandlingOptions, CompilerCompatOptions {
613
+ /**
614
+ * Base mode is platform agnostic and only parses HTML-like template syntax,
615
+ * treating all tags the same way. Specific tag parsing behavior can be
616
+ * configured by higher-level compilers.
617
+ *
618
+ * HTML mode adds additional logic for handling special parsing behavior in
619
+ * `<script>`, `<style>`,`<title>` and `<textarea>`.
620
+ * The logic is handled inside compiler-core for efficiency.
621
+ *
622
+ * SFC mode treats content of all root-level tags except `<template>` as plain
623
+ * text.
624
+ */
625
+ parseMode?: 'base' | 'html' | 'sfc';
626
+ /**
627
+ * Specify the root namepsace to use when parsing a tempalte.
628
+ * Defaults to `Namepsaces.HTML` (0).
629
+ */
630
+ ns?: Namespaces;
620
631
  /**
621
632
  * e.g. platform native elements, e.g. `<div>` for browsers
622
633
  */
@@ -640,11 +651,7 @@ export interface ParserOptions extends ErrorHandlingOptions, CompilerCompatOptio
640
651
  /**
641
652
  * Get tag namespace
642
653
  */
643
- getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace;
644
- /**
645
- * Get text parsing mode for this element
646
- */
647
- getTextMode?: (node: ElementNode, parent: ElementNode | undefined) => TextModes;
654
+ getNamespace?: (tag: string, parent: ElementNode | undefined, rootNamespace: Namespace) => Namespace;
648
655
  /**
649
656
  * @default ['{{', '}}']
650
657
  */
@@ -654,7 +661,8 @@ export interface ParserOptions extends ErrorHandlingOptions, CompilerCompatOptio
654
661
  */
655
662
  whitespace?: 'preserve' | 'condense';
656
663
  /**
657
- * Only needed for DOM compilers
664
+ * Only used for DOM compilers that runs in the browser.
665
+ * In non-browser builds, this option is ignored.
658
666
  */
659
667
  decodeEntities?: (rawText: string, asAttr: boolean) => string;
660
668
  /**
@@ -910,7 +918,7 @@ export interface CodegenContext extends Omit<Required<CodegenOptions>, 'bindingM
910
918
  pure: boolean;
911
919
  map?: SourceMapGenerator;
912
920
  helper(key: symbol): string;
913
- push(code: string, node?: CodegenNode): void;
921
+ push(code: string, newlineIndex?: number, node?: CodegenNode): void;
914
922
  indent(): void;
915
923
  deindent(withoutNewLine?: boolean): void;
916
924
  newline(): void;
@@ -924,10 +932,9 @@ export type TransformPreset = [
924
932
  Record<string, DirectiveTransform>
925
933
  ];
926
934
  export declare function getBaseTransformPreset(prefixIdentifiers?: boolean): TransformPreset;
927
- export declare function baseCompile(template: string | RootNode, options?: CompilerOptions): CodegenResult;
935
+ export declare function baseCompile(source: string | RootNode, options?: CompilerOptions): CodegenResult;
928
936
 
929
937
  export declare const isStaticExp: (p: JSChildNode) => p is SimpleExpressionNode;
930
- export declare const isBuiltInType: (tag: string, expected: string) => boolean;
931
938
  export declare function isCoreComponent(tag: string): symbol | void;
932
939
  export declare const isSimpleIdentifier: (name: string) => boolean;
933
940
  /**
@@ -939,7 +946,6 @@ export declare const isSimpleIdentifier: (name: string) => boolean;
939
946
  export declare const isMemberExpressionBrowser: (path: string) => boolean;
940
947
  export declare const isMemberExpressionNode: (path: string, context: TransformContext) => boolean;
941
948
  export declare const isMemberExpression: (path: string, context: TransformContext) => boolean;
942
- export declare function getInnerRange(loc: SourceLocation, offset: number, length: number): SourceLocation;
943
949
  export declare function advancePositionWithClone(pos: Position, source: string, numberOfCharacters?: number): Position;
944
950
  export declare function advancePositionWithMutation(pos: Position, source: string, numberOfCharacters?: number): Position;
945
951
  export declare function assert(condition: boolean, msg?: string): void;
@@ -955,6 +961,7 @@ export declare function injectProp(node: VNodeCall | RenderSlotCall, prop: Prope
955
961
  export declare function toValidAssetId(name: string, type: 'component' | 'directive' | 'filter'): string;
956
962
  export declare function hasScopeRef(node: TemplateChildNode | IfBranchNode | ExpressionNode | undefined, ids: TransformContext['identifiers']): boolean;
957
963
  export declare function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression): VNodeCall | RenderSlotCall;
964
+ export declare const forAliasRE: RegExp;
958
965
 
959
966
  export declare function walkIdentifiers(root: Node$1, onIdentifier: (node: Identifier, parent: Node$1, parentStack: Node$1[], isReference: boolean, isLocal: boolean) => void, includeAll?: boolean, parentStack?: Node$1[], knownIds?: Record<string, number>): void;
960
967
  export declare function isReferencedIdentifier(id: Identifier, parent: Node$1 | null, parentStack: Node$1[]): boolean;
@@ -977,13 +984,16 @@ export declare const noopDirectiveTransform: DirectiveTransform;
977
984
 
978
985
  export declare function processIf(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (node: IfNode, branch: IfBranchNode, isRoot: boolean) => (() => void) | undefined): (() => void) | undefined;
979
986
 
987
+ export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
988
+ export declare function createForLoopParams({ value, key, index }: ForParseResult, memoArgs?: ExpressionNode[]): ExpressionNode[];
989
+
980
990
  export declare const transformExpression: NodeTransform;
981
991
  export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean, localVars?: Record<string, number>): ExpressionNode;
982
992
  export declare function stringifyExpression(exp: ExpressionNode | string): string;
983
993
 
984
994
  export declare const trackSlotScopes: NodeTransform;
985
995
  export declare const trackVForSlotScopes: NodeTransform;
986
- export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, vForExp: ExpressionNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
996
+ export type SlotFnBuilder = (slotProps: ExpressionNode | undefined, vFor: DirectiveNode | undefined, slotChildren: TemplateChildNode[], loc: SourceLocation) => FunctionExpression;
987
997
  export declare function buildSlots(node: ElementNode, context: TransformContext, buildSlotFn?: SlotFnBuilder): {
988
998
  slots: SlotsExpression;
989
999
  hasDynamicSlots: boolean;