Difference between Browser and Node app - Null Propagation Operator
mattrout92 opened this issue · comments
mattrout92 commented
When I use the null propagation operator on a template with jsrender in the browser and again on a node application, I get different behavior. The template renders correctly in the browser, but when I use it on the node app, it returns a syntax error.
This is the example I have:
export const render = (template: string, data: any): string => {
jsrender.views.settings.allowCode(true);
jsrender.views.settings.debugMode(true);
template = `{{*: data.animal?.name || "Bob" }}`;
let tmpl = jsrender.compile(template);
return tmpl(data);
};
and this is the error that it throws on the node app:
2020-08-20T08:16:34.280Z 947a4602-aab6-1cf5-f28b-d867efa16560 INFO Error
at /var/task/node_modules/jsrender/jsrender-node.js:221:27
at Object.<anonymous> (/var/task/node_modules/jsrender/jsrender-node.js:2964:2)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/var/task/dist/utils/jsrender.js:3:16)
at Module._compile (internal/modules/cjs/loader.js:1138:30) {
name: 'JsRender Error',
message: 'Syntax error\n' +
'Compiled template code:\n' +
'\n' +
'// unnamed\n' +
'var v,ret="";\n' +
'\n' +
'ret+= data.animal?.name || "Bob" ;\n' +
'\n' +
'ret=ret;\n' +
'return ret;\n' +
`: "Unexpected token '.'"`
}
mattrout92 commented
This may be because I am using AWS's nodejs12.x runtime
mattrout92 commented
Can confirm this is not an issue on node 14+