@vue/compiler-sfc 3.2.34 → 3.2.37

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.
@@ -109,8 +109,6 @@ function sum (o) {
109
109
  var hashSum = sum;
110
110
 
111
111
  const CSS_VARS_HELPER = `useCssVars`;
112
- // match v-bind() with max 2-levels of nested parens.
113
- const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
114
112
  function genCssVarsFromList(vars, id, isProd, isSSR = false) {
115
113
  return `{\n ${vars
116
114
  .map(key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`)
@@ -132,31 +130,89 @@ function normalizeExpression(exp) {
132
130
  }
133
131
  return exp;
134
132
  }
133
+ const vBindRE = /v-bind\s*\(/g;
135
134
  function parseCssVars(sfc) {
136
135
  const vars = [];
137
136
  sfc.styles.forEach(style => {
138
137
  let match;
139
138
  // ignore v-bind() in comments /* ... */
140
139
  const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
141
- while ((match = cssVarRE.exec(content))) {
142
- const variable = normalizeExpression(match[1]);
143
- if (!vars.includes(variable)) {
144
- vars.push(variable);
140
+ while ((match = vBindRE.exec(content))) {
141
+ const start = match.index + match[0].length;
142
+ const end = lexBinding(content, start);
143
+ if (end !== null) {
144
+ const variable = normalizeExpression(content.slice(start, end));
145
+ if (!vars.includes(variable)) {
146
+ vars.push(variable);
147
+ }
145
148
  }
146
149
  }
147
150
  });
148
151
  return vars;
149
152
  }
153
+ function lexBinding(content, start) {
154
+ let state = 0 /* inParens */;
155
+ let parenDepth = 0;
156
+ for (let i = start; i < content.length; i++) {
157
+ const char = content.charAt(i);
158
+ switch (state) {
159
+ case 0 /* inParens */:
160
+ if (char === `'`) {
161
+ state = 1 /* inSingleQuoteString */;
162
+ }
163
+ else if (char === `"`) {
164
+ state = 2 /* inDoubleQuoteString */;
165
+ }
166
+ else if (char === `(`) {
167
+ parenDepth++;
168
+ }
169
+ else if (char === `)`) {
170
+ if (parenDepth > 0) {
171
+ parenDepth--;
172
+ }
173
+ else {
174
+ return i;
175
+ }
176
+ }
177
+ break;
178
+ case 1 /* inSingleQuoteString */:
179
+ if (char === `'`) {
180
+ state = 0 /* inParens */;
181
+ }
182
+ break;
183
+ case 2 /* inDoubleQuoteString */:
184
+ if (char === `"`) {
185
+ state = 0 /* inParens */;
186
+ }
187
+ break;
188
+ }
189
+ }
190
+ return null;
191
+ }
150
192
  const cssVarsPlugin = opts => {
151
193
  const { id, isProd } = opts;
152
194
  return {
153
195
  postcssPlugin: 'vue-sfc-vars',
154
196
  Declaration(decl) {
155
197
  // rewrite CSS variables
156
- if (cssVarRE.test(decl.value)) {
157
- decl.value = decl.value.replace(cssVarRE, (_, $1) => {
158
- return `var(--${genVarName(id, normalizeExpression($1), isProd)})`;
159
- });
198
+ const value = decl.value;
199
+ if (vBindRE.test(value)) {
200
+ vBindRE.lastIndex = 0;
201
+ let transformed = '';
202
+ let lastIndex = 0;
203
+ let match;
204
+ while ((match = vBindRE.exec(value))) {
205
+ const start = match.index + match[0].length;
206
+ const end = lexBinding(value, start);
207
+ if (end !== null) {
208
+ const variable = normalizeExpression(value.slice(start, end));
209
+ transformed +=
210
+ value.slice(lastIndex, match.index) +
211
+ `var(--${genVarName(id, variable, isProd)})`;
212
+ lastIndex = end + 1;
213
+ }
214
+ }
215
+ decl.value = transformed + value.slice(lastIndex);
160
216
  }
161
217
  }
162
218
  };
@@ -3313,7 +3369,7 @@ function rewriteDefault(input, as, parserPlugins) {
3313
3369
  }
3314
3370
  else {
3315
3371
  const end = specifierEnd(input, specifier.exported.end, node.end);
3316
- s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source?.value}'\n`);
3372
+ s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source.value}'\n`);
3317
3373
  s.overwrite(specifier.start, end, ``);
3318
3374
  s.append(`\nconst ${as} = ${specifier.local.name}`);
3319
3375
  continue;
@@ -3358,13 +3414,14 @@ const DEFINE_EXPOSE = 'defineExpose';
3358
3414
  const WITH_DEFAULTS = 'withDefaults';
3359
3415
  // constants
3360
3416
  const DEFAULT_VAR = `__default__`;
3361
- const isBuiltInDir = shared.makeMap(`once,memo,if,else,else-if,slot,text,html,on,bind,model,show,cloak,is`);
3417
+ const isBuiltInDir = shared.makeMap(`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`);
3362
3418
  /**
3363
3419
  * Compile `<script setup>`
3364
3420
  * It requires the whole SFC descriptor because we need to handle and merge
3365
3421
  * normal `<script>` + `<script setup>` if both are present.
3366
3422
  */
3367
3423
  function compileScript(sfc, options) {
3424
+ var _a;
3368
3425
  let { script, scriptSetup, source, filename } = sfc;
3369
3426
  // feature flags
3370
3427
  // TODO remove support for deprecated options when out of experimental
@@ -4237,7 +4294,7 @@ function compileScript(sfc, options) {
4237
4294
  // 8. inject `useCssVars` calls
4238
4295
  if (cssVars.length &&
4239
4296
  // no need to do this when targeting SSR
4240
- !(options.inlineTemplate && options.templateOptions?.ssr)) {
4297
+ !(options.inlineTemplate && ((_a = options.templateOptions) === null || _a === void 0 ? void 0 : _a.ssr))) {
4241
4298
  helperImports.add(CSS_VARS_HELPER);
4242
4299
  helperImports.add('unref');
4243
4300
  s.prependRight(startOffset, `\n${genCssVarsCode(cssVars, bindingMetadata, scopeId, isProd)}\n`);
@@ -4364,7 +4421,7 @@ function compileScript(sfc, options) {
4364
4421
  if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
4365
4422
  const match = filename.match(/([^/\\]+)\.\w+$/);
4366
4423
  if (match) {
4367
- runtimeOptions += `\n name: '${match[1]}',`;
4424
+ runtimeOptions += `\n __name: '${match[1]}',`;
4368
4425
  }
4369
4426
  }
4370
4427
  if (hasInlinedSsrRenderFn) {
@@ -4445,8 +4502,8 @@ function compileScript(sfc, options) {
4445
4502
  includeContent: true
4446
4503
  })
4447
4504
  : undefined,
4448
- scriptAst: scriptAst?.body,
4449
- scriptSetupAst: scriptSetupAst?.body
4505
+ scriptAst: scriptAst === null || scriptAst === void 0 ? void 0 : scriptAst.body,
4506
+ scriptSetupAst: scriptSetupAst === null || scriptSetupAst === void 0 ? void 0 : scriptSetupAst.body
4450
4507
  };
4451
4508
  }
4452
4509
  function registerBinding(bindings, node, type) {
@@ -4889,7 +4946,7 @@ function resolveTemplateUsageCheckString(sfc) {
4889
4946
  code += `,v${shared.capitalize(shared.camelize(prop.name))}`;
4890
4947
  }
4891
4948
  if (prop.exp) {
4892
- code += `,${processExp(prop.exp.content)}`;
4949
+ code += `,${processExp(prop.exp.content, prop.name)}`;
4893
4950
  }
4894
4951
  }
4895
4952
  }
@@ -4904,8 +4961,19 @@ function resolveTemplateUsageCheckString(sfc) {
4904
4961
  templateUsageCheckCache.set(content, code);
4905
4962
  return code;
4906
4963
  }
4907
- function processExp(exp) {
4908
- if (/ as \w|<.*>/.test(exp)) {
4964
+ const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
4965
+ function processExp(exp, dir) {
4966
+ if (/ as\s+\w|<.*>|:/.test(exp)) {
4967
+ if (dir === 'slot') {
4968
+ exp = `(${exp})=>{}`;
4969
+ }
4970
+ else if (dir === 'for') {
4971
+ const inMatch = exp.match(forAliasRE);
4972
+ if (inMatch) {
4973
+ const [, LHS, RHS] = inMatch;
4974
+ return processExp(`(${LHS})=>{}`) + processExp(RHS);
4975
+ }
4976
+ }
4909
4977
  let ret = '';
4910
4978
  // has potential type cast or generic arguments that uses types
4911
4979
  const ast = parser$2.parseExpression(exp, { plugins: ['typescript'] });
@@ -17347,6 +17347,14 @@ function getConstantType(node, context) {
17347
17347
  // static then they don't need to be blocks since there will be no
17348
17348
  // nested updates.
17349
17349
  if (codegenNode.isBlock) {
17350
+ // except set custom directives.
17351
+ for (let i = 0; i < node.props.length; i++) {
17352
+ const p = node.props[i];
17353
+ if (p.type === 7 /* DIRECTIVE */) {
17354
+ constantCache.set(node, 0 /* NOT_CONSTANT */);
17355
+ return 0 /* NOT_CONSTANT */;
17356
+ }
17357
+ }
17350
17358
  context.removeHelper(OPEN_BLOCK);
17351
17359
  context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
17352
17360
  codegenNode.isBlock = false;
@@ -27708,8 +27716,6 @@ function sum (o) {
27708
27716
  var hashSum = sum;
27709
27717
 
27710
27718
  const CSS_VARS_HELPER = `useCssVars`;
27711
- // match v-bind() with max 2-levels of nested parens.
27712
- const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
27713
27719
  function genCssVarsFromList(vars, id, isProd, isSSR = false) {
27714
27720
  return `{\n ${vars
27715
27721
  .map(key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`)
@@ -27731,31 +27737,89 @@ function normalizeExpression(exp) {
27731
27737
  }
27732
27738
  return exp;
27733
27739
  }
27740
+ const vBindRE = /v-bind\s*\(/g;
27734
27741
  function parseCssVars(sfc) {
27735
27742
  const vars = [];
27736
27743
  sfc.styles.forEach(style => {
27737
27744
  let match;
27738
27745
  // ignore v-bind() in comments /* ... */
27739
27746
  const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
27740
- while ((match = cssVarRE.exec(content))) {
27741
- const variable = normalizeExpression(match[1]);
27742
- if (!vars.includes(variable)) {
27743
- vars.push(variable);
27747
+ while ((match = vBindRE.exec(content))) {
27748
+ const start = match.index + match[0].length;
27749
+ const end = lexBinding(content, start);
27750
+ if (end !== null) {
27751
+ const variable = normalizeExpression(content.slice(start, end));
27752
+ if (!vars.includes(variable)) {
27753
+ vars.push(variable);
27754
+ }
27744
27755
  }
27745
27756
  }
27746
27757
  });
27747
27758
  return vars;
27748
27759
  }
27760
+ function lexBinding(content, start) {
27761
+ let state = 0 /* inParens */;
27762
+ let parenDepth = 0;
27763
+ for (let i = start; i < content.length; i++) {
27764
+ const char = content.charAt(i);
27765
+ switch (state) {
27766
+ case 0 /* inParens */:
27767
+ if (char === `'`) {
27768
+ state = 1 /* inSingleQuoteString */;
27769
+ }
27770
+ else if (char === `"`) {
27771
+ state = 2 /* inDoubleQuoteString */;
27772
+ }
27773
+ else if (char === `(`) {
27774
+ parenDepth++;
27775
+ }
27776
+ else if (char === `)`) {
27777
+ if (parenDepth > 0) {
27778
+ parenDepth--;
27779
+ }
27780
+ else {
27781
+ return i;
27782
+ }
27783
+ }
27784
+ break;
27785
+ case 1 /* inSingleQuoteString */:
27786
+ if (char === `'`) {
27787
+ state = 0 /* inParens */;
27788
+ }
27789
+ break;
27790
+ case 2 /* inDoubleQuoteString */:
27791
+ if (char === `"`) {
27792
+ state = 0 /* inParens */;
27793
+ }
27794
+ break;
27795
+ }
27796
+ }
27797
+ return null;
27798
+ }
27749
27799
  const cssVarsPlugin = opts => {
27750
27800
  const { id, isProd } = opts;
27751
27801
  return {
27752
27802
  postcssPlugin: 'vue-sfc-vars',
27753
27803
  Declaration(decl) {
27754
27804
  // rewrite CSS variables
27755
- if (cssVarRE.test(decl.value)) {
27756
- decl.value = decl.value.replace(cssVarRE, (_, $1) => {
27757
- return `var(--${genVarName(id, normalizeExpression($1), isProd)})`;
27758
- });
27805
+ const value = decl.value;
27806
+ if (vBindRE.test(value)) {
27807
+ vBindRE.lastIndex = 0;
27808
+ let transformed = '';
27809
+ let lastIndex = 0;
27810
+ let match;
27811
+ while ((match = vBindRE.exec(value))) {
27812
+ const start = match.index + match[0].length;
27813
+ const end = lexBinding(value, start);
27814
+ if (end !== null) {
27815
+ const variable = normalizeExpression(value.slice(start, end));
27816
+ transformed +=
27817
+ value.slice(lastIndex, match.index) +
27818
+ `var(--${genVarName(id, variable, isProd)})`;
27819
+ lastIndex = end + 1;
27820
+ }
27821
+ }
27822
+ decl.value = transformed + value.slice(lastIndex);
27759
27823
  }
27760
27824
  }
27761
27825
  };
@@ -33476,6 +33540,10 @@ const ssrTransformSlotOutlet = (node, context) => {
33476
33540
  resolveComponentType(parent, context, true) === TRANSITION &&
33477
33541
  parent.children.filter(c => c.type === 1 /* ELEMENT */).length === 1) {
33478
33542
  method = SSR_RENDER_SLOT_INNER;
33543
+ if (!(context.scopeId && context.slotted !== false)) {
33544
+ args.push('null');
33545
+ }
33546
+ args.push('true');
33479
33547
  }
33480
33548
  node.ssrCodegenNode = createCallExpression(context.helper(method), args);
33481
33549
  }
@@ -34804,7 +34872,6 @@ function rewriteDefault(input, as, parserPlugins) {
34804
34872
  plugins: parserPlugins
34805
34873
  }).program.body;
34806
34874
  ast.forEach(node => {
34807
- var _a;
34808
34875
  if (node.type === 'ExportDefaultDeclaration') {
34809
34876
  s.overwrite(node.start, node.declaration.start, `const ${as} = `);
34810
34877
  }
@@ -34823,7 +34890,7 @@ function rewriteDefault(input, as, parserPlugins) {
34823
34890
  }
34824
34891
  else {
34825
34892
  const end = specifierEnd(input, specifier.exported.end, node.end);
34826
- s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${(_a = node.source) === null || _a === void 0 ? void 0 : _a.value}'\n`);
34893
+ s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source.value}'\n`);
34827
34894
  s.overwrite(specifier.start, end, ``);
34828
34895
  s.append(`\nconst ${as} = ${specifier.local.name}`);
34829
34896
  continue;
@@ -35385,7 +35452,7 @@ const DEFINE_EXPOSE = 'defineExpose';
35385
35452
  const WITH_DEFAULTS = 'withDefaults';
35386
35453
  // constants
35387
35454
  const DEFAULT_VAR = `__default__`;
35388
- const isBuiltInDir = makeMap(`once,memo,if,else,else-if,slot,text,html,on,bind,model,show,cloak,is`);
35455
+ const isBuiltInDir = makeMap(`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`);
35389
35456
  /**
35390
35457
  * Compile `<script setup>`
35391
35458
  * It requires the whole SFC descriptor because we need to handle and merge
@@ -36371,7 +36438,7 @@ function compileScript(sfc, options) {
36371
36438
  if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
36372
36439
  const match = filename.match(/([^/\\]+)\.\w+$/);
36373
36440
  if (match) {
36374
- runtimeOptions += `\n name: '${match[1]}',`;
36441
+ runtimeOptions += `\n __name: '${match[1]}',`;
36375
36442
  }
36376
36443
  }
36377
36444
  if (hasInlinedSsrRenderFn) {
@@ -36888,7 +36955,7 @@ function resolveTemplateUsageCheckString(sfc) {
36888
36955
  code += `,v${capitalize(camelize(prop.name))}`;
36889
36956
  }
36890
36957
  if (prop.exp) {
36891
- code += `,${processExp(prop.exp.content)}`;
36958
+ code += `,${processExp(prop.exp.content, prop.name)}`;
36892
36959
  }
36893
36960
  }
36894
36961
  }
@@ -36903,8 +36970,19 @@ function resolveTemplateUsageCheckString(sfc) {
36903
36970
  templateUsageCheckCache.set(content, code);
36904
36971
  return code;
36905
36972
  }
36906
- function processExp(exp) {
36907
- if (/ as \w|<.*>/.test(exp)) {
36973
+ const forAliasRE$1 = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
36974
+ function processExp(exp, dir) {
36975
+ if (/ as\s+\w|<.*>|:/.test(exp)) {
36976
+ if (dir === 'slot') {
36977
+ exp = `(${exp})=>{}`;
36978
+ }
36979
+ else if (dir === 'for') {
36980
+ const inMatch = exp.match(forAliasRE$1);
36981
+ if (inMatch) {
36982
+ const [, LHS, RHS] = inMatch;
36983
+ return processExp(`(${LHS})=>{}`) + processExp(RHS);
36984
+ }
36985
+ }
36908
36986
  let ret = '';
36909
36987
  // has potential type cast or generic arguments that uses types
36910
36988
  const ast = parseExpression_1(exp, { plugins: ['typescript'] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/compiler-sfc",
3
- "version": "3.2.34",
3
+ "version": "3.2.37",
4
4
  "description": "@vue/compiler-sfc",
5
5
  "main": "dist/compiler-sfc.cjs.js",
6
6
  "module": "dist/compiler-sfc.esm-browser.js",
@@ -33,11 +33,11 @@
33
33
  "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
34
34
  "dependencies": {
35
35
  "@babel/parser": "^7.16.4",
36
- "@vue/compiler-core": "3.2.34",
37
- "@vue/compiler-dom": "3.2.34",
38
- "@vue/compiler-ssr": "3.2.34",
39
- "@vue/reactivity-transform": "3.2.34",
40
- "@vue/shared": "3.2.34",
36
+ "@vue/compiler-core": "3.2.37",
37
+ "@vue/compiler-dom": "3.2.37",
38
+ "@vue/compiler-ssr": "3.2.37",
39
+ "@vue/reactivity-transform": "3.2.37",
40
+ "@vue/shared": "3.2.37",
41
41
  "estree-walker": "^2.0.2",
42
42
  "magic-string": "^0.25.7",
43
43
  "source-map": "^0.6.1",