1.0.6 • Published 1 year ago

@tabaneproject/ecmagen v1.0.6

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
1 year ago

image BasedPkg CommitActivity GitHub last commit ECMAGen is an ECMAScript (pka. JavaScript) AST Code Transformator/Generator. Mostly supporting Mozilla's Parser API AST Specification. This project is a reduxed version of the commonly used escodegen package. Compared to the original package, this package should be used in a Node.js platform.

How to install

You can either clone the repos from releases, or you can add this current tree as a submodule for a potentially unstable release. To add as a submodule, use:

git submodules add https://github.com/tabaneproject/ecmagen

To get the latest release from the NPM registry, use:

npm install @tabaneproject/ecmagen

How to use

// Import ECMAGen and your favorite
// Code Parser; and of course the FS.
import ecmagen from '@tabaneproject/ecmagen';
import acorn from 'acorn';
import fs from 'node:fs';

// Use ECMAGen
let text = fs.readFileSync( __dirname + '/testcode.js', { encoding: 'utf-8' } );
let ast = acorn.parse( text, { ecmaVersion: 2020 } );
let output = ecmagen.generate( ast );

// Write Output
fs.writeFileSync( __dirname + '/testcode.copy.js', output );

Hello World Program

// Import ECMAGen
import ecmagen from '@tabaneproject/ecmagen';

// Use ECMAGen
let ast = {
    type: 'BinaryExpression',
    operator: '-',
    left: { type: 'Literal', value: 100 },
    right: { type: 'Literal', value: 60 }
};
let output = ecmagen.generate( ast );
console.log( output ); // 100 - 60

License

Copyright (C) 2012 Yusuke Suzuki for the original project escodegen Copyright (C) 2024 TabaneProject for the reduxed version, ECMAGen Copyright (C) 2024 Botaro Shinomiya, for TabaneProject Copyright (C) 2024 OSCILLIX, for TabaneProject Copyright (C) 2024 Bluskript, for TabaneProject And the copyright of the other contributors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

*   Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
*   Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1-fix

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago