diff --git a/src/path.js b/src/path.js index e75605532..5f2206c33 100644 --- a/src/path.js +++ b/src/path.js @@ -76,6 +76,33 @@ pathStateMachine[IN_DOUBLE_QUOTE] = { 'else': [IN_DOUBLE_QUOTE, APPEND] } +/** + * Check if an expression is a literal value. + * + * @param {String} exp + * @return {Boolean} + */ + +const literalValueRE = /^\s?(true|false|-?[\d\.]+|'[^']*'|"[^"]*")\s?$/ +function isLiteral (exp) { + return literalValueRE.test(exp) +} + +/** + * Strip quotes from a string + * + * @param {String} str + * @return {String | false} + */ + +function stripQuotes (str) { + const a = str.charCodeAt(0) + const b = str.charCodeAt(str.length - 1) + return a === b && (a === 0x22 || a === 0x27) + ? str.slice(1, -1) + : str +} + /** * Determine the type of a character in a keypath. * @@ -133,8 +160,6 @@ function getPathCharType (ch) { */ function formatSubPath (path) { - const { isLiteral, stripQuotes } = exports.Vue.util - const trimmed = path.trim() // invalid leading 0 if (path.charAt(0) === '0' && isNaN(path)) { return false } diff --git a/test/specs/issues.js b/test/specs/issues.js index f5f52f16c..3204208df 100644 --- a/test/specs/issues.js +++ b/test/specs/issues.js @@ -27,4 +27,13 @@ describe('issues', () => { ) }) }) + + describe('#42, #43', () => { + it('should not be occured error', () => { + assert.equal( + vm.$t('message[\'hello\']'), + locales[Vue.config.lang]['message']['hello'] + ) + }) + }) })