@vue/compiler-sfc 3.2.25 → 3.2.29
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/compiler-sfc.cjs.js +24 -12
- package/dist/compiler-sfc.d.ts +1 -1
- package/dist/compiler-sfc.esm-browser.js +106 -69
- package/package.json +9 -9
package/dist/compiler-sfc.cjs.js
CHANGED
|
@@ -109,7 +109,8 @@ function sum (o) {
|
|
|
109
109
|
var hashSum = sum;
|
|
110
110
|
|
|
111
111
|
const CSS_VARS_HELPER = `useCssVars`;
|
|
112
|
-
|
|
112
|
+
// match v-bind() with max 2-levels of nested parens.
|
|
113
|
+
const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
|
|
113
114
|
function genCssVarsFromList(vars, id, isProd) {
|
|
114
115
|
return `{\n ${vars
|
|
115
116
|
.map(key => `"${genVarName(id, key, isProd)}": (${key})`)
|
|
@@ -123,6 +124,14 @@ function genVarName(id, raw, isProd) {
|
|
|
123
124
|
return `${id}-${raw.replace(/([^\w-])/g, '_')}`;
|
|
124
125
|
}
|
|
125
126
|
}
|
|
127
|
+
function noramlizeExpression(exp) {
|
|
128
|
+
exp = exp.trim();
|
|
129
|
+
if ((exp[0] === `'` && exp[exp.length - 1] === `'`) ||
|
|
130
|
+
(exp[0] === `"` && exp[exp.length - 1] === `"`)) {
|
|
131
|
+
return exp.slice(1, -1);
|
|
132
|
+
}
|
|
133
|
+
return exp;
|
|
134
|
+
}
|
|
126
135
|
function parseCssVars(sfc) {
|
|
127
136
|
const vars = [];
|
|
128
137
|
sfc.styles.forEach(style => {
|
|
@@ -130,7 +139,7 @@ function parseCssVars(sfc) {
|
|
|
130
139
|
// ignore v-bind() in comments /* ... */
|
|
131
140
|
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
|
|
132
141
|
while ((match = cssVarRE.exec(content))) {
|
|
133
|
-
const variable = match[1]
|
|
142
|
+
const variable = noramlizeExpression(match[1]);
|
|
134
143
|
if (!vars.includes(variable)) {
|
|
135
144
|
vars.push(variable);
|
|
136
145
|
}
|
|
@@ -145,8 +154,8 @@ const cssVarsPlugin = opts => {
|
|
|
145
154
|
Declaration(decl) {
|
|
146
155
|
// rewrite CSS variables
|
|
147
156
|
if (cssVarRE.test(decl.value)) {
|
|
148
|
-
decl.value = decl.value.replace(cssVarRE, (_, $1
|
|
149
|
-
return `var(--${genVarName(id, $1
|
|
157
|
+
decl.value = decl.value.replace(cssVarRE, (_, $1) => {
|
|
158
|
+
return `var(--${genVarName(id, noramlizeExpression($1), isProd)})`;
|
|
150
159
|
});
|
|
151
160
|
}
|
|
152
161
|
}
|
|
@@ -3288,7 +3297,7 @@ function compileScript(sfc, options) {
|
|
|
3288
3297
|
let { script, scriptSetup, source, filename } = sfc;
|
|
3289
3298
|
// feature flags
|
|
3290
3299
|
// TODO remove support for deprecated options when out of experimental
|
|
3291
|
-
const
|
|
3300
|
+
const enableReactivityTransform = !!options.reactivityTransform ||
|
|
3292
3301
|
!!options.refSugar ||
|
|
3293
3302
|
!!options.refTransform;
|
|
3294
3303
|
const enablePropsTransform = !!options.reactivityTransform || !!options.propsDestructureTransform;
|
|
@@ -3308,6 +3317,7 @@ function compileScript(sfc, options) {
|
|
|
3308
3317
|
scriptLang === 'tsx' ||
|
|
3309
3318
|
scriptSetupLang === 'ts' ||
|
|
3310
3319
|
scriptSetupLang === 'tsx';
|
|
3320
|
+
// resolve parser plugins
|
|
3311
3321
|
const plugins = [];
|
|
3312
3322
|
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
|
|
3313
3323
|
plugins.push('jsx');
|
|
@@ -3332,7 +3342,7 @@ function compileScript(sfc, options) {
|
|
|
3332
3342
|
sourceType: 'module'
|
|
3333
3343
|
}).program;
|
|
3334
3344
|
const bindings = analyzeScriptBindings(scriptAst.body);
|
|
3335
|
-
if (
|
|
3345
|
+
if (enableReactivityTransform && reactivityTransform.shouldTransform(content)) {
|
|
3336
3346
|
const s = new MagicString__default(source);
|
|
3337
3347
|
const startOffset = script.loc.start.offset;
|
|
3338
3348
|
const endOffset = script.loc.end.offset;
|
|
@@ -3799,10 +3809,10 @@ function compileScript(sfc, options) {
|
|
|
3799
3809
|
walkDeclaration(node, scriptBindings, userImportAlias);
|
|
3800
3810
|
}
|
|
3801
3811
|
}
|
|
3802
|
-
// apply
|
|
3803
|
-
if (
|
|
3804
|
-
const { rootRefs
|
|
3805
|
-
refBindings =
|
|
3812
|
+
// apply reactivity transform
|
|
3813
|
+
if (enableReactivityTransform && reactivityTransform.shouldTransform(script.content)) {
|
|
3814
|
+
const { rootRefs, importedHelpers } = reactivityTransform.transformAST(scriptAst, s, scriptStartOffset);
|
|
3815
|
+
refBindings = rootRefs;
|
|
3806
3816
|
for (const h of importedHelpers) {
|
|
3807
3817
|
helperImports.add(h);
|
|
3808
3818
|
}
|
|
@@ -3987,8 +3997,10 @@ function compileScript(sfc, options) {
|
|
|
3987
3997
|
}
|
|
3988
3998
|
}
|
|
3989
3999
|
}
|
|
3990
|
-
// 3. Apply
|
|
3991
|
-
if ((
|
|
4000
|
+
// 3. Apply reactivity transform
|
|
4001
|
+
if ((enableReactivityTransform &&
|
|
4002
|
+
// normal <script> had ref bindings that maybe used in <script setup>
|
|
4003
|
+
(refBindings || reactivityTransform.shouldTransform(scriptSetup.content))) ||
|
|
3992
4004
|
propsDestructureDecl) {
|
|
3993
4005
|
const { rootRefs, importedHelpers } = reactivityTransform.transformAST(scriptSetupAst, s, startOffset, refBindings, propsDestructuredBindings);
|
|
3994
4006
|
refBindings = refBindings ? [...refBindings, ...rootRefs] : rootRefs;
|
package/dist/compiler-sfc.d.ts
CHANGED
|
@@ -302,8 +302,20 @@ const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,col
|
|
|
302
302
|
'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
|
|
303
303
|
'text,textPath,title,tspan,unknown,use,view';
|
|
304
304
|
const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
|
|
305
|
+
/**
|
|
306
|
+
* Compiler only.
|
|
307
|
+
* Do NOT use in runtime code paths unless behind `true` flag.
|
|
308
|
+
*/
|
|
305
309
|
const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
|
|
310
|
+
/**
|
|
311
|
+
* Compiler only.
|
|
312
|
+
* Do NOT use in runtime code paths unless behind `true` flag.
|
|
313
|
+
*/
|
|
306
314
|
const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
|
|
315
|
+
/**
|
|
316
|
+
* Compiler only.
|
|
317
|
+
* Do NOT use in runtime code paths unless behind `true` flag.
|
|
318
|
+
*/
|
|
307
319
|
const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
|
|
308
320
|
|
|
309
321
|
const escapeRE = /["'&<>]/;
|
|
@@ -16849,7 +16861,7 @@ function parseAttributes(context, type) {
|
|
|
16849
16861
|
}
|
|
16850
16862
|
const attr = parseAttribute(context, attributeNames);
|
|
16851
16863
|
// Trim whitespace between class
|
|
16852
|
-
// https://github.com/vuejs/
|
|
16864
|
+
// https://github.com/vuejs/core/issues/4251
|
|
16853
16865
|
if (attr.type === 6 /* ATTRIBUTE */ &&
|
|
16854
16866
|
attr.value &&
|
|
16855
16867
|
attr.name === 'class') {
|
|
@@ -17074,7 +17086,7 @@ function parseTextData(context, length, mode) {
|
|
|
17074
17086
|
advanceBy(context, length);
|
|
17075
17087
|
if (mode === 2 /* RAWTEXT */ ||
|
|
17076
17088
|
mode === 3 /* CDATA */ ||
|
|
17077
|
-
rawText.
|
|
17089
|
+
!rawText.includes('&')) {
|
|
17078
17090
|
return rawText;
|
|
17079
17091
|
}
|
|
17080
17092
|
else {
|
|
@@ -22201,7 +22213,7 @@ function isReferenced(node, parent, grandparent) {
|
|
|
22201
22213
|
// no: NODE.target
|
|
22202
22214
|
case 'MetaProperty':
|
|
22203
22215
|
return false;
|
|
22204
|
-
// yes: type X = {
|
|
22216
|
+
// yes: type X = { someProperty: NODE }
|
|
22205
22217
|
// no: type X = { NODE: OtherType }
|
|
22206
22218
|
case 'ObjectTypeProperty':
|
|
22207
22219
|
return parent.key !== node;
|
|
@@ -22708,6 +22720,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
22708
22720
|
const renderExp = createCallExpression(helper(RENDER_LIST), [
|
|
22709
22721
|
forNode.source
|
|
22710
22722
|
]);
|
|
22723
|
+
const isTemplate = isTemplateNode(node);
|
|
22711
22724
|
const memo = findDir(node, 'memo');
|
|
22712
22725
|
const keyProp = findProp(node, `key`);
|
|
22713
22726
|
const keyExp = keyProp &&
|
|
@@ -22715,15 +22728,17 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
22715
22728
|
? createSimpleExpression(keyProp.value.content, true)
|
|
22716
22729
|
: keyProp.exp);
|
|
22717
22730
|
const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
|
|
22718
|
-
if (
|
|
22719
|
-
|
|
22720
|
-
|
|
22721
|
-
//
|
|
22722
|
-
//
|
|
22723
|
-
|
|
22724
|
-
|
|
22725
|
-
|
|
22726
|
-
keyProperty
|
|
22731
|
+
if (isTemplate) {
|
|
22732
|
+
// #2085 / #5288 process :key and v-memo expressions need to be
|
|
22733
|
+
// processed on `<template v-for>`. In this case the node is discarded
|
|
22734
|
+
// and never traversed so its binding expressions won't be processed
|
|
22735
|
+
// by the normal transforms.
|
|
22736
|
+
if (memo) {
|
|
22737
|
+
memo.exp = processExpression(memo.exp, context);
|
|
22738
|
+
}
|
|
22739
|
+
if (keyProperty && keyProp.type !== 6 /* ATTRIBUTE */) {
|
|
22740
|
+
keyProperty.value = processExpression(keyProperty.value, context);
|
|
22741
|
+
}
|
|
22727
22742
|
}
|
|
22728
22743
|
const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
22729
22744
|
forNode.source.constType > 0 /* NOT_CONSTANT */;
|
|
@@ -22737,7 +22752,6 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
22737
22752
|
return () => {
|
|
22738
22753
|
// finish the codegen now that all children have been traversed
|
|
22739
22754
|
let childBlock;
|
|
22740
|
-
const isTemplate = isTemplateNode(node);
|
|
22741
22755
|
const { children } = forNode;
|
|
22742
22756
|
// check <template v-for> key placement
|
|
22743
22757
|
if (isTemplate) {
|
|
@@ -27648,7 +27662,8 @@ function sum (o) {
|
|
|
27648
27662
|
var hashSum = sum;
|
|
27649
27663
|
|
|
27650
27664
|
const CSS_VARS_HELPER = `useCssVars`;
|
|
27651
|
-
|
|
27665
|
+
// match v-bind() with max 2-levels of nested parens.
|
|
27666
|
+
const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
|
|
27652
27667
|
function genCssVarsFromList(vars, id, isProd) {
|
|
27653
27668
|
return `{\n ${vars
|
|
27654
27669
|
.map(key => `"${genVarName(id, key, isProd)}": (${key})`)
|
|
@@ -27662,6 +27677,14 @@ function genVarName(id, raw, isProd) {
|
|
|
27662
27677
|
return `${id}-${raw.replace(/([^\w-])/g, '_')}`;
|
|
27663
27678
|
}
|
|
27664
27679
|
}
|
|
27680
|
+
function noramlizeExpression(exp) {
|
|
27681
|
+
exp = exp.trim();
|
|
27682
|
+
if ((exp[0] === `'` && exp[exp.length - 1] === `'`) ||
|
|
27683
|
+
(exp[0] === `"` && exp[exp.length - 1] === `"`)) {
|
|
27684
|
+
return exp.slice(1, -1);
|
|
27685
|
+
}
|
|
27686
|
+
return exp;
|
|
27687
|
+
}
|
|
27665
27688
|
function parseCssVars(sfc) {
|
|
27666
27689
|
const vars = [];
|
|
27667
27690
|
sfc.styles.forEach(style => {
|
|
@@ -27669,7 +27692,7 @@ function parseCssVars(sfc) {
|
|
|
27669
27692
|
// ignore v-bind() in comments /* ... */
|
|
27670
27693
|
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
|
|
27671
27694
|
while ((match = cssVarRE.exec(content))) {
|
|
27672
|
-
const variable = match[1]
|
|
27695
|
+
const variable = noramlizeExpression(match[1]);
|
|
27673
27696
|
if (!vars.includes(variable)) {
|
|
27674
27697
|
vars.push(variable);
|
|
27675
27698
|
}
|
|
@@ -27684,8 +27707,8 @@ const cssVarsPlugin = opts => {
|
|
|
27684
27707
|
Declaration(decl) {
|
|
27685
27708
|
// rewrite CSS variables
|
|
27686
27709
|
if (cssVarRE.test(decl.value)) {
|
|
27687
|
-
decl.value = decl.value.replace(cssVarRE, (_, $1
|
|
27688
|
-
return `var(--${genVarName(id, $1
|
|
27710
|
+
decl.value = decl.value.replace(cssVarRE, (_, $1) => {
|
|
27711
|
+
return `var(--${genVarName(id, noramlizeExpression($1), isProd)})`;
|
|
27689
27712
|
});
|
|
27690
27713
|
}
|
|
27691
27714
|
}
|
|
@@ -33404,17 +33427,16 @@ function createSSRCompilerError(code, loc) {
|
|
|
33404
33427
|
return createCompilerError(code, loc, SSRErrorMessages);
|
|
33405
33428
|
}
|
|
33406
33429
|
const SSRErrorMessages = {
|
|
33407
|
-
[61 /*
|
|
33408
|
-
[62 /*
|
|
33409
|
-
[63 /*
|
|
33410
|
-
[64 /* X_SSR_INVALID_AST_NODE */]: `Invalid AST node during SSR transform.`
|
|
33430
|
+
[61 /* X_SSR_UNSAFE_ATTR_NAME */]: `Unsafe attribute name for SSR.`,
|
|
33431
|
+
[62 /* X_SSR_NO_TELEPORT_TARGET */]: `Missing the 'to' prop on teleport element.`,
|
|
33432
|
+
[63 /* X_SSR_INVALID_AST_NODE */]: `Invalid AST node during SSR transform.`
|
|
33411
33433
|
};
|
|
33412
33434
|
|
|
33413
33435
|
// Note: this is a 2nd-pass codegen transform.
|
|
33414
33436
|
function ssrProcessTeleport(node, context) {
|
|
33415
33437
|
const targetProp = findProp(node, 'to');
|
|
33416
33438
|
if (!targetProp) {
|
|
33417
|
-
context.onError(createSSRCompilerError(
|
|
33439
|
+
context.onError(createSSRCompilerError(62 /* X_SSR_NO_TELEPORT_TARGET */, node.loc));
|
|
33418
33440
|
return;
|
|
33419
33441
|
}
|
|
33420
33442
|
let target;
|
|
@@ -33426,7 +33448,7 @@ function ssrProcessTeleport(node, context) {
|
|
|
33426
33448
|
target = targetProp.exp;
|
|
33427
33449
|
}
|
|
33428
33450
|
if (!target) {
|
|
33429
|
-
context.onError(createSSRCompilerError(
|
|
33451
|
+
context.onError(createSSRCompilerError(62 /* X_SSR_NO_TELEPORT_TARGET */, targetProp.loc));
|
|
33430
33452
|
return;
|
|
33431
33453
|
}
|
|
33432
33454
|
const disabledProp = findProp(node, 'disabled', false, true /* allow empty */);
|
|
@@ -33527,7 +33549,7 @@ function ssrProcessTransitionGroup(node, context) {
|
|
|
33527
33549
|
|
|
33528
33550
|
// We need to construct the slot functions in the 1st pass to ensure proper
|
|
33529
33551
|
// scope tracking, but the children of each slot cannot be processed until
|
|
33530
|
-
// the 2nd pass, so we store the WIP slot functions in a
|
|
33552
|
+
// the 2nd pass, so we store the WIP slot functions in a weakMap during the 1st
|
|
33531
33553
|
// pass and complete them in the 2nd pass.
|
|
33532
33554
|
const wipMap$1 = new WeakMap();
|
|
33533
33555
|
const componentTypeMap = new WeakMap();
|
|
@@ -33840,14 +33862,10 @@ const ssrTransformElement = (node, context) => {
|
|
|
33840
33862
|
node.children = [createInterpolation(prop.exp, prop.loc)];
|
|
33841
33863
|
}
|
|
33842
33864
|
}
|
|
33843
|
-
else {
|
|
33865
|
+
else if (!hasDynamicVBind) {
|
|
33844
33866
|
// Directive transforms.
|
|
33845
33867
|
const directiveTransform = context.directiveTransforms[prop.name];
|
|
33846
|
-
if (
|
|
33847
|
-
// no corresponding ssr directive transform found.
|
|
33848
|
-
context.onError(createSSRCompilerError(61 /* X_SSR_CUSTOM_DIRECTIVE_NO_TRANSFORM */, prop.loc));
|
|
33849
|
-
}
|
|
33850
|
-
else if (!hasDynamicVBind) {
|
|
33868
|
+
if (directiveTransform) {
|
|
33851
33869
|
const { props, ssrTagParts } = directiveTransform(prop, node, context);
|
|
33852
33870
|
if (ssrTagParts) {
|
|
33853
33871
|
openTag.push(...ssrTagParts);
|
|
@@ -33887,7 +33905,7 @@ const ssrTransformElement = (node, context) => {
|
|
|
33887
33905
|
]));
|
|
33888
33906
|
}
|
|
33889
33907
|
else {
|
|
33890
|
-
context.onError(createSSRCompilerError(
|
|
33908
|
+
context.onError(createSSRCompilerError(61 /* X_SSR_UNSAFE_ATTR_NAME */, key.loc));
|
|
33891
33909
|
}
|
|
33892
33910
|
}
|
|
33893
33911
|
}
|
|
@@ -34082,7 +34100,7 @@ function processChildren(children, context, asFragment = false, disableNestedFra
|
|
|
34082
34100
|
// TODO
|
|
34083
34101
|
break;
|
|
34084
34102
|
default:
|
|
34085
|
-
context.onError(createSSRCompilerError(
|
|
34103
|
+
context.onError(createSSRCompilerError(63 /* X_SSR_INVALID_AST_NODE */, child.loc));
|
|
34086
34104
|
// make sure we exhaust all possible types
|
|
34087
34105
|
const exhaustiveCheck = child;
|
|
34088
34106
|
return exhaustiveCheck;
|
|
@@ -34114,7 +34132,7 @@ function processChildren(children, context, asFragment = false, disableNestedFra
|
|
|
34114
34132
|
// `transformText` is not used during SSR compile.
|
|
34115
34133
|
break;
|
|
34116
34134
|
default:
|
|
34117
|
-
context.onError(createSSRCompilerError(
|
|
34135
|
+
context.onError(createSSRCompilerError(63 /* X_SSR_INVALID_AST_NODE */, child.loc));
|
|
34118
34136
|
// make sure we exhaust all possible types
|
|
34119
34137
|
const exhaustiveCheck = child;
|
|
34120
34138
|
return exhaustiveCheck;
|
|
@@ -34757,33 +34775,7 @@ function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
|
|
|
34757
34775
|
function walkScope(node, isRoot = false) {
|
|
34758
34776
|
for (const stmt of node.body) {
|
|
34759
34777
|
if (stmt.type === 'VariableDeclaration') {
|
|
34760
|
-
|
|
34761
|
-
continue;
|
|
34762
|
-
for (const decl of stmt.declarations) {
|
|
34763
|
-
let refCall;
|
|
34764
|
-
const isCall = decl.init &&
|
|
34765
|
-
decl.init.type === 'CallExpression' &&
|
|
34766
|
-
decl.init.callee.type === 'Identifier';
|
|
34767
|
-
if (isCall &&
|
|
34768
|
-
(refCall = isRefCreationCall(decl.init.callee.name))) {
|
|
34769
|
-
processRefDeclaration(refCall, decl.id, decl.init);
|
|
34770
|
-
}
|
|
34771
|
-
else {
|
|
34772
|
-
const isProps = isRoot &&
|
|
34773
|
-
isCall &&
|
|
34774
|
-
decl.init.callee.name === 'defineProps';
|
|
34775
|
-
for (const id of extractIdentifiers(decl.id)) {
|
|
34776
|
-
if (isProps) {
|
|
34777
|
-
// for defineProps destructure, only exclude them since they
|
|
34778
|
-
// are already passed in as knownProps
|
|
34779
|
-
excludedIds.add(id);
|
|
34780
|
-
}
|
|
34781
|
-
else {
|
|
34782
|
-
registerBinding(id);
|
|
34783
|
-
}
|
|
34784
|
-
}
|
|
34785
|
-
}
|
|
34786
|
-
}
|
|
34778
|
+
walkVariableDeclaration(stmt, isRoot);
|
|
34787
34779
|
}
|
|
34788
34780
|
else if (stmt.type === 'FunctionDeclaration' ||
|
|
34789
34781
|
stmt.type === 'ClassDeclaration') {
|
|
@@ -34791,6 +34783,47 @@ function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
|
|
|
34791
34783
|
continue;
|
|
34792
34784
|
registerBinding(stmt.id);
|
|
34793
34785
|
}
|
|
34786
|
+
else if ((stmt.type === 'ForOfStatement' || stmt.type === 'ForInStatement') &&
|
|
34787
|
+
stmt.left.type === 'VariableDeclaration') {
|
|
34788
|
+
walkVariableDeclaration(stmt.left);
|
|
34789
|
+
}
|
|
34790
|
+
else if (stmt.type === 'ExportNamedDeclaration' &&
|
|
34791
|
+
stmt.declaration &&
|
|
34792
|
+
stmt.declaration.type === 'VariableDeclaration') {
|
|
34793
|
+
walkVariableDeclaration(stmt.declaration, isRoot);
|
|
34794
|
+
}
|
|
34795
|
+
else if (stmt.type === 'LabeledStatement' &&
|
|
34796
|
+
stmt.body.type === 'VariableDeclaration') {
|
|
34797
|
+
walkVariableDeclaration(stmt.body, isRoot);
|
|
34798
|
+
}
|
|
34799
|
+
}
|
|
34800
|
+
}
|
|
34801
|
+
function walkVariableDeclaration(stmt, isRoot = false) {
|
|
34802
|
+
if (stmt.declare) {
|
|
34803
|
+
return;
|
|
34804
|
+
}
|
|
34805
|
+
for (const decl of stmt.declarations) {
|
|
34806
|
+
let refCall;
|
|
34807
|
+
const isCall = decl.init &&
|
|
34808
|
+
decl.init.type === 'CallExpression' &&
|
|
34809
|
+
decl.init.callee.type === 'Identifier';
|
|
34810
|
+
if (isCall &&
|
|
34811
|
+
(refCall = isRefCreationCall(decl.init.callee.name))) {
|
|
34812
|
+
processRefDeclaration(refCall, decl.id, decl.init);
|
|
34813
|
+
}
|
|
34814
|
+
else {
|
|
34815
|
+
const isProps = isRoot && isCall && decl.init.callee.name === 'defineProps';
|
|
34816
|
+
for (const id of extractIdentifiers(decl.id)) {
|
|
34817
|
+
if (isProps) {
|
|
34818
|
+
// for defineProps destructure, only exclude them since they
|
|
34819
|
+
// are already passed in as knownProps
|
|
34820
|
+
excludedIds.add(id);
|
|
34821
|
+
}
|
|
34822
|
+
else {
|
|
34823
|
+
registerBinding(id);
|
|
34824
|
+
}
|
|
34825
|
+
}
|
|
34826
|
+
}
|
|
34794
34827
|
}
|
|
34795
34828
|
}
|
|
34796
34829
|
function processRefDeclaration(method, id, call) {
|
|
@@ -35041,6 +35074,7 @@ function transformAST(ast, s, offset = 0, knownRefs, knownProps) {
|
|
|
35041
35074
|
walkScope(node);
|
|
35042
35075
|
return;
|
|
35043
35076
|
}
|
|
35077
|
+
// skip type nodes
|
|
35044
35078
|
if (parent &&
|
|
35045
35079
|
parent.type.startsWith('TS') &&
|
|
35046
35080
|
parent.type !== 'TSAsExpression' &&
|
|
@@ -35120,7 +35154,7 @@ function warnOnce$1(msg) {
|
|
|
35120
35154
|
}
|
|
35121
35155
|
}
|
|
35122
35156
|
function warn$1(msg) {
|
|
35123
|
-
console.warn(`\x1b[1m\x1b[33m[@vue/
|
|
35157
|
+
console.warn(`\x1b[1m\x1b[33m[@vue/reactivity-transform]\x1b[0m\x1b[33m ${msg}\x1b[0m\n`);
|
|
35124
35158
|
}
|
|
35125
35159
|
|
|
35126
35160
|
// Special compiler macros
|
|
@@ -35140,7 +35174,7 @@ function compileScript(sfc, options) {
|
|
|
35140
35174
|
let { script, scriptSetup, source, filename } = sfc;
|
|
35141
35175
|
// feature flags
|
|
35142
35176
|
// TODO remove support for deprecated options when out of experimental
|
|
35143
|
-
const
|
|
35177
|
+
const enableReactivityTransform = !!options.reactivityTransform ||
|
|
35144
35178
|
!!options.refSugar ||
|
|
35145
35179
|
!!options.refTransform;
|
|
35146
35180
|
const enablePropsTransform = !!options.reactivityTransform || !!options.propsDestructureTransform;
|
|
@@ -35160,6 +35194,7 @@ function compileScript(sfc, options) {
|
|
|
35160
35194
|
scriptLang === 'tsx' ||
|
|
35161
35195
|
scriptSetupLang === 'ts' ||
|
|
35162
35196
|
scriptSetupLang === 'tsx';
|
|
35197
|
+
// resolve parser plugins
|
|
35163
35198
|
const plugins = [];
|
|
35164
35199
|
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
|
|
35165
35200
|
plugins.push('jsx');
|
|
@@ -35184,7 +35219,7 @@ function compileScript(sfc, options) {
|
|
|
35184
35219
|
sourceType: 'module'
|
|
35185
35220
|
}).program;
|
|
35186
35221
|
const bindings = analyzeScriptBindings(scriptAst.body);
|
|
35187
|
-
if (
|
|
35222
|
+
if (enableReactivityTransform && shouldTransform(content)) {
|
|
35188
35223
|
const s = new MagicString(source);
|
|
35189
35224
|
const startOffset = script.loc.start.offset;
|
|
35190
35225
|
const endOffset = script.loc.end.offset;
|
|
@@ -35651,10 +35686,10 @@ function compileScript(sfc, options) {
|
|
|
35651
35686
|
walkDeclaration(node, scriptBindings, userImportAlias);
|
|
35652
35687
|
}
|
|
35653
35688
|
}
|
|
35654
|
-
// apply
|
|
35655
|
-
if (
|
|
35656
|
-
const { rootRefs
|
|
35657
|
-
refBindings =
|
|
35689
|
+
// apply reactivity transform
|
|
35690
|
+
if (enableReactivityTransform && shouldTransform(script.content)) {
|
|
35691
|
+
const { rootRefs, importedHelpers } = transformAST(scriptAst, s, scriptStartOffset);
|
|
35692
|
+
refBindings = rootRefs;
|
|
35658
35693
|
for (const h of importedHelpers) {
|
|
35659
35694
|
helperImports.add(h);
|
|
35660
35695
|
}
|
|
@@ -35839,8 +35874,10 @@ function compileScript(sfc, options) {
|
|
|
35839
35874
|
}
|
|
35840
35875
|
}
|
|
35841
35876
|
}
|
|
35842
|
-
// 3. Apply
|
|
35843
|
-
if ((
|
|
35877
|
+
// 3. Apply reactivity transform
|
|
35878
|
+
if ((enableReactivityTransform &&
|
|
35879
|
+
// normal <script> had ref bindings that maybe used in <script setup>
|
|
35880
|
+
(refBindings || shouldTransform(scriptSetup.content))) ||
|
|
35844
35881
|
propsDestructureDecl) {
|
|
35845
35882
|
const { rootRefs, importedHelpers } = transformAST(scriptSetupAst, s, startOffset, refBindings, propsDestructuredBindings);
|
|
35846
35883
|
refBindings = refBindings ? [...refBindings, ...rootRefs] : rootRefs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/compiler-sfc",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.29",
|
|
4
4
|
"description": "@vue/compiler-sfc",
|
|
5
5
|
"main": "dist/compiler-sfc.cjs.js",
|
|
6
6
|
"module": "dist/compiler-sfc.esm-browser.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/vuejs/
|
|
22
|
+
"url": "git+https://github.com/vuejs/core.git",
|
|
23
23
|
"directory": "packages/compiler-sfc"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"author": "Evan You",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"bugs": {
|
|
31
|
-
"url": "https://github.com/vuejs/
|
|
31
|
+
"url": "https://github.com/vuejs/core/issues"
|
|
32
32
|
},
|
|
33
|
-
"homepage": "https://github.com/vuejs/
|
|
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.
|
|
37
|
-
"@vue/compiler-dom": "3.2.
|
|
38
|
-
"@vue/compiler-ssr": "3.2.
|
|
39
|
-
"@vue/reactivity-transform": "3.2.
|
|
40
|
-
"@vue/shared": "3.2.
|
|
36
|
+
"@vue/compiler-core": "3.2.29",
|
|
37
|
+
"@vue/compiler-dom": "3.2.29",
|
|
38
|
+
"@vue/compiler-ssr": "3.2.29",
|
|
39
|
+
"@vue/reactivity-transform": "3.2.29",
|
|
40
|
+
"@vue/shared": "3.2.29",
|
|
41
41
|
"estree-walker": "^2.0.2",
|
|
42
42
|
"magic-string": "^0.25.7",
|
|
43
43
|
"source-map": "^0.6.1",
|