ParseJS is a JavaScript parser for Dart. It is well-tested and is reasonably efficient.
import 'package:parsejs/parsejs.dart';
void main() {
new File('test.js').readAsString().then((String code) {
Program ast = parsejs(code, filename: 'test.js')
// Use the AST for something
})
}
The parsejs
function takes the following optional arguments:
filename
: An arbitrary string indicating where the source came from. For your convenience this will be available on Node.filename
and on ParseError.filename
.firstLine
: The line number to associate with the first line of code. Default is 1. Useful if code was extracted from an HTML file, and you prefer absolute line numbers.handleNoise
: If true, parser will try to ignore hash bangs and HTML comment tags surrounding the source code. Default is true.annotate
: If true, parser will initialize Node.parent
, Scope.environment
, and Name.scope
, to simplify subsequent AST analysis. Default is true.parseAsExpression
: If true, the input will be parsed as an expression statement.Add this to your package's pubspec.yaml file:
dependencies:
parsejs: "^1.2.0"
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:parsejs/parsejs.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.2.0 | May 6, 2017 |
|
|
1.1.0 | Jun 1, 2015 |
|
|
1.0.3 | Dec 17, 2014 |
|
|
1.0.2 | Nov 24, 2014 |
|
|
1.0.1 | Nov 24, 2014 |
|
|
1.0.0 | Nov 24, 2014 |
|
|
We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
20 | / 100 |
Health:
Code health derived from static analysis.
[more]
|
100 | / 100 |
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100 | / 100 |
Overall score:
Weighted score of the above.
[more]
|
60 |
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:parsejs/parsejs.dart
.
The description is too short.
Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.
Maintain an example.
Create a short demo in the
example/
directory to show how to use this package. Common file name patterns include:main.dart
,example.dart
or you could also useparsejs.dart
.
Fix analysis and formatting issues.
Analysis or formatting checks reported 1 hint.
Run
dartfmt
to formatlib/src/ast.dart
.