Skip to content

Commit 9a17c22

Browse files
authored
transpiles ojs imports of mutables (#168)
1 parent 8a6eee7 commit 9a17c22

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

src/javascript/__snapshots__/transpile.test.ts.snap

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,62 @@ Interpreter("node", {id: -1, format: "buffer"}).run(\`process.stdout.write(\\\`N
489489
}
490490
`;
491491
492+
exports[`transpiles ojs imports of mutables 1`] = `
493+
{
494+
"autodisplay": false,
495+
"body": "async (__variable) => {
496+
const {foo, mutable$foo} = await (import("https://api.observablehq.com/d/2d6bf7be248d66f3.js?v=4").then((_) => {
497+
const module = __variable._module._runtime.module(_.default);
498+
const outputs = new Map(Array.from(__variable._outputs, (v) => [v._name, v]));
499+
outputs.get("foo")?.import("foo", module);
500+
outputs.get("mutable$foo")?.import("mutable foo", "mutable$foo", module);
501+
return {};
502+
}));
503+
504+
return {foo,mutable$foo};
505+
}",
506+
"databases": Set {},
507+
"files": Set {},
508+
"inputs": [
509+
"@variable",
510+
],
511+
"output": undefined,
512+
"outputs": [
513+
"foo",
514+
"mutable$foo",
515+
],
516+
"secrets": Set {},
517+
}
518+
`;
519+
520+
exports[`transpiles ojs imports of mutables 2`] = `
521+
{
522+
"autodisplay": false,
523+
"body": "async (__variable) => {
524+
const {foo: bar, mutable$foo: mutable$bar} = await (import("https://api.observablehq.com/d/2d6bf7be248d66f3.js?v=4").then((_) => {
525+
const module = __variable._module._runtime.module(_.default);
526+
const outputs = new Map(Array.from(__variable._outputs, (v) => [v._name, v]));
527+
outputs.get("bar")?.import("foo", "bar", module);
528+
outputs.get("mutable$bar")?.import("mutable foo", "mutable$bar", module);
529+
return {};
530+
}));
531+
532+
return {bar,mutable$bar};
533+
}",
534+
"databases": Set {},
535+
"files": Set {},
536+
"inputs": [
537+
"@variable",
538+
],
539+
"output": undefined,
540+
"outputs": [
541+
"bar",
542+
"mutable$bar",
543+
],
544+
"secrets": Set {},
545+
}
546+
`;
547+
492548
exports[`transpiles static imports with {type: 'observable'} 1`] = `
493549
{
494550
"autodisplay": false,

src/javascript/transpile.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ it("transpiles Observable JavaScript imports", () => {
5555
expect(transpile('import {figure, viewof rotation as rot} from "@rreusser/drawing-3d-objects-with-svg"', "ojs")).toMatchSnapshot();
5656
});
5757

58+
it("transpiles ojs imports of mutables", () => {
59+
expect(transpile('import {mutable foo} from "2d6bf7be248d66f3"', "ojs")).toMatchSnapshot();
60+
expect(transpile('import {mutable foo as bar} from "2d6bf7be248d66f3"', "ojs")).toMatchSnapshot();
61+
});
62+
5863
it("transpiles import.meta.resolve", () => {
5964
expect(transpile('import.meta.resolve("npm:d3")', "js")).toMatchSnapshot();
6065
expect(transpile('import.meta.resolve("./test")', "js", {resolveLocalImports: true})).toMatchSnapshot();

0 commit comments

Comments
 (0)