Skip to content

Commit

Permalink
fix: filter out .d.ts before passing srcs to transpiler (#3238)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored and alexeagle committed Jan 13, 2022
1 parent 098f235 commit 11460e8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/typescript/index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,13 @@ def ts_project(
typecheck_target_name = "%s_typecheck" % name
test_target_name = "%s_typecheck_test" % name

transpile_srcs = [s for s in srcs if _lib.is_ts_src(s, allow_js)]
if (len(transpile_srcs) != len(js_outs)):
fail("ERROR: illegal state: transpile_srcs has length {} but js_outs has length {}".format(
len(transpile_srcs),
len(js_outs),
))

common_kwargs = {
"tags": kwargs.get("tags", []),
"visibility": kwargs.get("visibility", None),
Expand All @@ -505,7 +512,7 @@ def ts_project(
if type(transpiler) == "function" or type(transpiler) == "rule":
transpiler(
name = transpile_target_name,
srcs = srcs,
srcs = transpile_srcs,
js_outs = js_outs,
map_outs = map_outs,
**common_kwargs
Expand All @@ -514,7 +521,7 @@ def ts_project(
partial.call(
transpiler,
name = transpile_target_name,
srcs = srcs,
srcs = transpile_srcs,
js_outs = js_outs,
map_outs = map_outs,
**common_kwargs
Expand Down
23 changes: 23 additions & 0 deletions packages/typescript/test/ts_project/swc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ write_file(
content = ["export const a: string = 1"],
)

write_file(
name = "gen_lib_dts",
out = "lib.d.ts",
content = ["export const a: string;"],
)

write_file(
name = "gen_index_ts",
out = "index.ts",
content = ["export const a: string = \"1\";"],
)

ts_project(
name = "transpile_with_swc",
srcs = ["big.ts"],
Expand Down Expand Up @@ -53,4 +65,15 @@ ts_project(
tsconfig = _TSCONFIG,
)

ts_project(
name = "transpile_with_dts",
srcs = [
"index.ts",
"lib.d.ts",
],
tags = ["manual"],
transpiler = swc_macro,
tsconfig = _TSCONFIG,
)

test_suite()
16 changes: 16 additions & 0 deletions packages/typescript/test/ts_project/swc/tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ transpile_with_failing_typecheck_test = unittest.make(_impl1, attrs = {
"expected_js": attr.string_list(default = ["typeerror.js", "typeerror.js.map"]),
})

def _impl2(ctx):
env = unittest.begin(ctx)

js_files = []
for js in ctx.attr.lib[JSModuleInfo].sources.to_list():
js_files.append(js.basename)
asserts.equals(env, ctx.attr.expected_js, sorted(js_files))

return unittest.end(env)

transpile_with_dts_test = unittest.make(_impl2, attrs = {
"lib": attr.label(default = "transpile_with_dts"),
"expected_js": attr.string_list(default = ["index.js", "index.js.map"]),
})

def test_suite():
unittest.suite("t0", transitive_declarations_test)
unittest.suite("t1", transpile_with_failing_typecheck_test)
unittest.suite("t2", transpile_with_dts_test)

0 comments on commit 11460e8

Please sign in to comment.