Skip to content

Commit c4f8e91

Browse files
authored
chore(async-rewriter2): further limit number of wrapped expressions (#771)
This might help with performance a bit.
1 parent c05acb5 commit c4f8e91

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/async-rewriter2/src/async-writer-babel.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ describe('AsyncWriter', () => {
738738
});
739739

740740
it('throws sensible error messages for long expressions', () => {
741-
expect(() => runTranspiledCode('var abcdefghijklmnopqrstuvwxyz; abcdefghijklmnopqrstuvwxyz()'))
741+
expect(() => runTranspiledCode('globalThis.abcdefghijklmnopqrstuvwxyz = {}; abcdefghijklmnopqrstuvwxyz()'))
742742
.to.throw('abcdefghijklm ... uvwxyz is not a function');
743743
});
744744
});

packages/async-rewriter2/src/stages/transform-maybe-await.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,17 @@ export default ({ types: t }: { types: typeof BabelTypes }): babel.PluginObj<{ f
456456
path.isParenthesizedExpression() ||
457457
path.isUnaryExpression() ||
458458
path.isSuper() || // Would probably break stuff
459+
path.isThisExpression() ||
459460
path.isAwaitExpression() || // No point in awaiting twice
460461
path.parentPath.isAwaitExpression()) {
461462
return;
462463
}
463464

465+
// If it's an identifier and we know where it has been declared, it's fine as well
466+
// because having seen a declaration means either being undefined or having seen
467+
// an assignment as well.
468+
if (path.isIdentifier() && path.scope.hasBinding(path.node.name)) return;
469+
464470
const { expressionHolder, isSyntheticPromise, assertNotSyntheticPromise } = identifierGroup;
465471
const prettyOriginalString = limitStringLength(
466472
path.node.start !== undefined ?

0 commit comments

Comments
 (0)