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

@vue-macros/common

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue-macros/common - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

dist/index.d.mts

287

./dist/index.js

@@ -1,14 +0,181 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
var _magicstringast = require('magic-string-ast'); _createStarExport(_magicstringast);
var _astkit = require('ast-kit'); _createStarExport(_astkit);
// src/ast.ts
var _compilersfc = require('@vue/compiler-sfc');
function checkInvalidScopeReference(node, method, setupBindings) {
if (!node)
return;
_compilersfc.walkIdentifiers.call(void 0, node, (id) => {
if (setupBindings.includes(id.name))
throw new SyntaxError(
`\`${method}()\` in <script setup> cannot reference locally declared variables (${id.name}) because it will be hoisted outside of the setup() function.`
);
});
}
function isStaticExpression(node, options = {}) {
const { magicComment, fn, object, objectMethod, array, unary, regex } = options;
if (magicComment && _optionalChain([node, 'access', _ => _.leadingComments, 'optionalAccess', _2 => _2.some, 'call', _3 => _3(
(comment) => comment.value.trim() === magicComment
)]))
return true;
else if (fn && _astkit.isFunctionType.call(void 0, node))
return true;
switch (node.type) {
case "UnaryExpression":
return !!unary && isStaticExpression(node.argument, options);
case "LogicalExpression":
case "BinaryExpression":
return isStaticExpression(node.left, options) && isStaticExpression(node.right, options);
case "ConditionalExpression":
return isStaticExpression(node.test, options) && isStaticExpression(node.consequent, options) && isStaticExpression(node.alternate, options);
case "SequenceExpression":
case "TemplateLiteral":
return node.expressions.every((expr) => isStaticExpression(expr, options));
case "ArrayExpression":
return !!array && node.elements.every(
(element) => element && isStaticExpression(element, options)
);
case "ObjectExpression":
return !!object && node.properties.every((prop) => {
if (prop.type === "SpreadElement") {
return prop.argument.type === "ObjectExpression" && isStaticExpression(prop.argument, options);
} else if (!_astkit.isLiteralType.call(void 0, prop.key) && prop.computed) {
return false;
} else if (prop.type === "ObjectProperty" && !isStaticExpression(prop.value, options)) {
return false;
}
if (prop.type === "ObjectMethod" && !objectMethod) {
return false;
}
return true;
});
case "ParenthesizedExpression":
case "TSNonNullExpression":
case "TSAsExpression":
case "TSTypeAssertion":
case "TSSatisfiesExpression":
return isStaticExpression(node.expression, options);
case "RegExpLiteral":
return !!regex;
}
if (_astkit.isLiteralType.call(void 0, node))
return true;
return false;
}
function isStaticObjectKey(node) {
return node.properties.every((prop) => {
if (prop.type === "SpreadElement") {
return prop.argument.type === "ObjectExpression" && isStaticObjectKey(prop.argument);
}
return !prop.computed || _astkit.isLiteralType.call(void 0, prop.key);
});
}
function resolveObjectExpression(node) {
const maps = {};
for (const property of node.properties) {
if (property.type === "SpreadElement") {
if (property.argument.type !== "ObjectExpression")
return void 0;
Object.assign(maps, resolveObjectExpression(property.argument));
} else {
const key = resolveObjectKey(property.key, property.computed, false);
maps[key] = property;
}
}
return maps;
}
function resolveObjectKey(node, computed = false, raw = true) {
switch (node.type) {
case "StringLiteral":
case "NumericLiteral":
return raw ? node.extra.raw : node.value;
case "Identifier":
if (!computed)
return raw ? `'${node.name}'` : node.name;
default:
throw new SyntaxError(`Unexpected node type: ${node.type}`);
}
}
var importedMap = /* @__PURE__ */ new WeakMap();
var HELPER_PREFIX = "__MACROS_";
function importHelperFn(s, offset, local, from = "vue", isDefault = false) {
const imported = isDefault ? "default" : local;
const cacheKey = `${from}@${imported}`;
if (!_optionalChain([importedMap, 'access', _4 => _4.get, 'call', _5 => _5(s), 'optionalAccess', _6 => _6.has, 'call', _7 => _7(cacheKey)])) {
s.appendLeft(
offset,
`
import ${isDefault ? HELPER_PREFIX + local : `{ ${imported} as ${HELPER_PREFIX + local} }`} from ${JSON.stringify(from)};`
);
if (!importedMap.has(s)) {
importedMap.set(s, /* @__PURE__ */ new Set([cacheKey]));
} else {
importedMap.get(s).add(cacheKey);
}
}
return `${HELPER_PREFIX}${local}`;
}
// src/constants.ts
var DEFINE_PROPS = "defineProps";
var DEFINE_PROPS_DOLLAR = "$defineProps";
var DEFINE_PROPS_REFS = "definePropsRefs";
var DEFINE_EMITS = "defineEmits";
var WITH_DEFAULTS = "withDefaults";
var DEFINE_OPTIONS = "defineOptions";
var DEFINE_MODELS = "defineModels";
var DEFINE_MODELS_DOLLAR = "$defineModels";
var DEFINE_SETUP_COMPONENT = "defineSetupComponent";
var DEFINE_RENDER = "defineRender";
var DEFINE_SLOTS = "defineSlots";
var DEFINE_PROP = "defineProp";
var DEFINE_EMIT = "defineEmit";
var REPO_ISSUE_URL = "https://github.com/sxzz/vue-macros/issues";
var REGEX_SRC_FILE = /\.[cm]?[jt]sx?$/;
var REGEX_SETUP_SFC = /\.setup\.[cm]?[jt]sx?$/;
var REGEX_VUE_SFC = /\.vue$/;
var REGEX_VUE_SUB = /\.vue\?vue&type=script/;
var REGEX_NODE_MODULES = /node_modules/;
var REGEX_SUPPORTED_EXT = /\.([cm]?[jt]sx?|vue)$/;
var VIRTUAL_ID_PREFIX = "/vue-macros";
// src/dep.ts
var _localpkg = require('local-pkg');
function detectVueVersion(root = process.cwd()) {
const vuePkg = _localpkg.getPackageInfoSync.call(void 0, "vue", { paths: [root] });
if (vuePkg && vuePkg.version) {
const version = Number.parseFloat(vuePkg.version);
return version >= 2 && version < 3 ? Math.trunc(version) : version;
} else {
return 3;
}
}
// src/unplugin.ts
var _chunkRQ6FZHFJjs = require('./chunk-RQ6FZHFJ.js');
var _pluginutils = require('@rollup/pluginutils');
function getTransformResult(s, id) {
if (_optionalChain([s, 'optionalAccess', _8 => _8.hasChanged, 'call', _9 => _9()])) {
return {
code: s.toString(),
get map() {
return s.generateMap({
source: id,
includeContent: true,
hires: true
});
}
};
}
}
function createFilter(options) {
return _pluginutils.createFilter.call(void 0, options.include, options.exclude);
}
var _chunkTQ2AXDU4js = require('./chunk-TQ2AXDU4.js');
require('./chunk-6F4PWJZI.js');
// src/vue.ts

