Skip to content
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

[Bug]: RangeError: Invalid string length #16077

Closed
1 task
Lookout-ent opened this issue Oct 31, 2023 · 10 comments · Fixed by #16078
Closed
1 task

[Bug]: RangeError: Invalid string length #16077

Lookout-ent opened this issue Oct 31, 2023 · 10 comments · Fixed by #16078
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator

Comments

@Lookout-ent
Copy link

Lookout-ent commented Oct 31, 2023

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/eslint-parser

Input code

Configuration file name

No response

Configuration

No response

Current and expected behavior

RangeError: Invalid string length
at Buffer._append (cc.proxy.js:29347:20)
at Buffer.append (cc.proxy.js:29291:10)
at Generator._append (cc.proxy.js:33671:15)
at Generator._printComment (cc.proxy.js:34026:10)
at Generator._printComments (cc.proxy.js:34073:16)
at Generator.printInnerComments (cc.proxy.js:33936:10)
at Generator._maybePrintInnerComments (cc.proxy.js:33924:38)
at Generator.tokenChar (cc.proxy.js:33593:10)
at Generator.rightBrace (cc.proxy.js:33550:10)
at Generator.BlockStatement (cc.proxy.js:29563:8)

Environment

System:
OS: Windows 10 10.0.19045
Binaries:
Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
npmPackages:
@babel/generator: ^7.22.10 => 7.23.0
@babel/parser: ^7.22.13 => 7.23.0
webpack: ^5.88.2 => 5.88.2

Possible solution

No response

Additional context

I am parsing the input and then simply generating the code.
I observed that when i don't have concise:true, option in generator then i'm not seeing the error

let babelParserOption = {
        allowImportExportEverywhere: true,
        allowReturnOutsideFunction: true,
        allowAwaitOutsideFunction: true,
        allowUndeclaredExports:true,
        allowSuperOutsideMethod:true,
        attachComment :true,
        createParenthesizedExpressions: true,
        strictMode: false,
        sourceType:"unambiguous"
    }
    var ast = babelParser.parse(code, babelParserOption);    
    let babelgeneratorOptions = {
        compact: (options && options.compact) || false,
        concise:true,
        jsescOption : {
            quotes: 'single'
        }
    }
    //code generation
    let rewrittenCode = babelGenerator(ast, babelgeneratorOptions).code;
@babel-bot
Copy link
Collaborator

Hey @Lookout-ent! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@Lookout-ent
Copy link
Author

sorry the input is :

problematic.zip

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Oct 31, 2023

This is surprising because concise should generate smaller output than when it's not enabled, thus making the string smaller 🤔

With concise: false the generated code is 3_578_290 chars, with concise: true it throws at 535_587_727.

@nicolo-ribaudo
Copy link
Member

Ush, we add way too much indentation 😬 These are the first few lines of the generated file:

"undefined" === typeof Aura && (Aura = {}); Aura.bootstrap || (Aura.bootstrap = {}); Aura.frameworkJsReady || (Aura.ApplicationDefs = { cmpExporter: {}, libExporter: {} }, $A = { componentService: { addComponent: function (a, b) { Aura.ApplicationDefs.cmpExporter[a] = b; }, addLibraryExporter: function (a, b) { Aura.ApplicationDefs.libExporter[a] = b; }, initEventDefs: function (a) { Aura.ApplicationDefs.eventDefs = a; }, initLibraryDefs: function (a) { Aura.ApplicationDefs.libraryDefs = a; }, initControllerDefs: function (a) { Aura.ApplicationDefs.controllerDefs = a; }, initModuleDefs: function (a) { Aura.ApplicationDefs.moduleDefs = a; } } }); $A.componentService.addLibraryExporter("js://one.centerStageLibrary.Context", function () {/*$A.componentService.addLibraryInclude("js://one.centerStageLibrary.Context",[],function(){return{isSalesforceNativeDesktop:function(a){return a.get("m.isSalesforceNativeDesktop")},isNativeContainer:function(){return"sfNativeBridge"in window},isMasterDetailPanelSupported:function(a){return a.get("m.isMasterDetailEnabled")}}});*/}); $A.componentService.addLibraryExporter("js://one.centerStageLibrary.DefType", function () {/*$A.componentService.addLibraryInclude("js://one.centerStageLibrary.DefType",[],function(){return{getDefType:function(a){return!a?null:0===a.indexOf("e.")?"event":0===a.indexOf("/")?"route":"component"},isEventDef:function(a){return"event"===this.getDefType(a)},isRouteDef:function(a){return"route"===this.getDefType(a)}}});*/}); $A.componentService.addLibraryExporter("js://one.centerStageLibrary.URL", function () {/*$A.componentService.addLibraryInclude("js://one.centerStageLibrary.URL",[],function(){return{getSiteUrlPrefix:function(a){return a.get("m.siteUrlPrefix")},_getPathNameWithoutPrefix:function(a){var b=window.location.pathname;return $A.util.isUndefinedOrNull(b)?"":$A.util.isUndefinedOrNull(a)?b:0===b.indexOf(a)?b.substring(a.length):b},_getUrlWithSitePrefix:function(a,b){return $A.util.isUndefinedOrNull(a)||$A.util.isUndefinedOrNull(b)||0!==a.indexOf("/")||0===a.indexOf(b)?a:b+a},getFullSiteURLWithQuery:function(a){a=
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                a.get("m.fullSiteURLAction").executionComponent.attributes.url;return-1!=a.indexOf("?")?a:null},getFullSiteURL:function(a){a=a.get("m.fullSiteURLAction").executionComponent.attributes.url;var b=a.indexOf("?");return a.slice(0,b)}}});*/}); $A.componentService.addLibraryExporter("js://one.centerStageLibrary.RouteToComponentMapping", function () {/*$A.componentService.addLibraryInclude("js://one.centerStageLibrary.RouteToComponentMapping",[],function(){function g(a){return $A.util.isUndefinedOrNull(a)?[]:a.split("?")}function h(a,c){return a.replace(/{([^{}]{0,})}/g,function(a,e){var b=c[e];return"string"===typeof b||"number"===typeof b?b:a})}var f=function(a,c,d){this.routeDef=a;this.componentDef=c;this.componentAttributes=!$A.util.isEmpty(d)?d:{};this.routeParamsSortedList=this.getParameterNamesFromRouteDefinition(a);this.routeRegExp=this.getRegexpFromRouteDefinition(a);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               this.optionalAttributes=this.getOptionalParameterMapFromRouteDefinition(a)},k=/\{([a-zA-Z][a-zA-Z0-9-]{0,})\}|\([^\(\)]+\)/g;f.prototype.getParameterNamesFromRouteDefinition=function(a){a=g(a);for(var c,d=[];$A.util.isArray(c=k.exec(a[0]));)$A.util.isString(c[1])?d.push(c[1]):d.push(""+d.length);return d};f.prototype.getRegexpFromRouteDefinition=function(a){-1<a.indexOf("?")&&(a=g(a)[0]);"/"===a[a.length-1]&&(a=a.substr(0,a.length-1));a=a.replace(/\{[a-zA-Z][a-zA-Z0-9-]{0,}\}/g,"([._a-zA-Z0-9-]+)");
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               return RegExp("^"+a+"(?:/?$)")};f.prototype.getOptionalParameterMapFromRouteDefinition=function(a){a=g(a);if(2>a.length)return{};var c={},d;a[1].split("\x26").forEach(function(a){d=a.split("\x3d");a=d[0];var b;b=d[1];b=$A.util.isUndefinedOrNull(b)?"":b.replace(/\{|\}/g,"");c[a]=b});return c};f.prototype.match=function(a){a=a.split("?")[0];return this.routeRegExp.test(a)};f.prototype.parseRoute=function(a){a=a.split("?");var c=a[1]||"";a=a[0];if(this.match(a)){a=this.routeRegExp.exec(a);var d;if(c.length){d=
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               {};for(var c=c.split("\x26"),e,b,f=0;f<c.length;f++)b=c[f],e=b.indexOf("\x3d"),-1===e?d[b]=void 0:d[b.substring(0,e)]=decodeURIComponent(b.substring(e+1))}else d={};e={};c=this.optionalAttributes;for(b=1;b<a.length;b++)e[this.routeParamsSortedList[b-1]]=a[b];a=JSON.parse(h(this.componentAttributes,e));for(var g in c)e=c[g],b=g,c.hasOwnProperty(b)&&(d.hasOwnProperty(e)&&!$A.util.isEmpty(d[e]))&&(a[b]=d[e]);return{componentDef:this.componentDef,attributes:a,t:d.t||0}}};return{RouteToComponentMapping:f}});*/}); $A.componentService.addLibraryExporter("js://one.centerStageLibrary.Router", function () {/*$A.componentService.addLibraryInclude("js://one.centerStageLibrary.Router",["js://one.centerStageLibrary.RouteToComponentMapping"],function(h){function b(a,c,k,b,e){var g=$A.util.isObject(a),d=g?a:{};g||(d.path=a,d.routeDef=c,d.componentDef=k,d.componentAttributes=b,d.childRoutes=e);this.config=d;this.path=d.path;this.childRoutes=[]}var l=h.RouteToComponentMapping;b.prototype.initRoutes=function(){if(this.isInitialized)return this;var a=this.config,c=a.childRoutes||[];if(this.hasCmpMapping=!($A.util.isEmpty(a.routeDef)||
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                $A.util.isEmpty(a.componentDef)||$A.util.isUndefinedOrNull(a.componentAttributes)))this.routeToComponentMapping=new l(a.routeDef,a.componentDef,a.componentAttributes);$A.util.forEach(c,function(a){this.childRoutes.push(new b(a))},this);this.isInitialized=!0;return this};b.prototype.appendRoute=function(a){this.childRoutes.push(a);return this};b.prototype.prependRoute=function(a){this.childRoutes.unshift(a);return this};b.prototype.match=function(a){this.isInitialized||this.initRoutes();if(this.hasCmpMapping&&
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           this.routeToComponentMapping.match(a))return[this];if(!a||!(0<a.length&&0===a.indexOf(this.path)))return!1;if(a.length===this.path.length)return[this];a=this.isPassthrough?a:a.substring(this.path.length);0===a.indexOf("/")&&(a=a.substring(1));a=this.matchChildren(a);$A.util.isArray(a)&&a.unshift(this);return a};b.prototype.matchChildren=function(a){this.isInitialized||this.initRoutes();for(var c,b=0;b<this.childRoutes.length;b++)if((c=this.childRoutes[b].match(a))&&0<c.length)return c;return[]};b.prototype.parseRoute=

@Lookout-ent
Copy link
Author

when can we expect the release for this ?

@nicolo-ribaudo
Copy link
Member

I can release later today

@Lookout-ent
Copy link
Author

waiting for the release

@nicolo-ribaudo
Copy link
Member

Sorry I forgot, doing it right now — it will take ~15 minutes.

@Lookout-ent
Copy link
Author

no issue ... thanks for the update

@liuxingbaoyu
Copy link
Member

https://github.com/babel/babel/releases/tag/v7.23.3

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants