Skip to content

Unexpected token => #95

@ledsun

Description

@ledsun

Error information

I found a parse error when I convert the next code by the gulp-browserify.

const {
  EventEmitter
} = require('events')
const em = new EventEmitter()

em.on('data', ({
    one,
    two
  }) => console.log(one + two))
em.emit('data', {one: 1, two: 2})

The error messages are:

npx gulp browserify                                                                                                                                                          ~/test
[16:32:19] Using gulpfile ~/test/gulpfile.js
[16:32:19] Starting 'browserify'...

events.js:182
      throw er; // Unhandled 'error' event
      ^
Error: Parsing file /Users/shigerunakajima/test/fake_acd2fc2c.js: Line 9: Unexpected token =>
    at Deps.parseDeps (/Users/shigerunakajima/test/node_modules/module-deps/index.js:339:28)
    at /Users/shigerunakajima/test/node_modules/module-deps/index.js:261:37
    at ConcatStream.<anonymous> (/Users/shigerunakajima/test/node_modules/concat-stream/index.js:36:43)
    at emitNone (events.js:110:20)
    at ConcatStream.emit (events.js:207:7)
    at finishMaybe (/Users/shigerunakajima/test/node_modules/readable-stream/lib/_stream_writable.js:460:14)
    at endWritable (/Users/shigerunakajima/test/node_modules/readable-stream/lib/_stream_writable.js:469:3)
    at ConcatStream.Writable.end (/Users/shigerunakajima/test/node_modules/readable-stream/lib/_stream_writable.js:436:5)
    at DuplexWrapper.onend (/Users/shigerunakajima/test/node_modules/readable-stream/lib/_stream_readable.js:537:10)
    at Object.onceWrapper (events.js:314:30)

Run this code on the node v8.2.1 and it succeeds.

node index.js
=> 3

And the browserify v14.4.0 can convert this code.

To reproduce

gulpfile.js

const gulp = require('gulp')
const browserify = require('gulp-browserify')

gulp
  .task('browserify', () => gulp
    .src(['index.js'])
    .pipe(browserify({debug: true}))
    .pipe(gulp.dest('dist'))
  )

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "gulp": "^3.9.1",
    "gulp-browserify": "^0.5.1"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions