Skip to content

Commit

Permalink
fix(shaker): exports/object issue with TS (fixes #861)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Nov 5, 2021
1 parent 0a14309 commit e3ccad9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/babel/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default function extract(
lazyValues = evaluation.value.__linariaPreval || [];
debug('lazy-deps:values', evaluation.value.__linariaPreval);
} catch (e) {
error('lazy-deps:evaluate', code);
error('lazy-deps:evaluate:error', code);
throw new Error(
'An unexpected runtime error occurred during dependencies evaluation: \n' +
e.stack +
Expand Down
3 changes: 2 additions & 1 deletion packages/shaker/src/GraphBuilderState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Node, VisitorKeys } from '@babel/types';
import ScopeManager from './scope';
import DepsGraph from './DepsGraph';
import { VisitorAction } from './types';

export type OnVisitCallback = (n: Node) => void;

Expand Down Expand Up @@ -41,5 +42,5 @@ export default abstract class GraphBuilderState {
parent: TParent | null,
parentKey: VisitorKeys[TParent['type']] | null,
listIdx?: number | null
): void;
): VisitorAction;
}
11 changes: 10 additions & 1 deletion packages/shaker/src/langs/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,16 @@ export const visitors: Visitors = {
* `obj.b = 2` will be cut and we will get just `{ a: 1 }`.
*/
MemberExpression(this: GraphBuilderState, node: MemberExpression) {
this.baseVisit(node);
if (this.visit(node.object, node, 'object') !== 'ignore') {
this.graph.addEdge(node, node.object);
}

this.context.push('expression');
if (this.visit(node.property, node, 'property') !== 'ignore') {
this.graph.addEdge(node, node.property);
}
this.context.pop();

this.graph.addEdge(node.object, node);

if (
Expand Down

0 comments on commit e3ccad9

Please sign in to comment.