Code Monkey home page Code Monkey logo

babel-plugin-math's People

Contributors

andyogo avatar

Watchers

 avatar  avatar

babel-plugin-math's Issues

implement max micro optimization

Transform any Math.max(...) to a ternary conditional expression x > y ? x : y.

Todo:

  • any number of arguments shall work, i.e.:
    Math.max(1, 2, 3);
    // ->
    (foo = 1 > 2 ? 1 : 2) > 3 ? foo : 3
  • dot Math.max() and bracket Math['max']() notation should be transformed - https://github.com/babel/babylon/blob/master/ast/spec.md#memberexpression
  • dynamic apply Math.max.apply(Math, [5,20,50,35]) and call Math.max.call(Math, 5,20,50,35)
    var arr = [5,20,50,35];
    for(var i=1, l=arr.length, max=arr[0]; i<l; i++) {
      if(arr[i]>max) {
        max=arr[i]
      }
    }
    http://jsben.ch/srGJl
  • ES6 ... spread array Math.max(...args)
  • cached const { max } = Math, const max = Math.max, etc. should be transformed too (and the cached variable could be removed)
  • derived arguments, like function calls, binary and logical operations shall work
  • derived arguments be computed only once

Test Page:
https://astexplorer.net/#/gist/a094859432a2424927d0551f4d037ef8/2dc2ca279a17e3e20beb31627e789f97cc8602af

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.