Skip to content

Commit db47a84

Browse files
authored
Merge pull request #1262 from dart-lang/merge-source_maps-package
Merge `package:source_maps`
2 parents db4638d + e9fad4a commit db47a84

26 files changed

+2899
-0
lines changed

.github/ISSUE_TEMPLATE/source_maps.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:source_maps"
3+
about: "Create a bug or file a feature request against package:source_maps."
4+
labels: "package:source_maps"
5+
---

.github/labeler.yml

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696
- changed-files:
9797
- any-glob-to-any-file: 'pkgs/source_map_stack_trace/**'
9898

99+
'package:source_maps':
100+
- changed-files:
101+
- any-glob-to-any-file: 'pkgs/source_maps/**'
102+
99103
'package:unified_analytics':
100104
- changed-files:
101105
- any-glob-to-any-file: 'pkgs/unified_analytics/**'

.github/workflows/source_maps.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: package:source_maps
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/source_maps.yaml'
9+
- 'pkgs/source_maps/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/source_maps.yaml'
14+
- 'pkgs/source_maps/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/source_maps/
25+
26+
jobs:
27+
# Check code formatting and static analysis on a single OS (linux)
28+
# against Dart dev.
29+
analyze:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
sdk: [dev]
35+
steps:
36+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
37+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
38+
with:
39+
sdk: ${{ matrix.sdk }}
40+
- id: install
41+
name: Install dependencies
42+
run: dart pub get
43+
- name: Check formatting
44+
run: dart format --output=none --set-exit-if-changed .
45+
if: always() && steps.install.outcome == 'success'
46+
- name: Analyze code
47+
run: dart analyze --fatal-infos
48+
if: always() && steps.install.outcome == 'success'
49+
50+
# Run tests on a matrix consisting of two dimensions:
51+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
52+
# 2. release channel: dev
53+
test:
54+
needs: analyze
55+
runs-on: ${{ matrix.os }}
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
# Add macos-latest and/or windows-latest if relevant for this package.
60+
os: [ubuntu-latest]
61+
sdk: [3.3.0, dev]
62+
steps:
63+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
64+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
65+
with:
66+
sdk: ${{ matrix.sdk }}
67+
- id: install
68+
name: Install dependencies
69+
run: dart pub get
70+
- name: Run VM tests
71+
run: dart test --platform vm
72+
if: always() && steps.install.outcome == 'success'

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ don't naturally belong to other topic monorepos (like
3737
| [pool](pkgs/pool/) | Manage a finite pool of resources. Useful for controlling concurrent file system or network requests. | [![package issues](https://img.shields.io/badge/package:pool-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Apool) | [![pub package](https://img.shields.io/pub/v/pool.svg)](https://pub.dev/packages/pool) |
3838
| [pub_semver](pkgs/pub_semver/) | Versions and version constraints implementing pub's versioning policy. This is very similar to vanilla semver, with a few corner cases. | [![package issues](https://img.shields.io/badge/package:pub_semver-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Apub_semver) | [![pub package](https://img.shields.io/pub/v/pub_semver.svg)](https://pub.dev/packages/pub_semver) |
3939
| [source_map_stack_trace](pkgs/source_map_stack_trace/) | A package for applying source maps to stack traces. | [![package issues](https://img.shields.io/badge/package:source_map_stack_trace-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_map_stack_trace) | [![pub package](https://img.shields.io/pub/v/source_map_stack_trace.svg)](https://pub.dev/packages/source_map_stack_trace) |
40+
| [source_maps](pkgs/source_maps/) | A library to programmatically manipulate source map files. | [![package issues](https://img.shields.io/badge/package:source_maps-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_maps) | [![pub package](https://img.shields.io/pub/v/source_maps.svg)](https://pub.dev/packages/source_maps) |
4041
| [unified_analytics](pkgs/unified_analytics/) | A package for logging analytics for all Dart and Flutter related tooling to Google Analytics. | [![package issues](https://img.shields.io/badge/package:unified_analytics-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics) | [![pub package](https://img.shields.io/pub/v/unified_analytics.svg)](https://pub.dev/packages/unified_analytics) |
4142

4243
## Publishing automation

pkgs/source_maps/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.dart_tool/
2+
.packages
3+
.pub/
4+
pubspec.lock

pkgs/source_maps/CHANGELOG.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
## 0.10.13
2+
3+
* Require Dart 3.3
4+
* Move to `dart-lang/tools` monorepo.
5+
6+
## 0.10.12
7+
8+
* Add additional types at API boundaries.
9+
10+
## 0.10.11
11+
12+
* Populate the pubspec `repository` field.
13+
* Update the source map documentation link in the readme.
14+
15+
## 0.10.10
16+
17+
* Stable release for null safety.
18+
19+
## 0.10.9
20+
21+
* Fix a number of document comment issues.
22+
* Allow parsing source map files with a missing `names` field.
23+
24+
## 0.10.8
25+
26+
* Preserve source-map extensions in `SingleMapping`. Extensions are keys in the
27+
json map that start with `"x_"`.
28+
29+
## 0.10.7
30+
31+
* Set max SDK version to `<3.0.0`, and adjust other dependencies.
32+
33+
## 0.10.6
34+
35+
* Require version 2.0.0 of the Dart SDK.
36+
37+
## 0.10.5
38+
39+
* Add a `SingleMapping.files` field which provides access to `SourceFile`s
40+
representing the `"sourcesContent"` fields in the source map.
41+
42+
* Add an `includeSourceContents` flag to `SingleMapping.toJson()` which
43+
indicates whether to include source file contents in the source map.
44+
45+
## 0.10.4
46+
* Implement `highlight` in `SourceMapFileSpan`.
47+
* Require version `^1.3.0` of `source_span`.
48+
49+
## 0.10.3
50+
* Add `addMapping` and `containsMapping` members to `MappingBundle`.
51+
52+
## 0.10.2
53+
* Support for extended source map format.
54+
* Polish `MappingBundle.spanFor` handling of URIs that have a suffix that
55+
exactly match a source map in the MappingBundle.
56+
57+
## 0.10.1+5
58+
* Fix strong mode warning in test.
59+
60+
## 0.10.1+4
61+
62+
* Extend `MappingBundle.spanFor` to accept requests for output files that
63+
don't have source maps.
64+
65+
## 0.10.1+3
66+
67+
* Add `MappingBundle` class that handles extended source map format that
68+
supports source maps for multiple output files in a single mapper.
69+
Extend `Mapping.spanFor` API to accept a uri parameter that is optional
70+
for normal source maps but required for MappingBundle source maps.
71+
72+
## 0.10.1+2
73+
74+
* Fix more strong mode warnings.
75+
76+
## 0.10.1+1
77+
78+
* Fix all strong mode warnings.
79+
80+
## 0.10.1
81+
82+
* Add a `mapUrl` named argument to `parse` and `parseJson`. This argument is
83+
used to resolve source URLs for source spans.
84+
85+
## 0.10.0+2
86+
87+
* Fix analyzer error (FileSpan has a new field since `source_span` 1.1.1)
88+
89+
## 0.10.0+1
90+
91+
* Remove an unnecessary warning printed when the "file" field is missing from a
92+
Json formatted source map. This field is optional and its absence is not
93+
unusual.
94+
95+
## 0.10.0
96+
97+
* Remove the `Span`, `Location` and `SourceFile` classes. Use the
98+
corresponding `source_span` classes instead.
99+
100+
## 0.9.4
101+
102+
* Update `SpanFormatException` with `source` and `offset`.
103+
104+
* All methods that take `Span`s, `Location`s, and `SourceFile`s as inputs now
105+
also accept the corresponding `source_span` classes as well. Using the old
106+
classes is now deprecated and will be unsupported in version 0.10.0.
107+
108+
## 0.9.3
109+
110+
* Support writing SingleMapping objects to source map version 3 format.
111+
* Support the `sourceRoot` field in the SingleMapping class.
112+
* Support updating the `targetUrl` field in the SingleMapping class.
113+
114+
## 0.9.2+2
115+
116+
* Fix a bug in `FixedSpan.getLocationMessage`.
117+
118+
## 0.9.2+1
119+
120+
* Minor readability improvements to `FixedSpan.getLocationMessage` and
121+
`SpanException.toString`.
122+
123+
## 0.9.2
124+
125+
* Add `SpanException` and `SpanFormatException` classes.
126+
127+
## 0.9.1
128+
129+
* Support unmapped areas in source maps.
130+
131+
* Increase the readability of location messages.

pkgs/source_maps/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2014, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/source_maps/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/source_maps.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/source_maps.yaml)
2+
[![pub package](https://img.shields.io/pub/v/source_maps.svg)](https://pub.dev/packages/source_maps)
3+
[![package publisher](https://img.shields.io/pub/publisher/source_maps.svg)](https://pub.dev/packages/source_maps/publisher)
4+
5+
This project implements a Dart pub package to work with source maps.
6+
7+
## Docs and usage
8+
9+
The implementation is based on the [source map version 3 spec][spec] which was
10+
originated from the [Closure Compiler][closure] and has been implemented in
11+
Chrome and Firefox.
12+
13+
In this package we provide:
14+
15+
* Data types defining file locations and spans: these are not part of the
16+
original source map specification. These data types are great for tracking
17+
source locations on source maps, but they can also be used by tools to
18+
reporting useful error messages that include on source locations.
19+
* A builder that creates a source map programmatically and produces the encoded
20+
source map format.
21+
* A parser that reads the source map format and provides APIs to read the
22+
mapping information.
23+
24+
[closure]: https://github.com/google/closure-compiler/wiki/Source-Maps
25+
[spec]: https://docs.google.com/a/google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:dart_flutter_team_lints/analysis_options.yaml

pkgs/source_maps/lib/builder.dart

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Contains a builder object useful for creating source maps programatically.
6+
library source_maps.builder;
7+
8+
// TODO(sigmund): add a builder for multi-section mappings.
9+
10+
import 'dart:convert';
11+
12+
import 'package:source_span/source_span.dart';
13+
14+
import 'parser.dart';
15+
import 'src/source_map_span.dart';
16+
17+
/// Builds a source map given a set of mappings.
18+
class SourceMapBuilder {
19+
final List<Entry> _entries = <Entry>[];
20+
21+
/// Adds an entry mapping the [targetOffset] to [source].
22+
void addFromOffset(SourceLocation source, SourceFile targetFile,
23+
int targetOffset, String identifier) {
24+
ArgumentError.checkNotNull(targetFile, 'targetFile');
25+
_entries.add(Entry(source, targetFile.location(targetOffset), identifier));
26+
}
27+
28+
/// Adds an entry mapping [target] to [source].
29+
///
30+
/// If [isIdentifier] is true or if [target] is a [SourceMapSpan] with
31+
/// `isIdentifier` set to true, this entry is considered to represent an
32+
/// identifier whose value will be stored in the source map. [isIdentifier]
33+
/// takes precedence over [target]'s `isIdentifier` value.
34+
void addSpan(SourceSpan source, SourceSpan target, {bool? isIdentifier}) {
35+
isIdentifier ??= source is SourceMapSpan ? source.isIdentifier : false;
36+
37+
var name = isIdentifier ? source.text : null;
38+
_entries.add(Entry(source.start, target.start, name));
39+
}
40+
41+
/// Adds an entry mapping [target] to [source].
42+
void addLocation(
43+
SourceLocation source, SourceLocation target, String? identifier) {
44+
_entries.add(Entry(source, target, identifier));
45+
}
46+
47+
/// Encodes all mappings added to this builder as a json map.
48+
Map<String, dynamic> build(String fileUrl) {
49+
return SingleMapping.fromEntries(_entries, fileUrl).toJson();
50+
}
51+
52+
/// Encodes all mappings added to this builder as a json string.
53+
String toJson(String fileUrl) => jsonEncode(build(fileUrl));
54+
}
55+
56+
/// An entry in the source map builder.
57+
class Entry implements Comparable<Entry> {
58+
/// Span denoting the original location in the input source file
59+
final SourceLocation source;
60+
61+
/// Span indicating the corresponding location in the target file.
62+
final SourceLocation target;
63+
64+
/// An identifier name, when this location is the start of an identifier.
65+
final String? identifierName;
66+
67+
/// Creates a new [Entry] mapping [target] to [source].
68+
Entry(this.source, this.target, this.identifierName);
69+
70+
/// Implements [Comparable] to ensure that entries are ordered by their
71+
/// location in the target file. We sort primarily by the target offset
72+
/// because source map files are encoded by printing each mapping in order as
73+
/// they appear in the target file.
74+
@override
75+
int compareTo(Entry other) {
76+
var res = target.compareTo(other.target);
77+
if (res != 0) return res;
78+
res = source.sourceUrl
79+
.toString()
80+
.compareTo(other.source.sourceUrl.toString());
81+
if (res != 0) return res;
82+
return source.compareTo(other.source);
83+
}
84+
}

0 commit comments

Comments
 (0)