-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(3517): super-simplistic fix to avoid costly AST transforms when t… #4292
Merged
+92
−8
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33f9e9e
fix(3517): super-simplistic fix to avoid costly AST transforms when t…
janl f88e2c1
Add rewrite function with ast bypass into separate file
big-r81 3f2610e
Build multiple main js files
big-r81 d3672f6
file name consistency and gitignore
janl dca85ab
add main-ast-bypass.js to distribution
janl ea77ab5
docs: document workaround
janl 15da543
fix: create main-ast-bypass.js for SM 1.8.5 to make release happy
janl 3d540ab
fix typo
janl 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
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
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,61 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
// | ||
// Based on the normalizeFunction which can be | ||
// found here: | ||
// | ||
// https://github.com/dmunch/couch-chakra/blob/master/js/normalizeFunction.js | ||
|
||
function rewriteFunInt(fun) { | ||
// Skip lengthy AST transforms if the function passed can be | ||
// safely wrapped in parentheses. | ||
if (fun.startsWith('function') && fun.endsWith('}')) { | ||
return '(' + fun + ')' | ||
} | ||
|
||
const ast = esprima.parse(fun); | ||
let idx = ast.body.length - 1; | ||
let decl = {}; | ||
|
||
// Search for the first FunctionDeclaration beginning from the end | ||
do { | ||
decl = ast.body[idx--]; | ||
} while (idx >= 0 && decl.type !== "FunctionDeclaration"); | ||
idx++; | ||
|
||
// If we have a function declaration without an Id, wrap it | ||
// in an ExpressionStatement and change it into | ||
// a FunctionExpression | ||
if (decl.type == "FunctionDeclaration" && decl.id == null) { | ||
decl.type = "FunctionExpression"; | ||
ast.body[idx] = { | ||
type: "ExpressionStatement", | ||
expression: decl | ||
}; | ||
} | ||
|
||
// Generate source from the rewritten AST | ||
return escodegen.generate(ast); | ||
} | ||
|
||
function rewriteFun(funJSON) { | ||
const fun = JSON.parse(funJSON); | ||
return JSON.stringify(rewriteFunInt(fun)); | ||
} | ||
|
||
function rewriteFuns(funsJSON) { | ||
let funs = JSON.parse(funsJSON); | ||
const results = Array.from(funs, (fun) => { | ||
return rewriteFunInt(fun); | ||
}); | ||
return JSON.stringify(results); | ||
} |
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
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.
Wonder if a slightly unpleasant part here could be that an edit in
bin/couchdb
, which is installed by rpm/deb packages, would make that that file unable to be updated automatically by subsequent package upgrades?RPM would put updates in
.rpmnew
files and deb, I think?, stops and prompts the user about what to do. Prompts are easy for desktops, but can be a pain for unattended upgrades.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.
you can do this via env var, you don’t have to edit
bin/couchdb
— that’s just where you get the original paths that are valid for your system