-
-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(chore) - remove closure-compiler #1570
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cb984cb
remove closure-compiler, the current rollup plugin isn't really maint…
JoviDeCroock c7d6d90
add changeset
JoviDeCroock beefcd7
Update curvy-bobcats-fry.md
JoviDeCroock 3363e1a
Remove hoist options from Terser
kitten 3ced484
Remove version from ephemeral package.json
kitten e448217
Remove babel-plugin-closure-elimination
kitten e0c8eb1
Add transformation to clean up function expressions
kitten d97cfa5
Expand function expression transformer to more safe cases
kitten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
'@urql/exchange-auth': patch | ||
'@urql/exchange-execute': patch | ||
'@urql/exchange-graphcache': patch | ||
'@urql/exchange-multipart-fetch': patch | ||
'@urql/exchange-persisted-fetch': patch | ||
'@urql/exchange-populate': patch | ||
'@urql/exchange-refocus': patch | ||
'@urql/exchange-request-policy': patch | ||
'@urql/exchange-retry': patch | ||
'@urql/exchange-suspense': patch | ||
'@urql/core': patch | ||
'@urql/introspection': patch | ||
'next-urql': patch | ||
'@urql/preact': patch | ||
'urql': patch | ||
'@urql/storybook-addon': patch | ||
'@urql/svelte': patch | ||
'@urql/vue': patch | ||
--- | ||
|
||
Remove closure-compiler from the build step |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** Babel plugin for cleaning up arrow function transpilation, which turns function expressions assigned to variable decalators into function declarations when it's safe to do so. */ | ||
const functionExpressionCleanup = ({ types: t }) => { | ||
/** Checks whether this block has only safe conditions up until the given node. */ | ||
const isSafeUntil = (block, until) => { | ||
let body = []; | ||
if (t.isIfStatement(block)) { | ||
body = block.consequent; | ||
if (block.alternate && !isSafeUntil(block.alternate, until)) { | ||
return false; | ||
} | ||
} else if (t.isBlockStatement(block)) { | ||
body = block.body; | ||
} | ||
|
||
for (let i = 0, l = body.length; i < l; i++) { | ||
let node = body[i]; | ||
if (t.isIfStatement(node)) { | ||
// An if statement is safe if it also is safe throughout | ||
if (!isSafeUntil(node, until)) return false; | ||
} else if ( | ||
!t.isVariableDeclaration(node) && | ||
!t.isFunctionDeclaration(node) && | ||
!(t.isExpressionStatement(node) && t.isAssignmentExpression(node.expression)) | ||
) { | ||
// only variable declarations and function declarations are safe | ||
// assignments are fine too, since we're later checking the binding for "constantViolations" | ||
return false; | ||
} else if (node === until) { | ||
return true; | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
return { | ||
visitor: { | ||
FunctionExpression(path) { | ||
if (!t.isVariableDeclarator(path.parent)) { | ||
// Must be on a variable declarator | ||
return; | ||
} | ||
|
||
if ( | ||
t.isFunctionDeclaration(path.parentPath.scope.block) || | ||
t.isFunctionExpression(path.parentPath.scope.block) | ||
) { | ||
// When the function expression is nested inside another function, it may be safe | ||
// to turn this into a declaration, if it's only preceded by variable declarations | ||
// and assignments (potentially even nested in if-statements) | ||
if (!isSafeUntil(path.parentPath.scope.block.body, path.parentPath.parent)) | ||
return; | ||
} else if (!t.isProgram(path.parentPath.scope.block)) { | ||
return; | ||
} | ||
|
||
const binding = path.scope.getBinding(path.parent.id.name); | ||
|
||
if ( | ||
(binding.constantViolations && binding.constantViolations.length) || | ||
binding.referencePaths.some(path => | ||
!t.isCallExpression(path.parentPath.node) && | ||
!t.isProgram(path.parentPath.node)) | ||
) { | ||
// The declaration must not be reassigned and it must only be referenced as plain calls | ||
return; | ||
} | ||
|
||
const fn = t.functionDeclaration( | ||
path.parent.id, | ||
path.node.params, | ||
path.node.body, | ||
path.node.generator, | ||
path.node.async, | ||
); | ||
|
||
// We insert after other variable declarators to not rely on hoisting and for readability | ||
path.parentPath.parentPath.insertAfter( | ||
// If the variabe is exported then the function declaration must also be exported. | ||
t.isExportNamedDeclaration(path.parentPath.parentPath.parent) | ||
? t.exportNamedDeclaration(fn) | ||
: fn | ||
); | ||
|
||
if (path.parentPath.parent.declarations.length <= 1) { | ||
path.parentPath.parentPath.remove(); | ||
} else { | ||
path.remove(); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
export default functionExpressionCleanup; |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just personal taste FWIW but I believe we shouldn't forcefully bump all builds, maybe? It'd be cool if there was a way to tell changesets to "ignore" one and only include it when a non-ignored change set was in a release too