refactor(domain): share AST property name reader
This commit is contained in:
@@ -2,6 +2,8 @@ import { createHash } from "node:crypto";
|
|||||||
|
|
||||||
import * as t from "@babel/types";
|
import * as t from "@babel/types";
|
||||||
|
|
||||||
|
import { propertyName } from "./javascriptAstValues.js";
|
||||||
|
|
||||||
/** Static CommonJS export names. */
|
/** Static CommonJS export names. */
|
||||||
export interface StaticExports {
|
export interface StaticExports {
|
||||||
readonly values: readonly string[];
|
readonly values: readonly string[];
|
||||||
@@ -121,13 +123,6 @@ const memberPath = (node: t.Node | null | undefined): string => {
|
|||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
const propertyName = (node: t.Node): string => {
|
|
||||||
if (t.isIdentifier(node)) return node.name;
|
|
||||||
if (t.isStringLiteral(node) || t.isNumericLiteral(node))
|
|
||||||
return String(node.value);
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
const stringValue = (node: t.Node | null | undefined): string | undefined =>
|
const stringValue = (node: t.Node | null | undefined): string | undefined =>
|
||||||
t.isStringLiteral(node) ? node.value : undefined;
|
t.isStringLiteral(node) ? node.value : undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import * as t from "@babel/types";
|
||||||
|
|
||||||
|
/** Read an identifier or literal property name without evaluating syntax. */
|
||||||
|
export const propertyName = (node: t.Node): string => {
|
||||||
|
if (t.isIdentifier(node)) return node.name;
|
||||||
|
if (t.isStringLiteral(node) || t.isNumericLiteral(node))
|
||||||
|
return String(node.value);
|
||||||
|
return "";
|
||||||
|
};
|
||||||
@@ -10,6 +10,9 @@ import type {
|
|||||||
JavaScriptStaticPathContext,
|
JavaScriptStaticPathContext,
|
||||||
JavaScriptStaticStorage,
|
JavaScriptStaticStorage,
|
||||||
} from "./javascriptStaticAnalysisTypes.js";
|
} from "./javascriptStaticAnalysisTypes.js";
|
||||||
|
import { propertyName } from "./javascriptAstValues.js";
|
||||||
|
|
||||||
|
export { propertyName } from "./javascriptAstValues.js";
|
||||||
|
|
||||||
/** Explicit result for source text that Babel cannot parse. */
|
/** Explicit result for source text that Babel cannot parse. */
|
||||||
export const failedJavaScriptStaticAnalysis = (): JavaScriptStaticAnalysis => ({
|
export const failedJavaScriptStaticAnalysis = (): JavaScriptStaticAnalysis => ({
|
||||||
@@ -299,14 +302,6 @@ const calleeNameAt = (node: t.Node): string => {
|
|||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Read a literal property name without evaluating computed syntax. */
|
|
||||||
export const propertyName = (node: t.Node): string => {
|
|
||||||
if (t.isIdentifier(node)) return node.name;
|
|
||||||
if (t.isStringLiteral(node) || t.isNumericLiteral(node))
|
|
||||||
return String(node.value);
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Return a string literal value without evaluating an expression. */
|
/** Return a string literal value without evaluating an expression. */
|
||||||
export const stringValue = (
|
export const stringValue = (
|
||||||
node: t.Node | null | undefined,
|
node: t.Node | null | undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user