mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-05 05:27:59 +08:00
* fix object dot notation bug * add test case
This commit is contained in:
parent
9931b715cd
commit
46b3bcd707
@ -116,7 +116,7 @@ export function parseModel (val: string): Object {
|
|||||||
len = str.length
|
len = str.length
|
||||||
index = expressionPos = expressionEndPos = 0
|
index = expressionPos = expressionEndPos = 0
|
||||||
|
|
||||||
if (val.indexOf('[') < 0) {
|
if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {
|
||||||
return {
|
return {
|
||||||
exp: val,
|
exp: val,
|
||||||
idx: null
|
idx: null
|
||||||
|
@ -1,12 +1,24 @@
|
|||||||
import { parseModel } from 'compiler/helpers'
|
import { parseModel } from 'compiler/helpers'
|
||||||
|
|
||||||
describe('model expression parser', () => {
|
describe('model expression parser', () => {
|
||||||
|
it('parse object dot notation', () => {
|
||||||
|
const res = parseModel('a.b.c')
|
||||||
|
expect(res.exp).toBe('a.b.c')
|
||||||
|
expect(res.idx).toBe(null)
|
||||||
|
})
|
||||||
|
|
||||||
it('parse string in brackets', () => {
|
it('parse string in brackets', () => {
|
||||||
const res = parseModel('a["b"][c]')
|
const res = parseModel('a["b"][c]')
|
||||||
expect(res.exp).toBe('a["b"]')
|
expect(res.exp).toBe('a["b"]')
|
||||||
expect(res.idx).toBe('c')
|
expect(res.idx).toBe('c')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('parse brackets with object dot notation', () => {
|
||||||
|
const res = parseModel('a["b"][c].xxx')
|
||||||
|
expect(res.exp).toBe('a["b"][c].xxx')
|
||||||
|
expect(res.idx).toBe(null)
|
||||||
|
})
|
||||||
|
|
||||||
it('parse nested brackets', () => {
|
it('parse nested brackets', () => {
|
||||||
const res = parseModel('a[i[c]]')
|
const res = parseModel('a[i[c]]')
|
||||||
expect(res.exp).toBe('a')
|
expect(res.exp).toBe('a')
|
||||||
|
Loading…
Reference in New Issue
Block a user