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

Function CallExpression

src/javascript/files.ts:97–116  ·  view source on GitHub ↗
(node, state, stack)

Source from the content-addressed store, hash-verified

95 // you can’t reference a global file as a file attachment.
96 ancestor(body, {
97 CallExpression(node, state, stack) {
98 const {callee} = node;
99 if (callee.type !== "Identifier" || !alias.has(callee.name) || !references.has(callee)) return;
100 const args = node.arguments;
101 if (args.length !== 1) throw syntaxError("FileAttachment requires a single literal string argument", node, input);
102 const [arg] = args;
103 if (!isStringLiteral(arg)) throw syntaxError("FileAttachment requires a single literal string argument", node, input); // prettier-ignore
104 const fileName = getStringLiteralValue(arg);
105 const filePath = resolveLocalPath(path, fileName);
106 if (!filePath) throw syntaxError(`non-local file path: ${fileName}`, node, input);
107 const parent = stack[stack.length - 2];
108 const name = relativePath(path, filePath);
109 const method =
110 parent && isMemberExpression(parent) && parent.property.type === "Identifier"
111 ? parent.property.name === "arquero" && /\.parquet$/i.test(fileName)
112 ? "arquero-parquet" // FileAttachment("foo.parquet").arquero
113 : parent.property.name // FileAttachment("foo.csv").csv
114 : KNOWN_FILE_EXTENSIONS[extname(fileName).toLowerCase()]; // bare FileAttachment("foo.csv")
115 files.push({node, name, method});
116 }
117 });
118
119 return files;

Callers

nothing calls this directly

Calls 6

syntaxErrorFunction · 0.85
isStringLiteralFunction · 0.85
getStringLiteralValueFunction · 0.85
resolveLocalPathFunction · 0.85
relativePathFunction · 0.85
isMemberExpressionFunction · 0.70

Tested by

no test coverage detected