@@ -18,3 +185,78 @@

var _chunkAEW3CNU2js = require('./chunk-AEW3CNU2.js');
function parseSFC(code, id) {
const sfc = _compilersfc.parse.call(void 0, code, {
filename: id
});
const { descriptor, errors } = sfc;
const scriptLang = _optionalChain([sfc, 'access', _10 => _10.descriptor, 'access', _11 => _11.script, 'optionalAccess', _12 => _12.lang]);
const scriptSetupLang = _optionalChain([sfc, 'access', _13 => _13.descriptor, 'access', _14 => _14.scriptSetup, 'optionalAccess', _15 => _15.lang]);
if (sfc.descriptor.script && sfc.descriptor.scriptSetup && (scriptLang || "js") !== (scriptSetupLang || "js")) {
throw new Error(
`[unplugin-vue-macros] <script> and <script setup> must have the same language type.`
);
}
const lang = scriptLang || scriptSetupLang;
return {
sfc,
...descriptor,
lang,
errors,
offset: _nullishCoalesce(_optionalChain([descriptor, 'access', _16 => _16.scriptSetup, 'optionalAccess', _17 => _17.loc, 'access', _18 => _18.start, 'access', _19 => _19.offset]), () => ( 0)),
getSetupAst() {
if (!descriptor.scriptSetup)
return;
return _astkit.babelParse.call(void 0, descriptor.scriptSetup.content, lang, {
plugins: [["importAttributes", { deprecatedAssertSyntax: true }]]
});
},
getScriptAst() {
if (!descriptor.script)
return;
return _astkit.babelParse.call(void 0, descriptor.script.content, lang, {
plugins: [["importAttributes", { deprecatedAssertSyntax: true }]]
});
}
};
}
function getFileCodeAndLang(code, id) {
if (!REGEX_VUE_SFC.test(id)) {
return {
code,
lang: _astkit.getLang.call(void 0, id)
};
}
const sfc = parseSFC(code, id);
const scriptCode = _nullishCoalesce(_optionalChain([sfc, 'access', _20 => _20.script, 'optionalAccess', _21 => _21.content]), () => ( ""));
return {
code: sfc.scriptSetup ? `${scriptCode}
;
${sfc.scriptSetup.content}` : scriptCode,
lang: _nullishCoalesce(sfc.lang, () => ( "js"))
};
}
function addNormalScript({ script, lang }, s) {
return {
start() {
if (script)
return script.loc.end.offset;
const attrs = lang ? ` lang="${lang}"` : "";
s.prependLeft(0, `<script${attrs}>`);
return 0;
},
end() {
if (!script)
s.appendRight(0, `
</script>
`);
}
};
}
function removeMacroImport(node, s, offset) {
if (node.type === "ImportDeclaration" && _optionalChain([node, 'access', _22 => _22.attributes, 'optionalAccess', _23 => _23.some, 'call', _24 => _24(
(attr) => _astkit.resolveString.call(void 0, attr.key) === "type" && attr.value.value === "macro"
)])) {
s.removeNode(node, { offset });
return true;
}
}

@@ -25,3 +267,2 @@

var _chunkNJOR23B7js = require('./chunk-NJOR23B7.js');

@@ -49,7 +290,3 @@

var _chunk3KTXRYLFjs = require('./chunk-3KTXRYLF.js');
// src/index.ts
var _magicstringast = require('magic-string-ast'); _createStarExport(_magicstringast);
var _astkit = require('ast-kit'); _createStarExport(_astkit);

@@ -64,30 +301,2 @@

exports.DEFINE_EMIT = _chunk3KTXRYLFjs.DEFINE_EMIT; exports.DEFINE_EMITS = _chunk3KTXRYLFjs.DEFINE_EMITS; exports.DEFINE_MODELS = _chunk3KTXRYLFjs.DEFINE_MODELS; exports.DEFINE_MODELS_DOLLAR = _chunk3KTXRYLFjs.DEFINE_MODELS_DOLLAR; exports.DEFINE_OPTIONS = _chunk3KTXRYLFjs.DEFINE_OPTIONS; exports.DEFINE_PROP = _chunk3KTXRYLFjs.DEFINE_PROP; exports.DEFINE_PROPS = _chunk3KTXRYLFjs.DEFINE_PROPS; exports.DEFINE_PROPS_DOLLAR = _chunk3KTXRYLFjs.DEFINE_PROPS_DOLLAR; exports.DEFINE_PROPS_REFS = _chunk3KTXRYLFjs.DEFINE_PROPS_REFS; exports.DEFINE_RENDER = _chunk3KTXRYLFjs.DEFINE_RENDER; exports.DEFINE_SETUP_COMPONENT = _chunk3KTXRYLFjs.DEFINE_SETUP_COMPONENT; exports.DEFINE_SLOTS = _chunk3KTXRYLFjs.DEFINE_SLOTS; exports.HELPER_PREFIX = _chunkRQ6FZHFJjs.HELPER_PREFIX; exports.REGEX_NODE_MODULES = _chunk3KTXRYLFjs.REGEX_NODE_MODULES; exports.REGEX_SETUP_SFC = _chunk3KTXRYLFjs.REGEX_SETUP_SFC; exports.REGEX_SRC_FILE = _chunk3KTXRYLFjs.REGEX_SRC_FILE; exports.REGEX_SUPPORTED_EXT = _chunk3KTXRYLFjs.REGEX_SUPPORTED_EXT; exports.REGEX_VUE_SFC = _chunk3KTXRYLFjs.REGEX_VUE_SFC; exports.REGEX_VUE_SUB = _chunk3KTXRYLFjs.REGEX_VUE_SUB; exports.REPO_ISSUE_URL = _chunk3KTXRYLFjs.REPO_ISSUE_URL; exports.VIRTUAL_ID_PREFIX = _chunk3KTXRYLFjs.VIRTUAL_ID_PREFIX; exports.WITH_DEFAULTS = _chunk3KTXRYLFjs.WITH_DEFAULTS; exports.addNormalScript = _chunkNJOR23B7js.addNormalScript; exports.checkInvalidScopeReference = _chunkRQ6FZHFJjs.checkInvalidScopeReference; exports.createFilter = _chunkAEW3CNU2js.createFilter; exports.detectVueVersion = _chunkTQ2AXDU4js.detectVueVersion; exports.getFileCodeAndLang = _chunkNJOR23B7js.getFileCodeAndLang; exports.getTransformResult = _chunkAEW3CNU2js.getTransformResult; exports.importHelperFn = _chunkRQ6FZHFJjs.importHelperFn; exports.isStaticExpression = _chunkRQ6FZHFJjs.isStaticExpression; exports.isStaticObjectKey = _chunkRQ6FZHFJjs.isStaticObjectKey; exports.normalizePath = _chunkAEW3CNU2js.normalizePath; exports.parseSFC = _chunkNJOR23B7js.parseSFC; exports.removeMacroImport = _chunkNJOR23B7js.removeMacroImport; exports.resolveObjectExpression = _chunkRQ6FZHFJjs.resolveObjectExpression; exports.resolveObjectKey = _chunkRQ6FZHFJjs.resolveObjectKey;
exports.DEFINE_EMIT = DEFINE_EMIT; exports.DEFINE_EMITS = DEFINE_EMITS; exports.DEFINE_MODELS = DEFINE_MODELS; exports.DEFINE_MODELS_DOLLAR = DEFINE_MODELS_DOLLAR; exports.DEFINE_OPTIONS = DEFINE_OPTIONS; exports.DEFINE_PROP = DEFINE_PROP; exports.DEFINE_PROPS = DEFINE_PROPS; exports.DEFINE_PROPS_DOLLAR = DEFINE_PROPS_DOLLAR; exports.DEFINE_PROPS_REFS = DEFINE_PROPS_REFS; exports.DEFINE_RENDER = DEFINE_RENDER; exports.DEFINE_SETUP_COMPONENT = DEFINE_SETUP_COMPONENT; exports.DEFINE_SLOTS = DEFINE_SLOTS; exports.HELPER_PREFIX = HELPER_PREFIX; exports.REGEX_NODE_MODULES = REGEX_NODE_MODULES; exports.REGEX_SETUP_SFC = REGEX_SETUP_SFC; exports.REGEX_SRC_FILE = REGEX_SRC_FILE; exports.REGEX_SUPPORTED_EXT = REGEX_SUPPORTED_EXT; exports.REGEX_VUE_SFC = REGEX_VUE_SFC; exports.REGEX_VUE_SUB = REGEX_VUE_SUB; exports.REPO_ISSUE_URL = REPO_ISSUE_URL; exports.VIRTUAL_ID_PREFIX = VIRTUAL_ID_PREFIX; exports.WITH_DEFAULTS = WITH_DEFAULTS; exports.addNormalScript = addNormalScript; exports.checkInvalidScopeReference = checkInvalidScopeReference; exports.createFilter = createFilter; exports.detectVueVersion = detectVueVersion; exports.getFileCodeAndLang = getFileCodeAndLang; exports.getTransformResult = getTransformResult; exports.importHelperFn = importHelperFn; exports.isStaticExpression = isStaticExpression; exports.isStaticObjectKey = isStaticObjectKey; exports.normalizePath = _pluginutils.normalizePath; exports.parseSFC = parseSFC; exports.removeMacroImport = removeMacroImport; exports.resolveObjectExpression = resolveObjectExpression; exports.resolveObjectKey = resolveObjectKey;

@@ -0,11 +1,84 @@

import { MagicStringBase, MagicString } from 'magic-string-ast';
export * from 'magic-string-ast';
export * from 'ast-kit';
export { HELPER_PREFIX, checkInvalidScopeReference, importHelperFn, isStaticExpression, isStaticObjectKey, resolveObjectExpression, resolveObjectKey } from './ast.js';
export { DEFINE_EMIT, DEFINE_EMITS, DEFINE_MODELS, DEFINE_MODELS_DOLLAR, DEFINE_OPTIONS, DEFINE_PROP, DEFINE_PROPS, DEFINE_PROPS_DOLLAR, DEFINE_PROPS_REFS, DEFINE_RENDER, DEFINE_SETUP_COMPONENT, DEFINE_SLOTS, REGEX_NODE_MODULES, REGEX_SETUP_SFC, REGEX_SRC_FILE, REGEX_SUPPORTED_EXT, REGEX_VUE_SFC, REGEX_VUE_SUB, REPO_ISSUE_URL, VIRTUAL_ID_PREFIX, WITH_DEFAULTS } from './constants.js';
export { detectVueVersion } from './dep.js';
export { MarkRequired, Overwrite, RecordToUnion, UnionToIntersection } from './types.js';
export { BaseOptions, createFilter, getTransformResult } from './unplugin.js';
export { SFC, SFCScriptBlock, addNormalScript, getFileCodeAndLang, parseSFC, removeMacroImport } from './vue.js';
import { Node, ObjectExpression, ObjectMethod, ObjectProperty, Program } from '@babel/types';
import { FilterPattern } from '@rollup/pluginutils';
export { normalizePath } from '@rollup/pluginutils';
import '@babel/types';
import '@vue/compiler-sfc';
import { SFCScriptBlock as SFCScriptBlock$1, SFCDescriptor, SFCParseResult } from '@vue/compiler-sfc';
declare function checkInvalidScopeReference(node: Node | undefined, method: string, setupBindings: string[]): void;
declare function isStaticExpression(node: Node, options?: Partial<Record<'object' | 'fn' | 'objectMethod' | 'array' | 'unary' | 'regex', boolean> & {
magicComment?: string;
}>): boolean;
declare function isStaticObjectKey(node: ObjectExpression): boolean;
/**
* @param node must be a static expression, SpreadElement is not supported
*/
declare function resolveObjectExpression(node: ObjectExpression): Record<string | number, ObjectMethod | ObjectProperty> | undefined;
declare function resolveObjectKey(node: Node, computed?: boolean, raw?: true): string;
declare function resolveObjectKey(node: Node, computed: boolean | undefined, raw: false): string | number;
declare const HELPER_PREFIX = "__MACROS_";
declare function importHelperFn(s: MagicStringBase, offset: number, local: string, from?: string, isDefault?: boolean): string;
declare const DEFINE_PROPS = "defineProps";
declare const DEFINE_PROPS_DOLLAR = "$defineProps";
declare const DEFINE_PROPS_REFS = "definePropsRefs";
declare const DEFINE_EMITS = "defineEmits";
declare const WITH_DEFAULTS = "withDefaults";
declare const DEFINE_OPTIONS = "defineOptions";
declare const DEFINE_MODELS = "defineModels";
declare const DEFINE_MODELS_DOLLAR = "$defineModels";
declare const DEFINE_SETUP_COMPONENT = "defineSetupComponent";
declare const DEFINE_RENDER = "defineRender";
declare const DEFINE_SLOTS = "defineSlots";
declare const DEFINE_PROP = "defineProp";
declare const DEFINE_EMIT = "defineEmit";
declare const REPO_ISSUE_URL = "https://github.com/sxzz/vue-macros/issues";
declare const REGEX_SRC_FILE: RegExp;
declare const REGEX_SETUP_SFC: RegExp;
declare const REGEX_VUE_SFC: RegExp;
declare const REGEX_VUE_SUB: RegExp;
declare const REGEX_NODE_MODULES: RegExp;
declare const REGEX_SUPPORTED_EXT: RegExp;
declare const VIRTUAL_ID_PREFIX = "/vue-macros";
declare function detectVueVersion(root?: string): number;
type MarkRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
type RecordToUnion<T extends Record<string, any>> = T[keyof T];
type UnionToIntersection<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
declare function getTransformResult(s: MagicStringBase | undefined, id: string): {
code: string;
map: any;
} | undefined;
interface BaseOptions {
include?: FilterPattern;
exclude?: FilterPattern;
version?: number;
}
declare function createFilter(options: BaseOptions): (id: unknown) => boolean;
type SFCScriptBlock = Omit<SFCScriptBlock$1, 'scriptAst' | 'scriptSetupAst'>;
type SFC = Omit<SFCDescriptor, 'script' | 'scriptSetup'> & {
sfc: SFCParseResult;
script?: SFCScriptBlock | null;
scriptSetup?: SFCScriptBlock | null;
lang: string | undefined;
getScriptAst(): Program | undefined;
getSetupAst(): Program | undefined;
offset: number;
} & Pick<SFCParseResult, 'errors'>;
declare function parseSFC(code: string, id: string): SFC;
declare function getFileCodeAndLang(code: string, id: string): {
code: string;
lang: string;
};
declare function addNormalScript({ script, lang }: SFC, s: MagicStringBase): {
start(): number;
end(): void;
};
declare function removeMacroImport(node: Node, s: MagicString, offset: number): true | undefined;
export { BaseOptions, DEFINE_EMIT, DEFINE_EMITS, DEFINE_MODELS, DEFINE_MODELS_DOLLAR, DEFINE_OPTIONS, DEFINE_PROP, DEFINE_PROPS, DEFINE_PROPS_DOLLAR, DEFINE_PROPS_REFS, DEFINE_RENDER, DEFINE_SETUP_COMPONENT, DEFINE_SLOTS, HELPER_PREFIX, MarkRequired, Overwrite, REGEX_NODE_MODULES, REGEX_SETUP_SFC, REGEX_SRC_FILE, REGEX_SUPPORTED_EXT, REGEX_VUE_SFC, REGEX_VUE_SUB, REPO_ISSUE_URL, RecordToUnion, SFC, SFCScriptBlock, UnionToIntersection, VIRTUAL_ID_PREFIX, WITH_DEFAULTS, addNormalScript, checkInvalidScopeReference, createFilter, detectVueVersion, getFileCodeAndLang, getTransformResult, importHelperFn, isStaticExpression, isStaticObjectKey, parseSFC, removeMacroImport, resolveObjectExpression, resolveObjectKey };

