@@ -380,6 +380,11 @@ var defaultOptions = {
380380 // line being 1-based and column 0-based) will be attached to the
381381 // nodes.
382382 locations : false ,
383+ // Pass an optional `{line, column}` object to use for the start of
384+ // the parse. This is mostly useful when using `parseExpressionAt`
385+ // with `locations: true`, to prevent the parser from having to
386+ // determine the line position at the start position.
387+ startLocation : null ,
383388 // A function can be passed as `onToken` option, which will
384389 // cause Acorn to call that function with object in the same
385390 // format as tokens returned from `tokenizer().getToken()`. Note
@@ -533,13 +538,17 @@ var Parser = function Parser(options, input, startPos) {
533538 // Set up token state
534539
535540 // The current position of the tokenizer in the input.
536- if ( startPos ) {
537- this . pos = startPos ;
541+ this . pos = startPos || 0 ;
542+ this . curLine = 1 ;
543+ if ( options . startLocation ) {
544+ this . lineStart = this . pos - options . startLocation . column ;
545+ this . curLine = options . startLocation . line ;
546+ } else if ( startPos ) {
538547 this . lineStart = this . input . lastIndexOf ( "\n" , startPos - 1 ) + 1 ;
539- this . curLine = this . input . slice ( 0 , this . lineStart ) . split ( lineBreak ) . length ;
548+ if ( this . options . locations )
549+ { this . curLine = this . input . slice ( 0 , this . lineStart ) . split ( lineBreak ) . length ; }
540550 } else {
541- this . pos = this . lineStart = 0 ;
542- this . curLine = 1 ;
551+ this . lineStart = 0 ;
543552 }
544553
545554 // Properties of the current token:
@@ -2882,7 +2891,7 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
28822891 }
28832892 }
28842893
2885- if ( ! incDec && this . eat ( types$1 . starstar ) ) {
2894+ if ( ! incDec && ! ( expr . type === "ArrowFunctionExpression" && expr . start === startPos ) && this . eat ( types$1 . starstar ) ) {
28862895 if ( sawUnary )
28872896 { this . unexpected ( this . lastTokStart ) ; }
28882897 else
@@ -6252,7 +6261,7 @@ pp.readWord = function() {
62526261// [ghbt]: https://github.com/acornjs/acorn/issues
62536262
62546263
6255- var version = "8.17 .0" ;
6264+ var version = "8.18 .0" ;
62566265
62576266Parser . acorn = {
62586267 Parser : Parser ,
0 commit comments