-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add grammar error for invalid tagged template, more tests
- Loading branch information
Showing
23 changed files
with
562 additions
and
3 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
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,191 @@ | ||
describe("unittests:: evaluation:: optionalCall", () => { | ||
it("f?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
function f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
export const output: any[] = []; | ||
f?.(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.isUndefined(result.output[1]); | ||
}); | ||
it("o.f?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o.f?.(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o); | ||
}); | ||
it("o.x.f?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
x: { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o.x.f?.(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o.x); | ||
}); | ||
it("o?.f()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o?.f(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o); | ||
}); | ||
it("o?.f?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o?.f?.(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o); | ||
}); | ||
it("o.x?.f()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
x: { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o.x?.f(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o.x); | ||
}); | ||
it("o?.x.f()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
x: { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o?.x.f(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o.x); | ||
}); | ||
it("o?.x?.f()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
x: { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o?.x?.f(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o.x); | ||
}); | ||
it("o?.x?.f?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
x: { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
} | ||
}; | ||
export const output: any[] = []; | ||
o?.x?.f?.(1); | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], result.o.x); | ||
}); | ||
it("f?.()?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
function g(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
function f(a) { | ||
output.push(a); | ||
return g; | ||
} | ||
export const output: any[] = []; | ||
f?.(1)?.(2) | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], 2); | ||
assert.isUndefined(result.output[2]); | ||
}); | ||
it("f?.().f?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
}; | ||
function f(a) { | ||
output.push(a); | ||
return o; | ||
} | ||
export const output: any[] = []; | ||
f?.(1).f?.(2) | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], 2); | ||
assert.strictEqual(result.output[2], result.o); | ||
}); | ||
it("f?.()?.f?.()", async () => { | ||
const result = evaluator.evaluateTypeScript(` | ||
export const o = { | ||
f(a) { | ||
output.push(a); | ||
output.push(this); | ||
} | ||
}; | ||
function f(a) { | ||
output.push(a); | ||
return o; | ||
} | ||
export const output: any[] = []; | ||
f?.(1)?.f?.(2) | ||
`); | ||
assert.strictEqual(result.output[0], 1); | ||
assert.strictEqual(result.output[1], 2); | ||
assert.strictEqual(result.output[2], result.o); | ||
}); | ||
}); |
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,16 @@ | ||
//// [callChain.2.ts] | ||
declare const o1: undefined | (() => number); | ||
o1?.(); | ||
|
||
declare const o2: undefined | { b: () => number }; | ||
o2?.b(); | ||
|
||
declare const o3: { b: (() => { c: string }) | undefined }; | ||
o3.b?.().c; | ||
|
||
|
||
//// [callChain.2.js] | ||
var _a, _b, _c, _d; | ||
(_a = o1) === null || _a === void 0 ? void 0 : _a(); | ||
(_b = o2) === null || _b === void 0 ? void 0 : _b.b(); | ||
(_d = (_c = o3).b) === null || _d === void 0 ? void 0 : _d.call(_c).c; |
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,28 @@ | ||
=== tests/cases/conformance/expressions/optionalChaining/callChain/callChain.2.ts === | ||
declare const o1: undefined | (() => number); | ||
>o1 : Symbol(o1, Decl(callChain.2.ts, 0, 13)) | ||
|
||
o1?.(); | ||
>o1 : Symbol(o1, Decl(callChain.2.ts, 0, 13)) | ||
|
||
declare const o2: undefined | { b: () => number }; | ||
>o2 : Symbol(o2, Decl(callChain.2.ts, 3, 13)) | ||
>b : Symbol(b, Decl(callChain.2.ts, 3, 31)) | ||
|
||
o2?.b(); | ||
>o2?.b : Symbol(b, Decl(callChain.2.ts, 3, 31)) | ||
>o2 : Symbol(o2, Decl(callChain.2.ts, 3, 13)) | ||
>b : Symbol(b, Decl(callChain.2.ts, 3, 31)) | ||
|
||
declare const o3: { b: (() => { c: string }) | undefined }; | ||
>o3 : Symbol(o3, Decl(callChain.2.ts, 6, 13)) | ||
>b : Symbol(b, Decl(callChain.2.ts, 6, 19)) | ||
>c : Symbol(c, Decl(callChain.2.ts, 6, 31)) | ||
|
||
o3.b?.().c; | ||
>o3.b?.().c : Symbol(c, Decl(callChain.2.ts, 6, 31)) | ||
>o3.b : Symbol(b, Decl(callChain.2.ts, 6, 19)) | ||
>o3 : Symbol(o3, Decl(callChain.2.ts, 6, 13)) | ||
>b : Symbol(b, Decl(callChain.2.ts, 6, 19)) | ||
>c : Symbol(c, Decl(callChain.2.ts, 6, 31)) | ||
|
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,31 @@ | ||
=== tests/cases/conformance/expressions/optionalChaining/callChain/callChain.2.ts === | ||
declare const o1: undefined | (() => number); | ||
>o1 : () => number | ||
|
||
o1?.(); | ||
>o1?.() : number | ||
>o1 : () => number | ||
|
||
declare const o2: undefined | { b: () => number }; | ||
>o2 : { b: () => number; } | ||
>b : () => number | ||
|
||
o2?.b(); | ||
>o2?.b() : number | ||
>o2?.b : () => number | ||
>o2 : { b: () => number; } | ||
>b : () => number | ||
|
||
declare const o3: { b: (() => { c: string }) | undefined }; | ||
>o3 : { b: () => { c: string; }; } | ||
>b : () => { c: string; } | ||
>c : string | ||
|
||
o3.b?.().c; | ||
>o3.b?.().c : string | ||
>o3.b?.() : { c: string; } | ||
>o3.b : () => { c: string; } | ||
>o3 : { b: () => { c: string; }; } | ||
>b : () => { c: string; } | ||
>c : string | ||
|
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,20 @@ | ||
//// [elementAccessChain.2.ts] | ||
declare const o1: undefined | { b: string }; | ||
o1?.["b"]; | ||
|
||
declare const o2: undefined | { b: { c: string } }; | ||
o2?.["b"].c; | ||
o2?.b["c"]; | ||
|
||
declare const o3: { b: undefined | { c: string } }; | ||
o3["b"]?.c; | ||
o3.b?.["c"]; | ||
|
||
|
||
//// [elementAccessChain.2.js] | ||
var _a, _b, _c, _d, _e; | ||
(_a = o1) === null || _a === void 0 ? void 0 : _a["b"]; | ||
(_b = o2) === null || _b === void 0 ? void 0 : _b["b"].c; | ||
(_c = o2) === null || _c === void 0 ? void 0 : _c.b["c"]; | ||
(_d = o3["b"]) === null || _d === void 0 ? void 0 : _d.c; | ||
(_e = o3.b) === null || _e === void 0 ? void 0 : _e["c"]; |
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,43 @@ | ||
=== tests/cases/conformance/expressions/optionalChaining/elementAccessChain/elementAccessChain.2.ts === | ||
declare const o1: undefined | { b: string }; | ||
>o1 : Symbol(o1, Decl(elementAccessChain.2.ts, 0, 13)) | ||
>b : Symbol(b, Decl(elementAccessChain.2.ts, 0, 31)) | ||
|
||
o1?.["b"]; | ||
>o1 : Symbol(o1, Decl(elementAccessChain.2.ts, 0, 13)) | ||
>"b" : Symbol(b, Decl(elementAccessChain.2.ts, 0, 31)) | ||
|
||
declare const o2: undefined | { b: { c: string } }; | ||
>o2 : Symbol(o2, Decl(elementAccessChain.2.ts, 3, 13)) | ||
>b : Symbol(b, Decl(elementAccessChain.2.ts, 3, 31)) | ||
>c : Symbol(c, Decl(elementAccessChain.2.ts, 3, 36)) | ||
|
||
o2?.["b"].c; | ||
>o2?.["b"].c : Symbol(c, Decl(elementAccessChain.2.ts, 3, 36)) | ||
>o2 : Symbol(o2, Decl(elementAccessChain.2.ts, 3, 13)) | ||
>"b" : Symbol(b, Decl(elementAccessChain.2.ts, 3, 31)) | ||
>c : Symbol(c, Decl(elementAccessChain.2.ts, 3, 36)) | ||
|
||
o2?.b["c"]; | ||
>o2?.b : Symbol(b, Decl(elementAccessChain.2.ts, 3, 31)) | ||
>o2 : Symbol(o2, Decl(elementAccessChain.2.ts, 3, 13)) | ||
>b : Symbol(b, Decl(elementAccessChain.2.ts, 3, 31)) | ||
>"c" : Symbol(c, Decl(elementAccessChain.2.ts, 3, 36)) | ||
|
||
declare const o3: { b: undefined | { c: string } }; | ||
>o3 : Symbol(o3, Decl(elementAccessChain.2.ts, 7, 13)) | ||
>b : Symbol(b, Decl(elementAccessChain.2.ts, 7, 19)) | ||
>c : Symbol(c, Decl(elementAccessChain.2.ts, 7, 36)) | ||
|
||
o3["b"]?.c; | ||
>o3["b"]?.c : Symbol(c, Decl(elementAccessChain.2.ts, 7, 36)) | ||
>o3 : Symbol(o3, Decl(elementAccessChain.2.ts, 7, 13)) | ||
>"b" : Symbol(b, Decl(elementAccessChain.2.ts, 7, 19)) | ||
>c : Symbol(c, Decl(elementAccessChain.2.ts, 7, 36)) | ||
|
||
o3.b?.["c"]; | ||
>o3.b : Symbol(b, Decl(elementAccessChain.2.ts, 7, 19)) | ||
>o3 : Symbol(o3, Decl(elementAccessChain.2.ts, 7, 13)) | ||
>b : Symbol(b, Decl(elementAccessChain.2.ts, 7, 19)) | ||
>"c" : Symbol(c, Decl(elementAccessChain.2.ts, 7, 36)) | ||
|
Oops, something went wrong.