@rollup/plugin-esm-shim
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -26,19 +26,21 @@ 'use strict'; | ||
} | ||
let idx = 0; | ||
for (let i = 0; i < result.length; i++) { | ||
output.push(result[i].match(new RegExp(pattern)) || []); | ||
const match = [result[i]]; | ||
match.index = idx; | ||
idx += result[i].length; | ||
output.push(match); | ||
} | ||
return output; | ||
} | ||
function matchAll(regex, input, addition) { | ||
const matches = []; | ||
for (const match of matchAllPolyfill(input, regex)) { | ||
matches.push({ | ||
...addition, | ||
...match.groups, | ||
code: match[0], | ||
start: match.index, | ||
end: (match.index || 0) + match[0].length | ||
}); | ||
function findPositionToInsertShim(input, pattern) { | ||
let lastImport; | ||
// mimicking behavior of `String.matchAll` as it returns an iterator, not an array | ||
for (const match of matchAllPolyfill(input, pattern)) { | ||
lastImport = match; | ||
} | ||
return matches; | ||
if (!lastImport) { | ||
return 0; | ||
} | ||
return (lastImport.index || 0) + lastImport[0].length; | ||
} | ||
@@ -49,4 +51,3 @@ function provideCJSSyntax(code) { | ||
} | ||
const lastESMImport = matchAll(ESMStaticImportRegex, code, { type: 'static' }).pop(); | ||
const indexToAppend = lastESMImport ? lastESMImport.end : 0; | ||
const indexToAppend = findPositionToInsertShim(code, ESMStaticImportRegex); | ||
const s = new MagicString(code); | ||
@@ -95,5 +96,4 @@ s.appendRight(indexToAppend, ESMShim); | ||
exports.default = esmShim; | ||
exports.matchAll = matchAll; | ||
exports.provideCJSSyntax = provideCJSSyntax; | ||
module.exports = Object.assign(exports.default, exports); | ||
//# sourceMappingURL=index.js.map |
@@ -22,19 +22,21 @@ import MagicString from 'magic-string'; | ||
} | ||
let idx = 0; | ||
for (let i = 0; i < result.length; i++) { | ||
output.push(result[i].match(new RegExp(pattern)) || []); | ||
const match = [result[i]]; | ||
match.index = idx; | ||
idx += result[i].length; | ||
output.push(match); | ||
} | ||
return output; | ||
} | ||
function matchAll(regex, input, addition) { | ||
const matches = []; | ||
for (const match of matchAllPolyfill(input, regex)) { | ||
matches.push({ | ||
...addition, | ||
...match.groups, | ||
code: match[0], | ||
start: match.index, | ||
end: (match.index || 0) + match[0].length | ||
}); | ||
function findPositionToInsertShim(input, pattern) { | ||
let lastImport; | ||
// mimicking behavior of `String.matchAll` as it returns an iterator, not an array | ||
for (const match of matchAllPolyfill(input, pattern)) { | ||
lastImport = match; | ||
} | ||
return matches; | ||
if (!lastImport) { | ||
return 0; | ||
} | ||
return (lastImport.index || 0) + lastImport[0].length; | ||
} | ||
@@ -45,4 +47,3 @@ function provideCJSSyntax(code) { | ||
} | ||
const lastESMImport = matchAll(ESMStaticImportRegex, code, { type: 'static' }).pop(); | ||
const indexToAppend = lastESMImport ? lastESMImport.end : 0; | ||
const indexToAppend = findPositionToInsertShim(code, ESMStaticImportRegex); | ||
const s = new MagicString(code); | ||
@@ -90,3 +91,3 @@ s.appendRight(indexToAppend, ESMShim); | ||
export { esmShim as default, matchAll, provideCJSSyntax }; | ||
export { esmShim as default, provideCJSSyntax }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@rollup/plugin-esm-shim", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -16,4 +16,8 @@ import MagicString from 'magic-string'; | ||
let idx = 0; | ||
for (let i = 0; i < result.length; i++) { | ||
output.push(result[i].match(new RegExp(pattern)) || []); | ||
const match: RegExpMatchArray = [result[i]]; | ||
match.index = idx; | ||
idx += result[i].length; | ||
output.push(match); | ||
} | ||
@@ -23,14 +27,13 @@ return output; | ||
export function matchAll(regex: RegExp, input: string, addition: Record<string, any>) { | ||
const matches = []; | ||
for (const match of matchAllPolyfill(input, regex)) { | ||
matches.push({ | ||
...addition, | ||
...match.groups, | ||
code: match[0], | ||
start: match.index, | ||
end: (match.index || 0) + match[0].length | ||
}); | ||
function findPositionToInsertShim(input: string, pattern: RegExp) { | ||
let lastImport; | ||
// mimicking behavior of `String.matchAll` as it returns an iterator, not an array | ||
for (const match of matchAllPolyfill(input, pattern)) { | ||
lastImport = match; | ||
} | ||
return matches; | ||
if (!lastImport) { | ||
return 0; | ||
} | ||
return (lastImport.index || 0) + lastImport[0].length; | ||
} | ||
@@ -43,4 +46,3 @@ | ||
const lastESMImport = matchAll(ESMStaticImportRegex, code, { type: 'static' }).pop(); | ||
const indexToAppend = lastESMImport ? lastESMImport.end : 0; | ||
const indexToAppend = findPositionToInsertShim(code, ESMStaticImportRegex); | ||
const s = new MagicString(code); | ||
@@ -47,0 +49,0 @@ s.appendRight(indexToAppend, ESMShim); |
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
279
12519