MCPcopy Create free account
hub / github.com/observablehq/framework / isStringLiteral

Function isStringLiteral

src/javascript/source.ts:13–23  ·  view source on GitHub ↗
(node: Node)

Source from the content-addressed store, hash-verified

11}
12
13export function isStringLiteral(node: Node): node is StringLiteral {
14 return isLiteral(node)
15 ? /^['"]/.test(node.raw!)
16 : isTemplateLiteral(node)
17 ? node.expressions.every(isStringLiteral)
18 : isBinaryExpression(node)
19 ? node.operator === "+" && isStringLiteral(node.left) && isStringLiteral(node.right)
20 : isMemberExpression(node)
21 ? "value" in node // param
22 : false;
23}
24
25export function getStringLiteralValue(node: StringLiteral): string {
26 return node.type === "TemplateLiteral"

Callers 14

source-test.tsFile · 0.85
maybeStringLiteralValueFunction · 0.85
rewriteImportFunction · 0.85
rewriteImportMetaResolveFunction · 0.85
findImportFunction · 0.85
findImportMetaResolveFunction · 0.85
CallExpressionFunction · 0.85
transpileModuleFunction · 0.85
ImportExpressionFunction · 0.85
CallExpressionFunction · 0.85
ImportDeclarationFunction · 0.85
CallExpressionFunction · 0.85

Calls 4

isLiteralFunction · 0.85
isTemplateLiteralFunction · 0.85
isBinaryExpressionFunction · 0.85
isMemberExpressionFunction · 0.70

Tested by

no test coverage detected