rollup-plugin-re
Advanced tools
Comparing version 1.0.6 to 1.0.7
/*! | ||
* rollup-plugin-re v1.0.6 | ||
* (c) 2017 jetiny 86287344@qq.com | ||
* rollup-plugin-re v1.0.7 | ||
* (c) 2018 jetiny 86287344@qq.com | ||
* Release under the MIT License. | ||
@@ -121,2 +121,12 @@ */ | ||
function verbose (opts, result, id) { | ||
if (opts.verbose) { | ||
if (isFunction(opts.verbose)) { | ||
opts.verbose(result, id); | ||
} else { | ||
console.log(("[" + result + "]"), id); | ||
} | ||
} | ||
} | ||
function replace (options) { | ||
@@ -131,3 +141,2 @@ if ( options === void 0 ) options = {}; | ||
parsePatterns(patterns, contents); | ||
return { | ||
@@ -137,5 +146,7 @@ name: 're', | ||
if (!filter(id)) { | ||
verbose(options, 'exclude', id); | ||
return | ||
} | ||
if (!contents.length) { | ||
verbose(options, 'ignore', id); | ||
return | ||
@@ -183,12 +194,32 @@ } | ||
end = start + match[0].length; | ||
var str = (void 0); | ||
if (pattern.replaceIsString) { | ||
magicString.overwrite(start, end, pattern.replace); | ||
} else if (pattern.replaceIsFunction) { | ||
var str = pattern.replace.apply(null, match); | ||
if (!isString(str)) { | ||
throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
magicString.overwrite(start, end, str); | ||
// fill capture groups | ||
str = pattern.replace.replace(/\$\$|\$&|\$`|\$'|\$\d+/g, function (m) { | ||
if (m === '$$') { | ||
return '$' | ||
} | ||
if (m === '$&') { | ||
return match[0] | ||
} | ||
if (m === '$`') { | ||
return code.slice(0, start) | ||
} | ||
if (m === "$'") { | ||
return code.slice(end) | ||
} | ||
var n = +m.slice(1); | ||
if (n >= 1 && n < match.length) { | ||
return match[n] || '' | ||
} | ||
return m | ||
}); | ||
} else { | ||
str = pattern.replace.apply(null, match); | ||
} | ||
match = pattern.test.exec(code); | ||
if (!isString(str)) { | ||
throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
magicString.overwrite(start, end, str); | ||
match = pattern.test.global ? pattern.test.exec(code) : null; | ||
} | ||
@@ -206,3 +237,3 @@ } else if (pattern.testIsString) { | ||
} else if (pattern.replaceIsFunction) { | ||
var str$1 = pattern.replace(); | ||
var str$1 = pattern.replace(id); | ||
if (!isString(str$1)) { | ||
@@ -221,2 +252,3 @@ throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
verbose(options, 'replace', id); | ||
var result = { code: magicString.toString() }; | ||
@@ -223,0 +255,0 @@ if (options.sourceMap !== false) { |
/*! | ||
* rollup-plugin-re v1.0.6 | ||
* (c) 2017 jetiny 86287344@qq.com | ||
* rollup-plugin-re v1.0.7 | ||
* (c) 2018 jetiny 86287344@qq.com | ||
* Release under the MIT License. | ||
@@ -117,2 +117,12 @@ */ | ||
function verbose (opts, result, id) { | ||
if (opts.verbose) { | ||
if (isFunction(opts.verbose)) { | ||
opts.verbose(result, id); | ||
} else { | ||
console.log(("[" + result + "]"), id); | ||
} | ||
} | ||
} | ||
function replace (options) { | ||
@@ -127,3 +137,2 @@ if ( options === void 0 ) options = {}; | ||
parsePatterns(patterns, contents); | ||
return { | ||
@@ -133,5 +142,7 @@ name: 're', | ||
if (!filter(id)) { | ||
verbose(options, 'exclude', id); | ||
return | ||
} | ||
if (!contents.length) { | ||
verbose(options, 'ignore', id); | ||
return | ||
@@ -179,12 +190,32 @@ } | ||
end = start + match[0].length; | ||
var str = (void 0); | ||
if (pattern.replaceIsString) { | ||
magicString.overwrite(start, end, pattern.replace); | ||
} else if (pattern.replaceIsFunction) { | ||
var str = pattern.replace.apply(null, match); | ||
if (!isString(str)) { | ||
throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
magicString.overwrite(start, end, str); | ||
// fill capture groups | ||
str = pattern.replace.replace(/\$\$|\$&|\$`|\$'|\$\d+/g, function (m) { | ||
if (m === '$$') { | ||
return '$' | ||
} | ||
if (m === '$&') { | ||
return match[0] | ||
} | ||
if (m === '$`') { | ||
return code.slice(0, start) | ||
} | ||
if (m === "$'") { | ||
return code.slice(end) | ||
} | ||
var n = +m.slice(1); | ||
if (n >= 1 && n < match.length) { | ||
return match[n] || '' | ||
} | ||
return m | ||
}); | ||
} else { | ||
str = pattern.replace.apply(null, match); | ||
} | ||
match = pattern.test.exec(code); | ||
if (!isString(str)) { | ||
throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
magicString.overwrite(start, end, str); | ||
match = pattern.test.global ? pattern.test.exec(code) : null; | ||
} | ||
@@ -202,3 +233,3 @@ } else if (pattern.testIsString) { | ||
} else if (pattern.replaceIsFunction) { | ||
var str$1 = pattern.replace(); | ||
var str$1 = pattern.replace(id); | ||
if (!isString(str$1)) { | ||
@@ -217,2 +248,3 @@ throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
verbose(options, 'replace', id); | ||
var result = { code: magicString.toString() }; | ||
@@ -219,0 +251,0 @@ if (options.sourceMap !== false) { |
{ | ||
"name": "rollup-plugin-re", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "rollup replace plugin", | ||
@@ -46,2 +46,2 @@ "main": "dist/rollup-plugin-re.cjs.js", | ||
} | ||
} | ||
} |
@@ -112,2 +112,12 @@ import { createFilter } from 'rollup-pluginutils' | ||
function verbose (opts, result, id) { | ||
if (opts.verbose) { | ||
if (isFunction(opts.verbose)) { | ||
opts.verbose(result, id) | ||
} else { | ||
console.log(`[${result}]`, id) | ||
} | ||
} | ||
} | ||
export default function replace (options = {}) { | ||
@@ -120,3 +130,2 @@ const filter = createFilter(options.include, options.exclude) | ||
parsePatterns(patterns, contents) | ||
return { | ||
@@ -126,5 +135,7 @@ name: 're', | ||
if (!filter(id)) { | ||
verbose(options, 'exclude', id) | ||
return | ||
} | ||
if (!contents.length) { | ||
verbose(options, 'ignore', id) | ||
return | ||
@@ -172,12 +183,32 @@ } | ||
end = start + match[0].length | ||
let str | ||
if (pattern.replaceIsString) { | ||
magicString.overwrite(start, end, pattern.replace) | ||
} else if (pattern.replaceIsFunction) { | ||
let str = pattern.replace.apply(null, match) | ||
if (!isString(str)) { | ||
throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
magicString.overwrite(start, end, str) | ||
// fill capture groups | ||
str = pattern.replace.replace(/\$\$|\$&|\$`|\$'|\$\d+/g, m => { | ||
if (m === '$$') { | ||
return '$' | ||
} | ||
if (m === '$&') { | ||
return match[0] | ||
} | ||
if (m === '$`') { | ||
return code.slice(0, start) | ||
} | ||
if (m === "$'") { | ||
return code.slice(end) | ||
} | ||
const n = +m.slice(1) | ||
if (n >= 1 && n < match.length) { | ||
return match[n] || '' | ||
} | ||
return m | ||
}) | ||
} else { | ||
str = pattern.replace.apply(null, match) | ||
} | ||
match = pattern.test.exec(code) | ||
if (!isString(str)) { | ||
throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
magicString.overwrite(start, end, str) | ||
match = pattern.test.global ? pattern.test.exec(code) : null | ||
} | ||
@@ -195,3 +226,3 @@ } else if (pattern.testIsString) { | ||
} else if (pattern.replaceIsFunction) { | ||
let str = pattern.replace() | ||
let str = pattern.replace(id) | ||
if (!isString(str)) { | ||
@@ -210,2 +241,3 @@ throw new Error('[rollup-plugin-re] replace function should return a string') | ||
} | ||
verbose(options, 'replace', id) | ||
let result = { code: magicString.toString() } | ||
@@ -212,0 +244,0 @@ if (options.sourceMap !== false) { |
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
28152
789