You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/04/04 12:55:18 UTC

[GitHub] Antonio-Maranhao opened a new issue #1073: Investigate why code generated by build task had different behavior than original

Antonio-Maranhao opened a new issue #1073: Investigate why code generated by build task had different behavior than original
URL: https://github.com/apache/couchdb-fauxton/issues/1073
 
 
   Note this has been fixed in #1072. This issue is to investigate why it happened in the first place.
   
   ## Expected Behavior
   
   The minified code in `bundle.js` has the same behavior as the original source code.
   
   ## Current Behavior
   
   In PR #1071, the minified code generated in `bundle.js` was not semantically equivalent to the original code. The original `getQueryOptionsParams` in #1071 was :
   ```
   export const getQueryOptionsParams = (state) => {
     const {queryOptionsPanel} = state;
     const params = {};
   
     if (queryOptionsPanel.includeDocs) {
       params.include_docs = queryOptionsPanel.includeDocs;
     }
   
     if (queryOptionsPanel.showBetweenKeys) {
       const betweenKeys = queryOptionsPanel.betweenKeys;
       params.inclusive_end = betweenKeys.include;
       if (betweenKeys.startkey && betweenKeys.startkey != '') {
         params.start_key = betweenKeys.startkey;
       }
       if (betweenKeys.endkey && betweenKeys.endkey != '') {
         params.end_key = betweenKeys.endkey;
       }
     } else if (queryOptionsPanel.showByKeys) {
       if (queryOptionsPanel.byKeys.trim()) {
         params.keys = queryOptionsPanel.byKeys.replace(/\r?\n/g, '');
       }
     }
   
     if (queryOptionsPanel.limit !== 'none') {
       params.limit = parseInt(queryOptionsPanel.limit, 10);
     }
   
     if (queryOptionsPanel.skip) {
       params.skip = parseInt(queryOptionsPanel.skip, 10);
     }
   
     if (queryOptionsPanel.descending) {
       params.descending = queryOptionsPanel.descending;
     }
   
     if (queryOptionsPanel.reduce) {
       params.reduce = true;
   
       if (queryOptionsPanel.groupLevel === 'exact') {
         params.group = true;
       } else {
         params.group_level = queryOptionsPanel.groupLevel;
       }
     }
   
     // Only add UPDATE and STABLE parameters when different than
     // their respective default values. This prevent errors in
     // older CouchDB versions that don't support these parameters.
     if (queryOptionsPanel.update !== undefined) {
       // Default value is 'true'
       if (queryOptionsPanel.update !== 'true') {
         params.update = queryOptionsPanel.update;
       }
     }
   
     if (typeof queryOptionsPanel.stable === 'boolean') {
       // Default value is false
       if (queryOptionsPanel.stable === true) {
         params.stable = queryOptionsPanel.stable;
       }
     }
   
     return params;
   };
   ```
   
   And the corresponding code in `bundle.js` is: 
   ```
   getQueryOptionsParams=function(e){
     var t=e.queryOptionsPanel,a={};
     if(t.includeDocs&&(a.include_docs=t.includeDocs),t.showBetweenKeys){var n=t.betweenKeys;a.inclusive_end=n.include,n.startkey&&""!=n.startkey&&(a.start_key=n.startkey),n.endkey&&""!=n.endkey&&(a.end_key=n.endkey)} else t.showByKeys&&t.byKeys.trim()&&(a.keys=t.byKeys.replace(/\r?\n/g,""));return"none"!==t.limit&&(a.limit=parseInt(t.limit,10)),t.skip&&(a.skip=parseInt(t.skip,10)),t.descending&&(a.descending=t.descending),t.reduce&&(a.reduce=!0,"exact"===t.groupLevel?a.group=!0:a.group_level=t.groupLevel),void 0!==t.update&&(a.update=t.update),"boolean"==typeof t.stable&&(a.stable=t.stable),a}
   ```
   
   Using `getQueryOptionsParams({queryOptionsPanel: {includeDocs: true, stable: false, update: "true"}})` as an example, the original code returns `{include_docs: true, limit: NaN}` but the version in `bundle.js` returns `{include_docs: true, limit: NaN, update: "true", stable: false}`.
   
   ## Possible Solution
   N/A
   
   ## Steps to Reproduce (for bugs)
   1. Create a build using the `getQueryOptionsParams` code above
   2. Run the generated code using `getQueryOptionsParams({queryOptionsPanel: {includeDocs: true, stable: false, update: "true"}})`. It will `{include_docs: true, limit: NaN, update: "true", stable: false}` which is incorrect. The original code returns `{include_docs: true, limit: NaN}`.
   
   ## Context
   <!--- How has this issue affected you? What are you trying to accomplish? -->
   <!--- Providing context helps us come up with a solution that is most useful in the real world -->
   
   ## Your Environment
   
   * Version used: master branch after PR #1071 (https://github.com/apache/couchdb-fauxton/tree/d5d93f7e92416830ca2d53a42d7b642678cd1363)
   * Browser Name and version: chrome 64
   * Operating System and version (desktop or mobile): MacOS
   * Link to your project:
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services