Skip to content

global cwise transform fails if regl is a dependency #12

Open

Description

@rreusser

A weird interaction, but figured I'd ask since it lives in the same ecosystem. A global cwise transform is useful since most cwise-based modules are not cwise-transformed. However, browserify -g cwise fails if regl is a dependency.

To reproduce:

$ echo "require('regl')" > index.js
$ npm i cwise
$ browserify -g cwise index.js

The resulting output is:

SyntaxError: Unexpected token (2:22) while parsing file: /Users/rreusser/test8/node_modules/regl/lib/constants/arraytypes.json
    at Parser.pp.raise (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:1745:13)
    at Parser.pp.unexpected (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:2264:8)
    at Parser.pp.semicolon (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:2243:59)
    at Parser.pp.parseExpressionStatement (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:2677:8)
    at Parser.pp.parseStatement (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:2462:160)
    at Parser.pp.parseBlock (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:2692:21)
    at Parser.pp.parseStatement (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:2443:19)
    at Parser.pp.parseTopLevel (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:2379:21)
    at parse (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/node_modules/acorn/dist/acorn.js:101:12)
    at module.exports (/Users/rreusser/test8/node_modules/cwise/node_modules/static-module/node_modules/falafel/index.js:22:15)

It's just a small json file, so it's not immediately apparent what there is to dislike about it. I'm wondering if perhaps it's just uglify-js that needs a 2.6 -> 2.7 update or something of the sort (acorn maybe?).

Activity

  1. mikolalysenko commented on Aug 22, 2016

    @mikolalysenko
    Member

    It could be due to ES6 syntax. Switching the cwise transform to babel might fix it.

  2. rreusser commented on Aug 22, 2016

    @rreusser
    MemberAuthor

    Can you clarify what you mean? Do you mean to babelify first, then apply the cwise transform?

    $ browserify -g [ babelify --presets [ es2015 ] ] -g cwise index.js > bundle.js
  3. mikolalysenko commented on Aug 22, 2016

    @mikolalysenko
    Member

    That might work, but a better solution would be to fix the cwise transform falafel dependency to use es6 instead.

  4. rreusser commented on Aug 22, 2016

    @rreusser
    MemberAuthor

    I updated cwise's static-module dep to see if I'd get lucky, but that didn't fix it. I verified that the newer version indeed sends {ecmaVersion: 6} to falafel.

    The cause seems to be that acorn is parsing the json requires as javascript. See: acornjs/acorn#415 So in that sense, it's correct to fail, but the question then is which step in the chain is failing such that it's trying to parse json as javascript.

    The one simple fix that did work was to change regl's constants to .js files that export their data, but it's unpleasant to have to propagate silly workarounds upstream (edit: cross-stream?).

  5. rreusser commented on Aug 23, 2016

    @rreusser
    MemberAuthor

    For reference, a repo that reproduces this using cwise with an updated static-module dependency: https://github.com/rreusser/cwise-regl-interaction

    To reproduce:

    git clone https://github.com/rreusser/cwise-regl-interaction.git
    cd cwise-regl-interaction
    npm install
    npm run bundle

    Didn't otherwise manage to make headway though. 😞

  6. milcktoast commented on Jan 29, 2019

    @milcktoast

    Not sure if anyone's still working on a solution, but I hacked together a fix for the project I'm currently working on. Unfortunately I couldn't get the latest version of static-module working, so I hacked together a fork of static-module@1.5.0 which uses the older version of static-eval. Not a long-term solution, but it's working for now: https://github.com/jpweeks/cwise-es-transform.

    Editing to clarify: my use case doesn't involve regl, but is using cwise in ES6 source code, which seems to be the root issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions