@low-systems/javascript-renderer
Advanced tools
Comparing version 1.1.21 to 1.1.27
@@ -8,3 +8,3 @@ import { Renderer, RenderConfig, Context, IMap } from 'low'; | ||
getTemplate(config: RenderConfig<JavascriptTemplate>, context: Context): Promise<any>; | ||
makeFunction(code: string): Function; | ||
makeFunction(code: string, name?: string): Function; | ||
} | ||
@@ -11,0 +11,0 @@ export interface JavascriptConfig { |
@@ -26,3 +26,3 @@ "use strict"; | ||
for (const [name, code] of Object.entries(this.config.functions)) { | ||
const func = this.makeFunction(code); | ||
const func = this.makeFunction(code, name); | ||
this.functions[name] = func; | ||
@@ -55,3 +55,3 @@ } | ||
} | ||
const func = this.makeFunction(config.__template.code); | ||
const func = this.makeFunction(config.__template.code, config.__template.name); | ||
if (typeof config.__template.name === 'string') { | ||
@@ -67,7 +67,13 @@ this.functions[config.__template.name] = func; | ||
} | ||
makeFunction(code) { | ||
const promise = ` | ||
return new Promise((resolve, reject) => { | ||
${code} | ||
makeFunction(code, name) { | ||
let promise = `return new Promise((resolve, reject) => { | ||
try { | ||
${code} | ||
} catch (err) { | ||
reject(err); | ||
} | ||
});`; | ||
if (name) { | ||
promise = `//# sourceURL=${name}\n${promise}`; | ||
} | ||
const func = new Function('metadata', promise); | ||
@@ -74,0 +80,0 @@ return func; |
{ | ||
"version": "1.1.21", | ||
"version": "1.1.27", | ||
"main": "lib/javascript-renderer.js", | ||
@@ -28,3 +28,3 @@ "types": "lib/javascript-renderer.d.ts", | ||
}, | ||
"gitHead": "6f286107edc13a9ffc9b7434cd77b11bcdc1be00", | ||
"gitHead": "c994eb57314bac7fef70898160c232d933d005c1", | ||
"devDependencies": { | ||
@@ -31,0 +31,0 @@ "@types/jest": "^24.9.0", |
@@ -13,3 +13,3 @@ import { Renderer, RenderConfig, Context, IMap } from 'low'; | ||
for (const [name, code] of Object.entries(this.config.functions)) { | ||
const func = this.makeFunction(code); | ||
const func = this.makeFunction(code, name); | ||
this.functions[name] = func; | ||
@@ -40,3 +40,3 @@ } | ||
const func = this.makeFunction(config.__template.code); | ||
const func = this.makeFunction(config.__template.code, config.__template.name); | ||
@@ -53,5 +53,4 @@ if (typeof config.__template.name === 'string') { | ||
makeFunction(code: string): Function { | ||
const promise = ` | ||
return new Promise((resolve, reject) => { | ||
makeFunction(code: string, name?: string): Function { | ||
let promise = `return new Promise((resolve, reject) => { | ||
try { | ||
@@ -63,2 +62,6 @@ ${code} | ||
});`; | ||
if (name) { | ||
promise = `//# sourceURL=${name}\n${promise}`; | ||
} | ||
const func = new Function('metadata', promise); | ||
@@ -65,0 +68,0 @@ return func; |
Sorry, the diff of this file is not supported yet
17866
325