Skip to content

Error compiling labeled for-of in if without braces (T6806) #3858

@babel-bot

Description

@babel-bot

Issue originally made by @vadzim

Bug information

  • Babel version: 6.3.17 (babel-core 6.3.17)
  • Node version: v5.1.1
  • npm version: 3.3.12

Options

--no-babelrc --presets es2015

Input code

if ( true )
    loop: for ( let ch of [] ) {
    }

Description

> echo "if ( true )
    loop: for ( let ch of [] ) {
    }" | ./node_modules/.bin/babel --no-babelrc --presets es2015
TypeError: unknown: Property body expected type of array but got null
    at validate (/home/vadzim/v/work/nerojs/node_modules/babel-types/lib/definitions/index.js:150:13)
    at Object.validate (/home/vadzim/v/work/nerojs/node_modules/babel-types/lib/definitions/index.js:179:10)
    at Object.validate (/home/vadzim/v/work/nerojs/node_modules/babel-types/lib/index.js:266:9)
    at NodePath._replaceWith (/home/vadzim/v/work/nerojs/node_modules/babel-traverse/lib/path/replacement.js:201:7)
    at NodePath._remove (/home/vadzim/v/work/nerojs/node_modules/babel-traverse/lib/path/removal.js:55:10)
    at NodePath.remove (/home/vadzim/v/work/nerojs/node_modules/babel-traverse/lib/path/removal.js:27:8)
    at NodePath.replaceWithMultiple (/home/vadzim/v/work/nerojs/node_modules/babel-traverse/lib/path/replacement.js:95:10)
    at PluginPass.ForOfStatement (/home/vadzim/v/work/nerojs/node_modules/babel-plugin-transform-es2015-for-of/lib/index.js:63:23)
    at newFn (/home/vadzim/v/work/nerojs/node_modules/babel-traverse/lib/visitors.js:276:19)
    at NodePath._call (/home/vadzim/v/work/nerojs/node_modules/babel-traverse/lib/path/context.js:74:18)

If change to

if ( true )
    loop: for (;;) {
    }

or to

if ( true ) {
    loop: for ( let ch of [] ) {
    }
}

or just to

loop: for ( let ch of [] ) {
}

then compilation is okay.

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions