jsparser 2.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

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]
51
Health:
Code health derived from static analysis. [more]
75
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Jun 22, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1

Health suggestions

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

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

line 27 col 11: Unnecessary new keyword.

line 87 col 31: Unnecessary new keyword.

line 123 col 12: Unnecessary new keyword.

line 138 col 20: Unnecessary new keyword.

line 144 col 20: Unnecessary new keyword.

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

Analysis of lib/src/lexer.dart reported 12 hints, including:

line 71 col 31: Unnecessary new keyword.

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.

line 200 col 11: Unnecessary new keyword.

line 204 col 12: Unnecessary new keyword.

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

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

line 7 col 3: Unnecessary new keyword.

line 8 col 3: Unnecessary new keyword.

line 29 col 24: Unnecessary new keyword.

line 35 col 24: Unnecessary new keyword.

line 62 col 24: Unnecessary new keyword.

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

Additional issues in the following files:

  • lib/jsparser.dart (3 hints)
  • lib/src/noise.dart (2 hints)
  • lib/src/ast_visitor.dart (1 hint)
  • 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.4
Transitive dependencies
lists 0.1.6