PhoneNumber.js icon indicating copy to clipboard operation
PhoneNumber.js copied to clipboard

Error with `let is a reserved identifier` in browser.

Open jfrux opened this issue 11 years ago • 10 comments

Maybe I'm missing the purpose of this lib? Not using it correctly?

Is it meant for node.js?

If I remove strict mode, in Chrome I'm now getting Undefined identifier line 109 of PhoneNumber.js

In Firefox without strict mode I'm getting missing ; before statement

jfrux avatar May 07 '13 13:05 jfrux

It should work. We are using it in gecko: https://hg.mozilla.org/mozilla-central/file/2673016e7df4/dom/phonenumberutils/PhoneNumber.jsm

gregorwagner avatar May 10 '13 16:05 gregorwagner

This SO post should clarify it http://stackoverflow.com/questions/14331617/using-let-and-yield-in-firefox

briandipalma avatar Nov 06 '13 15:11 briandipalma

This raises an interesting question. Would you be willing to add non-spidermonkey engines support? If so, what method would you prefer?

Does simply replacing let and const with var ok?

sonnyp avatar Nov 06 '13 15:11 sonnyp

Last I saw, let and const are supported by V8. In node you can access them using --harmony.

briandipalma avatar Nov 06 '13 16:11 briandipalma

Supported in Node.js v11 which is unstable. It's also about other/older browser engines.

sonnyp avatar Nov 06 '13 16:11 sonnyp

I guess you could also transpile it. ES6 should be in a fairly stable position in 3 months. Stable enough for people to start writing ES6 code and transpiling it for older browsers.

briandipalma avatar Nov 06 '13 16:11 briandipalma

I'm talking about a change in this repository to let people use it, pain-free. We could add a transpiling build task but using a transpiler just to replace const/let with var sounds expensive.

sonnyp avatar Nov 06 '13 16:11 sonnyp

I am ok with replacing let with var. Please submit a pull request.

andreasgal avatar Nov 06 '13 17:11 andreasgal

please see PR #31

sonnyp avatar Nov 06 '13 17:11 sonnyp

I created a fork of PhoneNumber.js that runs even on IE6 - PhoneNumber.js for the Web.

Had to do the following adjustments:

  • const -> var
  • let -> var
  • Object.create(null) -> {}
  • removed getters from NationalNumber, precalculated all the needed values instead
  • Array.isArray(z) -> Object.prototype.toString.call(z) == "[object Array]"
  • number[0] -> number.charAt(0) (only needed in IE6, not in newer browsers)
  • removed some trailing commas (also updated xml2meta.py to skip the last comma in the output)

I also ported all the existing tests to Qunit test cases and the tests passed in every browser I checked.

andris9 avatar Nov 21 '13 13:11 andris9