--------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- project estools version 0.0.0 unit struct info This is a new project. Here we provide some user information in [Markdown](http://en.wikipedia.org/wiki/Markdown) syntax. comment A **comment** is some information for developers, hidden from the ordinary user. --- --- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- // EcmaScriptTools --------------------------------------------------------------------------------------------------- unit struct name EcmaScriptTools info See * [Esprima](http://require ('esprima') . org/) an ES6 parser * [The ESTree Spec](https://github.com/estree/estree) * [ECMAScript Tooling](https://github.com/estools) * [escodegen](https://github.com/estools/escodegen) --- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- // EcmaScriptTools.Esprima --------------------------------------------------------------------------------------------------- --- unit doc name EcmaScriptTools header Parsing ECMAScript code with `Esprima` --- unit struct name EcmaScriptTools.Esprima info Our interface with the [Esprima](http://require ('esprima') . org/) parser. --- --- unit doc name EcmaScriptTools.Esprima header The types --- unit type name EcmaScriptTools.Esprima.POSITION value Type.model ({line: INT, column: NUMBER}) --- unit type name EcmaScriptTools.Esprima.SOURCE_LOCATION value Type.model ({ source : Type.nullify (STRING), start : Type.nullify (POSITION), end : Type.nullify (POSITION) }) --- unit type name EcmaScriptTools.Esprima.NODE value Type.model ({type: STRING, loc: SOURCE_LOCATION}) --- unit type name EcmaScriptTools.Esprima.TOKEN value Type.model ({ type : Type.finite (['Boolean', 'Identifier', 'Keyword', 'Null', 'Numeric', 'Punctuator', 'String', 'RegularExpression']), value : ANYTHING, loc : SOURCE_LOCATION }) --- unit type name EcmaScriptTools.Esprima.COMMENT value Type.model ({ type : Type.finite (['Line', 'Block']), value : STRING, loc : SOURCE_LOCATION }) info .... --- unit doc name EcmaScriptTools.Esprima header The lexical tokenizer and syntactical parser --- --- unit function name EcmaScriptTools.Esprima.parse type Type.lambda ([STRING, NODE]) value function (s) { return require ('esprima') . parse (s, {loc: false, range: false, raw: false, tokens: false, comment: true}) } info .... --- unit function name EcmaScriptTools.Esprima.tokenize type Type.lambda ([STRING, Type.list (TOKEN)]) value function (s) { return require ('esprima') . tokenize (s, {loc: true}); } info ..... --- unit function name EcmaScriptTools.Esprima.comments type Type.lambda ([STRING, Type.list (COMMENT)]) value function (s) { return require ('esprima') . parse ((s, {comment: true, loc: true}) . comments); } info ..... --- --------------------------------------------------------------------------------------------------- // end EcmaScriptTools.Esprima --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- // EcmaScriptTools.EsCodeGen --------------------------------------------------------------------------------------------------- unit doc name EcmaScriptTools header Code generation with `escodegen` --- unit struct name EcmaScriptTools.EsCodeGen info Our interface with the [escodegen](https://github.com/estools/escodegen) code generator. --- --- unit function name EcmaScriptTools.EsCodeGen.code type Type.lambda ([Esprima.NODE, STRING]) value function (node) { var options = { comment: true, format: { compact: false, indent: { style: ' ', // four spaces is default, but I prefer two, base: 2, // base indent level adjustMultilineComment: true // Adjust the indentation of multiline comments to keep asterisks verticall aligned. Default is `false` } } }; try { return require ('escodegen') . generate (node, options); } catch (e) { throw Error ("Error generating the code for the given node:\n" + e); } } info ... --- unit function name EcmaScriptTools.EsCodeGen.compactCode type Type.lambda ([Esprima.NODE, STRING]) value function (node) { var options = { comment: false, format: { compact: true // do not include superfluous whitespace characters and line terminators } }; try { return require ('escodegen') . generate (node, options); } catch (e) { throw Error ("Error generating the code for the given node:\n" + e); } } info ... --- --------------------------------------------------------------------------------------------------- // end EcmaScriptTools.EsCodeGen --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- // end EcmaScriptTools ---------------------------------------------------------------------------------------------------