HTSource constructor

HTSource(
  1. String content, {
  2. String? fullName,
  3. HTResourceType type = HTResourceType.hetuModule,
  4. bool hashContent = false,
})

Implementation

HTSource(
  String content, {
  String? fullName,
  this.type = HTResourceType.hetuModule,
  bool hashContent = false,
})  : _content = content,
      _lineInfo = LineInfo.fromContent(content) {
  if (fullName != null) {
    _fullName = fullName;
  } else {
    final hash = crcString(content);
    final nameBuilder = StringBuffer();
    nameBuilder.write('${InternalIdentifier.anonymousScript}_$hash: ');
    var firstLine =
        content.trimLeft().replaceAll(RegExp(r'\s+'), ' ').trimRight();
    nameBuilder.write(firstLine.substring(
        0, math.min(_anonymousScriptNameLengthLimit, firstLine.length)));
    if (firstLine.length > _anonymousScriptNameLengthLimit) {
      nameBuilder.write('...');
    }
    _fullName = nameBuilder.toString();
  }

  if (hashContent) {
    _crc = crcString(content);
  }
}