Skip to content
No description, website, or topics provided.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
babel @ 81a6337
js-gen
js-samples
.gitmodules
LICENSE
README.md
index.js
package.json

README.md

returnif Demo

Checkout out the full post here: https://suczewski.com/2018/07/returnif

Here's a demonstration of the new returnif keyword.

This repo includes adamlouis/babel as a git submodule.

The index.js file:

  1. reads all files in js-samples dir as strings
  2. runs generate(parse(CODE))
  3. writes the AST and the transpiled JS to js-gen dir
  4. excutes the generated js in thejs-gen dir

before:

function fibonacci(num, results = {}) {
    returnif results[num];

    // TODO -> returnif (num <= 1) : 1;
    if (num <= 1) {
        return 1
    }

    return results[num] = (
        fibonacci(num - 1, results) +
        fibonacci(num - 2, results)
    );
}

after:

function fibonacci(num, results = {}) {
  var returnIf_2978980376 = (results[num]);
  if (returnIf_2978980376) {
    return returnIf_2978980376;
  }
  // TODO -> returnif (num <= 1) : 1;

  if (num <= 1) {
    return 1;
  }

  return results[num] = fibonacci(num - 1, results) + fibonacci(num - 2, results);
}

Running

clone

git clone git@github.com:adamlouis/returnif.git

build the babel submodule

git submodule update --init
cd babel
npm i
npm run build
cd ..

You may get some errors during npm run build. These are fine as long as @babel/generator and @babel/parser build correctly. You can verify this by checking for the presence of the ./babel/packages/babel-parser/lib and ./babel/packages/babel-generator/lib directories.

run

node .
You can’t perform that action at this time.