@vue/compiler-sfc 2.7.0-beta.3 → 2.7.0-beta.4
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.js +19 -14
- package/package.json +1 -1
package/dist/compiler-sfc.js
CHANGED
|
@@ -3050,6 +3050,9 @@ function markScopeIdentifier(node, child, knownIds) {
|
|
|
3050
3050
|
const isFunctionType = (node) => {
|
|
3051
3051
|
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
3052
3052
|
};
|
|
3053
|
+
const isStaticProperty = (node) => node &&
|
|
3054
|
+
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3055
|
+
!node.computed;
|
|
3053
3056
|
/**
|
|
3054
3057
|
* Copied from https://github.com/babel/babel/blob/main/packages/babel-types/src/validators/isReferenced.ts
|
|
3055
3058
|
* To avoid runtime dependency on @babel/types (which includes process references)
|
|
@@ -7978,16 +7981,27 @@ function prefixIdentifiers(source, isFunctional = false, isTS = false, babelOpti
|
|
|
7978
7981
|
];
|
|
7979
7982
|
const ast = parser$1.parseExpression(source, Object.assign(Object.assign({}, babelOptions), { plugins }));
|
|
7980
7983
|
const isScriptSetup = bindings && bindings.__isScriptSetup !== false;
|
|
7981
|
-
walkIdentifiers(ast, ident => {
|
|
7984
|
+
walkIdentifiers(ast, (ident, parent) => {
|
|
7982
7985
|
const { name } = ident;
|
|
7983
7986
|
if (doNotPrefix(name)) {
|
|
7984
7987
|
return;
|
|
7985
7988
|
}
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
+
let prefix = `_vm.`;
|
|
7990
|
+
if (isScriptSetup) {
|
|
7991
|
+
const type = bindings[name];
|
|
7992
|
+
if (type && type.startsWith('setup')) {
|
|
7993
|
+
prefix = `_setup.`;
|
|
7994
|
+
}
|
|
7995
|
+
}
|
|
7996
|
+
if (isStaticProperty(parent) && parent.shorthand) {
|
|
7997
|
+
// property shorthand like { foo }, we need to add the key since
|
|
7998
|
+
// we rewrite the value
|
|
7999
|
+
// { foo } -> { foo: _vm.foo }
|
|
8000
|
+
s.appendLeft(ident.end, `: ${prefix}${name}`);
|
|
8001
|
+
}
|
|
8002
|
+
else {
|
|
8003
|
+
s.prependRight(ident.start, prefix);
|
|
7989
8004
|
}
|
|
7990
|
-
s.overwrite(ident.start, ident.end, rewriteIdentifier(name, bindings));
|
|
7991
8005
|
}, node => {
|
|
7992
8006
|
if (node.type === 'WithStatement') {
|
|
7993
8007
|
s.remove(node.start, node.body.start + 1);
|
|
@@ -7998,15 +8012,6 @@ function prefixIdentifiers(source, isFunctional = false, isTS = false, babelOpti
|
|
|
7998
8012
|
}
|
|
7999
8013
|
});
|
|
8000
8014
|
return s.toString();
|
|
8001
|
-
}
|
|
8002
|
-
function rewriteIdentifier(name, bindings) {
|
|
8003
|
-
const type = bindings[name];
|
|
8004
|
-
if (type && type.startsWith('setup')) {
|
|
8005
|
-
return `_setup.${name}`;
|
|
8006
|
-
}
|
|
8007
|
-
else {
|
|
8008
|
-
return `_vm.${name}`;
|
|
8009
|
-
}
|
|
8010
8015
|
}
|
|
8011
8016
|
|
|
8012
8017
|
const CSS_VARS_HELPER = `useCssVars`;
|