parseDirectives function

  1. @Deprecated('Please use parseString instead')
CompilationUnit parseDirectives (
  1. String contents,
  2. {String name,
  3. bool suppressErrors: false,
  4. FeatureSet featureSet}

Parses the script tag and directives in a string of Dart code into an AST. (Currently broken; the entire file is parsed).

Stops parsing when the first non-directive is encountered. The rest of the string will not be parsed.

If name is passed, it's used in error messages as the name of the code being parsed.

Throws an AnalyzerErrorGroup if any errors occurred, unless suppressErrors is true, in which case any errors are discarded.

Deprecated - please use the parseString function (from package:analyzer/dart/analysis/utilities.dart) instead.

Note that parseString parses the whole file; callers that only require directives should simply ignore the rest of the parse result.


@Deprecated('Please use parseString instead')
CompilationUnit parseDirectives(String contents,
    {String name, bool suppressErrors = false, FeatureSet featureSet}) {
  // TODO(paulberry): make featureSet a required parameter.
  featureSet ??= FeatureSet.fromEnableFlags([]);
  var source = StringSource(contents, name);
  var errorCollector = _ErrorCollector();
  var reader = CharSequenceReader(contents);
  var scanner = Scanner(source, reader, errorCollector)
      featureSetForOverriding: featureSet,
      featureSet: featureSet,
  var token = scanner.tokenize();
  var parser = Parser(
    featureSet: featureSet,
  var unit = parser.parseDirectives(token);
  unit.lineInfo = LineInfo(scanner.lineStarts);

  if (errorCollector.hasErrors && !suppressErrors) throw;

  return unit;