@@ -1,14 +0,181 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
var _magicstringast = require('magic-string-ast'); _createStarExport(_magicstringast);
var _astkit = require('ast-kit'); _createStarExport(_astkit);
// src/ast.ts
var _compilersfc = require('@vue/compiler-sfc');
function checkInvalidScopeReference(node, method, setupBindings) {
if (!node)
return;
_compilersfc.walkIdentifiers.call(void 0, node, (id) => {
if (setupBindings.includes(id.name))
throw new SyntaxError(
`\`${method}()\` in <script setup> cannot reference locally declared variables (${id.name}) because it will be hoisted outside of the setup() function.`
);
});
}
function isStaticExpression(node, options = {}) {
const { magicComment, fn, object, objectMethod, array, unary, regex } = options;
if (magicComment && _optionalChain([node, 'access', _ => _.leadingComments, 'optionalAccess', _2 => _2.some, 'call', _3 => _3(
(comment) => comment.value.trim() === magicComment
)]))
return true;
else if (fn && _astkit.isFunctionType.call(void 0, node))
return true;
switch (node.type) {
case "UnaryExpression":
return !!unary && isStaticExpression(node.argument, options);
case "LogicalExpression":
case "BinaryExpression":
return isStaticExpression(node.left, options) && isStaticExpression(node.right, options);
case "ConditionalExpression":
return isStaticExpression(node.test, options) && isStaticExpression(node.consequent, options) && isStaticExpression(node.alternate, options);
case "SequenceExpression":
case "TemplateLiteral":
return node.expressions.every((expr) => isStaticExpression(expr, options));
case "ArrayExpression":
return !!array && node.elements.every(
(element) => element && isStaticExpression(element, options)
);
case "ObjectExpression":
return !!object && node.properties.every((prop) => {
if (prop.type === "SpreadElement") {
return prop.argument.type === "ObjectExpression" && isStaticExpression(prop.argument, options);
} else if (!_astkit.isLiteralType.call(void 0, prop.key) && prop.computed) {
return false;
} else if (prop.type === "ObjectProperty" && !isStaticExpression(prop.value, options)) {
return false;
}
if (prop.type === "ObjectMethod" && !objectMethod) {
return false;
}
return true;
});
case "ParenthesizedExpression":
case "TSNonNullExpression":
case "TSAsExpression":
case "TSTypeAssertion":
case "TSSatisfiesExpression":
return isStaticExpression(node.expression, options);
case "RegExpLiteral":
return !!regex;
}
if (_astkit.isLiteralType.call(void 0, node))
return true;
return false;
}
function isStaticObjectKey(node) {
return node.properties.every((prop) => {
if (prop.type === "SpreadElement") {
return prop.argument.type === "ObjectExpression" && isStaticObjectKey(prop.argument);
}
return !prop.computed || _astkit.isLiteralType.call(void 0, prop.key);
});
}
function resolveObjectExpression(node) {
const maps = {};
for (const property of node.properties) {
if (property.type === "SpreadElement") {
if (property.argument.type !== "ObjectExpression")
return void 0;
Object.assign(maps, resolveObjectExpression(property.argument));
} else {
const key = resolveObjectKey(property.key, property.computed, false);
maps[key] = property;
}
}
return maps;
}
function resolveObjectKey(node, computed = false, raw = true) {
switch (node.type) {
case "StringLiteral":
case "NumericLiteral":
return raw ? node.extra.raw : node.value;
case "Identifier":
if (!computed)
return raw ? `'${node.name}'` : node.name;
default:
throw new SyntaxError(`Unexpected node type: ${node.type}`);
}
}
var importedMap = /* @__PURE__ */ new WeakMap();
var HELPER_PREFIX = "__MACROS_";
function importHelperFn(s, offset, local, from = "vue", isDefault = false) {
const imported = isDefault ? "default" : local;
const cacheKey = `${from}@${imported}`;
if (!_optionalChain([importedMap, 'access', _4 => _4.get, 'call', _5 => _5(s), 'optionalAccess', _6 => _6.has, 'call', _7 => _7(cacheKey)])) {
s.appendLeft(
offset,
`
import ${isDefault ? HELPER_PREFIX + local : `{ ${imported} as ${HELPER_PREFIX + local} }`} from ${JSON.stringify(from)};`
);
if (!importedMap.has(s)) {
importedMap.set(s, /* @__PURE__ */ new Set([cacheKey]));
} else {
importedMap.get(s).add(cacheKey);
}
}
return `${HELPER_PREFIX}${local}`;
}
// src/constants.ts
var DEFINE_PROPS = "defineProps";
var DEFINE_PROPS_DOLLAR = "$defineProps";
var DEFINE_PROPS_REFS = "definePropsRefs";
var DEFINE_EMITS = "defineEmits";
var WITH_DEFAULTS = "withDefaults";
var DEFINE_OPTIONS = "defineOptions";
var DEFINE_MODELS = "defineModels";
var DEFINE_MODELS_DOLLAR = "$defineModels";
var DEFINE_SETUP_COMPONENT = "defineSetupComponent";
var DEFINE_RENDER = "defineRender";
var DEFINE_SLOTS = "defineSlots";
var DEFINE_PROP = "defineProp";
var DEFINE_EMIT = "defineEmit";
var REPO_ISSUE_URL = "https://github.com/sxzz/vue-macros/issues";
var REGEX_SRC_FILE = /\.[cm]?[jt]sx?$/;
var REGEX_SETUP_SFC = /\.setup\.[cm]?[jt]sx?$/;
var REGEX_VUE_SFC = /\.vue$/;
var REGEX_VUE_SUB = /\.vue\?vue&type=script/;
var REGEX_NODE_MODULES = /node_modules/;
var REGEX_SUPPORTED_EXT = /\.([cm]?[jt]sx?|vue)$/;
var VIRTUAL_ID_PREFIX = "/vue-macros";
// src/dep.ts
var _localpkg = require('local-pkg');
function detectVueVersion(root = process.cwd()) {
const vuePkg = _localpkg.getPackageInfoSync.call(void 0, "vue", { paths: [root] });
if (vuePkg && vuePkg.version) {
const version = Number.parseFloat(vuePkg.version);
return version >= 2 && version < 3 ? Math.trunc(version) : version;
} else {
return 3;
}
}
// src/unplugin.ts
var _chunkRQ6FZHFJjs = require('./chunk-RQ6FZHFJ.js');
var _pluginutils = require('@rollup/pluginutils');
function getTransformResult(s, id) {
if (_optionalChain([s, 'optionalAccess', _8 => _8.hasChanged, 'call', _9 => _9()])) {
return {
code: s.toString(),
get map() {
return s.generateMap({
source: id,
includeContent: true,
hires: true
});
}
};
}
}
function createFilter(options) {
return _pluginutils.createFilter.call(void 0, options.include, options.exclude);
}
var _chunkTQ2AXDU4js = require('./chunk-TQ2AXDU4.js');
require('./chunk-6F4PWJZI.js');
// src/vue.ts

