@vue/reactivity-transform
Advanced tools
Comparing version 3.2.41 to 3.2.42
@@ -17,2 +17,3 @@ 'use strict'; | ||
const ESCAPE_SYMBOL = '$$'; | ||
const IMPORT_SOURCE = 'vue/macros'; | ||
const shorthands = ['ref', 'computed', 'shallowRef', 'toRef', 'customRef']; | ||
@@ -60,30 +61,31 @@ const transformCheckRE = /[^\w]\$(?:\$|ref|computed|shallowRef)?\s*(\(|\<)/; | ||
warnExperimental(); | ||
let convertSymbol = CONVERT_SYMBOL; | ||
let escapeSymbol = ESCAPE_SYMBOL; | ||
const userImports = Object.create(null); | ||
for (const node of ast.body) { | ||
if (node.type !== 'ImportDeclaration') | ||
continue; | ||
walkImportDeclaration(node); | ||
} | ||
// macro import handling | ||
for (const node of ast.body) { | ||
if (node.type === 'ImportDeclaration' && | ||
node.source.value === 'vue/macros') { | ||
// remove macro imports | ||
s.remove(node.start + offset, node.end + offset); | ||
// check aliasing | ||
for (const specifier of node.specifiers) { | ||
if (specifier.type === 'ImportSpecifier') { | ||
const imported = specifier.imported.name; | ||
const local = specifier.local.name; | ||
if (local !== imported) { | ||
if (imported === ESCAPE_SYMBOL) { | ||
escapeSymbol = local; | ||
} | ||
else if (imported === CONVERT_SYMBOL) { | ||
convertSymbol = local; | ||
} | ||
else { | ||
error(`macro imports for ref-creating methods do not support aliasing.`, specifier); | ||
} | ||
} | ||
} | ||
let convertSymbol; | ||
let escapeSymbol; | ||
for (const { local, imported, source, specifier } of Object.values(userImports)) { | ||
if (source === IMPORT_SOURCE) { | ||
if (imported === ESCAPE_SYMBOL) { | ||
escapeSymbol = local; | ||
} | ||
else if (imported === CONVERT_SYMBOL) { | ||
convertSymbol = local; | ||
} | ||
else if (imported !== local) { | ||
error(`macro imports for ref-creating methods do not support aliasing.`, specifier); | ||
} | ||
} | ||
} | ||
// default symbol | ||
if (!convertSymbol && !userImports[CONVERT_SYMBOL]) { | ||
convertSymbol = CONVERT_SYMBOL; | ||
} | ||
if (!escapeSymbol && !userImports[ESCAPE_SYMBOL]) { | ||
escapeSymbol = ESCAPE_SYMBOL; | ||
} | ||
const importedHelpers = new Set(); | ||
@@ -109,3 +111,25 @@ const rootScope = {}; | ||
} | ||
function walkImportDeclaration(node) { | ||
const source = node.source.value; | ||
if (source === IMPORT_SOURCE) { | ||
s.remove(node.start + offset, node.end + offset); | ||
} | ||
for (const specifier of node.specifiers) { | ||
const local = specifier.local.name; | ||
const imported = (specifier.type === 'ImportSpecifier' && | ||
specifier.imported.type === 'Identifier' && | ||
specifier.imported.name) || | ||
'default'; | ||
userImports[local] = { | ||
source, | ||
local, | ||
imported, | ||
specifier | ||
}; | ||
} | ||
} | ||
function isRefCreationCall(callee) { | ||
if (!convertSymbol || currentScope[convertSymbol] !== undefined) { | ||
return false; | ||
} | ||
if (callee === convertSymbol) { | ||
@@ -234,4 +258,4 @@ return convertSymbol; | ||
} | ||
let nameId; | ||
for (const p of pattern.properties) { | ||
let nameId; | ||
let key; | ||
@@ -305,2 +329,5 @@ let defaultValue; | ||
} | ||
if (nameId) { | ||
s.appendLeft(call.end + offset, ';'); | ||
} | ||
} | ||
@@ -313,2 +340,3 @@ function processRefArrayPattern(pattern, call, tempVar, path = []) { | ||
} | ||
let nameId; | ||
for (let i = 0; i < pattern.elements.length; i++) { | ||
@@ -318,3 +346,2 @@ const e = pattern.elements[i]; | ||
continue; | ||
let nameId; | ||
let defaultValue; | ||
@@ -348,2 +375,5 @@ if (e.type === 'Identifier') { | ||
} | ||
if (nameId) { | ||
s.appendLeft(call.end + offset, ';'); | ||
} | ||
} | ||
@@ -429,3 +459,3 @@ function pathToString(source, path) { | ||
const publicKey = propsLocalToPublicMap[id.name]; | ||
s.prependRight(offset, `const __props_${publicKey} = ${helper(`toRef`)}(__props, '${publicKey}')\n`); | ||
s.prependRight(offset, `const __props_${publicKey} = ${helper(`toRef`)}(__props, '${publicKey}');\n`); | ||
} | ||
@@ -490,3 +520,5 @@ } | ||
} | ||
if (callee === escapeSymbol) { | ||
if (escapeSymbol && | ||
currentScope[escapeSymbol] === undefined && | ||
callee === escapeSymbol) { | ||
s.remove(node.callee.start + offset, node.callee.end + offset); | ||
@@ -493,0 +525,0 @@ escapeScope = node; |
@@ -0,1 +1,4 @@ | ||
import { ImportDefaultSpecifier } from '@babel/types'; | ||
import { ImportNamespaceSpecifier } from '@babel/types'; | ||
import { ImportSpecifier } from '@babel/types'; | ||
import MagicString from 'magic-string'; | ||
@@ -6,2 +9,9 @@ import { ParserPlugin } from '@babel/parser'; | ||
export declare interface ImportBinding { | ||
local: string; | ||
imported: string; | ||
source: string; | ||
specifier: ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier; | ||
} | ||
export declare interface RefTransformOptions { | ||
@@ -8,0 +18,0 @@ filename?: string; |
{ | ||
"name": "@vue/reactivity-transform", | ||
"version": "3.2.41", | ||
"version": "3.2.42", | ||
"description": "@vue/reactivity-transform", | ||
@@ -32,4 +32,4 @@ "main": "dist/reactivity-transform.cjs.js", | ||
"@babel/parser": "^7.16.4", | ||
"@vue/compiler-core": "3.2.41", | ||
"@vue/shared": "3.2.41", | ||
"@vue/compiler-core": "3.2.42", | ||
"@vue/shared": "3.2.42", | ||
"estree-walker": "^2.0.2", | ||
@@ -36,0 +36,0 @@ "magic-string": "^0.25.7" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28671
600
+ Added@vue/compiler-core@3.2.42(transitive)
+ Added@vue/shared@3.2.42(transitive)
- Removed@vue/compiler-core@3.2.41(transitive)
- Removed@vue/shared@3.2.41(transitive)
Updated@vue/compiler-core@3.2.42
Updated@vue/shared@3.2.42