0.0.1 • Published 7 years ago

orsa-js-analyzer v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Orsa Javascript analyzer

There is a reason why languages like TypeScript exist, and that's because Javascript, as much as we love it, has about fifteen ways to do anything. That makes it really hard to pick out language features, like class definitions, imports, exports, JSX uses, etc. This library exists apart from Orsa to make it easier to manage the pattern matching for features in Javascript.

This library normalizes the different ways that a feature is expressed in Javascript into a standard set of feature objects. For example, const Foo = React.createClass({...}), class Foo extends React.Component { ... }, and const MyComponent = (props) => (...); are all normalized into a class with different metadata. This makes it easier for downstream analysis applications, like Orsa, to get a high level view of what is defined and where.

Terminology

TermMeaning
FeaturesAn important feature in a JS file. This includes things like class definitions, uses of JSX, imports and requires. All features have a type which define what the feature is, as well as a start and end which store the start and end line numbers. Beyond that each feature has different attributes.
MatcherA function that, given an AST node and a path, returns a feature if it finds one.

Class

FieldTypeDescription
startnumberThe starting line number.
endnumberThe ending line number.
typestringclass
namestringThe name of the class.
superClassstringThe superclass
metadataobjectAdditional metadata about the class.
metadata.reactbooleanTrue if this is a react component.
metadata.statelessbooleanTrue if this is a stateless react component.
methodsarrayAn array of methods
jsDocobjectJSDoc information

Method

FieldTypeDescription
startnumberThe starting line number.
endnumberThe ending line number.
typestringmethod
namestringThe name of the method.
kindstringThe kind of the method as defined by babylon.
paramsarrayThe parameters.
jsDocobjectJSDoc information

Parameter

FieldTypeDescription
startnumberThe starting line number.
endnumberThe ending line number.
typestringparameter
namestringThe name of the method.

Import

FieldTypeDescription
startnumberThe starting line number.
endnumberThe ending line number.
typestringimport
fromstringThe name of what's being imported.
keysarrayThe names of the variables that the import is being assigned to.

JSX Usage

FieldTypeDescription
startnumberThe starting line number.
endnumberThe ending line number.
typestringjsx-usage
namestringThe name of the component.
basestringThe base name of the component if it's in the form of <Foo.Bar /> base would be Foo.
attributesarrayThe attributes used by the component invocation.

Connection to orsa-ast-parser

There is a development dependency on orsa-ast-parser because we want't to ensure that the AST that we are traversing is based on the same babylon parameters as is used by Orsa core.