Repository: buxlabs/boxwood
Pull request #604 (2020-04-09 21:05:33)

Stats


Patch:
diff --git a/package-lock.json b/package-lock.json
index 4289f4b..799eed6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -487,16 +487,16 @@
       "dev": true
     },
     "ava": {
-      "version": "3.5.1",
-      "resolved": "https://registry.npmjs.org/ava/-/ava-3.5.1.tgz",
-      "integrity": "sha512-gde/nh438C6cj6/pKntjoPmGg1VSsZlRjyuYTjp0ixsNDj+1YNVeASrlzI+NgvcUmbx17G8uOgByt7lDu8ddXA==",
+      "version": "3.6.0",
+      "resolved": "https://registry.npmjs.org/ava/-/ava-3.6.0.tgz",
+      "integrity": "sha512-cp+oK06JTFK9m4EhLq0APPSi6aTpwUOK0aKH5pCzIhU8AHFLXis0HNarfIr/EeBe9GzQKouuIsnlVedY7Lg0Cw==",
       "dev": true,
       "requires": {
         "@concordance/react": "^2.0.0",
         "ansi-styles": "^4.2.1",
         "arrgv": "^1.0.2",
         "arrify": "^2.0.1",
-        "chalk": "^3.0.0",
+        "chalk": "^4.0.0",
         "chokidar": "^3.3.1",
         "chunkd": "^2.0.1",
         "ci-info": "^2.0.0",
@@ -512,9 +512,9 @@
         "currently-unhandled": "^0.4.1",
         "debug": "^4.1.1",
         "del": "^5.1.0",
-        "emittery": "^0.5.1",
+        "emittery": "^0.6.0",
         "equal-length": "^1.0.0",
-        "figures": "^3.1.0",
+        "figures": "^3.2.0",
         "globby": "^11.0.0",
         "ignore-by-default": "^1.0.0",
         "import-local": "^3.0.2",
@@ -527,11 +527,11 @@
         "md5-hex": "^3.0.1",
         "ms": "^2.1.2",
         "ora": "^4.0.3",
-        "p-map": "^3.0.0",
-        "picomatch": "^2.2.1",
+        "p-map": "^4.0.0",
+        "picomatch": "^2.2.2",
         "pkg-conf": "^3.1.0",
         "plur": "^4.0.0",
-        "pretty-ms": "^6.0.0",
+        "pretty-ms": "^6.0.1",
         "read-pkg": "^5.2.0",
         "resolve-cwd": "^3.0.0",
         "slash": "^3.0.0",
@@ -542,8 +542,8 @@
         "temp-dir": "^2.0.0",
         "trim-off-newlines": "^1.0.1",
         "update-notifier": "^4.1.0",
-        "write-file-atomic": "^3.0.1",
-        "yargs": "^15.1.0"
+        "write-file-atomic": "^3.0.3",
+        "yargs": "^15.3.1"
       },
       "dependencies": {
         "ansi-styles": {
@@ -557,9 +557,9 @@
           }
         },
         "chalk": {
-          "version": "3.0.0",
-          "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
-          "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==",
+          "version": "4.0.0",
+          "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.0.0.tgz",
+          "integrity": "sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==",
           "dev": true,
           "requires": {
             "ansi-styles": "^4.1.0",
@@ -581,15 +581,6 @@
           "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
           "dev": true
         },
-        "convert-source-map": {
-          "version": "1.7.0",
-          "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.7.0.tgz",
-          "integrity": "sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==",
-          "dev": true,
-          "requires": {
-            "safe-buffer": "~5.1.1"
-          }
-        },
         "debug": {
           "version": "4.1.1",
           "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
@@ -617,6 +608,15 @@
             "validate-npm-package-license": "^3.0.1"
           }
         },
+        "p-map": {
+          "version": "4.0.0",
+          "resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz",
+          "integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==",
+          "dev": true,
+          "requires": {
+            "aggregate-error": "^3.0.0"
+          }
+        },
         "parse-json": {
           "version": "5.0.0",
           "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.0.0.tgz",
@@ -734,9 +734,9 @@
       "dev": true
     },
     "blueimp-md5": {
-      "version": "2.12.0",
-      "resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.12.0.tgz",
-      "integrity": "sha512-zo+HIdIhzojv6F1siQPqPFROyVy7C50KzHv/k/Iz+BtvtVzSHXiMXOpq2wCfNkeBqdCv+V8XOV96tsEt2W/3rQ==",
+      "version": "2.13.0",
+      "resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.13.0.tgz",
+      "integrity": "sha512-lmp0m647R5e77ORduxLW5mISIDcvgJZa52vMBv5uVI3UmSWTQjkJsZVBfaFqQPw/QFogJwvY6e3Gl9nP+Loe+Q==",
       "dev": true
     },
     "body-parser": {
@@ -1042,9 +1042,9 @@
       }
     },
     "cli-spinners": {
-      "version": "2.2.0",
-      "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.2.0.tgz",
-      "integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==",
+      "version": "2.3.0",
+      "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.3.0.tgz",
+      "integrity": "sha512-Xs2Hf2nzrvJMFKimOR7YR0QwZ8fc0u98kdtwN1eNAZzNQgH3vK2pXzff6GJtKh7S5hoJ87ECiAiZFS2fb5Ii2w==",
       "dev": true
     },
     "cli-truncate": {
@@ -1290,6 +1290,15 @@
       "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
       "dev": true
     },
