ast-kit
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -39,2 +39,3 @@ "use strict"; | ||
babelParse: () => babelParse, | ||
escapeKey: () => escapeKey, | ||
getLang: () => getLang, | ||
@@ -96,2 +97,3 @@ isCallOf: () => isCallOf, | ||
// src/utils.ts | ||
var import_parser2 = require("@babel/parser"); | ||
function isTypeOf(node, types) { | ||
@@ -136,6 +138,19 @@ return types.some((type) => { | ||
} | ||
function escapeKey(rawKey) { | ||
if (String(+rawKey) === rawKey) | ||
return rawKey; | ||
try { | ||
const node = (0, import_parser2.parseExpression)(`({${rawKey}: 1})`); | ||
if (node.properties[0].key.type === "Identifier") | ||
return rawKey; | ||
} catch { | ||
} | ||
return JSON.stringify(rawKey); | ||
} | ||
// src/resolve.ts | ||
function resolveString(node, computed = false) { | ||
if (node.type === "Identifier") { | ||
if (typeof node === "string") | ||
return node; | ||
else if (node.type === "Identifier") { | ||
if (computed) | ||
@@ -380,24 +395,1 @@ throw new TypeError("Invalid Identifier"); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
REGEX_DTS, | ||
REGEX_LANG_JSX, | ||
REGEX_LANG_TS, | ||
TS_NODE_TYPES, | ||
attachScopes, | ||
babelParse, | ||
getLang, | ||
isCallOf, | ||
isDts, | ||
isFunctionType, | ||
isLiteralType, | ||
isTs, | ||
isTypeOf, | ||
resolveIdentifier, | ||
resolveLiteral, | ||
resolveString, | ||
resolveTemplateLiteral, | ||
unwrapTSNode, | ||
walkAST, | ||
walkImportDeclaration | ||
}); |
@@ -15,3 +15,3 @@ import { ParserOptions } from '@babel/parser'; | ||
declare function resolveString(node: Identifier | Literal | PrivateName | ThisExpression | Super, computed?: boolean): string; | ||
declare function resolveString(node: string | Identifier | Literal | PrivateName | ThisExpression | Super, computed?: boolean): string; | ||
declare function resolveLiteral(node: Literal): string | number | boolean | null | RegExp | bigint; | ||
@@ -37,2 +37,3 @@ declare function resolveTemplateLiteral(node: TemplateLiteral): string; | ||
declare function unwrapTSNode(node: Node): Node; | ||
declare function escapeKey(rawKey: string): string; | ||
@@ -59,2 +60,2 @@ declare const walkAST: <T = Node>(node: T, hooks: { | ||
export { GetNode, ImportBinding, REGEX_DTS, REGEX_LANG_JSX, REGEX_LANG_TS, TS_NODE_TYPES, WithScope, attachScopes, babelParse, getLang, isCallOf, isDts, isFunctionType, isLiteralType, isTs, isTypeOf, resolveIdentifier, resolveLiteral, resolveString, resolveTemplateLiteral, unwrapTSNode, walkAST, walkImportDeclaration }; | ||
export { GetNode, ImportBinding, REGEX_DTS, REGEX_LANG_JSX, REGEX_LANG_TS, TS_NODE_TYPES, WithScope, attachScopes, babelParse, escapeKey, getLang, isCallOf, isDts, isFunctionType, isLiteralType, isTs, isTypeOf, resolveIdentifier, resolveLiteral, resolveString, resolveTemplateLiteral, unwrapTSNode, walkAST, walkImportDeclaration }; |
@@ -39,2 +39,3 @@ "use strict"; | ||
babelParse: () => babelParse, | ||
escapeKey: () => escapeKey, | ||
getLang: () => getLang, | ||
@@ -96,2 +97,3 @@ isCallOf: () => isCallOf, | ||
// src/utils.ts | ||
var import_parser2 = require("@babel/parser"); | ||
function isTypeOf(node, types) { | ||
@@ -136,6 +138,19 @@ return types.some((type) => { | ||
} | ||
function escapeKey(rawKey) { | ||
if (String(+rawKey) === rawKey) | ||
return rawKey; | ||
try { | ||
const node = (0, import_parser2.parseExpression)(`({${rawKey}: 1})`); | ||
if (node.properties[0].key.type === "Identifier") | ||
return rawKey; | ||
} catch { | ||
} | ||
return JSON.stringify(rawKey); | ||
} | ||
// src/resolve.ts | ||
function resolveString(node, computed = false) { | ||
if (node.type === "Identifier") { | ||
if (typeof node === "string") | ||
return node; | ||
else if (node.type === "Identifier") { | ||
if (computed) | ||
@@ -380,24 +395,1 @@ throw new TypeError("Invalid Identifier"); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
REGEX_DTS, | ||
REGEX_LANG_JSX, | ||
REGEX_LANG_TS, | ||
TS_NODE_TYPES, | ||
attachScopes, | ||
babelParse, | ||
getLang, | ||
isCallOf, | ||
isDts, | ||
isFunctionType, | ||
isLiteralType, | ||
isTs, | ||
isTypeOf, | ||
resolveIdentifier, | ||
resolveLiteral, | ||
resolveString, | ||
resolveTemplateLiteral, | ||
unwrapTSNode, | ||
walkAST, | ||
walkImportDeclaration | ||
}); |
{ | ||
"name": "ast-kit", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"packageManager": "pnpm@8.6.0", | ||
@@ -5,0 +5,0 @@ "description": "AST Toolkit.", |
Sorry, the diff of this file is not supported yet
40211