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

Incorrect Documentation for ImportType #170

Closed
joshunrau opened this issue Apr 23, 2024 · 1 comment · Fixed by #172
Closed

Incorrect Documentation for ImportType #170

joshunrau opened this issue Apr 23, 2024 · 1 comment · Fixed by #172

Comments

@joshunrau
Copy link

In the README it says the following:

// Import type is provided by `t` value
// (1 for static, 2, for dynamic)
// Returns true
imports[2].t == 2;

This is also stated in lexer.d.ts:

export declare enum ImportType {
    /**
     * A normal static using any syntax variations
     *   import .. from 'module'
     */
    Static = 1,
    /**
     * A dynamic import expression `import(specifier)`
     * or `import(specifier, opts)`
     */
    Dynamic = 2,
    /**
     * An import.meta expression
     */
    ImportMeta = 3,
    /**
     * A source phase import
     *   import source x from 'module'
     */
    StaticSourcePhase = 4,
    /**
     * A dynamic source phase import
     *   import.source('module')
     */
    DynamicSourcePhase = 5
}

However, at runtime, I observe that Static and Dynamic are in fact reversed:

import { init, parse } from 'es-module-lexer';

await init;

const input = `
  // dynamic
  const { a } = await import('a');
  // static
  import b from 'b';
  import { c } from 'c';
`;

const [imports] = parse(input);

console.log(imports);
// [
//   { n: 'a', t: 1, s: 43, e: 46, ss: 36, se: 47, d: 42, a: -1 },
//   { n: 'b', t: 2, s: 78, e: 79, ss: 63, se: 80, d: -1, a: -1 },
//   { n: 'c', t: 2, s: 103, e: 104, ss: 84, se: 105, d: -1, a: -1 }
// ];
@guybedford
Copy link
Owner

Great catch thank you, this is actually a bug.... added #172.

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