parseDirectives function

  1. @Deprecated('Please use parseString instead')
CompilationUnit parseDirectives (String contents, { String name, bool suppressErrors: false, 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 = new StringSource(contents, name);
  var errorCollector = new _ErrorCollector();
  var reader = new CharSequenceReader(contents);
  var scanner = new Scanner(source, reader, errorCollector)
  var token = scanner.tokenize();
  var parser = new Parser(source, errorCollector, featureSet: featureSet);
  var unit = parser.parseDirectives(token);
  unit.lineInfo = new LineInfo(scanner.lineStarts);

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

  return unit;