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

Tokens missing in template literals #215

Open
golopot opened this issue Apr 8, 2022 · 1 comment
Open

Tokens missing in template literals #215

golopot opened this issue Apr 8, 2022 · 1 comment

Comments

@golopot
Copy link

golopot commented Apr 8, 2022

When parsing this template literal,

`${a}b`

, there is no token corresponding to b.

Code:

const meriyah = require("meriyah");

const tokens = [];
const source = "`${a}b`";
const ast = meriyah.parse(source, {
  onToken(type, start, end) {
    tokens.push({
      type,
      value: source.slice(start, end),
      range: [start, end],
    });
  },
});

console.log(tokens);

Actual output:

[
  { type: 'TemplateLiteral', value: '`${', range: [ 0, 3 ] },
  { type: 'Identifier', value: 'a', range: [ 3, 4 ] },
  { type: 'Punctuator', value: '}', range: [ 4, 5 ] }
]

Expected:
The b part appears somewhere in the tokens.

@3cp
Copy link
Member

3cp commented Apr 9, 2022

scanTemplateTail() was called directly by parseTemplate() without going through standard nextToken(). This is bit odd. Needs some study to refactor template tail into nextToken().

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

No branches or pull requests

2 participants