Skip to content

Commit

Permalink
fix: terser changes files; add webpack/terser sgnature cleanup; fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Apr 25, 2020
1 parent d4fcd0b commit 5a851d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions __tests__/signatures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ describe('importMatch', () => {
it('maps function signatures', () => {
expect(getFunctionSignature(`import('file')`)).toEqual(getFunctionSignature(`import(/* */'file')`));
});

it('maps function signatures after terser pass', () => {
expect(getFunctionSignature('()=>$(`imported_-f5674t_component`,n.e(3).then(n.bind(null,`xxx`,7)))')).toEqual(
getFunctionSignature('()=>$(`imported_-f5674t_component`,x.e(3).then(x.bind(null,`xxx`,7)))')
);
});
});
10 changes: 10 additions & 0 deletions src/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ export const importMatch = (functionString: string): Mark => {

export const getFunctionSignature = (fn: AnyFunction | string) =>
String(fn)
// quotes
.replace(/(["'])/g, '`')

// comments
.replace(/\/\*([^\*]*)\*\//gi, '')

// webpack specific
.replace(/\w+.e\(/, 'we(')
.replace(/\w+.t.bind\(/, 'wbind(')
.replace(/\w+.bind\(/, 'wbind(')

// prefix imported
.replace(/([A-z0-9_]+)\(`imported_/g, '$(`imported_');

0 comments on commit 5a851d2

Please sign in to comment.