Skip to content

Commit d48ecd9

Browse files
committed
fix more tests
1 parent fcbad5a commit d48ecd9

5 files changed

Lines changed: 48 additions & 36 deletions

File tree

src/transpilation/resolve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ResolutionContext {
7373
return;
7474
}
7575

76-
if (this.noResolvePaths.find(isMatch => isMatch.test(required.requirePath))) {
76+
if (this.noResolvePaths.find(isMatch => picomatch.test(required.requirePath, isMatch))) {
7777
if (this.options.tstlVerbose) {
7878
console.log(
7979
`Skipping module resolution of ${required.requirePath} as it is in the tsconfig noResolvePaths.`

test/unit/destructuring.spec.ts

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,50 @@ import * as util from "../util";
33

44
const allBindings = "x, y, z, rest";
55
const testCases = [
6-
{ binding: "{ x }", value: { x: true } },
7-
{ binding: "{ x, y }", value: { x: false, y: true } },
8-
{ binding: "{ x: z, y }", value: { x: true, y: false } },
9-
{ binding: "{ x: { x, y }, z }", value: { x: { x: true, y: false }, z: false } },
10-
{ binding: "{ x, y = true }", value: { x: false, y: false } },
11-
{ binding: "{ x = true }", value: {} },
12-
{ binding: "{ x, y = true }", value: { x: false } },
13-
{ binding: "{ ...rest }", value: {} },
14-
{ binding: "{ x, ...rest }", value: { x: "x" } },
15-
{ binding: "{ x, ...rest }", value: { x: "x", y: "y", z: "z" } },
16-
{ binding: "{ x, ...y }", value: { x: "x", y: "y", z: "z" } },
17-
{ binding: "{ x: y, ...z }", value: { x: "x", y: "y", z: "z" } },
18-
19-
{ binding: "[]", value: [] },
20-
{ binding: "[x, y]", value: ["x", "y"] },
21-
{ binding: "[x, , y]", value: ["x", "", "y"] },
22-
{ binding: "[x = true]", value: [false] },
23-
{ binding: "[[x, y]]", value: [["x", "y"]] },
24-
{ binding: "[x, ...rest]", value: ["x"] },
25-
{ binding: "[x, ...rest]", value: ["x", "y", "z"] },
26-
27-
{ binding: "{ y: [z = true] }", value: { y: [false] } },
28-
{ binding: "{ x: [x, y] }", value: { x: ["x", "y"] } },
29-
{ binding: "{ x: [{ y }] }", value: { x: [{ y: "y" }] } },
30-
].map(({ binding, value }) => ({ binding, value: util.formatCode(value) }));
6+
{ binding: "{ x }", type: "{ x: boolean }", value: { x: true } },
7+
{ binding: "{ x, y }", type: "{ x: boolean, y: boolean }", value: { x: false, y: true } },
8+
{ binding: "{ x: z, y }", type: "{ x: boolean, y?: boolean, z?: boolean }", value: { x: true, y: false } },
9+
{
10+
binding: "{ x: { x, y }, z }",
11+
type: "{ x: { x: boolean, y: boolean }, z: boolean }",
12+
value: { x: { x: true, y: false }, z: false },
13+
},
14+
{ binding: "{ x, y = true }", type: "{ x: boolean, y?: boolean }", value: { x: false, y: false } },
15+
{ binding: "{ x = true }", type: "{ x?: boolean }", value: {} },
16+
{ binding: "{ x, y = true }", type: "{ x: boolean, y?: boolean }", value: { x: false } },
17+
{ binding: "{ ...rest }", type: "any", value: {} },
18+
{ binding: "{ x, ...rest }", type: "any", value: { x: "x" } },
19+
{ binding: "{ x, ...rest }", type: "any", value: { x: "x", y: "y", z: "z" } },
20+
{ binding: "{ x, ...y }", type: "any", value: { x: "x", y: "y", z: "z" } },
21+
{ binding: "{ x: y, ...z }", type: "any", value: { x: "x", y: "y", z: "z" } },
22+
23+
{ binding: "[]", type: "boolean[]", value: [] },
24+
{ binding: "[x, y]", type: "[string, string]", value: ["x", "y"] },
25+
{ binding: "[x, , y]", type: "string[]", value: ["x", "", "y"] },
26+
{ binding: "[x = true]", type: "boolean[]", value: [false] },
27+
{ binding: "[x = true]", type: "boolean[]", value: [] },
28+
{ binding: "[[x, y]]", type: "Array<string[]>", value: [["x", "y"]] },
29+
{ binding: "[x, ...rest]", type: "string[]", value: ["x"] },
30+
{ binding: "[x, ...rest]", type: "string[]", value: ["x", "y", "z"] },
31+
32+
{ binding: "{ y: [z = true] }", type: "{ y: boolean[] }", value: { y: [false] } },
33+
{ binding: "{ y: [z = true] }", type: "{ y: boolean[] }", value: { y: [] } },
34+
{ binding: "{ x: [x, y] }", type: "{ x: [string, string] }", value: { x: ["x", "y"] } },
35+
{ binding: "{ x: [{ y }] }", type: "{ x: [{ y: string }] }", value: { x: [{ y: "y" }] } },
36+
].map(({ binding, type, value }) => ({ binding, type, value: util.formatCode(value) }));
3137

3238
test.each([
3339
...testCases,
34-
{ binding: "{ x, y }, z", value: "{ x: false, y: false }, true" },
35-
{ binding: "{ x, y }, { z }", value: "{ x: false, y: false }, { z: true }" },
36-
])("in function parameter (%p)", ({ binding, value }) => {
40+
{ binding: "{ x, y }", type: "{ x: boolean, y: boolean }, z: boolean", value: "{ x: false, y: false }, true" },
41+
{
42+
binding: "{ x, y }",
43+
type: "{ x: boolean, y: boolean }, { z }: { z: boolean }",
44+
value: "{ x: false, y: false }, { z: true }",
45+
},
46+
])("in function parameter (%p)", ({ binding, type, value }) => {
3747
util.testFunction`
3848
let ${allBindings};
39-
function test(${binding}) {
49+
function test(${binding}: ${type}) {
4050
return { ${allBindings} };
4151
}
4252

test/unit/functions/generators.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test(".next()", () => {
2727

2828
test(".next() with parameters", () => {
2929
util.testFunction`
30-
function* generator() {
30+
function* generator(): Generator<number, number, number> {
3131
return yield 0;
3232
}
3333

test/unit/overloads.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ test("overload method2", () => {
6767
test("constructor1", () => {
6868
util.testFunction`
6969
class myclass {
70-
num: number;
71-
str: string;
70+
num?: number;
71+
str?: string;
7272
7373
constructor(def: number);
7474
constructor(def: string);
@@ -88,8 +88,8 @@ test("constructor1", () => {
8888
test("constructor2", () => {
8989
util.testFunction`
9090
class myclass {
91-
num: number;
92-
str: string;
91+
num?: number;
92+
str?: string;
9393
9494
constructor(def: number);
9595
constructor(def: string);

test/unit/spread.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ describe("in object literal", () => {
116116
"{ ...{ x: false }, x: true }",
117117
"{ ...{ x: false }, x: false, ...{ x: true } }",
118118
])("of object literal (%p)", expression => {
119-
util.testExpression(expression).expectToMatchJsResult();
119+
util.testExpression(expression)
120+
.ignoreDiagnostics([2783]) // duplicate property in spread — intentional, testing spread override behavior
121+
.expectToMatchJsResult();
120122
});
121123

122124
test("of object reference", () => {

0 commit comments

Comments
 (0)