@@ -18,3 +185,78 @@

var _chunkAEW3CNU2js = require('./chunk-AEW3CNU2.js');
function parseSFC(code, id) {
const sfc = _compilersfc.parse.call(void 0, code, {
filename: id
});
const { descriptor, errors } = sfc;
const scriptLang = _optionalChain([sfc, 'access', _10 => _10.descriptor, 'access', _11 => _11.script, 'optionalAccess', _12 => _12.lang]);
const scriptSetupLang = _optionalChain([sfc, 'access', _13 => _13.descriptor, 'access', _14 => _14.scriptSetup, 'optionalAccess', _15 => _15.lang]);
if (sfc.descriptor.script && sfc.descriptor.scriptSetup && (scriptLang || "js") !== (scriptSetupLang || "js")) {
throw new Error(
`[unplugin-vue-macros] <script> and <script setup> must have the same language type.`
);
}
const lang = scriptLang || scriptSetupLang;
return {
sfc,
...descriptor,
lang,
errors,
offset: _nullishCoalesce(_optionalChain([descriptor, 'access', _16 => _16.scriptSetup, 'optionalAccess', _17 => _17.loc, 'access', _18 => _18.start, 'access', _19 => _19.offset]), () => ( 0)),
getSetupAst() {
if (!descriptor.scriptSetup)
return;
return _astkit.babelParse.call(void 0, descriptor.scriptSetup.content, lang, {
plugins: [["importAttributes", { deprecatedAssertSyntax: true }]]
});
},
getScriptAst() {
if (!descriptor.script)
return;
return _astkit.babelParse.call(void 0, descriptor.script.content, lang, {
plugins: [["importAttributes", { deprecatedAssertSyntax: true }]]
});
}
};
}
function getFileCodeAndLang(code, id) {
if (!REGEX_VUE_SFC.test(id)) {
return {
code,
lang: _astkit.getLang.call(void 0, id)
};
}
const sfc = parseSFC(code, id);
const scriptCode = _nullishCoalesce(_optionalChain([sfc, 'access', _20 => _20.script, 'optionalAccess', _21 => _21.content]), () => ( ""));
return {
code: sfc.scriptSetup ? `${scriptCode}
;
${sfc.scriptSetup.content}` : scriptCode,
lang: _nullishCoalesce(sfc.lang, () => ( "js"))
};
}
function addNormalScript({ script, lang }, s) {
return {
start() {
if (script)
return script.loc.end.offset;
const attrs = lang ? ` lang="${lang}"` : "";
s.prependLeft(0, `<script${attrs}>`);
return 0;
},
end() {
if (!script)
s.appendRight(0, `
</script>
`);
}
};
}
function removeMacroImport(node, s, offset) {
if (node.type === "ImportDeclaration" && _optionalChain([node, 'access', _22 => _22.attributes, 'optionalAccess', _23 => _23.some, 'call', _24 => _24(
(attr) => _astkit.resolveString.call(void 0, attr.key) === "type" && attr.value.value === "macro"
)])) {
s.removeNode(node, { offset });
return true;
}
}

@@ -25,3 +267,2 @@

var _chunkNJOR23B7js = require('./chunk-NJOR23B7.js');

@@ -49,7 +290,3 @@

var _chunk3KTXRYLFjs = require('./chunk-3KTXRYLF.js');
// src/index.ts
var _magicstringast = require('magic-string-ast'); _createStarExport(_magicstringast);
var _astkit = require('ast-kit'); _createStarExport(_astkit);

@@ -64,30 +301,2 @@

exports.DEFINE_EMIT = _chunk3KTXRYLFjs.DEFINE_EMIT; exports.DEFINE_EMITS = _chunk3KTXRYLFjs.DEFINE_EMITS; exports.DEFINE_MODELS = _chunk3KTXRYLFjs.DEFINE_MODELS; exports.DEFINE_MODELS_DOLLAR = _chunk3KTXRYLFjs.DEFINE_MODELS_DOLLAR; exports.DEFINE_OPTIONS = _chunk3KTXRYLFjs.DEFINE_OPTIONS; exports.DEFINE_PROP = _chunk3KTXRYLFjs.DEFINE_PROP; exports.DEFINE_PROPS = _chunk3KTXRYLFjs.DEFINE_PROPS; exports.DEFINE_PROPS_DOLLAR = _chunk3KTXRYLFjs.DEFINE_PROPS_DOLLAR; exports.DEFINE_PROPS_REFS = _chunk3KTXRYLFjs.DEFINE_PROPS_REFS; exports.DEFINE_RENDER = _chunk3KTXRYLFjs.DEFINE_RENDER; exports.DEFINE_SETUP_COMPONENT = _chunk3KTXRYLFjs.DEFINE_SETUP_COMPONENT; exports.DEFINE_SLOTS = _chunk3KTXRYLFjs.DEFINE_SLOTS; exports.HELPER_PREFIX = _chunkRQ6FZHFJjs.HELPER_PREFIX; exports.REGEX_NODE_MODULES = _chunk3KTXRYLFjs.REGEX_NODE_MODULES; exports.REGEX_SETUP_SFC = _chunk3KTXRYLFjs.REGEX_SETUP_SFC; exports.REGEX_SRC_FILE = _chunk3KTXRYLFjs.REGEX_SRC_FILE; exports.REGEX_SUPPORTED_EXT = _chunk3KTXRYLFjs.REGEX_SUPPORTED_EXT; exports.REGEX_VUE_SFC = _chunk3KTXRYLFjs.REGEX_VUE_SFC; exports.REGEX_VUE_SUB = _chunk3KTXRYLFjs.REGEX_VUE_SUB; exports.REPO_ISSUE_URL = _chunk3KTXRYLFjs.REPO_ISSUE_URL; exports.VIRTUAL_ID_PREFIX = _chunk3KTXRYLFjs.VIRTUAL_ID_PREFIX; exports.WITH_DEFAULTS = _chunk3KTXRYLFjs.WITH_DEFAULTS; exports.addNormalScript = _chunkNJOR23B7js.addNormalScript; exports.checkInvalidScopeReference = _chunkRQ6FZHFJjs.checkInvalidScopeReference; exports.createFilter = _chunkAEW3CNU2js.createFilter; exports.detectVueVersion = _chunkTQ2AXDU4js.detectVueVersion; exports.getFileCodeAndLang = _chunkNJOR23B7js.getFileCodeAndLang; exports.getTransformResult = _chunkAEW3CNU2js.getTransformResult; exports.importHelperFn = _chunkRQ6FZHFJjs.importHelperFn; exports.isStaticExpression = _chunkRQ6FZHFJjs.isStaticExpression; exports.isStaticObjectKey = _chunkRQ6FZHFJjs.isStaticObjectKey; exports.normalizePath = _chunkAEW3CNU2js.normalizePath; exports.parseSFC = _chunkNJOR23B7js.parseSFC; exports.removeMacroImport = _chunkNJOR23B7js.removeMacroImport; exports.resolveObjectExpression = _chunkRQ6FZHFJjs.resolveObjectExpression; exports.resolveObjectKey = _chunkRQ6FZHFJjs.resolveObjectKey;
exports.DEFINE_EMIT = DEFINE_EMIT; exports.DEFINE_EMITS = DEFINE_EMITS; exports.DEFINE_MODELS = DEFINE_MODELS; exports.DEFINE_MODELS_DOLLAR = DEFINE_MODELS_DOLLAR; exports.DEFINE_OPTIONS = DEFINE_OPTIONS; exports.DEFINE_PROP = DEFINE_PROP; exports.DEFINE_PROPS = DEFINE_PROPS; exports.DEFINE_PROPS_DOLLAR = DEFINE_PROPS_DOLLAR; exports.DEFINE_PROPS_REFS = DEFINE_PROPS_REFS; exports.DEFINE_RENDER = DEFINE_RENDER; exports.DEFINE_SETUP_COMPONENT = DEFINE_SETUP_COMPONENT; exports.DEFINE_SLOTS = DEFINE_SLOTS; exports.HELPER_PREFIX = HELPER_PREFIX; exports.REGEX_NODE_MODULES = REGEX_NODE_MODULES; exports.REGEX_SETUP_SFC = REGEX_SETUP_SFC; exports.REGEX_SRC_FILE = REGEX_SRC_FILE; exports.REGEX_SUPPORTED_EXT = REGEX_SUPPORTED_EXT; exports.REGEX_VUE_SFC = REGEX_VUE_SFC; exports.REGEX_VUE_SUB = REGEX_VUE_SUB; exports.REPO_ISSUE_URL = REPO_ISSUE_URL; exports.VIRTUAL_ID_PREFIX = VIRTUAL_ID_PREFIX; exports.WITH_DEFAULTS = WITH_DEFAULTS; exports.addNormalScript = addNormalScript; exports.checkInvalidScopeReference = checkInvalidScopeReference; exports.createFilter = createFilter; exports.detectVueVersion = detectVueVersion; exports.getFileCodeAndLang = getFileCodeAndLang; exports.getTransformResult = getTransformResult; exports.importHelperFn = importHelperFn; exports.isStaticExpression = isStaticExpression; exports.isStaticObjectKey = isStaticObjectKey; exports.normalizePath = _pluginutils.normalizePath; exports.parseSFC = parseSFC; exports.removeMacroImport = removeMacroImport; exports.resolveObjectExpression = resolveObjectExpression; exports.resolveObjectKey = resolveObjectKey;

20

package.json
{
"name": "@vue-macros/common",
"version": "1.4.0",
"packageManager": "pnpm@8.6.0",
"version": "1.4.1",
"packageManager": "pnpm@8.6.5",
"description": "common feature from Vue Macros.",

@@ -35,7 +35,13 @@ "keywords": [

"dev": "./src/index.ts",
"types": "./dist/index.d.ts",
"types": {
"require": "./dist/index.d.ts",
"import": "./dist/index.d.mts"
},
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./*": "./*"
"./*": [
"./*",
"./*.d.ts"
]
},

@@ -51,6 +57,6 @@ "peerDependencies": {

"dependencies": {
"@babel/types": "^7.22.4",
"@babel/types": "^7.22.5",
"@rollup/pluginutils": "^5.0.2",
"@vue/compiler-sfc": "^3.3.4",
"ast-kit": "^0.6.2",
"ast-kit": "^0.6.6",
"local-pkg": "^0.4.3",

@@ -60,3 +66,3 @@ "magic-string-ast": "^0.1.2"

"devDependencies": {
"@babel/parser": "^7.22.4"
"@babel/parser": "^7.22.7"
},

@@ -63,0 +69,0 @@ "engines": {

Sorry, the diff of this file is not supported yet

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