This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 1,000,000+ packages pre-installed, including
compare-ast with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
This module exports a function with the following signature:
compareAst(expectedJsSource, actualJsSource [, options])
compareAst supports configuration of the following relaxing options:
varPattern- a regular expression describing identifier names that, when encountered in the "expected" AST, will be "bound" to the corresponding identifier in the "actual" AST. All further occurences of that identifier must match the original bound value.
stringPattern- a regular expression describing string values that, when encountered in the "expected" AST, will be "bound" to the corresponding string value in the "actual" AST. All further occurences of that string value must match the original bound value.
See the "Examples" section below for more information on defining these relaxing options.
options object may specify an array of
comparators. These functions can
be used to further relax the criteria for equivalency. Each will be invoked for
every node under comparison. These nodes are generated by
esprima; see the esprima
documentation for a description of their
compareAst recognizes the following comparator return types:
compareAst.Errors- the two nodes are not equivalent
true- the two nodes are equivalent
undefined- equivalency cannot be determined by this comparator
$ npm test
Copyright (c) 2014 Mike Pennisi
Licensed under the MIT license.