Repository navigation
Hoist top-level function declarations out of the wombat block - #370
Merged
Merged
Conversation
Backport of webrecorder/wabac.js#380 (fixes webrecorder/wabac.js#379): - carry top-level function declarations across the block, re-declared as var as they are on the global scope - re-declare classes as let instead of const, their binding can be reassigned - rename the carrier from self.___WB_const_x to self.___WB_hoist_x
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #370 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 42 42
Lines 2863 2868 +5
Branches 430 432 +2
=========================================
+ Hits 2863 2868 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tree-sitter never yields a nameless class or function declaration: a nameless function or class parses as an expression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of webrecorder/wabac.js#380 (released in wabac.js 2.27.x, fixes webrecorder/wabac.js#379) into our port of
jsrewriter.ts, as a follow-up of #329 which is not released yet.Changes:
functiondeclarations (includingasync, generator and async generator ones) are now carried across the wombat block likeconstandclass, and re-declared asvarafter it, as they are on the global scope; this fixes pages calling, from one script, a function declared at the top level of another oneclassdeclarations are re-declared asletinstead ofconst, since a class binding can be reassignedself.___WB_const_xtoself.___WB_hoist_x, to stay in line with wabac.jsfunction () {}/class {}is a function / class expression for tree-sitter, never a declaration, so no name guard is needed (unlike wabac.jsif (expr.id.name)check with acorn)Tests ported from wabac.js
test/rewriteJS.ts(combined fixture withfunction E/async function* F, expected strings verbatim), plus dedicated tests for functions of every kind, class reassignment and nameless function expressions.Also records, in
src/zimscraperlib/rewriting/js.pydocstring andrules/rules.yamlheader, that bothjsrewriter.tsandfuzzymatcher.tsare now in sync with wabac.js 2.27.4 (fuzzymatcher.tshas not changed since previous sync point).