+    "convert-source-map": {
+      "version": "1.7.0",
+      "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.7.0.tgz",
+      "integrity": "sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==",
+      "dev": true,
+      "requires": {
+        "safe-buffer": "~5.1.1"
+      }
+    },
     "convert-to-spaces": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/convert-to-spaces/-/convert-to-spaces-1.0.2.tgz",
@@ -1637,9 +1646,9 @@
       "dev": true
     },
     "emittery": {
-      "version": "0.5.1",
-      "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.5.1.tgz",
-      "integrity": "sha512-sYZXNHH9PhTfs98ROEFVC3bLiR8KSqXQsEHIwZ9J6H0RaQObC3JYq4G8IvDd0b45/LxfGKYBpmaUN4LiKytaNw==",
+      "version": "0.6.0",
+      "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.6.0.tgz",
+      "integrity": "sha512-6EMRGr9KzYWp8DzHFZsKVZBsMO6QhAeHMeHND8rhyBNCHKMLpgW9tZv40bwN3rAIKRS5CxcK8oLRKUJSB9h7yQ==",
       "dev": true
     },
     "emoji-regex": {
@@ -2388,9 +2397,9 @@
       "dev": true
     },
     "fastq": {
-      "version": "1.6.1",
-      "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.6.1.tgz",
-      "integrity": "sha512-mpIH5sKYueh3YyeJwqtVo8sORi0CgtmkVbK6kZStpQlZBYQuTzG2CZ7idSiJuA7bY0SFCWUc5WIs+oYumGCQNw==",
+      "version": "1.7.0",
+      "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.7.0.tgz",
+      "integrity": "sha512-YOadQRnHd5q6PogvAR/x62BGituF2ufiEA6s8aavQANw5YKHERI4AREboX6KotzP8oX2klxYF2wcV/7bn1clfQ==",
       "dev": true,
       "requires": {
         "reusify": "^1.0.4"
@@ -3304,9 +3313,9 @@
       }
     },
     "is-installed-globally": {
-      "version": "0.3.1",
-      "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.3.1.tgz",
-      "integrity": "sha512-oiEcGoQbGc+3/iijAijrK2qFpkNoNjsHOm/5V5iaeydyrS/hnwaRCEgH5cpW0P3T1lSjV5piB7S5b5lEugNLhg==",
+      "version": "0.3.2",
+      "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.3.2.tgz",
+      "integrity": "sha512-wZ8x1js7Ia0kecP/CHM/3ABkAmujX7WPvQk6uu3Fly/Mk44pySulQpnHG46OMjHGXApINnV4QhY3SWnECO2z5g==",
       "dev": true,
       "requires": {
         "global-dirs": "^2.0.1",
@@ -4217,6 +4226,12 @@
         "brace-expansion": "^1.1.7"
       }
     },
