Skip to content

Commit

Permalink
Rename Data to FileAttachment
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Sep 23, 2019
1 parent 07c42e4 commit 70e6f03
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 263 deletions.
16 changes: 8 additions & 8 deletions src/data.js → src/file-attachments.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {simple} from "acorn-walk";
import walk from "./walk.js";

export default function findData(cell) {
export default function findFileAttachments(cell) {
const ast = {type: "Program", body: [cell.body]};
const dataReferences = new Set();
const references = new Set();

simple(
ast,
{
CallExpression: node => {
const {callee, arguments: args} = node;

// Ignore function calls that are not references to Data
if (!(callee.type === "Identifier" && callee.name === "Data")) return;
// Ignore function calls that are not references to FileAttachment
if (!(callee.type === "Identifier" && callee.name === "FileAttachment")) return;

// Forbid all sorts of dynamic uses of Data
// Forbid all sorts of dynamic uses of FileAttachment
if (
!(
args.length === 1 &&
Expand All @@ -25,13 +25,13 @@ export default function findData(cell) {
) {
throw Object.assign(
new SyntaxError(
`Data() requires a single literal string as its argument.`
`FileAttachment() requires a single literal string as its argument.`
),
{node}
);
}

dataReferences.add(
references.add(
args[0].type === "Literal"
? args[0].value
: args[0].quasis[0].value.cooked
Expand All @@ -41,5 +41,5 @@ export default function findData(cell) {
walk
);

return dataReferences;
return references;
}
4 changes: 2 additions & 2 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import bigInt from "acorn-bigint";
import dynamicImport from "./dynamic-import.js";
import defaultGlobals from "./globals.js";
import findReferences from "./references.js";
import findData from "./data.js";
import findFileAttachments from "./file-attachments.js";

const SCOPE_FUNCTION = 2;
const SCOPE_ASYNC = 4;
Expand Down Expand Up @@ -306,7 +306,7 @@ function parseReferences(cell, input, globals = defaultGlobals) {
function parseData(cell, input) {
if (cell.body && cell.body.type !== "ImportDeclaration") {
try {
cell.data = findData(cell);
cell.fileAttachments = findFileAttachments(cell);
} catch (error) {
if (error.node) {
const loc = getLineInfo(input, error.node.start);
Expand Down
Loading

0 comments on commit 70e6f03

Please sign in to comment.