Skip to content

Commit 0374a0c

Browse files
committed
chore: fix
1 parent 0f224fb commit 0374a0c

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

src/macro.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
async function extractMacros(txt, { lib, reader, lang, importPaths }) {
1+
async function extractMacros(txt, options = {}) {
2+
const { lib, reader, lang, importPaths, requestOptions } = options;
3+
24
function getImports() {
35
var imps = [];
46
for (var i = 0; i < txt.length; i++) {
@@ -106,11 +108,9 @@ async function extractMacros(txt, { lib, reader, lang, importPaths }) {
106108
} else if (imports[i] in lib) {
107109
isrc = lib[imports[i]];
108110
} else {
109-
isrc = await reader(imports[i], importPaths);
111+
isrc = await reader(imports[i], importPaths, requestOptions);
110112
}
111-
macros = macros.concat(
112-
await extractMacros(isrc, { lib, reader, lang, importPaths })
113-
);
113+
macros = macros.concat(await extractMacros(isrc, options));
114114
}
115115
return macros;
116116
}

src/parser.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ function tokenRomanize(tokens, method) {
221221
}
222222
}
223223

224+
function defaultLogCallback(x) {
225+
return typeof x == "string"
226+
? console.log(x)
227+
: console.dir(x, { depth: null, maxArrayLength: null });
228+
}
229+
224230
function tokens2asc(
225231
tokens,
226232
assert = (msg, pos, b) => {
@@ -648,18 +654,24 @@ async function compile(arg1, arg2, arg3) {
648654
const {
649655
lang = "js",
650656
romanizeIdentifiers = "none",
651-
resetVarCnt,
652-
logCallback = x =>
653-
typeof x == "string"
654-
? console.log(x)
655-
: console.dir(x, { depth: null, maxArrayLength: null }),
657+
resetVarCnt = true,
658+
logCallback = defaultLogCallback,
656659
errorCallback = process.exit,
657660
lib = typeof STDLIB == "undefined" ? {} : STDLIB,
658661
reader = defaultImportReader,
659662
importPaths = [],
660-
strict = false
663+
strict = false,
664+
allowHttp = false,
665+
trustedHosts = [],
666+
requestTimeout = 2000
661667
} = options;
662668

669+
const requestOptions = {
670+
allowHttp,
671+
trustedHosts,
672+
requestTimeout
673+
};
674+
663675
if (resetVarCnt) idenMap = {};
664676
txt = (txt || "").replace(/\r\n/g, "\n");
665677

@@ -689,7 +701,13 @@ async function compile(arg1, arg2, arg3) {
689701
return 0;
690702
}
691703

692-
var macros = await extractMacros(txt, { lib, reader, lang, importPaths });
704+
var macros = await extractMacros(txt, {
705+
lib,
706+
reader,
707+
lang,
708+
importPaths,
709+
requestOptions
710+
});
693711
txt = expandMacros(txt, macros);
694712

695713
logCallback("\n\n=== [PASS 0] EXPAND-MACROS ===");
@@ -743,15 +761,9 @@ async function compile(arg1, arg2, arg3) {
743761
mwrapper(
744762
imports[i],
745763
await compile(isrc, {
746-
lang,
747-
romanizeIdentifiers,
764+
...options,
748765
resetVarCnt: false,
749-
strict: false,
750-
logCallback,
751-
errorCallback,
752-
lib,
753-
reader,
754-
importPaths
766+
strict: false
755767
})
756768
) + targ;
757769
}

src/reader.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ function isHostTrusted(url, trustedHosts) {
22
// TODO:
33
return false;
44
}
5+
56
function isHttpURL(uri) {
67
return !!uri.match(/^https?\:\/\//);
78
}
@@ -48,9 +49,6 @@ async function defaultImportReader(
4849
);
4950
}
5051

51-
try {
52-
module.exports = {
53-
normalizeImportPath,
54-
defaultImportReader
55-
};
56-
} catch (e) {}
52+
module.exports = {
53+
defaultImportReader
54+
};

0 commit comments

Comments
 (0)