How to use the escodegen.generate function in escodegen

To help you get started, we’ve selected a few escodegen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jaz303 / spark / app / lib / modes / sketch / index.js View on Github external
code = editor.getCopyText();
                        }

                        try {

                            var ast = esprima.parse(code);

                            // find globals
                            var globals = findGlobals(ast);

                            // detect slow loops
                            // TODO: make this a configuration option
                            slowpoke(ast, {timeout: 5000});

                            // regenerate code
                            code = escodegen.generate(ast);

                        } catch (e) {
                            console.log(e);
                            // Parse failed.
                            // We'll just ignore this and let the runtime throw the error.
                        }
                        
                        var result = self._ctx.evaluate(code);
                        if (isError(result)) {
                            self._console.printObject(result);    
                        } else {
                            // TODO: this is a work-around for not have global
                            // variable extraction/injection.
                            if (setup) {
                                self._ctx.__js_setup();    
                            }
github material-components / material-components-web / utils / uniffe.js View on Github external
escodegen.attachComments(ast, comments, tokens);

  if (ast.body[0].expression === undefined ||
      ast.body[0].expression.callee === undefined) {
    return contents;
  }

  var rootProgram = ast.body[0].expression.callee.body;

  rootProgram.type = 'Program';
  // drop use strict
  rootProgram.body = rootProgram.body.slice(1);
  // attach all leading comments from outside iffe
  rootProgram.leadingComments = ast.body[0].leadingComments;

  return escodegen.generate(rootProgram, {comment: true});
}
github treycordova / nativejsx / test / compositions.js View on Github external
it('builds `var hello = document.createTextNode(\'Hello\')`', () => {
      assert.equal(
        escodegen.generate(
          compositions.createTextNode('hello', generators.literal('Hello'))
        ),
        "var hello = document.createTextNode('Hello');"
      )
    })
  })
github xml3d / shade.js / test / test_snippet.js View on Github external
it(description, function () {
        var outputJs = {
                type: Syntax.Program,
                body: ast.body[1].body
            };
        outputJs.body[0].id.name = "main";
        var outputGLSL = {
                type: Syntax.Program,
                body: ast.body[2].body
            };
        outputGLSL.body[0].id.name = "main";

        var snippetList = createSnippetList(connection, snippetsFunctions);
        var resultJs = SnippetConnector.connectSnippets(snippetList, {mode: SnippetConnector.MODE.JS_ITERATE});
        var compiledCode = codegen.generate(resultJs.ast);
        var expectedCode = codegen.generate(outputJs);
        compiledCode.should.eql(expectedCode);
        resultJs.argTypes.should.eql(jsInfo.argTypes);


        snippetList = createSnippetList(connection, snippetsFunctions);
        var resultGLSL = SnippetConnector.connectSnippets(snippetList, {mode: SnippetConnector.MODE.GLSL_VS});
        compiledCode = codegen.generate(resultGLSL.ast);
        expectedCode = codegen.generate(outputGLSL);
        compiledCode.should.eql(expectedCode);
        resultGLSL.argTypes.should.eql(glslInfo.argTypes);
        resultGLSL.inputIndices.should.eql(glslInfo.inputIndices);
    });
}
github power-assert-js / espower / test_helper.js View on Github external
var extractBodyOfAssertionAsCode = function (node) {
        var expression;
        if (node.type === 'ExpressionStatement') {
            expression = node.expression;
        } else if (node.type === 'ReturnStatement') {
            expression = node.argument;
        }
        return escodegen.generate(expression.arguments[0], {format: {compact: true}});
    };
    return function (line, options) {
github treycordova / nativejsx / jsxdom.js View on Github external
let textNode = createTextNode(name, node.value);
        let appendChildNode = appendChild(state.parent, name);

        node.transform = [textNode, appendChildNode];
      }
    }
  },
  'BinaryExpression': (node, state) => {
    if (state === 'JSXExpression') {
    }
  }
}, jsxBase);

//console.log(util.inspect(ast, {depth: null}));
console.log(escodegen.generate(ast));
fs.writeFileSync('test.js', escodegen.generate(ast));
github BetterJS / try-wrapper / index.js View on Github external
},
              guard: null,
              body: opt.caller ?
                typeof opt.caller === 'Object' ?
                  opt.caller : _parse(opt.caller) :
                DEFAULT_CALLER
            },
            guardedHandlers: [],
            finalizer: null
          }
        ]
      };
    }
  });

  return escodegen.generate(ast, {
    format: {
      indent: {
        style: '    '
      }
    }
  });
};
github marko-js / marko / src / components / taglib / TransformHelper / handleRootNodes.js View on Github external
return;
            }
        }

        transformHelper.context.addError(classEl, message);
        return;
    }
    let expression = tree.body[0].expression;

    if (expression.superClass && expression.superClass.name) {
        transformHelper.context.addError(classEl, 'A component class is not allowed to use `extends`. See: https://github.com/marko-js/marko/wiki/Error:-Component-class-with-extends');
        return;
    }

    let object = classToObject(expression, classEl, transformHelper);
    let componentVar = transformHelper.context.addStaticVar('marko_component', escodegen.generate(object));

    if (transformHelper.getRendererModule() != null) {
        transformHelper.context.addError(classEl, 'The component has both an inline component `class` and a separate `component.js`. This is not allowed. See: https://github.com/marko-js/marko/wiki/Error:-Component-inline-and-external');
        return;
    }

    var moduleInfo = {
        inlineId: componentVar,
        filename: transformHelper.filename,
        requirePath: './' + path.basename(transformHelper.filename)
    };

    if (transformHelper.getComponentModule() == null) {
        transformHelper.setComponentModule(moduleInfo);
    }
github qooxdoo / qooxdoo / tool / grunt / task / package / dependency / lib / qxCoreEnv.js View on Github external
);
  }

  var defaultsMap = {};
  var tree = esprima.parse(classCode);

  var controller = new estraverse.Controller();
  controller.traverse(tree, {
    enter : function (node, parent) {
      if (isDefaultsMap(node)) {
        defaultsMap = node.value;
      }
    }
  });

  return eval('(' + escodegen.generate(defaultsMap) + ')');
}