azu / Ecmascript Version Detector
Licence: mit
ECMAScript Version Detector
Stars: ✭ 54
Programming Languages
javascript
184084 projects - #8 most used programming language
ecmascript-version-detector
ECMAScript Version Detection library.
Online demo
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.
data?
How to addmkdir data/<new-node-type>
- add
index.js
todata/<new-node-type>
npm run build
- 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.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Resources
-
babylon/spec.md at master · babel/babylon
- AST Spec
-
rse/astq: Abstract Syntax Tree (AST) Query Engine
- XPath like Query engine for AST
Changelog
See Releases page.
Running tests
Install devDependencies and Run npm test
:
npm i -d && npm test
Author
License
MIT © azu
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].