@wyw-in-js/transform 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/plugins/shaker.js +21 -8
- package/esm/plugins/shaker.js.map +1 -1
- package/esm/shaker.js +1 -1
- package/esm/shaker.js.map +1 -1
- package/esm/transform/generators/createStylisPreprocessor.js +99 -0
- package/esm/transform/generators/createStylisPreprocessor.js.map +1 -0
- package/esm/transform/generators/extract.js +1 -29
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/transform.js +1 -0
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +1 -1
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/utils/collectExportsAndImports.js +14 -10
- package/esm/utils/collectExportsAndImports.js.map +1 -1
- package/esm/utils/scopeHelpers.js +13 -0
- package/esm/utils/scopeHelpers.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/plugins/shaker.js +22 -9
- package/lib/plugins/shaker.js.map +1 -1
- package/lib/shaker.js +2 -1
- package/lib/shaker.js.map +1 -1
- package/lib/transform/generators/createStylisPreprocessor.js +112 -0
- package/lib/transform/generators/createStylisPreprocessor.js.map +1 -0
- package/lib/transform/generators/extract.js +2 -32
- package/lib/transform/generators/extract.js.map +1 -1
- package/lib/transform/generators/transform.js +1 -0
- package/lib/transform/generators/transform.js.map +1 -1
- package/lib/transform/helpers/loadWywOptions.js +3 -4
- package/lib/transform/helpers/loadWywOptions.js.map +1 -1
- package/lib/utils/collectExportsAndImports.js +14 -10
- package/lib/utils/collectExportsAndImports.js.map +1 -1
- package/lib/utils/scopeHelpers.js +13 -0
- package/lib/utils/scopeHelpers.js.map +1 -1
- package/package.json +7 -7
- package/types/index.d.ts +1 -1
- package/types/index.js +2 -2
- package/types/plugins/shaker.js +24 -9
- package/types/shaker.d.ts +1 -1
- package/types/shaker.js +3 -1
- package/types/transform/generators/createStylisPreprocessor.d.ts +11 -0
- package/types/transform/generators/createStylisPreprocessor.js +137 -0
- package/types/transform/generators/extract.d.ts +0 -3
- package/types/transform/generators/extract.js +3 -38
- package/types/transform/generators/transform.js +1 -0
- package/types/transform/helpers/loadWywOptions.js +3 -6
- package/types/utils/collectExportsAndImports.js +14 -10
- package/types/utils/scopeHelpers.js +13 -0
|
@@ -546,6 +546,13 @@ function addExport(path, exported, state) {
|
|
|
546
546
|
state.exports[exported] = path;
|
|
547
547
|
}
|
|
548
548
|
}
|
|
549
|
+
const saveRef = (state, exportName, memberExpression) => {
|
|
550
|
+
// Save all export.____ usages for later
|
|
551
|
+
if (!state.exportRefs.has(exportName)) {
|
|
552
|
+
state.exportRefs.set(exportName, []);
|
|
553
|
+
}
|
|
554
|
+
state.exportRefs.get(exportName).push(memberExpression);
|
|
555
|
+
};
|
|
549
556
|
function collectFromExports(path, state) {
|
|
550
557
|
if (!(0, isExports_1.isExports)(path))
|
|
551
558
|
return;
|
|
@@ -557,19 +564,12 @@ function collectFromExports(path, state) {
|
|
|
557
564
|
return;
|
|
558
565
|
}
|
|
559
566
|
const exportName = property.node.name;
|
|
560
|
-
const saveRef = () => {
|
|
561
|
-
// Save all export.____ usages for later
|
|
562
|
-
if (!state.exportRefs.has(exportName)) {
|
|
563
|
-
state.exportRefs.set(exportName, []);
|
|
564
|
-
}
|
|
565
|
-
state.exportRefs.get(exportName).push(memberExpression);
|
|
566
|
-
};
|
|
567
567
|
const assignmentExpression = memberExpression.parentPath;
|
|
568
568
|
if (!assignmentExpression.isAssignmentExpression({
|
|
569
569
|
left: memberExpression.node,
|
|
570
570
|
})) {
|
|
571
571
|
// If it's not `exports.prop = …`. Just save it.
|
|
572
|
-
saveRef();
|
|
572
|
+
saveRef(state, exportName, memberExpression);
|
|
573
573
|
return;
|
|
574
574
|
}
|
|
575
575
|
const right = assignmentExpression.get('right');
|
|
@@ -582,7 +582,7 @@ function collectFromExports(path, state) {
|
|
|
582
582
|
state.isEsModule = true;
|
|
583
583
|
return;
|
|
584
584
|
}
|
|
585
|
-
saveRef();
|
|
585
|
+
saveRef(state, exportName, memberExpression);
|
|
586
586
|
// eslint-disable-next-line no-param-reassign
|
|
587
587
|
state.exports[property.node.name] = right;
|
|
588
588
|
return;
|
|
@@ -838,7 +838,8 @@ function collectFromAssignmentExpression(path, state) {
|
|
|
838
838
|
const left = path.get('left');
|
|
839
839
|
const right = path.get('right');
|
|
840
840
|
let exported;
|
|
841
|
-
|
|
841
|
+
const isExportRef = left.isMemberExpression() && (0, isExports_1.isExports)(left.get('object'));
|
|
842
|
+
if (isExportRef) {
|
|
842
843
|
const property = left.get('property');
|
|
843
844
|
if (!left.node.computed && property.isIdentifier()) {
|
|
844
845
|
exported = property.node.name;
|
|
@@ -872,6 +873,9 @@ function collectFromAssignmentExpression(path, state) {
|
|
|
872
873
|
// eslint-disable-next-line no-param-reassign
|
|
873
874
|
state.exports[exported] = right;
|
|
874
875
|
}
|
|
876
|
+
if (isExportRef) {
|
|
877
|
+
saveRef(state, exported, left);
|
|
878
|
+
}
|
|
875
879
|
path.skip();
|
|
876
880
|
return;
|
|
877
881
|
}
|
|
@@ -258,6 +258,10 @@ function findActionForNode(path) {
|
|
|
258
258
|
];
|
|
259
259
|
}
|
|
260
260
|
if (parent.isAssignmentExpression()) {
|
|
261
|
+
if (path.isAssignmentExpression()) {
|
|
262
|
+
// `foo = bar = 42` should be replaced with `foo = 42`
|
|
263
|
+
return ['replace', path, path.node.right];
|
|
264
|
+
}
|
|
261
265
|
return findActionForNode(parent);
|
|
262
266
|
}
|
|
263
267
|
if (parent.isCallExpression()) {
|
|
@@ -295,6 +299,15 @@ function findActionForNode(path) {
|
|
|
295
299
|
}
|
|
296
300
|
}
|
|
297
301
|
if (parent.isVariableDeclarator()) {
|
|
302
|
+
if (path.key === 'init' && path.isAssignmentExpression()) {
|
|
303
|
+
// We are removing `bar` in `var foo = bar = 42`. Path should be replaced with `var foo = 42`
|
|
304
|
+
return ['replace', path, path.node.right];
|
|
305
|
+
}
|
|
306
|
+
const init = parent.get('init');
|
|
307
|
+
if (path.key === 'id' && init.isAssignmentExpression()) {
|
|
308
|
+
// We are removing `foo` in `var foo = bar = 42`. Ignore it.
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
298
311
|
return findActionForNode(parent);
|
|
299
312
|
}
|
|
300
313
|
if (parent.isExportNamedDeclaration() &&
|