FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

`import defer "./a.js"` is accepted without an error, and the output drops `defer` · Issue #64627 · microsoft/TypeScript · GitHub

import defer "./a.js" is accepted without an error, and the output drops defer #64627

Description

🔎 Search Terms

import defer, deferred import, side-effect import, import phase

🕗 Version & Regression Information

  • This is the behavior in every version I tried: 5.9.3 and 7.1.0-dev.20261004.1.

⏯ Playground Link

https://www.typescriptlang.org/play/?module=99&target=99#code/JYWwDg9gTgLgBAEwKYDMlTgIgHQHoCG2AVgM6YDcAUEA

💻 Code

import defer "./a.js";

🙁 Actual behavior

No error. The output leaves out defer, so the module is evaluated eagerly:

import "./a.js";

🙂 Expected behavior

An error. The import defer proposal only allows a namespace import after defer (import defer * as ns from "./a.js"), so this is a syntax error in JavaScript. Babel rejects it (Unexpected token, expected "{").

TypeScript 7.1 already reports an error for the same form with the source phase:

import source "./b.wasm";
// error TS18111: A source phase import must specify a local binding.

Additional information about the issue

In tryParseImportClause, a phase without bindings keeps an empty import clause only for source. For defer, the function returns nil, so the declaration has no import clause, and its phase is lost. checkGrammarImportClause also has no check for a deferred import without bindings: it reports a default import (TS18058) and named imports (TS18059) only.

Keeping the empty import clause for defer too, and reporting an error for it in checkGrammarImportClause, would match import source "./b.wasm".

Found while matching TypeScript's diagnostics in TSRX's parser.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL