Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace source-map with source-map-sync #102

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/ConcatSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const Source = require("./Source");
const RawSource = require("./RawSource");
const { SourceNode, SourceMapConsumer } = require("source-map");
const { SourceNode, SourceMapConsumer } = require("source-map-sync");
const { SourceListMap, fromStringWithSourceMap } = require("source-list-map");
const { getSourceAndMap, getMap } = require("./helpers");

Expand Down Expand Up @@ -105,10 +105,13 @@ class ConcatSource extends Source {
if (typeof item.node === "function") return item.node(options);
const sourceAndMap = item.sourceAndMap(options);
if (sourceAndMap.map) {
return SourceNode.fromStringWithSourceMap(
const consumer = new SourceMapConsumer(sourceAndMap.map);
const node = SourceNode.fromStringWithSourceMap(
sourceAndMap.source,
new SourceMapConsumer(sourceAndMap.map)
consumer
);
consumer.destroy();
return node;
} else {
return sourceAndMap.source;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/OriginalSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict";

const Source = require("./Source");
const { SourceNode } = require("source-map");
const { SourceNode } = require("source-map-sync");
const { SourceListMap } = require("source-list-map");
const { getSourceAndMap, getMap } = require("./helpers");

Expand Down
2 changes: 1 addition & 1 deletion lib/PrefixSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const Source = require("./Source");
const RawSource = require("./RawSource");
const { SourceNode } = require("source-map");
const { SourceNode } = require("source-map-sync");
const { getSourceAndMap, getMap } = require("./helpers");

const REPLACE_REGEX = /\n(?=.|\s)/g;
Expand Down
2 changes: 1 addition & 1 deletion lib/RawSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict";

const Source = require("./Source");
const { SourceNode } = require("source-map");
const { SourceNode } = require("source-map-sync");
const { SourceListMap } = require("source-list-map");

class RawSource extends Source {
Expand Down
2 changes: 1 addition & 1 deletion lib/ReplaceSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict";

const Source = require("./Source");
const { SourceNode } = require("source-map");
const { SourceNode } = require("source-map-sync");
const { getSourceAndMap, getMap, getNode, getListMap } = require("./helpers");

class Replacement {
Expand Down
10 changes: 7 additions & 3 deletions lib/SourceMapSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict";

const Source = require("./Source");
const { SourceNode, SourceMapConsumer } = require("source-map");
const { SourceNode, SourceMapConsumer } = require("source-map-sync");
const { SourceListMap, fromStringWithSourceMap } = require("source-list-map");
const { getSourceAndMap, getMap } = require("./helpers");
const applySourceMap = require("./applySourceMap");
Expand Down Expand Up @@ -188,19 +188,23 @@ class SourceMapSource extends Source {
this._ensureValueString();
this._ensureSourceMapObject();
this._ensureOriginalSourceString();
const consumer = new SourceMapConsumer(this._sourceMapAsObject);
let node = SourceNode.fromStringWithSourceMap(
this._valueAsString,
new SourceMapConsumer(this._sourceMapAsObject)
consumer
);
consumer.destroy();
node.setSourceContent(this._name, this._originalSourceAsString);
if (this._hasInnerSourceMap) {
this._ensureInnerSourceMapObject();
const consumer = new SourceMapConsumer(this._innerSourceMapAsObject);
node = applySourceMap(
node,
new SourceMapConsumer(this._innerSourceMapAsObject),
consumer,
this._name,
this._removeOriginalSource
);
consumer.destroy();
}
return node;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/applySourceMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

"use strict";

const SourceNode = require("source-map").SourceNode;
const SourceMapConsumer = require("source-map").SourceMapConsumer;
const SourceNode = require("source-map-sync").SourceNode;
const SourceMapConsumer = require("source-map-sync").SourceMapConsumer;

const applySourceMap = function (
sourceNode,
Expand Down Expand Up @@ -201,6 +201,7 @@ const applySourceMap = function (

// Put output into the resulting SourceNode
l2rResult.add(l2rOutput);
sourceMapConsumer.destroy();
return l2rResult;
};

Expand Down
9 changes: 6 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
"use strict";

const { SourceNode, SourceMapConsumer } = require("source-map");
const { SourceNode, SourceMapConsumer } = require("source-map-sync");
const { SourceListMap, fromStringWithSourceMap } = require("source-list-map");

exports.getSourceAndMap = (inputSource, options) => {
Expand Down Expand Up @@ -55,10 +55,13 @@ exports.getNode = (source, options) => {
} else {
const sourceAndMap = source.sourceAndMap(options);
if (sourceAndMap.map) {
return SourceNode.fromStringWithSourceMap(
const consumer = new SourceMapConsumer(sourceAndMap.map);
const node = SourceNode.fromStringWithSourceMap(
sourceAndMap.source,
new SourceMapConsumer(sourceAndMap.map)
consumer
);
consumer.destroy();
return node;
} else {
return new SourceNode(null, null, null, sourceAndMap.source);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"source-list-map": "^2.0.1",
"source-map": "^0.6.1"
"source-map-sync": "0.8.0-beta.2"
},
"devDependencies": {
"coveralls": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion test/SourceMapSource.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const SourceMapSource = require("../").SourceMapSource;
const OriginalSource = require("../").OriginalSource;
const ConcatSource = require("../").ConcatSource;
const SourceNode = require("source-map").SourceNode;
const SourceNode = require("source-map-sync").SourceNode;

describe("SourceMapSource", () => {
it("map correctly", () => {
Expand Down
28 changes: 28 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3582,6 +3582,13 @@ source-map-support@^0.5.6:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-sync@0.8.0-beta.2:
version "0.8.0-beta.2"
resolved "https://registry.yarnpkg.com/source-map-sync/-/source-map-sync-0.8.0-beta.2.tgz#a183568e147738bd249b5a11f402a25c7fa3e9f9"
integrity sha512-Q4ejvN6wENaQdYVcq4lMm/vHN9TiSoc/6hQbUhP2DogZ0kYIEYaQlYLbgJ8hEF0eFpQDeEkQAsMiARscl1Ur/Q==
dependencies:
whatwg-url "^7.0.0"

source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
Expand Down Expand Up @@ -3889,6 +3896,13 @@ tough-cookie@^3.0.1:
psl "^1.1.28"
punycode "^2.1.1"

tr46@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09"
integrity sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=
dependencies:
punycode "^2.1.0"

tr46@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.0.2.tgz#03273586def1595ae08fedb38d7733cee91d2479"
Expand Down Expand Up @@ -4063,6 +4077,11 @@ walker@^1.0.7, walker@~1.0.5:
dependencies:
makeerror "1.0.x"

webidl-conversions@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==

webidl-conversions@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff"
Expand All @@ -4085,6 +4104,15 @@ whatwg-mimetype@^2.3.0:
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==

whatwg-url@^7.0.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.1.0.tgz#c2c492f1eca612988efd3d2266be1b9fc6170d06"
integrity sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==
dependencies:
lodash.sortby "^4.7.0"
tr46 "^1.0.1"
webidl-conversions "^4.0.2"

whatwg-url@^8.0.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.1.0.tgz#c628acdcf45b82274ce7281ee31dd3c839791771"
Expand Down