magic-string
Advanced tools
Comparing version 0.29.0 to 0.30.0
@@ -382,2 +382,3 @@ 'use strict'; | ||
indentStr: { writable: true, value: undefined }, | ||
ignoreList: { writable: true, value: options.ignoreList }, | ||
}); | ||
@@ -500,7 +501,8 @@ | ||
return { | ||
file: options.file ? options.file.split(/[/\\]/).pop() : null, | ||
sources: [options.source ? getRelativePath(options.file || '', options.source) : null], | ||
sourcesContent: options.includeContent ? [this.original] : [null], | ||
file: options.file ? options.file.split(/[/\\]/).pop() : undefined, | ||
sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')], | ||
sourcesContent: options.includeContent ? [this.original] : undefined, | ||
names, | ||
mappings: mappings.raw, | ||
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined | ||
}; | ||
@@ -1175,3 +1177,3 @@ } | ||
['filename', 'indentExclusionRanges', 'separator'].forEach((option) => { | ||
['filename', 'ignoreList', 'indentExclusionRanges', 'separator'].forEach((option) => { | ||
if (!hasOwnProp.call(source, option)) source[option] = source.content[option]; | ||
@@ -1229,2 +1231,3 @@ }); | ||
const names = []; | ||
let x_google_ignoreList = undefined; | ||
this.sources.forEach((source) => { | ||
@@ -1287,6 +1290,13 @@ Object.keys(source.content.storedNames).forEach((name) => { | ||
} | ||
if (source.ignoreList && sourceIndex !== -1) { | ||
if (x_google_ignoreList === undefined) { | ||
x_google_ignoreList = []; | ||
} | ||
x_google_ignoreList.push(sourceIndex); | ||
} | ||
}); | ||
return { | ||
file: options.file ? options.file.split(/[/\\]/).pop() : null, | ||
file: options.file ? options.file.split(/[/\\]/).pop() : undefined, | ||
sources: this.uniqueSources.map((source) => { | ||
@@ -1300,2 +1310,3 @@ return options.file ? getRelativePath(options.file, source.filename) : source.filename; | ||
mappings: mappings.raw, | ||
x_google_ignoreList, | ||
}; | ||
@@ -1302,0 +1313,0 @@ } |
@@ -472,2 +472,3 @@ (function (global, factory) { | ||
indentStr: { writable: true, value: undefined }, | ||
ignoreList: { writable: true, value: options.ignoreList }, | ||
}); | ||
@@ -590,7 +591,8 @@ | ||
return { | ||
file: options.file ? options.file.split(/[/\\]/).pop() : null, | ||
sources: [options.source ? getRelativePath(options.file || '', options.source) : null], | ||
sourcesContent: options.includeContent ? [this.original] : [null], | ||
file: options.file ? options.file.split(/[/\\]/).pop() : undefined, | ||
sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')], | ||
sourcesContent: options.includeContent ? [this.original] : undefined, | ||
names, | ||
mappings: mappings.raw, | ||
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined | ||
}; | ||
@@ -1265,3 +1267,3 @@ } | ||
['filename', 'indentExclusionRanges', 'separator'].forEach((option) => { | ||
['filename', 'ignoreList', 'indentExclusionRanges', 'separator'].forEach((option) => { | ||
if (!hasOwnProp.call(source, option)) source[option] = source.content[option]; | ||
@@ -1319,2 +1321,3 @@ }); | ||
const names = []; | ||
let x_google_ignoreList = undefined; | ||
this.sources.forEach((source) => { | ||
@@ -1377,6 +1380,13 @@ Object.keys(source.content.storedNames).forEach((name) => { | ||
} | ||
if (source.ignoreList && sourceIndex !== -1) { | ||
if (x_google_ignoreList === undefined) { | ||
x_google_ignoreList = []; | ||
} | ||
x_google_ignoreList.push(sourceIndex); | ||
} | ||
}); | ||
return { | ||
file: options.file ? options.file.split(/[/\\]/).pop() : null, | ||
file: options.file ? options.file.split(/[/\\]/).pop() : undefined, | ||
sources: this.uniqueSources.map((source) => { | ||
@@ -1390,2 +1400,3 @@ return options.file ? getRelativePath(options.file, source.filename) : source.filename; | ||
mappings: mappings.raw, | ||
x_google_ignoreList, | ||
}; | ||
@@ -1392,0 +1403,0 @@ } |
@@ -68,3 +68,13 @@ export interface BundleOptions { | ||
constructor(options?: BundleOptions); | ||
addSource(source: MagicString | { filename?: string, content: MagicString }): Bundle; | ||
/** | ||
* Adds the specified source to the bundle, which can either be a `MagicString` object directly, | ||
* or an options object that holds a magic string `content` property and optionally provides | ||
* a `filename` for the source within the bundle, as well as an optional `ignoreList` hint | ||
* (which defaults to `false`). The `filename` is used when constructing the source map for the | ||
* bundle, to identify this `source` in the source map's `sources` field. The `ignoreList` hint | ||
* is used to populate the `x_google_ignoreList` extension field in the source map, which is a | ||
* mechanism for tools to signal to debuggers that certain sources should be ignored by default | ||
* (depending on user preferences). | ||
*/ | ||
addSource(source: MagicString | { filename?: string, content: MagicString, ignoreList?: boolean }): Bundle; | ||
append(str: string, options?: BundleOptions): Bundle; | ||
@@ -121,3 +131,3 @@ clone(): Bundle; | ||
* Appends the specified content at the index in the original string. | ||
* If a range *ending* with index is subsequently moved, the insert will be moved with it. | ||
* If a range *ending* with index is subsequently moved, the insert will be moved with it. | ||
* See also `s.prependLeft(...)`. | ||
@@ -167,3 +177,3 @@ */ | ||
/** | ||
* Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in | ||
* Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in | ||
* that range. The same restrictions as `s.remove()` apply. | ||
@@ -174,3 +184,3 @@ * | ||
* the content is overwritten, or anything that was appended/prepended to the range as well. | ||
* | ||
* | ||
* It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content. | ||
@@ -188,3 +198,3 @@ */ | ||
/** | ||
* Prepends the string with the specified content. | ||
* Prepends the string with the specified content. | ||
*/ | ||
@@ -191,0 +201,0 @@ prepend(content: string): MagicString; |
{ | ||
"name": "magic-string", | ||
"version": "0.29.0", | ||
"version": "0.30.0", | ||
"description": "Modify strings, generate sourcemaps", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -69,6 +69,7 @@ # magic-string | ||
const s = new MagicString(someCode, { | ||
// both these options will be used if you later | ||
// call `bundle.addSource( s )` - see below | ||
// these options will be used if you later call `bundle.addSource( s )` - see below | ||
filename: 'foo.js', | ||
indentExclusionRanges: [/*...*/] | ||
indentExclusionRanges: [/*...*/], | ||
// market source as ignore in DevTools, see below #Bundling | ||
ignoreList: false | ||
}); | ||
@@ -255,2 +256,11 @@ ``` | ||
// Sources can be marked as ignore-listed, which provides a hint to debuggers | ||
// to not step into this code and also don't show the source files depending | ||
// on user preferences. | ||
bundle.addSource({ | ||
filename: 'some-3rdparty-library.js', | ||
content: new MagicString('function myLib(){}'), | ||
ignoreList: false // <-- | ||
}) | ||
// Advanced: a source can include an `indentExclusionRanges` property | ||
@@ -257,0 +267,0 @@ // alongside `filename` and `content`. This will be passed to `s.indent()` |
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
411167
3772
300