Skip to content

Commit 9eaed03

Browse files
committed
javascriptProjectEmit
1 parent b54740f commit 9eaed03

File tree

3 files changed

+1045
-0
lines changed

3 files changed

+1045
-0
lines changed

internal/execute/tscbuild_test.go

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,192 @@ func TestBuildInferredTypeFromTransitiveModule(t *testing.T) {
472472
}
473473
}
474474

475+
func TestBuildJavascriptProjectEmit(t *testing.T) {
476+
t.Parallel()
477+
testCases := []*tscInput{
478+
{
479+
// !!! sheetal errors seem different
480+
subScenario: "loads js-based projects and emits them correctly",
481+
files: FileMap{
482+
"/home/src/workspaces/solution/common/nominal.js": stringtestutil.Dedent(`
483+
/**
484+
* @template T, Name
485+
* @typedef {T & {[Symbol.species]: Name}} Nominal
486+
*/
487+
module.exports = {};
488+
`),
489+
"/home/src/workspaces/solution/common/tsconfig.json": stringtestutil.Dedent(`
490+
{
491+
"extends": "../tsconfig.base.json",
492+
"compilerOptions": {
493+
"composite": true,
494+
},
495+
"include": ["nominal.js"],
496+
}
497+
`),
498+
"/home/src/workspaces/solution/sub-project/index.js": stringtestutil.Dedent(`
499+
import { Nominal } from '../common/nominal';
500+
501+
/**
502+
* @typedef {Nominal<string, 'MyNominal'>} MyNominal
503+
*/
504+
`),
505+
"/home/src/workspaces/solution/sub-project/tsconfig.json": stringtestutil.Dedent(`
506+
{
507+
"extends": "../tsconfig.base.json",
508+
"compilerOptions": {
509+
"composite": true,
510+
},
511+
"references": [
512+
{ "path": "../common" },
513+
],
514+
"include": ["./index.js"],
515+
}`),
516+
"/home/src/workspaces/solution/sub-project-2/index.js": stringtestutil.Dedent(`
517+
import { MyNominal } from '../sub-project/index';
518+
519+
const variable = {
520+
key: /** @type {MyNominal} */('value'),
521+
};
522+
523+
/**
524+
* @return {keyof typeof variable}
525+
*/
526+
export function getVar() {
527+
return 'key';
528+
}
529+
`),
530+
"/home/src/workspaces/solution/sub-project-2/tsconfig.json": stringtestutil.Dedent(`
531+
{
532+
"extends": "../tsconfig.base.json",
533+
"compilerOptions": {
534+
"composite": true,
535+
},
536+
"references": [
537+
{ "path": "../sub-project" },
538+
],
539+
"include": ["./index.js"],
540+
}`),
541+
"/home/src/workspaces/solution/tsconfig.json": stringtestutil.Dedent(`
542+
{
543+
"compilerOptions": {
544+
"composite": true,
545+
},
546+
"references": [
547+
{ "path": "./sub-project" },
548+
{ "path": "./sub-project-2" },
549+
],
550+
"include": [],
551+
}`),
552+
"/home/src/workspaces/solution/tsconfig.base.json": stringtestutil.Dedent(`
553+
{
554+
"compilerOptions": {
555+
"skipLibCheck": true,
556+
"rootDir": "./",
557+
"outDir": "../lib",
558+
"allowJs": true,
559+
"checkJs": true,
560+
"declaration": true,
561+
},
562+
}`),
563+
tscLibPath + "/lib.d.ts": strings.Replace(tscDefaultLibContent, "interface SymbolConstructor {", "interface SymbolConstructor {\n readonly species: symbol;", 1),
564+
},
565+
cwd: "/home/src/workspaces/solution",
566+
commandLineArgs: []string{"--b"},
567+
},
568+
{
569+
subScenario: `loads js-based projects with non-moved json files and emits them correctly`,
570+
files: FileMap{
571+
"/home/src/workspaces/solution/common/obj.json": stringtestutil.Dedent(`
572+
{
573+
"val": 42,
574+
}`),
575+
"/home/src/workspaces/solution/common/index.ts": stringtestutil.Dedent(`
576+
import x = require("./obj.json");
577+
export = x;
578+
`),
579+
"/home/src/workspaces/solution/common/tsconfig.json": stringtestutil.Dedent(`
580+
{
581+
"extends": "../tsconfig.base.json",
582+
"compilerOptions": {
583+
"outDir": null,
584+
"composite": true,
585+
},
586+
"include": ["index.ts", "obj.json"],
587+
}`),
588+
"/home/src/workspaces/solution/sub-project/index.js": stringtestutil.Dedent(`
589+
import mod from '../common';
590+
591+
export const m = mod;
592+
`),
593+
"/home/src/workspaces/solution/sub-project/tsconfig.json": stringtestutil.Dedent(`
594+
{
595+
"extends": "../tsconfig.base.json",
596+
"compilerOptions": {
597+
"composite": true,
598+
},
599+
"references": [
600+
{ "path": "../common" },
601+
],
602+
"include": ["./index.js"],
603+
}`),
604+
"/home/src/workspaces/solution/sub-project-2/index.js": stringtestutil.Dedent(`
605+
import { m } from '../sub-project/index';
606+
607+
const variable = {
608+
key: m,
609+
};
610+
611+
export function getVar() {
612+
return variable;
613+
}
614+
`),
615+
"/home/src/workspaces/solution/sub-project-2/tsconfig.json": stringtestutil.Dedent(`
616+
{
617+
"extends": "../tsconfig.base.json",
618+
"compilerOptions": {
619+
"composite": true,
620+
},
621+
"references": [
622+
{ "path": "../sub-project" },
623+
],
624+
"include": ["./index.js"],
625+
}`),
626+
"/home/src/workspaces/solution/tsconfig.json": stringtestutil.Dedent(`
627+
{
628+
"compilerOptions": {
629+
"composite": true,
630+
},
631+
"references": [
632+
{ "path": "./sub-project" },
633+
{ "path": "./sub-project-2" },
634+
],
635+
"include": [],
636+
}`),
637+
"/home/src/workspaces/solution/tsconfig.base.json": stringtestutil.Dedent(`
638+
{
639+
"compilerOptions": {
640+
"skipLibCheck": true,
641+
"rootDir": "./",
642+
"outDir": "../out",
643+
"allowJs": true,
644+
"checkJs": true,
645+
"resolveJsonModule": true,
646+
"esModuleInterop": true,
647+
"declaration": true,
648+
},
649+
}`),
650+
},
651+
cwd: "/home/src/workspaces/solution",
652+
commandLineArgs: []string{"-b"},
653+
},
654+
}
655+
656+
for _, test := range testCases {
657+
test.run(t, "javascriptProjectEmit")
658+
}
659+
}
660+
475661
func TestBuildSolutionProject(t *testing.T) {
476662
t.Parallel()
477663
testCases := []*tscInput{

0 commit comments

Comments
 (0)