Skip to content

Commit 542f87e

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/typescript-go into fix/1196
2 parents 17d7e16 + 9fb6cec commit 542f87e

File tree

898 files changed

+39800
-1252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

898 files changed

+39800
-1252
lines changed

internal/printer/printer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ func (p *Printer) emitNamedTupleMember(node *ast.NamedTupleMember) {
19641964
}
19651965

19661966
func (p *Printer) emitUnionTypeConstituent(node *ast.TypeNode) {
1967-
p.emitTypeNode(node, ast.TypePrecedenceIntersection)
1967+
p.emitTypeNode(node, ast.TypePrecedenceTypeOperator)
19681968
}
19691969

19701970
func (p *Printer) emitUnionType(node *ast.UnionTypeNode) {

internal/testrunner/compiler_runner.go

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212

1313
"github.com/microsoft/typescript-go/internal/checker"
14-
"github.com/microsoft/typescript-go/internal/collections"
1514
"github.com/microsoft/typescript-go/internal/core"
1615
"github.com/microsoft/typescript-go/internal/repo"
1716
"github.com/microsoft/typescript-go/internal/testutil"
@@ -83,30 +82,20 @@ func (r *CompilerBaselineRunner) EnumerateTestFiles() []string {
8382
return files
8483
}
8584

85+
var deprecatedTests = []string{
86+
// Test deprecated `importsNotUsedAsValue`
87+
"preserveUnusedImports.ts",
88+
"noCrashWithVerbatimModuleSyntaxAndImportsNotUsedAsValues.ts",
89+
"verbatimModuleSyntaxCompat.ts",
90+
"preserveValueImports_importsNotUsedAsValues.ts",
91+
"importsNotUsedAsValues_error.ts",
92+
}
93+
8694
func (r *CompilerBaselineRunner) RunTests(t *testing.T) {
8795
r.cleanUpLocal(t)
8896
files := r.EnumerateTestFiles()
89-
skippedTests := map[string]string{
90-
"mappedTypeRecursiveInference.ts": "Skipped until we have type printer with truncation limit.",
91-
"jsFileCompilationWithoutJsExtensions.ts": "Skipped until we have proper allowJS support (and errors when not enabled.)",
92-
"fileReferencesWithNoExtensions.ts": "Skipped until we support adding missing extensions in subtasks in fileloader.go",
93-
"typeOnlyMerge2.ts": "Needs investigation",
94-
"typeOnlyMerge3.ts": "Needs investigation",
95-
"filesEmittingIntoSameOutput.ts": "Output order nondeterministic due to collision on filename during parallel emit.",
96-
}
97-
deprecatedTests := []string{
98-
// Test deprecated `importsNotUsedAsValue`
99-
"preserveUnusedImports.ts",
100-
"noCrashWithVerbatimModuleSyntaxAndImportsNotUsedAsValues.ts",
101-
"verbatimModuleSyntaxCompat.ts",
102-
"preserveValueImports_importsNotUsedAsValues.ts",
103-
"importsNotUsedAsValues_error.ts",
104-
}
97+
10598
for _, filename := range files {
106-
if msg, ok := skippedTests[tspath.GetBaseFileName(filename)]; ok {
107-
t.Run(tspath.GetBaseFileName(filename), func(t *testing.T) { t.Skip(msg) })
108-
continue
109-
}
11099
if slices.Contains(deprecatedTests, tspath.GetBaseFileName(filename)) {
111100
continue
112101
}
@@ -324,19 +313,22 @@ func newCompilerTest(
324313
}
325314
}
326315

327-
var concurrentSkippedErrorBaselines = collections.NewSetFromItems(
328-
"circular1.ts",
329-
"circular3.ts",
330-
"recursiveExportAssignmentAndFindAliasedType1.ts",
331-
"recursiveExportAssignmentAndFindAliasedType2.ts",
332-
"recursiveExportAssignmentAndFindAliasedType3.ts",
333-
"superInStaticMembers1.ts target=es2015",
334-
)
316+
var concurrentSkippedErrorBaselines = map[string]string{
317+
"circular1.ts": "Circular error reported in an extra position.",
318+
"circular3.ts": "Circular error reported in an extra position.",
319+
"recursiveExportAssignmentAndFindAliasedType1.ts": "Circular error reported in an extra position.",
320+
"recursiveExportAssignmentAndFindAliasedType2.ts": "Circular error reported in an extra position.",
321+
"recursiveExportAssignmentAndFindAliasedType3.ts": "Circular error reported in an extra position.",
322+
"typeOnlyMerge2.ts": "Type-only merging is not detected when files are checked on different checkers.",
323+
"typeOnlyMerge3.ts": "Type-only merging is not detected when files are checked on different checkers.",
324+
}
335325

336326
func (c *compilerTest) verifyDiagnostics(t *testing.T, suiteName string, isSubmodule bool) {
337327
t.Run("error", func(t *testing.T) {
338-
if !testutil.TestProgramIsSingleThreaded() && concurrentSkippedErrorBaselines.Has(c.testName) {
339-
t.Skip("Skipping error baseline in concurrent mode")
328+
if !testutil.TestProgramIsSingleThreaded() {
329+
if msg, ok := concurrentSkippedErrorBaselines[c.basename]; ok {
330+
t.Skipf("Skipping in concurrent mode: %s", msg)
331+
}
340332
}
341333

342334
defer testutil.RecoverAndFail(t, "Panic on creating error baseline for test "+c.filename)
@@ -368,12 +360,27 @@ func (c *compilerTest) verifyDiagnostics(t *testing.T, suiteName string, isSubmo
368360
})
369361
}
370362

363+
var skippedEmitTests = map[string]string{
364+
"filesEmittingIntoSameOutput.ts": "Output order nondeterministic due to collision on filename during parallel emit.",
365+
"jsFileCompilationWithJsEmitPathSameAsInput.ts": "Output order nondeterministic due to collision on filename during parallel emit.",
366+
"grammarErrors.ts": "Output order nondeterministic due to collision on filename during parallel emit.",
367+
"jsFileCompilationEmitBlockedCorrectly.ts": "Output order nondeterministic due to collision on filename during parallel emit.",
368+
"jsDeclarationsReexportAliasesEsModuleInterop.ts": "cls.d.ts is missing statements when run concurrently.",
369+
"jsFileCompilationWithoutJsExtensions.ts": "No files are emitted.",
370+
"typeOnlyMerge2.ts": "Nondeterministic contents when run concurrently.",
371+
"typeOnlyMerge3.ts": "Nondeterministic contents when run concurrently.",
372+
}
373+
371374
func (c *compilerTest) verifyJavaScriptOutput(t *testing.T, suiteName string, isSubmodule bool) {
372375
if !c.hasNonDtsFiles {
373376
return
374377
}
375378

376379
t.Run("output", func(t *testing.T) {
380+
if msg, ok := skippedEmitTests[c.basename]; ok {
381+
t.Skip(msg)
382+
}
383+
377384
defer testutil.RecoverAndFail(t, "Panic on creating js output for test "+c.filename)
378385
headerComponents := tspath.GetPathComponentsRelativeTo(repo.TestDataPath, c.filename, tspath.ComparePathsOptions{})
379386
if isSubmodule {

internal/testutil/harnessutil/harnessutil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ func compileFilesWithHost(
581581
if config.CompilerOptions().GetEmitDeclarations() {
582582
diagnostics = append(diagnostics, program.GetDeclarationDiagnostics(ctx, nil)...)
583583
}
584+
if harnessOptions.CaptureSuggestions {
585+
diagnostics = append(diagnostics, program.GetSuggestionDiagnostics(ctx, nil)...)
586+
}
584587
emitResult := program.Emit(compiler.EmitOptions{})
585588

586589
return newCompilationResult(config.CompilerOptions(), program, emitResult, diagnostics, harnessOptions)

internal/testutil/tsbaseline/js_emit_baseline.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,13 @@ func DoJSEmitBaseline(
2525
harnessSettings *harnessutil.HarnessOptions,
2626
opts baseline.Options,
2727
) {
28-
if options.GetAllowJS() {
29-
t.Skip("AllowJS is not supported")
30-
return
31-
}
3228
if options.OutFile != "" || options.Out != "" {
33-
t.Skip("OutFile/Out is not supported")
29+
// Just return, no t.Skip; these options are not going to be supported so noting them is not helpful.
3430
return
3531
}
3632

3733
if !options.NoEmit.IsTrue() && !options.EmitDeclarationOnly.IsTrue() && result.JS.Size() == 0 && len(result.Diagnostics) == 0 {
38-
panic("Expected at least one js file to be emitted or at least one error to be created.")
34+
t.Fatal("Expected at least one js file to be emitted or at least one error to be created.")
3935
}
4036

4137
// check js output
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/conformance/salsa/deepElementAccessExpressionInJS.ts] ////
2+
3+
//// [declarations.d.ts]
4+
declare var module: {
5+
exports: {
6+
[key: string]: any;
7+
};
8+
}
9+
//// [elementAccessExpressionInJS.js]
10+
if (module[calculatePropertyName(1)]) {
11+
}
12+
function calculatePropertyName(index) {
13+
// this would be some webpack index in real life
14+
return `property${index}`;
15+
}
16+
17+
18+
//// [elementAccessExpressionInJS.js]
19+
if (module[calculatePropertyName(1)]) {
20+
}
21+
function calculatePropertyName(index) {
22+
// this would be some webpack index in real life
23+
return `property${index}`;
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/conformance/typeTagForMultipleVariableDeclarations.ts] ////
2+
3+
//// [typeTagForMultipleVariableDeclarations.js]
4+
/** @type {number} */
5+
var x,y,z;
6+
x
7+
y
8+
z
9+
10+
11+
//// [typeTagForMultipleVariableDeclarations.js]
12+
/** @type {number} */
13+
var x, y, z;
14+
x;
15+
y;
16+
z;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [tests/cases/compiler/accessorDeclarationEmitJs.ts] ////
2+
3+
//// [a.js]
4+
export const t1 = {
5+
p: 'value',
6+
get getter() {
7+
return 'value';
8+
},
9+
}
10+
11+
export const t2 = {
12+
v: 'value',
13+
set setter(v) {},
14+
}
15+
16+
export const t3 = {
17+
p: 'value',
18+
get value() {
19+
return 'value';
20+
},
21+
set value(v) {},
22+
}
23+
24+
25+
26+
27+
//// [a.d.ts]
28+
export declare const t1: {
29+
p: string;
30+
readonly getter: string;
31+
};
32+
export declare const t2: {
33+
v: string;
34+
setter: any;
35+
};
36+
export declare const t3: {
37+
p: string;
38+
value: string;
39+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--- old.accessorDeclarationEmitJs.js
2+
+++ new.accessorDeclarationEmitJs.js
3+
@@= skipped -24, +24 lines =@@
4+
5+
6+
//// [a.d.ts]
7+
-export namespace t1 {
8+
- let p: string;
9+
- const getter: string;
10+
-}
11+
-export namespace t2 {
12+
- let v: string;
13+
- let setter: any;
14+
-}
15+
-export namespace t3 {
16+
- let p_1: string;
17+
- export { p_1 as p };
18+
- export let value: string;
19+
-}
20+
+export declare const t1: {
21+
+ p: string;
22+
+ readonly getter: string;
23+
+};
24+
+export declare const t2: {
25+
+ v: string;
26+
+ setter: any;
27+
+};
28+
+export declare const t3: {
29+
+ p: string;
30+
+ value: string;
31+
+};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//// [tests/cases/compiler/allowJscheckJsTypeParameterNoCrash.ts] ////
2+
3+
//// [func.ts]
4+
interface ComponentOptions<V> {
5+
watch: Record<string, WatchHandler<any>>;
6+
}
7+
type WatchHandler<T> = (val: T) => void;
8+
declare function extend(options: ComponentOptions<{}>): void;
9+
export var vextend = extend;
10+
//// [app.js]
11+
import {vextend} from './func';
12+
// hover on vextend
13+
export var a = vextend({
14+
watch: {
15+
data1(val) {
16+
this.data2 = 1;
17+
},
18+
data2(val) { },
19+
}
20+
});
21+
22+
//// [func.js]
23+
"use strict";
24+
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.vextend = void 0;
26+
exports.vextend = extend;
27+
//// [app.js]
28+
"use strict";
29+
Object.defineProperty(exports, "__esModule", { value: true });
30+
exports.a = void 0;
31+
const func_1 = require("./func");
32+
// hover on vextend
33+
exports.a = (0, func_1.vextend)({
34+
watch: {
35+
data1(val) {
36+
this.data2 = 1;
37+
},
38+
data2(val) { },
39+
}
40+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- old.allowJscheckJsTypeParameterNoCrash.js
2+
+++ new.allowJscheckJsTypeParameterNoCrash.js
3+
@@= skipped -27, +27 lines =@@
4+
"use strict";
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.a = void 0;
7+
-var func_1 = require("./func");
8+
+const func_1 = require("./func");
9+
// hover on vextend
10+
exports.a = (0, func_1.vextend)({
11+
watch: {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/ambientRequireFunction.ts] ////
2+
3+
//// [node.d.ts]
4+
declare function require(moduleName: string): any;
5+
6+
declare module "fs" {
7+
export function readFileSync(s: string): string;
8+
}
9+
10+
//// [app.js]
11+
/// <reference path="node.d.ts"/>
12+
13+
const fs = require("fs");
14+
const text = fs.readFileSync("/a/b/c");
15+
16+
//// [app.js]
17+
/// <reference path="node.d.ts"/>
18+
const fs = require("fs");
19+
const text = fs.readFileSync("/a/b/c");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/ambientRequireFunction.ts] ////
2+
3+
//// [node.d.ts]
4+
declare function require(moduleName: string): any;
5+
6+
declare module "fs" {
7+
export function readFileSync(s: string): string;
8+
}
9+
10+
//// [app.js]
11+
/// <reference path="node.d.ts"/>
12+
13+
const fs = require("fs");
14+
const text = fs.readFileSync("/a/b/c");
15+
16+
//// [app.js]
17+
/// <reference path="node.d.ts"/>
18+
const fs = require("fs");
19+
const text = fs.readFileSync("/a/b/c");
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [tests/cases/compiler/amdLikeInputDeclarationEmit.ts] ////
2+
3+
//// [typing.d.ts]
4+
declare function define<T=unknown>(name: string, modules: string[], ready: (...modules: unknown[]) => T);
5+
//// [BaseClass.d.ts]
6+
declare module "deps/BaseClass" {
7+
class BaseClass {
8+
static extends<A>(a: A): new () => A & BaseClass;
9+
}
10+
export = BaseClass;
11+
}
12+
//// [ExtendedClass.js]
13+
define("lib/ExtendedClass", ["deps/BaseClass"],
14+
/**
15+
* {typeof import("deps/BaseClass")}
16+
* @param {typeof import("deps/BaseClass")} BaseClass
17+
* @returns
18+
*/
19+
(BaseClass) => {
20+
21+
const ExtendedClass = BaseClass.extends({
22+
f: function() {
23+
return "something";
24+
}
25+
});
26+
27+
// Exports the module in a way tsc recognize class export
28+
const module = {};
29+
module.exports = ExtendedClass
30+
return module.exports;
31+
});
32+
33+
34+
35+
//// [ExtendedClass.d.ts]
36+
export {};

0 commit comments

Comments
 (0)