improve code generation for jsImports
This commit is contained in:
parent
64ed32a17c
commit
e2abc53200
|
@ -24,7 +24,7 @@ const jsImportsValueToSquiggleCode = (v: JsImportsValue): string => {
|
||||||
return (
|
return (
|
||||||
"{" +
|
"{" +
|
||||||
Object.entries(v)
|
Object.entries(v)
|
||||||
.map(([k, v]) => `${k}:${jsImportsValueToSquiggleCode(v)},`)
|
.map(([k, v]) => `${quote(k)}:${jsImportsValueToSquiggleCode(v)},`)
|
||||||
.join("") +
|
.join("") +
|
||||||
"}"
|
"}"
|
||||||
);
|
);
|
||||||
|
@ -35,7 +35,17 @@ const jsImportsValueToSquiggleCode = (v: JsImportsValue): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const jsImportsToSquiggleCode = (v: JsImports) => {
|
export const jsImportsToSquiggleCode = (v: JsImports) => {
|
||||||
return Object.entries(v)
|
const validId = new RegExp("[a-zA-Z][[a-zA-Z0-9]*");
|
||||||
.map(([k, v]) => `$${k} = ${jsImportsValueToSquiggleCode(v)}\n`)
|
let result = Object.entries(v)
|
||||||
|
.map(([k, v]) => {
|
||||||
|
if (!k.match(validId)) {
|
||||||
|
return ""; // skipping without warnings; can be improved
|
||||||
|
}
|
||||||
|
return `$${k} = ${jsImportsValueToSquiggleCode(v)}\n`;
|
||||||
|
})
|
||||||
.join("");
|
.join("");
|
||||||
|
if (!result) {
|
||||||
|
result = "$__no_valid_imports__ = 1"; // without this generated squiggle code can be invalid
|
||||||
|
}
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user