Skip to content

- jslint-ecma - Add ES2015-feature for..of. - #504

Merged
kaizhu256 merged 29 commits into
jslint-org:betafrom
kaizhu256:branch-p2026.7.20
Jul 27, 2026
Merged

- jslint-ecma - Add ES2015-feature for..of.#504
kaizhu256 merged 29 commits into
jslint-org:betafrom
kaizhu256:branch-p2026.7.20

Conversation

@kaizhu256

Copy link
Copy Markdown
Member

Fixes #176.

A sorely missed feature, that happily is now implemented :)

// for-of statement using const or let now passes jslint w/o warnings
(function for_loop() {
    for (const [ // full destructure support
        {
            cc,
            dd = 0,
            dd: ee,
            ee: [{bb}],
            ...aa
        },
        [
            gg,
            ...ff
        ]
    ] of for_loop) {
        aa(bb, cc, dd, ee, ff, gg);
    }

    // traditional for(;;) statement using let is now allowed
    for (let aa = 0; aa < 8; aa += 1) {
        String(aa);
    }
}());

under-the-hood, jslint's scoping system was significantly revamped

- by adding block-level scoping for:
    - `const`, `let`, and `declared-function-name`.
- in order to integrate normal variable-declaration-logic into for-loop variables.

a beneficial side-effect, is that const and let declarations can be declared inside the top of statement-blocks,

- instead of top of function-block or script, e.g.:
/*jslint beta*/
function foo() {
    var aa = 0; // var statement still required to be at top of function
    ...
    if (aa) {
        let bb = 1; // let statement can now be inside the top of a block
        ...
    } else {
        const bb = 2; // const statement can now be inside the top of a block
                      // and won't complain about name-collision from previous block
        ...
    }
}

following special variables / parameters / names are declared inside a hidden scope to avoid name-collision with normal variables:

- catch-variable
- for-variable
- function-parameter
- label-name
image

This PR will:

  • jslint-ecma - Add ES2015-feature for..of.

This PR will additionally:

  • jslint - Disable directive-option /jslint for/, replacing it with for-loop specific warnings.
  • jslint - Update scope-related warnings for variables, depending on whether they are let/const (scope_block) or var (scope_function).
  • jslint - Change scope from scope_function to scope_block:
    • const-declaration
    • let-declaration
    • function-declaration
  • jslint - Add implicit scope_block for:
    • do-while
    • for-loop
    • if-else
    • while-loop
  • jslint - Add hidden scope_block for:
    • catch-variable
    • for-variable
    • function-parameter
    • label-name
  • jslint - Restrict scope from scope_function to its own function-body:
    • named-function-expression
  • jslint - Rename internal scope-variables to imporove readability of scope-logic:
    • 'blockage' to 'scope_block'
    • 'functionage' to 'scope_function'
  • jslint - Add block-scope to internal-function jslint_phase3_parse().

kaizhu256 added 27 commits July 16, 2026 20:35
… function-parameter, etc) is assigned a value.
…part2 - Replace argument 'enroll' with 'enroll_parent', to explicitly pass the parent-context to be enrolled in.
…e code-readability of jslint's scoping-logic.
…ed things:

    function-name-in-statement
    global-variable
    import-name
    var-variable
…in internal-functions jslint_phase3_parse(), jslint_phase4_walk().
    - const-declaration
    - let-declaration
    - function-declaration
- jslint - Restrict scope from function-scope to its own function-body:
    - named-function-expression
- Remove obsolete deadcode and function pre_b_lparen(thing), that was already marked deadcode in PR-502.
- Remove obsolete bookmarking-logic for 'alive_list' that tracks pseudo-block-scope.
…r 'unknown_warning_code'.

- jslint - Update internal-function infix_lparen() to allow fart, in addition to function.
    - parse_statement() to parse_statement_single()
    - parse_statements() to parse_statement_block()
…gument 'id', instead of making it optional. - part2 - Cleanup function-names.
… scope-logic:

    - 'blockage' to 'scope_block'
    - 'functionage' to 'scope_function'
    - for-loop
- jslint - Disable directive-option /*jslint for*/, replacing it with for-loop specific warnings.
    - if-else
    - while-loop
    - do-while
    - parse_statement_single()
    - stmt_label()
- jslint - split token-property '.label' into following to prevent confusion between 2 very different things:
    - 'label_goto' - the goto-label after 'break' statement, e.g. 'break aa;'
    - 'name_alias' - the alias after desctructure-colon, e.g. 'let {aa:name_alias} = ...;'
…k_pop() and scope_function_pop().

- jslint - split internal functions scope_stack_push() into scope_block_push() and scope_function_push().
…t label-name to statements do,for,switch,while.
…whether they are let/const (scope_block) or var (scope_function).
@kaizhu256 kaizhu256 changed the title Branch p2026.7.20 - jslint-ecma - Add ES2015-feature for..of. Jul 24, 2026
- jslint - Change warning 'out_of_scope_a' to 'temporal_dead_zone_a'.
@kaizhu256
kaizhu256 merged commit 4563300 into jslint-org:beta Jul 27, 2026
6 checks passed
@kaizhu256
kaizhu256 deleted the branch-p2026.7.20 branch July 27, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error on for...of statement

1 participant