bentonam / fakeit

Generates JSON documents based on models defined in YAML and adds them to a Couchbase Bucket
MIT License
86 stars 21 forks source link

using "let" with variable name of "class" #193

Open jadTalbert opened 4 years ago

jadTalbert commented 4 years ago

Ran into this issue today when faking a model. It seems that using class as a variable name within the build section of the yaml file throws the following error:

✖ Models (0/1)
[16:33:25] ✖ error: Error: Function Error in model 'test', for property: properties._class.data.build, Reason: Unexpected token class
    at /root/.nvm/versions/node/v10.0.0/lib/node_modules/fakeit/dist/models.js:724:13
    at Array.forEach (<anonymous>)
    at parseModelFunctions (/root/.nvm/versions/node/v10.0.0/lib/node_modules/fakeit/dist/models.js:680:9)
    at Models._callee4$ (/root/.nvm/versions/node/v10.0.0/lib/node_modules/fakeit/dist/models.js:577:17)
    at tryCatch (/root/.nvm/versions/node/v10.0.0/lib/node_modules/fakeit/node_modules/regenerator-runtime/runtime.js:65:40)
    at Generator.invoke [as _invoke] (/root/.nvm/versions/node/v10.0.0/lib/node_modules/fakeit/node_modules/regenerator-runtime/runtime.js:303:22)
    at Generator.prototype.(anonymous function) [as next] (/root/.nvm/versions/node/v10.0.0/lib/node_modules/fakeit/node_modules/regenerator-runtime/runtime.js:117:21)
    at step (/root/.nvm/versions/node/v10.0.0/lib/node_modules/fakeit/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)

To fix the issue, I simply prefaced the variable with an underscore _class A partial example of the yaml section throwing the error above is listed here:

  _class:
    description: spring data _class
    data:
      type: string
      build: |
        let class = "com.my.java.package.name.here"
        return class;