-
Notifications
You must be signed in to change notification settings - Fork 668
feat: throw error if the read-only property is tried to change #749
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
Changes from 2 commits
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 |
---|---|---|
|
@@ -5,12 +5,21 @@ import type VueWrapper from './vue-wrapper' | |
import { throwError, warn } from 'shared/util' | ||
|
||
export default class WrapperArray implements BaseWrapper { | ||
wrappers: Array<Wrapper | VueWrapper>; | ||
length: number; | ||
+wrappers: Array<Wrapper | VueWrapper>; | ||
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. Cool I didn't know you could specify read only with flow 👍 |
||
+length: number; | ||
|
||
constructor (wrappers: Array<Wrapper | VueWrapper>) { | ||
this.wrappers = wrappers || [] | ||
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.
|
||
this.length = this.wrappers.length | ||
const length = wrappers.length | ||
// $FlowIgnore | ||
Object.defineProperty(this, 'wrappers', { | ||
get: () => wrappers, | ||
set: () => throwError(`WrapperArray.wrappers is read-only`) | ||
}) | ||
// $FlowIgnore | ||
Object.defineProperty(this, 'length', { | ||
get: () => length, | ||
set: () => throwError(`WrapperArray.length is read-only`) | ||
}) | ||
} | ||
|
||
at (index: number): Wrapper | VueWrapper { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import { orderWatchers } from './order-watchers' | |
|
||
export default class Wrapper implements BaseWrapper { | ||
+vnode: VNode | null; | ||
_vnode: VNode | null; | ||
+vm: Component | null; | ||
_emitted: { [name: string]: Array<Array<any>> }; | ||
_emittedByOrder: Array<{ name: string, args: Array<any> }>; | ||
|
@@ -39,27 +40,28 @@ export default class Wrapper implements BaseWrapper { | |
const element = node instanceof Element ? node : node.elm | ||
// Prevent redefine by VueWrapper | ||
if (this.constructor.name === 'Wrapper') { | ||
this._vnode = vnode | ||
// $FlowIgnore | ||
Object.defineProperty(this, 'vnode', { | ||
get: () => vnode, | ||
set: () => {} | ||
get: () => this._vnode, | ||
set: () => throwError(`Wrapper.vnode is read-only`) | ||
}) | ||
// $FlowIgnore | ||
Object.defineProperty(this, 'element', { | ||
get: () => element, | ||
set: () => {} | ||
set: () => throwError(`Wrapper.element is read-only`) | ||
}) | ||
// $FlowIgnore | ||
Object.defineProperty(this, 'vm', { | ||
get: () => undefined, | ||
set: () => {} | ||
set: () => throwError(`Wrapper.vm is read-only`) | ||
}) | ||
} | ||
const frozenOptions = Object.freeze(options) | ||
// $FlowIgnore | ||
Object.defineProperty(this, 'options', { | ||
get: () => frozenOptions, | ||
set: () => {} | ||
set: () => throwError(`${this.constructor.name}.options is read-only`) | ||
}) | ||
if ( | ||
this.vnode && | ||
|
@@ -399,7 +401,6 @@ export default class Wrapper implements BaseWrapper { | |
} | ||
|
||
return !!( | ||
this.element && | ||
this.element.getAttribute && | ||
this.element.matches(selector) | ||
) | ||
|
@@ -667,7 +668,7 @@ export default class Wrapper implements BaseWrapper { | |
}) | ||
|
||
// $FlowIgnore : Problem with possibly null this.vm | ||
this.vnode = this.vm._vnode | ||
this._vnode = this.vm._vnode | ||
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. @eddyerburgh 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. You can flowignore it 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. Since vueWrapper.vnode is read-only, I removed this line. |
||
orderWatchers(this.vm || this.vnode.context.$root) | ||
Vue.config.silent = originalConfig | ||
} | ||
|
@@ -814,7 +815,7 @@ export default class Wrapper implements BaseWrapper { | |
*/ | ||
destroy () { | ||
if (!this.isVueInstance()) { | ||
throwError(`wrapper.destroy() can only be called on a Vue ` + `instance`) | ||
throwError(`wrapper.destroy() can only be called on a Vue instance`) | ||
} | ||
|
||
if (this.element.parentNode) { | ||
|
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 can be a Wrapper or a VueWrapper, I think just go with:I don't think we need to distinguish between a wrapper and a VueWrapper, I think just go with wrapper:
wrapper.vnode is read-only