rollup-plugin-preserve-directives
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -21,7 +21,11 @@ "use strict"; | ||
const ast = this.parse(code); | ||
if (ast.type === "Program") { | ||
if (ast.type === "Program" && ast.body) { | ||
const directives = []; | ||
let i = 0; | ||
while (((_a = ast.body) === null || _a === void 0 ? void 0 : _a[i].type) === "ExpressionStatement") { | ||
const node = ast.body[i]; | ||
// Nodes in body should never be falsy, but issue #5 tells us otherwise | ||
// so just in case we filter them out here | ||
const filteredBody = ast.body.filter(Boolean); | ||
// .type must be defined according to the spec, but just in case.. | ||
while (((_a = filteredBody[i]) === null || _a === void 0 ? void 0 : _a.type) === "ExpressionStatement") { | ||
const node = filteredBody[i]; | ||
if (node.directive) { | ||
@@ -28,0 +32,0 @@ directives.push(node.directive); |
{ | ||
"name": "rollup-plugin-preserve-directives", | ||
"description": "A Rollup plugin to preserve directives like \"use client\" when preserveModules is true.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "Fredrik Höglund <fredrik.hoglund@gmail.com>", | ||
@@ -28,4 +28,6 @@ "license": "MIT", | ||
}, | ||
"dependencies": { | ||
"magic-string": "^0.30.0" | ||
}, | ||
"devDependencies": { | ||
"magic-string": "^0.30.0", | ||
"rollup": "^3.19.1", | ||
@@ -32,0 +34,0 @@ "typescript": "^4.9.5" |
@@ -32,3 +32,3 @@ # rollup-plugin-preserve-directives | ||
If you are using a minifier like terser, make sure that is not removing this comment. In terser, you can set [`compress.directives`](https://terser.org/docs/api-reference#compress-options) to `false`. | ||
If you are using a minifier like terser, make sure that is not removing the directive again. In terser, you can set [`compress.directives`](https://terser.org/docs/api-reference#compress-options) to `false`. | ||
@@ -35,0 +35,0 @@ ## Disabling warnings |
10575
2
101
2
+ Addedmagic-string@^0.30.0
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Addedmagic-string@0.30.17(transitive)