@@ -65,7 +65,7 @@ const keywordRelationalOperator = /in(?:stanceof)?/y;
6565 * @param {* } tokens
6666 * @returns
6767 */
68- function babel7CompatTokens ( tokens ) {
68+ function babel7CompatTokens ( tokens , input ) {
6969 for ( let i = 0 ; i < tokens . length ; i ++ ) {
7070 const token = tokens [ i ] ;
7171 const { type } = token ;
@@ -106,7 +106,7 @@ function babel7CompatTokens(tokens) {
106106 const backquoteEnd = start + 1 ;
107107 const backquoteEndLoc = createPositionWithColumnOffset ( loc . start , 1 ) ;
108108 let startToken ;
109- if ( value . charCodeAt ( 0 ) === charCodes . graveAccent ) {
109+ if ( input . charCodeAt ( start ) === charCodes . graveAccent ) {
110110 // $FlowIgnore: hacky way to create token
111111 startToken = new Token ( {
112112 type : getExportedToken ( tt . backQuote ) ,
@@ -135,7 +135,7 @@ function babel7CompatTokens(tokens) {
135135 // ends with '`'
136136 templateElementEnd = end - 1 ;
137137 templateElementEndLoc = createPositionWithColumnOffset ( loc . end , - 1 ) ;
138- templateValue = value . slice ( 1 , - 1 ) ;
138+ templateValue = value === null ? null : value . slice ( 1 , - 1 ) ;
139139 // $FlowIgnore: hacky way to create token
140140 endToken = new Token ( {
141141 type : getExportedToken ( tt . backQuote ) ,
@@ -149,7 +149,7 @@ function babel7CompatTokens(tokens) {
149149 // ends with `${`
150150 templateElementEnd = end - 2 ;
151151 templateElementEndLoc = createPositionWithColumnOffset ( loc . end , - 2 ) ;
152- templateValue = value . slice ( 1 , - 2 ) ;
152+ templateValue = value === null ? null : value . slice ( 1 , - 2 ) ;
153153 // $FlowIgnore: hacky way to create token
154154 endToken = new Token ( {
155155 type : getExportedToken ( tt . dollarBraceL ) ,
@@ -197,7 +197,9 @@ export default class StatementParser extends ExpressionParser {
197197 file . program = this . parseProgram ( program ) ;
198198 file . comments = this . state . comments ;
199199
200- if ( this . options . tokens ) file . tokens = babel7CompatTokens ( this . tokens ) ;
200+ if ( this . options . tokens ) {
201+ file . tokens = babel7CompatTokens ( this . tokens , this . input ) ;
202+ }
201203
202204 return this . finishNode ( file , "File" ) ;
203205 }
0 commit comments