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

Regression in 5.1.1 related to template literals #575

Closed
shnhrrsn opened this issue Jul 26, 2017 · 1 comment · Fixed by #588
Closed

Regression in 5.1.1 related to template literals #575

shnhrrsn opened this issue Jul 26, 2017 · 1 comment · Fixed by #588

Comments

@shnhrrsn
Copy link

shnhrrsn commented Jul 26, 2017

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.

shnhrrsn added a commit to grindjs/stone that referenced this issue Jul 26, 2017
@mysticatea
Copy link
Contributor

I have the same issue.

Repro steps

  1. Execute the following code with acorn@latest (5.1.1)
const acorn = require("acorn")
const code = `
    \`\${ foo({class: 1}) }\`
`

console.log(acorn.version)
console.log(code)
console.log(acorn.parse(code, {ecmaVersion: 8}))

Expected result

※ This is the result of acorn@5.0.3.

5.0.3

    `${ foo({class: 1}) }`

Node {
  type: 'Program',
  start: 0,
  end: 28,
  body:
   [ Node {
       type: 'ExpressionStatement',
       start: 5,
       end: 27,
       expression: [Object] } ],
  sourceType: 'script' }

Actual result

※ This is the result of acorn@5.1.1.

5.1.1

    `${ foo({class: 1}) }`

C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:3457
      throw err
      ^

SyntaxError: Unterminated template (2:26)
    at Parser.pp$4.raise (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:2610:13)
    at Parser.pp$8.readTmplToken (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:3477:53)
    at Parser.pp$8.tryReadTemplateToken (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:3452:10)
    at TokContext.types$1.q_tmpl [as override] (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:2764:67)
    at Parser.pp$8.nextToken (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:2965:48)
    at Parser.pp$8.next (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:2923:8)
    at Parser.pp$3.parseTemplateElement (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:2235:8)
    at Parser.pp$3.parseTemplate (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:2254:38)
    at Parser.pp$3.parseExprAtom (C:\Users\t-nagashima.MSS\dev\sandbox\node_modules\acorn\dist\acorn.js:2091:17)
    at Parser.pp$3.parseExprSubscripts (C:\Users\t-nagashima.MSS\d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants