Git Product home page Git Product logo

es3ify's Introduction

es3ify

Browserify transform to convert quote reserved words in property keys for compatibility with ES3 JavaScript engines like IE8. In addition, trailing commas in array and object literals are removed.

// In
var x = {class: 2,};
x.class = [3, 4,];

// Out:
var x = {"class": 2};
x["class"] = [3, 4];

Run tests with:

npm install -g jasmine-node
jasmine-node spec

es3ify's People

Contributors

apaleslimghost avatar calvinmetcalf avatar rstacruz avatar sophiebits avatar stegano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

es3ify's Issues

Esprima Parse Error

Hello - trying to get started with es3ify. If I can get it to work, this should do exactly what I need. Thank you!

Here's the error I'm getting:

/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/jstransform/src/jstransform.js:222
    throw e;
          ^
Error: Parse Error: Line 18: Illegal return statement
    at throwError (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:2159:21)
    at throwErrorTolerant (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:2171:24)
    at parseReturnStatement (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:3873:13)
    at parseStatement (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:4115:24)
    at /Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:5832:38
    at parseSourceElement (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:4673:24)
    at parseStatementList (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:3274:25)
    at parseBlock (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:3289:17)
    at /Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:5832:38
    at parseStatement (/Users/alden/Source/bidder/ui/node_modules/lib-node/node_modules/es3ify/node_modules/esprima-fb/esprima.js:4088:24)

The JS source being parsed is valid (it works without errors in browsers > IE8.

A good starting point would be if es3ify could output error messages that include the file path (and line number if possible) that the parser is choking on.

Modifies code in comments in some cases

Consider the following code:

var data = [
  { 
    id: 0,
    name: "John Indigo"
  }/*,
  {
    id: 1,
    name: "Alice Beauxfort"
  },
  {
    id: 3,
    name: "Bram van Dijt"
  }*/
];

es3ify will return the following. Note that code inside the multi-line comment has been modified (all commas removed):

var data = [
    { 
      id: 0,
      name: "John Indigo"
    }/*
    {
      id: 1
      name: "Alice Beauxfort"
    }
    {
      id: 3
      name: "Bram van Dijt"
    }*/
  ];

Default property with OR

I'm supporting IE8 (I know, I know) in a project, and using react hot loader in dev, then looking at swapping out Nerv or Preact in production to support older browsers. (Yup all sounds crazy). But anyway, the following line is causing an error:

Module parse failed: Unexpected token. You may need an appropriate loader to handle this file type.

at:

var reactHotLoader = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : require('react-hot-loader')["default"];

I've create a simpler repro scenario to demonstrate the actual issue:

Repro steps

Run the following:

var transform = require('es3ify').transform;
console.log(transform(`(a || b).default`));

Expected result

(a || b)["default"]

Actual result

(a || b["default"]
// Note: missing closing bracket

Anyway, I think I can get round this using the babel-plugin-transform-es3-member-expression-literals plugin instead (similar to reduxjs/redux#1688) but raising it here in case anyone else encounters the same problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.