infernojs / ts-plugin-inferno

Typescript transformer for InfernoJS
MIT License
3 stars 1 forks source link

Type imports are not being removed during compilation #6

Closed MaijaHeiskanen closed 1 year ago

MaijaHeiskanen commented 1 year ago

Type imports are not being removed during compilation

Type imports are not being removed during compilation when they are in the first inferno import statement (import {...} from 'inferno') of a file.

Steps to reproduce:

Steps to reproduce:

  1. Clone https://github.com/MaijaHeiskanen/ts-plugin-inferno/tree/type-imports-are-not-removed and checkout branch "type-imports-are-not-removed"
  2. Go to examples/rollup
  3. yarn to install dependencies
  4. yarn build to build the project

Output has an error:

yarn run v1.22.19
$ rimraf dist && cross-env NODE_ENV=production rollup -c

src/index.tsx → dist/app.js...
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
src/components/Visualizer.tsx (6:9)
(!) Missing exports
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
src/components/Visualizer.tsx
InfernoNode is not exported by node_modules/inferno/index.esm.js
4:  */
5: // import {createVNode} from "inferno"; // If this line is uncommented, no problems
6: import { InfernoNode, createVNode } from "inferno";
            ^
7: import { a } from "./test";
8: export function Visualizer(_a) {
created dist/app.js in 679ms
Done in 1.34s.
  1. Go to examples/rollup/src/components/Visualizer.tsx
  2. Uncomment row 5 which is commented (// import {createVNode} from "inferno"; // If this line is uncommented, no problems)
  3. yarn build to build the project again

Output does not have an error anymore:

yarn run v1.22.19
$ rimraf dist && cross-env NODE_ENV=production rollup -c

src/index.tsx → dist/app.js...
created dist/app.js in 650ms
Done in 1.32s.

The transformer uses the first existing inferno import when adding stuff to inferno import. It seems like the transformer updating the import statement somehow messes up the process of removing imported types. This leads to a situation where the imported type is trying to be resolved from node_modules/inferno/index.esm.js instead of node_modules/inferno/index.d.ts.

Expected behavior

Type imports should have been removed when TS files have been compiled to JS.

Havunen commented 1 year ago

This is fixed in v6.0.0, please note that v6 introduces a breaking change. https://github.com/infernojs/ts-plugin-inferno#breaking-change-in-v600