guybedford / es-module-lexer

Low-overhead lexer dedicated to ES module parsing for fast analysis
MIT License
933 stars 48 forks source link

Inconsitency in i.s and i.e when parsing imports #144

Closed A-Shleifman closed 1 year ago

A-Shleifman commented 1 year ago

Thank you for the plugin!

Found the following inconsistency/bug:

import test from 'test'; // 👈 parsed as { n: 'test', s: 19: e: 23 }
//                                                        ^^^ length: 4

import('test'); // 👈 parsed as { n: 'test', s: 34: e: 40 }
//                                               ^^^ length: 6

When parsing static imports, {s,e} do not include quotes, while they are included when dynamic imports are parsed.

Demo

guybedford commented 1 year ago

This is by design, since dynamic import is an expression, and therefore includes the quotes, while static import is a direct string.