@hpcc-js/observablehq-compiler 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +27 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +2 -2
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.js +31 -19
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/package.json +3 -4
- package/src/__package__.ts +2 -2
- package/src/__tests__/m1.mjs +3 -0
- package/src/__tests__/node.ts +23 -1
- package/src/compiler.ts +8 -12
- package/src/cst.ts +9 -6
- package/src/util.ts +14 -0
- package/types/__package__.d.ts +2 -2
- package/types/__package__.d.ts.map +1 -1
- package/types/compiler.d.ts.map +1 -1
- package/types/cst.d.ts +1 -1
- package/types/cst.d.ts.map +1 -1
- package/types/util.d.ts +2 -0
- package/types/util.d.ts.map +1 -1
- package/types-3.4/__package__.d.ts +2 -2
- package/types-3.4/cst.d.ts +1 -1
- package/types-3.4/util.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@hpcc-js/observablehq-compiler"] = {}
|
|
5
|
-
})(this, (function (exports
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@hpcc-js/observablehq-compiler"] = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// This file was generated. Do not modify manually!
|
|
8
8
|
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 357, 0, 62, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
@@ -6661,6 +6661,18 @@
|
|
|
6661
6661
|
body.substring(1, body.length - 1).trim() :
|
|
6662
6662
|
`return (\n${body}\n);`);
|
|
6663
6663
|
}
|
|
6664
|
+
function join(baseURL, relativeURL) {
|
|
6665
|
+
return relativeURL
|
|
6666
|
+
? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "")
|
|
6667
|
+
: baseURL;
|
|
6668
|
+
}
|
|
6669
|
+
const isRelativePath = (path) => path[0] === ".";
|
|
6670
|
+
const fixRelativeUrl = (path, basePath) => {
|
|
6671
|
+
if (isRelativePath(path)) {
|
|
6672
|
+
return join(basePath, path);
|
|
6673
|
+
}
|
|
6674
|
+
return path;
|
|
6675
|
+
};
|
|
6664
6676
|
// Hide "import" from bundlers as they have a habit of replacing "import" with "require"
|
|
6665
6677
|
async function obfuscatedImport(url) {
|
|
6666
6678
|
return new FuncTypes.asyncFunctionType("url", "return import(url)")(url);
|
|
@@ -6803,7 +6815,7 @@
|
|
|
6803
6815
|
}
|
|
6804
6816
|
return retVal;
|
|
6805
6817
|
}
|
|
6806
|
-
function
|
|
6818
|
+
function parseImportDeclaration(cellAst) {
|
|
6807
6819
|
var _a, _b, _c, _d;
|
|
6808
6820
|
return {
|
|
6809
6821
|
type: "import",
|
|
@@ -6880,14 +6892,17 @@
|
|
|
6880
6892
|
func: createFunction(refs, cellAst.async, cellAst.generator, cellAst.body.type === "BlockStatement", bodyStr)
|
|
6881
6893
|
};
|
|
6882
6894
|
}
|
|
6883
|
-
function parseCell(cellStr) {
|
|
6895
|
+
function parseCell(cellStr, baseUrl) {
|
|
6884
6896
|
var _a, _b;
|
|
6885
6897
|
const cellAst = parseCell$2(cellStr);
|
|
6886
|
-
|
|
6887
|
-
|
|
6898
|
+
let bodyStr = cellAst.body && cellStr.substring(cellAst.body.start, cellAst.body.end);
|
|
6899
|
+
switch ((_a = (cellAst.body)) === null || _a === void 0 ? void 0 : _a.type) {
|
|
6900
|
+
case "ImportDeclaration":
|
|
6901
|
+
return parseImportDeclaration(cellAst);
|
|
6902
|
+
case "ImportExpression":
|
|
6903
|
+
bodyStr = `import("${fixRelativeUrl(cellAst.body.source.value, baseUrl)}")`;
|
|
6888
6904
|
}
|
|
6889
6905
|
const refs = calcRefs(cellAst, cellStr);
|
|
6890
|
-
const bodyStr = cellAst.body && cellStr.substring(cellAst.body.start, cellAst.body.end);
|
|
6891
6906
|
switch ((_b = cellAst.id) === null || _b === void 0 ? void 0 : _b.type) {
|
|
6892
6907
|
case "ViewExpression":
|
|
6893
6908
|
return parseViewExpression(cellStr, cellAst, refs, bodyStr);
|
|
@@ -6968,20 +6983,17 @@ export default function define(runtime, observer) {
|
|
|
6968
6983
|
}
|
|
6969
6984
|
}
|
|
6970
6985
|
|
|
6971
|
-
// Module ---
|
|
6972
|
-
const isRelativePath = (path) => path[0] === ".";
|
|
6973
|
-
const fullUrl = (path, basePath) => isRelativePath(path) ? util.join(basePath, path) : path;
|
|
6974
6986
|
async function importFile(relativePath, baseUrl) {
|
|
6975
|
-
const path =
|
|
6987
|
+
const path = fixRelativeUrl(relativePath, baseUrl);
|
|
6976
6988
|
const content = await fetchEx(path).then(r => r.text());
|
|
6977
6989
|
let notebook;
|
|
6978
|
-
if (
|
|
6990
|
+
if (relativePath.endsWith(".ojsnb")) {
|
|
6979
6991
|
notebook = JSON.parse(content);
|
|
6980
6992
|
}
|
|
6981
|
-
else if (
|
|
6993
|
+
else if (relativePath.endsWith(".ojs")) {
|
|
6982
6994
|
notebook = ojs2notebook(content);
|
|
6983
6995
|
}
|
|
6984
|
-
else if (
|
|
6996
|
+
else if (relativePath.endsWith(".omd")) {
|
|
6985
6997
|
notebook = omd2notebook(content);
|
|
6986
6998
|
}
|
|
6987
6999
|
const retVal = compile(notebook, { baseUrl });
|
|
@@ -7140,7 +7152,7 @@ ${node.value}
|
|
|
7140
7152
|
const text = node.mode && node.mode !== "js" ? `${node.mode}\`${encodeBacktick(node.value)}\`` : node.value;
|
|
7141
7153
|
const parsedModule = splitModule(text);
|
|
7142
7154
|
for (const cell of parsedModule) {
|
|
7143
|
-
const parsed = parseCell(cell.text);
|
|
7155
|
+
const parsed = parseCell(cell.text, options.baseUrl);
|
|
7144
7156
|
switch (parsed.type) {
|
|
7145
7157
|
case "import":
|
|
7146
7158
|
modules.push(await createModule(node, parsed, cell.text, options));
|
|
@@ -7183,7 +7195,7 @@ ${node.value}
|
|
|
7183
7195
|
// File ---
|
|
7184
7196
|
function createFile(file, options) {
|
|
7185
7197
|
function toString() { return globalThis.url; }
|
|
7186
|
-
return [file.name, { url: new URL(
|
|
7198
|
+
return [file.name, { url: new URL(fixRelativeUrl(file.url, options.baseUrl)), mimeType: file.mime_type, toString }];
|
|
7187
7199
|
}
|
|
7188
7200
|
function notebook(_files = [], _cells = [], { baseUrl = ".", importMode = "precompiled" } = {}) {
|
|
7189
7201
|
const files = _files.map(f => createFile(f, { baseUrl, importMode }));
|
|
@@ -7193,7 +7205,7 @@ ${node.value}
|
|
|
7193
7205
|
const main = runtime.module();
|
|
7194
7206
|
main.builtin("FileAttachment", runtime.fileAttachments(name => {
|
|
7195
7207
|
var _a;
|
|
7196
|
-
return (_a = fileAttachments.get(name)) !== null && _a !== void 0 ? _a : { url: new URL(
|
|
7208
|
+
return (_a = fileAttachments.get(name)) !== null && _a !== void 0 ? _a : { url: new URL(fixRelativeUrl(name, baseUrl)), mimeType: null };
|
|
7197
7209
|
}));
|
|
7198
7210
|
main.builtin("fetchEx", fetchEx);
|
|
7199
7211
|
cells.forEach(cell => {
|