From be949264e6524d5248165f2d06af15c662bc7518 Mon Sep 17 00:00:00 2001 From: Valentin Semirulnik Date: Sun, 14 Feb 2021 03:32:57 +0300 Subject: [PATCH 1/5] replace source-map with source-map-sync --- lib/ConcatSource.js | 2 +- lib/OriginalSource.js | 2 +- lib/PrefixSource.js | 2 +- lib/RawSource.js | 2 +- lib/ReplaceSource.js | 2 +- lib/SourceMapSource.js | 2 +- lib/applySourceMap.js | 4 ++-- lib/helpers.js | 2 +- package.json | 2 +- test/SourceMapSource.js | 2 +- yarn.lock | 28 ++++++++++++++++++++++++++++ 11 files changed, 39 insertions(+), 11 deletions(-) diff --git a/lib/ConcatSource.js b/lib/ConcatSource.js index 2e9a4d6..f59b0da 100644 --- a/lib/ConcatSource.js +++ b/lib/ConcatSource.js @@ -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"); diff --git a/lib/OriginalSource.js b/lib/OriginalSource.js index 921a210..260221c 100644 --- a/lib/OriginalSource.js +++ b/lib/OriginalSource.js @@ -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"); diff --git a/lib/PrefixSource.js b/lib/PrefixSource.js index d7872dd..668ae45 100644 --- a/lib/PrefixSource.js +++ b/lib/PrefixSource.js @@ -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; diff --git a/lib/RawSource.js b/lib/RawSource.js index 1c0a47e..a880aad 100644 --- a/lib/RawSource.js +++ b/lib/RawSource.js @@ -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 { diff --git a/lib/ReplaceSource.js b/lib/ReplaceSource.js index 5e8b09e..627dbf1 100644 --- a/lib/ReplaceSource.js +++ b/lib/ReplaceSource.js @@ -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 { diff --git a/lib/SourceMapSource.js b/lib/SourceMapSource.js index 8508ff8..60140cf 100644 --- a/lib/SourceMapSource.js +++ b/lib/SourceMapSource.js @@ -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"); diff --git a/lib/applySourceMap.js b/lib/applySourceMap.js index ab65bac..5a697f4 100644 --- a/lib/applySourceMap.js +++ b/lib/applySourceMap.js @@ -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, diff --git a/lib/helpers.js b/lib/helpers.js index b3084e2..d44be40 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -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) => { diff --git a/package.json b/package.json index 2cff7f2..e3c5b77 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "source-list-map": "^2.0.1", - "source-map": "^0.6.1" + "source-map-sync": "^0.0.0" }, "devDependencies": { "coveralls": "^3.0.2", diff --git a/test/SourceMapSource.js b/test/SourceMapSource.js index f406d47..1bca3fe 100644 --- a/test/SourceMapSource.js +++ b/test/SourceMapSource.js @@ -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", () => { diff --git a/yarn.lock b/yarn.lock index 794aa6d..b12e07d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3582,6 +3582,13 @@ source-map-support@^0.5.6: buffer-from "^1.0.0" source-map "^0.6.0" +source-map-sync@^0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/source-map-sync/-/source-map-sync-0.0.0.tgz#99424c1ce94a6656c5f2a5adde93a3bf93bf7609" + integrity sha512-brORCqrTKaSTOEBMiR+5m1p8LpIi3fJLBFFgIPZS1wmnEPQM5D3YR7M6aO8bBOzxiI5nxe5iXtypSEZBlSMDMw== + 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" @@ -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" @@ -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" @@ -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" From 77be86dce513fac7dc24c809244fad2485d19979 Mon Sep 17 00:00:00 2001 From: Valentin Semirulnik Date: Mon, 15 Feb 2021 01:48:55 +0300 Subject: [PATCH 2/5] bump source-map-sync to 0.8.0-beta.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e3c5b77..8acf0ac 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "source-list-map": "^2.0.1", - "source-map-sync": "^0.0.0" + "source-map-sync": "^0.8.0-beta.0" }, "devDependencies": { "coveralls": "^3.0.2", diff --git a/yarn.lock b/yarn.lock index b12e07d..211e2cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3582,10 +3582,10 @@ source-map-support@^0.5.6: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-sync@^0.0.0: - version "0.0.0" - resolved "https://registry.yarnpkg.com/source-map-sync/-/source-map-sync-0.0.0.tgz#99424c1ce94a6656c5f2a5adde93a3bf93bf7609" - integrity sha512-brORCqrTKaSTOEBMiR+5m1p8LpIi3fJLBFFgIPZS1wmnEPQM5D3YR7M6aO8bBOzxiI5nxe5iXtypSEZBlSMDMw== +source-map-sync@^0.8.0-beta.0: + version "0.8.0-beta.0" + resolved "https://registry.yarnpkg.com/source-map-sync/-/source-map-sync-0.8.0-beta.0.tgz#4943350f7ac91c58489cc19b17231e364cdff5b0" + integrity sha512-NaP8fP2gfxxXgANPk9ZjEI0oDipd97g6eSHkzGu38jP0F5iGNadB+lmSHe5pPjvMmC9PcJdNNIZEfA+50VeqWg== dependencies: whatwg-url "^7.0.0" From 55ecb8022f691df533e25dab0734d2217529e5c3 Mon Sep 17 00:00:00 2001 From: Valentin Semirulnik Date: Mon, 15 Feb 2021 01:49:10 +0300 Subject: [PATCH 3/5] destroy consumer after use --- lib/ConcatSource.js | 7 +++++-- lib/SourceMapSource.js | 8 ++++++-- lib/applySourceMap.js | 1 + lib/helpers.js | 7 +++++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/ConcatSource.js b/lib/ConcatSource.js index f59b0da..f8047cd 100644 --- a/lib/ConcatSource.js +++ b/lib/ConcatSource.js @@ -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; } diff --git a/lib/SourceMapSource.js b/lib/SourceMapSource.js index 60140cf..1088d55 100644 --- a/lib/SourceMapSource.js +++ b/lib/SourceMapSource.js @@ -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; } diff --git a/lib/applySourceMap.js b/lib/applySourceMap.js index 5a697f4..8353999 100644 --- a/lib/applySourceMap.js +++ b/lib/applySourceMap.js @@ -201,6 +201,7 @@ const applySourceMap = function ( // Put output into the resulting SourceNode l2rResult.add(l2rOutput); + sourceMapConsumer.destroy(); return l2rResult; }; diff --git a/lib/helpers.js b/lib/helpers.js index d44be40..3741ff7 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -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); } From 5110ac241f5834f23171d232377aa41634730a3b Mon Sep 17 00:00:00 2001 From: Valentin Semirulnik Date: Mon, 15 Feb 2021 02:26:47 +0300 Subject: [PATCH 4/5] use 0.8.0-beta.1 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8acf0ac..c98b90e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "source-list-map": "^2.0.1", - "source-map-sync": "^0.8.0-beta.0" + "source-map-sync": "^0.8.0-beta.1" }, "devDependencies": { "coveralls": "^3.0.2", diff --git a/yarn.lock b/yarn.lock index 211e2cb..f3dc9d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3582,10 +3582,10 @@ source-map-support@^0.5.6: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-sync@^0.8.0-beta.0: - version "0.8.0-beta.0" - resolved "https://registry.yarnpkg.com/source-map-sync/-/source-map-sync-0.8.0-beta.0.tgz#4943350f7ac91c58489cc19b17231e364cdff5b0" - integrity sha512-NaP8fP2gfxxXgANPk9ZjEI0oDipd97g6eSHkzGu38jP0F5iGNadB+lmSHe5pPjvMmC9PcJdNNIZEfA+50VeqWg== +source-map-sync@^0.8.0-beta.1: + version "0.8.0-beta.1" + resolved "https://registry.yarnpkg.com/source-map-sync/-/source-map-sync-0.8.0-beta.1.tgz#5ac363771ad04e135a5df8b6969f0a7c2450b545" + integrity sha512-MAII5Kn5JAEnvBvV2s6e3+muLjf9VjDN87Rq0Ihlm1/e9Ba8GWNXrohTCuqMEFOBNw2HsDKFDzc5lvx56nIk6w== dependencies: whatwg-url "^7.0.0" From 19a268166644deb34c1517c13d7ce52dc34eeb77 Mon Sep 17 00:00:00 2001 From: Valentin Semirulnik Date: Tue, 16 Feb 2021 02:11:31 +0300 Subject: [PATCH 5/5] source-map-sync@0.8.0-beta.2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c98b90e..ffb2d8b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "source-list-map": "^2.0.1", - "source-map-sync": "^0.8.0-beta.1" + "source-map-sync": "0.8.0-beta.2" }, "devDependencies": { "coveralls": "^3.0.2", diff --git a/yarn.lock b/yarn.lock index f3dc9d3..6e30ee3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3582,10 +3582,10 @@ source-map-support@^0.5.6: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-sync@^0.8.0-beta.1: - version "0.8.0-beta.1" - resolved "https://registry.yarnpkg.com/source-map-sync/-/source-map-sync-0.8.0-beta.1.tgz#5ac363771ad04e135a5df8b6969f0a7c2450b545" - integrity sha512-MAII5Kn5JAEnvBvV2s6e3+muLjf9VjDN87Rq0Ihlm1/e9Ba8GWNXrohTCuqMEFOBNw2HsDKFDzc5lvx56nIk6w== +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"