Loading ...
Sorry, an error occurred while loading the content.

Re: Some parser problems

Expand Messages
  • Douglas Crockford
    ... 1. Fix your code, then it won t stop. 2. Fix your code, then it won t stop. 3. b was used before it was declared. This can confuse a reader, who will
    Message 1 of 7 , May 11, 2010
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "avegaart" <avegaart@...> wrote:
      >
      > I just ran the ExtJS javascript library through JSLint again and I am pleasantly surprised by the progress that JSLint has made in the past few months.
      > The parser is able to scan almost all of the code and there are only 2 constructs that stop JSLint from parsing the entire library.
      >
      > 1. The following line obviously should generate a warning, but it also stops the parser:
      >
      > var a = (.5 * 2);
      >
      > Problem at line 1 character 10: A leading decimal point can be confused with a dot: '.5'.
      > Problem at line 1 character 13: Expected ')' to match '(' from line 1 and instead saw '*'.
      > Problem at line 1 character 14: Missing semicolon.
      > Problem at line 1 character 15: Expected an assignment or function call and instead saw an expression.
      > Problem at line 1 character 16: Missing semicolon.
      > Problem at line 1 character 16: Expected an identifier and instead saw ')'.
      > Problem at line 1 character 16: Stopping, unable to continue. (100% scanned).
      >
      >
      > 2. The following fragment also should generate a warning, but it too stops the parser:
      >
      > var x, y;
      > if (x = y = 1) {
      > // do stuff
      > }
      >
      > Problem at line 2 character 7: Expected a conditional expression and instead saw an assignment.
      > Problem at line 2 character 11: Expected ')' to match '(' from line 2 and instead saw '='.
      > Problem at line 2 character 13: Expected '{' and instead saw '1'.
      > Problem at line 2 character 13: Expected an assignment or function call and instead saw an expression.
      > Problem at line 2 character 14: Missing semicolon.
      > Problem at line 2 character 14: Expected an identifier and instead saw ')'.
      > Problem at line 2 character 14: Stopping, unable to continue. (40% scanned).
      >
      >
      > 3. Why does the following fragment generate an "Implied global: b" message?
      >
      > function x() {
      > function a () {
      > return b;
      > }
      > var b = 1;
      > }
      >
      >
      > 4. I had to add a few keywords to the predefined list which IMHO should have been part of the default or browser set:
      >
      > self, escape, unescape, window

      1. Fix your code, then it won't stop.
      2. Fix your code, then it won't stop.
      3. b was used before it was declared. This can confuse a reader, who will likely read b as being a global variable.
      4. self and window are commonly abused. You have to declare those yourself. escape and unescape have been deprecated. Do not use them.
    • Cheney, Edward A SSG RES USAR USARC
      ... You are still performing assignment in a condition and not evaluation. At the same time never use redundant assignment, such as x = y = 1, because that is
      Message 2 of 7 , May 11, 2010
      • 0 Attachment
        > if ((x = (y = 1))) {
        > // do stuff
        > }

        You are still performing assignment in a condition and not evaluation. At the same time never use redundant assignment, such as x = y = 1, because that is extremely unpredictable with regard to closure.

        In your original example variable "b" is an implied global, BECAUSE it is used before it is declared.

        > I know I can fix issues 1 and 2, but my question was why the
        > parser stops when it should continue with a warning.

        I am sure when Douglas built the tool one of the problems he may have encountered were patterns of faulty input that potentially choke the logical evaluation of the tool. If that is the case it makes more sense to return prematurely than to double the size of the tool to compensate for bad practices or faulty input.

        Austin
      • Rob Richardson
        Is there a good rule-of-thumb for what type of errors stop JSLint immediately and what type of errors accumulate? Rob ________________________________ From:
        Message 3 of 7 , May 11, 2010
        • 0 Attachment
          Is there a good rule-of-thumb for what type of errors stop JSLint immediately and what type of errors accumulate?

          Rob

          ________________________________
          From: Douglas Crockford <douglas@...>
          To: jslint_com@yahoogroups.com
          Sent: Tue, May 11, 2010 6:26:12 AM
          Subject: [jslint] Re: Some parser problems


          --- In jslint_com@yahoogro ups.com, "avegaart" <avegaart@.. .> wrote:
          >
          > I just ran the ExtJS javascript library through JSLint again and I am pleasantly surprised by the progress that JSLint has made in the past few months.
          > The parser is able to scan almost all of the code and there are only 2 constructs that stop JSLint from parsing the entire library.
          >
          ...

          1. Fix your code, then it won't stop.
          2. Fix your code, then it won't stop.
          3. b was used before it was declared. This can confuse a reader, who will likely read b as being a global variable.
          4. self and window are commonly abused. You have to declare those yourself. escape and unescape have been deprecated. Do not use them.
        • Cheney, Edward A SSG RES USAR USARC
          Rob, Evaluation of the code, JSLint function, will tell you exactly that. It is not likely that there are static definitions that point certain errors to
          Message 4 of 7 , May 11, 2010
          • 0 Attachment
            Rob,

            Evaluation of the code, JSLint function, will tell you exactly that. It is not likely that there are static definitions that point certain errors to cumulative output versus others that prematurely return. Instead the premature termination is likely due to various patterns of input that may result from interactions of various errors. The code that produces such errors is sure to let you know.

            Austin
          Your message has been successfully submitted and would be delivered to recipients shortly.