Skip to content

Regression in 5.1.1 related to template literals #575

@shnhrrsn

Description

@shnhrrsn

I'm seeing an issue in 5.1.1 that’s not present prior (tested 5.0.3 and 5.1.0).

Here’s my how I’m testing:

sample.js:

console.log(`${JSON.stringify({
	class: 'testing'
})}`)

test.js:

const acorn = require('acorn')
const fs = require('fs')
const sample = fs.readFileSync('./sample.js').toString()
acorn.parse(sample)

Running this in both Node 8.2 and through acorn.parse in 5.0.3 and 5.1.0 works fine. Trying to parse it in 5.1.1 yields the following:

node acorn.js       
./node_modules/acorn/dist/acorn.js:3457
      throw err
      ^

SyntaxError: Unterminated template (3:4)
    at Parser.pp$4.raise (./node_modules/acorn/dist/acorn.js:2610:13)
    at Parser.pp$8.readTmplToken (./node_modules/acorn/dist/acorn.js:3477:53)
    at Parser.pp$8.tryReadTemplateToken (./node_modules/acorn/dist/acorn.js:3452:10)
    at TokContext.types$1.q_tmpl [as override] (./node_modules/acorn/dist/acorn.js:2764:67)
    at Parser.pp$8.nextToken (./node_modules/acorn/dist/acorn.js:2965:48)
    at Parser.pp$8.next (./node_modules/acorn/dist/acorn.js:2923:8)
    at Parser.pp$3.parseTemplateElement (./node_modules/acorn/dist/acorn.js:2235:8)
    at Parser.pp$3.parseTemplate (./node_modules/acorn/dist/acorn.js:2254:38)
    at Parser.pp$3.parseExprAtom (./node_modules/acorn/dist/acorn.js:2091:17)
    at Parser.pp$3.parseExprSubscripts (./node_modules/acorn/dist/acorn.js:1955:19)

It appears to be the class key, if I quote it it works fine. Interestingly, if I keep the same JSON.stringify block of code without template literals, acorn parses it just fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions