@linaria/shaker
Advanced tools
Comparing version 4.2.3 to 4.2.4
@@ -182,3 +182,21 @@ import { join } from 'path'; | ||
}); | ||
it('should delete import', () => { | ||
const { | ||
code, | ||
metadata | ||
} = keep(['Alive'])` | ||
import { A, B } from "ABC"; | ||
const AB = { | ||
A, | ||
B, | ||
}; | ||
export const Alive = ""; | ||
export default AB; | ||
`; | ||
expect(code).toMatchSnapshot(); | ||
expect(metadata.imports.size).toBe(0); | ||
}); | ||
}); | ||
//# sourceMappingURL=shaker-plugin.test.js.map |
import { createCustomDebug } from '@linaria/logger'; | ||
import { collectExportsAndImports, getFileIdx, isRemoved, removeWithRelated, sideEffectImport, reference, findParentForDelete, dereference } from '@linaria/utils'; | ||
import { collectExportsAndImports, getFileIdx, isRemoved, removeWithRelated, sideEffectImport, reference, findActionForNode, dereference, mutate } from '@linaria/utils'; | ||
export const hasShakerMetadata = metadata => metadata !== undefined && '__linariaShaker' in metadata; | ||
@@ -171,3 +171,4 @@ | ||
const binding = getBindingForExport(path); | ||
const parent = findParentForDelete(path); | ||
const action = findActionForNode(path); | ||
const parent = action?.[1]; | ||
const outerReferences = (binding?.referencePaths || []).filter(ref => ref !== parent && !parent?.isAncestor(ref)); | ||
@@ -182,3 +183,16 @@ | ||
if (!deleted.has(path) && (!binding || outerReferences.length === 0)) { | ||
removeWithRelated([parent ?? path]); | ||
if (action) { | ||
mutate(action[1], p => { | ||
if (isRemoved(p)) return; | ||
if (action[0] === 'remove') { | ||
p.remove(); | ||
} else if (action[0] === 'replace') { | ||
p.replaceWith(action[2]); | ||
} | ||
}); | ||
} else { | ||
removeWithRelated([path]); | ||
} | ||
deleted.add(path); | ||
@@ -185,0 +199,0 @@ changed = true; |
@@ -193,3 +193,21 @@ "use strict"; | ||
}); | ||
it('should delete import', () => { | ||
const { | ||
code, | ||
metadata | ||
} = keep(['Alive'])` | ||
import { A, B } from "ABC"; | ||
const AB = { | ||
A, | ||
B, | ||
}; | ||
export const Alive = ""; | ||
export default AB; | ||
`; | ||
expect(code).toMatchSnapshot(); | ||
expect(metadata.imports.size).toBe(0); | ||
}); | ||
}); | ||
//# sourceMappingURL=shaker-plugin.test.js.map |
@@ -183,3 +183,4 @@ "use strict"; | ||
const binding = getBindingForExport(path); | ||
const parent = (0, _utils.findParentForDelete)(path); | ||
const action = (0, _utils.findActionForNode)(path); | ||
const parent = action === null || action === void 0 ? void 0 : action[1]; | ||
const outerReferences = ((binding === null || binding === void 0 ? void 0 : binding.referencePaths) || []).filter(ref => ref !== parent && !(parent !== null && parent !== void 0 && parent.isAncestor(ref))); | ||
@@ -194,3 +195,16 @@ | ||
if (!deleted.has(path) && (!binding || outerReferences.length === 0)) { | ||
(0, _utils.removeWithRelated)([parent !== null && parent !== void 0 ? parent : path]); | ||
if (action) { | ||
(0, _utils.mutate)(action[1], p => { | ||
if ((0, _utils.isRemoved)(p)) return; | ||
if (action[0] === 'remove') { | ||
p.remove(); | ||
} else if (action[0] === 'replace') { | ||
p.replaceWith(action[2]); | ||
} | ||
}); | ||
} else { | ||
(0, _utils.removeWithRelated)([path]); | ||
} | ||
deleted.add(path); | ||
@@ -197,0 +211,0 @@ changed = true; |
{ | ||
"name": "@linaria/shaker", | ||
"description": "Blazing fast zero-runtime CSS in JS library", | ||
"version": "4.2.3", | ||
"version": "4.2.4", | ||
"bugs": "https://github.com/callstack/linaria/issues", | ||
@@ -14,3 +14,3 @@ "dependencies": { | ||
"@linaria/logger": "^4.0.0", | ||
"@linaria/utils": "^4.2.3", | ||
"@linaria/utils": "^4.2.4", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.24", | ||
@@ -17,0 +17,0 @@ "ts-invariant": "^0.10.3" |
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
101825
917
Updated@linaria/utils@^4.2.4