-
Notifications
You must be signed in to change notification settings - Fork 15
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 parser for computed properties with an explicit getter function #12
Changes from all commits
e47c626
05c8f74
cd503e0
3a6278e
3e99e20
1025369
af38128
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,15 +59,16 @@ class Parser extends EventEmitter { | |
entry.name = Object.keys(entry.value)[0] | ||
entry.value = entry.value[entry.name] | ||
|
||
if (entry.value instanceof utils.NodeFunction) { | ||
switch (property.key.name) { | ||
case 'computed': | ||
entry.dependencies = utils.getDependencies(entry.value, this.source.script) | ||
break | ||
|
||
default: | ||
entry.params = entry.value.params | ||
if (property.key.name === 'computed') { | ||
if (entry.value instanceof utils.NodeFunction) { | ||
entry.dependencies = utils.getDependencies(entry.value, this.source.script) | ||
} else if (entry.value instanceof Object && entry.value.get instanceof utils.NodeFunction) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, ok I will change it to return an empty array and change the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for the quick response! |
||
entry.dependencies = utils.getDependencies(entry.value.get, this.source.script) | ||
} else { | ||
entry.dependencies = [] | ||
} | ||
} else if (entry.value instanceof utils.NodeFunction) { | ||
entry.params = entry.value.params | ||
} else if (property.key.name === 'props') { | ||
if (entry.describeModel) { | ||
entry.name = 'v-model' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -463,6 +463,80 @@ describe('Parser', () => { | |
}) | ||
}) | ||
|
||
it('should successfully emit a computed property item with a getter', (done) => { | ||
const filename = './fixtures/checkbox.vue' | ||
const script = ` | ||
export default { | ||
computed: { | ||
/** | ||
* ID computed prop | ||
* | ||
* @private | ||
*/ | ||
idGetter: { | ||
get () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mistaken... your changes already cover this purpose. |
||
const value = this.value | ||
return this.name + value | ||
} | ||
} | ||
} | ||
} | ||
` | ||
const options = { | ||
source: { script }, | ||
filename | ||
} | ||
const parser = new Parser(options) | ||
const expected = { | ||
name: 'idGetter', | ||
keywords: [{ name: 'private', description: '' }], | ||
visibility: 'private', | ||
description: 'ID computed prop', | ||
dependencies: ['value', 'name'] | ||
} | ||
|
||
parser.walk().on('computed', (prop) => { | ||
assert.equal(prop.name, expected.name) | ||
assert.deepEqual(prop.keywords, expected.keywords) | ||
assert.equal(prop.visibility, expected.visibility) | ||
assert.equal(prop.description, expected.description) | ||
assert.equal(prop.value.get.type, 'FunctionExpression') | ||
assert.deepEqual(prop.dependencies, expected.dependencies) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should ignore functions other than get on computed property', (done) => { | ||
const filename = './fixtures/checkbox.vue' | ||
const script = ` | ||
export default { | ||
computed: { | ||
/** | ||
* ID computed prop | ||
* | ||
* @private | ||
*/ | ||
idGetter: { | ||
foo () { | ||
const value = this.value | ||
return this.name + value | ||
} | ||
} | ||
} | ||
} | ||
` | ||
const options = { | ||
source: { script }, | ||
filename | ||
} | ||
const parser = new Parser(options) | ||
|
||
parser.walk().on('computed', (prop) => { | ||
assert.deepEqual(prop.dependencies, []) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should successfully emit an unknow item', (done) => { | ||
const filename = './fixtures/checkbox.vue' | ||
const defaultMethodVisibility = 'public' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch need to be cover by unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the unit tests, coverage is back up :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. Now you have to add a unit test to cover the case where we have a missing
get()
function. Some think like: