rollup-preserve-directives
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -27,2 +27,4 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
const magicString = new MagicString__default.default(code); | ||
// MagicString's `hasChanged()` is slow, so we track the change manually | ||
let hasChanged = false; | ||
/** | ||
@@ -51,2 +53,3 @@ * Here we are making 3 assumptions: | ||
magicString.remove(0, firstNewLineIndex + 1); | ||
hasChanged = true; | ||
} | ||
@@ -58,2 +61,3 @@ } | ||
try { | ||
// rollup 2 built-in parser doesn't have `allowShebang`, we need to use the sliced code here. Hence the `magicString.toString()` | ||
ast = this.parse(magicString.toString(), { | ||
@@ -101,10 +105,15 @@ allowReturnOutsideFunction: true, | ||
magicString.remove(node.start, node.end); | ||
hasChanged = true; | ||
} | ||
} | ||
} | ||
if (!hasChanged) { | ||
// If nothing has changed, we can avoid the expensive `toString()` and `generateMap()` calls | ||
return null; | ||
} | ||
return { | ||
code: magicString ? magicString.toString() : code, | ||
map: magicString ? magicString.generateMap({ | ||
code: magicString.toString(), | ||
map: magicString.generateMap({ | ||
hires: true | ||
}) : null, | ||
}), | ||
meta: { | ||
@@ -144,5 +153,9 @@ preserveDirectives: { | ||
} | ||
// Neither outputDirectives nor meta.shebang is present, no change is needed | ||
if (!magicString) { | ||
return null; | ||
} | ||
return { | ||
code: magicString ? magicString.toString() : code, | ||
map: sourcemap && magicString ? magicString.generateMap({ | ||
code: magicString.toString(), | ||
map: sourcemap ? magicString.generateMap({ | ||
hires: true | ||
@@ -149,0 +162,0 @@ }) : null |
{ | ||
"name": "rollup-preserve-directives", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Rollup plugin to preserve directives", | ||
@@ -17,8 +17,2 @@ "types": "./dist/index.d.ts", | ||
], | ||
"scripts": { | ||
"build": "bunchee", | ||
"prepublishOnly": "rm -rf dist && pnpm run build", | ||
"test": "jest --env node", | ||
"test:update": "jest --env node --updateSnapshot" | ||
}, | ||
"keywords": [ | ||
@@ -55,3 +49,8 @@ "rollup", | ||
}, | ||
"packageManager": "pnpm@7.24.3" | ||
} | ||
"packageManager": "pnpm@7.24.3", | ||
"scripts": { | ||
"build": "bunchee", | ||
"test": "jest --env node", | ||
"test:update": "jest --env node --updateSnapshot" | ||
} | ||
} |
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
18399
336