magic-string
Advanced tools
Comparing version 0.26.2 to 0.26.3
@@ -174,11 +174,16 @@ 'use strict'; | ||
let btoa = () => { | ||
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.'); | ||
}; | ||
if (typeof window !== 'undefined' && typeof window.btoa === 'function') { | ||
btoa = (str) => window.btoa(unescape(encodeURIComponent(str))); | ||
} else if (typeof Buffer === 'function') { | ||
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64'); | ||
function getBtoa () { | ||
if (typeof window !== 'undefined' && typeof window.btoa === 'function') { | ||
return (str) => window.btoa(unescape(encodeURIComponent(str))); | ||
} else if (typeof Buffer === 'function') { | ||
return (str) => Buffer.from(str, 'utf-8').toString('base64'); | ||
} else { | ||
return () => { | ||
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.'); | ||
}; | ||
} | ||
} | ||
const btoa = /*#__PURE__*/ getBtoa(); | ||
class SourceMap { | ||
@@ -375,3 +380,3 @@ constructor(properties) { | ||
storedNames: { writable: true, value: {} }, | ||
indentStr: { writable: true, value: guessIndent(string) }, | ||
indentStr: { writable: true, value: undefined }, | ||
}); | ||
@@ -506,3 +511,15 @@ | ||
_ensureindentStr() { | ||
if (this.indentStr === undefined) { | ||
this.indentStr = guessIndent(this.original); | ||
} | ||
} | ||
_getRawIndentString() { | ||
this._ensureindentStr(); | ||
return this.indentStr; | ||
} | ||
getIndentString() { | ||
this._ensureindentStr(); | ||
return this.indentStr === null ? '\t' : this.indentStr; | ||
@@ -519,3 +536,6 @@ } | ||
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t'; | ||
if (indentStr === undefined) { | ||
this._ensureindentStr(); | ||
indentStr = this.indentStr || '\t'; | ||
} | ||
@@ -1236,3 +1256,3 @@ if (indentStr === '') return this; // noop | ||
this.sources.forEach((source) => { | ||
const indentStr = source.content.indentStr; | ||
const indentStr = source.content._getRawIndentString(); | ||
@@ -1239,0 +1259,0 @@ if (indentStr === null) return; |
@@ -176,7 +176,3 @@ (function (global, factory) { | ||
var charToInteger = {}; | ||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
for (var i = 0; i < chars.length; i++) { | ||
charToInteger[chars.charCodeAt(i)] = i; | ||
} | ||
function encode(decoded) { | ||
@@ -233,11 +229,16 @@ var sourceFileIndex = 0; // second field | ||
let btoa = () => { | ||
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.'); | ||
}; | ||
if (typeof window !== 'undefined' && typeof window.btoa === 'function') { | ||
btoa = (str) => window.btoa(unescape(encodeURIComponent(str))); | ||
} else if (typeof Buffer === 'function') { | ||
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64'); | ||
function getBtoa () { | ||
if (typeof window !== 'undefined' && typeof window.btoa === 'function') { | ||
return (str) => window.btoa(unescape(encodeURIComponent(str))); | ||
} else if (typeof Buffer === 'function') { | ||
return (str) => Buffer.from(str, 'utf-8').toString('base64'); | ||
} else { | ||
return () => { | ||
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.'); | ||
}; | ||
} | ||
} | ||
const btoa = /*#__PURE__*/ getBtoa(); | ||
class SourceMap { | ||
@@ -434,3 +435,3 @@ constructor(properties) { | ||
storedNames: { writable: true, value: {} }, | ||
indentStr: { writable: true, value: guessIndent(string) }, | ||
indentStr: { writable: true, value: undefined }, | ||
}); | ||
@@ -565,3 +566,15 @@ | ||
_ensureindentStr() { | ||
if (this.indentStr === undefined) { | ||
this.indentStr = guessIndent(this.original); | ||
} | ||
} | ||
_getRawIndentString() { | ||
this._ensureindentStr(); | ||
return this.indentStr; | ||
} | ||
getIndentString() { | ||
this._ensureindentStr(); | ||
return this.indentStr === null ? '\t' : this.indentStr; | ||
@@ -578,3 +591,6 @@ } | ||
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t'; | ||
if (indentStr === undefined) { | ||
this._ensureindentStr(); | ||
indentStr = this.indentStr || '\t'; | ||
} | ||
@@ -1295,3 +1311,3 @@ if (indentStr === '') return this; // noop | ||
this.sources.forEach((source) => { | ||
const indentStr = source.content.indentStr; | ||
const indentStr = source.content._getRawIndentString(); | ||
@@ -1298,0 +1314,0 @@ if (indentStr === null) return; |
{ | ||
"name": "magic-string", | ||
"version": "0.26.2", | ||
"version": "0.26.3", | ||
"description": "Modify strings, generate sourcemaps", | ||
@@ -42,2 +42,3 @@ "keywords": [ | ||
"test": "mocha", | ||
"bench": "npm run build && node benchmark/index.mjs", | ||
"watch": "rollup -cw" | ||
@@ -49,11 +50,12 @@ }, | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"@rollup/plugin-replace": "^4.0.0", | ||
"bumpp": "^7.1.1", | ||
"benchmark": "^2.1.4", | ||
"bumpp": "^8.2.1", | ||
"conventional-changelog-cli": "^2.2.2", | ||
"eslint": "^8.10.0", | ||
"mocha": "^9.2.1", | ||
"prettier": "^2.5.1", | ||
"rollup": "^2.69.0", | ||
"source-map": "^0.6.1", | ||
"eslint": "^8.23.0", | ||
"mocha": "^10.0.0", | ||
"prettier": "^2.7.1", | ||
"rollup": "^2.78.1", | ||
"source-map-js": "^1.0.2", | ||
"source-map-support": "^0.5.21" | ||
@@ -60,0 +62,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
386332
3546
11