Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vue/ref-transform

Package Overview
Dependencies
Maintainers
19
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue/ref-transform - npm Package Compare versions

Comparing version 3.2.19 to 3.2.20

72

dist/ref-transform.cjs.js

@@ -34,3 +34,3 @@ 'use strict';

sourceType: 'module',
plugins: [...new Set([...shared.babelParserDefaultPlugins, ...plugins])]
plugins
});

@@ -53,5 +53,7 @@ const s = new MagicString__default(src);

}
function transformAST(ast, s, offset = 0, knownRootVars) {
function transformAST(ast, s, offset = 0, knownRefs, knownProps, rewritePropsOnly = false) {
// TODO remove when out of experimental
warnExperimental();
if (!rewritePropsOnly) {
warnExperimental();
}
const importedHelpers = new Set();

@@ -63,8 +65,18 @@ const rootScope = {};

const parentStack = [];
if (knownRootVars) {
for (const key of knownRootVars) {
const propsLocalToPublicMap = Object.create(null);
if (knownRefs) {
for (const key of knownRefs) {
rootScope[key] = true;
}
}
if (knownProps) {
for (const key in knownProps) {
const { local } = knownProps[key];
rootScope[local] = 'prop';
propsLocalToPublicMap[local] = key;
}
}
function error(msg, node) {
if (rewritePropsOnly)
return;
const e = new Error(msg);

@@ -88,3 +100,3 @@ e.node = node;

const registerRefBinding = (id) => registerBinding(id, true);
function walkScope(node) {
function walkScope(node, isRoot = false) {
for (const stmt of node.body) {

@@ -96,5 +108,6 @@ if (stmt.type === 'VariableDeclaration') {

let toVarCall;
if (decl.init &&
const isCall = decl.init &&
decl.init.type === 'CallExpression' &&
decl.init.callee.type === 'Identifier' &&
decl.init.callee.type === 'Identifier';
if (isCall &&
(toVarCall = isToVarCall(decl.init.callee.name))) {

@@ -104,4 +117,14 @@ processRefDeclaration(toVarCall, decl.init, decl.id, stmt);

else {
const isProps = isRoot &&
isCall &&
decl.init.callee.name === 'defineProps';
for (const id of compilerCore.extractIdentifiers(decl.id)) {
registerBinding(id);
if (isProps) {
// for defineProps destructure, only exclude them since they
// are already passed in as knownProps
excludedIds.add(id);
}
else {
registerBinding(id);
}
}

@@ -232,16 +255,33 @@ }

}
function checkRefId(scope, id, parent, parentStack) {
function rewriteId(scope, id, parent, parentStack) {
if (shared.hasOwn(scope, id.name)) {
if (scope[id.name]) {
const bindingType = scope[id.name];
if (bindingType) {
const isProp = bindingType === 'prop';
if (rewritePropsOnly && !isProp) {
return true;
}
// ref
if (compilerCore.isStaticProperty(parent) && parent.shorthand) {
// let binding used in a property shorthand
// { foo } -> { foo: foo.value }
// { prop } -> { prop: __prop.prop }
// skip for destructure patterns
if (!parent.inPattern ||
compilerCore.isInDestructureAssignment(parent, parentStack)) {
s.appendLeft(id.end + offset, `: ${id.name}.value`);
if (isProp) {
s.appendLeft(id.end + offset, `: __props.${propsLocalToPublicMap[id.name]}`);
}
else {
s.appendLeft(id.end + offset, `: ${id.name}.value`);
}
}
}
else {
s.appendLeft(id.end + offset, '.value');
if (isProp) {
s.overwrite(id.start + offset, id.end + offset, `__props.${propsLocalToPublicMap[id.name]}`);
}
else {
s.appendLeft(id.end + offset, '.value');
}
}

@@ -254,3 +294,3 @@ }

// check root scope first
walkScope(ast);
walkScope(ast, true);
estreeWalker.walk(ast, {

@@ -287,3 +327,3 @@ enter(node, parent) {

while (i--) {
if (checkRefId(scopeStack[i], node, parent, parentStack)) {
if (rewriteId(scopeStack[i], node, parent, parentStack)) {
return;

@@ -325,3 +365,3 @@ }

return {
rootVars: Object.keys(rootScope).filter(key => rootScope[key]),
rootRefs: Object.keys(rootScope).filter(key => rootScope[key] === true),
importedHelpers: [...importedHelpers]

@@ -328,0 +368,0 @@ };

@@ -16,3 +16,3 @@ import MagicString from 'magic-string';

map: SourceMap | null;
rootVars: string[];
rootRefs: string[];
importedHelpers: string[];

@@ -25,4 +25,8 @@ }

export declare function transformAST(ast: Program, s: MagicString, offset?: number, knownRootVars?: string[]): {
rootVars: string[];
export declare function transformAST(ast: Program, s: MagicString, offset?: number, knownRefs?: string[], knownProps?: Record<string, // public prop key
{
local: string;
default?: any;
}>, rewritePropsOnly?: boolean): {
rootRefs: string[];
importedHelpers: string[];

@@ -29,0 +33,0 @@ };

{
"name": "@vue/ref-transform",
"version": "3.2.19",
"version": "3.2.20",
"description": "@vue/ref-transform",

@@ -32,4 +32,4 @@ "main": "dist/ref-transform.cjs.js",

"@babel/parser": "^7.15.0",
"@vue/compiler-core": "3.2.19",
"@vue/shared": "3.2.19",
"@vue/compiler-core": "3.2.20",
"@vue/shared": "3.2.20",
"estree-walker": "^2.0.2",

@@ -36,0 +36,0 @@ "magic-string": "^0.25.7"

@@ -67,3 +67,5 @@ # @vue/ref-transform

// so in most cases explicit parserPlugins are not necessary
parserPlugins: [/* ... */]
parserPlugins: [
/* ... */
]
})

@@ -97,3 +99,3 @@ ```

const {
rootVars, // ['a']
rootRefs, // ['a']
importedHelpers // ['ref']

@@ -100,0 +102,0 @@ } = transformAST(ast, s)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc