ultimate-express 1.3.7 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/declarative.js +15 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "The Ultimate Express. Fastest http server with full Express compatibility, based on uWebSockets.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,4 +1,5 @@
1
1
  const acorn = require("acorn");
2
+ const { stringify } = require("./utils.js");
2
3
  const uWS = require("uWebSockets.js");
3
4
 
4
5
  const parser = acorn.Parser;
@@ -272,6 +273,20 @@ module.exports = function compileDeclarative(cb, app) {
272
273
  return false;
273
274
  }
274
275
  body.push(...stuff.reverse());
276
+ } else if(arg.type === 'ObjectExpression') {
277
+ // only simple objects can be optimized
278
+ for(let property of arg.properties) {
279
+ if(property.key.type !== 'Identifier' && property.key.type !== 'Literal') {
280
+ return false;
281
+ }
282
+ if(property.value.type !== 'Literal') {
283
+ return false;
284
+ }
285
+ }
286
+ if(typeof app.get('json replacer') !== 'undefined' && typeof app.get('json replacer') !== 'string') {
287
+ return false;
288
+ }
289
+ 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'))});
275
290
  } else {
276
291
  return false;
277
292
  }