Skip to content

Commit

Permalink
chore: better error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
shepherdwind committed Nov 12, 2021
1 parent 3f79104 commit 1ae4423
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
1 change: 0 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ All notable changes to this project will be documented in this file. Dates are d
- fix: support null as var, fix #139 [`#139`](https://github.com/shepherdwind/velocity.js/issues/139)
- chore: support auto changelog [`984fc38`](https://github.com/shepherdwind/velocity.js/commit/984fc387b9dd1b09887a622af49005b4bd27de93)
- chore: update history.md [`600548e`](https://github.com/shepherdwind/velocity.js/commit/600548eaa8789d7f8b9c3762b8af7794bfbc9b71)

#### [v2.0.3](https://github.com/shepherdwind/velocity.js/compare/v2.0.2...v2.0.3)

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "velocityjs",
"description": "Velocity Template Language(VTL) for JavaScript",
"version": "2.0.4",
"version": "2.0.5-beta",
"license": "MIT",
"keywords": [
"velocity template"
Expand All @@ -23,6 +23,7 @@
"path": false
},
"devDependencies": {
"amplify-appsync-simulator": "^1.27.8",
"auto-changelog": "^2.3.0",
"coveralls": "~2.11.2",
"istanbul": "~0.3.5",
Expand All @@ -33,7 +34,7 @@
},
"scripts": {
"test": "mocha test --require should",
"prepublishOnly": "npm run version && PACKAGE_VERSION=$(node -p -e \"require('./package.json').version\") npm run tag",
"prepublishOnly": "PACKAGE_VERSION=$(node -p -e \"require('./package.json').version\") npm run tag",
"version": "npm run changelog && git add . && git commit -m 'chore: update history.md' && git push origin",
"tag": "if [[ $PACKAGE_VERSION != *\"beta\"* ]];then git tag v$PACKAGE_VERSION && git push --tags; fi",
"changelog": "auto-changelog -p -u"
Expand Down
2 changes: 1 addition & 1 deletion src/compile/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = function(Velocity, utils) {
var err = '\n at ' + text + ' L/N ' + pos.first_line + ':' + pos.first_column;
e.name = '';
e.message += err;
throw new Error(e);
throw e;
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function(Velocity, utils) {

} else {

return this.getReferences(literal);
ret = this.getReferences(literal);

}

Expand Down
4 changes: 2 additions & 2 deletions src/compile/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ module.exports = function(Velocity, utils) {
var text = Velocity.Helper.getRefText(ast);
var err = ' on ' + text + ' at L/N ' +
pos.first_line + ':' + pos.first_column;
e.name = '';
// e.name = '';
e.message += err;
throw new Error(e);
throw e;
}

} else {
Expand Down
46 changes: 46 additions & 0 deletions test/issues.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const utils = require('amplify-appsync-simulator/lib/velocity/util');
const mapper = require('amplify-appsync-simulator/lib/velocity/value-mapper/mapper');
const assert = require("assert");
const Velocity = require('../src/velocity');

const { Compile, parse } = Velocity;

function createVtlContext(args) {
const util = utils.create([], new Date(Date.now()), Object())
const context = {
args,
arguments: args
}
return {
util,
utils: util,
ctx: context,
context
}
}

describe('test/issues.test.js', () => {
it('#140', () => {
const ast = parse(`
#set( $keyFields = ["id"] )
#foreach( $entry in $util.map.copyAndRemoveAllKeys($ctx.args.input, $keyFields).entrySet() )
$entry.toJSON()
#end
`);

const compiler = new Compile(ast, {
valueMapper: mapper.map,
escape: false
})
const args = {
input: mapper.map({
id: '000',
timestamp: '2021-12-01T08:00:00.000Z',
})
}
const context = createVtlContext(args);
const result = compiler.render(context);
// console.log(result);
assert.equal(result.trim(), '{key=timestamp, value=2021-12-01T08:00:00.000Z}');
});
});

0 comments on commit 1ae4423

Please sign in to comment.