GithubHelp home page GithubHelp logo

dart-lang / source_maps Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 14.0 239 KB

A package to programmatically manipulate source maps.

Home Page: https://pub.dev/packages/source_maps

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%

source_maps's People

Contributors

athomas avatar chalin avatar dam0vm3nt avatar davidmorgan avatar dependabot[bot] avatar devoncarew avatar dgrove avatar floitschg avatar franklinyow avatar jacob314 avatar jakemac53 avatar kevmoo avatar lrhn avatar natebosch avatar nex3 avatar pq avatar ricowind avatar sethladd avatar sigmundch avatar srawlins avatar szakarias avatar todbachman-wf avatar whesse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

source_maps's Issues

add Mapping.urls property to sourcemaps

<img src="https://avatars.githubusercontent.com/u/2049220?v=3" align="left" width="96" height="96"hspace="10"> Issue by sigmundch
Originally opened as dart-lang/sdk#13194


Bug reported by @­skybrian in the old github repo (https://github.com/dart-lang/source-maps/issues/3)

Original bug description:


It seems like you should be able to say parse(json).urls to get all the source URL's, regardless of whether it's a SingleMapping or a MultiSectionMapping. To support this, Mapping should have an abstract "urls" getter which is implemented by MultiSectionMapping to combine all the url lists from the individual mappings.

Workaround: implement this yourself; it's not that hard.


Source-mapped Stack Trace Doesn't Match Chrome

We are having trouble with the reliability of applying source maps to stack traces. One of the things I'm finding is Mapping.spanFor sometimes returns null when I'd have expected to get a specific line in my code. It's possible that the way we are using source_maps is at fault, so if that's the case please let me know!

Here's a simple example that demonstrates the problem. It renders a single button that throws an exception when clicked. It catches the exception and applies the source map to the exception and then rethrows the exception so we can let Chrome handle it too.

pubspec.yaml:

name: stack_trace_parser

dependencies:
  browser: ">=0.10.0 <0.11.0"
  source_maps: ^0.10.1
  stack_trace: ^1.6.6

transformers:
- $dart2js:
    sourceMaps: true

web/index.html:

<html>
<head>
    <title>Stack Trace Parsing</title>
</head>
<body>
    <script type="application/dart" src="main.dart"></script>
    <script src="/packages/browser/dart.js"></script>
</body>
</html>

web/main.dart

import 'dart:async';
import 'dart:html';

import 'package:stack_trace_parser/stack_trace_parser.dart';

Future main() async {
  await loadSourceMap();
  addElements();
}

void addElements() {
  querySelector('body')
    ..append(new ButtonElement()
      ..text = 'Throw Exception'
      ..onClick.listen(_handleExceptionButton));
}

void _handleExceptionButton(_) {
  try {
    throw new IntegerDivisionByZeroException();
  } catch (e, stackTrace) {
    print(mapStackTrace(stackTrace));
    throw e;
  }
}

lib/stack_trace_parser.dart:

import 'dart:async';
import 'dart:html';

import 'package:source_maps/source_maps.dart';
import 'package:stack_trace/stack_trace.dart';

Mapping _sourceMap;

Future loadSourceMap() async {
  _sourceMap = parse(await HttpRequest.getString('main.dart.js.map'));
}

StackTrace mapStackTrace(StackTrace stackTrace) {
  var frames = new Trace.from(stackTrace).frames.map((Frame frame) {
    var span = _sourceMap.spanFor(frame.line - 1, (frame.column ?? 1) - 1);
    if (span == null) {
      return frame;
    }
    return new Frame(
        span.sourceUrl, span.start.line + 1, span.start.column + 1, span.text);
  });
  return new Trace(frames);
}

Steps to generate stack traces:

  1. Open Chrome
  2. Open the dev tools
  3. Edit dev tools settings and ensure Enable JavaScript source maps is checked
  4. pub serve
  5. Navigate to localhost:8080 in Chrome
  6. Click the button labeled Throw Exception
  7. Switch to the dev tools Console
  8. You should see the output from us applying the source map followed by Chrome handling the exception and applying the source map itself:
    image

Notice that our output differs on the second line of the stack trace from that of Chrome. In our case Mapping.spanFor returned null and we just passed the stack trace frame through unchanged. On the other hand, Chrome was able to use the source map to identify a line number in the original source file, main.dart (although the actual line number is off by two 😉 ).

Am I using the source_maps API correctly? If so, it seems like there might be an issue here in the source map parser.

DDC issue "Missing concrete implementation of 'SourceSpanMixin.highlight'. "

From @zoechi on November 19, 2016 11:43

I run bazelify init and bazelify serve on an Angular2 project. I didn't expect to succeed, just curious what would happen. If this issue is not useful or actionable, please just close it.

____[96 / 178] Compiling @yaml//:yaml with ddc
ERROR: /home/myuser/.cache/bazel/_bazel_myuser/d7cc63dbd0d8e0618a44683ac56d1bee/external/source_maps/BUILD:15:1: Compiling @source_maps//:source_maps with ddc failed: Worker process sent response with exit code: 1..
[error] Missing concrete implementation of 'SourceSpanMixin.highlight'. (package:source_maps/src/source_map_span.dart, line 39, col 7)

Dart VM version: 1.21.0-edge.66cb033ac11dfc576967025ba4a20e3aefbf41f2 (Fri Nov 18 16:50:33 2016) on "linux_x64"

bazel 0.2.2

Copied from original issue: dart-lang/source_span#11

Parser bug in source maps

<img src="https://avatars.githubusercontent.com/u/5689005?v=3" align="left" width="96" height="96"hspace="10"> Issue by peter-ahe-google
Originally opened as dart-lang/sdk#15124


From issue dart-lang/sdk#14746:

Although I haven't tested it, from looking at the source, I believe there is a similar issue when parsing a sourcemap. Sourcemap entries can have 1, 4, or 5 fields and the 1-field entries (representing an unmapped range) aren't handled correctly; the sourceUrlId, sourceLine, sourceColumn, and fields in a TargetEntry should be set to null but instead they will be set to whatever the values were in the previous TargetEntry.

Invalid version constraint in recent pubspec.yaml

Our build server is throwing an error based on the recent changes to the source_maps/pubspec.yaml file. The dart sdk version we have been using sucessfully for over a year to build a GUI throws the following error:

[exec] Error in pubspec for package "source_maps" loaded from https://pub.dartlang.org/api/packages/source_maps/versions/0.10.0%2B2:
[exec] Invalid version constraint for "dependencies.path": Could not parse version "^1.2.0". Unknown text at "^1.2.0".
[exec] Result: 1

Where there changes to the pubspec specification that now allow for carets?

Thanks,

-Dirv

PKG source_maps: No member named 'url'...

Originally opened as dart-lang/sdk#19605

This issue was originally filed by [email protected]


bin/packages/source_maps/span.dart:67:18:
Warning: No member named 'url' in class 'Span'.
    var source = url == null ? '' : ' of ${p.prettyUri(url)}';
                 ^^^
bin/packages/source_maps/span.dart:67:56:
Warning: No member named 'url' in class 'Span'.
    var source = url == null ? '' : ' of ${p.prettyUri(url)}';
                                                       ^^^

Analyzer issue in parser_test.dart

When analyzing parser_test.dart, Analyzer shows me:

253: The argument type 'List' can't be assigned to the parameter type 'Map'. [ARGUMENT_TYPE_NOT_ASSIGNABLE]

because parseJson() doesn't take a List.

Span.getLocationMessage returns incorrect output for lines without trailing newlines

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="96" height="96"hspace="10"> Issue by nex3
Originally opened as dart-lang/sdk#19665


If a span points to the final line in a file, and that line doesn't end in a newline, the arrows in getLocationMessage will be rendered on the same line as the source text. For example:

    Error on line 12, column 28 of pubspec.yaml: Error loading transformer: I hate these settings!
      - app/src/html_rewriter: {} ^^

Invalid override in strong mode

 (master) $ bazelify serve
Building server via bazel...

WARNING: Sandboxed execution is not supported on your system and thus hermeticity of actions cannot be guaranteed. See http://bazel.io/docs/bazel-user-manual.html#sandboxing for more information. You can turn off this warning via --ignore_unsupported_sandboxing.
____Loading package: 
____Loading complete.  Analyzing...
____Found 1 target...
____Building...
____[9 / 75] Compiling @charcode//:charcode with ddc
____[14 / 92] Compiling @watcher//:watcher with ddc
____[18 / 104] Compiling @mime//:mime with ddc
____[28 / 114] Compiling @fixnum//:fixnum with ddc
____[30 / 114] Building flattened source layout for //:main_ddc_serve
____[32 / 114] Compiling @package_config//:package_config with ddc
____[42 / 114] Summarizing Dart library @intl//:intl (strong mode)
____From Compiling @which//:which with ddc:
[warning] Unsound implicit cast from 'dynamic' to 'Future<bool>'. (package:which/src/is_executable.dart, line 12, col 5)
[warning] Unsound implicit cast from 'dynamic' to '(dynamic) → bool'. (package:which/src/util.dart, line 9, col 23)
____From Compiling @mime//:mime with ddc:
[warning] Unsound implicit cast from 'Stream<dynamic>' to 'Stream<MimeMultipart>'. (package:mime/src/bound_multipart_stream.dart, line 89, col 40)
[warning] Unsound implicit cast from 'Stream<dynamic>' to 'Stream<List<int>>'. (package:mime/src/bound_multipart_stream.dart, line 321, col 45)
____From Compiling @isolate//:isolate with ddc:
[warning] Unsound implicit cast from 'Future<dynamic>' to 'Future<bool>'. (package:isolate/isolate_runner.dart, line 133, col 12)
[warning] Unsound implicit cast from 'List<dynamic>' to 'List<Future<dynamic>>'. (package:isolate/load_balancer.dart, line 101, col 14)
[warning] Unsound implicit cast from 'List<dynamic>' to 'List<Future<dynamic>>'. (package:isolate/load_balancer.dart, line 130, col 12)
[warning] Unsound implicit cast from 'List<dynamic>' to 'List<_LoadBalancerEntry>'. (package:isolate/load_balancer.dart, line 240, col 14)
[warning] Unsound implicit cast from 'Future<dynamic>' to 'Future<Capability>'. (package:isolate/registry.dart, line 128, col 12)
[warning] Unsound implicit cast from 'Future<dynamic>' to 'Future<bool>'. (package:isolate/registry.dart, line 150, col 12)
[warning] Unsound implicit cast from 'List<dynamic>' to 'List<int>'. (package:isolate/registry.dart, line 164, col 21)
[warning] Unsound implicit cast from 'Future<dynamic>' to 'Future<List<T>>'. (package:isolate/registry.dart, line 220, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'List<int>'. (package:isolate/registry.dart, line 323, col 18)
[warning] Unsound implicit cast from 'dynamic' to 'List<int>'. (package:isolate/registry.dart, line 326, col 21)
[warning] Unsound implicit cast from 'Future<dynamic>' to 'Future<List<dynamic>>'. (package:isolate/src/errors.dart, line 89, col 12)
[warning] Unsound implicit cast from 'Future<dynamic>' to 'Future<List<dynamic>>'. (package:isolate/src/errors.dart, line 147, col 12)
ERROR: /home/zoechi/.cache/bazel/_bazel_zoechi/3e443aaa6a6cf1824cc4980f306f0a94/external/source_maps/BUILD:15:1: Compiling @source_maps//:source_maps with ddc failed: Worker process sent response with exit code: 1..
[error] Invalid override. The type of 'Entry.compareTo' ('(Entry) → int') isn't a subtype of 'Comparable<dynamic>.compareTo' ('(dynamic) → int'). (package:source_maps/builder.dart, line 80, col 3)

Please fix all errors before compiling (warnings are okay).
Target //:main_ddc_serve failed to build
Use --verbose_failures to see the command lines of failed build steps.
____Elapsed time: 3.953s, Critical Path: 3.59s

Dart VM version: 1.21.0-edge.89560c68a0660c752025339154271cccc3bc12dc (Fri Oct 28 12:49:47 2016) on "linux_x64"

Create a unified SourceMap class

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="96" height="96"hspace="10"> Issue by nex3
Originally opened as dart-lang/sdk#13805


Right now, when building a source map, you can only get a map or a JSON string. When parsing the map, though, you get an instance of the Mapping interface, which provides a few APIs for inspecting the contents but no way to re-serialize the map.

It would be preferable to have a single class representing a source map that can be serialized and inspected. It would also be good to have a more thorough inspection API than Mapping currently provides -- at the very least a way to get a list of all the segments in the source map, a way to access/modify the source files, etc.

strong mode still fails

: [error] Invalid override. The type of Entry.compareTo ((Entry) → int) is not a subtype of Comparable<dynamic>.compareTo ((dynamic) → int). (package:source_maps/builder.dart, line 80, col 3)

Support absolute URLs

Currently the URLs presented for a source map's source spans are exactly as they appear in the original file. However, tools like dart2js often generate relative or root-relative URLs. It would be cool to have an option when parsing a source map to pass a sourceUrl parameter that would produce a mapping with absolute URLs.

How do I use generated source maps in my server application?

My setup may be a bit unique but I'm hoping I can get some guidance here.

I have working Firebase Cloud Functions written in Dart and compiled with dart2js and working with Node. I'm using the following package to make this happen:

https://pub.dev/packages/firebase_functions_interop
https://pub.dev/packages/firebase_admin_interop

Everything works great except that stack traces aren't human readable. I can see the source map that is generated but I can't seem to figure out how to get that to help make our printed stack traces usable. Any tips?

Emit spans with reasonable ends

Currently (unless the user passes in SourceFiles) the spans emitted by this package don't have useful end locations. Non-identifier spans are always point locations, although typically a source map entry is considered to continue until the next entry rather than being a single point. Identifier spans are even worse: their text fields are used to contain the identifier, which is often (usually) not actual text from the source file, which is what the field is for.

Issue dart-lang/source_span#3 will allow these spans to have the correct end position set without necessarily having access to the text of the span.

Issue with Polymer v0.12.0 and Dart v1.6.0-edge

<img src="https://avatars.githubusercontent.com/u/2130849?v=3" align="left" width="96" height="96"hspace="10"> Issue by kaendfinger
Originally opened as dart-lang/sdk#20290


When I run 'pub serve':

IO : Created temp directory /tmp/pub_5DIc3B
IO : Writing 220 characters to text file /tmp/pub_5DIc3B/runInIsolate.dart.
ERR : [Observable on polymer|lib/src/instance.dart]:
    | Class 'Object' has no instance getter 'sourceUrl'.
    |
    | NoSuchMethodError: method not found: 'sourceUrl'
    | Receiver: Instance of 'Object'
    | Arguments: []
    | dart:core-patch/object_patch.dart 45 Object.noSuchMethod
    | http://0.0.0.0:40411/packages/source_span/src/location.dart 81:26 SourceLocation.==
    | http://0.0.0.0:40411/packages/source_maps/printer.dart 228:23 NestedPrinter.writeTo
    | http://0.0.0.0:40411/packages/source_maps/printer.dart 213:12 NestedPrinter.build
    | http://0.0.0.0:40411/packages/observe/transformer.dart 78:20 ObservableTransformer.apply.<fn>
    | dart:async/zone.dart 1088 _RootZone.runUnary
    | dart:async/future_impl.dart 488 _Future._propagateToListeners.handleValueCallback
    | dart:async/future_impl.dart 571 _Future._propagateToListeners
    | dart:async/future_impl.dart 331 _Future._completeWithValue
    | dart:async/future_impl.dart 393 _Future._asyncComplete.<fn>
    | dart:async/schedule_microtask.dart 23 _asyncRunCallbackLoop
    | dart:async/schedule_microtask.dart 32 _asyncRunCallback
    | dart:isolate-patch/isolate_patch.dart 126 _RawReceivePortImpl._handleMessage
    |
    | dart:core Object.noSuchMethod
    | http://0.0.0.0:40411/packages/source_span/src/location.dart 81:26 SourceLocation.==
    | http://0.0.0.0:40411/packages/source_maps/printer.dart 228:23 NestedPrinter.writeTo
    | http://0.0.0.0:40411/packages/source_maps/printer.dart 213:12 NestedPrinter.build
    | http://0.0.0.0:40411/packages/observe/transformer.dart 78:20 ObservableTransformer.apply.<fn>
    | dart:isolate _RawReceivePortImpl._handleMessage
IO : Deleting directory /tmp/pub_5DIc3B.
FINE: Loading polymer transformers finished (0.8s).
FINE: Transformers from polymer: {Instance of 'PolymerTransformerGroup'}
FINE: Transformers from polymer: {Instance of 'PolymerTransformerGroup'}

How to get source maps from dart2js compiled files and deferred loading?

Hi,
I am trying to use source_map_stack_trace package and in the example it requires me to get the source map in code.

var mapping = // Get a source map mapping the JS to the Dart source.

// Convert jsTrace to refer to the Dart source instead.
var dartTrace = mapStackTrace(jsTrace, sourceMap);

I do not understand how to get the mapping. During compiling, I know that dart2js outputs a source map with .map extension. Should I fetch the file in code with HTTP or with other methods? If so, dart2js with deferred loading generates maps for all part.js files. How can I retrieve those source maps in code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.