tern icon indicating copy to clipboard operation
tern copied to clipboard

TypeError: str.charCodeAt is not a function

Open Pacl0 opened this issue 8 years ago • 2 comments
trafficstars

Hi, We use tern for our project a I get error when tern parse our javascript file with object: {'0': 'data'}.

TypeError: str.charCodeAt is not a function at isInteger (tern\lib\infer.js:536:15) at extend.hasProp (tern\lib\infer.js:573:11) at extend.getProp (tern\lib\infer.js:605:24)

function isInteger(str) { var c0 = str.charCodeAt(0)

Tern badly convert property name '0' to number instead of string. It would be possible fix it?

Thanks

Pacl0 avatar Aug 15 '17 12:08 Pacl0

How can I reproduce the problem? Just including {'0': 'data'} as an expression in a file doesn't seem to cause any immediate problems.

marijnh avatar Aug 15 '17 16:08 marijnh

Hi, I find bad code which throw exception: Thats code with property name number 1.

function () {
	return {1: 'data'}
}

Error stack: key is object without name and value 1. To propName save key.value = 1

ObjectExpression: function(node) {
      for (var i = 0; i < node.properties.length; ++i) {
        var prop = node.properties[i], key = prop.key, propName = key && (key.name || key.value);
        if (propName) interpretComments(
            prop, key._closureComment, node.objType.getProp(propName));

infer.js: in prop is value 1

  getProp: function(prop) {
      var found = this.hasProp(prop, true) || (this.maybeProps && this.maybeProps[prop]);

infer.js in prop is value 1

 hasProp: function(prop, searchProto) {
      if (isInteger(prop)) prop = this.normalizeIntegerProp(prop)

Here is throw error

function isInteger(str) {
      var c0 = str.charCodeAt(0)

Thank you.

Pacl0 avatar Aug 22 '17 13:08 Pacl0