+    "minimist": {
+      "version": "1.2.5",
+      "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+      "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
+      "dev": true
+    },
     "mkdirp": {
       "version": "0.5.5",
       "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
@@ -5113,14 +5128,6 @@
         "ini": "~1.3.0",
         "minimist": "^1.2.0",
         "strip-json-comments": "~2.0.1"
-      },
-      "dependencies": {
-        "minimist": {
-          "version": "1.2.5",
-          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
-          "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
-          "dev": true
-        }
       }
     },
     "react-is": {
diff --git a/package.json b/package.json
index 6f6ea63..b794ae1 100644
--- a/package.json
+++ b/package.json
@@ -76,7 +76,7 @@
     "yaml-js": "^0.2.3"
   },
   "devDependencies": {
-    "ava": "^3.5.1",
+    "ava": "^3.6.0",
     "benchmark": "^2.1.4",
     "express": "^4.16.4",
     "handlebars": "^4.7.6",
diff --git a/src/Compiler.js b/src/Compiler.js
index f9e2c68..37246d1 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -22,12 +22,13 @@ const generate = async (source, html, options) => {
   const renderer = new Renderer()
   const { tree, statistics, warnings, errors } = await renderer.render(source, html, options)
   const generator = new Generator()
-  const { template } = generator.generate(tree)
+  const { template, dynamic } = generator.generate(tree)
   return {
     template,
     statistics: statistics.serialize(),
     errors: errors.concat(validateOptions(options)).map(normalizeErrors),
-    warnings
+    warnings,
+    dynamic
   }
 }
 
diff --git a/src/Generator.js b/src/Generator.js
index 9d80dcd..0d155ab 100644
--- a/src/Generator.js
+++ b/src/Generator.js
@@ -11,7 +11,8 @@ class Generator {
   generate (tree) {
     const { params } = analyze(tree)
     const template = new Function(`return function render(${params}) {\n${tree.source}}`)() // eslint-disable-line
-    return { template }
+    const dynamic = params.length > 0
+    return { template, dynamic }
   }
 }
 


Test patch:
diff --git a/test/helpers/compile.js b/test/helpers/compile.js
index 3561ff3..2606f35 100644
--- a/test/helpers/compile.js
+++ b/test/helpers/compile.js
@@ -1,12 +1,13 @@
 const { compile } = require('../..')
 
 module.exports = async function (source, options) {
-  return compile(source, { compact: true, ...options }).then(({ template, statistics, errors, warnings, from }) => {
+  return compile(source, { compact: true, ...options }).then((output) => {
     if (process.env.DEBUG === 'boxwood') {
+      const { template, warnings, errors } = output
       console.log(template.toString())
       if (warnings.length > 0) { console.log(warnings) }
       if (errors.length > 0) { console.log(errors) }
     }
-    return { template, statistics, errors, warnings, from }
+    return output
   })
 }
diff --git a/test/spec/compiler.spec.js b/test/spec/compiler.spec.js
index f95cf02..6fe67e6 100644
--- a/test/spec/compiler.spec.js
+++ b/test/spec/compiler.spec.js
@@ -130,8 +130,21 @@ test('compiler: returns errors for invalid styles option', async assert => {
 test('compiler: caches templates and related data', async assert => {
   const output1 = await compile('<div>foo</div>', { cache: true })
   const output2 = await compile('<div>foo</div>', { cache: true })
-  const output3 = await compile('<div>bar</div>', { cache: true })
+  const output3 = await compile('<div>{bar}</div>', { cache: true })
   assert.deepEqual(output1.from, 'generator')
+  assert.deepEqual(output1.dynamic, false)
   assert.deepEqual(output2.from, 'cache')
+  assert.deepEqual(output2.dynamic, false)
   assert.deepEqual(output3.from, 'generator')
+  assert.deepEqual(output3.dynamic, true)
+})
+
+test('compiler: returns dynamic flag that is set to true if the template uses any data', async assert => {
+  const { dynamic } = await compile('<div>{foo}</div>')
+  assert.deepEqual(dynamic, true)
+})
+
+test('compiler: returns dynamic flag that is set to false if the template does not use any data', async assert => {
+  const { dynamic } = await compile('<div>foo</div>')
+  assert.deepEqual(dynamic, false)
 })