jsparser 2.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

JSParser #

JSParser is an updgraded version, for Dart 2.4 and above, of ParseJS. ParseJS is a JavaScript parser for Dart. It is well-tested and is reasonably efficient. Original project : https://github.com/asgerf/parsejs.dart This project is intended to migrate it to dart 2.4 or above

Example Usage #

import 'package:jsparser/jsparser.dart';
import 'dart:io';

void main() {
    new File('test.js').readAsString().then((String code) {
        Program ast = parsejs(code, filename: 'test.js');
        // Use the AST for something
    });
}

Options #

The jsparser 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.

To run test cases #

  1. Open terminal and cd to parsejs.dart/test/util directory
  2. Do npm install
  3. CD to parsejs.dart/test/ director and run ./runtest

2.0.1 (2019-08-06) #

  • Amended Pub analysis suggestions

2.0.0 (2019-08-06) #

  • Updated for Dart 2.4

1.2.0 (2017-05-06) #

  • Added an option to parse the input as an expression.

1.1.0 (2015-06-01) #

  • Added visitor with one argument.

1.0.0 - 1.0.3 #

  • Initial version with some bugfixes releases.

example/example.dart

import 'package:jsparser/jsparser.dart';
import 'dart:io';

void main() {
  new File('test.js').readAsString().then((String code) {
    Program ast = parsejs(code, filename: 'test.js');
    // Use the AST for something
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jsparser: ^2.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:jsparser/jsparser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
22
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:jsparser/jsparser.dart with components: io.

Health suggestions

Fix lib/src/parser.dart. (-2.96 points)

Analysis of lib/src/parser.dart reported 6 hints, including:

line 319 col 11: Use isNotEmpty instead of length

line 460 col 11: DO use curly braces for all flow control structures.

line 488 col 43: Use = to separate a named parameter from its default value.

line 502 col 43: Use = to separate a named parameter from its default value.

line 536 col 65: Use = to separate a named parameter from its default value.

Fix lib/src/lexer.dart. (-1 points)

Analysis of lib/src/lexer.dart reported 2 hints:

line 176 col 39: Use = to separate a named parameter from its default value.

line 176 col 54: Use = to separate a named parameter from its default value.

Fix lib/src/annotations.dart. (-0.50 points)

Analysis of lib/src/annotations.dart reported 1 hint:

line 91 col 9: DO use curly braces for all flow control structures.

Fix additional 4 files with analysis or formatting issues. (-1 points)

Additional issues in the following files:

  • lib/src/ast_visitor.dart (1 hint)
  • lib/src/noise.dart (1 hint)
  • lib/jsparser.dart (Run dartfmt to format lib/jsparser.dart.)
  • lib/src/ast.dart (Run dartfmt to format lib/src/ast.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 < 3.0.0
unicode >=0.0.8 <1.0.0 0.2.2
Transitive dependencies
lists 0.1.3