Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Handle null names field when parsing source map files #40

Merged

Conversation

todbachman-wf
Copy link
Contributor

Problem:

If names doesn't exist in a source map file, parsing it fails with the following exception:

  NoSuchMethodError: The getter 'iterator' was called on null.
  Receiver: null
  Tried calling: iterator
  dart:core                               new List.from
  package:source_maps/parser.dart 345:15  new SingleMapping.fromJson
  package:source_maps/parser.dart 72:24   parseJson
  package:source_maps/parser.dart 27:5    parse
  test/parser_test.dart 134:9             main.<fn>

Source maps created by Dart tooling don't seem to omit this field. However, you will encounter this exception if you use this library to parse a source map that was created by tooling that omits the names field when the list is empty. For example, the Go package used by gopherjs to generate source maps omits fields when they are empty. We could update that package so it doesn't omit empty fields when encoding them to json, but it's certainly possible this could be an issue with source maps generated by other toolchains as well.

Solution:

Added a null-aware operator to treat a missing names field as an empty list.

@robbecker-wf
Copy link

@kevmoo @sigmundch This fixes some sourcemapping errors we're getting. Mind taking a look?

Copy link
Contributor

@sigmundch sigmundch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Technically this is a mandatory field according to the source-map v3 specification, but I'm not opposed to making the parser a bit more resilient here. It might not be a bad idea to send a fix to the Go package as well.

@todbachman-wf
Copy link
Contributor Author

@sigmundch I agree this ought to be fixed at the source too. I just put up a PR to the Go package to do just that. It looks like there haven't been any commits in over 4 years, so I'm not sure if this will get merged or not. 🤞

@natebosch natebosch merged commit de5ce0b into dart-archive:master Feb 11, 2020
@todbachman-wf todbachman-wf deleted the handle_null_names_field branch February 11, 2020 15:42
@todbachman-wf
Copy link
Contributor Author

Thanks for the merge y'all! Would you mind cutting a release for us? Thanks!

@natebosch
Copy link
Contributor

published as 0.10.9

mosuem pushed a commit to dart-lang/tools that referenced this pull request Dec 10, 2024
…ource_maps#40)

The field is required by the spec, but we can be more lenient.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

5 participants