meteor-messageformat icon indicating copy to clipboard operation
meteor-messageformat copied to clipboard

parse_whitespace error with bad arguments

Open dcsan opened this issue 11 years ago • 2 comments

I was getting an error on parse_whitespace this turns out that spacebars will pass this default argument onto any helper after other params

Spacebars.kw {hash: Object}
hash: Object
__proto__: Spacebars.kw

since meteor-messageformat requires vars and str extra arguments, which 90% of the time i dont use (just the key), it makes things susceptible to picking up this extra spacebars arguments hash and getting passed in.

if possible translation code should probably guard against being handed such a property.

Exception in template helper: TypeError: undefined is not a function
    at parse_whitespace (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:1336:39)
    at parse__ (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:1315:21)
    at parse_string (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:944:21)
    at parse_messageFormatPattern (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:289:21)
    at Object.parse_start [as start] (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:273:21)
    at Object.result.parse (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:1395:47)
    at MessageFormat.parse (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:1482:26)
    at MessageFormat.compile (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:1622:16)
    at mf (http://localhost:3000/packages/messageformat.js?8b6ee4f6288947174a577244af7ef80c5ac9d318:1792:53)
    at Object.Loco.trans (http://localhost:3000/packages/loco.js?ed2d3a176ba38f407149c7e64a66f36745bded2d:251:9)
                                                                                                                      // 1282
        function parse_whitespace() {                                                                                 // 1283
          var result0;                                                                                                // 1284
                                                                                                                      // 1285
          if (/^[ \t\n\r]/.test(input.charAt(pos))) {                                                                 // 1286
            result0 = input.charAt(pos);                                                                              // 1287
            pos++;                                                                                                    // 1288
          } else {                                                                                                    // 1289
            result0 = null;                                                                                           // 1290
            if (reportFailures === 0) {                                                                               // 1291
              matchFailed("[ \\t\\n\\r]");                                                                            // 1292
            }                                                                                                         // 1293
          }                                                                                                           // 1294
          return result0;                                                                                             // 1295
        }                                                                                                             // 1296

I added this in my wrapper method to guard for now:

Loco.trans = (key, str, langMode) ->

  if typeof(str) == "object"
    # Spacebars.kw gets added to all helpers 
    # yet typeof is not string doesnt catch
    console.warn("Loco.trans got str of:", str)
    str = key

dcsan avatar Sep 25 '14 00:09 dcsan

Hey, just to be clear, can you paste a copy of the template and mention which Meteor version you're using?

It's gotten quiet difficult to support 0.8.2-, 0.8.3, 0.9.0, and 0.9.1+, which all had various changes to the Blaze API which we rely on quite extensively. I suspect on the refactor we'll only support 0.9.1+, which make it a lot simpler to make sure everything works. Just to be clear, not specifying a string is indeed a supported pattern and should not be throwing this error.

gadicc avatar Sep 25 '14 09:09 gadicc

i'm on 0.8x right now, hoping to upgrade to 0.9 very shortly. if i still have the issue then i'll create a repo. thanks.

dcsan avatar Sep 25 '14 16:09 dcsan