Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amplify-velocity-template): support 'get' and 'set' of array vars #5741

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 4 additions & 20 deletions packages/amplify-velocity-template/src/compile/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,10 @@ module.exports = function(Velocity, utils) {
var id = property.id;
var ret = '';

// getter 处理
if (id.indexOf('get') === 0 && !(id in baseRef)) {
if (id.length === 3) {
// get('address')
ret = getter(baseRef, this.getLiteral(property.args[0]));
} else {
// getAddress()
ret = getter(baseRef, id.slice(3));
}

return ret;

// setter 处理
} else if (id.indexOf('set') === 0 && !baseRef[id]) {
baseRef[id.slice(3)] = this.getLiteral(property.args[0]);
// $page.setName(123)
baseRef.toString = function() {
return '';
};
return baseRef;
if (id === 'get' && !baseRef[id]) {
return baseRef[this.getLiteral(property.args[0])];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason in removing the getter? Referencing this pr: https://github.com/shepherdwind/velocity.js/pull/133/files

} else if (id === 'set' && !baseRef[id] && typeof baseRef.splice === 'function') {
return baseRef[this.getLiteral(property.args[0])] = this.getLiteral(property.args[1]);
} else if (id.indexOf('is') === 0 && !(id in baseRef)) {
return getter(baseRef, id.slice(2));
} else if (id === 'keySet' && !baseRef[id]) {
Expand Down