@vue/compat 3.2.12 → 3.2.13

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.
package/dist/vue.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var estreeWalker = require('estree-walker');
4
3
  var parser = require('@babel/parser');
4
+ var estreeWalker = require('estree-walker');
5
5
  var sourceMap = require('source-map');
6
6
 
7
7
  /**
@@ -1633,7 +1633,8 @@ class ComputedRefImpl {
1633
1633
  function computed(getterOrOptions, debugOptions) {
1634
1634
  let getter;
1635
1635
  let setter;
1636
- if (isFunction(getterOrOptions)) {
1636
+ const onlyGetter = isFunction(getterOrOptions);
1637
+ if (onlyGetter) {
1637
1638
  getter = getterOrOptions;
1638
1639
  setter = () => {
1639
1640
  console.warn('Write operation failed: computed value is readonly');
@@ -1644,7 +1645,7 @@ function computed(getterOrOptions, debugOptions) {
1644
1645
  getter = getterOrOptions.get;
1645
1646
  setter = getterOrOptions.set;
1646
1647
  }
1647
- const cRef = new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set);
1648
+ const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter);
1648
1649
  if (debugOptions) {
1649
1650
  cRef.effect.onTrack = debugOptions.onTrack;
1650
1651
  cRef.effect.onTrigger = debugOptions.onTrigger;
@@ -2099,7 +2100,7 @@ const deprecationData = {
2099
2100
  ["PRIVATE_APIS" /* PRIVATE_APIS */]: {
2100
2101
  message: name => `"${name}" is a Vue 2 private API that no longer exists in Vue 3. ` +
2101
2102
  `If you are seeing this warning only due to a dependency, you can ` +
2102
- `suppress this warning via { PRIVATE_APIS: 'supress-warning' }.`
2103
+ `suppress this warning via { PRIVATE_APIS: 'suppress-warning' }.`
2103
2104
  }
2104
2105
  };
2105
2106
  const instanceWarned = Object.create(null);
@@ -5420,7 +5421,7 @@ function createCompatVue(createApp, createSingletonApp) {
5420
5421
  return vm;
5421
5422
  }
5422
5423
  }
5423
- Vue.version = "3.2.12";
5424
+ Vue.version = "3.2.13";
5424
5425
  Vue.config = singletonApp.config;
