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

nanohtml transform is not applied to code transpiled from Typescript with esModuleInterop #536

Open
hugueschabot opened this issue Dec 10, 2019 · 0 comments · May be fixed by #537
Open

Comments

@hugueschabot
Copy link

Context

In order to use choo with Typescript, is is better to transpile the code first and then pass it to bankai as suggested in #285 .

And in order to be able to apply nanohtml transform, one need to transpile to es2015 at least (otherwise the template strings are transformed).

When I need to enable the Typescript esModuleInterop option, it breaks the nanohtml transform.

How to reproduce

Create index.ts

import Choo from 'choo'
import html from 'choo/html'

const app = new Choo()
app.route('/', function () {
  return html`<body>meow</body>`
})

module.exports = app.mount('body')

Create tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2015",
    "esModuleInterop": true
  }
}

Transpile with tsc index.ts to get index.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const choo_1 = __importDefault(require("choo"));
const html_1 = __importDefault(require("choo/html"));
const app = new choo_1.default();
app.route('/', function () {
    return html_1.default `<body>meow</body>`;
});
module.exports = app.mount('body');

Expected Behavior

When processing index.js the HTML template strings are replace by DOM element creation.

Current Behavior

Currently, the HTML templates string are not replace and we get Uncaught TypeError: html_1.default is not a function in the Javascript console when starting bankai.

Possible Solution

Upgrade nanohtml to version 1.7.0

@hugueschabot hugueschabot linked a pull request Dec 10, 2019 that will close this issue
3 tasks
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.

1 participant