Skip to content

Unexpected token with typescript jsxFactory #432

@lolgesten

Description

@lolgesten
  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version: 4.1.2
  • Rollup Version: 2.12.0
  • Operating System (or Browser): macOS
  • Node Version: 12.14.1

How Do We Reproduce?

Set up tsconfig.json for use with preact:

    "jsx": "react",
    "jsxFactory": "h",

https://mariusschulz.com/blog/per-file-jsx-factories-in-typescript
https://www.typescriptlang.org/docs/handbook/jsx.html

Make some minimal .tsx file:

import { h, render } from 'preact';

const App = () => <div>App</div>;

const holder = document.getElementById('app')!;
render(<App />, holder);

And run it through rollup's typescript plugin.

Expected Behavior

That the rollup typescript plugin will produce javascript ready to be bundled.

Actual Behavior

bundles ./src/index.ts → out...
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/view/App.tsx (3:25)
1: import { h, render } from 'preact';
2: 
3: export const App = () => <div>App</div>;
                            ^

It looks like we get unprocessed JSX, which makes me suspect that the configuration combo jsx: 'react' + jsxFacory: 'h' is not kicking in.

It's a similar error to what's described here: https://github.com/rollup/plugins/tree/master/packages/typescript#preserving-jsx-output

The solution there is to build in an additional transformation step using acorn-jsx, but this shouldn't be necessary since typescript can do the transformation by itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions