diff --git a/.eslintrc.js b/.eslintrc.js
index ce74b583..e08d79be 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,51 +1,35 @@
"use strict";
module.exports = {
- "env": {
- "node": true,
- "es6": true
+ env: {
+ node: true,
+ es6: true,
},
- "parserOptions": {
- "ecmaVersion": 9
- },
+ extends: ["prettier"],
- "globals": {
- "fetch": false,
- "WebAssembly": false
+ parserOptions: {
+ ecmaVersion: 9,
},
- "rules": {
- // Require spacing around =>
- "arrow-spacing": "error",
-
- // Braces only needed for multi-line arrow function blocks
- // "arrow-body-style": ["error", "as-needed"]
+ globals: {
+ fetch: false,
+ WebAssembly: false,
+ },
+ rules: {
// Always require spacing around a single line block
"block-spacing": "error",
- // No newline before open brace for a block
- "brace-style": ["error", "1tbs", { "allowSingleLine": true }],
-
- // No space before always a space after a comma
- "comma-spacing": ["error", {"after": true, "before": false}],
-
- // Commas at the end of the line not the start
- "comma-style": "error",
-
// Warn about cyclomatic complexity in functions.
// XXX Get this down to 20?
- "complexity": ["error", 25],
-
- // Don't require spaces around computed properties
- "computed-property-spacing": ["error", "never"],
+ complexity: ["error", 25],
// Functions must always return something or nothing
"consistent-return": "error",
// Require braces around blocks that start a new line
- "curly": ["error", "multi-line"],
+ curly: ["error", "multi-line"],
// Encourage the use of dot notation whenever possible.
"dot-notation": "error",
@@ -53,25 +37,6 @@ module.exports = {
// Always require a trailing EOL
"eol-last": "error",
- // No spaces between function name and parentheses
- "func-call-spacing": "error",
-
- // Require function* name()
- "generator-star-spacing": ["error", {"after": true, "before": false}],
-
- // Two space indent
- // "indent": ["error", 2, { "SwitchCase": 1 }],
-
- // Space after colon not before in property declarations
- "key-spacing": ["error", {
- "afterColon": true,
- "beforeColon": false,
- "mode": "minimum"
- }],
-
- // Require spaces before and after keywords
- "keyword-spacing": "error",
-
// Unix linebreaks
"linebreak-style": ["error", "unix"],
@@ -125,7 +90,7 @@ module.exports = {
"no-else-return": "error",
// No empty statements
- "no-empty": ["error", {"allowEmptyCatch": true}],
+ "no-empty": ["error", { allowEmptyCatch: true }],
// No empty character classes in regex
"no-empty-character-class": "error",
@@ -145,9 +110,6 @@ module.exports = {
// No using !! where casting to boolean is already happening
"no-extra-boolean-cast": "error",
- // No double semicolon
- "no-extra-semi": "error",
-
// No overwriting defined functions
"no-func-assign": "error",
@@ -163,7 +125,7 @@ module.exports = {
// Disallow the use of the __iterator__ property
"no-iterator": "error",
- // No labels
+ // No labels
"no-labels": "error",
// Disallow unnecessary nested blocks
@@ -172,16 +134,18 @@ module.exports = {
// No single if block inside an else block
"no-lonely-if": "error",
- // no-tabs disallows tabs completely.
- // "no-mixed-spaces-and-tabs": "error",
-
// No unnecessary spacing
- "no-multi-spaces": ["error", { exceptions: {
- "ArrayExpression": true,
- "AssignmentExpression": true,
- "ObjectExpression": true,
- "VariableDeclarator": true
- } }],
+ "no-multi-spaces": [
+ "error",
+ {
+ exceptions: {
+ ArrayExpression: true,
+ AssignmentExpression: true,
+ ObjectExpression: true,
+ VariableDeclarator: true,
+ },
+ },
+ ],
// No reassigning native JS objects
"no-native-reassign": "error",
@@ -228,9 +192,6 @@ module.exports = {
// Disallow tabs.
"no-tabs": "error",
- // No trailing whitespace
- "no-trailing-spaces": "error",
-
// No using undeclared variables
"no-undef": "error",
@@ -250,10 +211,13 @@ module.exports = {
"no-unsafe-negation": "error",
// No declaring variables that are never used
- "no-unused-vars": ["error", {
- "args": "none",
- "vars": "local"
- }],
+ "no-unused-vars": [
+ "error",
+ {
+ args: "none",
+ vars: "local",
+ },
+ ],
// No using variables before defined
"no-use-before-define": ["error", "nofunc"],
@@ -271,56 +235,18 @@ module.exports = {
// Use const or let instead of var
"no-var": "error",
- // Disallow whitespace before properties.
- "no-whitespace-before-property": "error",
-
// No using with
"no-with": "error",
// Require object-literal shorthand with ES6 method syntax
- "object-shorthand": ["error", "always", { "avoidQuotes": true }],
+ "object-shorthand": ["error", "always", { avoidQuotes: true }],
// Use const instead of let where possible
"prefer-const": "error",
- // Require double-quotes everywhere, except where quotes are escaped
- // or template literals are used.
- "quotes": ["error", "double", {
- "allowTemplateLiterals": true,
- "avoidEscape": true
- }],
-
- // No spacing inside rest or spread expressions
- "rest-spread-spacing": "error",
-
- // Always require semicolon at end of statement
- "semi": ["error", "always"],
-
// Require space before blocks
"space-before-blocks": "error",
- // Never use spaces before function parentheses
- "space-before-function-paren": ["error", {
- "anonymous": "never",
- "asyncArrow": "always",
- "named": "never"
- }],
-
- // No space padding in parentheses
- "space-in-parens": ["error", "never"],
-
- // Require spaces around operators
- "space-infix-ops": ["error", { "int32Hint": true }],
-
- // ++ and -- should not need spacing
- "space-unary-ops": ["error", {
- "nonwords": false,
- "overrides": {
- "typeof": false // We tend to use typeof as a function call
- },
- "words": true
- }],
-
// Requires or disallows a whitespace (space or tab) beginning a comment
"spaced-comment": "error",
@@ -328,6 +254,8 @@ module.exports = {
"use-isnan": "error",
// Only check typeof against valid results
- "valid-typeof": "error"
- }
+ "valid-typeof": "error",
+
+ "max-len": ["error", { code: 120, ignoreUrls: true }],
+ },
};
diff --git a/.gitattributes b/.gitattributes
index 4e271005..476ec9d3 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,18 +1,2 @@
-dist/source-map.debug.js binary
-dist/source-map.js binary
-dist/source-map.min.js binary
-dist/source-map.min.js.map binary
-
-dist/test/test_api.js binary
-dist/test/test_array_set.js binary
-dist/test/test_base64.js binary
-dist/test/test_base64_vlq.js binary
-dist/test/test_binary_search.js binary
-dist/test/test_dog_fooding.js binary
-dist/test/test_quick_sort.js binary
-dist/test/test_source_map_consumer.js binary
-dist/test/test_source_map_generator.js binary
-dist/test/test_source_node.js binary
-dist/test/test_util.js binary
-
bench/scalajs-runtime-sourcemap.js binary
+wasm-mappings/benches/part-of-scala-js-source-map -diff -merge
diff --git a/.github/codecov.yml b/.github/codecov.yml
new file mode 100644
index 00000000..5f0c402a
--- /dev/null
+++ b/.github/codecov.yml
@@ -0,0 +1,11 @@
+comment:
+ require_changes: true
+
+coverage:
+ status:
+ project:
+ default:
+ informational: true
+ patch:
+ default:
+ informational: true
diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml
new file mode 100644
index 00000000..bb422d05
--- /dev/null
+++ b/.github/workflows/cargo.yml
@@ -0,0 +1,41 @@
+on:
+ pull_request:
+ branches: [master]
+ paths:
+ - wasm-mappings/**
+ - .github/workflows/cargo.yml
+ push:
+ branches: [master]
+ workflow_dispatch:
+
+name: WASM tests
+
+defaults:
+ run:
+ working-directory: ./wasm-mappings
+
+jobs:
+ build_and_test:
+ name: WASM mappings
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ toolchain: [stable, beta, nightly]
+ job: [test, bench, wasm]
+ exclude:
+ - toolchain: stable
+ job: bench
+ - toolchain: stable
+ job: wasm
+ - toolchain: beta
+ job: bench
+ - toolchain: beta
+ job: wasm
+ steps:
+ - uses: actions/checkout@v2
+ - uses: actions-rs/toolchain@v1
+ with:
+ toolchain: ${{ matrix.toolchain }}
+ override: true
+ default: true
+ - run: JOB=${{ matrix.job }} ./ci/script.sh
diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
new file mode 100644
index 00000000..bcb3d7b0
--- /dev/null
+++ b/.github/workflows/nodejs.yml
@@ -0,0 +1,39 @@
+name: Node.js
+
+on:
+ pull_request:
+ branches: [master]
+ push:
+ branches: [master]
+ workflow_dispatch:
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ node-version: [12, 14, 16, 18]
+
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: ${{ matrix.node-version }}
+ - run: npm ci
+ - run: npm test
+
+ lint:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ - run: npm ci
+ - run: npm run lint
+ - run: npm run toc
+ - run: git diff --stat --exit-code
+ - run: npx prettier --check .
+ - run: npm run coverage
+ - run: npx c8 report --reporter=lcov
+ - uses: codecov/codecov-action@v3
diff --git a/.gitignore b/.gitignore
index b81c6373..7abedbcf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,10 @@
*.iml
*.log
.idea
+.DS_Store
node_modules/*
build/
-package-lock.json
bench/*.svg
-.nyc_output/
+bench/dist/
+bench/node_modules
coverage/
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..163c0757
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "test/source-map-tests"]
+ path = test/source-map-tests
+ url = https://github.com/tc39/source-map-tests.git
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 00000000..9179b1bd
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,4 @@
+bench/
+coverage/
+node_modules/
+target/
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 00000000..c2ad263b
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,7 @@
+{
+ "arrowParens": "avoid",
+ "endOfLine": "lf",
+ "printWidth": 80,
+ "tabWidth": 2,
+ "trailingComma": "es5"
+}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 0bc39f18..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-language: node_js
-
-sudo: false
-
-node_js:
- - "8"
- - "9"
-
-install:
-- npm install
-- npm install coveralls
-
-script:
-- npm run coverage
-
-after_success:
-- nyc report --reporter=text-lcov | coveralls
-
-cache:
- directories:
- - node_modules
-
-os:
- - linux
- - osx
diff --git a/.waiting.html b/.waiting.html
deleted file mode 100644
index a964629d..00000000
--- a/.waiting.html
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- Code coverage report for All files
-
-
-
- This page will refresh with a coverage report, as long as you have
- executed npm run dev
. Please be patient.
-
-
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef31a099..35f97a9e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,344 +1,378 @@
# Change Log
+## 0.8.0-beta.0
+
+### Breaking changes
+
+- [#350](https://github.com/mozilla/source-map/pull/350) -
+ Change browser detection logic for WASM loading.
+- [#363](https://github.com/mozilla/source-map/pull/363) -
+ Change WASM loading detection to rely on `package.json#browser` field.
+- [#362](https://github.com/mozilla/source-map/pull/362) -
+ Remove the `dist/` bundle.
+- [#371](https://github.com/mozilla/source-map/pull/371) -
+ Reimplement sourcemap URL processing using the WHATWG URL API.
+
+### Nonbreaking changes:
+
+- [#339](https://github.com/mozilla/source-map/pull/339) -
+ Allow initializing the consumer `mappings.wasm` file as an `ArrayBuffer`.
+
+### Internal Improvements:
+
+- [#347](https://github.com/mozilla/source-map/pull/347) -
+ Improve tests.
+- [#352](https://github.com/mozilla/source-map/pull/352) -
+ Improve documentation.
+- [#361](https://github.com/mozilla/source-map/pull/361) -
+ Use newer Webpack CLI when bundling.
+- [#364](https://github.com/mozilla/source-map/pull/364) -
+ Convert `IndexedSourceMapConsumer` implementation to pass more through
+ to `BasicSourceMapConsumer`.
+- [#366](https://github.com/mozilla/source-map/pull/366) -
+ Normalize internal URL representation to be easier to follow.
+- [#341](https://github.com/mozilla/source-map/pull/341) -
+ Use async functions to simplify `SourceMapConsumer.with` implementation.
+
## 0.7.3
-* Fix a bug where nested uses of `SourceMapConsumer` could result in a
+- Fix a bug where nested uses of `SourceMapConsumer` could result in a
`TypeError`. [#338](https://github.com/mozilla/source-map/issues/338)
[#330](https://github.com/mozilla/source-map/issues/330)
[#319](https://github.com/mozilla/source-map/issues/319)
## 0.7.2
-* Another 3x speed up in `SourceMapConsumer`. Read about it here:
+- Another 3x speed up in `SourceMapConsumer`. Read about it here:
http://fitzgeraldnick.com/2018/02/26/speed-without-wizardry.html
## 0.7.1
-* Updated TypeScript typings. [#321][]
+- Updated TypeScript typings. [#321][]
[#321]: https://github.com/mozilla/source-map/pull/321
## 0.7.0
-* `SourceMapConsumer` now uses WebAssembly, and is **much** faster! Read about
+- `SourceMapConsumer` now uses WebAssembly, and is **much** faster! Read about
it here:
https://hacks.mozilla.org/2018/01/oxidizing-source-maps-with-rust-and-webassembly/
-* **Breaking change:** `new SourceMapConsumer` now returns a `Promise` object
+- **Breaking change:** `new SourceMapConsumer` now returns a `Promise` object
that resolves to the newly constructed `SourceMapConsumer` instance, rather
than returning the new instance immediately.
-* **Breaking change:** when you're done using a `SourceMapConsumer` instance,
+- **Breaking change:** when you're done using a `SourceMapConsumer` instance,
you must call `SourceMapConsumer.prototype.destroy` on it. After calling
`destroy`, you must not use the instance again.
-* **Breaking change:** `SourceMapConsumer` used to be able to handle lines,
+- **Breaking change:** `SourceMapConsumer` used to be able to handle lines,
columns numbers and source and name indices up to `2^53 - 1` (aka
`Number.MAX_SAFE_INTEGER`). It can now only handle them up to `2^32 - 1`.
-* **Breaking change:** The `source-map` library now uses modern ECMAScript-isms:
+- **Breaking change:** The `source-map` library now uses modern ECMAScript-isms:
`let`, arrow functions, `async`, etc. Use Babel to compile it down to
ECMAScript 5 if you need to support older JavaScript environments.
-* **Breaking change:** Drop support for Node < 8. If you want to support older
-versions of node, please use v0.6 or below.
+- **Breaking change:** Drop support for Node < 8. If you want to support older
+ versions of node, please use v0.6 or below.
## 0.5.6
-* Fix for regression when people were using numbers as names in source maps. See
+- Fix for regression when people were using numbers as names in source maps. See
#236.
## 0.5.5
-* Fix "regression" of unsupported, implementation behavior that half the world
+- Fix "regression" of unsupported, implementation behavior that half the world
happens to have come to depend on. See #235.
-* Fix regression involving function hoisting in SpiderMonkey. See #233.
+- Fix regression involving function hoisting in SpiderMonkey. See #233.
## 0.5.4
-* Large performance improvements to source-map serialization. See #228 and #229.
+- Large performance improvements to source-map serialization. See #228 and #229.
## 0.5.3
-* Do not include unnecessary distribution files. See
+- Do not include unnecessary distribution files. See
commit ef7006f8d1647e0a83fdc60f04f5a7ca54886f86.
## 0.5.2
-* Include browser distributions of the library in package.json's `files`. See
+- Include browser distributions of the library in package.json's `files`. See
issue #212.
## 0.5.1
-* Fix latent bugs in IndexedSourceMapConsumer.prototype._parseMappings. See
+- Fix latent bugs in IndexedSourceMapConsumer.prototype.\_parseMappings. See
ff05274becc9e6e1295ed60f3ea090d31d843379.
## 0.5.0
-* Node 0.8 is no longer supported.
+- Node 0.8 is no longer supported.
-* Use webpack instead of dryice for bundling.
+- Use webpack instead of dryice for bundling.
-* Big speedups serializing source maps. See pull request #203.
+- Big speedups serializing source maps. See pull request #203.
-* Fix a bug with `SourceMapConsumer.prototype.sourceContentFor` and sources that
+- Fix a bug with `SourceMapConsumer.prototype.sourceContentFor` and sources that
explicitly start with the source root. See issue #199.
## 0.4.4
-* Fix an issue where using a `SourceMapGenerator` after having created a
+- Fix an issue where using a `SourceMapGenerator` after having created a
`SourceMapConsumer` from it via `SourceMapConsumer.fromSourceMap` failed. See
issue #191.
-* Fix an issue with where `SourceMapGenerator` would mistakenly consider
+- Fix an issue with where `SourceMapGenerator` would mistakenly consider
different mappings as duplicates of each other and avoid generating them. See
issue #192.
## 0.4.3
-* A very large number of performance improvements, particularly when parsing
+- A very large number of performance improvements, particularly when parsing
source maps. Collectively about 75% of time shaved off of the source map
parsing benchmark!
-* Fix a bug in `SourceMapConsumer.prototype.allGeneratedPositionsFor` and fuzzy
+- Fix a bug in `SourceMapConsumer.prototype.allGeneratedPositionsFor` and fuzzy
searching in the presence of a column option. See issue #177.
-* Fix a bug with joining a source and its source root when the source is above
+- Fix a bug with joining a source and its source root when the source is above
the root. See issue #182.
-* Add the `SourceMapConsumer.prototype.hasContentsOfAllSources` method to
+- Add the `SourceMapConsumer.prototype.hasContentsOfAllSources` method to
determine when all sources' contents are inlined into the source map. See
issue #190.
## 0.4.2
-* Add an `.npmignore` file so that the benchmarks aren't pulled down by
+- Add an `.npmignore` file so that the benchmarks aren't pulled down by
dependent projects. Issue #169.
-* Add an optional `column` argument to
+- Add an optional `column` argument to
`SourceMapConsumer.prototype.allGeneratedPositionsFor` and better handle lines
with no mappings. Issues #172 and #173.
## 0.4.1
-* Fix accidentally defining a global variable. #170.
+- Fix accidentally defining a global variable. #170.
## 0.4.0
-* The default direction for fuzzy searching was changed back to its original
+- The default direction for fuzzy searching was changed back to its original
direction. See #164.
-* There is now a `bias` option you can supply to `SourceMapConsumer` to control
+- There is now a `bias` option you can supply to `SourceMapConsumer` to control
the fuzzy searching direction. See #167.
-* About an 8% speed up in parsing source maps. See #159.
+- About an 8% speed up in parsing source maps. See #159.
-* Added a benchmark for parsing and generating source maps.
+- Added a benchmark for parsing and generating source maps.
## 0.3.0
-* Change the default direction that searching for positions fuzzes when there is
+- Change the default direction that searching for positions fuzzes when there is
not an exact match. See #154.
-* Support for environments using json2.js for JSON serialization. See #156.
+- Support for environments using json2.js for JSON serialization. See #156.
## 0.2.0
-* Support for consuming "indexed" source maps which do not have any remote
+- Support for consuming "indexed" source maps which do not have any remote
sections. See pull request #127. This introduces a minor backwards
incompatibility if you are monkey patching `SourceMapConsumer.prototype`
methods.
## 0.1.43
-* Performance improvements for `SourceMapGenerator` and `SourceNode`. See issue
+- Performance improvements for `SourceMapGenerator` and `SourceNode`. See issue
#148 for some discussion and issues #150, #151, and #152 for implementations.
## 0.1.42
-* Fix an issue where `SourceNode`s from different versions of the source-map
+- Fix an issue where `SourceNode`s from different versions of the source-map
library couldn't be used in conjunction with each other. See issue #142.
## 0.1.41
-* Fix a bug with getting the source content of relative sources with a "./"
+- Fix a bug with getting the source content of relative sources with a "./"
prefix. See issue #145 and [Bug 1090768](bugzil.la/1090768).
-* Add the `SourceMapConsumer.prototype.computeColumnSpans` method to compute the
+- Add the `SourceMapConsumer.prototype.computeColumnSpans` method to compute the
column span of each mapping.
-* Add the `SourceMapConsumer.prototype.allGeneratedPositionsFor` method to find
+- Add the `SourceMapConsumer.prototype.allGeneratedPositionsFor` method to find
all generated positions associated with a given original source and line.
## 0.1.40
-* Performance improvements for parsing source maps in SourceMapConsumer.
+- Performance improvements for parsing source maps in SourceMapConsumer.
## 0.1.39
-* Fix a bug where setting a source's contents to null before any source content
+- Fix a bug where setting a source's contents to null before any source content
had been set before threw a TypeError. See issue #131.
## 0.1.38
-* Fix a bug where finding relative paths from an empty path were creating
+- Fix a bug where finding relative paths from an empty path were creating
absolute paths. See issue #129.
## 0.1.37
-* Fix a bug where if the source root was an empty string, relative source paths
+- Fix a bug where if the source root was an empty string, relative source paths
would turn into absolute source paths. Issue #124.
## 0.1.36
-* Allow the `names` mapping property to be an empty string. Issue #121.
+- Allow the `names` mapping property to be an empty string. Issue #121.
## 0.1.35
-* A third optional parameter was added to `SourceNode.fromStringWithSourceMap`
+- A third optional parameter was added to `SourceNode.fromStringWithSourceMap`
to specify a path that relative sources in the second parameter should be
relative to. Issue #105.
-* If no file property is given to a `SourceMapGenerator`, then the resulting
+- If no file property is given to a `SourceMapGenerator`, then the resulting
source map will no longer have a `null` file property. The property will
simply not exist. Issue #104.
-* Fixed a bug where consecutive newlines were ignored in `SourceNode`s.
+- Fixed a bug where consecutive newlines were ignored in `SourceNode`s.
Issue #116.
## 0.1.34
-* Make `SourceNode` work with windows style ("\r\n") newlines. Issue #103.
+- Make `SourceNode` work with windows style ("\r\n") newlines. Issue #103.
-* Fix bug involving source contents and the
+- Fix bug involving source contents and the
`SourceMapGenerator.prototype.applySourceMap`. Issue #100.
## 0.1.33
-* Fix some edge cases surrounding path joining and URL resolution.
+- Fix some edge cases surrounding path joining and URL resolution.
-* Add a third parameter for relative path to
+- Add a third parameter for relative path to
`SourceMapGenerator.prototype.applySourceMap`.
-* Fix issues with mappings and EOLs.
+- Fix issues with mappings and EOLs.
## 0.1.32
-* Fixed a bug where SourceMapConsumer couldn't handle negative relative columns
+- Fixed a bug where SourceMapConsumer couldn't handle negative relative columns
(issue 92).
-* Fixed test runner to actually report number of failed tests as its process
+- Fixed test runner to actually report number of failed tests as its process
exit code.
-* Fixed a typo when reporting bad mappings (issue 87).
+- Fixed a typo when reporting bad mappings (issue 87).
## 0.1.31
-* Delay parsing the mappings in SourceMapConsumer until queried for a source
+- Delay parsing the mappings in SourceMapConsumer until queried for a source
location.
-* Support Sass source maps (which at the time of writing deviate from the spec
+- Support Sass source maps (which at the time of writing deviate from the spec
in small ways) in SourceMapConsumer.
## 0.1.30
-* Do not join source root with a source, when the source is a data URI.
+- Do not join source root with a source, when the source is a data URI.
-* Extend the test runner to allow running single specific test files at a time.
+- Extend the test runner to allow running single specific test files at a time.
-* Performance improvements in `SourceNode.prototype.walk` and
+- Performance improvements in `SourceNode.prototype.walk` and
`SourceMapConsumer.prototype.eachMapping`.
-* Source map browser builds will now work inside Workers.
+- Source map browser builds will now work inside Workers.
-* Better error messages when attempting to add an invalid mapping to a
+- Better error messages when attempting to add an invalid mapping to a
`SourceMapGenerator`.
## 0.1.29
-* Allow duplicate entries in the `names` and `sources` arrays of source maps
+- Allow duplicate entries in the `names` and `sources` arrays of source maps
(usually from TypeScript) we are parsing. Fixes github issue 72.
## 0.1.28
-* Skip duplicate mappings when creating source maps from SourceNode; github
+- Skip duplicate mappings when creating source maps from SourceNode; github
issue 75.
## 0.1.27
-* Don't throw an error when the `file` property is missing in SourceMapConsumer,
+- Don't throw an error when the `file` property is missing in SourceMapConsumer,
we don't use it anyway.
## 0.1.26
-* Fix SourceNode.fromStringWithSourceMap for empty maps. Fixes github issue 70.
+- Fix SourceNode.fromStringWithSourceMap for empty maps. Fixes github issue 70.
## 0.1.25
-* Make compatible with browserify
+- Make compatible with browserify
## 0.1.24
-* Fix issue with absolute paths and `file://` URIs. See
+- Fix issue with absolute paths and `file://` URIs. See
https://bugzilla.mozilla.org/show_bug.cgi?id=885597
## 0.1.23
-* Fix issue with absolute paths and sourcesContent, github issue 64.
+- Fix issue with absolute paths and sourcesContent, github issue 64.
## 0.1.22
-* Ignore duplicate mappings in SourceMapGenerator. Fixes github issue 21.
+- Ignore duplicate mappings in SourceMapGenerator. Fixes github issue 21.
## 0.1.21
-* Fixed handling of sources that start with a slash so that they are relative to
+- Fixed handling of sources that start with a slash so that they are relative to
the source root's host.
## 0.1.20
-* Fixed github issue #43: absolute URLs aren't joined with the source root
+- Fixed github issue #43: absolute URLs aren't joined with the source root
anymore.
## 0.1.19
-* Using Travis CI to run tests.
+- Using Travis CI to run tests.
## 0.1.18
-* Fixed a bug in the handling of sourceRoot.
+- Fixed a bug in the handling of sourceRoot.
## 0.1.17
-* Added SourceNode.fromStringWithSourceMap.
+- Added SourceNode.fromStringWithSourceMap.
## 0.1.16
-* Added missing documentation.
+- Added missing documentation.
-* Fixed the generating of empty mappings in SourceNode.
+- Fixed the generating of empty mappings in SourceNode.
## 0.1.15
-* Added SourceMapGenerator.applySourceMap.
+- Added SourceMapGenerator.applySourceMap.
## 0.1.14
-* The sourceRoot is now handled consistently.
+- The sourceRoot is now handled consistently.
## 0.1.13
-* Added SourceMapGenerator.fromSourceMap.
+- Added SourceMapGenerator.fromSourceMap.
## 0.1.12
-* SourceNode now generates empty mappings too.
+- SourceNode now generates empty mappings too.
## 0.1.11
-* Added name support to SourceNode.
+- Added name support to SourceNode.
## 0.1.10
-* Added sourcesContent support to the customer and generator.
+- Added sourcesContent support to the customer and generator.
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 00000000..0d424fd8
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,16 @@
+# Community Participation Guidelines
+
+This repository is governed by Mozilla's code of conduct and etiquette guidelines.
+For more details, please read the
+[Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/).
+
+## How to Report
+
+For more information on how to report violations of the Community Participation Guidelines, please read our '[How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/)' page.
+
+
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 053a5ab8..c3509743 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -3,13 +3,16 @@
Thank you for your interest in contributing to this library! Contributions are
very appreciated.
---------------------------------------------------------------------------------
+If you want help or mentorship, reach out to us in a GitHub issue,
+or over Matrix in [source-map on mozilla.org](https://matrix.to/#/#source-map:mozilla.org)
+and introduce yourself.
-
+---
+
+## Table of Contents
-## Table of Contents
- [Filing Issues](#filing-issues)
- [Building From Source](#building-from-source)
@@ -21,25 +24,23 @@ very appreciated.
-
-
## Filing Issues
If you are filing an issue for a bug or other misbehavior, please provide:
-* **A test case.** The more minimal the better, but sometimes a larger test case
+- **A test case.** The more minimal the better, but sometimes a larger test case
cannot be helped. This should be in the form of a gist, node script,
repository, etc.
-* **Steps to reproduce the bug.** The more exact and specific the better.
+- **Steps to reproduce the bug.** The more exact and specific the better.
-* **The result you expected.**
+- **The result you expected.**
-* **The actual result.**
+- **The actual result.**
## Building From Source
-Install Node.js `8` or greater and then run
+Install Node.js `12` or greater and then run
$ git clone https://github.com/mozilla/source-map.git
$ cd source-map/
@@ -51,7 +52,7 @@ Next, run
This will create the following files:
-* `dist/source-map.js` - The plain browser build.
+- `dist/source-map.js` - The plain browser build.
## Submitting Pull Requests
@@ -64,7 +65,7 @@ force push to the remote branch to update the pull request.
## Running Tests
-The test suite is written for node.js. Install node.js `8` or greater and
+The test suite is written for node.js. Install node.js `12` or greater and
then run the tests with `npm test`:
```shell
@@ -93,15 +94,15 @@ suite.
The `assert` argument is a cut down version of node's assert module. You have
access to the following assertion functions:
-* `doesNotThrow`
+- `doesNotThrow`
-* `equal`
+- `equal`
-* `ok`
+- `ok`
-* `strictEqual`
+- `strictEqual`
-* `throws`
+- `throws`
(The reason for the restricted set of test functions is because we need the
tests to run inside Firefox's test suite as well and Firefox has a shimmed
@@ -111,31 +112,19 @@ There are additional test utilities and helpers in `./test/util.js` which you
can use as well:
```js
-var util = require('./util');
+var util = require("./util");
```
## Checking code coverage
-It's fun to find ways to test lines of code that aren't visited by
-the tests yet.
+It's fun to find ways to test lines of code that aren't visited by the tests yet.
```shell
$ npm run coverage
$ open coverage/index.html
```
-This will allow you to browse to red sections of the code that need
-more attention. Even more cool, however, is to run:
-
-```shell
-$ npm run dev
-```
-
-(On some operating systems, this may pop up a request for node to be able to open a socket. Click "Allow" or the equivalent.)
-
-This will run the coverage tools, and monitor all of the files in the
-project, re-running the coverage tools and refreshing the browser when
-any files change. There will be a small web server running on port 4103 to enable this. Control-C to stop.
+This will allow you to browse to red sections of the code that need more attention.
## Updating the `lib/mappings.wasm` WebAssembly Module
@@ -153,11 +142,10 @@ $ rustup toolchain install nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
```
-Next, clone the Rust source used to create `lib/mappings.wasm`:
+Move to wasm sources folder:
```
-$ git clone https://github.com/fitzgen/source-map-mappings.git
-$ cd source-map-mappings/
+$ cd wasm-mappings/
```
Make sure the crate's tests pass:
@@ -173,9 +161,13 @@ Ensure that you have the following wasm post-processing tools installed:
- `wasm-snip`: https://github.com/fitzgen/wasm-snip
- `wasm-opt`: https://github.com/WebAssembly/binaryen
+(These dependencies should automatically be installed by cargo)
+
Build Rust crate as a `.wasm` file:
```
$ cd source-map-mappings-wasm-api/
-$ ./build.py -o path/to/source-map/lib/mappings.wasm
+$ ./build.py -o ../../lib/mappings.wasm
```
+
+See further information in [wasm-mappings/CONTRIBUTING.md].
diff --git a/README.md b/README.md
index 56e5ac3e..72402e35 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,5 @@
# Source Map
-[](https://travis-ci.org/mozilla/source-map)
-
-[](https://coveralls.io/github/mozilla/source-map)
-
[](https://www.npmjs.com/package/source-map)
This is a library to generate and consume the source map format
@@ -17,20 +13,21 @@ This is a library to generate and consume the source map format
## Use on the Web
-
-
+```html
+
+
+```
---------------------------------------------------------------------------------
+---
-
+## Table of Contents
-## Table of Contents
- [Examples](#examples)
- [Consuming a source map](#consuming-a-source-map)
@@ -79,33 +76,37 @@ This is a library to generate and consume the source map format
```js
const rawSourceMap = {
version: 3,
- file: 'min.js',
- names: ['bar', 'baz', 'n'],
- sources: ['one.js', 'two.js'],
- sourceRoot: 'http://example.com/www/js/',
- mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
+ file: "min.js",
+ names: ["bar", "baz", "n"],
+ sources: ["one.js", "two.js"],
+ sourceRoot: "http://example.com/www/js/",
+ mappings:
+ "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA",
};
const whatever = await SourceMapConsumer.with(rawSourceMap, null, consumer => {
-
console.log(consumer.sources);
// [ 'http://example.com/www/js/one.js',
// 'http://example.com/www/js/two.js' ]
- console.log(consumer.originalPositionFor({
- line: 2,
- column: 28
- }));
+ console.log(
+ consumer.originalPositionFor({
+ line: 2,
+ column: 28,
+ })
+ );
// { source: 'http://example.com/www/js/two.js',
// line: 2,
// column: 10,
// name: 'n' }
- console.log(consumer.generatedPositionFor({
- source: 'http://example.com/www/js/two.js',
- line: 2,
- column: 10
- }));
+ console.log(
+ consumer.generatedPositionFor({
+ source: "http://example.com/www/js/two.js",
+ line: 2,
+ column: 10,
+ })
+ );
// { line: 2, column: 28 }
consumer.eachMapping(function (m) {
@@ -126,30 +127,32 @@ In depth guide:
```js
function compile(ast) {
switch (ast.type) {
- case 'BinaryExpression':
- return new SourceNode(
- ast.location.line,
- ast.location.column,
- ast.location.source,
- [compile(ast.left), " + ", compile(ast.right)]
- );
- case 'Literal':
- return new SourceNode(
- ast.location.line,
- ast.location.column,
- ast.location.source,
- String(ast.value)
- );
- // ...
- default:
- throw new Error("Bad AST");
+ case "BinaryExpression":
+ return new SourceNode(
+ ast.location.line,
+ ast.location.column,
+ ast.location.source,
+ [compile(ast.left), " + ", compile(ast.right)]
+ );
+ case "Literal":
+ return new SourceNode(
+ ast.location.line,
+ ast.location.column,
+ ast.location.source,
+ String(ast.value)
+ );
+ // ...
+ default:
+ throw new Error("Bad AST");
}
}
var ast = parse("40 + 2", "add.js");
-console.log(compile(ast).toStringWithSourceMap({
- file: 'add.js'
-}));
+console.log(
+ compile(ast).toStringWithSourceMap({
+ file: "add.js",
+ })
+);
// { code: '40 + 2',
// map: [object SourceMapGenerator] }
```
@@ -158,20 +161,20 @@ console.log(compile(ast).toStringWithSourceMap({
```js
var map = new SourceMapGenerator({
- file: "source-mapped.js"
+ file: "source-mapped.js",
});
map.addMapping({
generated: {
line: 10,
- column: 35
+ column: 35,
},
source: "foo.js",
original: {
line: 33,
- column: 2
+ column: 2,
},
- name: "christopher"
+ name: "christopher",
});
console.log(map.toString());
@@ -184,7 +187,7 @@ Get a reference to the module:
```js
// Node.js
-var sourceMap = require('source-map');
+var sourceMap = require("source-map");
// Browser builds
var sourceMap = window.sourceMap;
@@ -207,12 +210,12 @@ calling `initialize` before constructing any `SourceMapConsumer`s.
The options object has the following properties:
-* `"lib/mappings.wasm"`: A `String` containing the URL of the
+- `"lib/mappings.wasm"`: A `String` containing the URL of the
`lib/mappings.wasm` file, or an `ArrayBuffer` with the contents of `lib/mappings.wasm`.
```js
sourceMap.SourceMapConsumer.initialize({
- "lib/mappings.wasm": "https://example.com/source-map/lib/mappings.wasm"
+ "lib/mappings.wasm": "https://example.com/source-map/lib/mappings.wasm",
});
```
@@ -222,20 +225,24 @@ The only parameter is the raw source map (either as a string which can be
`JSON.parse`'d, or an object). According to the spec, source maps have the
following attributes:
-* `version`: Which version of the source map spec this map is following.
+- `version`: Which version of the source map spec this map is following.
-* `sources`: An array of URLs to the original source files.
+- `sources`: An array of URLs to the original source files.
-* `names`: An array of identifiers which can be referenced by individual
+- `names`: An array of identifiers which can be referenced by individual
mappings.
-* `sourceRoot`: Optional. The URL root from which all sources are relative.
+- `sourceRoot`: Optional. The URL root from which all sources are relative.
+
+- `sourcesContent`: Optional. An array of contents of the original source files.
-* `sourcesContent`: Optional. An array of contents of the original source files.
+- `mappings`: A string of base64 VLQs which contain the actual mappings.
-* `mappings`: A string of base64 VLQs which contain the actual mappings.
+- `file`: Optional. The generated filename this source map is associated with.
-* `file`: Optional. The generated filename this source map is associated with.
+- `x_google_ignoreList`: Optional. An additional extension field which is an array
+ of indices refering to urls in the sources array. This is used to identify third-party
+ sources, that the developer might want to avoid when debugging. [Read more](https://developer.chrome.com/articles/x-google-ignore-list/)
The promise of the constructed souce map consumer is returned.
@@ -254,8 +261,7 @@ to call `destroy`.
#### SourceMapConsumer.with
Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl`
-(see the `SourceMapConsumer` constructor for details. Then, invoke the `async
-function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait
+(see the `SourceMapConsumer` constructor for details. Then, invoke the `async function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait
for `f` to complete, call `destroy` on the consumer, and return `f`'s return
value.
@@ -300,7 +306,7 @@ inclusive.
```js
// Before:
-consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" })
+consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" });
// [ { line: 2,
// column: 1 },
// { line: 2,
@@ -311,7 +317,7 @@ consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" })
consumer.computeColumnSpans();
// After:
-consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" })
+consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" });
// [ { line: 2,
// column: 1,
// lastColumn: 9 },
@@ -329,41 +335,44 @@ Returns the original source, line, and column information for the generated
source's line and column positions provided. The only argument is an object with
the following properties:
-* `line`: The line number in the generated source. Line numbers in
+- `line`: The line number in the generated source. Line numbers in
this library are 1-based (note that the underlying source map
specification uses 0-based line numbers -- this library handles the
translation).
-* `column`: The column number in the generated source. Column numbers
+- `column`: The column number in the generated source. Column numbers
in this library are 0-based.
-* `bias`: Either `SourceMapConsumer.GREATEST_LOWER_BOUND` or
+- `bias`: Either `SourceMapConsumer.GREATEST_LOWER_BOUND` or
`SourceMapConsumer.LEAST_UPPER_BOUND`. Specifies whether to return the closest
element that is smaller than or greater than the one we are searching for,
- respectively, if the exact element cannot be found. Defaults to
+ respectively, if the exact element cannot be found. Defaults to
`SourceMapConsumer.GREATEST_LOWER_BOUND`.
and an object is returned with the following properties:
-* `source`: The original source file, or null if this information is not
+- `source`: The original source file, or null if this information is not
available.
-* `line`: The line number in the original source, or null if this information is
- not available. The line number is 1-based.
+- `line`: The line number in the original source, or null if this information is
+ not available. The line number is 1-based.
-* `column`: The column number in the original source, or null if this
- information is not available. The column number is 0-based.
+- `column`: The column number in the original source, or null if this
+ information is not available. The column number is 0-based.
-* `name`: The original identifier, or null if this information is not available.
+- `name`: The original identifier, or null if this information is not available.
```js
-consumer.originalPositionFor({ line: 2, column: 10 })
+consumer.originalPositionFor({ line: 2, column: 10 });
// { source: 'foo.coffee',
// line: 2,
// column: 2,
// name: null }
-consumer.originalPositionFor({ line: 99999999999999999, column: 999999999999999 })
+consumer.originalPositionFor({
+ line: 99999999999999999,
+ column: 999999999999999,
+});
// { source: null,
// line: null,
// column: null,
@@ -376,24 +385,24 @@ Returns the generated line and column information for the original source,
line, and column positions provided. The only argument is an object with
the following properties:
-* `source`: The filename of the original source.
+- `source`: The filename of the original source.
-* `line`: The line number in the original source. The line number is
+- `line`: The line number in the original source. The line number is
1-based.
-* `column`: The column number in the original source. The column
+- `column`: The column number in the original source. The column
number is 0-based.
and an object is returned with the following properties:
-* `line`: The line number in the generated source, or null. The line
+- `line`: The line number in the generated source, or null. The line
number is 1-based.
-* `column`: The column number in the generated source, or null. The
+- `column`: The column number in the generated source, or null. The
column number is 0-based.
```js
-consumer.generatedPositionFor({ source: "example.js", line: 2, column: 10 })
+consumer.generatedPositionFor({ source: "example.js", line: 2, column: 10 });
// { line: 1,
// column: 56 }
```
@@ -409,24 +418,24 @@ that has any offsets.
The only argument is an object with the following properties:
-* `source`: The filename of the original source.
+- `source`: The filename of the original source.
-* `line`: The line number in the original source. The line number is
+- `line`: The line number in the original source. The line number is
1-based.
-* `column`: Optional. The column number in the original source. The
+- `column`: Optional. The column number in the original source. The
column number is 0-based.
and an array of objects is returned, each with the following properties:
-* `line`: The line number in the generated source, or null. The line
+- `line`: The line number in the generated source, or null. The line
number is 1-based.
-* `column`: The column number in the generated source, or null. The
+- `column`: The column number in the generated source, or null. The
column number is 0-based.
```js
-consumer.allGeneratedpositionsfor({ line: 2, source: "foo.coffee" })
+consumer.allGeneratedPositionsFor({ line: 2, source: "foo.coffee" });
// [ { line: 2,
// column: 1 },
// { line: 2,
@@ -464,10 +473,10 @@ thrown. Optionally, pass `true` as the second param to have `null` returned
instead.
```js
-consumer.sources
+consumer.sources;
// [ "my-cool-lib.clj" ]
-consumer.sourceContentFor("my-cool-lib.clj")
+consumer.sourceContentFor("my-cool-lib.clj");
// "..."
consumer.sourceContentFor("this is not in the source map");
@@ -482,21 +491,22 @@ consumer.sourceContentFor("this is not in the source map", true);
Iterate over each mapping between an original source/line/column and a
generated line/column in this source map.
-* `callback`: The function that is called with each mapping. Mappings have the
- form `{ source, generatedLine, generatedColumn, originalLine, originalColumn,
- name }`
+- `callback`: The function that is called with each mapping. Mappings have the
+ form `{ source, generatedLine, generatedColumn, originalLine, originalColumn, name }`
-* `context`: Optional. If specified, this object will be the value of `this`
+- `context`: Optional. If specified, this object will be the value of `this`
every time that `callback` is called.
-* `order`: Either `SourceMapConsumer.GENERATED_ORDER` or
+- `order`: Either `SourceMapConsumer.GENERATED_ORDER` or
`SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to iterate over
the mappings sorted by the generated file's line/column order or the
original's source/line/column order, respectively. Defaults to
`SourceMapConsumer.GENERATED_ORDER`.
```js
-consumer.eachMapping(function (m) { console.log(m); })
+consumer.eachMapping(function (m) {
+ console.log(m);
+});
// ...
// { source: 'illmatic.js',
// generatedLine: 1,
@@ -512,6 +522,7 @@ consumer.eachMapping(function (m) { console.log(m); })
// name: null }
// ...
```
+
### SourceMapGenerator
An instance of the SourceMapGenerator represents a source map which is being
@@ -521,12 +532,12 @@ built incrementally.
You may pass an object with the following properties:
-* `file`: The filename of the generated source that this source map is
+- `file`: The filename of the generated source that this source map is
associated with.
-* `sourceRoot`: A root for all relative URLs in this source map.
+- `sourceRoot`: A root for all relative URLs in this source map.
-* `skipValidation`: Optional. When `true`, disables validation of mappings as
+- `skipValidation`: Optional. When `true`, disables validation of mappings as
they are added. This can improve performance but should be used with
discretion, as a last resort. Even then, one should avoid using this flag when
running tests, if possible.
@@ -534,7 +545,7 @@ You may pass an object with the following properties:
```js
var generator = new sourceMap.SourceMapGenerator({
file: "my-generated-javascript-file.js",
- sourceRoot: "http://example.com/app/js/"
+ sourceRoot: "http://example.com/app/js/",
});
```
@@ -542,7 +553,7 @@ var generator = new sourceMap.SourceMapGenerator({
Creates a new `SourceMapGenerator` from an existing `SourceMapConsumer` instance.
-* `sourceMapConsumer` The SourceMap.
+- `sourceMapConsumer` The SourceMap.
```js
var generator = sourceMap.SourceMapGenerator.fromSourceMap(consumer);
@@ -554,33 +565,35 @@ Add a single mapping from original source line and column to the generated
source's line and column for this source map being created. The mapping object
should have the following properties:
-* `generated`: An object with the generated line and column positions.
+- `generated`: An object with the generated line and column positions.
-* `original`: An object with the original line and column positions.
+- `original`: An object with the original line and column positions.
-* `source`: The original source file (relative to the sourceRoot).
+- `source`: The original source file (relative to the sourceRoot).
-* `name`: An optional original token name for this mapping.
+- `name`: An optional original token name for this mapping.
```js
generator.addMapping({
source: "module-one.scm",
original: { line: 128, column: 0 },
- generated: { line: 3, column: 456 }
-})
+ generated: { line: 3, column: 456 },
+});
```
#### SourceMapGenerator.prototype.setSourceContent(sourceFile, sourceContent)
Set the source content for an original source file.
-* `sourceFile` the URL of the original source file.
+- `sourceFile` the URL of the original source file.
-* `sourceContent` the content of the source file.
+- `sourceContent` the content of the source file.
```js
-generator.setSourceContent("module-one.scm",
- fs.readFileSync("path/to/module-one.scm"))
+generator.setSourceContent(
+ "module-one.scm",
+ fs.readFileSync("path/to/module-one.scm")
+);
```
#### SourceMapGenerator.prototype.applySourceMap(sourceMapConsumer[, sourceFile[, sourceMapPath]])
@@ -590,13 +603,13 @@ Each mapping to the supplied source file is rewritten using the
supplied SourceMap. Note: The resolution for the resulting mappings
is the minimum of this map and the supplied map.
-* `sourceMapConsumer`: The SourceMap to be applied.
+- `sourceMapConsumer`: The SourceMap to be applied.
-* `sourceFile`: Optional. The filename of the source file.
+- `sourceFile`: Optional. The filename of the source file.
If omitted, sourceMapConsumer.file will be used, if it exists.
Otherwise an error will be thrown.
-* `sourceMapPath`: Optional. The dirname of the path to the SourceMap
+- `sourceMapPath`: Optional. The dirname of the path to the SourceMap
to be applied. If relative, it is relative to the SourceMap.
This parameter is needed when the two SourceMaps aren't in the same
@@ -612,7 +625,7 @@ is the minimum of this map and the supplied map.
Renders the source map being generated to a string.
```js
-generator.toString()
+generator.toString();
// '{"version":3,"sources":["module-one.scm"],"names":[],"mappings":"...snip...","file":"my-generated-javascript-file.js","sourceRoot":"http://example.com/app/js/"}'
```
@@ -626,19 +639,19 @@ use before outputting the generated JS and source map.
#### new SourceNode([line, column, source[, chunk[, name]]])
-* `line`: The original line number associated with this source node, or null if
- it isn't associated with an original line. The line number is 1-based.
+- `line`: The original line number associated with this source node, or null if
+ it isn't associated with an original line. The line number is 1-based.
-* `column`: The original column number associated with this source node, or null
- if it isn't associated with an original column. The column number
+- `column`: The original column number associated with this source node, or null
+ if it isn't associated with an original column. The column number
is 0-based.
-* `source`: The original source's filename; null if no filename is provided.
+- `source`: The original source's filename; null if no filename is provided.
-* `chunk`: Optional. Is immediately passed to `SourceNode.prototype.add`, see
+- `chunk`: Optional. Is immediately passed to `SourceNode.prototype.add`, see
below.
-* `name`: Optional. The original identifier.
+- `name`: Optional. The original identifier.
```js
var node = new SourceNode(1, 2, "a.cpp", [
@@ -652,24 +665,29 @@ var node = new SourceNode(1, 2, "a.cpp", [
Creates a SourceNode from generated code and a SourceMapConsumer.
-* `code`: The generated code
+- `code`: The generated code
-* `sourceMapConsumer` The SourceMap for the generated code
+- `sourceMapConsumer` The SourceMap for the generated code
-* `relativePath` The optional path that relative sources in `sourceMapConsumer`
+- `relativePath` The optional path that relative sources in `sourceMapConsumer`
should be relative to.
```js
-const consumer = await new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8"));
-const node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"), consumer);
+const consumer = await new SourceMapConsumer(
+ fs.readFileSync("path/to/my-file.js.map", "utf8")
+);
+const node = SourceNode.fromStringWithSourceMap(
+ fs.readFileSync("path/to/my-file.js"),
+ consumer
+);
```
#### SourceNode.prototype.add(chunk)
Add a chunk of generated JS to this source node.
-* `chunk`: A string snippet of generated JS code, another instance of
- `SourceNode`, or an array where each member is one of those things.
+- `chunk`: A string snippet of generated JS code, another instance of
+ `SourceNode`, or an array where each member is one of those things.
```js
node.add(" + ");
@@ -681,8 +699,8 @@ node.add([leftHandOperandNode, " + ", rightHandOperandNode]);
Prepend a chunk of generated JS to this source node.
-* `chunk`: A string snippet of generated JS code, another instance of
- `SourceNode`, or an array where each member is one of those things.
+- `chunk`: A string snippet of generated JS code, another instance of
+ `SourceNode`, or an array where each member is one of those things.
```js
node.prepend("/** Build Id: f783haef86324gf **/\n\n");
@@ -693,13 +711,15 @@ node.prepend("/** Build Id: f783haef86324gf **/\n\n");
Set the source content for a source file. This will be added to the
`SourceMap` in the `sourcesContent` field.
-* `sourceFile`: The filename of the source file
+- `sourceFile`: The filename of the source file
-* `sourceContent`: The content of the source file
+- `sourceContent`: The content of the source file
```js
-node.setSourceContent("module-one.scm",
- fs.readFileSync("path/to/module-one.scm"))
+node.setSourceContent(
+ "module-one.scm",
+ fs.readFileSync("path/to/module-one.scm")
+);
```
#### SourceNode.prototype.walk(fn)
@@ -708,19 +728,18 @@ Walk over the tree of JS snippets in this node and its children. The walking
function is called once for each snippet of JS and is passed that snippet and
the its original associated source's line/column location.
-* `fn`: The traversal function.
+- `fn`: The traversal function.
```js
var node = new SourceNode(1, 2, "a.js", [
new SourceNode(3, 4, "b.js", "uno"),
"dos",
- [
- "tres",
- new SourceNode(5, 6, "c.js", "quatro")
- ]
+ ["tres", new SourceNode(5, 6, "c.js", "quatro")],
]);
-node.walk(function (code, loc) { console.log("WALK:", code, loc); })
+node.walk(function (code, loc) {
+ console.log("WALK:", code, loc);
+});
// WALK: uno { source: 'b.js', line: 3, column: 4, name: null }
// WALK: dos { source: 'a.js', line: 1, column: 2, name: null }
// WALK: tres { source: 'a.js', line: 1, column: 2, name: null }
@@ -732,7 +751,7 @@ node.walk(function (code, loc) { console.log("WALK:", code, loc); })
Walk over the tree of SourceNodes. The walking function is called for each
source file content and is passed the filename and source content.
-* `fn`: The traversal function.
+- `fn`: The traversal function.
```js
var a = new SourceNode(1, 2, "a.js", "generated from a");
@@ -743,7 +762,9 @@ var c = new SourceNode(1, 2, "c.js", "generated from c");
c.setSourceContent("c.js", "original c");
var node = new SourceNode(null, null, null, [a, b, c]);
-node.walkSourceContents(function (source, contents) { console.log("WALK:", source, ":", contents); })
+node.walkSourceContents(function (source, contents) {
+ console.log("WALK:", source, ":", contents);
+});
// WALK: a.js : original a
// WALK: b.js : original b
// WALK: c.js : original c
@@ -754,14 +775,14 @@ node.walkSourceContents(function (source, contents) { console.log("WALK:", sourc
Like `Array.prototype.join` except for SourceNodes. Inserts the separator
between each of this source node's children.
-* `sep`: The separator.
+- `sep`: The separator.
```js
var lhs = new SourceNode(1, 2, "a.rs", "my_copy");
var operand = new SourceNode(3, 4, "a.rs", "=");
var rhs = new SourceNode(5, 6, "a.rs", "orig.clone()");
-var node = new SourceNode(null, null, null, [ lhs, operand, rhs ]);
+var node = new SourceNode(null, null, null, [lhs, operand, rhs]);
var joinedNode = node.join(" ");
```
@@ -770,9 +791,9 @@ var joinedNode = node.join(" ");
Call `String.prototype.replace` on the very right-most source snippet. Useful
for trimming white space from the end of a source node, etc.
-* `pattern`: The pattern to replace.
+- `pattern`: The pattern to replace.
-* `replacement`: The thing to replace the pattern with.
+- `replacement`: The thing to replace the pattern with.
```js
// Trim trailing white space.
@@ -788,13 +809,10 @@ concatenates all the various snippets together to one string.
var node = new SourceNode(1, 2, "a.js", [
new SourceNode(3, 4, "b.js", "uno"),
"dos",
- [
- "tres",
- new SourceNode(5, 6, "c.js", "quatro")
- ]
+ ["tres", new SourceNode(5, 6, "c.js", "quatro")],
]);
-node.toString()
+node.toString();
// 'unodostresquatro'
```
@@ -810,13 +828,10 @@ The arguments are the same as those to `new SourceMapGenerator`.
var node = new SourceNode(1, 2, "a.js", [
new SourceNode(3, 4, "b.js", "uno"),
"dos",
- [
- "tres",
- new SourceNode(5, 6, "c.js", "quatro")
- ]
+ ["tres", new SourceNode(5, 6, "c.js", "quatro")],
]);
-node.toStringWithSourceMap({ file: "my-output-file.js" })
+node.toStringWithSourceMap({ file: "my-output-file.js" });
// { code: 'unodostresquatro',
// map: [object SourceMapGenerator] }
```
diff --git a/bench/bench-dom-bindings.js b/bench/bench-dom-bindings.js
index b4650a42..fe321eb5 100644
--- a/bench/bench-dom-bindings.js
+++ b/bench/bench-dom-bindings.js
@@ -1,5 +1,5 @@
sourceMap.SourceMapConsumer.initialize({
- "lib/mappings.wasm": "../lib/mappings.wasm?bust_cache=" + String(Math.random()).replace(/0\./, ""),
+ "lib/mappings.wasm": "../lib/mappings.wasm?bust_cache=" + String(Math.random()).replace(/0\./, "")
});
function bindRange(labelId, updater) {
@@ -68,28 +68,28 @@ const updateImplAndBrowser = () => {
implAndBrowserInput.addEventListener("input", updateImplAndBrowser);
updateImplAndBrowser();
-
// Run a benchmark when the given button is clicked and display results in the
// given element.
function benchOnClick(button, results, benchName, bencher) {
- button.addEventListener("click", async function (e) {
- e.preventDefault();
+ button.addEventListener(
+ "click",
+ async function(e) {
+ e.preventDefault();
- const buttons = [...document.querySelectorAll("button")];
- buttons.forEach(b => b.setAttribute("disabled", true));
- results.innerHTML = "";
- await new Promise(r => requestAnimationFrame(r));
+ const buttons = [...document.querySelectorAll("button")];
+ buttons.forEach(b => b.setAttribute("disabled", true));
+ results.innerHTML = "";
+ await new Promise(r => requestAnimationFrame(r));
- var stats = await bencher();
+ var stats = await bencher();
- buttons.forEach(b => b.removeAttribute("disabled"));
+ buttons.forEach(b => b.removeAttribute("disabled"));
- const csv = stats
- .xs
- .map(x => `"${implAndBrowser}",${testSourceMap.mappings.length},"${benchName}",${x}`)
- .join("\n");
+ const csv = stats.xs
+ .map(x => `"${implAndBrowser}",${testSourceMap.mappings.length},"${benchName}",${x}`)
+ .join("\n");
- results.innerHTML = `
+ results.innerHTML = `
@@ -110,7 +110,9 @@ function benchOnClick(button, results, benchName, bencher) {
${csv}
`;
- }, false);
+ },
+ false
+ );
}
for (let bench of Object.keys(benchmarks)) {
diff --git a/bench/bench.html b/bench/bench.html
index 3bd14035..6445ab52 100644
--- a/bench/bench.html
+++ b/bench/bench.html
@@ -24,53 +24,53 @@
Benchmark mozilla/source-map
-
+