5425
5426
  Vue.use = (p, ...options) => {
5426
5427
  if (p && isFunction(p.install)) {
@@ -5951,7 +5952,7 @@ function createAppAPI(render, hydrate) {
5951
5952
  app._instance = vnode.component;
5952
5953
  devtoolsInitApp(app, version);
5953
5954
  }
5954
- return vnode.component.proxy;
5955
+ return getExposeProxy(vnode.component) || vnode.component.proxy;
5955
5956
  }
5956
5957
  else {
5957
5958
  warn$1(`App has already been mounted.\n` +
@@ -6160,14 +6161,14 @@ function createHydrationFunctions(rendererInternals) {
6160
6161
  for (const key in props) {
6161
6162
  if ((forcePatchValue && key.endsWith('value')) ||
6162
6163
  (isOn(key) && !isReservedProp(key))) {
6163
- patchProp(el, key, null, props[key]);
6164
+ patchProp(el, key, null, props[key], false, undefined, parentComponent);
6164
6165
  }
6165
6166
  }
6166
6167
  }
6167
6168
  else if (props.onClick) {
6168
6169
  // Fast path for click listeners (which is most often) to avoid
6169
6170
  // iterating through props.
6170
- patchProp(el, 'onClick', null, props.onClick);
6171
+ patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
6171
6172
  }
6172
6173
  }
6173
6174
  // vnode / directive hooks
@@ -10604,7 +10605,7 @@ function createPathGetter(ctx, path) {
10604
10605
  return cur;
10605
10606
  };
10606
10607
  }
10607
- function traverse(value, seen = new Set()) {
10608
+ function traverse(value, seen) {
10608
10609
  if (!isObject(value) || value["__v_skip" /* SKIP */]) {
10609
10610
  return value;
10610
10611
  }
@@ -11020,7 +11021,7 @@ function isMemoSame(cached, memo) {
11020
11021
  }
11021
11022
 
11022
11023
  // Core API ------------------------------------------------------------------
11023
- const version = "3.2.12";
11024
+ const version = "3.2.13";
11024
11025
  const _ssrUtils = {
11025
11026
  createComponentInstance,
11026
11027
  setupComponent,
@@ -12980,7 +12981,7 @@ const errorMessages = {
12980
12981
  // transform errors
12981
12982
  [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
12982
12983
  [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
12983
- [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if.`,
12984
+ [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
12984
12985
  [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
12985
12986
  [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
12986
12987
  [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
@@ -13250,84 +13251,27 @@ function isCoreComponent(tag) {
13250
13251
  const nonIdentifierRE = /^\d|[^\$\w]/;
13251
13252
  const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
13252
13253
  const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
13253
- const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
13254
- const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
13255
- /**
13256
- * Simple lexer to check if an expression is a member expression. This is
13257
- * lax and only checks validity at the root level (i.e. does not validate exps
13258
- * inside square brackets), but it's ok since these are only used on template
13259
- * expressions and false positives are invalid expressions in the first place.
13260
- */
13261
- const isMemberExpression = (path) => {
13262
- // remove whitespaces around . or [ first
13263
- path = path.trim().replace(whitespaceRE, s => s.trim());
13264
- let state = 0 /* inMemberExp */;
13265
- let stateStack = [];
13266
- let currentOpenBracketCount = 0;
13267
- let currentOpenParensCount = 0;
13268
- let currentStringType = null;
13269
- for (let i = 0; i < path.length; i++) {
13270
- const char = path.charAt(i);
13271
- switch (state) {
13272
- case 0 /* inMemberExp */:
13273
- if (char === '[') {
13274
- stateStack.push(state);
13275
- state = 1 /* inBrackets */;
13276
- currentOpenBracketCount++;
13277
- }
13278
- else if (char === '(') {
13279
- stateStack.push(state);
13280
- state = 2 /* inParens */;
13281
- currentOpenParensCount++;
13282
- }
13283
- else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
13284
- return false;
13285
- }
13286
- break;
13287
- case 1 /* inBrackets */:
13288
- if (char === `'` || char === `"` || char === '`') {
13289
- stateStack.push(state);
13290
- state = 3 /* inString */;
13291
- currentStringType = char;
13292
- }
13293
- else if (char === `[`) {
13294
- currentOpenBracketCount++;
13295
- }
13296
- else if (char === `]`) {
13297
- if (!--currentOpenBracketCount) {
13298
- state = stateStack.pop();
13299
- }
13300
- }
13301
- break;
13302
- case 2 /* inParens */:
13303
- if (char === `'` || char === `"` || char === '`') {
13304
- stateStack.push(state);
13305
- state = 3 /* inString */;
13306
- currentStringType = char;
13307
- }
13308
- else if (char === `(`) {
13309
- currentOpenParensCount++;
13310
- }
13311
- else if (char === `)`) {
13312
- // if the exp ends as a call then it should not be considered valid
13313
- if (i === path.length - 1) {
13314
- return false;
13315
- }
13316
- if (!--currentOpenParensCount) {
13317
- state = stateStack.pop();
13318
- }
13319
- }
13320
- break;
13321
- case 3 /* inString */:
13322
- if (char === currentStringType) {
13323
- state = stateStack.pop();
13324
- currentStringType = null;
13325
- }
13326
- break;
13254
+ const isMemberExpressionNode = (path, context) => {
13255
+ path = path.trim();
13256
+ if (!validFirstIdentCharRE.test(path[0])) {
13257
+ return false;
13258
+ }
13259
+ try {
13260
+ let ret = parser.parseExpression(path, {
13261
+ plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
13262
+ });
13263
+ if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
13264
+ ret = ret.expression;
13327
13265
  }
13266
+ return (ret.type === 'MemberExpression' ||
13267
+ ret.type === 'OptionalMemberExpression' ||
13268
+ ret.type === 'Identifier');
13269
+ }
13270
+ catch (e) {
13271
+ return false;
13328
13272
  }
13329
- return !currentOpenBracketCount && !currentOpenParensCount;
13330
13273
  };
13274
+ const isMemberExpression = isMemberExpressionNode;
13331
13275
  function getInnerRange(loc, offset, length) {
13332
13276
  const source = loc.source.substr(offset, length);
13333
13277
  const newLoc = {
@@ -14517,7 +14461,7 @@ function walk$1(node, context, doNotHoistNode = false) {
14517
14461
  // This is only a concern for pre-stringification (via transformHoist by
14518
14462
  // @vue/compiler-dom), but doing it here allows us to perform only one full
14519
14463
  // walk of the AST and allow `stringifyStatic` to stop walking as soon as its
14520
- // stringficiation threshold is met.
14464
+ // stringification threshold is met.
14521
14465
  let canStringify = true;
14522
14466
  const { children } = node;
14523
14467
  const originalCount = children.length;
@@ -14763,7 +14707,7 @@ function getGeneratedPropsConstantType(node, context) {
14763
14707
  else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
14764
14708
  // some helper calls can be hoisted,
14765
14709
  // such as the `normalizeProps` generated by the compiler for pre-normalize class,
14766
- // in this case we need to respect the ConstanType of the helper's argments
14710
+ // in this case we need to respect the ConstantType of the helper's argments
14767
14711
  valueType = getConstantTypeOfHelperCall(value, context);
14768
14712
  }
14769
14713
  else {
@@ -15414,22 +15358,22 @@ function genHoists(hoists, context) {
15414
15358
  const { push, newline, helper, scopeId, mode } = context;
15415
15359
  const genScopeId = scopeId != null && mode !== 'function';
15416
15360
  newline();
15417
- // push scope Id before initializing hoisted vnodes so that these vnodes
15418
- // get the proper scopeId as well.
15361
+ // generate inlined withScopeId helper
15419
15362
  if (genScopeId) {
15420
- push(`${helper(PUSH_SCOPE_ID)}("${scopeId}")`);
15363
+ push(`const _withScopeId = n => (${helper(PUSH_SCOPE_ID)}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`);
15421
15364
  newline();
15422
15365
  }
15423
- hoists.forEach((exp, i) => {
15366
+ for (let i = 0; i < hoists.length; i++) {
15367
+ const exp = hoists[i];
15424
15368
  if (exp) {
15425
- push(`const _hoisted_${i + 1} = `);
15369
+ const needScopeIdWrapper = genScopeId && exp.type === 13 /* VNODE_CALL */;
15370
+ push(`const _hoisted_${i + 1} = ${needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : ``}`);
15426
15371
  genNode(exp, context);
15372
+ if (needScopeIdWrapper) {
15373
+ push(`)`);
15374
+ }
15427
15375
  newline();
15428
15376
  }
15429
- });
15430
- if (genScopeId) {
15431
- push(`${helper(POP_SCOPE_ID)}()`);
15432
- newline();
15433
15377
  }
15434
15378
  context.pure = false;
15435
15379
  }
@@ -16515,6 +16459,11 @@ function processIf(node, dir, context, processCodegen) {
16515
16459
  continue;
16516
16460
  }
16517
16461
  if (sibling && sibling.type === 9 /* IF */) {
16462
+ // Check if v-else was followed by v-else-if
16463
+ if (dir.name === 'else-if' &&
16464
+ sibling.branches[sibling.branches.length - 1].condition === undefined) {
16465
+ context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
16466
+ }
16518
16467
  // move the node to the if node's branches
16519
16468
  context.removeNode();
16520
16469
  const branch = createIfBranch(node, dir);
@@ -17727,7 +17676,7 @@ function dedupeProperties(properties) {
17727
17676
  const name = prop.key.content;
17728
17677
  const existing = knownProps.get(name);
17729
17678
  if (existing) {
17730
- if (name === 'style' || name === 'class' || name.startsWith('on')) {
17679
+ if (name === 'style' || name === 'class' || isOn(name)) {
17731
17680
  mergeAsArray$1(existing, prop);
17732
17681
  }
17733
17682
  // unexpected duplicate, should have emitted error during parse
@@ -17823,26 +17772,24 @@ const transformSlotOutlet = (node, context) => {
17823
17772
  const { slotName, slotProps } = processSlotOutlet(node, context);
17824
17773
  const slotArgs = [
17825
17774
  context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
17826
- slotName
17775
+ slotName,
17776
+ '{}',
17777
+ 'undefined',
17778
+ 'true'
17827
17779
  ];
17780
+ let expectedLen = 2;
17828
17781
  if (slotProps) {
17829
- slotArgs.push(slotProps);
17782
+ slotArgs[2] = slotProps;
17783
+ expectedLen = 3;
17830
17784
  }
17831
17785
  if (children.length) {
17832
- if (!slotProps) {
17833
- slotArgs.push(`{}`);
17834
- }
17835
- slotArgs.push(createFunctionExpression([], children, false, false, loc));
17786
+ slotArgs[3] = createFunctionExpression([], children, false, false, loc);
17787
+ expectedLen = 4;
17836
17788
  }
17837
17789
  if (context.scopeId && !context.slotted) {
17838
- if (!slotProps) {
17839
- slotArgs.push(`{}`);
17840
- }
17841
- if (!children.length) {
17842
- slotArgs.push(`undefined`);
17843
- }
17844
- slotArgs.push(`true`);
17790
+ expectedLen = 5;
17845
17791
  }
17792
+ slotArgs.splice(expectedLen); // remove unused arguments
17846
17793
  node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
17847
17794
  }
17848
17795
  };
@@ -17924,7 +17871,7 @@ const transformOn = (dir, node, context, augmentor) => {
17924
17871
  }
17925
17872
  let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
17926
17873
  if (exp) {
17927
- const isMemberExp = isMemberExpression(exp.content);
17874
+ const isMemberExp = isMemberExpression(exp.content, context);
17928
17875
  const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
17929
17876
  const hasMultipleStatements = exp.content.includes(`;`);
17930
17877
  // process the expression since it's been skipped
@@ -18181,7 +18128,8 @@ const transformModel = (dir, node, context) => {
18181
18128
  const maybeRef = context.inline &&
18182
18129
  bindingType &&
18183
18130
  bindingType !== "setup-const" /* SETUP_CONST */;
18184
- if (!expString.trim() || (!isMemberExpression(expString) && !maybeRef)) {
18131
+ if (!expString.trim() ||
18132
+ (!isMemberExpression(expString, context) && !maybeRef)) {
18185
18133
  context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
18186
18134
  return createTransformProps();
18187
18135
  }
@@ -18490,6 +18438,12 @@ function baseCompile(template, options = {}) {
18490
18438
  }
18491
18439
  const ast = isString(template) ? baseParse(template, options) : template;
18492
18440
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
18441
+ if (options.isTS) {
18442
+ const { expressionPlugins } = options;
18443
+ if (!expressionPlugins || !expressionPlugins.includes('typescript')) {
18444
+ options.expressionPlugins = [...(expressionPlugins || []), 'typescript'];
18445
+ }
18446
+ }
18493
18447
  transform(ast, extend({}, options, {
18494
18448
  prefixIdentifiers,
18495
18449
  nodeTransforms: [
@@ -21256,7 +21210,8 @@ const warnTransitionChildren = (node, context) => {
21256
21210
  };
21257
21211
  function hasMultipleChildren(node) {
21258
21212
  // #1352 filter out potential comment nodes.
21259
- const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */));
21213
+ const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
21214
+ !(c.type === 2 /* TEXT */ && !c.content.trim())));
21260
21215
  const child = children[0];
21261
21216
  return (children.length !== 1 ||
21262
21217
  child.type === 11 /* FOR */ ||
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var estreeWalker = require('estree-walker');
4
3
  var parser = require('@babel/parser');
4
+ var estreeWalker = require('estree-walker');
5
5
  var sourceMap = require('source-map');
6
6
 
7
7
  /**
@@ -1476,7 +1476,8 @@ class ComputedRefImpl {
1476
1476
  function computed(getterOrOptions, debugOptions) {
1477
1477
  let getter;
1478
1478
  let setter;
1479
- if (isFunction(getterOrOptions)) {
1479
+ const onlyGetter = isFunction(getterOrOptions);
1480
+ if (onlyGetter) {
1480
1481
  getter = getterOrOptions;
1481
1482
  setter = NOOP;
1482
1483
  }
@@ -1484,7 +1485,7 @@ function computed(getterOrOptions, debugOptions) {
1484
1485
  getter = getterOrOptions.get;
1485
1486
  setter = getterOrOptions.set;
1486
1487
  }
1487
- const cRef = new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set);
1488
+ const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter);
1488
1489
  return cRef;
1489
1490
  }
1490
1491
 
@@ -4232,7 +4233,7 @@ function createCompatVue(createApp, createSingletonApp) {
4232
4233
  return vm;
4233
4234
  }
4234
4235
  }
4235
- Vue.version = "3.2.12";
4236
+ Vue.version = "3.2.13";
4236
4237
  Vue.config = singletonApp.config;
4237
4238
  Vue.use = (p, ...options) => {
4238
4239
  if (p && isFunction(p.install)) {
@@ -4688,7 +4689,7 @@ function createAppAPI(render, hydrate) {
4688
4689
  isMounted = true;
4689
4690
  app._container = rootContainer;
4690
4691
  rootContainer.__vue_app__ = app;
4691
- return vnode.component.proxy;
4692
+ return getExposeProxy(vnode.component) || vnode.component.proxy;
4692
4693
  }
4693
4694
  },
4694
4695
  unmount() {
@@ -4873,14 +4874,14 @@ function createHydrationFunctions(rendererInternals) {
4873
4874
  for (const key in props) {
4874
4875
  if ((forcePatchValue && key.endsWith('value')) ||
4875
4876
  (isOn(key) && !isReservedProp(key))) {
4876
- patchProp(el, key, null, props[key]);
4877
+ patchProp(el, key, null, props[key], false, undefined, parentComponent);
4877
4878
  }
4878
4879
  }
4879
4880
  }
4880
4881
  else if (props.onClick) {
4881
4882
  // Fast path for click listeners (which is most often) to avoid
4882
4883
  // iterating through props.
4883
- patchProp(el, 'onClick', null, props.onClick);
4884
+ patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
4884
4885
  }
4885
4886
  }
4886
4887
  // vnode / directive hooks
@@ -8700,7 +8701,7 @@ function createPathGetter(ctx, path) {
8700
8701
  return cur;
8701
8702
  };
8702
8703
  }
8703
- function traverse(value, seen = new Set()) {
8704
+ function traverse(value, seen) {
8704
8705
  if (!isObject(value) || value["__v_skip" /* SKIP */]) {
8705
8706
  return value;
8706
8707
  }
@@ -8909,7 +8910,7 @@ function isMemoSame(cached, memo) {
8909
8910
  }
8910
8911
 
8911
8912
  // Core API ------------------------------------------------------------------
8912
- const version = "3.2.12";
8913
+ const version = "3.2.13";
8913
8914
  const _ssrUtils = {
8914
8915
  createComponentInstance,
8915
8916
  setupComponent,
@@ -10749,7 +10750,7 @@ const errorMessages = {
10749
10750
  // transform errors
10750
10751
  [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
10751
10752
  [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
10752
- [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if.`,
10753
+ [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
10753
10754
  [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
10754
10755
  [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
10755
10756
  [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
@@ -11019,84 +11020,27 @@ function isCoreComponent(tag) {
11019
11020
  const nonIdentifierRE = /^\d|[^\$\w]/;
11020
11021
  const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
11021
11022
  const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
11022
- const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
11023
- const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
11024
- /**
11025
- * Simple lexer to check if an expression is a member expression. This is
11026
- * lax and only checks validity at the root level (i.e. does not validate exps
11027
- * inside square brackets), but it's ok since these are only used on template
11028
- * expressions and false positives are invalid expressions in the first place.
11029
- */
11030
- const isMemberExpression = (path) => {
11031
- // remove whitespaces around . or [ first
11032
- path = path.trim().replace(whitespaceRE, s => s.trim());
11033
- let state = 0 /* inMemberExp */;
11034
- let stateStack = [];
11035
- let currentOpenBracketCount = 0;
11036
- let currentOpenParensCount = 0;
11037
- let currentStringType = null;
11038
- for (let i = 0; i < path.length; i++) {
11039
- const char = path.charAt(i);
11040
- switch (state) {
11041
- case 0 /* inMemberExp */:
11042
- if (char === '[') {
11043
- stateStack.push(state);
11044
- state = 1 /* inBrackets */;
11045
- currentOpenBracketCount++;
11046
- }
11047
- else if (char === '(') {
11048
- stateStack.push(state);
11049
- state = 2 /* inParens */;
11050
- currentOpenParensCount++;
11051
- }
11052
- else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
11053
- return false;
11054
- }
11055
- break;
11056
- case 1 /* inBrackets */:
11057
- if (char === `'` || char === `"` || char === '`') {
11058
- stateStack.push(state);
11059
- state = 3 /* inString */;
11060
- currentStringType = char;
11061
- }
11062
- else if (char === `[`) {
11063
- currentOpenBracketCount++;
11064
- }
11065
- else if (char === `]`) {
11066
- if (!--currentOpenBracketCount) {
11067
- state = stateStack.pop();
11068
- }
11069
- }
11070
- break;
11071
- case 2 /* inParens */:
11072
- if (char === `'` || char === `"` || char === '`') {
11073
- stateStack.push(state);
11074
- state = 3 /* inString */;
11075
- currentStringType = char;
11076
- }
11077
- else if (char === `(`) {
11078
- currentOpenParensCount++;
11079
- }
11080
- else if (char === `)`) {
11081
- // if the exp ends as a call then it should not be considered valid
11082
- if (i === path.length - 1) {
11083
- return false;
11084
- }
11085
- if (!--currentOpenParensCount) {
11086
- state = stateStack.pop();
11087
- }
11088
- }
11089
- break;
11090
- case 3 /* inString */:
11091
- if (char === currentStringType) {
11092
- state = stateStack.pop();
11093
- currentStringType = null;
11094
- }
11095
- break;
11023
+ const isMemberExpressionNode = (path, context) => {
11024
+ path = path.trim();
11025
+ if (!validFirstIdentCharRE.test(path[0])) {
11026
+ return false;
11027
+ }
11028
+ try {
11029
+ let ret = parser.parseExpression(path, {
11030
+ plugins: [...context.expressionPlugins, ...babelParserDefaultPlugins]
11031
+ });
11032
+ if (ret.type === 'TSAsExpression' || ret.type === 'TSTypeAssertion') {
11033
+ ret = ret.expression;
11096
11034
  }
11035
+ return (ret.type === 'MemberExpression' ||
11036
+ ret.type === 'OptionalMemberExpression' ||
11037
+ ret.type === 'Identifier');
11038
+ }
11039
+ catch (e) {
11040
+ return false;
11097
11041
  }
11098
- return !currentOpenBracketCount && !currentOpenParensCount;
11099
11042
  };
11043
+ const isMemberExpression = isMemberExpressionNode;
11100
11044
  function getInnerRange(loc, offset, length) {
11101
11045
  const source = loc.source.substr(offset, length);
11102
11046
  const newLoc = {
@@ -12184,7 +12128,7 @@ function walk$1(node, context, doNotHoistNode = false) {
12184
12128
  // This is only a concern for pre-stringification (via transformHoist by
12185
12129
  // @vue/compiler-dom), but doing it here allows us to perform only one full
12186
12130
  // walk of the AST and allow `stringifyStatic` to stop walking as soon as its
12187
- // stringficiation threshold is met.
12131
+ // stringification threshold is met.
12188
12132
  let canStringify = true;
12189
12133
  const { children } = node;
12190
12134
  const originalCount = children.length;
@@ -12430,7 +12374,7 @@ function getGeneratedPropsConstantType(node, context) {
12430
12374
  else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
12431
12375
  // some helper calls can be hoisted,
12432
12376
  // such as the `normalizeProps` generated by the compiler for pre-normalize class,
12433
- // in this case we need to respect the ConstanType of the helper's argments
12377
+ // in this case we need to respect the ConstantType of the helper's argments
12434
12378
  valueType = getConstantTypeOfHelperCall(value, context);
12435
12379
  }
12436
12380
  else {
@@ -13058,22 +13002,22 @@ function genHoists(hoists, context) {
13058
13002
  const { push, newline, helper, scopeId, mode } = context;
13059
13003
  const genScopeId = scopeId != null && mode !== 'function';
13060
13004
  newline();
13061
- // push scope Id before initializing hoisted vnodes so that these vnodes
13062
- // get the proper scopeId as well.
13005
+ // generate inlined withScopeId helper
13063
13006
  if (genScopeId) {
13064
- push(`${helper(PUSH_SCOPE_ID)}("${scopeId}")`);
13007
+ push(`const _withScopeId = n => (${helper(PUSH_SCOPE_ID)}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`);
13065
13008
  newline();
13066
13009
  }
13067
- hoists.forEach((exp, i) => {
13010
+ for (let i = 0; i < hoists.length; i++) {
13011
+ const exp = hoists[i];
13068
13012
  if (exp) {
13069
- push(`const _hoisted_${i + 1} = `);
13013
+ const needScopeIdWrapper = genScopeId && exp.type === 13 /* VNODE_CALL */;
13014
+ push(`const _hoisted_${i + 1} = ${needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : ``}`);
13070
13015
  genNode(exp, context);
13016
+ if (needScopeIdWrapper) {
13017
+ push(`)`);
13018
+ }
13071
13019
  newline();
13072
13020
  }
13073
- });
13074
- if (genScopeId) {
13075
- push(`${helper(POP_SCOPE_ID)}()`);
13076
- newline();
13077
13021
  }
13078
13022
  context.pure = false;
13079
13023
  }
@@ -14140,6 +14084,11 @@ function processIf(node, dir, context, processCodegen) {
14140
14084
  continue;
14141
14085
  }
14142
14086
  if (sibling && sibling.type === 9 /* IF */) {
14087
+ // Check if v-else was followed by v-else-if
14088
+ if (dir.name === 'else-if' &&
14089
+ sibling.branches[sibling.branches.length - 1].condition === undefined) {
14090
+ context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
14091
+ }
14143
14092
  // move the node to the if node's branches
14144
14093
  context.removeNode();
14145
14094
  const branch = createIfBranch(node, dir);
@@ -15295,7 +15244,7 @@ function dedupeProperties(properties) {
15295
15244
  const name = prop.key.content;
15296
15245
  const existing = knownProps.get(name);
15297
15246
  if (existing) {
15298
- if (name === 'style' || name === 'class' || name.startsWith('on')) {
15247
+ if (name === 'style' || name === 'class' || isOn(name)) {
15299
15248
  mergeAsArray$1(existing, prop);
15300
15249
  }
15301
15250
  // unexpected duplicate, should have emitted error during parse
@@ -15391,26 +15340,24 @@ const transformSlotOutlet = (node, context) => {
15391
15340
  const { slotName, slotProps } = processSlotOutlet(node, context);
15392
15341
  const slotArgs = [
15393
15342
  context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
15394
- slotName
15343
+ slotName,
15344
+ '{}',
15345
+ 'undefined',
15346
+ 'true'
15395
15347
  ];
15348
+ let expectedLen = 2;
15396
15349
  if (slotProps) {
15397
- slotArgs.push(slotProps);
15350
+ slotArgs[2] = slotProps;
15351
+ expectedLen = 3;
15398
15352
  }
15399
15353
  if (children.length) {
15400
- if (!slotProps) {
15401
- slotArgs.push(`{}`);
15402
- }
15403
- slotArgs.push(createFunctionExpression([], children, false, false, loc));
15354
+ slotArgs[3] = createFunctionExpression([], children, false, false, loc);
15355
+ expectedLen = 4;
15404
15356
  }
15405
15357
  if (context.scopeId && !context.slotted) {
15406
- if (!slotProps) {
15407
- slotArgs.push(`{}`);
15408
- }
15409
- if (!children.length) {
15410
- slotArgs.push(`undefined`);
15411
- }
15412
- slotArgs.push(`true`);
15358
+ expectedLen = 5;
15413
15359
  }
15360
+ slotArgs.splice(expectedLen); // remove unused arguments
15414
15361
  node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
15415
15362
  }
15416
15363
  };
@@ -15492,7 +15439,7 @@ const transformOn = (dir, node, context, augmentor) => {
15492
15439
  }
15493
15440
  let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
15494
15441
  if (exp) {
15495
- const isMemberExp = isMemberExpression(exp.content);
15442
+ const isMemberExp = isMemberExpression(exp.content, context);
15496
15443
  const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
15497
15444
  const hasMultipleStatements = exp.content.includes(`;`);
15498
15445
  // process the expression since it's been skipped
@@ -15749,7 +15696,8 @@ const transformModel = (dir, node, context) => {
15749
15696
  const maybeRef = context.inline &&
15750
15697
  bindingType &&
15751
15698
  bindingType !== "setup-const" /* SETUP_CONST */;
15752
- if (!expString.trim() || (!isMemberExpression(expString) && !maybeRef)) {
15699
+ if (!expString.trim() ||
15700
+ (!isMemberExpression(expString, context) && !maybeRef)) {
15753
15701
  context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
15754
15702
  return createTransformProps();
15755
15703
  }
@@ -16057,6 +16005,12 @@ function baseCompile(template, options = {}) {
16057
16005
  }
16058
16006
  const ast = isString(template) ? baseParse(template, options) : template;
16059
16007
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
16008
+ if (options.isTS) {
16009
+ const { expressionPlugins } = options;
16010
+ if (!expressionPlugins || !expressionPlugins.includes('typescript')) {
16011
+ options.expressionPlugins = [...(expressionPlugins || []), 'typescript'];
16012
+ }
16013
+ }
16060
16014
  transform(ast, extend({}, options, {
16061
16015
  prefixIdentifiers,
16062
16016
  nodeTransforms: [