From 31323b685044e20fe2dee4f0d5d7c712139800ea Mon Sep 17 00:00:00 2001 From: exoego Date: Thu, 14 Mar 2019 07:17:34 +0900 Subject: [PATCH] feat(path): Whitespace except 0x20 should be ignored --- dist/vue-i18n.common.js | 6 +++--- dist/vue-i18n.esm.js | 6 +++--- dist/vue-i18n.js | 6 +++--- dist/vue-i18n.min.js | 2 +- src/path.js | 2 +- test/unit/path.test.js | 10 ++++++++++ 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dist/vue-i18n.common.js b/dist/vue-i18n.common.js index 08bf73c64..7ca6a62a7 100644 --- a/dist/vue-i18n.common.js +++ b/dist/vue-i18n.common.js @@ -679,7 +679,7 @@ pathStateMachine[IN_IDENT] = { 'ident': [IN_IDENT, APPEND], '0': [IN_IDENT, APPEND], 'number': [IN_IDENT, APPEND], - 'ws': [IN_PATH, PUSH], + 'ws': [IN_IDENT], '.': [BEFORE_IDENT, PUSH], '[': [IN_SUB_PATH, PUSH], 'eof': [AFTER_PATH, PUSH] @@ -749,7 +749,6 @@ function getPathCharType (ch) { case 0x2D: // - return 'ident' - case 0x20: // Space case 0x09: // Tab case 0x0A: // Newline case 0x0D: // Return @@ -781,7 +780,8 @@ function formatSubPath (path) { * Parse a string path into an array of segments */ -function parse$1 (path) { +function +parse$1 (path) { var keys = []; var index = -1; var mode = BEFORE_PATH; diff --git a/dist/vue-i18n.esm.js b/dist/vue-i18n.esm.js index 4451c7667..fb4a8a61b 100644 --- a/dist/vue-i18n.esm.js +++ b/dist/vue-i18n.esm.js @@ -677,7 +677,7 @@ pathStateMachine[IN_IDENT] = { 'ident': [IN_IDENT, APPEND], '0': [IN_IDENT, APPEND], 'number': [IN_IDENT, APPEND], - 'ws': [IN_PATH, PUSH], + 'ws': [IN_IDENT], '.': [BEFORE_IDENT, PUSH], '[': [IN_SUB_PATH, PUSH], 'eof': [AFTER_PATH, PUSH] @@ -747,7 +747,6 @@ function getPathCharType (ch) { case 0x2D: // - return 'ident' - case 0x20: // Space case 0x09: // Tab case 0x0A: // Newline case 0x0D: // Return @@ -779,7 +778,8 @@ function formatSubPath (path) { * Parse a string path into an array of segments */ -function parse$1 (path) { +function +parse$1 (path) { var keys = []; var index = -1; var mode = BEFORE_PATH; diff --git a/dist/vue-i18n.js b/dist/vue-i18n.js index 23adf4f77..d604d0285 100644 --- a/dist/vue-i18n.js +++ b/dist/vue-i18n.js @@ -683,7 +683,7 @@ 'ident': [IN_IDENT, APPEND], '0': [IN_IDENT, APPEND], 'number': [IN_IDENT, APPEND], - 'ws': [IN_PATH, PUSH], + 'ws': [IN_IDENT], '.': [BEFORE_IDENT, PUSH], '[': [IN_SUB_PATH, PUSH], 'eof': [AFTER_PATH, PUSH] @@ -753,7 +753,6 @@ case 0x2D: // - return 'ident' - case 0x20: // Space case 0x09: // Tab case 0x0A: // Newline case 0x0D: // Return @@ -785,7 +784,8 @@ * Parse a string path into an array of segments */ - function parse$1 (path) { + function + parse$1 (path) { var keys = []; var index = -1; var mode = BEFORE_PATH; diff --git a/dist/vue-i18n.min.js b/dist/vue-i18n.min.js index cb8a1e801..cfab91add 100644 --- a/dist/vue-i18n.min.js +++ b/dist/vue-i18n.min.js @@ -3,4 +3,4 @@ * (c) 2019 kazuya kawaguchi * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueI18n=e()}(this,function(){"use strict";function t(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function e(t){return null!==t&&"object"==typeof t}function n(t){return L.call(t)===O}function r(t){return null===t||void 0===t}function i(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var r=null,i=null;return 1===t.length?e(t[0])||Array.isArray(t[0])?i=t[0]:"string"==typeof t[0]&&(r=t[0]):2===t.length&&("string"==typeof t[0]&&(r=t[0]),(e(t[1])||Array.isArray(t[1]))&&(i=t[1])),{locale:r,params:i}}function a(t){return JSON.parse(JSON.stringify(t))}function o(t,e){if(t.length){var n=t.indexOf(e);if(n>-1)return t.splice(n,1)}}function s(t,e){return C.call(t,e)}function l(t){for(var n=arguments,r=Object(t),i=1;i0;)e[n]=arguments[n+1];var r=this.$i18n;return r._t.apply(r,[t,r.locale,r._getMessages(),this].concat(e))},t.prototype.$tc=function(t,e){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];var i=this.$i18n;return i._tc.apply(i,[t,i.locale,i._getMessages(),this,e].concat(n))},t.prototype.$te=function(t,e){var n=this.$i18n;return n._te(t,n.locale,n._getMessages(),e)},t.prototype.$d=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).d.apply(e,[t].concat(n))},t.prototype.$n=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).n.apply(e,[t].concat(n))}}function f(t,e,n){m(t,n)&&v(t,e,n)}function h(t,e,n,r){if(m(t,n)){var i=n.context.$i18n;_(t,n)&&c(e.value,e.oldValue)&&c(t._localeMessage,i.getLocaleMessage(i.locale))||v(t,e,n)}}function p(e,n,r,i){if(!r.context)return void t("Vue instance does not exists in VNode context");var a=r.context.$i18n||{};n.modifiers.preserve||a.preserveDirectiveContent||(e.textContent=""),e._vt=void 0,delete e._vt,e._locale=void 0,delete e._locale,e._localeMessage=void 0,delete e._localeMessage}function m(e,n){var r=n.context;return r?!!r.$i18n||(t("VueI18n instance does not exists in Vue instance"),!1):(t("Vue instance does not exists in VNode context"),!1)}function _(t,e){var n=e.context;return t._locale===n.$i18n.locale}function v(e,n,r){var i,a,o=n.value,s=g(o),l=s.path,c=s.locale,u=s.args,f=s.choice;if(!l&&!c&&!u)return void t("value type not supported");if(!l)return void t("`path` is required in v-t directive");var h=r.context;e._vt=e.textContent=f?(i=h.$i18n).tc.apply(i,[l,f].concat(y(c,u))):(a=h.$i18n).t.apply(a,[l].concat(y(c,u))),e._locale=h.$i18n.locale,e._localeMessage=h.$i18n.getLocaleMessage(h.$i18n.locale)}function g(t){var e,r,i,a;return"string"==typeof t?e=t:n(t)&&(e=t.path,r=t.locale,i=t.args,a=t.choice),{path:e,locale:r,args:i,choice:a}}function y(t,e){var r=[];return t&&r.push(t),e&&(Array.isArray(e)||n(e))&&r.push(e),r}function d(t){d.installed=!0,T=t;T.version&&Number(T.version.split(".")[0]);u(T),T.mixin(W),T.directive("t",{bind:f,update:h,unbind:p}),T.component(M.name,M),T.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}function b(t){for(var e=[],n=0,r="";n0)f--,u=P,h[I]();else{if(f=0,!1===(n=D(n)))return!1;h[R]()}};null!==u;)if(c++,"\\"!==(e=t[c])||!function(){var e=t[c+1];if(u===E&&"'"===e||u===U&&'"'===e)return c++,r="\\"+e,h[I](),!0}()){if(i=w(e),s=G[u],(a=s[i]||s.else||q)===q)return;if(u=a[0],(o=h[a[1]])&&(r=a[2],r=void 0===r?e:r,!1===o()))return;if(u===J)return l}}var T,L=Object.prototype.toString,O="[object Object]",C=Object.prototype.hasOwnProperty,W={beforeCreate:function(){var t=this.$options;if(t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n){if(t.i18n instanceof et){if(t.__i18n)try{var e={};t.__i18n.forEach(function(t){e=l(e,JSON.parse(t))}),Object.keys(e).forEach(function(n){t.i18n.mergeLocaleMessage(n,e[n])})}catch(t){}this._i18n=t.i18n,this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0}else if(n(t.i18n)){if(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et&&(t.i18n.root=this.$root,t.i18n.formatter=this.$root.$i18n.formatter,t.i18n.fallbackLocale=this.$root.$i18n.fallbackLocale,t.i18n.silentTranslationWarn=this.$root.$i18n.silentTranslationWarn,t.i18n.silentFallbackWarn=this.$root.$i18n.silentFallbackWarn,t.i18n.pluralizationRules=this.$root.$i18n.pluralizationRules,t.i18n.preserveDirectiveContent=this.$root.$i18n.preserveDirectiveContent),t.__i18n)try{var r={};t.__i18n.forEach(function(t){r=l(r,JSON.parse(t))}),t.i18n.messages=r}catch(t){}this._i18n=new et(t.i18n),this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0,(void 0===t.i18n.sync||t.i18n.sync)&&(this._localeWatcher=this.$i18n.watchLocale())}}else this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et?(this._i18n=this.$root.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0):t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof et&&(this._i18n=t.parent.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0)},beforeDestroy:function(){if(this._i18n){var t=this;this.$nextTick(function(){t._subscribing&&(t._i18n.unsubscribeDataChanging(t),delete t._subscribing),t._i18nWatcher&&(t._i18nWatcher(),t._i18n.destroyVM(),delete t._i18nWatcher),t._localeWatcher&&(t._localeWatcher(),delete t._localeWatcher),t._i18n=null})}}},M={name:"i18n",functional:!0,props:{tag:{type:String,default:"span"},path:{type:String,required:!0},locale:{type:String},places:{type:[Array,Object]}},render:function(t,e){var n=e.props,r=e.data,i=e.children,a=e.parent,o=a.$i18n;if(i=(i||[]).filter(function(t){return t.tag||(t.text=t.text.trim())}),!o)return i;var s=n.path,l=n.locale,c={},u=n.places||{},f=(Array.isArray(u)?u.length:Object.keys(u).length,i.every(function(t){if(t.data&&t.data.attrs){var e=t.data.attrs.place;return void 0!==e&&""!==e}}));return Array.isArray(u)?u.forEach(function(t,e){c[e]=t}):Object.keys(u).forEach(function(t){c[t]=u[t]}),i.forEach(function(t,e){var n=f?""+t.data.attrs.place:""+e;c[n]=t}),t(n.tag,r,o.i(s,l,c))}},j=function(){this._caches=Object.create(null)};j.prototype.interpolate=function(t,e){if(!e)return[t];var n=this._caches[t];return n||(n=b(t),this._caches[t]=n),$(n,e)};var A=/^(?:\d)+/,N=/^(?:\w)+/,I=0,R=1,V=2,S=3,z=0,P=4,E=5,U=6,J=7,q=8,G=[];G[z]={ws:[z],ident:[3,I],"[":[P],eof:[J]},G[1]={ws:[1],".":[2],"[":[P],eof:[J]},G[2]={ws:[2],ident:[3,I],0:[3,I],number:[3,I]},G[3]={ident:[3,I],0:[3,I],number:[3,I],ws:[1,R],".":[2,R],"[":[P,R],eof:[J,R]},G[P]={"'":[E,I],'"':[U,I],"[":[P,V],"]":[1,S],eof:q,else:[P,I]},G[E]={"'":[P,I],eof:q,else:[E,I]},G[U]={'"':[P,I],eof:q,else:[U,I]};var B=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/,H=function(){this._cache=Object.create(null)};H.prototype.parsePath=function(t){var e=this._cache[t];return e||(e=x(t))&&(this._cache[t]=e),e||[]},H.prototype.getPathValue=function(t,n){if(!e(t))return null;var r=this.parsePath(n);if(0===r.length)return null;for(var i=r.length,a=t,o=0;o=0||u.indexOf("@.")>=0)&&(u=this._link(t,e,u,a,"raw",s,l)),this._render(u,o,s,i)},et.prototype._link=function(t,e,n,r,i,a,o){var s=this,l=n,c=l.match(Q);for(var u in c)if(c.hasOwnProperty(u)){var f=c[u],h=f.match(X),p=h[0],m=h[1],_=f.replace(p,"").replace(Y,"");if(o.includes(_))return l;o.push(_);var v=s._interpolate(t,e,_,r,"raw"===i?"string":i,"raw"===i?void 0:a,o);if(s._isFallbackRoot(v)){if(!s._root)throw Error("unexpected error");var g=s._root.$i18n;v=g._translate(g._getMessages(),g.locale,g.fallbackLocale,_,r,i,a)}v=s._warnDefault(t,_,v,r,Array.isArray(a)?a:[a]),Z.hasOwnProperty(m)&&(v=Z[m](v)),o.pop(),l=v?l.replace(f,v):l}return l},et.prototype._render=function(t,e,n,r){var i=this._formatter.interpolate(t,n,r);return i||(i=tt.interpolate(t,n,r)),"string"===e?i.join(""):i},et.prototype._translate=function(t,e,n,i,a,o,s){var l=this._interpolate(e,t[e],i,a,o,s,[i]);return r(l)?(l=this._interpolate(n,t[n],i,a,o,s,[i]),r(l)?null:l):l},et.prototype._t=function(t,e,n,r){for(var a,o=[],s=arguments.length-4;s-- >0;)o[s]=arguments[s+4];if(!t)return"";var l=i.apply(void 0,o),c=l.locale||e,u=this._translate(n,c,this.fallbackLocale,t,r,"string",l.params);if(this._isFallbackRoot(u)){if(!this._root)throw Error("unexpected error");return(a=this._root).$t.apply(a,[t].concat(o))}return this._warnDefault(c,t,u,r,o)},et.prototype.t=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this)._t.apply(e,[t,this.locale,this._getMessages(),null].concat(n))},et.prototype._i=function(t,e,n,r,i){var a=this._translate(n,e,this.fallbackLocale,t,r,"raw",i);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.i(t,e,i)}return this._warnDefault(e,t,a,r,[i])},et.prototype.i=function(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""},et.prototype._tc=function(t,e,n,r,a){for(var o,s=[],l=arguments.length-5;l-- >0;)s[l]=arguments[l+5];if(!t)return"";void 0===a&&(a=1);var c={count:a,n:a},u=i.apply(void 0,s);return u.params=Object.assign(c,u.params),s=null===u.locale?[u.params]:[u.locale,u.params],this.fetchChoice((o=this)._t.apply(o,[t,e,n,r].concat(s)),a)},et.prototype.fetchChoice=function(t,e){if(!t&&"string"!=typeof t)return null;var n=t.split("|");return e=this.getChoiceIndex(e,n.length),n[e]?n[e].trim():t},et.prototype.getChoiceIndex=function(t,e){return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):function(t,e){return t=Math.abs(t),2===e?t?t>1?1:0:1:t?Math.min(t,2):0}(t,e)},et.prototype.tc=function(t,e){for(var n,r=[],i=arguments.length-2;i-- >0;)r[i]=arguments[i+2];return(n=this)._tc.apply(n,[t,this.locale,this._getMessages(),null,e].concat(r))},et.prototype._te=function(t,e,n){for(var r=[],a=arguments.length-3;a-- >0;)r[a]=arguments[a+3];var o=i.apply(void 0,r).locale||e;return this._exist(n[o],t)},et.prototype.te=function(t,e){return this._te(t,this.locale,this._getMessages(),e)},et.prototype.getLocaleMessage=function(t){return a(this._vm.messages[t]||{})},et.prototype.setLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,e)},et.prototype.mergeLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,l(this._vm.messages[t]||{},e))},et.prototype.getDateTimeFormat=function(t){return a(this._vm.dateTimeFormats[t]||{})},et.prototype.setDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)},et.prototype.mergeDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,l(this._vm.dateTimeFormats[t]||{},e))},et.prototype._localizeDateTime=function(t,e,n,i,a){var o=e,s=i[o];if((r(s)||r(s[a]))&&(o=n,s=i[o]),r(s)||r(s[a]))return null;var l=s[a],c=o+"__"+a,u=this._dateTimeFormatters[c];return u||(u=this._dateTimeFormatters[c]=new Intl.DateTimeFormat(o,l)),u.format(t)},et.prototype._d=function(t,e,n){if(!n)return new Intl.DateTimeFormat(e).format(t);var r=this._localizeDateTime(t,e,this.fallbackLocale,this._getDateTimeFormats(),n);if(this._isFallbackRoot(r)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.d(t,n,e)}return r||""},et.prototype.d=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._d(t,i,a)},et.prototype.getNumberFormat=function(t){return a(this._vm.numberFormats[t]||{})},et.prototype.setNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,e)},et.prototype.mergeNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,l(this._vm.numberFormats[t]||{},e))},et.prototype._localizeNumber=function(t,e,n,i,a,o){var s=e,l=i[s];if((r(l)||r(l[a]))&&(s=n,l=i[s]),r(l)||r(l[a]))return null;var c,u=l[a];if(o)c=new Intl.NumberFormat(s,Object.assign({},u,o));else{var f=s+"__"+a;c=this._numberFormatters[f],c||(c=this._numberFormatters[f]=new Intl.NumberFormat(s,u))}return c.format(t)},et.prototype._n=function(t,e,n,r){if(!et.availabilities.numberFormat)return"";if(!n){return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).format(t)}var i=this._localizeNumber(t,e,this.fallbackLocale,this._getNumberFormats(),n,r);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},r))}return i||""},et.prototype.n=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null,o=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key),o=Object.keys(n[0]).reduce(function(t,e){var r;return K.includes(e)?Object.assign({},t,(r={},r[e]=n[0][e],r)):t},null)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._n(t,i,a,o)},Object.defineProperties(et.prototype,nt);var rt;return Object.defineProperty(et,"availabilities",{get:function(){if(!rt){var t="undefined"!=typeof Intl;rt={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return rt}}),et.install=d,et.version="8.9.0",et}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueI18n=e()}(this,function(){"use strict";function t(t,e){"undefined"!=typeof console&&(console.warn("[vue-i18n] "+t),e&&console.warn(e.stack))}function e(t){return null!==t&&"object"==typeof t}function n(t){return L.call(t)===O}function r(t){return null===t||void 0===t}function i(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var r=null,i=null;return 1===t.length?e(t[0])||Array.isArray(t[0])?i=t[0]:"string"==typeof t[0]&&(r=t[0]):2===t.length&&("string"==typeof t[0]&&(r=t[0]),(e(t[1])||Array.isArray(t[1]))&&(i=t[1])),{locale:r,params:i}}function a(t){return JSON.parse(JSON.stringify(t))}function o(t,e){if(t.length){var n=t.indexOf(e);if(n>-1)return t.splice(n,1)}}function s(t,e){return C.call(t,e)}function l(t){for(var n=arguments,r=Object(t),i=1;i0;)e[n]=arguments[n+1];var r=this.$i18n;return r._t.apply(r,[t,r.locale,r._getMessages(),this].concat(e))},t.prototype.$tc=function(t,e){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];var i=this.$i18n;return i._tc.apply(i,[t,i.locale,i._getMessages(),this,e].concat(n))},t.prototype.$te=function(t,e){var n=this.$i18n;return n._te(t,n.locale,n._getMessages(),e)},t.prototype.$d=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).d.apply(e,[t].concat(n))},t.prototype.$n=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this.$i18n).n.apply(e,[t].concat(n))}}function f(t,e,n){m(t,n)&&v(t,e,n)}function h(t,e,n,r){if(m(t,n)){var i=n.context.$i18n;_(t,n)&&c(e.value,e.oldValue)&&c(t._localeMessage,i.getLocaleMessage(i.locale))||v(t,e,n)}}function p(e,n,r,i){if(!r.context)return void t("Vue instance does not exists in VNode context");var a=r.context.$i18n||{};n.modifiers.preserve||a.preserveDirectiveContent||(e.textContent=""),e._vt=void 0,delete e._vt,e._locale=void 0,delete e._locale,e._localeMessage=void 0,delete e._localeMessage}function m(e,n){var r=n.context;return r?!!r.$i18n||(t("VueI18n instance does not exists in Vue instance"),!1):(t("Vue instance does not exists in VNode context"),!1)}function _(t,e){var n=e.context;return t._locale===n.$i18n.locale}function v(e,n,r){var i,a,o=n.value,s=g(o),l=s.path,c=s.locale,u=s.args,f=s.choice;if(!l&&!c&&!u)return void t("value type not supported");if(!l)return void t("`path` is required in v-t directive");var h=r.context;e._vt=e.textContent=f?(i=h.$i18n).tc.apply(i,[l,f].concat(y(c,u))):(a=h.$i18n).t.apply(a,[l].concat(y(c,u))),e._locale=h.$i18n.locale,e._localeMessage=h.$i18n.getLocaleMessage(h.$i18n.locale)}function g(t){var e,r,i,a;return"string"==typeof t?e=t:n(t)&&(e=t.path,r=t.locale,i=t.args,a=t.choice),{path:e,locale:r,args:i,choice:a}}function y(t,e){var r=[];return t&&r.push(t),e&&(Array.isArray(e)||n(e))&&r.push(e),r}function d(t){d.installed=!0,T=t;T.version&&Number(T.version.split(".")[0]);u(T),T.mixin(W),T.directive("t",{bind:f,update:h,unbind:p}),T.component(M.name,M),T.config.optionMergeStrategies.i18n=function(t,e){return void 0===e?t:e}}function b(t){for(var e=[],n=0,r="";n0)f--,u=P,h[I]();else{if(f=0,!1===(n=D(n)))return!1;h[R]()}};null!==u;)if(c++,"\\"!==(e=t[c])||!function(){var e=t[c+1];if(u===E&&"'"===e||u===U&&'"'===e)return c++,r="\\"+e,h[I](),!0}()){if(i=w(e),s=G[u],(a=s[i]||s.else||q)===q)return;if(u=a[0],(o=h[a[1]])&&(r=a[2],r=void 0===r?e:r,!1===o()))return;if(u===J)return l}}var T,L=Object.prototype.toString,O="[object Object]",C=Object.prototype.hasOwnProperty,W={beforeCreate:function(){var t=this.$options;if(t.i18n=t.i18n||(t.__i18n?{}:null),t.i18n){if(t.i18n instanceof et){if(t.__i18n)try{var e={};t.__i18n.forEach(function(t){e=l(e,JSON.parse(t))}),Object.keys(e).forEach(function(n){t.i18n.mergeLocaleMessage(n,e[n])})}catch(t){}this._i18n=t.i18n,this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0}else if(n(t.i18n)){if(this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et&&(t.i18n.root=this.$root,t.i18n.formatter=this.$root.$i18n.formatter,t.i18n.fallbackLocale=this.$root.$i18n.fallbackLocale,t.i18n.silentTranslationWarn=this.$root.$i18n.silentTranslationWarn,t.i18n.silentFallbackWarn=this.$root.$i18n.silentFallbackWarn,t.i18n.pluralizationRules=this.$root.$i18n.pluralizationRules,t.i18n.preserveDirectiveContent=this.$root.$i18n.preserveDirectiveContent),t.__i18n)try{var r={};t.__i18n.forEach(function(t){r=l(r,JSON.parse(t))}),t.i18n.messages=r}catch(t){}this._i18n=new et(t.i18n),this._i18nWatcher=this._i18n.watchI18nData(),this._i18n.subscribeDataChanging(this),this._subscribing=!0,(void 0===t.i18n.sync||t.i18n.sync)&&(this._localeWatcher=this.$i18n.watchLocale())}}else this.$root&&this.$root.$i18n&&this.$root.$i18n instanceof et?(this._i18n=this.$root.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0):t.parent&&t.parent.$i18n&&t.parent.$i18n instanceof et&&(this._i18n=t.parent.$i18n,this._i18n.subscribeDataChanging(this),this._subscribing=!0)},beforeDestroy:function(){if(this._i18n){var t=this;this.$nextTick(function(){t._subscribing&&(t._i18n.unsubscribeDataChanging(t),delete t._subscribing),t._i18nWatcher&&(t._i18nWatcher(),t._i18n.destroyVM(),delete t._i18nWatcher),t._localeWatcher&&(t._localeWatcher(),delete t._localeWatcher),t._i18n=null})}}},M={name:"i18n",functional:!0,props:{tag:{type:String,default:"span"},path:{type:String,required:!0},locale:{type:String},places:{type:[Array,Object]}},render:function(t,e){var n=e.props,r=e.data,i=e.children,a=e.parent,o=a.$i18n;if(i=(i||[]).filter(function(t){return t.tag||(t.text=t.text.trim())}),!o)return i;var s=n.path,l=n.locale,c={},u=n.places||{},f=(Array.isArray(u)?u.length:Object.keys(u).length,i.every(function(t){if(t.data&&t.data.attrs){var e=t.data.attrs.place;return void 0!==e&&""!==e}}));return Array.isArray(u)?u.forEach(function(t,e){c[e]=t}):Object.keys(u).forEach(function(t){c[t]=u[t]}),i.forEach(function(t,e){var n=f?""+t.data.attrs.place:""+e;c[n]=t}),t(n.tag,r,o.i(s,l,c))}},j=function(){this._caches=Object.create(null)};j.prototype.interpolate=function(t,e){if(!e)return[t];var n=this._caches[t];return n||(n=b(t),this._caches[t]=n),$(n,e)};var A=/^(?:\d)+/,N=/^(?:\w)+/,I=0,R=1,V=2,S=3,z=0,P=4,E=5,U=6,J=7,q=8,G=[];G[z]={ws:[z],ident:[3,I],"[":[P],eof:[J]},G[1]={ws:[1],".":[2],"[":[P],eof:[J]},G[2]={ws:[2],ident:[3,I],0:[3,I],number:[3,I]},G[3]={ident:[3,I],0:[3,I],number:[3,I],ws:[3],".":[2,R],"[":[P,R],eof:[J,R]},G[P]={"'":[E,I],'"':[U,I],"[":[P,V],"]":[1,S],eof:q,else:[P,I]},G[E]={"'":[P,I],eof:q,else:[E,I]},G[U]={'"':[P,I],eof:q,else:[U,I]};var B=/^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/,H=function(){this._cache=Object.create(null)};H.prototype.parsePath=function(t){var e=this._cache[t];return e||(e=x(t))&&(this._cache[t]=e),e||[]},H.prototype.getPathValue=function(t,n){if(!e(t))return null;var r=this.parsePath(n);if(0===r.length)return null;for(var i=r.length,a=t,o=0;o=0||u.indexOf("@.")>=0)&&(u=this._link(t,e,u,a,"raw",s,l)),this._render(u,o,s,i)},et.prototype._link=function(t,e,n,r,i,a,o){var s=this,l=n,c=l.match(Q);for(var u in c)if(c.hasOwnProperty(u)){var f=c[u],h=f.match(X),p=h[0],m=h[1],_=f.replace(p,"").replace(Y,"");if(o.includes(_))return l;o.push(_);var v=s._interpolate(t,e,_,r,"raw"===i?"string":i,"raw"===i?void 0:a,o);if(s._isFallbackRoot(v)){if(!s._root)throw Error("unexpected error");var g=s._root.$i18n;v=g._translate(g._getMessages(),g.locale,g.fallbackLocale,_,r,i,a)}v=s._warnDefault(t,_,v,r,Array.isArray(a)?a:[a]),Z.hasOwnProperty(m)&&(v=Z[m](v)),o.pop(),l=v?l.replace(f,v):l}return l},et.prototype._render=function(t,e,n,r){var i=this._formatter.interpolate(t,n,r);return i||(i=tt.interpolate(t,n,r)),"string"===e?i.join(""):i},et.prototype._translate=function(t,e,n,i,a,o,s){var l=this._interpolate(e,t[e],i,a,o,s,[i]);return r(l)?(l=this._interpolate(n,t[n],i,a,o,s,[i]),r(l)?null:l):l},et.prototype._t=function(t,e,n,r){for(var a,o=[],s=arguments.length-4;s-- >0;)o[s]=arguments[s+4];if(!t)return"";var l=i.apply(void 0,o),c=l.locale||e,u=this._translate(n,c,this.fallbackLocale,t,r,"string",l.params);if(this._isFallbackRoot(u)){if(!this._root)throw Error("unexpected error");return(a=this._root).$t.apply(a,[t].concat(o))}return this._warnDefault(c,t,u,r,o)},et.prototype.t=function(t){for(var e,n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];return(e=this)._t.apply(e,[t,this.locale,this._getMessages(),null].concat(n))},et.prototype._i=function(t,e,n,r,i){var a=this._translate(n,e,this.fallbackLocale,t,r,"raw",i);if(this._isFallbackRoot(a)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.i(t,e,i)}return this._warnDefault(e,t,a,r,[i])},et.prototype.i=function(t,e,n){return t?("string"!=typeof e&&(e=this.locale),this._i(t,e,this._getMessages(),null,n)):""},et.prototype._tc=function(t,e,n,r,a){for(var o,s=[],l=arguments.length-5;l-- >0;)s[l]=arguments[l+5];if(!t)return"";void 0===a&&(a=1);var c={count:a,n:a},u=i.apply(void 0,s);return u.params=Object.assign(c,u.params),s=null===u.locale?[u.params]:[u.locale,u.params],this.fetchChoice((o=this)._t.apply(o,[t,e,n,r].concat(s)),a)},et.prototype.fetchChoice=function(t,e){if(!t&&"string"!=typeof t)return null;var n=t.split("|");return e=this.getChoiceIndex(e,n.length),n[e]?n[e].trim():t},et.prototype.getChoiceIndex=function(t,e){return this.locale in this.pluralizationRules?this.pluralizationRules[this.locale].apply(this,[t,e]):function(t,e){return t=Math.abs(t),2===e?t?t>1?1:0:1:t?Math.min(t,2):0}(t,e)},et.prototype.tc=function(t,e){for(var n,r=[],i=arguments.length-2;i-- >0;)r[i]=arguments[i+2];return(n=this)._tc.apply(n,[t,this.locale,this._getMessages(),null,e].concat(r))},et.prototype._te=function(t,e,n){for(var r=[],a=arguments.length-3;a-- >0;)r[a]=arguments[a+3];var o=i.apply(void 0,r).locale||e;return this._exist(n[o],t)},et.prototype.te=function(t,e){return this._te(t,this.locale,this._getMessages(),e)},et.prototype.getLocaleMessage=function(t){return a(this._vm.messages[t]||{})},et.prototype.setLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,e)},et.prototype.mergeLocaleMessage=function(t,e){this._vm.$set(this._vm.messages,t,l(this._vm.messages[t]||{},e))},et.prototype.getDateTimeFormat=function(t){return a(this._vm.dateTimeFormats[t]||{})},et.prototype.setDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,e)},et.prototype.mergeDateTimeFormat=function(t,e){this._vm.$set(this._vm.dateTimeFormats,t,l(this._vm.dateTimeFormats[t]||{},e))},et.prototype._localizeDateTime=function(t,e,n,i,a){var o=e,s=i[o];if((r(s)||r(s[a]))&&(o=n,s=i[o]),r(s)||r(s[a]))return null;var l=s[a],c=o+"__"+a,u=this._dateTimeFormatters[c];return u||(u=this._dateTimeFormatters[c]=new Intl.DateTimeFormat(o,l)),u.format(t)},et.prototype._d=function(t,e,n){if(!n)return new Intl.DateTimeFormat(e).format(t);var r=this._localizeDateTime(t,e,this.fallbackLocale,this._getDateTimeFormats(),n);if(this._isFallbackRoot(r)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.d(t,n,e)}return r||""},et.prototype.d=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._d(t,i,a)},et.prototype.getNumberFormat=function(t){return a(this._vm.numberFormats[t]||{})},et.prototype.setNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,e)},et.prototype.mergeNumberFormat=function(t,e){this._vm.$set(this._vm.numberFormats,t,l(this._vm.numberFormats[t]||{},e))},et.prototype._localizeNumber=function(t,e,n,i,a,o){var s=e,l=i[s];if((r(l)||r(l[a]))&&(s=n,l=i[s]),r(l)||r(l[a]))return null;var c,u=l[a];if(o)c=new Intl.NumberFormat(s,Object.assign({},u,o));else{var f=s+"__"+a;c=this._numberFormatters[f],c||(c=this._numberFormatters[f]=new Intl.NumberFormat(s,u))}return c.format(t)},et.prototype._n=function(t,e,n,r){if(!et.availabilities.numberFormat)return"";if(!n){return(r?new Intl.NumberFormat(e,r):new Intl.NumberFormat(e)).format(t)}var i=this._localizeNumber(t,e,this.fallbackLocale,this._getNumberFormats(),n,r);if(this._isFallbackRoot(i)){if(!this._root)throw Error("unexpected error");return this._root.$i18n.n(t,Object.assign({},{key:n,locale:e},r))}return i||""},et.prototype.n=function(t){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var i=this.locale,a=null,o=null;return 1===n.length?"string"==typeof n[0]?a=n[0]:e(n[0])&&(n[0].locale&&(i=n[0].locale),n[0].key&&(a=n[0].key),o=Object.keys(n[0]).reduce(function(t,e){var r;return K.includes(e)?Object.assign({},t,(r={},r[e]=n[0][e],r)):t},null)):2===n.length&&("string"==typeof n[0]&&(a=n[0]),"string"==typeof n[1]&&(i=n[1])),this._n(t,i,a,o)},Object.defineProperties(et.prototype,nt);var rt;return Object.defineProperty(et,"availabilities",{get:function(){if(!rt){var t="undefined"!=typeof Intl;rt={dateTimeFormat:t&&void 0!==Intl.DateTimeFormat,numberFormat:t&&void 0!==Intl.NumberFormat}}return rt}}),et.install=d,et.version="8.9.0",et}); \ No newline at end of file diff --git a/src/path.js b/src/path.js index 6688c3da0..948f44740 100644 --- a/src/path.js +++ b/src/path.js @@ -52,7 +52,7 @@ pathStateMachine[IN_IDENT] = { 'ident': [IN_IDENT, APPEND], '0': [IN_IDENT, APPEND], 'number': [IN_IDENT, APPEND], - 'ws': [IN_PATH, PUSH], + 'ws': [IN_IDENT], '.': [BEFORE_IDENT, PUSH], '[': [IN_SUB_PATH, PUSH], 'eof': [AFTER_PATH, PUSH] diff --git a/test/unit/path.test.js b/test/unit/path.test.js index a53ac7fcb..adfc81daf 100644 --- a/test/unit/path.test.js +++ b/test/unit/path.test.js @@ -14,6 +14,16 @@ describe('path', () => { const val = path.getPathValue({ a: { b: 1 } }, 'a') assert.strictEqual(val.b, 1) }) + + it('should accept space 0x20 as keypath', () => { + const val = path.getPathValue({ a: { 'b c d': 1 } }, 'a.b c d') + assert.strictEqual(val, 1) + }) + + it('should ignore whitespace chars except space 0x20', () => { + const val = path.getPathValue({ a: { bcd: 1 } }, 'a.b\tc\nd') + assert.strictEqual(val, 1) + }) }) describe('number key in object', () => {