Skip to content
ECMAScript Version Detector
JavaScript CSS HTML
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.
.travis
data
src
test
tools
website
.babelrc
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

ecmascript-version-detector Build Status

ECMAScript Version Detection library.

Online demo

screenshot

Go to https://azu.github.io/ecmascript-version-detector/

Install

Install with npm:

npm install ecmascript-version-detector

Usage

parse(code: string): {selector:string, version:string, node: Object, en: Object}[]

Parse code and return results.

const parse = require("ecmascript-version-detector").parse;
parse(`const x = 1 ** 2;`);
/*
[
    {
        "selector": "//BinaryExpression[@operator=='**']",
        "version": "2016",
        "en": {
            "name": "BinaryExpression exponentiation operator"
        },
        "node": {
            "type": "BinaryExpression",
            "start": 0,
            "end": 6,
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 6
                }
            },
            "left": {
                "type": "NumericLiteral",
                "start": 0,
                "end": 1,
                "loc": {
                    "start": {
                        "line": 1,
                        "column": 0
                    },
                    "end": {
                        "line": 1,
                        "column": 1
                    }
                },
                "extra": {
                    "rawValue": 1,
                    "raw": "1"
                },
                "value": 1
            },
            "operator": "**",
            "right": {
                "type": "NumericLiteral",
                "start": 5,
                "end": 6,
                "loc": {
                    "start": {
                        "line": 1,
                        "column": 5
                    },
                    "end": {
                        "line": 1,
                        "column": 6
                    }
                },
                "extra": {
                    "rawValue": 2,
                    "raw": "2"
                },
                "value": 2
            }
        }
    },
    ....
]
*/

Contributing

Pull requests and stars are always welcome.

How to add data?

  1. mkdir data/<new-node-type>
  2. add index.js to data/<new-node-type>
  3. npm run build
  4. Pull Request!!

index.js is following format:

// BooleanLiteral is `true` or `false`
// This is available since ECMAScript version 3
// Display name is "BooleanLiteral"
module.exports = {
    "selector": "//BooleanLiteral",
    "version": "3",
    "en": {
        "name": "BooleanLiteral",
        "link": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean"
    }
};
  • selector: the selector match the node type.
    • This project use ASTq query engine
    • This is similar to XPath query.
  • version: the feature is available in the version
  • en
    • name: display name
    • link: related link. e.g.) MDN link

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Resources

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Author

License

MIT © azu

You can’t perform that action at this time.