Skip to content

Plugin is not transforming virtual modules #567

Description

@Tundon
  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version: ^5.0.2

Expected Behavior / Situation

Take an example config as followed, (also available in this reproducible link: https://repl.it/repls/FocusedAptOutsourcing#rollup.config.js):

import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';

export default [
  // this physically present typescript file works fine, as expected
  {
    input: "src/main.ts",
    plugins: [
      resolve(),
      typescript()
    ]
  },

  // this virtually loaded file doesn't work
  {
    input: "src/virtual.ts",
    plugins: [
      {
        resolveId(source) {
          if (source == "src/virtual.ts") return source;

          return null;
        },
        load(id) {
          if (id == "src/virtual.ts") return virtualContent;

          return null;
        }
      },
      resolve(),
      typescript()
    ]
  },
]

var virtualContent = `
interface IType {
  name: string;
}

export function hello(t: IType) {
  console.log(t.name);
}
`

I would assume since the custom plugin loaded the module, the typescript plugin would just transform the module without any problem.

Actual Behavior / Situation

The second config would have an error
[!] Error: The keyword 'interface' is reserved (Note that you need plugins to import files that are not JavaScript)

Modification Proposal

I believe this is because the typescript plugin is using load hook to transform the module (which I am a bit confused the reasoning).

Maybe I missed something behind, but I do think the transform hook is a better place for compiling typescript modules.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions