New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vue-macros/api

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue-macros/api - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

dist/index.d.mts

780

./dist/index.js

@@ -1,3 +0,5 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } async function _asyncOptionalChain(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 = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
var _common = require('@vue-macros/common');
// src/vue/analyze.ts

@@ -11,2 +13,3 @@

// src/vue/props.ts

@@ -18,4 +21,33 @@

// src/ts/create.ts
function createUnionType(types) {
return {
type: "TSUnionType",
types
};
}
function createStringLiteral(value) {
return {
type: "StringLiteral",
value,
extra: {
rawValue: value,
raw: JSON.stringify(value)
}
};
}
function createTSLiteralType(literal) {
return {
type: "TSLiteralType",
literal
};
}
// src/ts/is.ts
var _types = require('@babel/types');
function isTSDeclaration(node) {
return _types.isDeclaration.call(void 0, node) && node.type.startsWith("TS");
}
// src/ts/resolve-reference.ts

@@ -25,32 +57,583 @@

// src/ts/resolve.ts
// src/ts/property.ts
function mergeTSProperties(a, b) {
return {
callSignatures: [...a.callSignatures, ...b.callSignatures],
constructSignatures: [...a.constructSignatures, ...b.constructSignatures],
methods: { ...a.methods, ...b.methods },
properties: { ...a.properties, ...b.properties }
};
}
function checkForTSProperties(node) {
return !!node && [
"TSInterfaceDeclaration",
"TSInterfaceBody",
"TSTypeLiteral",
"TSIntersectionType",
"TSMappedType",
"TSFunctionType"
].includes(node.type);
}
async function resolveTSProperties({
type,
scope
}) {
switch (type.type) {
case "TSInterfaceBody":
return resolveTypeElements(scope, type.body);
case "TSTypeLiteral":
return resolveTypeElements(scope, type.members);
case "TSInterfaceDeclaration": {
let properties = resolveTypeElements(scope, type.body.body);
if (type.extends) {
const resolvedExtends = (await Promise.all(
type.extends.map(
(node) => node.expression.type === "Identifier" ? resolveTSReferencedType({
scope,
type: node.expression
}) : void 0
)
)).filter(filterValidExtends);
if (resolvedExtends.length > 0) {
const ext = (await Promise.all(
resolvedExtends.map((resolved) => resolveTSProperties(resolved))
)).reduceRight((acc, curr) => mergeTSProperties(acc, curr));
properties = mergeTSProperties(ext, properties);
}
}
return properties;
}
case "TSIntersectionType": {
let properties = {
callSignatures: [],
constructSignatures: [],
methods: {},
properties: {}
};
for (const subType of type.types) {
const resolved = await resolveTSReferencedType({
scope,
type: subType
});
if (!filterValidExtends(resolved))
continue;
properties = mergeTSProperties(
properties,
await resolveTSProperties(resolved)
);
}
return properties;
}
case "TSMappedType": {
const properties = {
callSignatures: [],
constructSignatures: [],
methods: {},
properties: {}
};
if (!type.typeParameter.constraint)
return properties;
const constraint = await resolveTSReferencedType({
type: type.typeParameter.constraint,
scope
});
if (!constraint || isTSNamespace(constraint))
return properties;
const types = resolveMaybeTSUnion(constraint.type);
for (const subType of types) {
if (subType.type !== "TSLiteralType")
continue;
const literal = await resolveTSLiteralType({
type: subType,
scope: constraint.scope
});
if (!literal)
continue;
const keys = resolveMaybeTSUnion(literal).map(
(literal2) => String(_common.resolveLiteral.call(void 0, literal2))
);
for (const key of keys) {
properties.properties[String(key)] = {
value: type.typeAnnotation ? { scope, type: type.typeAnnotation } : null,
optional: type.optional === "+" || type.optional === true,
signature: { type, scope }
};
}
}
return properties;
}
case "TSFunctionType": {
const properties = {
callSignatures: [{ type, scope }],
constructSignatures: [],
methods: {},
properties: {}
};
return properties;
}
default:
throw new Error(`unknown node: ${_optionalChain([type, 'optionalAccess', _ => _.type])}`);
}
function filterValidExtends(node) {
return !isTSNamespace(node) && checkForTSProperties(_optionalChain([node, 'optionalAccess', _2 => _2.type]));
}
}
function getTSPropertiesKeys(properties) {
return [
.../* @__PURE__ */ new Set([
...Object.keys(properties.properties),
...Object.keys(properties.methods)
])
];
}
// src/ts/resolve.ts
function resolveReferenceName(node) {
if (node.type === "TSTypeReference") {
return resolveReferenceName(node.typeName);
} else if (node.type === "Identifier")
return [node];
else {
return [...resolveReferenceName(node.left), node.right];
}
}
async function resolveTSTemplateLiteral({
type,
scope
}) {
const types = (await resolveKeys("", type.quasis, type.expressions)).map(
(k) => createStringLiteral(k)
);
return types;
async function resolveKeys(prefix, quasis, expressions) {
if (expressions.length === 0) {
return [prefix + (_nullishCoalesce(_optionalChain([quasis, 'access', _3 => _3[0], 'optionalAccess', _4 => _4.value, 'access', _5 => _5.cooked]), () => ( "")))];
}
const [expr, ...restExpr] = expressions;
const [quasi, ...restQuasis] = quasis;
const subTypes = resolveMaybeTSUnion(expr);
const keys = [];
for (const type2 of subTypes) {
if (!isSupportedForTSReferencedType(type2))
continue;
const resolved = await resolveTSReferencedType({
type: type2,
scope
});
if (!resolved || isTSNamespace(resolved))
continue;
const types2 = resolveMaybeTSUnion(resolved.type);
for (const type3 of types2) {
if (type3.type !== "TSLiteralType")
continue;
const literal = await resolveTSLiteralType({ type: type3, scope });
if (!literal)
continue;
const subKeys = resolveMaybeTSUnion(literal).map(
(literal2) => String(_common.resolveLiteral.call(void 0, literal2))
);
for (const key of subKeys) {
const newPrefix = prefix + quasi.value.cooked + String(key);
keys.push(...await resolveKeys(newPrefix, restQuasis, restExpr));
}
}
}
return keys;
}
}
async function resolveTSLiteralType({
type,
scope
}) {
if (type.literal.type === "UnaryExpression")
return;
if (type.literal.type === "TemplateLiteral") {
const types = await resolveTSTemplateLiteral({ type: type.literal, scope });
return types;
}
return type.literal;
}
function resolveTypeElements(scope, elements) {
const properties = {
callSignatures: [],
constructSignatures: [],
methods: {},
properties: {}
};
const tryGetKey = (element) => {
try {
return _common.resolveObjectKey.call(void 0, element.key, element.computed, false);
} catch (e) {
}
};
for (const element of elements) {
switch (element.type) {
case "TSCallSignatureDeclaration":
properties.callSignatures.push({ scope, type: element });
break;
case "TSConstructSignatureDeclaration":
properties.constructSignatures.push({ scope, type: element });
break;
case "TSMethodSignature": {
const key = tryGetKey(element);
if (!key)
continue;
if (properties.properties[key])
continue;
if (!properties.methods[key])
properties.methods[key] = [];
if (element.typeAnnotation) {
properties.methods[key].push({ scope, type: element });
}
break;
}
case "TSPropertySignature": {
const key = tryGetKey(element);
if (!key)
continue;
if (!properties.properties[key] && !properties.methods[key]) {
const type = _optionalChain([element, 'access', _6 => _6.typeAnnotation, 'optionalAccess', _7 => _7.typeAnnotation]);
properties.properties[key] = {
value: type ? { type, scope } : null,
optional: !!element.optional,
signature: { type: element, scope }
};
}
break;
}
case "TSIndexSignature":
break;
}
}
return properties;
}
async function resolveTSIndexedAccessType({ scope, type }, stacks = []) {
const object = await resolveTSReferencedType(
{ type: type.objectType, scope },
stacks
);
if (!object || isTSNamespace(object))
return void 0;
const objectType = object.type;
if (type.indexType.type === "TSNumberKeyword") {
let types;
if (objectType.type === "TSArrayType") {
types = [objectType.elementType];
} else if (objectType.type === "TSTupleType") {
types = objectType.elementTypes.map(
(t) => t.type === "TSNamedTupleMember" ? t.elementType : t
);
} else if (objectType.type === "TSTypeReference" && objectType.typeName.type === "Identifier" && objectType.typeName.name === "Array" && objectType.typeParameters) {
types = objectType.typeParameters.params;
} else {
return void 0;
}
return { type: createUnionType(types), scope };
} else if (objectType.type !== "TSInterfaceDeclaration" && objectType.type !== "TSTypeLiteral" && objectType.type !== "TSIntersectionType" && objectType.type !== "TSMappedType" && objectType.type !== "TSFunctionType")
return void 0;
const properties = await resolveTSProperties({
type: objectType,
scope: object.scope
});
const indexTypes = resolveMaybeTSUnion(type.indexType);
const indexes = [];
let optional = false;
for (const index of indexTypes) {
let keys;
if (index.type === "TSLiteralType") {
const literal = await resolveTSLiteralType({
type: index,
scope: object.scope
});
if (!literal)
continue;
keys = resolveMaybeTSUnion(literal).map(
(literal2) => String(_common.resolveLiteral.call(void 0, literal2))
);
} else if (index.type === "TSTypeOperator") {
const keysStrings = await resolveTSTypeOperator({
type: index,
scope: object.scope
});
if (!keysStrings)
continue;
keys = resolveMaybeTSUnion(keysStrings).map(
(literal) => String(_common.resolveLiteral.call(void 0, literal))
);
} else
continue;
for (const key of keys) {
const property = properties.properties[key];
if (property) {
optional ||= property.optional;
const propertyType = properties.properties[key].value;
if (propertyType)
indexes.push(propertyType.type);
}
const methods = properties.methods[key];
if (methods) {
optional ||= methods.some((m) => !!m.type.optional);
indexes.push(
...methods.map(
({ type: type2 }) => ({
...type2,
type: "TSFunctionType"
})
)
);
}
}
}
if (indexes.length === 0)
return void 0;
if (optional)
indexes.push({ type: "TSUndefinedKeyword" });
return { type: createUnionType(indexes), scope };
}
async function resolveTSTypeOperator({ scope, type }, stacks = []) {
if (type.operator !== "keyof")
return void 0;
const resolved = await resolveTSReferencedType(
{
type: type.typeAnnotation,
scope
},
stacks
);
if (!resolved || isTSNamespace(resolved))
return void 0;
const { type: resolvedType, scope: resolvedScope } = resolved;
if (!checkForTSProperties(resolvedType))
return void 0;
const properties = await resolveTSProperties({
type: resolvedType,
scope: resolvedScope
});
return getTSPropertiesKeys(properties).map((k) => createStringLiteral(k));
}
function resolveMaybeTSUnion(node) {
if (Array.isArray(node))
return node;
if (node.type === "TSUnionType")
return node.types.flatMap((t) => resolveMaybeTSUnion(t));
return [node];
}
// src/ts/scope.ts
var _promises = require('fs/promises');
var _chunkQOJYKENBjs = require('./chunk-QOJYKENB.js');
var _chunk5IUQDHHYjs = require('./chunk-5IUQDHHY.js');
// src/index.ts
var _common = require('@vue-macros/common');
// src/vue/analyze.ts
var tsFileCache = {};
async function getTSFile(filePath) {
if (tsFileCache[filePath])
return tsFileCache[filePath];
const content = await _promises.readFile.call(void 0, filePath, "utf-8");
const { code, lang } = _common.getFileCodeAndLang.call(void 0, content, filePath);
return tsFileCache[filePath] = {
kind: "file",
filePath,
content,
ast: _common.REGEX_SUPPORTED_EXT.test(filePath) ? _common.babelParse.call(void 0, code, lang).body : void 0
};
}
function resolveTSScope(scope) {
const isFile = scope.kind === "file";
let parentScope;
if (!isFile)
parentScope = resolveTSScope(scope.scope);
const file = isFile ? scope : parentScope.file;
const body = isFile ? scope.ast : scope.ast.body;
const exports = scope.exports;
const declarations = isFile ? scope.declarations : { ...resolveTSScope(scope.scope).declarations, ...scope.declarations };
return {
isFile,
file,
body,
declarations,
exports
};
}
// src/ts/resolve-reference.ts
function isSupportedForTSReferencedType(node) {
return _types.isTSType.call(void 0, node) || node.type === "Identifier" || isTSDeclaration(node);
}
async function resolveTSReferencedType(ref, stacks = []) {
const { scope, type } = ref;
if (stacks.some((stack) => stack.scope === scope && stack.type === type)) {
return ref;
}
stacks.push(ref);
switch (type.type) {
case "TSTypeAliasDeclaration":
case "TSParenthesizedType":
return resolveTSReferencedType(
{ scope, type: type.typeAnnotation },
stacks
);
case "TSIndexedAccessType":
return resolveTSIndexedAccessType({ type, scope }, stacks);
case "TSModuleDeclaration": {
if (type.body.type === "TSModuleBlock") {
const newScope = {
kind: "module",
ast: type.body,
scope
};
await resolveTSNamespace(newScope);
return newScope.exports;
}
return void 0;
}
}
if (type.type !== "Identifier" && type.type !== "TSTypeReference")
return { scope, type };
await resolveTSNamespace(scope);
const refNames = resolveReferenceName(type).map((id) => id.name);
let resolved = resolveTSScope(scope).declarations;
for (const name of refNames) {
if (isTSNamespace(resolved) && resolved[name]) {
resolved = resolved[name];
} else if (type.type === "TSTypeReference") {
return { type, scope };
}
}
return resolved;
}
// src/ts/resolve-file.ts
var _fs = require('fs');
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
var resolveTSFileIdImpl = resolveTSFileIdNode;
function resolveTSFileId(id, importer) {
return resolveTSFileIdImpl(id, importer);
}
function resolveTSFileIdNode(id, importer) {
function tryResolve(id2, importer2) {
const filePath = _path2.default.resolve(importer2, "..", id2);
if (!_fs.existsSync.call(void 0, filePath))
return;
return filePath;
}
return tryResolve(id, importer) || tryResolve(`${id}.ts`, importer) || tryResolve(`${id}.d.ts`, importer) || tryResolve(`${id}/index`, importer) || tryResolve(`${id}/index.ts`, importer) || tryResolve(`${id}/index.d.ts`, importer);
}
function setResolveTSFileIdImpl(impl) {
resolveTSFileIdImpl = impl;
}
// src/ts/namespace.ts
var namespaceSymbol = Symbol("namespace");
function isTSNamespace(val) {
return !!val && typeof val === "object" && namespaceSymbol in val;
}
async function resolveTSNamespace(scope) {
if (scope.exports)
return;
const exports = {
[namespaceSymbol]: true
};
scope.exports = exports;
const declarations = {
[namespaceSymbol]: true,
...scope.declarations
};
scope.declarations = declarations;
const { body, file } = resolveTSScope(scope);
for (const stmt of body || []) {
if (stmt.type === "ExportDefaultDeclaration" && isTSDeclaration(stmt.declaration)) {
exports["default"] = await resolveTSReferencedType({
scope,
type: stmt.declaration
});
} else if (stmt.type === "ExportAllDeclaration") {
const resolved = await resolveTSFileId(stmt.source.value, file.filePath);
if (!resolved)
continue;
const sourceScope = await getTSFile(resolved);
await resolveTSNamespace(sourceScope);
Object.assign(exports, sourceScope.exports);
} else if (stmt.type === "ExportNamedDeclaration") {
let sourceExports;
if (stmt.source) {
const resolved = await resolveTSFileId(stmt.source.value, file.filePath);
if (!resolved)
continue;
const scope2 = await getTSFile(resolved);
await resolveTSNamespace(scope2);
sourceExports = scope2.exports;
} else {
sourceExports = declarations;
}
for (const specifier of stmt.specifiers) {
let exported;
if (specifier.type === "ExportDefaultSpecifier") {
exported = sourceExports["default"];
} else if (specifier.type === "ExportNamespaceSpecifier") {
exported = sourceExports;
} else if (specifier.type === "ExportSpecifier") {
exported = sourceExports[specifier.local.name];
} else {
throw new Error(`Unknown export type: ${specifier.type}`);
}
const name = specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value;
exports[name] = exported;
}
if (isTSDeclaration(stmt.declaration)) {
const decl = stmt.declaration;
if (_optionalChain([decl, 'access', _8 => _8.id, 'optionalAccess', _9 => _9.type]) === "Identifier") {
const exportedName = decl.id.name;
declarations[exportedName] = exports[exportedName] = await resolveTSReferencedType({
scope,
type: decl
});
}
}
} else if (isTSDeclaration(stmt)) {
if (_optionalChain([stmt, 'access', _10 => _10.id, 'optionalAccess', _11 => _11.type]) !== "Identifier")
continue;
declarations[stmt.id.name] = await resolveTSReferencedType({
scope,
type: stmt
});
} else if (stmt.type === "ImportDeclaration") {
const resolved = await resolveTSFileId(stmt.source.value, file.filePath);
if (!resolved)
continue;
const importScope = await getTSFile(resolved);
await resolveTSNamespace(importScope);
const exports2 = importScope.exports;
for (const specifier of stmt.specifiers) {
const local = specifier.local.name;
let imported;
if (specifier.type === "ImportDefaultSpecifier") {
imported = exports2["default"];
} else if (specifier.type === "ImportNamespaceSpecifier") {
imported = exports2;
} else if (specifier.type === "ImportSpecifier") {
const name = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
imported = exports2[name];
} else {
throw new Error(`Unknown import type: ${specifier.type}`);
}
declarations[local] = imported;
}
}
}
}
// src/utils.ts
function keyToString(key) {
if (typeof key === "string")
return key;
else
return key.value;
}
// src/vue/props.ts
// src/vue/types.ts

@@ -67,3 +650,3 @@ var DefinitionKind = /* @__PURE__ */ ((DefinitionKind2) => {

async function inferRuntimeType(node) {
if (_chunkQOJYKENBjs.isTSNamespace.call(void 0, node))
if (isTSNamespace(node))
return ["Object"];

@@ -132,3 +715,3 @@ switch (node.type.type) {

if (node.type.typeParameters && node.type.typeParameters.params[1]) {
const t = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const t = await resolveTSReferencedType({
scope: node.scope,

@@ -143,3 +726,3 @@ type: node.type.typeParameters.params[1]

if (node.type.typeParameters && node.type.typeParameters.params[0]) {
const t = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const t = await resolveTSReferencedType({
scope: node.scope,

@@ -158,7 +741,7 @@ type: node.type.typeParameters.params[0]

node.type.types.map(async (subType) => {
const resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const resolved = await resolveTSReferencedType({
scope: node.scope,
type: subType
});
return resolved && !_chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved) ? inferRuntimeType(resolved) : void 0;
return resolved && !isTSNamespace(resolved) ? inferRuntimeType(resolved) : void 0;
})

@@ -214,3 +797,3 @@ )).flatMap((t) => t ? t : ["null"]);

handleType(resolved) {
return _optionalChain([resolved, 'access', _ => _.typeParameters, 'optionalAccess', _2 => _2.params, 'access', _3 => _3[0]]);
return _optionalChain([resolved, 'access', _12 => _12.typeParameters, 'optionalAccess', _13 => _13.params, 'access', _14 => _14[0]]);
},

@@ -226,3 +809,3 @@ handleTSProperties(properties) {

handleType(resolved) {
return _optionalChain([resolved, 'access', _4 => _4.typeParameters, 'optionalAccess', _5 => _5.params, 'access', _6 => _6[0]]);
return _optionalChain([resolved, 'access', _15 => _15.typeParameters, 'optionalAccess', _16 => _16.params, 'access', _17 => _17[0]]);
},

@@ -238,3 +821,3 @@ handleTSProperties(properties) {

handleType(resolved) {
return _optionalChain([resolved, 'access', _7 => _7.typeParameters, 'optionalAccess', _8 => _8.params, 'access', _9 => _9[0]]);
return _optionalChain([resolved, 'access', _18 => _18.typeParameters, 'optionalAccess', _19 => _19.params, 'access', _20 => _20[0]]);
}

@@ -340,3 +923,3 @@ }

const removeProp = (name) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
if (!definitions[key])

@@ -386,3 +969,3 @@ return false;

}
const defaultValue = _optionalChain([defaults, 'optionalAccess', _10 => _10[propName]]);
const defaultValue = _optionalChain([defaults, 'optionalAccess', _21 => _21[propName]]);
if (defaultValue) {

@@ -525,7 +1108,7 @@ prop.default = (key = "default") => {

for (const [key, value] of Object.entries(properties.properties)) {
const referenced = value.value ? await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, value.value) : void 0;
const referenced = value.value ? await resolveTSReferencedType(value.value) : void 0;
definitions2[key] = {
type: "property",
addByAPI: false,
value: referenced && !_chunkQOJYKENBjs.isTSNamespace.call(void 0, referenced) ? buildDefinition(referenced) : void 0,
value: referenced && !isTSNamespace(referenced) ? buildDefinition(referenced) : void 0,
optional: value.optional,

@@ -538,5 +1121,5 @@ signature: buildDefinition(value.signature)

async function resolveDefinitions(typeDeclRaw2) {
let resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, typeDeclRaw2) || typeDeclRaw2;
let resolved = await resolveTSReferencedType(typeDeclRaw2) || typeDeclRaw2;
let builtInTypesHandler;
if (resolved && !_chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved) && resolved.type.type === "TSTypeReference" && resolved.type.typeName.type === "Identifier") {
if (resolved && !isTSNamespace(resolved) && resolved.type.type === "TSTypeReference" && resolved.type.typeName.type === "Identifier") {
const typeName = resolved.type.typeName.name;

@@ -549,3 +1132,3 @@ let type;

if (type)
resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
resolved = await resolveTSReferencedType({
type,

@@ -555,3 +1138,3 @@ scope: resolved.scope

}
if (!resolved || _chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved)) {
if (!resolved || isTSNamespace(resolved)) {
throw new SyntaxError(`Cannot resolve TS definition.`);

@@ -568,7 +1151,7 @@ }

);
let properties = await _chunkQOJYKENBjs.resolveTSProperties.call(void 0, {
let properties = await resolveTSProperties({
scope,
type: definitionsAst2
});
if (_optionalChain([builtInTypesHandler, 'optionalAccess', _11 => _11.handleTSProperties]))
if (_optionalChain([builtInTypesHandler, 'optionalAccess', _22 => _22.handleTSProperties]))
properties = builtInTypesHandler.handleTSProperties(properties);

@@ -592,3 +1175,3 @@ return {

function buildNewProp(name, value, optional) {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
const signature = `${name}${optional ? "?" : ""}: ${value}`;

@@ -604,3 +1187,3 @@ const valueAst = _common.babelParse.call(void 0, `type T = (${value})`, "ts").body[0].typeAnnotation.typeAnnotation;

return {
code: _chunkQOJYKENBjs.resolveTSScope.call(void 0, scope).file.content.slice(type.start, type.end),
code: resolveTSScope(scope).file.content.slice(type.start, type.end),
ast: type,

@@ -632,3 +1215,3 @@ scope

const addEmit = (name, signature) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
if (definitionsAst.scope === file) {

@@ -652,3 +1235,3 @@ if (definitionsAst.ast.type === "TSIntersectionType") {

const setEmit = (name, idx, signature) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
const def = definitions[key][idx];

@@ -669,3 +1252,3 @@ if (!def)

const removeEmit = (name, idx) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
const def = definitions[key][idx];

@@ -694,4 +1277,4 @@ if (!def)

async function resolveDefinitions(typeDeclRaw2) {
const resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, typeDeclRaw2);
if (!resolved || _chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved))
const resolved = await resolveTSReferencedType(typeDeclRaw2);
if (!resolved || isTSNamespace(resolved))
throw new SyntaxError(`Cannot resolve TS definition.`);

@@ -703,3 +1286,3 @@ const { type: definitionsAst2, scope } = resolved;

);
const properties = await _chunkQOJYKENBjs.resolveTSProperties.call(void 0, {
const properties = await resolveTSProperties({
scope,

@@ -711,9 +1294,9 @@ type: definitionsAst2

const evtArg = signature.type.parameters[0];
if (!evtArg || evtArg.type !== "Identifier" || _optionalChain([evtArg, 'access', _12 => _12.typeAnnotation, 'optionalAccess', _13 => _13.type]) !== "TSTypeAnnotation")
if (!evtArg || evtArg.type !== "Identifier" || _optionalChain([evtArg, 'access', _23 => _23.typeAnnotation, 'optionalAccess', _24 => _24.type]) !== "TSTypeAnnotation")
continue;
const evtType = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const evtType = await resolveTSReferencedType({
type: evtArg.typeAnnotation.typeAnnotation,
scope: signature.scope
});
if (_chunkQOJYKENBjs.isTSNamespace.call(void 0, evtType) || !_optionalChain([evtType, 'optionalAccess', _14 => _14.type]))
if (isTSNamespace(evtType) || !_optionalChain([evtType, 'optionalAccess', _25 => _25.type]))
continue;

@@ -745,3 +1328,3 @@ const types = evtType.type.type === "TSUnionType" ? evtType.type.types : [evtType.type];

return {
code: _chunkQOJYKENBjs.resolveTSScope.call(void 0, scope).file.content.slice(type.start, type.end),
code: resolveTSScope(scope).file.content.slice(type.start, type.end),
ast: type,

@@ -821,3 +1404,3 @@ scope

return false;
const typeDeclRaw = _optionalChain([defineProps, 'access', _15 => _15.typeParameters, 'optionalAccess', _16 => _16.params, 'access', _17 => _17[0]]);
const typeDeclRaw = _optionalChain([defineProps, 'access', _26 => _26.typeParameters, 'optionalAccess', _27 => _27.params, 'access', _28 => _28[0]]);
if (typeDeclRaw) {

@@ -871,3 +1454,3 @@ props = await handleTSPropsDefinition({

return false;
const typeDeclRaw = _optionalChain([defineEmits, 'access', _18 => _18.typeParameters, 'optionalAccess', _19 => _19.params, 'access', _20 => _20[0]]);
const typeDeclRaw = _optionalChain([defineEmits, 'access', _29 => _29.typeParameters, 'optionalAccess', _30 => _30.params, 'access', _31 => _31[0]]);
if (typeDeclRaw) {

@@ -891,5 +1474,100 @@ emits = await handleTSEmitsDefinition({

// src/resolve.ts
var RollupResolve = () => {
const referencedFiles = /* @__PURE__ */ new Map();
function collectReferencedFile(importer, file) {
if (!importer)
return;
if (!referencedFiles.has(file)) {
referencedFiles.set(file, /* @__PURE__ */ new Set([importer]));
} else {
referencedFiles.get(file).add(importer);
}
}
const resolveCache = /* @__PURE__ */ new Map();
function withResolveCache(id, importer, result) {
if (!resolveCache.has(importer)) {
resolveCache.set(importer, /* @__PURE__ */ new Map([[id, result]]));
return result;
}
resolveCache.get(importer).set(id, result);
return result;
}
const resolve = (ctx) => async (id, importer) => {
async function tryPkgEntry() {
try {
const pkgPath = await _asyncOptionalChain([(await ctx.resolve(`${id}/package.json`, importer)), 'optionalAccess', async _32 => _32.id]);
if (!pkgPath)
return;
const pkg = JSON.parse(await _promises.readFile.call(void 0, pkgPath, "utf-8"));
const types = pkg.types || pkg.typings;
if (!types)
return;
const entry = _path2.default.resolve(pkgPath, "..", types);
return _fs.existsSync.call(void 0, entry) ? entry : void 0;
} catch (e2) {
}
}
const tryResolve = async (id2) => {
try {
return await _asyncOptionalChain([(await ctx.resolve(id2, importer)), 'optionalAccess', async _33 => _33.id]) || await _asyncOptionalChain([(await ctx.resolve(`${id2}.d`, importer)), 'optionalAccess', async _34 => _34.id]);
} catch (e3) {
}
return;
};
const cached = _optionalChain([resolveCache, 'access', _35 => _35.get, 'call', _36 => _36(importer), 'optionalAccess', _37 => _37.get, 'call', _38 => _38(id)]);
if (cached)
return cached;
if (!id.startsWith(".")) {
const entry = await tryPkgEntry();
if (entry)
return withResolveCache(id, importer, entry);
}
let resolved = await tryResolve(id);
if (!resolved)
return;
if (_fs.existsSync.call(void 0, resolved)) {
collectReferencedFile(importer, resolved);
return withResolveCache(id, importer, resolved);
}
resolved = await tryResolve(resolved);
if (resolved && _fs.existsSync.call(void 0, resolved)) {
collectReferencedFile(importer, resolved);
return withResolveCache(id, importer, resolved);
}
};
const handleHotUpdate = ({
file,
server,
modules
}) => {
const cache = /* @__PURE__ */ new Map();
function getAffectedModules(file2) {
if (cache.has(file2))
return cache.get(file2);
if (!referencedFiles.has(file2))
return /* @__PURE__ */ new Set([]);
const modules2 = /* @__PURE__ */ new Set([]);
cache.set(file2, modules2);
for (const importer of referencedFiles.get(file2)) {
const mods = server.moduleGraph.getModulesByFile(importer);
if (mods)
mods.forEach((m) => modules2.add(m));
getAffectedModules(importer).forEach((m) => modules2.add(m));
}
return modules2;
}
if (tsFileCache[file])
delete tsFileCache[file];
const affected = getAffectedModules(file);
return [...modules, ...affected];
};
return {
resolve,
handleHotUpdate
};
};

@@ -930,2 +1608,6 @@

exports.DefinitionKind = DefinitionKind; exports.MagicString = _common.MagicString; exports.RollupResolve = _chunkQOJYKENBjs.RollupResolve; exports.UNKNOWN_TYPE = UNKNOWN_TYPE; exports.analyzeSFC = analyzeSFC; exports.attachNodeLoc = attachNodeLoc; exports.checkForTSProperties = _chunkQOJYKENBjs.checkForTSProperties; exports.createStringLiteral = _chunkQOJYKENBjs.createStringLiteral; exports.createTSLiteralType = _chunkQOJYKENBjs.createTSLiteralType; exports.createUnionType = _chunkQOJYKENBjs.createUnionType; exports.genRuntimePropDefinition = genRuntimePropDefinition; exports.getTSFile = _chunkQOJYKENBjs.getTSFile; exports.getTSPropertiesKeys = _chunkQOJYKENBjs.getTSPropertiesKeys; exports.handleTSEmitsDefinition = handleTSEmitsDefinition; exports.handleTSPropsDefinition = handleTSPropsDefinition; exports.inferRuntimeType = inferRuntimeType; exports.isSupportedForTSReferencedType = _chunkQOJYKENBjs.isSupportedForTSReferencedType; exports.isTSDeclaration = _chunkQOJYKENBjs.isTSDeclaration; exports.isTSNamespace = _chunkQOJYKENBjs.isTSNamespace; exports.keyToString = _chunk5IUQDHHYjs.keyToString; exports.mergeTSProperties = _chunkQOJYKENBjs.mergeTSProperties; exports.namespaceSymbol = _chunkQOJYKENBjs.namespaceSymbol; exports.parseSFC = _common.parseSFC; exports.resolveMaybeTSUnion = _chunkQOJYKENBjs.resolveMaybeTSUnion; exports.resolveReferenceName = _chunkQOJYKENBjs.resolveReferenceName; exports.resolveTSFileId = _chunkQOJYKENBjs.resolveTSFileId; exports.resolveTSFileIdNode = _chunkQOJYKENBjs.resolveTSFileIdNode; exports.resolveTSIndexedAccessType = _chunkQOJYKENBjs.resolveTSIndexedAccessType; exports.resolveTSLiteralType = _chunkQOJYKENBjs.resolveTSLiteralType; exports.resolveTSNamespace = _chunkQOJYKENBjs.resolveTSNamespace; exports.resolveTSProperties = _chunkQOJYKENBjs.resolveTSProperties; exports.resolveTSReferencedType = _chunkQOJYKENBjs.resolveTSReferencedType; exports.resolveTSScope = _chunkQOJYKENBjs.resolveTSScope; exports.resolveTSTemplateLiteral = _chunkQOJYKENBjs.resolveTSTemplateLiteral; exports.resolveTSTypeOperator = _chunkQOJYKENBjs.resolveTSTypeOperator; exports.resolveTypeElements = _chunkQOJYKENBjs.resolveTypeElements; exports.setResolveTSFileIdImpl = _chunkQOJYKENBjs.setResolveTSFileIdImpl; exports.tsFileCache = _chunkQOJYKENBjs.tsFileCache;
exports.DefinitionKind = DefinitionKind; exports.MagicString = _common.MagicString; exports.RollupResolve = RollupResolve; exports.UNKNOWN_TYPE = UNKNOWN_TYPE; exports.analyzeSFC = analyzeSFC; exports.attachNodeLoc = attachNodeLoc; exports.checkForTSProperties = checkForTSProperties; exports.createStringLiteral = createStringLiteral; exports.createTSLiteralType = createTSLiteralType; exports.createUnionType = createUnionType; exports.genRuntimePropDefinition = genRuntimePropDefinition; exports.getTSFile = getTSFile; exports.getTSPropertiesKeys = getTSPropertiesKeys; exports.handleTSEmitsDefinition = handleTSEmitsDefinition; exports.handleTSPropsDefinition = handleTSPropsDefinition; exports.inferRuntimeType = inferRuntimeType; exports.isSupportedForTSReferencedType = isSupportedForTSReferencedType; exports.isTSDeclaration = isTSDeclaration; exports.isTSNamespace = isTSNamespace; exports.keyToString = keyToString; exports.mergeTSProperties = mergeTSProperties; exports.namespaceSymbol = namespaceSymbol; exports.parseSFC = _common.parseSFC; exports.resolveMaybeTSUnion = resolveMaybeTSUnion; exports.resolveReferenceName = resolveReferenceName; exports.resolveTSFileId = resolveTSFileId; exports.resolveTSFileIdNode = resolveTSFileIdNode; exports.resolveTSIndexedAccessType = resolveTSIndexedAccessType; exports.resolveTSLiteralType = resolveTSLiteralType; exports.resolveTSNamespace = resolveTSNamespace; exports.resolveTSProperties = resolveTSProperties; exports.resolveTSReferencedType = resolveTSReferencedType; exports.resolveTSScope = resolveTSScope; exports.resolveTSTemplateLiteral = resolveTSTemplateLiteral; exports.resolveTSTypeOperator = resolveTSTypeOperator; exports.resolveTypeElements = resolveTypeElements; exports.setResolveTSFileIdImpl = setResolveTSFileIdImpl; exports.tsFileCache = tsFileCache;

24

dist/index.d.ts
import { MagicString, SFC } from '@vue-macros/common';
export { MagicString, SFC, parseSFC } from '@vue-macros/common';
import { TSType, TSUnionType, StringLiteral, TSLiteralType, TypeScript, Declaration, Statement, TSModuleBlock, TSParenthesizedType, TSTypeAliasDeclaration, Node, Identifier, TSCallSignatureDeclaration, TSFunctionType, TSConstructSignatureDeclaration, TSMethodSignature, TSPropertySignature, TSMappedType, TSInterfaceDeclaration, TSInterfaceBody, TSTypeLiteral, TSIntersectionType, TSTypeReference, TSEntityName, TemplateLiteral, NumericLiteral, BooleanLiteral, BigIntLiteral, TSTypeElement, TSIndexedAccessType, TSTypeOperator, CallExpression, LVal, VariableDeclaration, ExpressionStatement, ObjectMethod, ObjectProperty, Expression } from '@babel/types';
export { a as ResolveTSFileIdImpl, R as RollupResolve, r as resolveTSFileId, b as resolveTSFileIdNode, s as setResolveTSFileIdImpl } from './resolve-df3aeb53.js';
export { keyToString } from './utils.js';
import 'vite';
import 'rollup';
import * as vite from 'vite';
import { ModuleNode } from 'vite';
import { PluginContext } from 'rollup';

@@ -93,2 +92,10 @@ declare function createUnionType(types: TSType[]): TSUnionType;

type ResolveTSFileIdImpl = (id: string, importer: string) => Promise<string | undefined> | string | undefined;
declare function resolveTSFileId(id: string, importer: string): string | Promise<string | undefined> | undefined;
/**
* @limitation don't node_modules and JavaScript file
*/
declare function resolveTSFileIdNode(id: string, importer: string): string | undefined;
declare function setResolveTSFileIdImpl(impl: ResolveTSFileIdImpl): void;
declare function resolveReferenceName(node: TSTypeReference | Identifier | TSEntityName): Identifier[];

@@ -282,2 +289,9 @@ declare function resolveTSTemplateLiteral({ type, scope, }: TSResolvedType<TemplateLiteral>): Promise<StringLiteral[]>;

export { ASTDefinition, AnalyzeResult, DefaultsASTRaw, DefineEmitsStatement, DefinePropsStatement, DefinitionKind, Emits, EmitsBase, Props, PropsBase, RuntimePropDefinition, TSDeclaration, TSEmits, TSFile, TSModule, TSNamespace, TSProperties, TSProps, TSPropsMethod, TSPropsProperty, TSResolvedType, TSScope, TSScopeBase, UNKNOWN_TYPE, analyzeSFC, attachNodeLoc, checkForTSProperties, createStringLiteral, createTSLiteralType, createUnionType, genRuntimePropDefinition, getTSFile, getTSPropertiesKeys, handleTSEmitsDefinition, handleTSPropsDefinition, inferRuntimeType, isSupportedForTSReferencedType, isTSDeclaration, isTSNamespace, mergeTSProperties, namespaceSymbol, resolveMaybeTSUnion, resolveReferenceName, resolveTSIndexedAccessType, resolveTSLiteralType, resolveTSNamespace, resolveTSProperties, resolveTSReferencedType, resolveTSScope, resolveTSTemplateLiteral, resolveTSTypeOperator, resolveTypeElements, tsFileCache };
declare const RollupResolve: () => {
resolve: (ctx: PluginContext) => ResolveTSFileIdImpl;
handleHotUpdate: (this: void, ctx: vite.HmrContext) => void | ModuleNode[] | Promise<void | ModuleNode[]>;
};
declare function keyToString(key: string | StringLiteral): string;
export { ASTDefinition, AnalyzeResult, DefaultsASTRaw, DefineEmitsStatement, DefinePropsStatement, DefinitionKind, Emits, EmitsBase, Props, PropsBase, ResolveTSFileIdImpl, RollupResolve, RuntimePropDefinition, TSDeclaration, TSEmits, TSFile, TSModule, TSNamespace, TSProperties, TSProps, TSPropsMethod, TSPropsProperty, TSResolvedType, TSScope, TSScopeBase, UNKNOWN_TYPE, analyzeSFC, attachNodeLoc, checkForTSProperties, createStringLiteral, createTSLiteralType, createUnionType, genRuntimePropDefinition, getTSFile, getTSPropertiesKeys, handleTSEmitsDefinition, handleTSPropsDefinition, inferRuntimeType, isSupportedForTSReferencedType, isTSDeclaration, isTSNamespace, keyToString, mergeTSProperties, namespaceSymbol, resolveMaybeTSUnion, resolveReferenceName, resolveTSFileId, resolveTSFileIdNode, resolveTSIndexedAccessType, resolveTSLiteralType, resolveTSNamespace, resolveTSProperties, resolveTSReferencedType, resolveTSScope, resolveTSTemplateLiteral, resolveTSTypeOperator, resolveTypeElements, setResolveTSFileIdImpl, tsFileCache };

@@ -1,3 +0,5 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } async function _asyncOptionalChain(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 = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
var _common = require('@vue-macros/common');
// src/vue/analyze.ts

@@ -11,2 +13,3 @@

// src/vue/props.ts

@@ -18,4 +21,33 @@

// src/ts/create.ts
function createUnionType(types) {
return {
type: "TSUnionType",
types
};
}
function createStringLiteral(value) {
return {
type: "StringLiteral",
value,
extra: {
rawValue: value,
raw: JSON.stringify(value)
}
};
}
function createTSLiteralType(literal) {
return {
type: "TSLiteralType",
literal
};
}
// src/ts/is.ts
var _types = require('@babel/types');
function isTSDeclaration(node) {
return _types.isDeclaration.call(void 0, node) && node.type.startsWith("TS");
}
// src/ts/resolve-reference.ts

@@ -25,32 +57,583 @@

// src/ts/resolve.ts
// src/ts/property.ts
function mergeTSProperties(a, b) {
return {
callSignatures: [...a.callSignatures, ...b.callSignatures],
constructSignatures: [...a.constructSignatures, ...b.constructSignatures],
methods: { ...a.methods, ...b.methods },
properties: { ...a.properties, ...b.properties }
};
}
function checkForTSProperties(node) {
return !!node && [
"TSInterfaceDeclaration",
"TSInterfaceBody",
"TSTypeLiteral",
"TSIntersectionType",
"TSMappedType",
"TSFunctionType"
].includes(node.type);
}
async function resolveTSProperties({
type,
scope
}) {
switch (type.type) {
case "TSInterfaceBody":
return resolveTypeElements(scope, type.body);
case "TSTypeLiteral":
return resolveTypeElements(scope, type.members);
case "TSInterfaceDeclaration": {
let properties = resolveTypeElements(scope, type.body.body);
if (type.extends) {
const resolvedExtends = (await Promise.all(
type.extends.map(
(node) => node.expression.type === "Identifier" ? resolveTSReferencedType({
scope,
type: node.expression
}) : void 0
)
)).filter(filterValidExtends);
if (resolvedExtends.length > 0) {
const ext = (await Promise.all(
resolvedExtends.map((resolved) => resolveTSProperties(resolved))
)).reduceRight((acc, curr) => mergeTSProperties(acc, curr));
properties = mergeTSProperties(ext, properties);
}
}
return properties;
}
case "TSIntersectionType": {
let properties = {
callSignatures: [],
constructSignatures: [],
methods: {},
properties: {}
};
for (const subType of type.types) {
const resolved = await resolveTSReferencedType({
scope,
type: subType
});
if (!filterValidExtends(resolved))
continue;
properties = mergeTSProperties(
properties,
await resolveTSProperties(resolved)
);
}
return properties;
}
case "TSMappedType": {
const properties = {
callSignatures: [],
constructSignatures: [],
methods: {},
properties: {}
};
if (!type.typeParameter.constraint)
return properties;
const constraint = await resolveTSReferencedType({
type: type.typeParameter.constraint,
scope
});
if (!constraint || isTSNamespace(constraint))
return properties;
const types = resolveMaybeTSUnion(constraint.type);
for (const subType of types) {
if (subType.type !== "TSLiteralType")
continue;
const literal = await resolveTSLiteralType({
type: subType,
scope: constraint.scope
});
if (!literal)
continue;
const keys = resolveMaybeTSUnion(literal).map(
(literal2) => String(_common.resolveLiteral.call(void 0, literal2))
);
for (const key of keys) {
properties.properties[String(key)] = {
value: type.typeAnnotation ? { scope, type: type.typeAnnotation } : null,
optional: type.optional === "+" || type.optional === true,
signature: { type, scope }
};
}
}
return properties;
}
case "TSFunctionType": {
const properties = {
callSignatures: [{ type, scope }],
constructSignatures: [],
methods: {},
properties: {}
};
return properties;
}
default:
throw new Error(`unknown node: ${_optionalChain([type, 'optionalAccess', _ => _.type])}`);
}
function filterValidExtends(node) {
return !isTSNamespace(node) && checkForTSProperties(_optionalChain([node, 'optionalAccess', _2 => _2.type]));
}
}
function getTSPropertiesKeys(properties) {
return [
.../* @__PURE__ */ new Set([
...Object.keys(properties.properties),
...Object.keys(properties.methods)
])
];
}
// src/ts/resolve.ts
function resolveReferenceName(node) {
if (node.type === "TSTypeReference") {
return resolveReferenceName(node.typeName);
} else if (node.type === "Identifier")
return [node];
else {
return [...resolveReferenceName(node.left), node.right];
}
}
async function resolveTSTemplateLiteral({
type,
scope
}) {
const types = (await resolveKeys("", type.quasis, type.expressions)).map(
(k) => createStringLiteral(k)
);
return types;
async function resolveKeys(prefix, quasis, expressions) {
if (expressions.length === 0) {
return [prefix + (_nullishCoalesce(_optionalChain([quasis, 'access', _3 => _3[0], 'optionalAccess', _4 => _4.value, 'access', _5 => _5.cooked]), () => ( "")))];
}
const [expr, ...restExpr] = expressions;
const [quasi, ...restQuasis] = quasis;
const subTypes = resolveMaybeTSUnion(expr);
const keys = [];
for (const type2 of subTypes) {
if (!isSupportedForTSReferencedType(type2))
continue;
const resolved = await resolveTSReferencedType({
type: type2,
scope
});
if (!resolved || isTSNamespace(resolved))
continue;
const types2 = resolveMaybeTSUnion(resolved.type);
for (const type3 of types2) {
if (type3.type !== "TSLiteralType")
continue;
const literal = await resolveTSLiteralType({ type: type3, scope });
if (!literal)
continue;
const subKeys = resolveMaybeTSUnion(literal).map(
(literal2) => String(_common.resolveLiteral.call(void 0, literal2))
);
for (const key of subKeys) {
const newPrefix = prefix + quasi.value.cooked + String(key);
keys.push(...await resolveKeys(newPrefix, restQuasis, restExpr));
}
}
}
return keys;
}
}
async function resolveTSLiteralType({
type,
scope
}) {
if (type.literal.type === "UnaryExpression")
return;
if (type.literal.type === "TemplateLiteral") {
const types = await resolveTSTemplateLiteral({ type: type.literal, scope });
return types;
}
return type.literal;
}
function resolveTypeElements(scope, elements) {
const properties = {
callSignatures: [],
constructSignatures: [],
methods: {},
properties: {}
};
const tryGetKey = (element) => {
try {
return _common.resolveObjectKey.call(void 0, element.key, element.computed, false);
} catch (e) {
}
};
for (const element of elements) {
switch (element.type) {
case "TSCallSignatureDeclaration":
properties.callSignatures.push({ scope, type: element });
break;
case "TSConstructSignatureDeclaration":
properties.constructSignatures.push({ scope, type: element });
break;
case "TSMethodSignature": {
const key = tryGetKey(element);
if (!key)
continue;
if (properties.properties[key])
continue;
if (!properties.methods[key])
properties.methods[key] = [];
if (element.typeAnnotation) {
properties.methods[key].push({ scope, type: element });
}
break;
}
case "TSPropertySignature": {
const key = tryGetKey(element);
if (!key)
continue;
if (!properties.properties[key] && !properties.methods[key]) {
const type = _optionalChain([element, 'access', _6 => _6.typeAnnotation, 'optionalAccess', _7 => _7.typeAnnotation]);
properties.properties[key] = {
value: type ? { type, scope } : null,
optional: !!element.optional,
signature: { type: element, scope }
};
}
break;
}
case "TSIndexSignature":
break;
}
}
return properties;
}
async function resolveTSIndexedAccessType({ scope, type }, stacks = []) {
const object = await resolveTSReferencedType(
{ type: type.objectType, scope },
stacks
);
if (!object || isTSNamespace(object))
return void 0;
const objectType = object.type;
if (type.indexType.type === "TSNumberKeyword") {
let types;
if (objectType.type === "TSArrayType") {
types = [objectType.elementType];
} else if (objectType.type === "TSTupleType") {
types = objectType.elementTypes.map(
(t) => t.type === "TSNamedTupleMember" ? t.elementType : t
);
} else if (objectType.type === "TSTypeReference" && objectType.typeName.type === "Identifier" && objectType.typeName.name === "Array" && objectType.typeParameters) {
types = objectType.typeParameters.params;
} else {
return void 0;
}
return { type: createUnionType(types), scope };
} else if (objectType.type !== "TSInterfaceDeclaration" && objectType.type !== "TSTypeLiteral" && objectType.type !== "TSIntersectionType" && objectType.type !== "TSMappedType" && objectType.type !== "TSFunctionType")
return void 0;
const properties = await resolveTSProperties({
type: objectType,
scope: object.scope
});
const indexTypes = resolveMaybeTSUnion(type.indexType);
const indexes = [];
let optional = false;
for (const index of indexTypes) {
let keys;
if (index.type === "TSLiteralType") {
const literal = await resolveTSLiteralType({
type: index,
scope: object.scope
});
if (!literal)
continue;
keys = resolveMaybeTSUnion(literal).map(
(literal2) => String(_common.resolveLiteral.call(void 0, literal2))
);
} else if (index.type === "TSTypeOperator") {
const keysStrings = await resolveTSTypeOperator({
type: index,
scope: object.scope
});
if (!keysStrings)
continue;
keys = resolveMaybeTSUnion(keysStrings).map(
(literal) => String(_common.resolveLiteral.call(void 0, literal))
);
} else
continue;
for (const key of keys) {
const property = properties.properties[key];
if (property) {
optional ||= property.optional;
const propertyType = properties.properties[key].value;
if (propertyType)
indexes.push(propertyType.type);
}
const methods = properties.methods[key];
if (methods) {
optional ||= methods.some((m) => !!m.type.optional);
indexes.push(
...methods.map(
({ type: type2 }) => ({
...type2,
type: "TSFunctionType"
})
)
);
}
}
}
if (indexes.length === 0)
return void 0;
if (optional)
indexes.push({ type: "TSUndefinedKeyword" });
return { type: createUnionType(indexes), scope };
}
async function resolveTSTypeOperator({ scope, type }, stacks = []) {
if (type.operator !== "keyof")
return void 0;
const resolved = await resolveTSReferencedType(
{
type: type.typeAnnotation,
scope
},
stacks
);
if (!resolved || isTSNamespace(resolved))
return void 0;
const { type: resolvedType, scope: resolvedScope } = resolved;
if (!checkForTSProperties(resolvedType))
return void 0;
const properties = await resolveTSProperties({
type: resolvedType,
scope: resolvedScope
});
return getTSPropertiesKeys(properties).map((k) => createStringLiteral(k));
}
function resolveMaybeTSUnion(node) {
if (Array.isArray(node))
return node;
if (node.type === "TSUnionType")
return node.types.flatMap((t) => resolveMaybeTSUnion(t));
return [node];
}
// src/ts/scope.ts
var _promises = require('fs/promises');
var _chunkQOJYKENBjs = require('./chunk-QOJYKENB.js');
var _chunk5IUQDHHYjs = require('./chunk-5IUQDHHY.js');
// src/index.ts
var _common = require('@vue-macros/common');
// src/vue/analyze.ts
var tsFileCache = {};
async function getTSFile(filePath) {
if (tsFileCache[filePath])
return tsFileCache[filePath];
const content = await _promises.readFile.call(void 0, filePath, "utf-8");
const { code, lang } = _common.getFileCodeAndLang.call(void 0, content, filePath);
return tsFileCache[filePath] = {
kind: "file",
filePath,
content,
ast: _common.REGEX_SUPPORTED_EXT.test(filePath) ? _common.babelParse.call(void 0, code, lang).body : void 0
};
}
function resolveTSScope(scope) {
const isFile = scope.kind === "file";
let parentScope;
if (!isFile)
parentScope = resolveTSScope(scope.scope);
const file = isFile ? scope : parentScope.file;
const body = isFile ? scope.ast : scope.ast.body;
const exports = scope.exports;
const declarations = isFile ? scope.declarations : { ...resolveTSScope(scope.scope).declarations, ...scope.declarations };
return {
isFile,
file,
body,
declarations,
exports
};
}
// src/ts/resolve-reference.ts
function isSupportedForTSReferencedType(node) {
return _types.isTSType.call(void 0, node) || node.type === "Identifier" || isTSDeclaration(node);
}
async function resolveTSReferencedType(ref, stacks = []) {
const { scope, type } = ref;
if (stacks.some((stack) => stack.scope === scope && stack.type === type)) {
return ref;
}
stacks.push(ref);
switch (type.type) {
case "TSTypeAliasDeclaration":
case "TSParenthesizedType":
return resolveTSReferencedType(
{ scope, type: type.typeAnnotation },
stacks
);
case "TSIndexedAccessType":
return resolveTSIndexedAccessType({ type, scope }, stacks);
case "TSModuleDeclaration": {
if (type.body.type === "TSModuleBlock") {
const newScope = {
kind: "module",
ast: type.body,
scope
};
await resolveTSNamespace(newScope);
return newScope.exports;
}
return void 0;
}
}
if (type.type !== "Identifier" && type.type !== "TSTypeReference")
return { scope, type };
await resolveTSNamespace(scope);
const refNames = resolveReferenceName(type).map((id) => id.name);
let resolved = resolveTSScope(scope).declarations;
for (const name of refNames) {
if (isTSNamespace(resolved) && resolved[name]) {
resolved = resolved[name];
} else if (type.type === "TSTypeReference") {
return { type, scope };
}
}
return resolved;
}
// src/ts/resolve-file.ts
var _fs = require('fs');
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
var resolveTSFileIdImpl = resolveTSFileIdNode;
function resolveTSFileId(id, importer) {
return resolveTSFileIdImpl(id, importer);
}
function resolveTSFileIdNode(id, importer) {
function tryResolve(id2, importer2) {
const filePath = _path2.default.resolve(importer2, "..", id2);
if (!_fs.existsSync.call(void 0, filePath))
return;
return filePath;
}
return tryResolve(id, importer) || tryResolve(`${id}.ts`, importer) || tryResolve(`${id}.d.ts`, importer) || tryResolve(`${id}/index`, importer) || tryResolve(`${id}/index.ts`, importer) || tryResolve(`${id}/index.d.ts`, importer);
}
function setResolveTSFileIdImpl(impl) {
resolveTSFileIdImpl = impl;
}
// src/ts/namespace.ts
var namespaceSymbol = Symbol("namespace");
function isTSNamespace(val) {
return !!val && typeof val === "object" && namespaceSymbol in val;
}
async function resolveTSNamespace(scope) {
if (scope.exports)
return;
const exports = {
[namespaceSymbol]: true
};
scope.exports = exports;
const declarations = {
[namespaceSymbol]: true,
...scope.declarations
};
scope.declarations = declarations;
const { body, file } = resolveTSScope(scope);
for (const stmt of body || []) {
if (stmt.type === "ExportDefaultDeclaration" && isTSDeclaration(stmt.declaration)) {
exports["default"] = await resolveTSReferencedType({
scope,
type: stmt.declaration
});
} else if (stmt.type === "ExportAllDeclaration") {
const resolved = await resolveTSFileId(stmt.source.value, file.filePath);
if (!resolved)
continue;
const sourceScope = await getTSFile(resolved);
await resolveTSNamespace(sourceScope);
Object.assign(exports, sourceScope.exports);
} else if (stmt.type === "ExportNamedDeclaration") {
let sourceExports;
if (stmt.source) {
const resolved = await resolveTSFileId(stmt.source.value, file.filePath);
if (!resolved)
continue;
const scope2 = await getTSFile(resolved);
await resolveTSNamespace(scope2);
sourceExports = scope2.exports;
} else {
sourceExports = declarations;
}
for (const specifier of stmt.specifiers) {
let exported;
if (specifier.type === "ExportDefaultSpecifier") {
exported = sourceExports["default"];
} else if (specifier.type === "ExportNamespaceSpecifier") {
exported = sourceExports;
} else if (specifier.type === "ExportSpecifier") {
exported = sourceExports[specifier.local.name];
} else {
throw new Error(`Unknown export type: ${specifier.type}`);
}
const name = specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value;
exports[name] = exported;
}
if (isTSDeclaration(stmt.declaration)) {
const decl = stmt.declaration;
if (_optionalChain([decl, 'access', _8 => _8.id, 'optionalAccess', _9 => _9.type]) === "Identifier") {
const exportedName = decl.id.name;
declarations[exportedName] = exports[exportedName] = await resolveTSReferencedType({
scope,
type: decl
});
}
}
} else if (isTSDeclaration(stmt)) {
if (_optionalChain([stmt, 'access', _10 => _10.id, 'optionalAccess', _11 => _11.type]) !== "Identifier")
continue;
declarations[stmt.id.name] = await resolveTSReferencedType({
scope,
type: stmt
});
} else if (stmt.type === "ImportDeclaration") {
const resolved = await resolveTSFileId(stmt.source.value, file.filePath);
if (!resolved)
continue;
const importScope = await getTSFile(resolved);
await resolveTSNamespace(importScope);
const exports2 = importScope.exports;
for (const specifier of stmt.specifiers) {
const local = specifier.local.name;
let imported;
if (specifier.type === "ImportDefaultSpecifier") {
imported = exports2["default"];
} else if (specifier.type === "ImportNamespaceSpecifier") {
imported = exports2;
} else if (specifier.type === "ImportSpecifier") {
const name = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
imported = exports2[name];
} else {
throw new Error(`Unknown import type: ${specifier.type}`);
}
declarations[local] = imported;
}
}
}
}
// src/utils.ts
function keyToString(key) {
if (typeof key === "string")
return key;
else
return key.value;
}
// src/vue/props.ts
// src/vue/types.ts

@@ -67,3 +650,3 @@ var DefinitionKind = /* @__PURE__ */ ((DefinitionKind2) => {

async function inferRuntimeType(node) {
if (_chunkQOJYKENBjs.isTSNamespace.call(void 0, node))
if (isTSNamespace(node))
return ["Object"];

@@ -132,3 +715,3 @@ switch (node.type.type) {

if (node.type.typeParameters && node.type.typeParameters.params[1]) {
const t = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const t = await resolveTSReferencedType({
scope: node.scope,

@@ -143,3 +726,3 @@ type: node.type.typeParameters.params[1]

if (node.type.typeParameters && node.type.typeParameters.params[0]) {
const t = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const t = await resolveTSReferencedType({
scope: node.scope,

@@ -158,7 +741,7 @@ type: node.type.typeParameters.params[0]

node.type.types.map(async (subType) => {
const resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const resolved = await resolveTSReferencedType({
scope: node.scope,
type: subType
});
return resolved && !_chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved) ? inferRuntimeType(resolved) : void 0;
return resolved && !isTSNamespace(resolved) ? inferRuntimeType(resolved) : void 0;
})

@@ -214,3 +797,3 @@ )).flatMap((t) => t ? t : ["null"]);

handleType(resolved) {
return _optionalChain([resolved, 'access', _ => _.typeParameters, 'optionalAccess', _2 => _2.params, 'access', _3 => _3[0]]);
return _optionalChain([resolved, 'access', _12 => _12.typeParameters, 'optionalAccess', _13 => _13.params, 'access', _14 => _14[0]]);
},

@@ -226,3 +809,3 @@ handleTSProperties(properties) {

handleType(resolved) {
return _optionalChain([resolved, 'access', _4 => _4.typeParameters, 'optionalAccess', _5 => _5.params, 'access', _6 => _6[0]]);
return _optionalChain([resolved, 'access', _15 => _15.typeParameters, 'optionalAccess', _16 => _16.params, 'access', _17 => _17[0]]);
},

@@ -238,3 +821,3 @@ handleTSProperties(properties) {

handleType(resolved) {
return _optionalChain([resolved, 'access', _7 => _7.typeParameters, 'optionalAccess', _8 => _8.params, 'access', _9 => _9[0]]);
return _optionalChain([resolved, 'access', _18 => _18.typeParameters, 'optionalAccess', _19 => _19.params, 'access', _20 => _20[0]]);
}

@@ -340,3 +923,3 @@ }

const removeProp = (name) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
if (!definitions[key])

@@ -386,3 +969,3 @@ return false;

}
const defaultValue = _optionalChain([defaults, 'optionalAccess', _10 => _10[propName]]);
const defaultValue = _optionalChain([defaults, 'optionalAccess', _21 => _21[propName]]);
if (defaultValue) {

@@ -525,7 +1108,7 @@ prop.default = (key = "default") => {

for (const [key, value] of Object.entries(properties.properties)) {
const referenced = value.value ? await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, value.value) : void 0;
const referenced = value.value ? await resolveTSReferencedType(value.value) : void 0;
definitions2[key] = {
type: "property",
addByAPI: false,
value: referenced && !_chunkQOJYKENBjs.isTSNamespace.call(void 0, referenced) ? buildDefinition(referenced) : void 0,
value: referenced && !isTSNamespace(referenced) ? buildDefinition(referenced) : void 0,
optional: value.optional,

@@ -538,5 +1121,5 @@ signature: buildDefinition(value.signature)

async function resolveDefinitions(typeDeclRaw2) {
let resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, typeDeclRaw2) || typeDeclRaw2;
let resolved = await resolveTSReferencedType(typeDeclRaw2) || typeDeclRaw2;
let builtInTypesHandler;
if (resolved && !_chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved) && resolved.type.type === "TSTypeReference" && resolved.type.typeName.type === "Identifier") {
if (resolved && !isTSNamespace(resolved) && resolved.type.type === "TSTypeReference" && resolved.type.typeName.type === "Identifier") {
const typeName = resolved.type.typeName.name;

@@ -549,3 +1132,3 @@ let type;

if (type)
resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
resolved = await resolveTSReferencedType({
type,

@@ -555,3 +1138,3 @@ scope: resolved.scope

}
if (!resolved || _chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved)) {
if (!resolved || isTSNamespace(resolved)) {
throw new SyntaxError(`Cannot resolve TS definition.`);

@@ -568,7 +1151,7 @@ }

);
let properties = await _chunkQOJYKENBjs.resolveTSProperties.call(void 0, {
let properties = await resolveTSProperties({
scope,
type: definitionsAst2
});
if (_optionalChain([builtInTypesHandler, 'optionalAccess', _11 => _11.handleTSProperties]))
if (_optionalChain([builtInTypesHandler, 'optionalAccess', _22 => _22.handleTSProperties]))
properties = builtInTypesHandler.handleTSProperties(properties);

@@ -592,3 +1175,3 @@ return {

function buildNewProp(name, value, optional) {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
const signature = `${name}${optional ? "?" : ""}: ${value}`;

@@ -604,3 +1187,3 @@ const valueAst = _common.babelParse.call(void 0, `type T = (${value})`, "ts").body[0].typeAnnotation.typeAnnotation;

return {
code: _chunkQOJYKENBjs.resolveTSScope.call(void 0, scope).file.content.slice(type.start, type.end),
code: resolveTSScope(scope).file.content.slice(type.start, type.end),
ast: type,

@@ -632,3 +1215,3 @@ scope

const addEmit = (name, signature) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
if (definitionsAst.scope === file) {

@@ -652,3 +1235,3 @@ if (definitionsAst.ast.type === "TSIntersectionType") {

const setEmit = (name, idx, signature) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
const def = definitions[key][idx];

@@ -669,3 +1252,3 @@ if (!def)

const removeEmit = (name, idx) => {
const key = _chunk5IUQDHHYjs.keyToString.call(void 0, name);
const key = keyToString(name);
const def = definitions[key][idx];

@@ -694,4 +1277,4 @@ if (!def)

async function resolveDefinitions(typeDeclRaw2) {
const resolved = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, typeDeclRaw2);
if (!resolved || _chunkQOJYKENBjs.isTSNamespace.call(void 0, resolved))
const resolved = await resolveTSReferencedType(typeDeclRaw2);
if (!resolved || isTSNamespace(resolved))
throw new SyntaxError(`Cannot resolve TS definition.`);

@@ -703,3 +1286,3 @@ const { type: definitionsAst2, scope } = resolved;

);
const properties = await _chunkQOJYKENBjs.resolveTSProperties.call(void 0, {
const properties = await resolveTSProperties({
scope,

@@ -711,9 +1294,9 @@ type: definitionsAst2

const evtArg = signature.type.parameters[0];
if (!evtArg || evtArg.type !== "Identifier" || _optionalChain([evtArg, 'access', _12 => _12.typeAnnotation, 'optionalAccess', _13 => _13.type]) !== "TSTypeAnnotation")
if (!evtArg || evtArg.type !== "Identifier" || _optionalChain([evtArg, 'access', _23 => _23.typeAnnotation, 'optionalAccess', _24 => _24.type]) !== "TSTypeAnnotation")
continue;
const evtType = await _chunkQOJYKENBjs.resolveTSReferencedType.call(void 0, {
const evtType = await resolveTSReferencedType({
type: evtArg.typeAnnotation.typeAnnotation,
scope: signature.scope
});
if (_chunkQOJYKENBjs.isTSNamespace.call(void 0, evtType) || !_optionalChain([evtType, 'optionalAccess', _14 => _14.type]))
if (isTSNamespace(evtType) || !_optionalChain([evtType, 'optionalAccess', _25 => _25.type]))
continue;

@@ -745,3 +1328,3 @@ const types = evtType.type.type === "TSUnionType" ? evtType.type.types : [evtType.type];

return {
code: _chunkQOJYKENBjs.resolveTSScope.call(void 0, scope).file.content.slice(type.start, type.end),
code: resolveTSScope(scope).file.content.slice(type.start, type.end),
ast: type,

@@ -821,3 +1404,3 @@ scope

return false;
const typeDeclRaw = _optionalChain([defineProps, 'access', _15 => _15.typeParameters, 'optionalAccess', _16 => _16.params, 'access', _17 => _17[0]]);
const typeDeclRaw = _optionalChain([defineProps, 'access', _26 => _26.typeParameters, 'optionalAccess', _27 => _27.params, 'access', _28 => _28[0]]);
if (typeDeclRaw) {

@@ -871,3 +1454,3 @@ props = await handleTSPropsDefinition({

return false;
const typeDeclRaw = _optionalChain([defineEmits, 'access', _18 => _18.typeParameters, 'optionalAccess', _19 => _19.params, 'access', _20 => _20[0]]);
const typeDeclRaw = _optionalChain([defineEmits, 'access', _29 => _29.typeParameters, 'optionalAccess', _30 => _30.params, 'access', _31 => _31[0]]);
if (typeDeclRaw) {

@@ -891,5 +1474,100 @@ emits = await handleTSEmitsDefinition({

// src/resolve.ts
var RollupResolve = () => {
const referencedFiles = /* @__PURE__ */ new Map();
function collectReferencedFile(importer, file) {
if (!importer)
return;
if (!referencedFiles.has(file)) {
referencedFiles.set(file, /* @__PURE__ */ new Set([importer]));
} else {
referencedFiles.get(file).add(importer);
}
}
const resolveCache = /* @__PURE__ */ new Map();
function withResolveCache(id, importer, result) {
if (!resolveCache.has(importer)) {
resolveCache.set(importer, /* @__PURE__ */ new Map([[id, result]]));
return result;
}
resolveCache.get(importer).set(id, result);
return result;
}
const resolve = (ctx) => async (id, importer) => {
async function tryPkgEntry() {
try {
const pkgPath = await _asyncOptionalChain([(await ctx.resolve(`${id}/package.json`, importer)), 'optionalAccess', async _32 => _32.id]);
if (!pkgPath)
return;
const pkg = JSON.parse(await _promises.readFile.call(void 0, pkgPath, "utf-8"));
const types = pkg.types || pkg.typings;
if (!types)
return;
const entry = _path2.default.resolve(pkgPath, "..", types);
return _fs.existsSync.call(void 0, entry) ? entry : void 0;
} catch (e2) {
}
}
const tryResolve = async (id2) => {
try {
return await _asyncOptionalChain([(await ctx.resolve(id2, importer)), 'optionalAccess', async _33 => _33.id]) || await _asyncOptionalChain([(await ctx.resolve(`${id2}.d`, importer)), 'optionalAccess', async _34 => _34.id]);
} catch (e3) {
}
return;
};
const cached = _optionalChain([resolveCache, 'access', _35 => _35.get, 'call', _36 => _36(importer), 'optionalAccess', _37 => _37.get, 'call', _38 => _38(id)]);
if (cached)
return cached;
if (!id.startsWith(".")) {
const entry = await tryPkgEntry();
if (entry)
return withResolveCache(id, importer, entry);
}
let resolved = await tryResolve(id);
if (!resolved)
return;
if (_fs.existsSync.call(void 0, resolved)) {
collectReferencedFile(importer, resolved);
return withResolveCache(id, importer, resolved);
}
resolved = await tryResolve(resolved);
if (resolved && _fs.existsSync.call(void 0, resolved)) {
collectReferencedFile(importer, resolved);
return withResolveCache(id, importer, resolved);
}
};
const handleHotUpdate = ({
file,
server,
modules
}) => {
const cache = /* @__PURE__ */ new Map();
function getAffectedModules(file2) {
if (cache.has(file2))
return cache.get(file2);
if (!referencedFiles.has(file2))
return /* @__PURE__ */ new Set([]);
const modules2 = /* @__PURE__ */ new Set([]);
cache.set(file2, modules2);
for (const importer of referencedFiles.get(file2)) {
const mods = server.moduleGraph.getModulesByFile(importer);
if (mods)
mods.forEach((m) => modules2.add(m));
getAffectedModules(importer).forEach((m) => modules2.add(m));
}
return modules2;
}
if (tsFileCache[file])
delete tsFileCache[file];
const affected = getAffectedModules(file);
return [...modules, ...affected];
};
return {
resolve,
handleHotUpdate
};
};

@@ -930,2 +1608,6 @@

exports.DefinitionKind = DefinitionKind; exports.MagicString = _common.MagicString; exports.RollupResolve = _chunkQOJYKENBjs.RollupResolve; exports.UNKNOWN_TYPE = UNKNOWN_TYPE; exports.analyzeSFC = analyzeSFC; exports.attachNodeLoc = attachNodeLoc; exports.checkForTSProperties = _chunkQOJYKENBjs.checkForTSProperties; exports.createStringLiteral = _chunkQOJYKENBjs.createStringLiteral; exports.createTSLiteralType = _chunkQOJYKENBjs.createTSLiteralType; exports.createUnionType = _chunkQOJYKENBjs.createUnionType; exports.genRuntimePropDefinition = genRuntimePropDefinition; exports.getTSFile = _chunkQOJYKENBjs.getTSFile; exports.getTSPropertiesKeys = _chunkQOJYKENBjs.getTSPropertiesKeys; exports.handleTSEmitsDefinition = handleTSEmitsDefinition; exports.handleTSPropsDefinition = handleTSPropsDefinition; exports.inferRuntimeType = inferRuntimeType; exports.isSupportedForTSReferencedType = _chunkQOJYKENBjs.isSupportedForTSReferencedType; exports.isTSDeclaration = _chunkQOJYKENBjs.isTSDeclaration; exports.isTSNamespace = _chunkQOJYKENBjs.isTSNamespace; exports.keyToString = _chunk5IUQDHHYjs.keyToString; exports.mergeTSProperties = _chunkQOJYKENBjs.mergeTSProperties; exports.namespaceSymbol = _chunkQOJYKENBjs.namespaceSymbol; exports.parseSFC = _common.parseSFC; exports.resolveMaybeTSUnion = _chunkQOJYKENBjs.resolveMaybeTSUnion; exports.resolveReferenceName = _chunkQOJYKENBjs.resolveReferenceName; exports.resolveTSFileId = _chunkQOJYKENBjs.resolveTSFileId; exports.resolveTSFileIdNode = _chunkQOJYKENBjs.resolveTSFileIdNode; exports.resolveTSIndexedAccessType = _chunkQOJYKENBjs.resolveTSIndexedAccessType; exports.resolveTSLiteralType = _chunkQOJYKENBjs.resolveTSLiteralType; exports.resolveTSNamespace = _chunkQOJYKENBjs.resolveTSNamespace; exports.resolveTSProperties = _chunkQOJYKENBjs.resolveTSProperties; exports.resolveTSReferencedType = _chunkQOJYKENBjs.resolveTSReferencedType; exports.resolveTSScope = _chunkQOJYKENBjs.resolveTSScope; exports.resolveTSTemplateLiteral = _chunkQOJYKENBjs.resolveTSTemplateLiteral; exports.resolveTSTypeOperator = _chunkQOJYKENBjs.resolveTSTypeOperator; exports.resolveTypeElements = _chunkQOJYKENBjs.resolveTypeElements; exports.setResolveTSFileIdImpl = _chunkQOJYKENBjs.setResolveTSFileIdImpl; exports.tsFileCache = _chunkQOJYKENBjs.tsFileCache;
exports.DefinitionKind = DefinitionKind; exports.MagicString = _common.MagicString; exports.RollupResolve = RollupResolve; exports.UNKNOWN_TYPE = UNKNOWN_TYPE; exports.analyzeSFC = analyzeSFC; exports.attachNodeLoc = attachNodeLoc; exports.checkForTSProperties = checkForTSProperties; exports.createStringLiteral = createStringLiteral; exports.createTSLiteralType = createTSLiteralType; exports.createUnionType = createUnionType; exports.genRuntimePropDefinition = genRuntimePropDefinition; exports.getTSFile = getTSFile; exports.getTSPropertiesKeys = getTSPropertiesKeys; exports.handleTSEmitsDefinition = handleTSEmitsDefinition; exports.handleTSPropsDefinition = handleTSPropsDefinition; exports.inferRuntimeType = inferRuntimeType; exports.isSupportedForTSReferencedType = isSupportedForTSReferencedType; exports.isTSDeclaration = isTSDeclaration; exports.isTSNamespace = isTSNamespace; exports.keyToString = keyToString; exports.mergeTSProperties = mergeTSProperties; exports.namespaceSymbol = namespaceSymbol; exports.parseSFC = _common.parseSFC; exports.resolveMaybeTSUnion = resolveMaybeTSUnion; exports.resolveReferenceName = resolveReferenceName; exports.resolveTSFileId = resolveTSFileId; exports.resolveTSFileIdNode = resolveTSFileIdNode; exports.resolveTSIndexedAccessType = resolveTSIndexedAccessType; exports.resolveTSLiteralType = resolveTSLiteralType; exports.resolveTSNamespace = resolveTSNamespace; exports.resolveTSProperties = resolveTSProperties; exports.resolveTSReferencedType = resolveTSReferencedType; exports.resolveTSScope = resolveTSScope; exports.resolveTSTemplateLiteral = resolveTSTemplateLiteral; exports.resolveTSTypeOperator = resolveTSTypeOperator; exports.resolveTypeElements = resolveTypeElements; exports.setResolveTSFileIdImpl = setResolveTSFileIdImpl; exports.tsFileCache = tsFileCache;
{
"name": "@vue-macros/api",
"version": "0.7.2",
"packageManager": "pnpm@8.6.0",
"version": "0.7.3",
"packageManager": "pnpm@8.6.5",
"description": "General API for Vue Macros.",

@@ -35,14 +35,20 @@ "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"
]
},
"dependencies": {
"@babel/types": "^7.22.4",
"@vue-macros/common": "~1.4.0"
"@babel/types": "^7.22.5",
"@vue-macros/common": "1.4.1"
},
"devDependencies": {
"rollup": "^3.23.1"
"rollup": "^3.26.2"
},

@@ -49,0 +55,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