microsoft / microsoft/TypeScript
Allow `.js` file generated from `.tsx` file to be runnable in browser with less configuration
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔍 Search Terms
- jsx-dev-runtime.js
- jsx-runtime.js
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
The .js file generated from .tsx file should have file extension in the injected import statement.
Also, if the value of jsxImportSource is relative (for e.g. ./myCustomJSX instead of myCustomJSX), the import statement should have correct relative path to JSX runtime files.
📃 Motivating Example
Suppose, a web project has following files and folders:
/tsconfig.json/myCustomJSX/jsx-dev-runtime.ts/Foo.tsx/subfolder/Bar.tsx/index.html
And, tsconfig.json looks like:
{
"compilerOptions": {
"jsx": "react-jsxdev",
"jsxImportSource": "./myCustomJSX",
}
}
After running npx tsc, all generated .js files (/Foo.js, /subfolder/Bar.js) have following code at the top:
import { jsxDEV as _jsxDEV, Fragment as _Fragment } from "./myCustomJSX/jsx-dev-runtime";
There are three problems with this:
- The
.jsextension is missing in the import statement. - The path of the module is not accurate for
/subfolder/Bar.js - Also,
tscshows following error for/subfolder/Bar.tsx:subfolder/Bar.tsx:13:3 - error TS2307: Cannot find module './myCustomJSX/jsx-dev-runtime' or its corresponding type declarations.
Expected behavior:
/Foo.js:
import { jsxDEV as _jsxDEV, Fragment as _Fragment } from "./myCustomJSX/jsx-dev-runtime.js";
/subfolder/Bar.js:
import { jsxDEV as _jsxDEV, Fragment as _Fragment } from "../myCustomJSX/jsx-dev-runtime.js";
💻 Use Cases
-
What do you want to use this for?
I want to use this for web project that utilizes JSX syntax and uses only TypeScript as build tool. -
What shortcomings exist with current approaches?
The current approach requires too much extra steps when using the generated.jsfile in web project without additional build steps, especially when using relative path injsxImportSource. -
What workarounds are you using in the meantime?
I am providing following inimportmapin/index.htmlfile:<script type="importmap"> { "imports": { "./myCustomJSX/jsx-dev-runtime": "./myCustomJSX/jsx-dev-runtime.js" "./subfolder/myCustomJSX/jsx-dev-runtime": "./myCustomJSX/jsx-dev-runtime.js" } } </script>However, the importmap can grow when there are
.tsxfiles in many depths in file system.
If this issue is solved, there won't be any need for importmap when using relative path injsxImportSource. However, for bare module path, 1 entry in importmap is still required.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
示された tsconfig.json と、Foo.tsx、subfolder/Bar.tsx、myCustomJSX/jsx-dev-runtime.ts のレイアウトで問題を再現します。まず tsc の JSX インポートの出力とモジュール解決の動作を確認し、その後、生成されたインポートに両方の出力ファイル用の .js 拡張子と正しい相対パスが含まれていることを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- build-system, compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100