-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): add support for "jsx: preserve" compiler option (#2574
) When tsc is instructed to preserve jsx, the emitted files have a .jsx extension for .tsx and .jsx inputs, which means ts_project needs to be aware of the option to properly define outputs.
- Loading branch information
Showing
7 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test") | ||
load("//packages/typescript:index.bzl", "ts_project") | ||
|
||
# Ensure that jsx inputs result in jsx outputs with preserve_jsx = True | ||
SRCS = [ | ||
"a.tsx", | ||
"b.jsx", | ||
] | ||
|
||
ts_project( | ||
name = "tsconfig", | ||
srcs = SRCS, | ||
allow_js = True, | ||
declaration = True, | ||
declaration_map = True, | ||
out_dir = "out", | ||
preserve_jsx = True, | ||
source_map = True, | ||
) | ||
|
||
filegroup( | ||
name = "types", | ||
srcs = [":tsconfig"], | ||
output_group = "types", | ||
) | ||
|
||
nodejs_test( | ||
name = "test", | ||
data = [ | ||
":tsconfig", | ||
":types", | ||
], | ||
entry_point = "verify-preserve.js", | ||
templated_args = [ | ||
"$(locations :types)", | ||
"$(locations :tsconfig)", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const A = <div>a</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const B = <div>b</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"sourceMap": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"jsx": "preserve", | ||
"types": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const assert = require('assert'); | ||
|
||
const files = process.argv.slice(2); | ||
assert.ok(files.some(f => f.endsWith('out/a.d.ts')), 'Missing a.d.ts'); | ||
assert.ok(files.some(f => f.endsWith('out/a.d.ts.map')), 'Missing a.d.ts.map'); | ||
assert.ok(files.some(f => f.endsWith('out/a.jsx.map'), 'Missing a.jsx.map')); | ||
assert.ok(files.some(f => f.endsWith('out/a.jsx'), 'Missing a.jsx')); | ||
assert.ok(files.some(f => f.endsWith('out/b.jsx'), 'Missing b.jsx')); |