Package Exports
- ecmascript-version-detector
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ecmascript-version-detector) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ecmascript-version-detector 
ECMAScript Version Detector library.
Online demo
Go to https://azu.github.io/ecmascript-version-detector/
Install
Install with npm:
npm install ecmascript-version-detectorUsage
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
}
}
},
{
"selector": "//ExpressionStatement",
"trivial": true,
"version": "3",
"en": {
"name": "ExpressionStatement"
},
"node": {
"type": "ExpressionStatement",
"start": 0,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 7
}
},
"expression": {
"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
}
}
}
},
{
"selector": "//NumericLiteral",
"version": "3",
"en": {
"name": "NumericLiteral"
},
"node": {
"type": "NumericLiteral",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
},
{
"selector": "//NumericLiteral",
"version": "3",
"en": {
"name": "NumericLiteral"
},
"node": {
"type": "NumericLiteral",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
}
},
"extra": {
"rawValue": 2,
"raw": "2"
},
"value": 2
}
},
{
"selector": "//Program[@sourceType=='module']",
"trivial": true,
"version": "2015",
"en": {
"name": "Program-module"
},
"node": {
"type": "Program",
"start": 0,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 7
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 7
}
},
"expression": {
"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
}
}
}
],
"directives": []
}
}
]
*/Contributing
Pull requests and stars are always welcome.
How to add data?
mkdir data/<new-node-type>- add
index.jstodata/<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 versionenname: display namelink: 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 testAuthor
License
MIT © azu
