Skip to content

Commit

Permalink
support simple objects in declarative responses
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Nov 10, 2024
1 parent 3398194 commit 071d750
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ultimate-express",
"version": "1.3.7",
"version": "1.3.8",
"description": "The Ultimate Express. Fastest http server with full Express compatibility, based on uWebSockets.",
"main": "src/index.js",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions src/declarative.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const acorn = require("acorn");
const { stringify } = require("./utils.js");
const uWS = require("uWebSockets.js");

const parser = acorn.Parser;
Expand Down Expand Up @@ -272,6 +273,20 @@ module.exports = function compileDeclarative(cb, app) {
return false;
}
body.push(...stuff.reverse());
} else if(arg.type === 'ObjectExpression') {
// only simple objects can be optimized
for(let property of arg.properties) {
if(property.key.type !== 'Identifier' && property.key.type !== 'Literal') {
return false;
}
if(property.value.type !== 'Literal') {
return false;
}
}
if(typeof app.get('json replacer') !== 'undefined' && typeof app.get('json replacer') !== 'string') {
return false;
}
body.push({type: 'text', value: stringify(JSON.parse(code.slice(arg.start, arg.end)), app.get('json replacer'), app.get('json spaces'), app.get('json escape'))});
} else {
return false;
}
Expand Down

0 comments on commit 071d750

Please sign in to comment.