How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • let acorn = require("acorn");
    console.log(acorn.parse("1 + 1", { ecmaVersion: 2020 }));
    
    Docs
    0
  • var acorn = require("acorn"),
      jsesc = require("jsesc"),
      walk = require("estree-walker").walk,
      MagicString = require("magic-string"),
      createFilter = require("rollup-pluginutils").createFilter,
      extname = require("path").extname;
    
    module.exports = function (options) {
      if (options == null) options = {};
      var filter = createFilter(
          options.include,
          options.exclude
        ),
        map = options.sourceMap !== false;
      return {
        transform: function (code, id) {
          if (!filter(id) || extname(id) !== ".js") return;
    
          var ast,
            magic = new MagicString(code),
            modified;
    
          try {
            ast = acorn.parse(code, {
              ecmaVersion: 6,
              sourceType: "module",
            });
          } catch (error) {
            error.message += " in " + id;
            throw error;
          }
    
          walk(ast, {
            enter: function (node, parent) {
              if (map) {
                magic.addSourcemapLocation(node.start);
                magic.addSourcemapLocation(node.end);
              }
              if (
                node.type === "Literal" &&
                typeof node.value === "string"
              ) {
                var raw0 = node.raw,
                  raw1 = jsesc(node.value, {
                    wrap: true,
                    quotes:
                      raw0[0] === "'" ? "single" : "double",
                  });
                if (raw0 !== raw1) {
                  modified = true;
                  magic.overwrite(node.start, node.end, raw1);
                }
              }
            },
          });
    
          return (
            modified && {
              code: magic.toString(),
              map: map && magic.generateMap(),
            }
          );
        },
      };
    };
    
    /mbostock/rollup-plugin-ascii bsd-3-clause
    0
  • var acorn = require("acorn");
    var jsx = require("acorn-jsx");
    var JSXParser = acorn.Parser.extend(jsx());
    JSXParser.parse("foo()", { ecmaVersion: 2020 });
    
    Docs
    0
  • var acorn = require("acorn");
    var jsx = require("acorn-jsx");
    var JSXParser = acorn.Parser.extend(jsx());
    JSXParser.parse("foo()", { ecmaVersion: 2020 });
    
    Docs
    0
  • var acorn = require("acorn");
    var jsx = require("acorn-jsx");
    acorn.Parser.extend(jsx()).parse("my(, 'code');");
    
    Docs
    0
  • for (let token of acorn.tokenizer(str)) {
      // iterate over the tokens
    }
    
    // transform code to array of tokens:
    var tokens = [...acorn.tokenizer(str)];
    
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples