Comparing version 0.2.0 to 0.3.0
@@ -45,3 +45,5 @@ "use strict"; | ||
isTs: () => isTs, | ||
toStringValue: () => toStringValue, | ||
resolveLiteral: () => resolveLiteral, | ||
resolveString: () => resolveString, | ||
resolveTemplateLiteral: () => resolveTemplateLiteral, | ||
unwrapTSNode: () => unwrapTSNode, | ||
@@ -91,6 +93,2 @@ walkAST: () => walkAST, | ||
// src/scope.ts | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
var attachScopes = import_pluginutils.attachScopes; | ||
// src/utils.ts | ||
@@ -125,6 +123,41 @@ function isCallOf(node, test) { | ||
} | ||
function toStringValue(node) { | ||
// src/resolve.ts | ||
function resolveString(node) { | ||
return node.type === "StringLiteral" ? node.value : node.name; | ||
} | ||
function resolveLiteral(node) { | ||
switch (node.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node.pattern, node.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node.value; | ||
case "DecimalLiteral": | ||
return Number(node.value); | ||
} | ||
} | ||
function resolveTemplateLiteral(node) { | ||
return node.quasis.reduce((prev, curr, idx) => { | ||
const expr = node.expressions[idx]; | ||
if (expr) { | ||
if (!isLiteralType(expr)) | ||
throw new TypeError("TemplateLiteral expression must be a literal"); | ||
return prev + curr.value.cooked + resolveLiteral(expr); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
// src/scope.ts | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
var attachScopes = import_pluginutils.attachScopes; | ||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js | ||
@@ -292,4 +325,6 @@ var WalkerBase = class { | ||
for (const specifier of node.specifiers) { | ||
if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") | ||
continue; | ||
const local = specifier.local.name; | ||
const imported = specifier.type === "ImportSpecifier" ? toStringValue(specifier.imported) : specifier.type === "ImportNamespaceSpecifier" ? "*" : "default"; | ||
const imported = specifier.type === "ImportSpecifier" ? resolveString(specifier.imported) : specifier.type === "ImportNamespaceSpecifier" ? "*" : "default"; | ||
imports[local] = { | ||
@@ -317,3 +352,5 @@ source, | ||
isTs, | ||
toStringValue, | ||
resolveLiteral, | ||
resolveString, | ||
resolveTemplateLiteral, | ||
unwrapTSNode, | ||
@@ -320,0 +357,0 @@ walkAST, |
import { ParserOptions } from '@babel/parser'; | ||
import { Program, Node, CallExpression, Literal, Function, Identifier, StringLiteral, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportDeclaration } from '@babel/types'; | ||
import { Program, Identifier, StringLiteral, Literal, TemplateLiteral, Node, CallExpression, Function, ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportDeclaration } from '@babel/types'; | ||
import { AttachedScope } from '@rollup/pluginutils'; | ||
@@ -15,2 +15,6 @@ export { AttachedScope } from '@rollup/pluginutils'; | ||
declare function resolveString(node: Identifier | StringLiteral): string; | ||
declare function resolveLiteral(node: Literal): string | number | boolean | null | RegExp | bigint; | ||
declare function resolveTemplateLiteral(node: TemplateLiteral): string; | ||
declare const attachScopes: <T>(ast: T, propertyName?: string) => AttachedScope; | ||
@@ -27,3 +31,2 @@ | ||
declare function unwrapTSNode(node: Node): Node; | ||
declare function toStringValue(node: Identifier | StringLiteral): string; | ||
@@ -50,2 +53,2 @@ declare function walkAST<T = Node>(node: T, options: { | ||
export { ImportBinding, REGEX_DTS, REGEX_LANG_JSX, REGEX_LANG_TS, TS_NODE_TYPES, WithScope, attachScopes, babelParse, getLang, isCallOf, isDts, isFunctionType, isLiteralType, isTs, toStringValue, unwrapTSNode, walkAST, walkImportDeclaration }; | ||
export { ImportBinding, REGEX_DTS, REGEX_LANG_JSX, REGEX_LANG_TS, TS_NODE_TYPES, WithScope, attachScopes, babelParse, getLang, isCallOf, isDts, isFunctionType, isLiteralType, isTs, resolveLiteral, resolveString, resolveTemplateLiteral, unwrapTSNode, walkAST, walkImportDeclaration }; |
@@ -45,3 +45,5 @@ "use strict"; | ||
isTs: () => isTs, | ||
toStringValue: () => toStringValue, | ||
resolveLiteral: () => resolveLiteral, | ||
resolveString: () => resolveString, | ||
resolveTemplateLiteral: () => resolveTemplateLiteral, | ||
unwrapTSNode: () => unwrapTSNode, | ||
@@ -91,6 +93,2 @@ walkAST: () => walkAST, | ||
// src/scope.ts | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
var attachScopes = import_pluginutils.attachScopes; | ||
// src/utils.ts | ||
@@ -125,6 +123,41 @@ function isCallOf(node, test) { | ||
} | ||
function toStringValue(node) { | ||
// src/resolve.ts | ||
function resolveString(node) { | ||
return node.type === "StringLiteral" ? node.value : node.name; | ||
} | ||
function resolveLiteral(node) { | ||
switch (node.type) { | ||
case "TemplateLiteral": | ||
return resolveTemplateLiteral(node); | ||
case "NullLiteral": | ||
return null; | ||
case "BigIntLiteral": | ||
return BigInt(node.value); | ||
case "RegExpLiteral": | ||
return new RegExp(node.pattern, node.flags); | ||
case "BooleanLiteral": | ||
case "NumericLiteral": | ||
case "StringLiteral": | ||
return node.value; | ||
case "DecimalLiteral": | ||
return Number(node.value); | ||
} | ||
} | ||
function resolveTemplateLiteral(node) { | ||
return node.quasis.reduce((prev, curr, idx) => { | ||
const expr = node.expressions[idx]; | ||
if (expr) { | ||
if (!isLiteralType(expr)) | ||
throw new TypeError("TemplateLiteral expression must be a literal"); | ||
return prev + curr.value.cooked + resolveLiteral(expr); | ||
} | ||
return prev + curr.value.cooked; | ||
}, ""); | ||
} | ||
// src/scope.ts | ||
var import_pluginutils = require("@rollup/pluginutils"); | ||
var attachScopes = import_pluginutils.attachScopes; | ||
// node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js | ||
@@ -292,4 +325,6 @@ var WalkerBase = class { | ||
for (const specifier of node.specifiers) { | ||
if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") | ||
continue; | ||
const local = specifier.local.name; | ||
const imported = specifier.type === "ImportSpecifier" ? toStringValue(specifier.imported) : specifier.type === "ImportNamespaceSpecifier" ? "*" : "default"; | ||
const imported = specifier.type === "ImportSpecifier" ? resolveString(specifier.imported) : specifier.type === "ImportNamespaceSpecifier" ? "*" : "default"; | ||
imports[local] = { | ||
@@ -317,3 +352,5 @@ source, | ||
isTs, | ||
toStringValue, | ||
resolveLiteral, | ||
resolveString, | ||
resolveTemplateLiteral, | ||
unwrapTSNode, | ||
@@ -320,0 +357,0 @@ walkAST, |
{ | ||
"name": "ast-kit", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"packageManager": "pnpm@8.6.0", | ||
@@ -5,0 +5,0 @@ "description": "AST Toolkit.", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35277
1026