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

findStaticImports() import detection parses strings containing " import" words #225

Open
dmnsgn opened this issue Feb 1, 2024 · 0 comments

Comments

@dmnsgn
Copy link

dmnsgn commented Feb 1, 2024

Environment

Node.js v21.6.1
"mlly": "^1.5.0"

Reproduction

var mlly = require("mlly")

const imports = mlly.findStaticImports(`

// Examples of strings (backticks and single quote) 
const a = \`// Empty comment\n import Nodes from "\\$\\{v\\}";\`
const b = '// Empty comment\n import myString from "module-string";'

// Code from "highlight.js" qml language
var main = {
  keyword: ' import',
  dn: '',
};
`);
console.log(imports);

returns:

[
  {
    type: 'static',
    imports: 'Nodes ',
    specifier: '\\$\\{v\\}',
    code: 'import Nodes from "\\$\\{v\\}";',
    start: 30,
    end: 58
  },
  {
    type: 'static',
    imports: 'myString ',
    specifier: 'module-string',
    code: 'import myString from "module-string";',
    start: 89,
    end: 126
  },
  {
    type: 'static',
    imports: undefined,
    specifier: ',\n  dn:',
    code: "import',\n  dn: '",
    start: 196,
    end: 212
  }
]

Link: https://runkit.com/embed/fclpb908pqho

Describe the bug

The ESM_STATIC_IMPORT_RE probably doesn't account for that edge case.

Additional context

No response

Logs

No response

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

1 participant